Re: Reducing expression evaluation overhead

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Greg Stark <gsstark(at)mit(dot)edu>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Reducing expression evaluation overhead
Date: 2004-03-16 15:10:26
Message-ID: 24751.1079449826@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Greg Stark <gsstark(at)mit(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2004-03-16 15:36:38 Re: WAL write of full pages
Previous Message Dave Cramer 2004-03-16 15:07:55 Some one deleted pg_database entry how to fix it?