@@ -1047,14 +1047,14 @@ group_clauses_by_indexkey(IndexOptInfo *index,
10471047{
10481048 List * clausegroup_list = NIL ;
10491049 bool found_outer_clause = false;
1050- int indexcol = 0 ;
1050+ int indexcol ;
10511051
10521052 * found_clause = false; /* default result */
10531053
10541054 if (clauses == NIL && outer_clauses == NIL )
10551055 return NIL ; /* cannot succeed */
10561056
1057- do
1057+ for ( indexcol = 0 ; indexcol < index -> ncolumns ; indexcol ++ )
10581058 {
10591059 List * clausegroup = NIL ;
10601060 ListCell * l ;
@@ -1102,10 +1102,7 @@ group_clauses_by_indexkey(IndexOptInfo *index,
11021102 return NIL ;
11031103
11041104 clausegroup_list = lappend (clausegroup_list , clausegroup );
1105-
1106- indexcol ++ ;
1107-
1108- } while (indexcol < index -> ncolumns );
1105+ }
11091106
11101107 if (!* found_clause && !found_outer_clause )
11111108 return NIL ; /* no indexable clauses anywhere */
@@ -1163,8 +1160,8 @@ group_clauses_by_indexkey(IndexOptInfo *index,
11631160 *
11641161 * 'index' is the index of interest.
11651162 * 'indexcol' is a column number of 'index' (counting from 0).
1166- * 'opfamily' is the corresponding operator family.
11671163 * 'rinfo' is the clause to be tested (as a RestrictInfo node).
1164+ * 'outer_relids' lists rels whose Vars can be considered pseudoconstant.
11681165 * 'saop_control' indicates whether ScalarArrayOpExpr clauses can be used.
11691166 *
11701167 * Returns true if the clause can be used with this index key.
@@ -1180,12 +1177,12 @@ match_clause_to_indexcol(IndexOptInfo *index,
11801177 SaOpControl saop_control )
11811178{
11821179 Expr * clause = rinfo -> clause ;
1180+ Oid opfamily = index -> opfamily [indexcol ];
11831181 Node * leftop ,
11841182 * rightop ;
11851183 Relids left_relids ;
11861184 Relids right_relids ;
11871185 Oid expr_op ;
1188- Oid opfamily = index -> opfamily [indexcol ];
11891186 bool plain_op ;
11901187
11911188 /*
@@ -1571,19 +1568,17 @@ matches_any_index(RestrictInfo *rinfo, RelOptInfo *rel, Relids outer_relids)
15711568 foreach (l , rel -> indexlist )
15721569 {
15731570 IndexOptInfo * index = (IndexOptInfo * ) lfirst (l );
1574- int indexcol = 0 ;
1571+ int indexcol ;
15751572
1576- do
1573+ for ( indexcol = 0 ; indexcol < index -> ncolumns ; indexcol ++ )
15771574 {
15781575 if (match_clause_to_indexcol (index ,
15791576 indexcol ,
15801577 rinfo ,
15811578 outer_relids ,
15821579 SAOP_ALLOW ))
15831580 return true;
1584-
1585- indexcol ++ ;
1586- } while (indexcol < index -> ncolumns );
1581+ }
15871582 }
15881583
15891584 return false;
@@ -1605,9 +1600,9 @@ eclass_matches_any_index(EquivalenceClass *ec, EquivalenceMember *em,
16051600 foreach (l , rel -> indexlist )
16061601 {
16071602 IndexOptInfo * index = (IndexOptInfo * ) lfirst (l );
1608- int indexcol = 0 ;
1603+ int indexcol ;
16091604
1610- do
1605+ for ( indexcol = 0 ; indexcol < index -> ncolumns ; indexcol ++ )
16111606 {
16121607 Oid curFamily = index -> opfamily [indexcol ];
16131608
@@ -1625,9 +1620,7 @@ eclass_matches_any_index(EquivalenceClass *ec, EquivalenceMember *em,
16251620 list_member_oid (ec -> ec_opfamilies , curFamily )) &&
16261621 match_index_to_operand ((Node * ) em -> em_expr , indexcol , index ))
16271622 return true;
1628-
1629- indexcol ++ ;
1630- } while (indexcol < index -> ncolumns );
1623+ }
16311624 }
16321625
16331626 return false;
@@ -2360,21 +2353,25 @@ List *
23602353expand_indexqual_conditions (IndexOptInfo * index , List * clausegroups )
23612354{
23622355 List * resultquals = NIL ;
2363- ListCell * clausegroup_item ;
2364- int indexcol = 0 ;
2356+ ListCell * lc ;
2357+ int indexcol ;
23652358
23662359 if (clausegroups == NIL )
23672360 return NIL ;
23682361
2369- clausegroup_item = list_head (clausegroups );
2370- do
2362+ /* clausegroups must correspond to index columns */
2363+ Assert (list_length (clausegroups ) <= index -> ncolumns );
2364+
2365+ indexcol = 0 ;
2366+ foreach (lc , clausegroups )
23712367 {
2368+ List * clausegroup = (List * ) lfirst (lc );
23722369 Oid curFamily = index -> opfamily [indexcol ];
2373- ListCell * l ;
2370+ ListCell * lc2 ;
23742371
2375- foreach (l , ( List * ) lfirst ( clausegroup_item ) )
2372+ foreach (lc2 , clausegroup )
23762373 {
2377- RestrictInfo * rinfo = (RestrictInfo * ) lfirst (l );
2374+ RestrictInfo * rinfo = (RestrictInfo * ) lfirst (lc2 );
23782375 Expr * clause = rinfo -> clause ;
23792376
23802377 /* First check for boolean cases */
@@ -2426,12 +2423,8 @@ expand_indexqual_conditions(IndexOptInfo *index, List *clausegroups)
24262423 (int ) nodeTag (clause ));
24272424 }
24282425
2429- clausegroup_item = lnext (clausegroup_item );
2430-
24312426 indexcol ++ ;
2432- } while (clausegroup_item != NULL && indexcol < index -> ncolumns );
2433-
2434- Assert (clausegroup_item == NULL ); /* else more groups than indexkeys */
2427+ }
24352428
24362429 return resultquals ;
24372430}
0 commit comments