pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Don't remove surplus columns from GROUP BY for inheritance paren
5+ messages / 1 participants
[nested] [flat]

* pgsql: Don't remove surplus columns from GROUP BY for inheritance paren
@ 2019-07-03 11:48  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: David Rowley @ 2019-07-03 11:48 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a5be4062f7bf2ae9487c5a31ee337a56425cdc84

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Don't remove surplus columns from GROUP BY for inheritance paren
@ 2019-07-03 11:49  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: David Rowley @ 2019-07-03 11:49 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/0cce43a716b40c555892b1d22b41d390ef524ec8

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Don't remove surplus columns from GROUP BY for inheritance paren
@ 2019-07-03 11:49  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: David Rowley @ 2019-07-03 11:49 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/133f5ae214de4a9aed7bfb138ea72ad7926262e2

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Don't remove surplus columns from GROUP BY for inheritance paren
@ 2019-07-03 11:50  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: David Rowley @ 2019-07-03 11:50 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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(-)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* pgsql: Don't remove surplus columns from GROUP BY for inheritance paren
@ 2019-07-03 11:51  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 5+ messages in thread

From: David Rowley @ 2019-07-03 11:51 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

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
------
REL9_6_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/388d05a5e1551e34e3908c2bfad21860adfcc5a7

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



^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2019-07-03 11:51 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-07-03 11:48 pgsql: Don't remove surplus columns from GROUP BY for inheritance paren David Rowley <drowley@postgresql.org>
2019-07-03 11:49 pgsql: Don't remove surplus columns from GROUP BY for inheritance paren David Rowley <drowley@postgresql.org>
2019-07-03 11:49 pgsql: Don't remove surplus columns from GROUP BY for inheritance paren David Rowley <drowley@postgresql.org>
2019-07-03 11:50 pgsql: Don't remove surplus columns from GROUP BY for inheritance paren David Rowley <drowley@postgresql.org>
2019-07-03 11:51 pgsql: Don't remove surplus columns from GROUP BY for inheritance paren David Rowley <drowley@postgresql.org>

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