Re: Reducing expression evaluation overhead - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Reducing expression evaluation overhead
Date
Msg-id 24751.1079449826@sss.pgh.pa.us
Whole thread Raw
In response to Re: Reducing expression evaluation overhead  (Greg Stark <gsstark@mit.edu>)
Responses Re: Reducing expression evaluation overhead  (Sailesh Krishnamurthy <sailesh@cs.berkeley.edu>)
List pgsql-hackers
Greg Stark <gsstark@mit.edu> writes:
> That's not true all the time, but I know 90% of my case statements are of this
> form. In some ideal world postgres would recognize this form and handle it
> specially using some kind of quick hash table lookup. 

> I don't see how to reconcile that with postgres's extensible types though. I
> guess if postgres can see that every arm of the CASE is a '=' expression one
> side of which is a constant expression and all of the same type then it could
> use the same operators that the hash index code uses? That seems like it would
> be a lot of work though.

Yeah, trying to hash it is more work than I feel like doing.  However I
think it would be a good idea to avoid multiple evaluations of the CASE
test expression, both for speed and to respect the principle of least
surprise.  If the test expression is volatile, our present behavior is
unlikely to make the user happy.

The idea I was toying with is to generate, not "x = y" with repeated
copies of x, but "placeholder = y" where placeholder is a dummy
expression tree node.  Then at runtime, the CASE code would evaluate the
test expression once and save it into the econtext so the dummy node(s)
could regurgitate that value.  We already have exactly such a mechanism
in place to handle the VALUE keyword for domain check constraints;
it'd be easy to duplicate it for CASE.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Dave Cramer
Date:
Subject: Some one deleted pg_database entry how to fix it?
Next
From: Tom Lane
Date:
Subject: Re: WAL write of full pages