diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2019-02-14 19:37:30 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2019-02-14 19:37:30 -0500 |
commit | 8fd3fdd85a3e22f04b2cb0949450f63cb48952cd (patch) | |
tree | 1b3468699da2df4730637f972a7eb94e2546acce /src/backend/utils/adt/selfuncs.c | |
parent | 86eea78694ce0d95e74cc82cc29c096d66a9accd (diff) | |
download | postgresql-8fd3fdd85a3e22f04b2cb0949450f63cb48952cd.tar.gz postgresql-8fd3fdd85a3e22f04b2cb0949450f63cb48952cd.zip |
Simplify the planner's new representation of indexable clauses a little.
In commit 1a8d5afb0, I thought it'd be a good idea to define
IndexClause.indexquals as NIL in the most common case where the given
clause (IndexClause.rinfo) is usable exactly as-is. It'd be more
consistent to define the indexquals in that case as being a one-element
list containing IndexClause.rinfo, but I thought saving the palloc
overhead for making such a list would be worthwhile.
In hindsight, that was a great example of "premature optimization is the
root of all evil": it's complicated everyplace that needs to deal with
the indexquals, requiring duplicative code to handle both the simple
case and the not-simple case. I'd initially found that tolerable but
it's getting less so as I mop up some areas that I'd not touched in
1a8d5afb0. In any case, two more pallocs during a planner run are
surely at the noise level (a conclusion confirmed by a bit of
microbenchmarking). So let's change this decision before it becomes
set in stone, and insist that IndexClause.indexquals always be a valid
list of the actual index quals for the clause.
Discussion: https://postgr.es/m/24586.1550106354@sss.pgh.pa.us
Diffstat (limited to 'src/backend/utils/adt/selfuncs.c')
-rw-r--r-- | src/backend/utils/adt/selfuncs.c | 112 |
1 files changed, 41 insertions, 71 deletions
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c index c25357a0088..0ceb72eaea6 100644 --- a/src/backend/utils/adt/selfuncs.c +++ b/src/backend/utils/adt/selfuncs.c @@ -197,8 +197,6 @@ static bool get_actual_variable_range(PlannerInfo *root, Oid sortop, Datum *min, Datum *max); static RelOptInfo *find_join_input_rel(PlannerInfo *root, Relids relids); -static IndexQualInfo *deconstruct_indexqual(RestrictInfo *rinfo, - IndexOptInfo *index, int indexcol); static List *add_predicate_to_quals(IndexOptInfo *index, List *indexQuals); @@ -5263,16 +5261,13 @@ get_index_quals(List *indexclauses) foreach(lc, indexclauses) { IndexClause *iclause = lfirst_node(IndexClause, lc); + ListCell *lc2; - if (iclause->indexquals == NIL) + foreach(lc2, iclause->indexquals) { - /* rinfo->clause is directly usable as an indexqual */ - result = lappend(result, iclause->rinfo); - } - else - { - /* report the derived indexquals */ - result = list_concat(result, list_copy(iclause->indexquals)); + RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc2); + + result = lappend(result, rinfo); } } return result; @@ -5282,83 +5277,58 @@ List * deconstruct_indexquals(IndexPath *path) { List *result = NIL; - IndexOptInfo *index = path->indexinfo; ListCell *lc; foreach(lc, path->indexclauses) { IndexClause *iclause = lfirst_node(IndexClause, lc); int indexcol = iclause->indexcol; - IndexQualInfo *qinfo; + ListCell *lc2; - if (iclause->indexquals == NIL) - { - /* rinfo->clause is directly usable as an indexqual */ - qinfo = deconstruct_indexqual(iclause->rinfo, index, indexcol); - result = lappend(result, qinfo); - } - else + foreach(lc2, iclause->indexquals) { - /* Process the derived indexquals */ - ListCell *lc2; + RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc2); + Expr *clause = rinfo->clause; + IndexQualInfo *qinfo; - foreach(lc2, iclause->indexquals) - { - RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc2); + qinfo = (IndexQualInfo *) palloc(sizeof(IndexQualInfo)); + qinfo->rinfo = rinfo; + qinfo->indexcol = indexcol; - qinfo = deconstruct_indexqual(rinfo, index, indexcol); - result = lappend(result, qinfo); + if (IsA(clause, OpExpr)) + { + qinfo->clause_op = ((OpExpr *) clause)->opno; + qinfo->other_operand = get_rightop(clause); } - } - } - return result; -} - -static IndexQualInfo * -deconstruct_indexqual(RestrictInfo *rinfo, IndexOptInfo *index, int indexcol) -{ - { - Expr *clause; - IndexQualInfo *qinfo; - - clause = rinfo->clause; - - qinfo = (IndexQualInfo *) palloc(sizeof(IndexQualInfo)); - qinfo->rinfo = rinfo; - qinfo->indexcol = indexcol; + else if (IsA(clause, RowCompareExpr)) + { + RowCompareExpr *rc = (RowCompareExpr *) clause; - if (IsA(clause, OpExpr)) - { - qinfo->clause_op = ((OpExpr *) clause)->opno; - qinfo->other_operand = get_rightop(clause); - } - else if (IsA(clause, RowCompareExpr)) - { - RowCompareExpr *rc = (RowCompareExpr *) clause; + qinfo->clause_op = linitial_oid(rc->opnos); + qinfo->other_operand = (Node *) rc->rargs; + } + else if (IsA(clause, ScalarArrayOpExpr)) + { + ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) clause; - qinfo->clause_op = linitial_oid(rc->opnos); - qinfo->other_operand = (Node *) rc->rargs; - } - else if (IsA(clause, ScalarArrayOpExpr)) - { - ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) clause; + qinfo->clause_op = saop->opno; + qinfo->other_operand = (Node *) lsecond(saop->args); + } + else if (IsA(clause, NullTest)) + { + qinfo->clause_op = InvalidOid; + qinfo->other_operand = NULL; + } + else + { + elog(ERROR, "unsupported indexqual type: %d", + (int) nodeTag(clause)); + } - qinfo->clause_op = saop->opno; - qinfo->other_operand = (Node *) lsecond(saop->args); - } - else if (IsA(clause, NullTest)) - { - qinfo->clause_op = InvalidOid; - qinfo->other_operand = NULL; - } - else - { - elog(ERROR, "unsupported indexqual type: %d", - (int) nodeTag(clause)); + result = lappend(result, qinfo); } - - return qinfo; } + return result; } /* |