Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id AA6CD9F938C for ; Thu, 4 Jan 2007 02:56:20 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-new, port 10024) with ESMTP id 59043-02 for ; Thu, 4 Jan 2007 02:56:14 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from 66-226-76-106.dedicated.abac.net (66-226-76-106.dedicated.abac.net [66.226.76.106]) by postgresql.org (Postfix) with ESMTP id 12D0B9FA473 for ; Thu, 4 Jan 2007 02:56:13 -0400 (AST) Received: (qmail 6955 invoked by uid 2020); 4 Jan 2007 00:02:32 -0800 Received: from wsip-70-167-125-69.sd.sd.cox.net (HELO ?192.168.0.3?) (70.167.125.69) by 192.168.0.4 with (DHE-RSA-AES256-SHA encrypted) SMTP; 4 Jan 2007 00:02:32 -0800 Message-ID: <459CA541.3060009@modgraph-usa.com> Date: Wed, 03 Jan 2007 22:57:05 -0800 From: "Craig A. James" User-Agent: Thunderbird 1.5.0.9 (X11/20061206) MIME-Version: 1.0 To: Tom Lane CC: pgsql-performance@postgresql.org Subject: Re: Trivial function query optimized badly References: <459C705C.1060803@modgraph-usa.com> <12930.1167889610@sss.pgh.pa.us> In-Reply-To: <12930.1167889610@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=2.899 tagged_above=0 required=5 tests=AWL, BAYES_50, HELO_DYNAMIC_IPADDR2 X-Spam-Level: ** X-Archive-Number: 200701/51 X-Sequence-Number: 22652 Tom Lane wrote: > "Craig A. James" writes: >> CREATE OR REPLACE FUNCTION cansmiles(text) RETURNS text >> AS '/usr/local/pgsql/lib/libchem.so', 'cansmiles' >> LANGUAGE 'C' STRICT IMMUTABLE; > > Umm ... this is a single-argument function. > >> db=> explain analyze select version_id, 'Brc1ccc2nc(cn2c1)C(=O)O' from version where version.isosmiles = cansmiles('Brc1ccc2nc(cn2c1)C(=O)O', 1); > > And this query is invoking some other, two-argument function; which > apparently hasn't been marked IMMUTABLE, else it'd have been folded > to a constant. Good catch, mystery solved. There are two definitions for this function, the first just a "wrapper" for the second with the latter parameter defaulting to "1". The second definition was missing the "IMMUTABLE" keyword. Thanks! Craig