[PATCH] Remove twice assignment with var pageop (nbtree.c).

Started by Ranier Vilelaabout 6 years ago7 messages
#1Ranier Vilela
ranier_gyn@hotmail.com
1 attachment(s)

Hi,
The var pageop has twice assigment, maybe is a mistake?
The assigned in the line 593, has no effect?

Ranier Vilela

Attachments:

nbtree.c.patchtext/x-patch; name=nbtree.c.patchDownload
diff --git a/src/backend/access/nbtree/nbtxlog.c b/src/backend/access/nbtree/nbtxlog.c
index 44f6283950..29c7b41c8c 100644
--- a/src/backend/access/nbtree/nbtxlog.c
+++ b/src/backend/access/nbtree/nbtxlog.c
@@ -590,7 +590,6 @@ btree_xlog_mark_page_halfdead(uint8 info, XLogReaderState *record)
 		BlockNumber rightsib;
 
 		page = (Page) BufferGetPage(buffer);
-		pageop = (BTPageOpaque) PageGetSpecialPointer(page);
 
 		poffset = xlrec->poffset;

#2Ranier Vilela
ranier_gyn@hotmail.com
In reply to: Ranier Vilela (#1)
1 attachment(s)
RE: [PATCH] Remove twice assignment with var pageop (nbtree.c).

Same case on nbtpage.c at line 1637, with var opaque.
make check, passed all 195 tests here with all commits.

Ranier Vilela

Attachments:

nbtpage.c.patchtext/x-patch; name=nbtpage.c.patchDownload
diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c
index 268f869a36..144fefccad 100644
--- a/src/backend/access/nbtree/nbtpage.c
+++ b/src/backend/access/nbtree/nbtpage.c
@@ -1634,8 +1634,6 @@ _bt_mark_page_halfdead(Relation rel, Buffer leafbuf, BTStack stack)
 	 * delete the following item.
 	 */
 	page = BufferGetPage(topparent);
-	opaque = (BTPageOpaque) PageGetSpecialPointer(page);
-
 	itemid = PageGetItemId(page, topoff);
 	itup = (IndexTuple) PageGetItem(page, itemid);
 	BTreeInnerTupleSetDownLink(itup, rightsib);

#3Bruce Momjian
bruce@momjian.us
In reply to: Ranier Vilela (#2)
Re: [PATCH] Remove twice assignment with var pageop (nbtree.c).

On Tue, Nov 26, 2019 at 01:45:10PM +0000, Ranier Vilela wrote:

Same case on nbtpage.c at line 1637, with var opaque.
make check, passed all 195 tests here with all commits.

Ranier Vilela

You were right about both of these, so removed in master. I am
surprised no one else saw this before.

---------------------------------------------------------------------------

diff --git a/src/backend/access/nbtree/nbtpage.c b/src/backend/access/nbtree/nbtpage.c
index 268f869a36..144fefccad 100644
--- a/src/backend/access/nbtree/nbtpage.c
+++ b/src/backend/access/nbtree/nbtpage.c
@@ -1634,8 +1634,6 @@ _bt_mark_page_halfdead(Relation rel, Buffer leafbuf, BTStack stack)
* delete the following item.
*/
page = BufferGetPage(topparent);
-	opaque = (BTPageOpaque) PageGetSpecialPointer(page);
-
itemid = PageGetItemId(page, topoff);
itup = (IndexTuple) PageGetItem(page, itemid);
BTreeInnerTupleSetDownLink(itup, rightsib);

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ As you are, so once was I.  As I am, so you will be. +
+                      Ancient Roman grave inscription +
#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bruce Momjian (#3)
Re: [PATCH] Remove twice assignment with var pageop (nbtree.c).

Bruce Momjian <bruce@momjian.us> writes:

On Tue, Nov 26, 2019 at 01:45:10PM +0000, Ranier Vilela wrote:

Same case on nbtpage.c at line 1637, with var opaque.
make check, passed all 195 tests here with all commits.

You were right about both of these, so removed in master. I am
surprised no one else saw this before.

I don't think this is actually a good idea. What it is is a foot-gun,
because if anyone adds code there that wants to access the special area
of that particular page, it'll do the wrong thing, unless they remember
to put back the assignment of "opaque". The sequence of BufferGetPage()
and PageGetSpecialPointer() is a very standard switch-our-attention-
to-another-page locution in nbtree and other index AMs.

Any optimizing compiler will delete the dead store, we do not have
to do it by hand.

Let me put it this way: if we had the BufferGetPage() and
PageGetSpecialPointer() calls wrapped up as an "access new page" macro,
would we undo that in order to make this code change? We would not.

regards, tom lane

#5Bruce Momjian
bruce@momjian.us
In reply to: Tom Lane (#4)
Re: [PATCH] Remove twice assignment with var pageop (nbtree.c).

On Thu, Dec 19, 2019 at 10:55:42AM -0500, Tom Lane wrote:

Bruce Momjian <bruce@momjian.us> writes:

On Tue, Nov 26, 2019 at 01:45:10PM +0000, Ranier Vilela wrote:

Same case on nbtpage.c at line 1637, with var opaque.
make check, passed all 195 tests here with all commits.

You were right about both of these, so removed in master. I am
surprised no one else saw this before.

I don't think this is actually a good idea. What it is is a foot-gun,
because if anyone adds code there that wants to access the special area
of that particular page, it'll do the wrong thing, unless they remember
to put back the assignment of "opaque". The sequence of BufferGetPage()
and PageGetSpecialPointer() is a very standard switch-our-attention-
to-another-page locution in nbtree and other index AMs.

Oh, I was not aware that was boilerplate code. I agree it should be
consistent, so patch reverted. Sorry.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ As you are, so once was I.  As I am, so you will be. +
+                      Ancient Roman grave inscription +
#6Ranier Vilela
ranier_gyn@hotmail.com
In reply to: Bruce Momjian (#5)
RE: [PATCH] Remove twice assignment with var pageop (nbtree.c).

De: Bruce Momjian <bruce@momjian.us>
Enviado: quinta-feira, 19 de dezembro de 2019 16:19

Oh, I was not aware that was boilerplate code. I agree it should be
consistent, so patch reverted. Sorry.

I apologize to you, Bruce.
It is difficult to define where a "boilerplate" exists.
I agree that decent compiler, will remove, maybe, msvc not, but that's another story...

Best regards,
Ranier Vilela

In reply to: Tom Lane (#4)
Re: [PATCH] Remove twice assignment with var pageop (nbtree.c).

On Thu, Dec 19, 2019 at 7:55 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:

I don't think this is actually a good idea. What it is is a foot-gun,
because if anyone adds code there that wants to access the special area
of that particular page, it'll do the wrong thing, unless they remember
to put back the assignment of "opaque". The sequence of BufferGetPage()
and PageGetSpecialPointer() is a very standard switch-our-attention-
to-another-page locution in nbtree and other index AMs.

+1

--
Peter Geoghegan