Re: Question about simple function folding optimization - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Question about simple function folding optimization
Date
Msg-id 7724.1049903663@sss.pgh.pa.us
Whole thread Raw
In response to Question about simple function folding optimization  (Stephan Szabo <sszabo@megazone23.bigpanda.com>)
Responses Re: Question about simple function folding optimization  (Joe Conway <mail@joeconway.com>)
Re: Question about simple function folding optimization  (Bruno Wolff III <bruno@wolff.to>)
Re: Question about simple function folding optimization  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-hackers
Stephan Szabo <sszabo@megazone23.bigpanda.com> writes:
> I noticed today (while trying to answer a question) that the following
> doesn't seem to use the index on reasonably recent sources whereas it
> seems to have at 7.3.1.

> create table b1(a int, b text);
> create function fold_clients(int, text) returns text as 'select
> $1 || ''_'' || upper($2)' language 'sql' immutable;
> create index b1ind on b1(fold_clients(a,b));
> set enable_seqscan=off;
> explain select * from b1 where (fold_clients(a,b))='1_A';

Hmm.  That's an unexpected downside of the recent change to inline
simple SQL functions :-(.  The inlined expression no longer looks
like a match to the index.

The simplest answer is probably to convert the function to plpgsql,
which would probably give better performance for index access anyway.
But I wonder whether any better answer is possible.  I don't want to
give up on the inlining optimization --- anyone see another fix?
        regards, tom lane



pgsql-hackers by date:

Previous
From: "John Liu"
Date:
Subject: pg_dump and indexes
Next
From: Joe Conway
Date:
Subject: Re: Question about simple function folding optimization