pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix hash partition pruning with asymmetric partition sets.
4+ messages / 1 participants
[nested] [flat]

* pgsql: Fix hash partition pruning with asymmetric partition sets.
@ 2021-01-28 18:42 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2021-01-28 18:42 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix hash partition pruning with asymmetric partition sets.

perform_pruning_combine_step() was not taught about the number of
partition indexes used in hash partitioning; more embarrassingly,
get_matching_hash_bounds() also had it wrong.  These errors are masked
in the common case where all the partitions have the same modulus
and no partition is missing.  However, with missing or unequal-size
partitions, we could erroneously prune some partitions that need
to be scanned, leading to silently wrong query answers.

While a minimal-footprint fix for this could be to export
get_partition_bound_num_indexes and make the incorrect functions use it,
I'm of the opinion that that function should never have existed in the
first place.  It's not reasonable data structure design that
PartitionBoundInfoData lacks any explicit record of the length of
its indexes[] array.  Perhaps that was all right when it could always
be assumed equal to ndatums, but something should have been done about
it as soon as that stopped being true.  Putting in an explicit
"nindexes" field makes both partition_bounds_equal() and
partition_bounds_copy() simpler, safer, and faster than before,
and removes explicit knowledge of the number-of-partition-indexes
rules from some other places too.

This change also makes get_hash_partition_greatest_modulus obsolete.
I left that in place in case any external code uses it, but no core
code does anymore.

Per bug #16840 from Michał Albrycht.  Back-patch to v11 where the
hash partitioning code came in.  (In the back branches, add the new
field at the end of PartitionBoundInfoData to minimize ABI risks.)

Discussion: https://postgr.es/m/16840-571a22976f829ad4@postgresql.org

Branch
------
master

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

Modified Files
--------------
src/backend/executor/execPartition.c          |   4 +-
src/backend/partitioning/partbounds.c         | 115 +++++++-------------------
src/backend/partitioning/partprune.c          |  30 +++----
src/include/partitioning/partbounds.h         |  29 ++++---
src/test/regress/expected/partition_prune.out |  60 ++++++++++----
src/test/regress/sql/partition_prune.sql      |  27 ++++--
6 files changed, 124 insertions(+), 141 deletions(-)



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

* pgsql: Fix hash partition pruning with asymmetric partition sets.
@ 2021-01-28 18:42 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2021-01-28 18:42 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix hash partition pruning with asymmetric partition sets.

perform_pruning_combine_step() was not taught about the number of
partition indexes used in hash partitioning; more embarrassingly,
get_matching_hash_bounds() also had it wrong.  These errors are masked
in the common case where all the partitions have the same modulus
and no partition is missing.  However, with missing or unequal-size
partitions, we could erroneously prune some partitions that need
to be scanned, leading to silently wrong query answers.

While a minimal-footprint fix for this could be to export
get_partition_bound_num_indexes and make the incorrect functions use it,
I'm of the opinion that that function should never have existed in the
first place.  It's not reasonable data structure design that
PartitionBoundInfoData lacks any explicit record of the length of
its indexes[] array.  Perhaps that was all right when it could always
be assumed equal to ndatums, but something should have been done about
it as soon as that stopped being true.  Putting in an explicit
"nindexes" field makes both partition_bounds_equal() and
partition_bounds_copy() simpler, safer, and faster than before,
and removes explicit knowledge of the number-of-partition-indexes
rules from some other places too.

This change also makes get_hash_partition_greatest_modulus obsolete.
I left that in place in case any external code uses it, but no core
code does anymore.

Per bug #16840 from Michał Albrycht.  Back-patch to v11 where the
hash partitioning code came in.  (In the back branches, add the new
field at the end of PartitionBoundInfoData to minimize ABI risks.)

Discussion: https://postgr.es/m/16840-571a22976f829ad4@postgresql.org

Branch
------
REL_13_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/7f1921cb922879796f7946273db304922a439a58

Modified Files
--------------
src/backend/executor/execPartition.c          |   4 +-
src/backend/partitioning/partbounds.c         | 115 +++++++-------------------
src/backend/partitioning/partprune.c          |  30 +++----
src/include/partitioning/partbounds.h         |  29 ++++---
src/test/regress/expected/partition_prune.out |  60 ++++++++++----
src/test/regress/sql/partition_prune.sql      |  27 ++++--
6 files changed, 124 insertions(+), 141 deletions(-)



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

* pgsql: Fix hash partition pruning with asymmetric partition sets.
@ 2021-01-28 18:42 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2021-01-28 18:42 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix hash partition pruning with asymmetric partition sets.

perform_pruning_combine_step() was not taught about the number of
partition indexes used in hash partitioning; more embarrassingly,
get_matching_hash_bounds() also had it wrong.  These errors are masked
in the common case where all the partitions have the same modulus
and no partition is missing.  However, with missing or unequal-size
partitions, we could erroneously prune some partitions that need
to be scanned, leading to silently wrong query answers.

While a minimal-footprint fix for this could be to export
get_partition_bound_num_indexes and make the incorrect functions use it,
I'm of the opinion that that function should never have existed in the
first place.  It's not reasonable data structure design that
PartitionBoundInfoData lacks any explicit record of the length of
its indexes[] array.  Perhaps that was all right when it could always
be assumed equal to ndatums, but something should have been done about
it as soon as that stopped being true.  Putting in an explicit
"nindexes" field makes both partition_bounds_equal() and
partition_bounds_copy() simpler, safer, and faster than before,
and removes explicit knowledge of the number-of-partition-indexes
rules from some other places too.

This change also makes get_hash_partition_greatest_modulus obsolete.
I left that in place in case any external code uses it, but no core
code does anymore.

Per bug #16840 from Michał Albrycht.  Back-patch to v11 where the
hash partitioning code came in.  (In the back branches, add the new
field at the end of PartitionBoundInfoData to minimize ABI risks.)

Discussion: https://postgr.es/m/16840-571a22976f829ad4@postgresql.org

Branch
------
REL_12_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/7c53a80675dffd63250cb3fbb9495d4552c68313

Modified Files
--------------
src/backend/executor/execPartition.c          |   4 +-
src/backend/partitioning/partbounds.c         | 114 +++++++-------------------
src/backend/partitioning/partprune.c          |  30 +++----
src/include/partitioning/partbounds.h         |  29 ++++---
src/test/regress/expected/partition_prune.out |  60 ++++++++++----
src/test/regress/sql/partition_prune.sql      |  27 ++++--
6 files changed, 123 insertions(+), 141 deletions(-)



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

* pgsql: Fix hash partition pruning with asymmetric partition sets.
@ 2021-01-28 18:42 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 4+ messages in thread

From: Tom Lane @ 2021-01-28 18:42 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix hash partition pruning with asymmetric partition sets.

perform_pruning_combine_step() was not taught about the number of
partition indexes used in hash partitioning; more embarrassingly,
get_matching_hash_bounds() also had it wrong.  These errors are masked
in the common case where all the partitions have the same modulus
and no partition is missing.  However, with missing or unequal-size
partitions, we could erroneously prune some partitions that need
to be scanned, leading to silently wrong query answers.

While a minimal-footprint fix for this could be to export
get_partition_bound_num_indexes and make the incorrect functions use it,
I'm of the opinion that that function should never have existed in the
first place.  It's not reasonable data structure design that
PartitionBoundInfoData lacks any explicit record of the length of
its indexes[] array.  Perhaps that was all right when it could always
be assumed equal to ndatums, but something should have been done about
it as soon as that stopped being true.  Putting in an explicit
"nindexes" field makes both partition_bounds_equal() and
partition_bounds_copy() simpler, safer, and faster than before,
and removes explicit knowledge of the number-of-partition-indexes
rules from some other places too.

This change also makes get_hash_partition_greatest_modulus obsolete.
I left that in place in case any external code uses it, but no core
code does anymore.

Per bug #16840 from Michał Albrycht.  Back-patch to v11 where the
hash partitioning code came in.  (In the back branches, add the new
field at the end of PartitionBoundInfoData to minimize ABI risks.)

Discussion: https://postgr.es/m/16840-571a22976f829ad4@postgresql.org

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/6f94531b0cf83b1401aca31c71412e633c566a63

Modified Files
--------------
src/backend/executor/execPartition.c          |   4 +-
src/backend/partitioning/partbounds.c         | 109 ++++++--------------------
src/backend/partitioning/partprune.c          |  30 +++----
src/backend/utils/cache/partcache.c           |   3 +
src/include/partitioning/partbounds.h         |  29 ++++---
src/test/regress/expected/partition_prune.out |  62 +++++++++++----
src/test/regress/sql/partition_prune.sql      |  27 +++++--
7 files changed, 124 insertions(+), 140 deletions(-)



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


end of thread, other threads:[~2021-01-28 18:42 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-01-28 18:42 pgsql: Fix hash partition pruning with asymmetric partition sets. Tom Lane <tgl@sss.pgh.pa.us>
2021-01-28 18:42 pgsql: Fix hash partition pruning with asymmetric partition sets. Tom Lane <tgl@sss.pgh.pa.us>
2021-01-28 18:42 pgsql: Fix hash partition pruning with asymmetric partition sets. Tom Lane <tgl@sss.pgh.pa.us>
2021-01-28 18:42 pgsql: Fix hash partition pruning with asymmetric partition sets. Tom Lane <tgl@sss.pgh.pa.us>

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