{
List *clausegroup_list = NIL;
bool found_outer_clause = false;
- int indexcol = 0;
+ int indexcol;
*found_clause = false; /* default result */
if (clauses == NIL && outer_clauses == NIL)
return NIL; /* cannot succeed */
- do
+ for (indexcol = 0; indexcol < index->ncolumns; indexcol++)
{
List *clausegroup = NIL;
ListCell *l;
return NIL;
clausegroup_list = lappend(clausegroup_list, clausegroup);
-
- indexcol++;
-
- } while (indexcol < index->ncolumns);
+ }
if (!*found_clause && !found_outer_clause)
return NIL; /* no indexable clauses anywhere */
*
* 'index' is the index of interest.
* 'indexcol' is a column number of 'index' (counting from 0).
- * 'opfamily' is the corresponding operator family.
* 'rinfo' is the clause to be tested (as a RestrictInfo node).
+ * 'outer_relids' lists rels whose Vars can be considered pseudoconstant.
* 'saop_control' indicates whether ScalarArrayOpExpr clauses can be used.
*
* Returns true if the clause can be used with this index key.
SaOpControl saop_control)
{
Expr *clause = rinfo->clause;
+ Oid opfamily = index->opfamily[indexcol];
Node *leftop,
*rightop;
Relids left_relids;
Relids right_relids;
Oid expr_op;
- Oid opfamily = index->opfamily[indexcol];
bool plain_op;
/*
foreach(l, rel->indexlist)
{
IndexOptInfo *index = (IndexOptInfo *) lfirst(l);
- int indexcol = 0;
+ int indexcol;
- do
+ for (indexcol = 0; indexcol < index->ncolumns; indexcol++)
{
if (match_clause_to_indexcol(index,
indexcol,
outer_relids,
SAOP_ALLOW))
return true;
-
- indexcol++;
- } while (indexcol < index->ncolumns);
+ }
}
return false;
foreach(l, rel->indexlist)
{
IndexOptInfo *index = (IndexOptInfo *) lfirst(l);
- int indexcol = 0;
+ int indexcol;
- do
+ for (indexcol = 0; indexcol < index->ncolumns; indexcol++)
{
Oid curFamily = index->opfamily[indexcol];
list_member_oid(ec->ec_opfamilies, curFamily)) &&
match_index_to_operand((Node *) em->em_expr, indexcol, index))
return true;
-
- indexcol++;
- } while (indexcol < index->ncolumns);
+ }
}
return false;
expand_indexqual_conditions(IndexOptInfo *index, List *clausegroups)
{
List *resultquals = NIL;
- ListCell *clausegroup_item;
- int indexcol = 0;
+ ListCell *lc;
+ int indexcol;
if (clausegroups == NIL)
return NIL;
- clausegroup_item = list_head(clausegroups);
- do
+ /* clausegroups must correspond to index columns */
+ Assert(list_length(clausegroups) <= index->ncolumns);
+
+ indexcol = 0;
+ foreach(lc, clausegroups)
{
+ List *clausegroup = (List *) lfirst(lc);
Oid curFamily = index->opfamily[indexcol];
- ListCell *l;
+ ListCell *lc2;
- foreach(l, (List *) lfirst(clausegroup_item))
+ foreach(lc2, clausegroup)
{
- RestrictInfo *rinfo = (RestrictInfo *) lfirst(l);
+ RestrictInfo *rinfo = (RestrictInfo *) lfirst(lc2);
Expr *clause = rinfo->clause;
/* First check for boolean cases */
(int) nodeTag(clause));
}
- clausegroup_item = lnext(clausegroup_item);
-
indexcol++;
- } while (clausegroup_item != NULL && indexcol < index->ncolumns);
-
- Assert(clausegroup_item == NULL); /* else more groups than indexkeys */
+ }
return resultquals;
}
/*
* Allocate per-column info arrays. To save a few palloc cycles
- * we allocate all the Oid-type arrays in one request. Note that
- * the opfamily array needs an extra, terminating zero at the end.
- * We pre-zero the ordering info in case the index is unordered.
+ * we allocate all the Oid-type arrays in one request. We must
+ * pre-zero the sortop and nulls_first arrays in case the index is
+ * unordered.
*/
info->indexkeys = (int *) palloc(sizeof(int) * ncolumns);
- info->opfamily = (Oid *) palloc0(sizeof(Oid) * (4 * ncolumns + 1));
- info->opcintype = info->opfamily + (ncolumns + 1);
+ info->opfamily = (Oid *) palloc0(sizeof(Oid) * (4 * ncolumns));
+ info->opcintype = info->opfamily + ncolumns;
info->fwdsortop = info->opcintype + ncolumns;
info->revsortop = info->fwdsortop + ncolumns;
info->nulls_first = (bool *) palloc0(sizeof(bool) * ncolumns);