Re: Reduce planning time for large NOT IN lists containing NULL
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Ilia Evdokimov <ilya.evdokimov@tantorlabs.com>
Cc: Zsolt Parragi <zsolt.parragi@percona.com>,
David Geier <geidav.pg@gmail.com>, PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>
Date: 2026-03-19T04:28:11Z
Lists: pgsql-hackers
On Thu, 19 Mar 2026 at 03:26, Ilia Evdokimov <ilya.evdokimov@tantorlabs.com> wrote: > After the new test was committed, I realized that v8 tests relies on selectivity calculation, which are not guaranteed to remain stable over time and way vary depending on planner heuristics or platform differences. Therefore, it seems better to remove tests from v8. > > Instead, we can test the invariant behavior: when NULL is present in a <> ALL clause, the selectivity is always 0.0. > > The v9-patch adds three test cases: a degenerate case with only NULL, NULL combined with constants, NULL combined with both constants and non-constant expression. > > Thoughts? I've now pushed the main patch. I did end up removing the first test of the v9 tests since it was exercising the same code path as the 2nd test. I also didn't see the need to execute the query, so I changed it to run EXPLAIN without ANALYZE. For the main patch, I only adjusted the comments a little. I wanted to make reference to var_eq_const() as the short-circuit really is trying to follow what that function would have done if the short-circuit path hadn't been taken. I also added comments in the tests to explain what we are expecting to see. I am probably in a minority of people who do this. I find it's important to understand that when it comes to updating the expected results of existing tests. I expect we have plenty of tests that no longer test what the original test was meant to test as a result of people not doing this. David
Commits
-
Short-circuit row estimation in NOT IN containing NULL consts
- c95cd2991f1e 19 (unreleased) landed
-
Move planner row-estimation tests to new planner_est.sql
- 374a6394c6ae 19 (unreleased) landed