pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Don't remove surplus columns from GROUP BY for inheritance paren
Date: Wed, 03 Jul 2019 11:50:36 +0000
Message-ID: <E1hidmW-0002jQ-Gf@gemulon.postgresql.org> (raw)

Don't remove surplus columns from GROUP BY for inheritance parents

d4c3a156c added code to remove columns that were not part of a table's
PRIMARY KEY constraint from the GROUP BY clause when all the primary key
columns were present in the group by.  This is fine to do since we know
that there will only be one row per group coming from this relation.
However, the logic failed to consider inheritance parent relations.  These
can have child relations without a primary key, but even if they did, they
could duplicate one of the parent's rows or one from another child
relation.  In this case, those additional GROUP BY columns are required.

Fix this by disabling the optimization for inheritance parent tables.
In v11 and beyond, partitioned tables are fine since partitions cannot
overlap and before v11 partitioned tables could not have a primary key.

Reported-by: Manuel Rigger
Discussion: http://postgr.es/m/CA+u7OA7VLKf_vEr6kLF3MnWSA9LToJYncgpNX2tQ-oWzYCBQAw@mail.gmail.com
Backpatch-through: 9.6

Branch
------
REL_10_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/232019b79229db7a438f00f358d86659fbd6fcb9

Modified Files
--------------
src/backend/optimizer/plan/planner.c     |  8 ++++++++
src/test/regress/expected/aggregates.out | 24 +++++++++++++++++++++++-
src/test/regress/sql/aggregates.sql      | 10 +++++++++-
3 files changed, 40 insertions(+), 2 deletions(-)



view thread (5+ messages)  latest in thread

Message-ID: <E1hidmW-0002jQ-Gf@gemulon.postgresql.org>
Permalink:  ../E1hidmW-0002jQ-Gf@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1hidmW-0002jQ-Gf@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: drowley@postgresql.org
  Subject: Re: pgsql: Don't remove surplus columns from GROUP BY for inheritance paren
  In-Reply-To: <E1hidmW-0002jQ-Gf@gemulon.postgresql.org>
  References: <E1hidmW-0002jQ-Gf@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox