mirror of
https://github.com/postgres/postgres.git
synced 2025-07-27 12:41:57 +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:
@ -93,10 +93,7 @@ fixup_whole_row_references(Oid relOid, Bitmapset *columns)
|
||||
static Bitmapset *
|
||||
fixup_inherited_columns(Oid parentId, Oid childId, Bitmapset *columns)
|
||||
{
|
||||
AttrNumber attno;
|
||||
Bitmapset *tmpset;
|
||||
Bitmapset *result = NULL;
|
||||
char *attname;
|
||||
int index;
|
||||
|
||||
/*
|
||||
@ -105,10 +102,12 @@ fixup_inherited_columns(Oid parentId, Oid childId, Bitmapset *columns)
|
||||
if (parentId == childId)
|
||||
return columns;
|
||||
|
||||
tmpset = bms_copy(columns);
|
||||
while ((index = bms_first_member(tmpset)) > 0)
|
||||
index = -1;
|
||||
while ((index = bms_next_member(columns, index)) >= 0)
|
||||
{
|
||||
attno = index + FirstLowInvalidHeapAttributeNumber;
|
||||
/* bit numbers are offset by FirstLowInvalidHeapAttributeNumber */
|
||||
AttrNumber attno = index + FirstLowInvalidHeapAttributeNumber;
|
||||
char *attname;
|
||||
|
||||
/*
|
||||
* whole-row-reference shall be fixed-up later
|
||||
@ -128,12 +127,11 @@ fixup_inherited_columns(Oid parentId, Oid childId, Bitmapset *columns)
|
||||
elog(ERROR, "cache lookup failed for attribute %s of relation %u",
|
||||
attname, childId);
|
||||
|
||||
index = attno - FirstLowInvalidHeapAttributeNumber;
|
||||
result = bms_add_member(result, index);
|
||||
result = bms_add_member(result,
|
||||
attno - FirstLowInvalidHeapAttributeNumber);
|
||||
|
||||
pfree(attname);
|
||||
}
|
||||
bms_free(tmpset);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
Reference in New Issue
Block a user