mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
Simplify the planner's new representation of indexable clauses a little.
In commit1a8d5afb0
, 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 in1a8d5afb0
. 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
This commit is contained in:
@ -2435,7 +2435,7 @@ match_clause_to_indexcol(PlannerInfo *root,
|
||||
{
|
||||
iclause = makeNode(IndexClause);
|
||||
iclause->rinfo = rinfo;
|
||||
iclause->indexquals = NIL;
|
||||
iclause->indexquals = list_make1(rinfo);
|
||||
iclause->lossy = false;
|
||||
iclause->indexcol = indexcol;
|
||||
iclause->indexcols = NIL;
|
||||
@ -2599,7 +2599,7 @@ match_opclause_to_indexcol(PlannerInfo *root,
|
||||
{
|
||||
iclause = makeNode(IndexClause);
|
||||
iclause->rinfo = rinfo;
|
||||
iclause->indexquals = NIL;
|
||||
iclause->indexquals = list_make1(rinfo);
|
||||
iclause->lossy = false;
|
||||
iclause->indexcol = indexcol;
|
||||
iclause->indexcols = NIL;
|
||||
@ -2819,7 +2819,7 @@ match_saopclause_to_indexcol(RestrictInfo *rinfo,
|
||||
IndexClause *iclause = makeNode(IndexClause);
|
||||
|
||||
iclause->rinfo = rinfo;
|
||||
iclause->indexquals = NIL;
|
||||
iclause->indexquals = list_make1(rinfo);
|
||||
iclause->lossy = false;
|
||||
iclause->indexcol = indexcol;
|
||||
iclause->indexcols = NIL;
|
||||
@ -3078,7 +3078,7 @@ expand_indexqual_rowcompare(RestrictInfo *rinfo,
|
||||
* usable as index quals.
|
||||
*/
|
||||
if (var_on_left && !iclause->lossy)
|
||||
iclause->indexquals = NIL;
|
||||
iclause->indexquals = list_make1(rinfo);
|
||||
else
|
||||
{
|
||||
/*
|
||||
|
@ -3075,11 +3075,8 @@ create_bitmap_subplan(PlannerInfo *root, Path *bitmapqual,
|
||||
|
||||
Assert(!rinfo->pseudoconstant);
|
||||
subquals = lappend(subquals, rinfo->clause);
|
||||
if (iclause->indexquals)
|
||||
subindexquals = list_concat(subindexquals,
|
||||
get_actual_clauses(iclause->indexquals));
|
||||
else
|
||||
subindexquals = lappend(subindexquals, rinfo->clause);
|
||||
subindexquals = list_concat(subindexquals,
|
||||
get_actual_clauses(iclause->indexquals));
|
||||
if (rinfo->parent_ec)
|
||||
subindexECs = lappend(subindexECs, rinfo->parent_ec);
|
||||
}
|
||||
@ -4491,33 +4488,18 @@ fix_indexqual_references(PlannerInfo *root, IndexPath *index_path,
|
||||
{
|
||||
IndexClause *iclause = lfirst_node(IndexClause, lc);
|
||||
int indexcol = iclause->indexcol;
|
||||
ListCell *lc2;
|
||||
|
||||
if (iclause->indexquals == NIL)
|
||||
foreach(lc2, iclause->indexquals)
|
||||
{
|
||||
/* rinfo->clause is directly usable as an indexqual */
|
||||
Node *clause = (Node *) iclause->rinfo->clause;
|
||||
RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc2);
|
||||
Node *clause = (Node *) rinfo->clause;
|
||||
|
||||
stripped_indexquals = lappend(stripped_indexquals, clause);
|
||||
clause = fix_indexqual_clause(root, index, indexcol,
|
||||
clause, iclause->indexcols);
|
||||
fixed_indexquals = lappend(fixed_indexquals, clause);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Process the derived indexquals */
|
||||
ListCell *lc2;
|
||||
|
||||
foreach(lc2, iclause->indexquals)
|
||||
{
|
||||
RestrictInfo *rinfo = lfirst_node(RestrictInfo, lc2);
|
||||
Node *clause = (Node *) rinfo->clause;
|
||||
|
||||
stripped_indexquals = lappend(stripped_indexquals, clause);
|
||||
clause = fix_indexqual_clause(root, index, indexcol,
|
||||
clause, iclause->indexcols);
|
||||
fixed_indexquals = lappend(fixed_indexquals, clause);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*stripped_indexquals_p = stripped_indexquals;
|
||||
|
Reference in New Issue
Block a user