pgsql: Avoid inserting Result nodes that only compute identity projecti

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Avoid inserting Result nodes that only compute identity projecti
Date: 2013-03-14 17:43:33
Message-ID: E1UGCBh-0006P3-A0@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Avoid inserting Result nodes that only compute identity projections.

The planner sometimes inserts Result nodes to perform column projections
(ie, arbitrary scalar calculations) above plan nodes that lack projection
logic of their own. However, we did that even if the lower plan node was
in fact producing the required column set already; which is a pretty common
case given the popularity of "SELECT * FROM ...". Measurements show that
the useless plan node adds non-negligible overhead, especially when there
are many columns in the result. So add a check to avoid inserting a Result
node unless there's something useful for it to do.

There are a couple of remaining places where unnecessary Result nodes
could get inserted, but they are (a) much less performance-critical,
and (b) coded in such a way that it's hard to avoid inserting a Result,
because the desired tlist is changed on-the-fly in subsequent logic.
We'll leave those alone for now.

Kyotaro Horiguchi; reviewed and further hacked on by Amit Kapila and
Tom Lane.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/4387cf956b9eb13aad569634e0c4df081d76e2e3

Modified Files
--------------
src/backend/optimizer/plan/createplan.c | 8 ++-
src/backend/optimizer/plan/planner.c | 17 +++--
src/backend/optimizer/util/tlist.c | 37 ++++++++++
src/include/optimizer/tlist.h | 3 +
src/test/regress/expected/alter_table.out | 88 +++++++++++------------
src/test/regress/expected/inherit.out | 110 ++++++++++++++---------------
src/test/regress/expected/union.out | 28 ++++----
7 files changed, 163 insertions(+), 128 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2013-03-14 17:51:55 pgsql: Minor fixes for hstore_to_json_loose().
Previous Message Heikki Linnakangas 2013-03-14 17:05:49 pgsql: Change the way UESCAPE is lexed, to reduce the size of the flex