@@ -2329,8 +2329,8 @@ match_clause_to_indexcol(IndexOptInfo *index,
23292329{
23302330 Expr * clause = rinfo -> clause ;
23312331 Index index_relid = index -> rel -> relid ;
2332- Oid opfamily = index -> opfamily [ indexcol ] ;
2333- Oid idxcollation = index -> indexcollations [ indexcol ] ;
2332+ Oid opfamily ;
2333+ Oid idxcollation ;
23342334 Node * leftop ,
23352335 * rightop ;
23362336 Relids left_relids ;
@@ -2339,6 +2339,11 @@ match_clause_to_indexcol(IndexOptInfo *index,
23392339 Oid expr_coll ;
23402340 bool plain_op ;
23412341
2342+ Assert (indexcol < index -> nkeycolumns );
2343+
2344+ opfamily = index -> opfamily [indexcol ];
2345+ idxcollation = index -> indexcollations [indexcol ];
2346+
23422347 /* First check for boolean-index cases. */
23432348 if (IsBooleanOpfamily (opfamily ))
23442349 {
@@ -2678,15 +2683,19 @@ match_clause_to_ordering_op(IndexOptInfo *index,
26782683 Expr * clause ,
26792684 Oid pk_opfamily )
26802685{
2681- Oid opfamily = index -> opfamily [ indexcol ] ;
2682- Oid idxcollation = index -> indexcollations [ indexcol ] ;
2686+ Oid opfamily ;
2687+ Oid idxcollation ;
26832688 Node * leftop ,
26842689 * rightop ;
26852690 Oid expr_op ;
26862691 Oid expr_coll ;
26872692 Oid sortfamily ;
26882693 bool commuted ;
26892694
2695+ Assert (indexcol < index -> nkeycolumns );
2696+
2697+ opfamily = index -> opfamily [indexcol ];
2698+ idxcollation = index -> indexcollations [indexcol ];
26902699 /*
26912700 * Clause must be a binary opclause.
26922701 */
@@ -2921,8 +2930,13 @@ ec_member_matches_indexcol(PlannerInfo *root, RelOptInfo *rel,
29212930{
29222931 IndexOptInfo * index = ((ec_member_matches_arg * ) arg )-> index ;
29232932 int indexcol = ((ec_member_matches_arg * ) arg )-> indexcol ;
2924- Oid curFamily = index -> opfamily [indexcol ];
2925- Oid curCollation = index -> indexcollations [indexcol ];
2933+ Oid curFamily ;
2934+ Oid curCollation ;
2935+
2936+ Assert (indexcol < index -> nkeycolumns );
2937+
2938+ curFamily = index -> opfamily [indexcol ];
2939+ curCollation = index -> indexcollations [indexcol ];
29262940
29272941 /*
29282942 * If it's a btree index, we can reject it if its opfamily isn't
@@ -3548,8 +3562,13 @@ expand_indexqual_conditions(IndexOptInfo *index,
35483562 RestrictInfo * rinfo = (RestrictInfo * ) lfirst (lcc );
35493563 int indexcol = lfirst_int (lci );
35503564 Expr * clause = rinfo -> clause ;
3551- Oid curFamily = index -> opfamily [indexcol ];
3552- Oid curCollation = index -> indexcollations [indexcol ];
3565+ Oid curFamily ;
3566+ Oid curCollation ;
3567+
3568+ Assert (indexcol < index -> nkeycolumns );
3569+
3570+ curFamily = index -> opfamily [indexcol ];
3571+ curCollation = index -> indexcollations [indexcol ];
35533572
35543573 /* First check for boolean cases */
35553574 if (IsBooleanOpfamily (curFamily ))
@@ -3918,14 +3937,15 @@ adjust_rowcompare_for_index(RowCompareExpr *clause,
39183937 /*
39193938 * The Var side can match any column of the index.
39203939 */
3921- for (i = 0 ; i < index -> ncolumns ; i ++ )
3940+ for (i = 0 ; i < index -> nkeycolumns ; i ++ )
39223941 {
39233942 if (match_index_to_operand (varop , i , index ) &&
39243943 get_op_opfamily_strategy (expr_op ,
39253944 index -> opfamily [i ]) == op_strategy &&
39263945 IndexCollMatchesExprColl (index -> indexcollations [i ],
39273946 lfirst_oid (collids_cell )))
3928- break ;
3947+
3948+ break ;
39293949 }
39303950 if (i >= index -> ncolumns )
39313951 break ; /* no match found */
0 commit comments