From 1640c0d05269c3368fb41fcffc66e38630ff522d Mon Sep 17 00:00:00 2001 From: "tender.wang" Date: Wed, 11 Oct 2023 11:32:04 +0800 Subject: [PATCH] Fix null partition key pruning for hash parittion table. --- src/backend/partitioning/partprune.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/backend/partitioning/partprune.c b/src/backend/partitioning/partprune.c index 7179b22a05..c2a388d454 100644 --- a/src/backend/partitioning/partprune.c +++ b/src/backend/partitioning/partprune.c @@ -2438,6 +2438,7 @@ get_steps_using_prefix_recurse(GeneratePruningStepsContext *context, List *result = NIL; ListCell *lc; int cur_keyno; + int prefix_lastkeyno; /* Actually, recursion would be limited by PARTITION_MAX_KEYS. */ check_stack_depth(); @@ -2445,7 +2446,11 @@ get_steps_using_prefix_recurse(GeneratePruningStepsContext *context, /* Check if we need to recurse. */ Assert(start != NULL); cur_keyno = ((PartClauseInfo *) lfirst(start))->keyno; - if (cur_keyno < step_lastkeyno - 1) + /* Note that for hash partitioning, if partition key is IS NULL clause, + * that partition key will not present in prefix List. + */ + prefix_lastkeyno = ((PartClauseInfo *) llast(prefix))->keyno; + if (cur_keyno < step_lastkeyno - 1 && cur_keyno != prefix_lastkeyno) { PartClauseInfo *pc; ListCell *next_start; -- 2.25.1