Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eGo34-0006xR-E9 for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Nov 2017 15:31:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eGo34-0002DF-2u for pgsql-hackers@arkaria.postgresql.org; Mon, 20 Nov 2017 15:31:50 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1eGo2e-0007Ea-Jn for pgsql-hackers@lists.postgresql.org; Mon, 20 Nov 2017 15:31:24 +0000 Received: from mail.postgrespro.ru ([93.174.131.138]) by makus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1eGo2a-0005V8-Io for pgsql-hackers@postgresql.org; Mon, 20 Nov 2017 15:31:23 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.postgrespro.ru (Postfix) with ESMTP id CFBC321C172E for ; Mon, 20 Nov 2017 18:31:17 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at postgrespro.ru Received: from [192.168.27.109] (gw.postgrespro.ru [93.174.131.141]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) by mail.postgrespro.ru (Postfix) with ESMTPSA id A8DDE21C0909 for ; Mon, 20 Nov 2017 18:31:17 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mail; t=1511191877; bh=y1VoAI41rcjcYWE1sSHCLhUr4FBArlaiT9n0zX2yYsk=; h=From:To:Subject:Date; b=RGW1p2K5JFHg1wwEb3F0DoJODxlLIYjdLTpHbRsxo0FenqlhJGXu9Ix4xjId1MFxI cRsLlF4L4bAghpAmN+C0rtF1MLl6REnIdn44TYcy7b82QbmhB0zs5kjT5l+L3BuEVg qu1b/psRWwTPX5bbhF9JV3NJZsV5BDtFtpcV4rvw= From: Ildar Musin To: Pg Hackers Subject: IndexTupleDSize macro seems redundant Message-ID: <0274288e-9e88-13b6-c61c-7b36928bf221@postgrespro.ru> Date: Mon, 20 Nov 2017 18:31:17 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------9B47690A0A7F6DEF78A81C37" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------9B47690A0A7F6DEF78A81C37 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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 --------------9B47690A0A7F6DEF78A81C37 Content-Type: text/x-patch; name="IndexTupleDSize.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="IndexTupleDSize.patch" 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)) --------------9B47690A0A7F6DEF78A81C37--