pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix handling of NULLs in MCV items and constants 2+ messages / 1 participants [nested] [flat]
* pgsql: Fix handling of NULLs in MCV items and constants @ 2019-07-18 09:30 Tomas Vondra <tomas.vondra@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: Tomas Vondra @ 2019-07-18 09:30 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix handling of NULLs in MCV items and constants There were two issues in how the extended statistics handled NULL values in opclauses. Firstly, the code was oblivious to the possibility that Const may be NULL (constisnull=true) in which case the constvalue is undefined. We need to treat this as a mismatch, and not call the proc. Secondly, the MCV item itself may contain NULL values too - the code already did check that, and updated the match bitmap accordingly, but failed to ensure we won't call the operator procedure anyway. It did work for AND-clauses, because in that case false in the bitmap stops evaluation of further clauses. But for OR-clauses ir was not easy to get incorrect estimates or even trigger a crash. This fixes both issues by extending the existing check so that it looks at constisnull too, and making sure it skips calling the procedure. Discussion: https://postgr.es/m/8736jdhbhc.fsf%40ansel.ydns.eu Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/e4deae7396f2a5576c0c8289e2bfc005ed3d6989 Modified Files -------------- src/backend/statistics/mcv.c | 16 +++++++++++----- src/test/regress/expected/stats_ext.out | 26 ++++++++++++++++++++++++++ src/test/regress/sql/stats_ext.sql | 23 +++++++++++++++++++++++ 3 files changed, 60 insertions(+), 5 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
* pgsql: Fix handling of NULLs in MCV items and constants @ 2019-07-18 09:30 Tomas Vondra <tomas.vondra@postgresql.org> 0 siblings, 0 replies; 2+ messages in thread From: Tomas Vondra @ 2019-07-18 09:30 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org Fix handling of NULLs in MCV items and constants There were two issues in how the extended statistics handled NULL values in opclauses. Firstly, the code was oblivious to the possibility that Const may be NULL (constisnull=true) in which case the constvalue is undefined. We need to treat this as a mismatch, and not call the proc. Secondly, the MCV item itself may contain NULL values too - the code already did check that, and updated the match bitmap accordingly, but failed to ensure we won't call the operator procedure anyway. It did work for AND-clauses, because in that case false in the bitmap stops evaluation of further clauses. But for OR-clauses ir was not easy to get incorrect estimates or even trigger a crash. This fixes both issues by extending the existing check so that it looks at constisnull too, and making sure it skips calling the procedure. Discussion: https://postgr.es/m/8736jdhbhc.fsf%40ansel.ydns.eu Branch ------ REL_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/1c2acc32dc6cb15c6ea038a954af9a4db8d01f08 Modified Files -------------- src/backend/statistics/mcv.c | 16 +++++++++++----- src/test/regress/expected/stats_ext.out | 26 ++++++++++++++++++++++++++ src/test/regress/sql/stats_ext.sql | 23 +++++++++++++++++++++++ 3 files changed, 60 insertions(+), 5 deletions(-) ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2019-07-18 09:30 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2019-07-18 09:30 pgsql: Fix handling of NULLs in MCV items and constants Tomas Vondra <tomas.vondra@postgresql.org> 2019-07-18 09:30 pgsql: Fix handling of NULLs in MCV items and constants 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