pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix crash with single-input aggregates with multiple sort keys
7+ messages / 1 participants
[nested] [flat]

* pgsql: Fix crash with single-input aggregates with multiple sort keys
@ 2026-11-06 07:19  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: David Rowley @ 2026-11-06 07:19 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix crash with single-input aggregates with multiple sort keys

An aggregate's ORDER BY can list the same sort key more than once with
different sort operators, and transformDistinctClause() copies such
items into the DISTINCT list.  So an aggregate with a single input can
have several sort keys and several DISTINCT columns.

nodeAgg.c and execExpr.c mistakenly only checked the number of inputs
when deciding if a Datum sort was possible.  That check must also
consider the number of sort keys.

Fix by using the Datum sort only for a single input with a single sort
key.

Also for v16+, fix crash in pre-sorted aggregate code where the uniqslot
was only created when the number of inputs for a DISTINCT aggregate was
above 1.  The uniqslot is required when there are multiple DISTINCT
columns, and an ORDER BY clause may cause more than one of these to exist
when there's only a single input column.

Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAJTYsWXMuo5QZSy_az+86mty2XdbDw_7uB3C4FjWpFACvD_rzg@mail.gmail.com
Backpatch-through: 14

Branch
------
master

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

Modified Files
--------------
src/backend/executor/execExpr.c          |  8 ++++----
src/backend/executor/nodeAgg.c           | 22 ++++++++++++++--------
src/test/regress/expected/aggregates.out | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/aggregates.sql      | 17 +++++++++++++++++
4 files changed, 63 insertions(+), 12 deletions(-)



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

* pgsql: Fix crash with single-input aggregates with multiple sort keys
@ 2026-11-06 07:20  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: David Rowley @ 2026-11-06 07:20 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix crash with single-input aggregates with multiple sort keys

An aggregate's ORDER BY can list the same sort key more than once with
different sort operators, and transformDistinctClause() copies such
items into the DISTINCT list.  So an aggregate with a single input can
have several sort keys and several DISTINCT columns.

nodeAgg.c and execExpr.c mistakenly only checked the number of inputs
when deciding if a Datum sort was possible.  That check must also
consider the number of sort keys.

Fix by using the Datum sort only for a single input with a single sort
key.

Also for v16+, fix crash in pre-sorted aggregate code where the uniqslot
was only created when the number of inputs for a DISTINCT aggregate was
above 1.  The uniqslot is required when there are multiple DISTINCT
columns, and an ORDER BY clause may cause more than one of these to exist
when there's only a single input column.

Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAJTYsWXMuo5QZSy_az+86mty2XdbDw_7uB3C4FjWpFACvD_rzg@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/1c087e61685c5db80ca898b4c4278bf7a349c602

Modified Files
--------------
src/backend/executor/execExpr.c          |  8 ++++----
src/backend/executor/nodeAgg.c           | 22 ++++++++++++++--------
src/test/regress/expected/aggregates.out | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/aggregates.sql      | 17 +++++++++++++++++
4 files changed, 63 insertions(+), 12 deletions(-)



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

* pgsql: Fix crash with single-input aggregates with multiple sort keys
@ 2026-11-06 07:20  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: David Rowley @ 2026-11-06 07:20 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix crash with single-input aggregates with multiple sort keys

An aggregate's ORDER BY can list the same sort key more than once with
different sort operators, and transformDistinctClause() copies such
items into the DISTINCT list.  So an aggregate with a single input can
have several sort keys and several DISTINCT columns.

nodeAgg.c and execExpr.c mistakenly only checked the number of inputs
when deciding if a Datum sort was possible.  That check must also
consider the number of sort keys.

Fix by using the Datum sort only for a single input with a single sort
key.

Also for v16+, fix crash in pre-sorted aggregate code where the uniqslot
was only created when the number of inputs for a DISTINCT aggregate was
above 1.  The uniqslot is required when there are multiple DISTINCT
columns, and an ORDER BY clause may cause more than one of these to exist
when there's only a single input column.

Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAJTYsWXMuo5QZSy_az+86mty2XdbDw_7uB3C4FjWpFACvD_rzg@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/744ca40cbe2cac09124cc8b560d01e71e8c1f8b8

Modified Files
--------------
src/backend/executor/execExpr.c          |  8 ++++----
src/backend/executor/nodeAgg.c           | 22 ++++++++++++++--------
src/test/regress/expected/aggregates.out | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/aggregates.sql      | 17 +++++++++++++++++
4 files changed, 63 insertions(+), 12 deletions(-)



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

* pgsql: Fix crash with single-input aggregates with multiple sort keys
@ 2026-11-06 07:20  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: David Rowley @ 2026-11-06 07:20 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix crash with single-input aggregates with multiple sort keys

An aggregate's ORDER BY can list the same sort key more than once with
different sort operators, and transformDistinctClause() copies such
items into the DISTINCT list.  So an aggregate with a single input can
have several sort keys and several DISTINCT columns.

nodeAgg.c and execExpr.c mistakenly only checked the number of inputs
when deciding if a Datum sort was possible.  That check must also
consider the number of sort keys.

Fix by using the Datum sort only for a single input with a single sort
key.

Also for v16+, fix crash in pre-sorted aggregate code where the uniqslot
was only created when the number of inputs for a DISTINCT aggregate was
above 1.  The uniqslot is required when there are multiple DISTINCT
columns, and an ORDER BY clause may cause more than one of these to exist
when there's only a single input column.

Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAJTYsWXMuo5QZSy_az+86mty2XdbDw_7uB3C4FjWpFACvD_rzg@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_17_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2a3ac15548c6318a33e954b9858284bc05e62bc8

Modified Files
--------------
src/backend/executor/execExpr.c          |  8 ++++----
src/backend/executor/nodeAgg.c           | 22 ++++++++++++++--------
src/test/regress/expected/aggregates.out | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/aggregates.sql      | 17 +++++++++++++++++
4 files changed, 63 insertions(+), 12 deletions(-)



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

* pgsql: Fix crash with single-input aggregates with multiple sort keys
@ 2026-11-06 07:20  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: David Rowley @ 2026-11-06 07:20 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix crash with single-input aggregates with multiple sort keys

An aggregate's ORDER BY can list the same sort key more than once with
different sort operators, and transformDistinctClause() copies such
items into the DISTINCT list.  So an aggregate with a single input can
have several sort keys and several DISTINCT columns.

nodeAgg.c and execExpr.c mistakenly only checked the number of inputs
when deciding if a Datum sort was possible.  That check must also
consider the number of sort keys.

Fix by using the Datum sort only for a single input with a single sort
key.

Also for v16+, fix crash in pre-sorted aggregate code where the uniqslot
was only created when the number of inputs for a DISTINCT aggregate was
above 1.  The uniqslot is required when there are multiple DISTINCT
columns, and an ORDER BY clause may cause more than one of these to exist
when there's only a single input column.

Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAJTYsWXMuo5QZSy_az+86mty2XdbDw_7uB3C4FjWpFACvD_rzg@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/1d57f6ef755b380eea613234bebda37aa766d6b5

Modified Files
--------------
src/backend/executor/execExpr.c          |  8 ++++----
src/backend/executor/nodeAgg.c           | 22 ++++++++++++++--------
src/test/regress/expected/aggregates.out | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/aggregates.sql      | 17 +++++++++++++++++
4 files changed, 63 insertions(+), 12 deletions(-)



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

* pgsql: Fix crash with single-input aggregates with multiple sort keys
@ 2026-11-06 07:20  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: David Rowley @ 2026-11-06 07:20 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix crash with single-input aggregates with multiple sort keys

An aggregate's ORDER BY can list the same sort key more than once with
different sort operators, and transformDistinctClause() copies such
items into the DISTINCT list.  So an aggregate with a single input can
have several sort keys and several DISTINCT columns.

nodeAgg.c and execExpr.c mistakenly only checked the number of inputs
when deciding if a Datum sort was possible.  That check must also
consider the number of sort keys.

Fix by using the Datum sort only for a single input with a single sort
key.

Also for v16+, fix crash in pre-sorted aggregate code where the uniqslot
was only created when the number of inputs for a DISTINCT aggregate was
above 1.  The uniqslot is required when there are multiple DISTINCT
columns, and an ORDER BY clause may cause more than one of these to exist
when there's only a single input column.

Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAJTYsWXMuo5QZSy_az+86mty2XdbDw_7uB3C4FjWpFACvD_rzg@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_15_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/21a53865fb5a199fc7f234a9f9fce5608a39e581

Modified Files
--------------
src/backend/executor/execExpr.c          | 10 ++++++----
src/backend/executor/nodeAgg.c           | 22 ++++++++++++++--------
src/test/regress/expected/aggregates.out | 17 +++++++++++++++++
src/test/regress/sql/aggregates.sql      |  9 +++++++++
4 files changed, 46 insertions(+), 12 deletions(-)



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

* pgsql: Fix crash with single-input aggregates with multiple sort keys
@ 2026-11-06 07:21  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 7+ messages in thread

From: David Rowley @ 2026-11-06 07:21 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix crash with single-input aggregates with multiple sort keys

An aggregate's ORDER BY can list the same sort key more than once with
different sort operators, and transformDistinctClause() copies such
items into the DISTINCT list.  So an aggregate with a single input can
have several sort keys and several DISTINCT columns.

nodeAgg.c and execExpr.c mistakenly only checked the number of inputs
when deciding if a Datum sort was possible.  That check must also
consider the number of sort keys.

Fix by using the Datum sort only for a single input with a single sort
key.

Also for v16+, fix crash in pre-sorted aggregate code where the uniqslot
was only created when the number of inputs for a DISTINCT aggregate was
above 1.  The uniqslot is required when there are multiple DISTINCT
columns, and an ORDER BY clause may cause more than one of these to exist
when there's only a single input column.

Author: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Reviewed-by: David Rowley <dgrowleyml@gmail.com>
Discussion: https://postgr.es/m/CAJTYsWXMuo5QZSy_az+86mty2XdbDw_7uB3C4FjWpFACvD_rzg@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_14_STABLE

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

Modified Files
--------------
src/backend/executor/execExpr.c          | 10 ++++++----
src/backend/executor/nodeAgg.c           | 22 ++++++++++++++--------
src/test/regress/expected/aggregates.out | 17 +++++++++++++++++
src/test/regress/sql/aggregates.sql      |  9 +++++++++
4 files changed, 46 insertions(+), 12 deletions(-)



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


end of thread, other threads:[~2026-11-06 07:21 UTC | newest]

Thread overview: 7+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-06 07:19 pgsql: Fix crash with single-input aggregates with multiple sort keys David Rowley <drowley@postgresql.org>
2026-11-06 07:20 pgsql: Fix crash with single-input aggregates with multiple sort keys David Rowley <drowley@postgresql.org>
2026-11-06 07:20 pgsql: Fix crash with single-input aggregates with multiple sort keys David Rowley <drowley@postgresql.org>
2026-11-06 07:20 pgsql: Fix crash with single-input aggregates with multiple sort keys David Rowley <drowley@postgresql.org>
2026-11-06 07:20 pgsql: Fix crash with single-input aggregates with multiple sort keys David Rowley <drowley@postgresql.org>
2026-11-06 07:20 pgsql: Fix crash with single-input aggregates with multiple sort keys David Rowley <drowley@postgresql.org>
2026-11-06 07:21 pgsql: Fix crash with single-input aggregates with multiple sort keys 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