mirror of
https://github.com/postgres/postgres.git
synced 2025-11-19 13:42:17 +03:00
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
This commit is contained in:
@@ -1875,9 +1875,8 @@ get_loop_count(PlannerInfo *root, Relids outer_relids)
|
||||
{
|
||||
int relid;
|
||||
|
||||
/* Need a working copy since bms_first_member is destructive */
|
||||
outer_relids = bms_copy(outer_relids);
|
||||
while ((relid = bms_first_member(outer_relids)) >= 0)
|
||||
relid = -1;
|
||||
while ((relid = bms_next_member(outer_relids, relid)) >= 0)
|
||||
{
|
||||
RelOptInfo *outer_rel;
|
||||
|
||||
@@ -1900,7 +1899,6 @@ get_loop_count(PlannerInfo *root, Relids outer_relids)
|
||||
if (result == 1.0 || result > outer_rel->rows)
|
||||
result = outer_rel->rows;
|
||||
}
|
||||
bms_free(outer_relids);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user