Re: Problem, partition pruning for prepared statement with IS NULL clause.
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Sergei Glukhov <s.glukhov@postgrespro.ru>
Cc: pgsql-hackers@lists.postgresql.org
Date: 2023-10-11T02:49:38Z
Lists: pgsql-hackers
On Tue, 10 Oct 2023 at 21:31, Sergei Glukhov <s.glukhov@postgrespro.ru> wrote: > create table hp (a int, b text, c int, d int) > partition by hash (a part_test_int4_ops, b part_test_text_ops, c > part_test_int4_ops); > create table hp0 partition of hp for values with (modulus 4, remainder 0); > create table hp3 partition of hp for values with (modulus 4, remainder 3); > create table hp1 partition of hp for values with (modulus 4, remainder 1); > create table hp2 partition of hp for values with (modulus 4, remainder 2); > > > Another crash in the different place even with the fix: > explain select * from hp where a = 1 and b is null and c = 1; Ouch. It looks like 13838740f tried to fix things in this area before and even added a regression test for it. Namely: -- Test that get_steps_using_prefix() handles non-NULL step_nullkeys explain (costs off) select * from hp_prefix_test where a = 1 and b is null and c = 1 and d = 1; I guess that one does not crash because of the "d = 1" clause is in the "start" ListCell in get_steps_using_prefix_recurse(), whereas, with your case start is NULL which is an issue for cur_keyno = ((PartClauseInfo *) lfirst(start))->keyno;. It might have been better if PartClauseInfo could also describe IS NULL quals, but I feel if we do that now then it would require lots of careful surgery in partprune.c to account for that. Probably the fix should be localised to get_steps_using_prefix_recurse() to have it do something like pass the keyno to try and work on rather than trying to get that from the "prefix" list. That way if there's no item in that list for that keyno, we can check in step_nullkeys for the keyno. I'll continue looking. David
Commits
-
Fix runtime partition pruning for HASH partitioned tables
- 2759924f33a6 11.22 landed
- 3cc0c25172b2 12.17 landed
- 890a73ba3ac0 13.13 landed
- d26f33c32436 14.10 landed
- 1e81d3e6e0a0 15.5 landed
- 595db9e9cc41 16.1 landed
- d9e46dfb78ab 17.0 landed
-
Fix incorrect step generation in HASH partition pruning
- 07f261b3172d 11.22 landed
- cd259de50ac5 12.17 landed
- 45c4b2a3aa72 13.13 landed
- cd15bff4814b 14.10 landed
- 916adc7c50bb 15.5 landed
- 6352f1627641 16.1 landed
- f0c409d9c7a6 17.0 landed