summaryrefslogtreecommitdiff
path: root/src/backend/access/heap/heapam.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2023-03-02 11:34:29 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2023-03-02 11:34:29 -0500
commit462bb7f12851c215dfc21a88ae0ed4bf7fcb36a3 (patch)
tree1ab5f6429f5833fd548c1eb079d6129339acb077 /src/backend/access/heap/heapam.c
parent2f80c95740f88e9e3e04ee0c2063e55a497315b4 (diff)
Remove bms_first_member().
This function has been semi-deprecated ever since we invented bms_next_member(). Its habit of scribbling on the input bitmapset isn't great, plus for sufficiently large bitmapsets it would take O(N^2) time to complete a loop. Now we have the additional problem that reducing the input to empty while leaving it still accessible would violate a planned invariant. So let's just get rid of it, after updating the few extant callers to use bms_next_member(). Patch by me; thanks to Nathan Bossart and Richard Guo for review. Discussion: https://postgr.es/m/1159933.1677621588@sss.pgh.pa.us
Diffstat (limited to 'src/backend/access/heap/heapam.c')
-rw-r--r--src/backend/access/heap/heapam.c27
1 files changed, 9 insertions, 18 deletions
diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index 7eb79cee58d..4f50e0dd347 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -3859,9 +3859,6 @@ heap_attr_equals(TupleDesc tupdesc, int attrnum, Datum value1, Datum value2,
* has_external indicates if any of the unmodified attributes (from those
* listed as interesting) of the old tuple is a member of external_cols and is
* stored externally.
- *
- * The input interesting_cols bitmapset is destructively modified; that is OK
- * since this is invoked at most once in heap_update.
*/
static Bitmapset *
HeapDetermineColumnsInfo(Relation relation,
@@ -3870,19 +3867,20 @@ HeapDetermineColumnsInfo(Relation relation,
HeapTuple oldtup, HeapTuple newtup,
bool *has_external)
{
- int attrnum;
+ int attidx;
Bitmapset *modified = NULL;
TupleDesc tupdesc = RelationGetDescr(relation);
- while ((attrnum = bms_first_member(interesting_cols)) >= 0)
+ attidx = -1;
+ while ((attidx = bms_next_member(interesting_cols, attidx)) >= 0)
{
+ /* attidx is zero-based, attrnum is the normal attribute number */
+ AttrNumber attrnum = attidx + FirstLowInvalidHeapAttributeNumber;
Datum value1,
value2;
bool isnull1,
isnull2;
- attrnum += FirstLowInvalidHeapAttributeNumber;
-
/*
* If it's a whole-tuple reference, say "not equal". It's not really
* worth supporting this case, since it could only succeed after a
@@ -3890,9 +3888,7 @@ HeapDetermineColumnsInfo(Relation relation,
*/
if (attrnum == 0)
{
- modified = bms_add_member(modified,
- attrnum -
- FirstLowInvalidHeapAttributeNumber);
+ modified = bms_add_member(modified, attidx);
continue;
}
@@ -3905,9 +3901,7 @@ HeapDetermineColumnsInfo(Relation relation,
{
if (attrnum != TableOidAttributeNumber)
{
- modified = bms_add_member(modified,
- attrnum -
- FirstLowInvalidHeapAttributeNumber);
+ modified = bms_add_member(modified, attidx);
continue;
}
}
@@ -3924,9 +3918,7 @@ HeapDetermineColumnsInfo(Relation relation,
if (!heap_attr_equals(tupdesc, attrnum, value1,
value2, isnull1, isnull2))
{
- modified = bms_add_member(modified,
- attrnum -
- FirstLowInvalidHeapAttributeNumber);
+ modified = bms_add_member(modified, attidx);
continue;
}
@@ -3943,8 +3935,7 @@ HeapDetermineColumnsInfo(Relation relation,
* member of external_cols.
*/
if (VARATT_IS_EXTERNAL((struct varlena *) DatumGetPointer(value1)) &&
- bms_is_member(attrnum - FirstLowInvalidHeapAttributeNumber,
- external_cols))
+ bms_is_member(attidx, external_cols))
*has_external = true;
}