diff options
author | Bruce Momjian <bruce@momjian.us> | 2025-04-07 21:33:42 -0400 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 2025-04-07 21:33:42 -0400 |
commit | 46b4ba533cee9f64a60714d91607e74362abf67f (patch) | |
tree | da20e7e5a7fa827c9488d57ad51fc837f21032a9 /src | |
parent | 039549d70f6aa2daa3714a13752a08fa8ca2fb05 (diff) | |
download | postgresql-46b4ba533cee9f64a60714d91607e74362abf67f.tar.gz postgresql-46b4ba533cee9f64a60714d91607e74362abf67f.zip |
Fix PG 17 [NOT] NULL optimization bug for domains
A PG 17 optimization allowed columns with NOT NULL constraints to skip
table scans for IS NULL queries, and to skip IS NOT NULL checks for IS
NOT NULL queries. This didn't work for domain types, since domain types
don't follow the IS NULL/IS NOT NULL constraint logic. To fix, disable
this optimization for domains for PG 17+.
Reported-by: Jan Behrens
Diagnosed-by: Tom Lane
Discussion: https://postgr.es/m/Z37p0paENWWUarj-@momjian.us
Backpatch-through: 17
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/optimizer/plan/initsplan.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/backend/optimizer/plan/initsplan.c b/src/backend/optimizer/plan/initsplan.c index 1d1aa27d450..01804b085b3 100644 --- a/src/backend/optimizer/plan/initsplan.c +++ b/src/backend/optimizer/plan/initsplan.c @@ -3109,6 +3109,13 @@ restriction_is_always_true(PlannerInfo *root, if (nulltest->nulltesttype != IS_NOT_NULL) return false; + /* + * Empty rows can appear NULL in some contexts and NOT NULL in others, + * so avoid this optimization for row expressions. + */ + if (nulltest->argisrow) + return false; + return expr_is_nonnullable(root, nulltest->arg); } @@ -3167,6 +3174,13 @@ restriction_is_always_false(PlannerInfo *root, if (nulltest->nulltesttype != IS_NULL) return false; + /* + * Empty rows can appear NULL in some contexts and NOT NULL in others, + * so avoid this optimization for row expressions. + */ + if (nulltest->argisrow) + return false; + return expr_is_nonnullable(root, nulltest->arg); } |