mirror of
https://github.com/postgres/postgres.git
synced 2025-11-07 19:06:32 +03:00
Replace planner's representation of relation sets, per pghackers discussion.
Instead of Lists of integers, we now store variable-length bitmap sets. This should be faster as well as less error-prone.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.2 2003/01/25 23:10:27 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.3 2003/02/08 20:20:55 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -236,7 +236,7 @@ pull_up_subqueries(Query *parse, Node *jtnode, bool below_outer_join)
|
||||
parse->rowMarks = nconc(parse->rowMarks, subquery->rowMarks);
|
||||
|
||||
/*
|
||||
* We also have to fix the relid lists of any parent InClauseInfo
|
||||
* We also have to fix the relid sets of any parent InClauseInfo
|
||||
* nodes. (This could perhaps be done by ResolveNew, but it
|
||||
* would clutter that routine's API unreasonably.)
|
||||
*/
|
||||
@@ -611,10 +611,10 @@ preprocess_jointree(Query *parse, Node *jtnode)
|
||||
}
|
||||
|
||||
/*
|
||||
* fix_in_clause_relids: update RT-index lists of InClauseInfo nodes
|
||||
* fix_in_clause_relids: update RT-index sets of InClauseInfo nodes
|
||||
*
|
||||
* When we pull up a subquery, any InClauseInfo references to the subquery's
|
||||
* RT index have to be replaced by the list of substituted relids.
|
||||
* RT index have to be replaced by the set of substituted relids.
|
||||
*
|
||||
* We assume we may modify the InClauseInfo nodes in-place.
|
||||
*/
|
||||
@@ -627,26 +627,26 @@ fix_in_clause_relids(List *in_info_list, int varno, Relids subrelids)
|
||||
{
|
||||
InClauseInfo *ininfo = (InClauseInfo *) lfirst(l);
|
||||
|
||||
if (intMember(varno, ininfo->lefthand))
|
||||
if (bms_is_member(varno, ininfo->lefthand))
|
||||
{
|
||||
ininfo->lefthand = lremovei(varno, ininfo->lefthand);
|
||||
ininfo->lefthand = nconc(ininfo->lefthand, listCopy(subrelids));
|
||||
ininfo->lefthand = bms_del_member(ininfo->lefthand, varno);
|
||||
ininfo->lefthand = bms_add_members(ininfo->lefthand, subrelids);
|
||||
}
|
||||
if (intMember(varno, ininfo->righthand))
|
||||
if (bms_is_member(varno, ininfo->righthand))
|
||||
{
|
||||
ininfo->righthand = lremovei(varno, ininfo->righthand);
|
||||
ininfo->righthand = nconc(ininfo->righthand, listCopy(subrelids));
|
||||
ininfo->righthand = bms_del_member(ininfo->righthand, varno);
|
||||
ininfo->righthand = bms_add_members(ininfo->righthand, subrelids);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* get_relids_in_jointree: get list of base RT indexes present in a jointree
|
||||
* get_relids_in_jointree: get set of base RT indexes present in a jointree
|
||||
*/
|
||||
List *
|
||||
Relids
|
||||
get_relids_in_jointree(Node *jtnode)
|
||||
{
|
||||
Relids result = NIL;
|
||||
Relids result = NULL;
|
||||
|
||||
if (jtnode == NULL)
|
||||
return result;
|
||||
@@ -654,21 +654,17 @@ get_relids_in_jointree(Node *jtnode)
|
||||
{
|
||||
int varno = ((RangeTblRef *) jtnode)->rtindex;
|
||||
|
||||
result = makeListi1(varno);
|
||||
result = bms_make_singleton(varno);
|
||||
}
|
||||
else if (IsA(jtnode, FromExpr))
|
||||
{
|
||||
FromExpr *f = (FromExpr *) jtnode;
|
||||
List *l;
|
||||
|
||||
/*
|
||||
* Note: we assume it's impossible to see same RT index from more
|
||||
* than one subtree, so nconc() is OK rather than set_unioni().
|
||||
*/
|
||||
foreach(l, f->fromlist)
|
||||
{
|
||||
result = nconc(result,
|
||||
get_relids_in_jointree(lfirst(l)));
|
||||
result = bms_join(result,
|
||||
get_relids_in_jointree(lfirst(l)));
|
||||
}
|
||||
}
|
||||
else if (IsA(jtnode, JoinExpr))
|
||||
@@ -677,7 +673,7 @@ get_relids_in_jointree(Node *jtnode)
|
||||
|
||||
/* join's own RT index is not wanted in result */
|
||||
result = get_relids_in_jointree(j->larg);
|
||||
result = nconc(result, get_relids_in_jointree(j->rarg));
|
||||
result = bms_join(result, get_relids_in_jointree(j->rarg));
|
||||
}
|
||||
else
|
||||
elog(ERROR, "get_relids_in_jointree: unexpected node type %d",
|
||||
@@ -686,12 +682,12 @@ get_relids_in_jointree(Node *jtnode)
|
||||
}
|
||||
|
||||
/*
|
||||
* get_relids_for_join: get list of base RT indexes making up a join
|
||||
* get_relids_for_join: get set of base RT indexes making up a join
|
||||
*
|
||||
* NB: this will not work reliably after preprocess_jointree() is run,
|
||||
* since that may eliminate join nodes from the jointree.
|
||||
*/
|
||||
List *
|
||||
Relids
|
||||
get_relids_for_join(Query *parse, int joinrelid)
|
||||
{
|
||||
Node *jtnode;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.88 2003/01/20 18:54:54 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.89 2003/02/08 20:20:55 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -62,7 +62,7 @@ static List *generate_append_tlist(List *colTypes, bool flag,
|
||||
List *refnames_tlist);
|
||||
static Node *adjust_inherited_attrs_mutator(Node *node,
|
||||
adjust_inherited_attrs_context *context);
|
||||
static List *adjust_rtindex_list(List *relids, Index oldrelid, Index newrelid);
|
||||
static Relids adjust_relid_set(Relids relids, Index oldrelid, Index newrelid);
|
||||
static List *adjust_inherited_tlist(List *tlist, Oid new_relid);
|
||||
|
||||
|
||||
@@ -604,7 +604,7 @@ tlist_same_datatypes(List *tlist, List *colTypes, bool junkOK)
|
||||
|
||||
/*
|
||||
* find_all_inheritors -
|
||||
* Returns an integer list of relids including the given rel plus
|
||||
* Returns an integer list of relation OIDs including the given rel plus
|
||||
* all relations that inherit from it, directly or indirectly.
|
||||
*/
|
||||
List *
|
||||
@@ -662,6 +662,8 @@ find_all_inheritors(Oid parentrel)
|
||||
* its inh flag cleared, whether or not there were any children. This
|
||||
* ensures we won't expand the same RTE twice, which would otherwise occur
|
||||
* for the case of an inherited UPDATE/DELETE target relation.
|
||||
*
|
||||
* XXX probably should convert the result type to Relids?
|
||||
*/
|
||||
List *
|
||||
expand_inherted_rtentry(Query *parse, Index rti, bool dup_parent)
|
||||
@@ -840,13 +842,13 @@ adjust_inherited_attrs_mutator(Node *node,
|
||||
ininfo = (InClauseInfo *) expression_tree_mutator(node,
|
||||
adjust_inherited_attrs_mutator,
|
||||
(void *) context);
|
||||
/* now fix InClauseInfo's rtindex lists */
|
||||
ininfo->lefthand = adjust_rtindex_list(ininfo->lefthand,
|
||||
context->old_rt_index,
|
||||
context->new_rt_index);
|
||||
ininfo->righthand = adjust_rtindex_list(ininfo->righthand,
|
||||
context->old_rt_index,
|
||||
context->new_rt_index);
|
||||
/* now fix InClauseInfo's relid sets */
|
||||
ininfo->lefthand = adjust_relid_set(ininfo->lefthand,
|
||||
context->old_rt_index,
|
||||
context->new_rt_index);
|
||||
ininfo->righthand = adjust_relid_set(ininfo->righthand,
|
||||
context->old_rt_index,
|
||||
context->new_rt_index);
|
||||
return (Node *) ininfo;
|
||||
}
|
||||
|
||||
@@ -873,14 +875,14 @@ adjust_inherited_attrs_mutator(Node *node,
|
||||
newinfo->subclauseindices = NIL;
|
||||
|
||||
/*
|
||||
* Adjust left/right relids lists too.
|
||||
* Adjust left/right relid sets too.
|
||||
*/
|
||||
newinfo->left_relids = adjust_rtindex_list(oldinfo->left_relids,
|
||||
context->old_rt_index,
|
||||
context->new_rt_index);
|
||||
newinfo->right_relids = adjust_rtindex_list(oldinfo->right_relids,
|
||||
context->old_rt_index,
|
||||
context->new_rt_index);
|
||||
newinfo->left_relids = adjust_relid_set(oldinfo->left_relids,
|
||||
context->old_rt_index,
|
||||
context->new_rt_index);
|
||||
newinfo->right_relids = adjust_relid_set(oldinfo->right_relids,
|
||||
context->old_rt_index,
|
||||
context->new_rt_index);
|
||||
|
||||
newinfo->eval_cost.startup = -1; /* reset these too */
|
||||
newinfo->this_selec = -1;
|
||||
@@ -928,18 +930,18 @@ adjust_inherited_attrs_mutator(Node *node,
|
||||
}
|
||||
|
||||
/*
|
||||
* Substitute newrelid for oldrelid in a list of RT indexes
|
||||
* Substitute newrelid for oldrelid in a Relid set
|
||||
*/
|
||||
static List *
|
||||
adjust_rtindex_list(List *relids, Index oldrelid, Index newrelid)
|
||||
static Relids
|
||||
adjust_relid_set(Relids relids, Index oldrelid, Index newrelid)
|
||||
{
|
||||
if (intMember(oldrelid, relids))
|
||||
if (bms_is_member(oldrelid, relids))
|
||||
{
|
||||
/* Ensure we have a modifiable copy */
|
||||
relids = listCopy(relids);
|
||||
relids = bms_copy(relids);
|
||||
/* Remove old, add new */
|
||||
relids = lremovei(oldrelid, relids);
|
||||
relids = lconsi(newrelid, relids);
|
||||
relids = bms_del_member(relids, oldrelid);
|
||||
relids = bms_add_member(relids, newrelid);
|
||||
}
|
||||
return relids;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user