mirror of
https://github.com/postgres/postgres.git
synced 2025-11-06 07:49:08 +03:00
Clean up optimizer's handling of indexscan quals that need to be
commuted (ie, the index var appears on the right). These are now handled the same way as merge and hash join quals that need to be commuted: the actual reversing of the clause only happens if we actually choose the path and generate a plan from it. Furthermore, the clause is only reversed in the 'indexqual' field of the plan, not in the 'indxqualorig' field. This allows the clause to still be recognized and removed from qpquals of upper level join plans. Also, simplify and generalize match_clause_to_indexkey; now it recognizes binary-compatible indexes for join as well as restriction clauses.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.45 1999/08/10 03:00:15 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/util/clauses.c,v 1.46 1999/08/12 04:32:54 tgl Exp $
|
||||
*
|
||||
* HISTORY
|
||||
* AUTHOR DATE MAJOR EVENT
|
||||
@@ -666,38 +666,39 @@ get_rels_atts(Node *clause,
|
||||
*--------------------
|
||||
*/
|
||||
void
|
||||
CommuteClause(Node *clause)
|
||||
CommuteClause(Expr *clause)
|
||||
{
|
||||
Node *temp;
|
||||
Oper *commu;
|
||||
Form_pg_operator commuTup;
|
||||
HeapTuple heapTup;
|
||||
Form_pg_operator commuTup;
|
||||
Oper *commu;
|
||||
Node *temp;
|
||||
|
||||
if (!is_opclause(clause))
|
||||
elog(ERROR, "CommuteClause: applied to non-operator clause");
|
||||
if (!is_opclause((Node *) clause) ||
|
||||
length(clause->args) != 2)
|
||||
elog(ERROR, "CommuteClause: applied to non-binary-operator clause");
|
||||
|
||||
heapTup = (HeapTuple)
|
||||
get_operator_tuple(get_commutator(((Oper *) ((Expr *) clause)->oper)->opno));
|
||||
get_operator_tuple(get_commutator(((Oper *) clause->oper)->opno));
|
||||
|
||||
if (heapTup == (HeapTuple) NULL)
|
||||
elog(ERROR, "CommuteClause: no commutator for operator %u",
|
||||
((Oper *) ((Expr *) clause)->oper)->opno);
|
||||
((Oper *) clause->oper)->opno);
|
||||
|
||||
commuTup = (Form_pg_operator) GETSTRUCT(heapTup);
|
||||
|
||||
commu = makeOper(heapTup->t_data->t_oid,
|
||||
commuTup->oprcode,
|
||||
commuTup->oprresult,
|
||||
((Oper *) ((Expr *) clause)->oper)->opsize,
|
||||
((Oper *) clause->oper)->opsize,
|
||||
NULL);
|
||||
|
||||
/*
|
||||
* re-form the clause in-place!
|
||||
*/
|
||||
((Expr *) clause)->oper = (Node *) commu;
|
||||
temp = lfirst(((Expr *) clause)->args);
|
||||
lfirst(((Expr *) clause)->args) = lsecond(((Expr *) clause)->args);
|
||||
lsecond(((Expr *) clause)->args) = temp;
|
||||
clause->oper = (Node *) commu;
|
||||
temp = lfirst(clause->args);
|
||||
lfirst(clause->args) = lsecond(clause->args);
|
||||
lsecond(clause->args) = temp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user