Add assertion to verify derived clause has constant RHS
authorAmit Langote <[email protected]>
Fri, 4 Apr 2025 01:40:04 +0000 (10:40 +0900)
committerAmit Langote <[email protected]>
Fri, 4 Apr 2025 01:45:05 +0000 (10:45 +0900)
find_derived_clause_for_ec_member() searches for a previously-derived
clause that equates a non-constant EquivalenceMember to a constant.
It is only called for EquivalenceClasses with ec_has_const set, and
with a non-constant member the EquivalenceMember to search for.

The matched clause is expected to have the non-constant member on the
left-hand side and the constant EquivalenceMember on the right.

Assert that the RHS is indeed a constant, to catch violations of this
structure and enforce assumptions made by
generate_base_implied_equalities_const().

Author: Ashutosh Bapat <[email protected]>
Reviewed-by: Amit Langote <[email protected]>
Discussion: https://postgr.es/m/CAExHW5scMxyFRqOFE6ODmBiW2rnVBEmeEcA-p4W_CyuEikURdA@mail.gmail.com

src/backend/optimizer/path/equivclass.c

index 0f9ecf5ee8b2d80a3bb3aa21dd51e6df5e42dcdd..493a95d26ccf86b0e7ed0b3020abf8d6b729ac4a 100644 (file)
@@ -2664,7 +2664,10 @@ find_derived_clause_for_ec_member(EquivalenceClass *ec,
         * members on the left side of derived clauses.
         */
        if (rinfo->left_em == em)
+       {
+           Assert(rinfo->right_em->em_is_const);
            return rinfo;
+       }
    }
    return NULL;
 }