From 8046a7dc0782a6ce95e808853a839ad529d76743 Mon Sep 17 00:00:00 2001 From: Antonin Houska Date: Wed, 8 Apr 2020 15:03:20 +0200 Subject: [PATCH 3/4] Return early from ri_NullCheck() if possible. --- src/backend/utils/adt/ri_triggers.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/backend/utils/adt/ri_triggers.c b/src/backend/utils/adt/ri_triggers.c index 3bedb75846..93e46ddf7a 100644 --- a/src/backend/utils/adt/ri_triggers.c +++ b/src/backend/utils/adt/ri_triggers.c @@ -2541,6 +2541,13 @@ ri_NullCheck(TupleDesc tupDesc, nonenull = false; else allnull = false; + + /* + * If seen both NULL and non-NULL, the next attributes cannot change + * the result. + */ + if (!nonenull && !allnull) + return RI_KEYS_SOME_NULL; } if (allnull) @@ -2549,7 +2556,8 @@ ri_NullCheck(TupleDesc tupDesc, if (nonenull) return RI_KEYS_NONE_NULL; - return RI_KEYS_SOME_NULL; + /* Should not happen. */ + Assert(false); } -- 2.20.1