Re: Reducing expression evaluation overhead

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: sailesh(at)cs(dot)berkeley(dot)edu
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Reducing expression evaluation overhead
Date: 2004-03-16 04:47:52
Message-ID: 12971.1079412472@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Sailesh Krishnamurthy <sailesh(at)cs(dot)berkeley(dot)edu> writes:
> I like the idea of memoizing the switch with function pointers as I
> don't think branch prediction helps much with varying switch arms
> selected with different exprs.

Check, it's hard to see how any CPU could get much traction on the
behavior of the switch jump in ExecEvalExpr.

> I've forgotten the syntax of case, but for the simple form isn't
> expr=const going to be the same expr for each case arm ? If that's the
> case, couldn't we actually save the value of expr in a Datum and then
> reuse that (through a Const) in each of the other arms to evaluate the
> actual exprs ? That should reduce the number of times ExecEvalVar (and
> through it heapgetattr) are called.

Right now we expand the simple form of CASE into the general form:
CASE x WHEN y THEN ... WHEN z THEN ...
becomes
CASE WHEN x=y THEN ... WHEN x=z THEN ...
This does involve multiple evaluation of x, which'd be particularly
nasty if it's more than just a variable reference. It's probably a good
idea to try to improve that. But inlining ExecEvalExpr will help all
expressions not just CASE, so I'll work on that first ...

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Joe Conway 2004-03-16 04:59:16 Re: rapid degradation after postmaster restart
Previous Message mike g 2004-03-16 04:42:46 Confusion over Copy.c/Count rows from file patch