--- a/src/backend/optimizer/util/clauses.c
+++ b/src/backend/optimizer/util/clauses.c
@@ -3308,7 +3308,13 @@ eval_const_expressions_mutator(Node *node,
                                                newntest = makeNode(NullTest);
                                                newntest->arg = (Expr *) relem;
                                                newntest->nulltesttype = ntest->nulltesttype;
-                                               newntest->argisrow = type_is_rowtype(exprType(relem));
+                                               /*
+                                                * We must unconditionally set argisrow false here.
+                                                * Otherwise, we'd be treating a nested composite
+                                                * structure as though it were at top level, which
+                                                * would change the semantics of the test.
+                                                */
+                                               newntest->argisrow = false;
                                                newntest->location = ntest->location;
                                                newargs = lappend(newargs, newntest);
                                        }
