Re: Index on immutable function call - Mailing list pgsql-general

From Philippe Lang
Subject Re: Index on immutable function call
Date
Msg-id E6A0649F1FBFA3408A37F505400E7AC215CFA2@email.attiksystem.ch
Whole thread Raw
In response to Index on immutable function call  ("Philippe Lang" <philippe.lang@attiksystem.ch>)
Responses Re: Index on immutable function call  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
Re: Index on immutable function call  (Dean Rasheed <dean.a.rasheed@googlemail.com>)
List pgsql-general
pgsql-general-owner@postgresql.org wrote:
> On Tue, Jan 19, 2010 at 10:22 AM, Alban Hertroys
> <dalroi@solfertje.student.utwente.nl> wrote:
>>
>> On 19 Jan 2010, at 8:26, A. Kretschmer wrote:
>>> The planner doesn't know the actual parameter for the function, so
>>> he picked out the wrong plan. You can force the planner to
>>> re-planning with a dynamical statement within the function and
>>> EXECUTE that.
>>
>>
>> There are no queries in his function, I think you misread his post.
>
> Perhaps this might work?
>
> create index transform_index on indexed_table(serial) where data1 >
> this_is_a_long_transformation(data2);

Hi,

It does!

With your index alone:

---------------------------
Bitmap Heap Scan on indexed_table  (cost=815.17..10106.08 rows=33333
width=12) (actual time=7.796..236.722 rows=50116 loops=1)
  Recheck Cond: (data1 > this_is_a_long_transformation(data2))
  ->  Bitmap Index Scan on transform_index  (cost=0.00..806.84
rows=33333 width=0) (actual time=7.665..7.665 rows=50116 loops=1)
Total runtime: 459.380 ms
---------------------------

That works just fine, but is there maybe a way of creating a slighly
more "generic" index? If I change the ">" with a "<" in the query, index
cannot of course be used. According to documentation, answer seems to be
"no"...

Thanks, and best regards.

-----------------------------------------------------------------------
Philippe Lang                   Web    : www.attiksystem.ch
Attik System                    Email  : philippe.lang@attiksystem.ch
rte de la Fonderie 2            Phone  : +41 26 422 13 75
1700 Fribourg                   Mobile : +41 79 351 49 94
Switzerland                     Fax    : +41 26 422 13 76






pgsql-general by date:

Previous
From: "Philippe Lang"
Date:
Subject: Re: Index on immutable function call
Next
From: Alban Hertroys
Date:
Subject: Re: Index on immutable function call