+ /*
+ * Check to see if the indexkey is on the right; if so, commute
+ * the clause. The indexkey should be the side that refers to
+ * (only) the base relation.
+ */
+ if (!bms_equal(rinfo->left_relids, index->rel->relids))
+ CommuteOpExpr(op);
+
+ /*
+ * Now, determine which index attribute this is, change the
+ * indexkey operand as needed, and get the index opclass.
+ */
+ linitial(op->args) = fix_indexqual_operand(linitial(op->args),
+ index,
+ &opclass);
+ clause_op = op->opno;
+ }
+ else if (IsA(clause, RowCompareExpr))
+ {
+ RowCompareExpr *rc = (RowCompareExpr *) clause;
+ ListCell *lc;
+
+ /*
+ * Check to see if the indexkey is on the right; if so, commute
+ * the clause. The indexkey should be the side that refers to
+ * (only) the base relation.
+ */
+ if (!bms_overlap(pull_varnos(linitial(rc->largs)),
+ index->rel->relids))
+ CommuteRowCompareExpr(rc);
+
+ /*
+ * For each column in the row comparison, determine which index
+ * attribute this is and change the indexkey operand as needed.
+ *
+ * Save the index opclass for only the first column. We will
+ * return the operator and opclass info for just the first
+ * column of the row comparison; the executor will have to
+ * look up the rest if it needs them.
+ */
+ foreach(lc, rc->largs)
+ {
+ Oid tmp_opclass;
+
+ lfirst(lc) = fix_indexqual_operand(lfirst(lc),
+ index,
+ &tmp_opclass);
+ if (lc == list_head(rc->largs))
+ opclass = tmp_opclass;
+ }
+ clause_op = linitial_oid(rc->opnos);
+ }
+ else if (IsA(clause, ScalarArrayOpExpr))
+ {
+ ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) clause;
+
+ /* Never need to commute... */
+
+ /*
+ * Now, determine which index attribute this is, change the
+ * indexkey operand as needed, and get the index opclass.
+ */
+ linitial(saop->args) = fix_indexqual_operand(linitial(saop->args),
+ index,
+ &opclass);
+ clause_op = saop->opno;
+ }
+ else
+ {
+ elog(ERROR, "unsupported indexqual type: %d",
+ (int) nodeTag(clause));
+ continue; /* keep compiler quiet */
+ }
+
+ *fixed_indexquals = lappend(*fixed_indexquals, clause);