pgsql: Simplify COALESCE() with one surviving argument. - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Simplify COALESCE() with one surviving argument.
Date
Msg-id E1uXRfO-004Zru-1i@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Simplify COALESCE() with one surviving argument.

If, after removal of useless null-constant arguments, a CoalesceExpr
has exactly one remaining argument, we can just take that argument as
the result, without bothering to wrap a new CoalesceExpr around it.
This isn't likely to produce any great improvement in runtime per se,
but it can lead to better plans since the planner no longer has to
treat the expression as non-strict.

However, there were a few regression test cases that intentionally
wrote COALESCE(x) as a shorthand way of creating a non-strict
subexpression.  To avoid ruining the intent of those tests, write
COALESCE(x,x) instead.  (If anyone ever proposes de-duplicating
COALESCE arguments, we'll need another iteration of this arms race.
But it seems pretty unlikely that such an optimization would be
worthwhile.)

Author: Maksim Milyutin <maksim.milyutin@tantorlabs.ru>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/8e8573c3-1411-448d-877e-53258b7b2be0@tantorlabs.ru

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/931766aaec58b2ce09c82203456877e0b05e1271

Modified Files
--------------
src/backend/optimizer/util/clauses.c    |  7 +++++
src/test/regress/expected/join.out      | 32 +++++++++++------------
src/test/regress/expected/subselect.out | 46 ++++++++++++++++-----------------
src/test/regress/sql/join.sql           | 10 +++----
src/test/regress/sql/subselect.sql      |  8 +++---
5 files changed, 55 insertions(+), 48 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Add more cross-type comparisons to contrib/btree_gin.
Next
From: Fujii Masao
Date:
Subject: pgsql: Speed up truncation of temporary relations.