Re: Functional index performance question - Mailing list pgsql-general

From Mike Mascari
Subject Re: Functional index performance question
Date
Msg-id 3F798B23.6070600@mascari.com
Whole thread Raw
In response to Re: Functional index performance question  (Arguile <arguile@lucentstudios.com>)
Responses Re: Functional index performance question
List pgsql-general
Arguile wrote:

> On Tue, 2003-09-30 at 07:06, Mike Mascari wrote:
>
>>CREATE INDEX i_employees ON employees(lower(name));
>>
>>Let's also assume that the lower() function is computationally
>>expensive. Now if I have a query like:
>>
>>SELECT lower(name)
>>FROM employees
>>WHERE lower(name) = 'mike'
>>
>>will PostgreSQL re-evaluate lower(name)? Is it necessary?
>
> No, it won't re-evaluate. Which is why functional indexes work and why
> you can only declare a functional index on a referentially transparent
> function (see IMMUTABLE flag in CREATE FUNCTION).

I think it will.

Create a function that lies about its IMMUTABLE state and internally
modifies some global variable and execute the query more than once. It
appears that the evaluation of the predicate will not invoke the
function again, but the evaluation of the expression in the attribute
list of the SELECT will.

My point was that re-evaluation of the expression might be avoidable...

Mike Mascari
mascarm@mascari.com



pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: [postgis-users] Union as an aggregate
Next
From: "Nigel J. Andrews"
Date:
Subject: Re: pg_hba.conf