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 06:10:14 |
Message-ID: | 21122.1079417414@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:
> a) I don't see why you would assume branch prediction would be ineffective
> here. There are probably a few arms of the switch that are more common than
> all the others, especially when a large query is evaluating the same
> expression over and over again.
Sure, but the problem from the CPU's point of view is that the pattern
isn't 11111111...2222222...3333333 but 123123123123123... For instance
when evaluating "var op const" over and over, as in this example, the
branches will go to ExecEvalVar, ExecEvalConst, ExecEvalOper,
ExecEvalVar, ExecEvalConst, etc etc. I know of no modern CPU that will
guess right in that scenario. Inlining ExecEvalExpr will push back this
uncertainty to the call points --- which won't make things better, but
can't make 'em any worse either.
> However worrying about branch prediction is probably being premature
True, I'm not sure that it's really an issue. On the other hand, I have
measurements on two different architectures that show ExecEvalExpr being
an unreasonably large fraction of the runtime. Given that there's
hardly anything in there except a switch(), Sailesh's idea that branch
misprediction is part of the problem seems like a reasonable thought.
> b) Instead of storing one of a small set of function pointers in every
> node of every expression, wouldn't it make more sense to have a table
> lookup from node type to function pointer?
That's pretty much what the ExecEvalExpr switch() does already, on most
modern architectures.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Manfred Spraul | 2004-03-16 06:18:31 | Re: WAL write of full pages |
Previous Message | Tom Lane | 2004-03-16 05:52:14 | Re: Confusion over Copy.c/Count rows from file patch |