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

pgsql: Fix SELECT DISTINCT with index-optimized MIN/MAX oninheritance

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix SELECT DISTINCT with index-optimized MIN/MAX oninheritance
Date: 2012-11-26 17:58:32
Message-ID: E1Td2wy-0002Q9-Hf@gemulon.postgresql.org (view raw or flat)
Thread:
Lists: pgsql-committers
Fix SELECT DISTINCT with index-optimized MIN/MAX on inheritance trees.

In a query such as "SELECT DISTINCT min(x) FROM tab", the DISTINCT is
pretty useless (there being only one output row), but nonetheless it
shouldn't fail.  But it could fail if "tab" is an inheritance parent,
because planagg.c's code for fixing up equivalence classes after making the
index-optimized MIN/MAX transformation wasn't prepared to find child-table
versions of the aggregate expression.  The least ugly fix seems to be
to add an option to mutate_eclass_expressions() to skip child-table
equivalence class members, which aren't used anymore at this stage of
planning so it's not really necessary to fix them.  Since child members
are ignored in many cases already, it seems plausible for
mutate_eclass_expressions() to have an option to ignore them too.

Per bug #7703 from Maxim Boguk.

Back-patch to 9.1.  Although the same code exists before that, it cannot
encounter child-table aggregates AFAICS, because the index optimization
transformation cannot succeed on inheritance trees before 9.1 (for lack
of MergeAppend).

Branch
------
REL9_2_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/eea6ada926c356087f3d3093dc39a71408ce26ec

Modified Files
--------------
src/backend/optimizer/path/equivclass.c  |   10 +++++--
src/backend/optimizer/plan/planagg.c     |    8 ++++-
src/include/optimizer/paths.h            |    3 +-
src/test/regress/expected/aggregates.out |   39 ++++++++++++++++++++++++++++++
src/test/regress/sql/aggregates.sql      |    5 ++++
5 files changed, 59 insertions(+), 6 deletions(-)


pgsql-committers by date

Next:From: Tom LaneDate: 2012-11-26 20:56:12
Subject: pgsql: Revert patch for taking fewer snapshots.
Previous:From: Bruce MomjianDate: 2012-11-25 03:39:08
Subject: pgsql: In pg_upgrade,simplify function copy_file() by using pg_malloc(

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