pgsql: In locate_grouping_columns(), don't expect an exact match of Var

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: In locate_grouping_columns(), don't expect an exact match of Var
Date: 2013-08-23 21:31:41
Message-ID: E1VCyxJ-0003w1-Lc@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

In locate_grouping_columns(), don't expect an exact match of Var typmods.

It's possible that inlining of SQL functions (or perhaps other changes?)
has exposed typmod information not known at parse time. In such cases,
Vars generated by query_planner might have valid typmod values while the
original grouping columns only have typmod -1. This isn't a semantic
problem since the behavior of grouping only depends on type not typmod,
but it breaks locate_grouping_columns' use of tlist_member to locate the
matching entry in query_planner's result tlist.

We can fix this without an excessive amount of new code or complexity by
relying on the fact that locate_grouping_columns only gets called when
make_subplanTargetList has set need_tlist_eval == false, and that can only
happen if all the grouping columns are simple Vars. Therefore we only need
to search the sub_tlist for a matching Var, and we can reasonably define a
"match" as being a match of the Var identity fields
varno/varattno/varlevelsup. The code still Asserts that vartype matches,
but ignores vartypmod.

Per bug #8393 from Evan Martin. The added regression test case is
basically the same as his example. This has been broken for a very long
time, so back-patch to all supported branches.

Branch
------
REL9_2_STABLE

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

Modified Files
--------------
src/backend/optimizer/plan/planner.c | 21 ++++++++++++++++++---
src/backend/optimizer/util/tlist.c | 29 +++++++++++++++++++++++++++++
src/include/optimizer/tlist.h | 1 +
src/test/regress/expected/rangefuncs.out | 11 +++++++++++
src/test/regress/sql/rangefuncs.sql | 7 +++++++
5 files changed, 66 insertions(+), 3 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message pgsql 2013-08-24 01:17:29 pgsql: Tag refs/tags/REL9_3_RC1 was created
Previous Message Tom Lane 2013-08-21 22:32:13 pgsql: Disable -faggressive-loop-optimizations in gcc 4.8+ for pre-9.2