MCPcopy Create free account
hub / github.com/apache/cloudberry / process_equivalence

Function process_equivalence

src/backend/optimizer/path/equivclass.c:118–469  ·  view source on GitHub ↗

* process_equivalence * The given clause has a mergejoinable operator and can be applied without * any delay by an outer join, so its two sides can be considered equal * anywhere they are both computable; moreover that equality can be * extended transitively. Record this knowledge in the EquivalenceClass * data structure, if applicable. Returns true if successful, false if not *

Source from the content-addressed store, hash-verified

116 * memory context.
117 */
118bool
119process_equivalence(PlannerInfo *root,
120 RestrictInfo **p_restrictinfo,
121 bool below_outer_join)
122{
123 RestrictInfo *restrictinfo = *p_restrictinfo;
124 Expr *clause = restrictinfo->clause;
125 Oid opno,
126 collation,
127 item1_type,
128 item2_type;
129 Expr *item1;
130 Expr *item2;
131 Relids item1_relids,
132 item2_relids,
133 item1_nullable_relids,
134 item2_nullable_relids;
135 List *opfamilies;
136 EquivalenceClass *ec1,
137 *ec2;
138 EquivalenceMember *em1,
139 *em2;
140 ListCell *lc1;
141 int ec2_idx;
142
143 /* Should not already be marked as having generated an eclass */
144 Assert(restrictinfo->left_ec == NULL);
145 Assert(restrictinfo->right_ec == NULL);
146
147 /* Reject if it is potentially postponable by security considerations */
148 if (restrictinfo->security_level > 0 && !restrictinfo->leakproof)
149 return false;
150
151 /* Extract info from given clause */
152 Assert(is_opclause(clause));
153 opno = ((OpExpr *) clause)->opno;
154 collation = ((OpExpr *) clause)->inputcollid;
155 item1 = (Expr *) get_leftop(clause);
156 item2 = (Expr *) get_rightop(clause);
157 item1_relids = restrictinfo->left_relids;
158 item2_relids = restrictinfo->right_relids;
159
160 /*
161 * Ensure both input expressions expose the desired collation (their types
162 * should be OK already); see comments for canonicalize_ec_expression.
163 */
164 item1 = canonicalize_ec_expression(item1,
165 exprType((Node *) item1),
166 collation);
167 item2 = canonicalize_ec_expression(item2,
168 exprType((Node *) item2),
169 collation);
170
171 /*
172 * Clauses of the form X=X cannot be translated into EquivalenceClasses.
173 * We'd either end up with a single-entry EC, losing the knowledge that
174 * the clause was present at all, or else make an EC with duplicate
175 * entries, causing other issues.

Callers 3

distribute_qual_to_relsFunction · 0.85

Calls 15

is_opclauseFunction · 0.85
get_leftopFunction · 0.85
get_rightopFunction · 0.85
exprTypeFunction · 0.85
equalFunction · 0.85
set_opfuncidFunction · 0.85
func_strictFunction · 0.85
make_restrictinfoFunction · 0.85
bms_is_emptyFunction · 0.85
bms_intersectFunction · 0.85

Tested by

no test coverage detected