summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/util/joininfo.c
diff options
context:
space:
mode:
authorTom Lane2014-11-28 18:37:25 +0000
committerTom Lane2014-11-28 18:37:25 +0000
commitf4e031c662a6b600b786c4849968a099c58fcce7 (patch)
tree6a082f889ff2ea5b64bb43c467760686e5f013b0 /src/backend/optimizer/util/joininfo.c
parent96d66bcfc60d9bcb7db767f23d33abf4d8bc7021 (diff)
Add bms_next_member(), and use it where appropriate.
This patch adds a way of iterating through the members of a bitmapset nondestructively, unlike the old way with bms_first_member(). While bms_next_member() is very slightly slower than bms_first_member() (at least for typical-size bitmapsets), eliminating the need to palloc and pfree a temporary copy of the target bitmapset is a significant win. So this method should be preferred in all cases where a temporary copy would be necessary. Tom Lane, with suggestions from Dean Rasheed and David Rowley
Diffstat (limited to 'src/backend/optimizer/util/joininfo.c')
-rw-r--r--src/backend/optimizer/util/joininfo.c12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/backend/optimizer/util/joininfo.c b/src/backend/optimizer/util/joininfo.c
index 0418946d714..40af38d7ada 100644
--- a/src/backend/optimizer/util/joininfo.c
+++ b/src/backend/optimizer/util/joininfo.c
@@ -96,17 +96,15 @@ add_join_clause_to_rels(PlannerInfo *root,
RestrictInfo *restrictinfo,
Relids join_relids)
{
- Relids tmprelids;
int cur_relid;
- tmprelids = bms_copy(join_relids);
- while ((cur_relid = bms_first_member(tmprelids)) >= 0)
+ cur_relid = -1;
+ while ((cur_relid = bms_next_member(join_relids, cur_relid)) >= 0)
{
RelOptInfo *rel = find_base_rel(root, cur_relid);
rel->joininfo = lappend(rel->joininfo, restrictinfo);
}
- bms_free(tmprelids);
}
/*
@@ -125,11 +123,10 @@ remove_join_clause_from_rels(PlannerInfo *root,
RestrictInfo *restrictinfo,
Relids join_relids)
{
- Relids tmprelids;
int cur_relid;
- tmprelids = bms_copy(join_relids);
- while ((cur_relid = bms_first_member(tmprelids)) >= 0)
+ cur_relid = -1;
+ while ((cur_relid = bms_next_member(join_relids, cur_relid)) >= 0)
{
RelOptInfo *rel = find_base_rel(root, cur_relid);
@@ -140,5 +137,4 @@ remove_join_clause_from_rels(PlannerInfo *root,
Assert(list_member_ptr(rel->joininfo, restrictinfo));
rel->joininfo = list_delete_ptr(rel->joininfo, restrictinfo);
}
- bms_free(tmprelids);
}