Fix up handling of simple-form CASE with constant test expression.
eval_const_expressions() can replace CaseTestExprs with constants when
the surrounding CASE's test expression is a constant. This confuses
ruleutils.c's heuristic for deparsing simple-form CASEs, leading to
Assert failures or "unexpected CASE WHEN clause" errors. I had put in
a hack solution for that years ago (see commit
514ce7a331c5bea8e55b106d624e55732a002295 of 2006-10-01), but bug #5794
from Peter Speck shows that that solution failed to cover all cases.
Fortunately, there's a much better way, which came to me upon reflecting
that Peter's "CASE TRUE WHEN" seemed pretty redundant: we can "simplify"
the simple-form CASE to the general form of CASE, by simply omitting the
constant test expression from the rebuilt CASE construct. This is
intuitively valid because there is no need for the executor to evaluate
the test expression at runtime; it will never be referenced, because any
CaseTestExprs that would have referenced it are now replaced by constants.
This won't save a whole lot of cycles, since evaluating a Const is pretty
cheap, but a cycle saved is a cycle earned. In any case it beats kluging
ruleutils.c still further. So this patch improves const-simplification
and reverts the previous change in ruleutils.c.
Back-patch to all supported branches. The bug exists in 8.1 too, but it's
out of warranty.
src/backend/optimizer/util/clauses.c | 16 +++++++++++++++-
src/backend/utils/adt/ruleutils.c | 16 ++++++----------
2 files changed, 21 insertions(+), 11 deletions(-)
pgsql-committers by date
|Next:||From: Magnus Hagander||Date: 2010-12-19 20:33:39|
|Subject: pgsql: Remove thread dumping constant that requires newer Platform SDK|
|Previous:||From: Tom Lane||Date: 2010-12-19 17:49:17|
|Subject: pgsql: Fix erroneous parsing of tsquery input "... & !(subexpression)||