pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pgsql: Fix choose_best_statistics to check clauses individually
2+ messages / 1 participants
[nested] [flat]

* pgsql: Fix choose_best_statistics to check clauses individually
@ 2019-11-28 21:29  Tomas Vondra <tomas.vondra@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Tomas Vondra @ 2019-11-28 21:29 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix choose_best_statistics to check clauses individually

When picking the best extended statistics object for a list of clauses,
it's not enough to look at attnums extracted from the clause list as a
whole. Consider for example this query with OR clauses:

   SELECT * FROM t WHERE (t.a = 1) OR (t.b = 1) OR (t.c = 1)

with a statistics defined on columns (a,b). Relying on attnums extracted
from the whole OR clause, we'd consider the statistics usable. That does
not work, as we see the conditions as a single OR-clause, referencing an
attribute not covered by the statistic, leading to empty list of clauses
to be estimated using the statistics and an assert failure.

This changes choose_best_statistics to check which clauses are actually
covered, and only using attributes from the fully covered ones. For the
previous example this means the statistics object will not be considered
as compatible with the OR-clause.

Backpatch to 12, where MCVs were introduced. The issue does not affect
older versions because functional dependencies don't handle OR clauses.

Author: Tomas Vondra
Reviewed-by: Dean Rasheed
Reported-By: Manuel Rigger
Discussion: https://postgr.es/m/CA+u7OA7H5rcE2=8f263w4NZD6ipO_XOrYB816nuLXbmSTH9pQQ@mail.gmail.com
Backpatch-through: 12

Branch
------
REL_12_STABLE

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

Modified Files
--------------
src/backend/statistics/dependencies.c   | 26 ++++++++++++---------
src/backend/statistics/extended_stats.c | 40 ++++++++++++++++++++++++---------
src/include/statistics/statistics.h     |  5 +++--
src/test/regress/expected/stats_ext.out | 25 +++++++++++++++++++++
src/test/regress/sql/stats_ext.sql      |  9 ++++++++
5 files changed, 81 insertions(+), 24 deletions(-)



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

* pgsql: Fix choose_best_statistics to check clauses individually
@ 2019-11-28 21:29  Tomas Vondra <tomas.vondra@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Tomas Vondra @ 2019-11-28 21:29 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix choose_best_statistics to check clauses individually

When picking the best extended statistics object for a list of clauses,
it's not enough to look at attnums extracted from the clause list as a
whole. Consider for example this query with OR clauses:

   SELECT * FROM t WHERE (t.a = 1) OR (t.b = 1) OR (t.c = 1)

with a statistics defined on columns (a,b). Relying on attnums extracted
from the whole OR clause, we'd consider the statistics usable. That does
not work, as we see the conditions as a single OR-clause, referencing an
attribute not covered by the statistic, leading to empty list of clauses
to be estimated using the statistics and an assert failure.

This changes choose_best_statistics to check which clauses are actually
covered, and only using attributes from the fully covered ones. For the
previous example this means the statistics object will not be considered
as compatible with the OR-clause.

Backpatch to 12, where MCVs were introduced. The issue does not affect
older versions because functional dependencies don't handle OR clauses.

Author: Tomas Vondra
Reviewed-by: Dean Rasheed
Reported-By: Manuel Rigger
Discussion: https://postgr.es/m/CA+u7OA7H5rcE2=8f263w4NZD6ipO_XOrYB816nuLXbmSTH9pQQ@mail.gmail.com
Backpatch-through: 12

Branch
------
master

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

Modified Files
--------------
src/backend/statistics/dependencies.c   | 26 ++++++++++++---------
src/backend/statistics/extended_stats.c | 40 ++++++++++++++++++++++++---------
src/include/statistics/statistics.h     |  5 +++--
src/test/regress/expected/stats_ext.out | 25 +++++++++++++++++++++
src/test/regress/sql/stats_ext.sql      |  9 ++++++++
5 files changed, 81 insertions(+), 24 deletions(-)



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


end of thread, other threads:[~2019-11-28 21:29 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-11-28 21:29 pgsql: Fix choose_best_statistics to check clauses individually Tomas Vondra <tomas.vondra@postgresql.org>
2019-11-28 21:29 pgsql: Fix choose_best_statistics to check clauses individually Tomas Vondra <tomas.vondra@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