pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Ildar Musin <i.musin@postgrespro.ru>
To: Pg Hackers <pgsql-hackers@postgresql.org>
Subject: IndexTupleDSize macro seems redundant
Date: Mon, 20 Nov 2017 18:31:17 +0300
Message-ID: <0274288e-9e88-13b6-c61c-7b36928bf221@postgrespro.ru> (raw )
Hi all,
While I was looking through the indexes code I got confused by couple of
macros - IndexTupleSize() and IndexTupleDSize() - which seem to do the
same thing with only difference that the first one takes pointer as an
argument while the second one takes struct. And in most cases
IndexTupleDSize() is used with dereferencing of index tuple where
IndexTupleSize() would suit perfectly. Is there a particular reason to
have them both? I've made a patch that removes IndexTupleDSize macro.
All the tests have passed.
--
Ildar Musin
i.musin@postgrespro.ru
Attachments:
IndexTupleDSize.patch (text/x-patch, 5.5K) download
diff --git a/src/backend/access/hash/hash_xlog.c b/src/backend/access/hash/hash_xlog.c
index f19f6fd..a133143 100644
--- a/src/backend/access/hash/hash_xlog.c
+++ b/src/backend/access/hash/hash_xlog.c
@@ -558,7 +558,7 @@ hash_xlog_move_page_contents(XLogReaderState *record)
Size itemsz;
OffsetNumber l;
- itemsz = IndexTupleDSize(*itup);
+ itemsz = IndexTupleSize(itup);
itemsz = MAXALIGN(itemsz);
data += itemsz;
@@ -686,7 +686,7 @@ hash_xlog_squeeze_page(XLogReaderState *record)
Size itemsz;
OffsetNumber l;
- itemsz = IndexTupleDSize(*itup);
+ itemsz = IndexTupleSize(itup);
itemsz = MAXALIGN(itemsz);
data += itemsz;
diff --git a/src/backend/access/hash/hashinsert.c b/src/backend/access/hash/hashinsert.c
index dc08db9..b90d417 100644
--- a/src/backend/access/hash/hashinsert.c
+++ b/src/backend/access/hash/hashinsert.c
@@ -55,7 +55,7 @@ _hash_doinsert(Relation rel, IndexTuple itup, Relation heapRel)
hashkey = _hash_get_indextuple_hashkey(itup);
/* compute item size too */
- itemsz = IndexTupleDSize(*itup);
+ itemsz = IndexTupleSize(itup);
itemsz = MAXALIGN(itemsz); /* be safe, PageAddItem will do this but we
* need to be consistent */
@@ -222,7 +222,7 @@ restart_insert:
XLogRegisterBuffer(1, metabuf, REGBUF_STANDARD);
XLogRegisterBuffer(0, buf, REGBUF_STANDARD);
- XLogRegisterBufData(0, (char *) itup, IndexTupleDSize(*itup));
+ XLogRegisterBufData(0, (char *) itup, IndexTupleSize(itup));
recptr = XLogInsert(RM_HASH_ID, XLOG_HASH_INSERT);
@@ -309,7 +309,7 @@ _hash_pgaddmultitup(Relation rel, Buffer buf, IndexTuple *itups,
{
Size itemsize;
- itemsize = IndexTupleDSize(*itups[i]);
+ itemsize = IndexTupleSize(itups[i]);
itemsize = MAXALIGN(itemsize);
/* Find where to insert the tuple (preserving page's hashkey ordering) */
diff --git a/src/backend/access/hash/hashovfl.c b/src/backend/access/hash/hashovfl.c
index c206e70..b5ec0f6 100644
--- a/src/backend/access/hash/hashovfl.c
+++ b/src/backend/access/hash/hashovfl.c
@@ -890,7 +890,7 @@ readpage:
itup = (IndexTuple) PageGetItem(rpage,
PageGetItemId(rpage, roffnum));
- itemsz = IndexTupleDSize(*itup);
+ itemsz = IndexTupleSize(itup);
itemsz = MAXALIGN(itemsz);
/*
diff --git a/src/backend/access/hash/hashpage.c b/src/backend/access/hash/hashpage.c
index a50e35d..51100e0 100644
--- a/src/backend/access/hash/hashpage.c
+++ b/src/backend/access/hash/hashpage.c
@@ -1173,7 +1173,7 @@ _hash_splitbucket(Relation rel,
* the current page in the new bucket, we must allocate a new
* overflow page and place the tuple on that page instead.
*/
- itemsz = IndexTupleDSize(*new_itup);
+ itemsz = IndexTupleSize(new_itup);
itemsz = MAXALIGN(itemsz);
if (PageGetFreeSpaceForMultipleTuples(npage, nitups + 1) < (all_tups_size + itemsz))
diff --git a/src/backend/access/nbtree/nbtinsert.c b/src/backend/access/nbtree/nbtinsert.c
index 310589d..b39090a 100644
--- a/src/backend/access/nbtree/nbtinsert.c
+++ b/src/backend/access/nbtree/nbtinsert.c
@@ -558,7 +558,7 @@ _bt_findinsertloc(Relation rel,
lpageop = (BTPageOpaque) PageGetSpecialPointer(page);
- itemsz = IndexTupleDSize(*newtup);
+ itemsz = IndexTupleSize(newtup);
itemsz = MAXALIGN(itemsz); /* be safe, PageAddItem will do this but we
* need to be consistent */
@@ -755,7 +755,7 @@ _bt_insertonpg(Relation rel,
elog(ERROR, "cannot insert to incompletely split page %u",
BufferGetBlockNumber(buf));
- itemsz = IndexTupleDSize(*itup);
+ itemsz = IndexTupleSize(itup);
itemsz = MAXALIGN(itemsz); /* be safe, PageAddItem will do this but we
* need to be consistent */
@@ -914,7 +914,7 @@ _bt_insertonpg(Relation rel,
sizeof(IndexTupleData));
}
else
- XLogRegisterBufData(0, (char *) itup, IndexTupleDSize(*itup));
+ XLogRegisterBufData(0, (char *) itup, IndexTupleSize(itup));
recptr = XLogInsert(RM_BTREE_ID, xlinfo);
diff --git a/src/backend/access/nbtree/nbtsort.c b/src/backend/access/nbtree/nbtsort.c
index bf6c03c..b71529f 100644
--- a/src/backend/access/nbtree/nbtsort.c
+++ b/src/backend/access/nbtree/nbtsort.c
@@ -468,7 +468,7 @@ _bt_buildadd(BTWriteState *wstate, BTPageState *state, IndexTuple itup)
last_off = state->btps_lastoff;
pgspc = PageGetFreeSpace(npage);
- itupsz = IndexTupleDSize(*itup);
+ itupsz = IndexTupleSize(itup);
itupsz = MAXALIGN(itupsz);
/*
diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c
index 7250b4f..c18a0d2 100644
--- a/src/backend/access/nbtree/nbtxlog.c
+++ b/src/backend/access/nbtree/nbtxlog.c
@@ -53,7 +53,7 @@ _bt_restore_page(Page page, char *from, int len)
{
/* Need to copy tuple header due to alignment considerations */
memcpy(&itupdata, from, sizeof(IndexTupleData));
- itemsz = IndexTupleDSize(itupdata);
+ itemsz = IndexTupleSize(&itupdata);
itemsz = MAXALIGN(itemsz);
items[i] = (Item) from;
diff --git a/src/include/access/itup.h b/src/include/access/itup.h
index c178ae9..37b6137 100644
--- a/src/include/access/itup.h
+++ b/src/include/access/itup.h
@@ -68,7 +68,6 @@ typedef IndexAttributeBitMapData * IndexAttributeBitMap;
#define INDEX_NULL_MASK 0x8000
#define IndexTupleSize(itup) ((Size) (((IndexTuple) (itup))->t_info & INDEX_SIZE_MASK))
-#define IndexTupleDSize(itup) ((Size) ((itup).t_info & INDEX_SIZE_MASK))
#define IndexTupleHasNulls(itup) ((((IndexTuple) (itup))->t_info & INDEX_NULL_MASK))
#define IndexTupleHasVarwidths(itup) ((((IndexTuple) (itup))->t_info & INDEX_VAR_MASK))
view thread (15+ messages) latest in thread
Message-ID: <0274288e-9e88-13b6-c61c-7b36928bf221@postgrespro.ru>
Permalink: ../0274288e-9e88-13b6-c61c-7b36928bf221@postgrespro.ru/
Also on: postgresql.org/message-id/0274288e-9e88-13b6-c61c-7b36928bf221@postgrespro.ru
copy link · copy postgr.es · copy git am
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: i.musin@postgrespro.ru
Subject: Re: IndexTupleDSize macro seems redundant
In-Reply-To: <0274288e-9e88-13b6-c61c-7b36928bf221@postgrespro.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox