Skip site navigation (1) Skip section navigation (2)

pgsql: Fix up handling of simple-form CASE with constant testexpressio

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix up handling of simple-form CASE with constant testexpressio
Date: 2010-12-19 20:32:59
Message-ID: E1PUPwB-0003HB-EO@gemulon.postgresql.org (view raw or flat)
Thread:
Lists: pgsql-committers
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.

Branch
------
master

Details
-------
http://git.postgresql.org/gitweb?p=postgresql.git;a=commitdiff;h=1b19e2c0baedb959650a27f25bd8537bd51d60b0

Modified Files
--------------
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 HaganderDate: 2010-12-19 20:33:39
Subject: pgsql: Remove thread dumping constant that requires newer Platform SDK
Previous:From: Tom LaneDate: 2010-12-19 17:49:17
Subject: pgsql: Fix erroneous parsing of tsquery input "... & !(subexpression)|

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group