@@ -1511,6 +1511,31 @@ find_nonnullable_rels_walker(Node *node, bool top_level)
1511
1511
expr -> booltesttype == IS_NOT_UNKNOWN ))
1512
1512
result = find_nonnullable_rels_walker ((Node * ) expr -> arg , false);
1513
1513
}
1514
+ else if (IsA (node , SubPlan ))
1515
+ {
1516
+ SubPlan * splan = (SubPlan * ) node ;
1517
+
1518
+ /*
1519
+ * For some types of SubPlan, we can infer strictness from Vars in the
1520
+ * testexpr (the LHS of the original SubLink).
1521
+ *
1522
+ * For ANY_SUBLINK, if the subquery produces zero rows, the result is
1523
+ * always FALSE. If the subquery produces more than one row, the
1524
+ * per-row results of the testexpr are combined using OR semantics.
1525
+ * Hence ANY_SUBLINK can be strict only at top level, but there it's
1526
+ * as strict as the testexpr is.
1527
+ *
1528
+ * For ROWCOMPARE_SUBLINK, if the subquery produces zero rows, the
1529
+ * result is always NULL. Otherwise, the result is as strict as the
1530
+ * testexpr is. So we can check regardless of top_level.
1531
+ *
1532
+ * We can't prove anything for other sublink types (in particular,
1533
+ * note that ALL_SUBLINK will return TRUE if the subquery is empty).
1534
+ */
1535
+ if ((top_level && splan -> subLinkType == ANY_SUBLINK ) ||
1536
+ splan -> subLinkType == ROWCOMPARE_SUBLINK )
1537
+ result = find_nonnullable_rels_walker (splan -> testexpr , top_level );
1538
+ }
1514
1539
else if (IsA (node , PlaceHolderVar ))
1515
1540
{
1516
1541
PlaceHolderVar * phv = (PlaceHolderVar * ) node ;
@@ -1736,6 +1761,15 @@ find_nonnullable_vars_walker(Node *node, bool top_level)
1736
1761
expr -> booltesttype == IS_NOT_UNKNOWN ))
1737
1762
result = find_nonnullable_vars_walker ((Node * ) expr -> arg , false);
1738
1763
}
1764
+ else if (IsA (node , SubPlan ))
1765
+ {
1766
+ SubPlan * splan = (SubPlan * ) node ;
1767
+
1768
+ /* See analysis in find_nonnullable_rels_walker */
1769
+ if ((top_level && splan -> subLinkType == ANY_SUBLINK ) ||
1770
+ splan -> subLinkType == ROWCOMPARE_SUBLINK )
1771
+ result = find_nonnullable_vars_walker (splan -> testexpr , top_level );
1772
+ }
1739
1773
else if (IsA (node , PlaceHolderVar ))
1740
1774
{
1741
1775
PlaceHolderVar * phv = (PlaceHolderVar * ) node ;
0 commit comments