1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-09 06:21:09 +03:00

Remove Item type

This type is just char * underneath, it provides no real value, no
type safety, and just makes the code one level more mysterious.  It is
more idiomatic to refer to blobs of memory by a combination of void *
and size_t, so change it to that.

Also, since this type hides the pointerness, we can't apply qualifiers
to what is pointed to, which requires some unconstify nonsense.  This
change allows fixing that.

Extension code that uses the Item type can change its code to use
void * to be backward compatible.

Reviewed-by: Nathan Bossart <nathandbossart@gmail.com>
Reviewed-by: Peter Geoghegan <pg@bowt.ie>
Discussion: https://www.postgresql.org/message-id/flat/c75cccf5-5709-407b-a36a-2ae6570be766@eisentraut.org
This commit is contained in:
Peter Eisentraut
2025-10-27 09:54:16 +01:00
parent 64d2b0968e
commit 76acf4b722
29 changed files with 102 additions and 178 deletions

View File

@@ -165,8 +165,7 @@ spgPageIndexMultiDelete(SpGistState *state, Page page,
if (tuple == NULL || tuple->tupstate != tupstate)
tuple = spgFormDeadTuple(state, tupstate, blkno, offnum);
if (PageAddItem(page, (Item) tuple, tuple->size,
itemno, false, false) != itemno)
if (PageAddItem(page, tuple, tuple->size, itemno, false, false) != itemno)
elog(ERROR, "failed to add item of size %u to SPGiST index page",
tuple->size);
@@ -222,7 +221,7 @@ addLeafTuple(Relation index, SpGistState *state, SpGistLeafTuple leafTuple,
/* Tuple is not part of a chain */
SGLT_SET_NEXTOFFSET(leafTuple, InvalidOffsetNumber);
current->offnum = SpGistPageAddNewItem(state, current->page,
(Item) leafTuple, leafTuple->size,
leafTuple, leafTuple->size,
NULL, false);
xlrec.offnumLeaf = current->offnum;
@@ -255,7 +254,7 @@ addLeafTuple(Relation index, SpGistState *state, SpGistLeafTuple leafTuple,
{
SGLT_SET_NEXTOFFSET(leafTuple, SGLT_GET_NEXTOFFSET(head));
offnum = SpGistPageAddNewItem(state, current->page,
(Item) leafTuple, leafTuple->size,
leafTuple, leafTuple->size,
NULL, false);
/*
@@ -274,7 +273,7 @@ addLeafTuple(Relation index, SpGistState *state, SpGistLeafTuple leafTuple,
SGLT_SET_NEXTOFFSET(leafTuple, InvalidOffsetNumber);
PageIndexTupleDelete(current->page, current->offnum);
if (PageAddItem(current->page,
(Item) leafTuple, leafTuple->size,
leafTuple, leafTuple->size,
current->offnum, false, false) != current->offnum)
elog(ERROR, "failed to add item of size %u to SPGiST index page",
leafTuple->size);
@@ -478,8 +477,7 @@ moveLeafs(Relation index, SpGistState *state,
*/
SGLT_SET_NEXTOFFSET(it, r);
r = SpGistPageAddNewItem(state, npage, (Item) it, it->size,
&startOffset, false);
r = SpGistPageAddNewItem(state, npage, it, it->size, &startOffset, false);
toInsert[nInsert] = r;
nInsert++;
@@ -492,9 +490,7 @@ moveLeafs(Relation index, SpGistState *state,
/* add the new tuple as well */
SGLT_SET_NEXTOFFSET(newLeafTuple, r);
r = SpGistPageAddNewItem(state, npage,
(Item) newLeafTuple, newLeafTuple->size,
&startOffset, false);
r = SpGistPageAddNewItem(state, npage, newLeafTuple, newLeafTuple->size, &startOffset, false);
toInsert[nInsert] = r;
nInsert++;
memcpy(leafptr, newLeafTuple, newLeafTuple->size);
@@ -1226,7 +1222,7 @@ doPickSplit(Relation index, SpGistState *state,
/* Insert it on page */
newoffset = SpGistPageAddNewItem(state, BufferGetPage(leafBuffer),
(Item) it, it->size,
it, it->size,
&startOffsets[leafPageSelect[i]],
false);
toInsert[i] = newoffset;
@@ -1268,7 +1264,7 @@ doPickSplit(Relation index, SpGistState *state,
current->page = parent->page;
xlrec.offnumInner = current->offnum =
SpGistPageAddNewItem(state, current->page,
(Item) innerTuple, innerTuple->size,
innerTuple, innerTuple->size,
NULL, false);
/*
@@ -1302,7 +1298,7 @@ doPickSplit(Relation index, SpGistState *state,
current->page = BufferGetPage(current->buffer);
xlrec.offnumInner = current->offnum =
SpGistPageAddNewItem(state, current->page,
(Item) innerTuple, innerTuple->size,
innerTuple, innerTuple->size,
NULL, false);
/* Done modifying new current buffer, mark it dirty */
@@ -1340,7 +1336,7 @@ doPickSplit(Relation index, SpGistState *state,
xlrec.innerIsParent = false;
xlrec.offnumInner = current->offnum =
PageAddItem(current->page, (Item) innerTuple, innerTuple->size,
PageAddItem(current->page, innerTuple, innerTuple->size,
InvalidOffsetNumber, false, false);
if (current->offnum != FirstOffsetNumber)
elog(ERROR, "failed to add item of size %u to SPGiST index page",
@@ -1547,7 +1543,7 @@ spgAddNodeAction(Relation index, SpGistState *state,
PageIndexTupleDelete(current->page, current->offnum);
if (PageAddItem(current->page,
(Item) newInnerTuple, newInnerTuple->size,
newInnerTuple, newInnerTuple->size,
current->offnum, false, false) != current->offnum)
elog(ERROR, "failed to add item of size %u to SPGiST index page",
newInnerTuple->size);
@@ -1631,7 +1627,7 @@ spgAddNodeAction(Relation index, SpGistState *state,
/* insert new ... */
xlrec.offnumNew = current->offnum =
SpGistPageAddNewItem(state, current->page,
(Item) newInnerTuple, newInnerTuple->size,
newInnerTuple, newInnerTuple->size,
NULL, false);
MarkBufferDirty(current->buffer);
@@ -1654,7 +1650,7 @@ spgAddNodeAction(Relation index, SpGistState *state,
current->blkno, current->offnum);
PageIndexTupleDelete(saveCurrent.page, saveCurrent.offnum);
if (PageAddItem(saveCurrent.page, (Item) dt, dt->size,
if (PageAddItem(saveCurrent.page, dt, dt->size,
saveCurrent.offnum,
false, false) != saveCurrent.offnum)
elog(ERROR, "failed to add item of size %u to SPGiST index page",
@@ -1818,7 +1814,7 @@ spgSplitNodeAction(Relation index, SpGistState *state,
*/
PageIndexTupleDelete(current->page, current->offnum);
xlrec.offnumPrefix = PageAddItem(current->page,
(Item) prefixTuple, prefixTuple->size,
prefixTuple, prefixTuple->size,
current->offnum, false, false);
if (xlrec.offnumPrefix != current->offnum)
elog(ERROR, "failed to add item of size %u to SPGiST index page",
@@ -1832,7 +1828,7 @@ spgSplitNodeAction(Relation index, SpGistState *state,
postfixBlkno = current->blkno;
xlrec.offnumPostfix = postfixOffset =
SpGistPageAddNewItem(state, current->page,
(Item) postfixTuple, postfixTuple->size,
postfixTuple, postfixTuple->size,
NULL, false);
xlrec.postfixBlkSame = true;
}
@@ -1841,7 +1837,7 @@ spgSplitNodeAction(Relation index, SpGistState *state,
postfixBlkno = BufferGetBlockNumber(newBuffer);
xlrec.offnumPostfix = postfixOffset =
SpGistPageAddNewItem(state, BufferGetPage(newBuffer),
(Item) postfixTuple, postfixTuple->size,
postfixTuple, postfixTuple->size,
NULL, false);
MarkBufferDirty(newBuffer);
xlrec.postfixBlkSame = false;

View File

@@ -1200,7 +1200,7 @@ spgExtractNodeLabels(SpGistState *state, SpGistInnerTuple innerTuple)
* rather than returning InvalidOffsetNumber.
*/
OffsetNumber
SpGistPageAddNewItem(SpGistState *state, Page page, Item item, Size size,
SpGistPageAddNewItem(SpGistState *state, Page page, const void *item, Size size,
OffsetNumber *startOffset, bool errorOK)
{
SpGistPageOpaque opaque = SpGistPageGetOpaque(page);

View File

@@ -47,7 +47,7 @@ fillFakeState(SpGistState *state, spgxlogState stateSrc)
* existing tuple, it had better be a placeholder tuple.
*/
static void
addOrReplaceTuple(Page page, Item tuple, int size, OffsetNumber offset)
addOrReplaceTuple(Page page, const void *tuple, int size, OffsetNumber offset)
{
if (offset <= PageGetMaxOffsetNumber(page))
{
@@ -110,8 +110,7 @@ spgRedoAddLeaf(XLogReaderState *record)
if (xldata->offnumLeaf != xldata->offnumHeadLeaf)
{
/* normal cases, tuple was added by SpGistPageAddNewItem */
addOrReplaceTuple(page, (Item) leafTuple, leafTupleHdr.size,
xldata->offnumLeaf);
addOrReplaceTuple(page, leafTuple, leafTupleHdr.size, xldata->offnumLeaf);
/* update head tuple's chain link if needed */
if (xldata->offnumHeadLeaf != InvalidOffsetNumber)
@@ -129,7 +128,7 @@ spgRedoAddLeaf(XLogReaderState *record)
/* replacing a DEAD tuple */
PageIndexTupleDelete(page, xldata->offnumLeaf);
if (PageAddItem(page,
(Item) leafTuple, leafTupleHdr.size,
leafTuple, leafTupleHdr.size,
xldata->offnumLeaf, false, false) != xldata->offnumLeaf)
elog(ERROR, "failed to add item of size %u to SPGiST index page",
leafTupleHdr.size);
@@ -232,8 +231,7 @@ spgRedoMoveLeafs(XLogReaderState *record)
memcpy(&leafTupleHdr, leafTuple,
sizeof(SpGistLeafTupleData));
addOrReplaceTuple(page, (Item) leafTuple,
leafTupleHdr.size, toInsert[i]);
addOrReplaceTuple(page, leafTuple, leafTupleHdr.size, toInsert[i]);
ptr += leafTupleHdr.size;
}
@@ -309,7 +307,7 @@ spgRedoAddNode(XLogReaderState *record)
page = BufferGetPage(buffer);
PageIndexTupleDelete(page, xldata->offnum);
if (PageAddItem(page, (Item) innerTuple, innerTupleHdr.size,
if (PageAddItem(page, innerTuple, innerTupleHdr.size,
xldata->offnum,
false, false) != xldata->offnum)
elog(ERROR, "failed to add item of size %u to SPGiST index page",
@@ -351,8 +349,7 @@ spgRedoAddNode(XLogReaderState *record)
{
page = BufferGetPage(buffer);
addOrReplaceTuple(page, (Item) innerTuple,
innerTupleHdr.size, xldata->offnumNew);
addOrReplaceTuple(page, innerTuple, innerTupleHdr.size, xldata->offnumNew);
/*
* If parent is in this same page, update it now.
@@ -390,7 +387,7 @@ spgRedoAddNode(XLogReaderState *record)
xldata->offnumNew);
PageIndexTupleDelete(page, xldata->offnum);
if (PageAddItem(page, (Item) dt, dt->size,
if (PageAddItem(page, dt, dt->size,
xldata->offnum,
false, false) != xldata->offnum)
elog(ERROR, "failed to add item of size %u to SPGiST index page",
@@ -492,8 +489,7 @@ spgRedoSplitTuple(XLogReaderState *record)
{
page = BufferGetPage(buffer);
addOrReplaceTuple(page, (Item) postfixTuple,
postfixTupleHdr.size, xldata->offnumPostfix);
addOrReplaceTuple(page, postfixTuple, postfixTupleHdr.size, xldata->offnumPostfix);
PageSetLSN(page, lsn);
MarkBufferDirty(buffer);
@@ -508,15 +504,13 @@ spgRedoSplitTuple(XLogReaderState *record)
page = BufferGetPage(buffer);
PageIndexTupleDelete(page, xldata->offnumPrefix);
if (PageAddItem(page, (Item) prefixTuple, prefixTupleHdr.size,
if (PageAddItem(page, prefixTuple, prefixTupleHdr.size,
xldata->offnumPrefix, false, false) != xldata->offnumPrefix)
elog(ERROR, "failed to add item of size %u to SPGiST index page",
prefixTupleHdr.size);
if (xldata->postfixBlkSame)
addOrReplaceTuple(page, (Item) postfixTuple,
postfixTupleHdr.size,
xldata->offnumPostfix);
addOrReplaceTuple(page, postfixTuple, postfixTupleHdr.size, xldata->offnumPostfix);
PageSetLSN(page, lsn);
MarkBufferDirty(buffer);
@@ -662,8 +656,7 @@ spgRedoPickSplit(XLogReaderState *record)
if (page == NULL)
continue; /* no need to touch this page */
addOrReplaceTuple(page, (Item) leafTuple, leafTupleHdr.size,
toInsert[i]);
addOrReplaceTuple(page, leafTuple, leafTupleHdr.size, toInsert[i]);
}
/* Now update src and dest page LSNs if needed */
@@ -692,8 +685,7 @@ spgRedoPickSplit(XLogReaderState *record)
{
page = BufferGetPage(innerBuffer);
addOrReplaceTuple(page, (Item) innerTuple, innerTupleHdr.size,
xldata->offnumInner);
addOrReplaceTuple(page, innerTuple, innerTupleHdr.size, xldata->offnumInner);
/* if inner is also parent, update link while we're here */
if (xldata->innerIsParent)