pgsql: Fix missed optimization in relation_excluded_by_constraints(). - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Fix missed optimization in relation_excluded_by_constraints().
Date
Msg-id E1qqcR3-0001Xb-15@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix missed optimization in relation_excluded_by_constraints().

In commit 3fc6e2d7f, I (tgl) argued that we only need to check for
a constant-FALSE restriction clause when there's exactly one
restriction clause, on the grounds that const-folding would have
thrown away anything ANDed with a Const FALSE.  That's true just after
const-folding has been applied, but subsequent processing such as
equivalence class expansion could result in cases where a Const FALSE
is ANDed with some other stuff.  (Compare for instance joinrels.c's
restriction_is_constant_false.)  Hence, tweak this logic to check all
the elements of the baserestrictinfo list, not just one; that's cheap
enough to not be worth worrying about.

There is one existing test case where this visibly improves the plan.
There would not be any savings in runtime, but the planner effort and
executor startup effort will be reduced, and anyway it's odd that
we can detect related cases but not this one.

Richard Guo (independently discovered by David Rowley)

Discussion: https://postgr.es/m/CAMbWs4_x3-CnVVrCboS1LkEhB5V+W7sLSCabsRiG+n7+5_kqbg@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/5d8aa8bcedae7376bd97e79052d606db4e4f8dd4

Modified Files
--------------
src/backend/optimizer/util/plancat.c | 17 +++++++++--------
src/test/regress/expected/join.out   |  8 +++-----
2 files changed, 12 insertions(+), 13 deletions(-)


pgsql-committers by date:

Previous
From: Heikki Linnakangas
Date:
Subject: pgsql: Move canAcceptConnections check from ProcessStartupPacket to cal
Next
From: Tom Lane
Date:
Subject: pgsql: Reindent comment in GenericXLogFinish().