agora inbox for [email protected]
help / color / mirror / Atom feedFrom: Tomas Vondra <[email protected]>
Subject: [PATCH 3/5] Fix handling of NULLs in MCV items and constants
Date: Mon, 15 Jul 2019 02:00:31 +0200
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.
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
---
src/backend/statistics/mcv.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/src/backend/statistics/mcv.c b/src/backend/statistics/mcv.c
index 865981bbb4..77daa647e2 100644
--- a/src/backend/statistics/mcv.c
+++ b/src/backend/statistics/mcv.c
@@ -1593,12 +1593,18 @@ mcv_get_match_bitmap(PlannerInfo *root, List *clauses,
MCVItem *item = &mcvlist->items[i];
/*
- * For AND-lists, we can also mark NULL items as 'no
- * match' (and then skip them). For OR-lists this is not
- * possible.
+ * When the MCV item or the Const value is NULL we can treat
+ * this as a mismatch. We must not call the operator proc
+ * because of strictness.
*/
- if ((!is_or) && item->isnull[idx])
- matches[i] = false;
+ if (item->isnull[idx] || cst->constisnull)
+ {
+ /* we only care about AND, because OR can't change */
+ if (!is_or)
+ matches[i] = false;
+
+ continue;
+ }
/* skip MCV items that were already ruled out */
if ((!is_or) && (matches[i] == false))
--
2.20.1
--ztxiowpcs6gwvnvh
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment;
filename="0004-Refactor-simplify-evaluation-of-MCV-bitmap.patch"
view thread (180+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected]
Subject: Re: [PATCH 3/5] Fix handling of NULLs in MCV items and constants
In-Reply-To: <no-message-id-1882046@localhost>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox