pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix partition pruning to treat stable comparison operators prope
2+ messages / 1 participants
[nested] [flat]

* pgsql: Fix partition pruning to treat stable comparison operators prope
@ 2019-05-16 15:58 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2019-05-16 15:58 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix partition pruning to treat stable comparison operators properly.

Cross-type comparison operators in a btree or hash opclass might be
only stable not immutable (this is true of timestamp vs. timestamptz
for example).  partprune.c ignored this possibility and would perform
plan-time pruning with them anyway, possibly leading to wrong answers
if the environment changed between planning and execution.

To fix, teach gen_partprune_steps() to do things differently when
creating plan-time pruning steps vs. run-time pruning steps.
analyze_partkey_exprs() also needs an extra check, which is rather
annoying but now is not the time to restructure things enough to
avoid that.

While at it, simplify the logic for the plan-time case a little
by insisting that the comparison value be a Const and nothing else.
This relies on the assumption that eval_const_expressions will have
reduced any immutable expression to a Const; which is not quite
100% true, but certainly any case that comes up often enough to be
interesting should have simplification logic there.

Also improve a bunch of inadequate/obsolete/wrong comments.

Per discussion of a report from Alan Jackson (though this fixes only one
aspect of that problem).  Back-patch to v11 where this code came in.

David Rowley, with some further hacking by me

Discussion: https://postgr.es/m/FAD28A83-AC73-489E-A058-2681FA31D648@tvsquared.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/4b1fcb43d070ba8b34ea01d5a657630d76e4b33f

Modified Files
--------------
src/backend/partitioning/partprune.c          | 203 +++++++++++++++++++-------
src/test/regress/expected/partition_prune.out |  87 +++++++++++
src/test/regress/sql/partition_prune.sql      |  38 +++++
3 files changed, 278 insertions(+), 50 deletions(-)



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

* pgsql: Fix partition pruning to treat stable comparison operators prope
@ 2019-05-16 15:58 Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2019-05-16 15:58 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix partition pruning to treat stable comparison operators properly.

Cross-type comparison operators in a btree or hash opclass might be
only stable not immutable (this is true of timestamp vs. timestamptz
for example).  partprune.c ignored this possibility and would perform
plan-time pruning with them anyway, possibly leading to wrong answers
if the environment changed between planning and execution.

To fix, teach gen_partprune_steps() to do things differently when
creating plan-time pruning steps vs. run-time pruning steps.
analyze_partkey_exprs() also needs an extra check, which is rather
annoying but now is not the time to restructure things enough to
avoid that.

While at it, simplify the logic for the plan-time case a little
by insisting that the comparison value be a Const and nothing else.
This relies on the assumption that eval_const_expressions will have
reduced any immutable expression to a Const; which is not quite
100% true, but certainly any case that comes up often enough to be
interesting should have simplification logic there.

Also improve a bunch of inadequate/obsolete/wrong comments.

Per discussion of a report from Alan Jackson (though this fixes only one
aspect of that problem).  Back-patch to v11 where this code came in.

David Rowley, with some further hacking by me

Discussion: https://postgr.es/m/FAD28A83-AC73-489E-A058-2681FA31D648@tvsquared.com

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/10c5cc4b4f88d249751e27034a8dd59ea903a698

Modified Files
--------------
src/backend/partitioning/partprune.c          | 191 ++++++++++++++++++++------
src/test/regress/expected/partition_prune.out |  88 ++++++++++++
src/test/regress/sql/partition_prune.sql      |  38 +++++
3 files changed, 272 insertions(+), 45 deletions(-)



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


end of thread, other threads:[~2019-05-16 15:58 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-05-16 15:58 pgsql: Fix partition pruning to treat stable comparison operators prope Tom Lane <tgl@sss.pgh.pa.us>
2019-05-16 15:58 pgsql: Fix partition pruning to treat stable comparison operators prope 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