aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/src/sgml/ref/create_domain.sgml3
-rw-r--r--src/backend/optimizer/plan/initsplan.c14
2 files changed, 16 insertions, 1 deletions
diff --git a/doc/src/sgml/ref/create_domain.sgml b/doc/src/sgml/ref/create_domain.sgml
index ce555203486..c111285a69c 100644
--- a/doc/src/sgml/ref/create_domain.sgml
+++ b/doc/src/sgml/ref/create_domain.sgml
@@ -283,7 +283,8 @@ CREATE TABLE us_snail_addy (
<para>
The syntax <literal>NOT NULL</literal> in this command is a
<productname>PostgreSQL</productname> extension. (A standard-conforming
- way to write the same would be <literal>CHECK (VALUE IS NOT
+ way to write the same for non-composite data types would be
+ <literal>CHECK (VALUE IS NOT
NULL)</literal>. However, per <xref linkend="sql-createdomain-notes"/>,
such constraints are best avoided in practice anyway.) The
<literal>NULL</literal> <quote>constraint</quote> is a
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);
}