@@ -4142,47 +4142,26 @@ ec_member_matches_indexcol(PlannerInfo *root, RelOptInfo *rel,
4142
4142
* a set of equality conditions, because the conditions constrain all
4143
4143
* columns of some unique index.
4144
4144
*
4145
- * The conditions can be represented in either or both of two ways:
4146
- * 1. A list of RestrictInfo nodes, where the caller has already determined
4147
- * that each condition is a mergejoinable equality with an expression in
4148
- * this relation on one side, and an expression not involving this relation
4149
- * on the other. The transient outer_is_left flag is used to identify which
4150
- * side we should look at: left side if outer_is_left is false, right side
4151
- * if it is true.
4152
- * 2. A list of expressions in this relation, and a corresponding list of
4153
- * equality operators. The caller must have already checked that the operators
4154
- * represent equality. (Note: the operators could be cross-type; the
4155
- * expressions should correspond to their RHS inputs.)
4145
+ * The conditions are provided as a list of RestrictInfo nodes, where the
4146
+ * caller has already determined that each condition is a mergejoinable
4147
+ * equality with an expression in this relation on one side, and an
4148
+ * expression not involving this relation on the other. The transient
4149
+ * outer_is_left flag is used to identify which side we should look at:
4150
+ * left side if outer_is_left is false, right side if it is true.
4156
4151
*
4157
4152
* The caller need only supply equality conditions arising from joins;
4158
4153
* this routine automatically adds in any usable baserestrictinfo clauses.
4159
4154
* (Note that the passed-in restrictlist will be destructively modified!)
4155
+ *
4156
+ * If extra_clauses isn't NULL, return baserestrictinfo clauses which were used
4157
+ * to derive uniqueness.
4160
4158
*/
4161
4159
bool
4162
4160
relation_has_unique_index_for (PlannerInfo * root , RelOptInfo * rel ,
4163
- List * restrictlist ,
4164
- List * exprlist , List * oprlist )
4165
- {
4166
- return relation_has_unique_index_ext (root , rel , restrictlist ,
4167
- exprlist , oprlist , NULL );
4168
- }
4169
-
4170
- /*
4171
- * relation_has_unique_index_ext
4172
- * Same as relation_has_unique_index_for(), but supports extra_clauses
4173
- * parameter. If extra_clauses isn't NULL, return baserestrictinfo clauses
4174
- * which were used to derive uniqueness.
4175
- */
4176
- bool
4177
- relation_has_unique_index_ext (PlannerInfo * root , RelOptInfo * rel ,
4178
- List * restrictlist ,
4179
- List * exprlist , List * oprlist ,
4180
- List * * extra_clauses )
4161
+ List * restrictlist , List * * extra_clauses )
4181
4162
{
4182
4163
ListCell * ic ;
4183
4164
4184
- Assert (list_length (exprlist ) == list_length (oprlist ));
4185
-
4186
4165
/* Short-circuit if no indexes... */
4187
4166
if (rel -> indexlist == NIL )
4188
4167
return false;
@@ -4225,7 +4204,7 @@ relation_has_unique_index_ext(PlannerInfo *root, RelOptInfo *rel,
4225
4204
}
4226
4205
4227
4206
/* Short-circuit the easy case */
4228
- if (restrictlist == NIL && exprlist == NIL )
4207
+ if (restrictlist == NIL )
4229
4208
return false;
4230
4209
4231
4210
/* Examine each index of the relation ... */
@@ -4247,14 +4226,12 @@ relation_has_unique_index_ext(PlannerInfo *root, RelOptInfo *rel,
4247
4226
continue ;
4248
4227
4249
4228
/*
4250
- * Try to find each index column in the lists of conditions. This is
4229
+ * Try to find each index column in the list of conditions. This is
4251
4230
* O(N^2) or worse, but we expect all the lists to be short.
4252
4231
*/
4253
4232
for (c = 0 ; c < ind -> nkeycolumns ; c ++ )
4254
4233
{
4255
- bool matched = false;
4256
4234
ListCell * lc ;
4257
- ListCell * lc2 ;
4258
4235
4259
4236
foreach (lc , restrictlist )
4260
4237
{
@@ -4284,8 +4261,6 @@ relation_has_unique_index_ext(PlannerInfo *root, RelOptInfo *rel,
4284
4261
4285
4262
if (match_index_to_operand (rexpr , c , ind ))
4286
4263
{
4287
- matched = true; /* column is unique */
4288
-
4289
4264
if (bms_membership (rinfo -> clause_relids ) == BMS_SINGLETON )
4290
4265
{
4291
4266
MemoryContext oldMemCtx =
@@ -4303,43 +4278,11 @@ relation_has_unique_index_ext(PlannerInfo *root, RelOptInfo *rel,
4303
4278
MemoryContextSwitchTo (oldMemCtx );
4304
4279
}
4305
4280
4306
- break ;
4281
+ break ; /* found a match; column is unique */
4307
4282
}
4308
4283
}
4309
4284
4310
- if (matched )
4311
- continue ;
4312
-
4313
- forboth (lc , exprlist , lc2 , oprlist )
4314
- {
4315
- Node * expr = (Node * ) lfirst (lc );
4316
- Oid opr = lfirst_oid (lc2 );
4317
-
4318
- /* See if the expression matches the index key */
4319
- if (!match_index_to_operand (expr , c , ind ))
4320
- continue ;
4321
-
4322
- /*
4323
- * The equality operator must be a member of the index
4324
- * opfamily, else it is not asserting the right kind of
4325
- * equality behavior for this index. We assume the caller
4326
- * determined it is an equality operator, so we don't need to
4327
- * check any more tightly than this.
4328
- */
4329
- if (!op_in_opfamily (opr , ind -> opfamily [c ]))
4330
- continue ;
4331
-
4332
- /*
4333
- * XXX at some point we may need to check collations here too.
4334
- * For the moment we assume all collations reduce to the same
4335
- * notion of equality.
4336
- */
4337
-
4338
- matched = true; /* column is unique */
4339
- break ;
4340
- }
4341
-
4342
- if (!matched )
4285
+ if (lc == NULL )
4343
4286
break ; /* no match; this index doesn't help us */
4344
4287
}
4345
4288
0 commit comments