Re: Missed compiler optimization issue in function select_rtable_names_for_explain

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Daniel Gustafsson <daniel(at)yesql(dot)se>
Cc: XChy <xxs_chy(at)outlook(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Missed compiler optimization issue in function select_rtable_names_for_explain
Date: 2024-05-22 16:53:33
Message-ID: 4162324.1716396813@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Daniel Gustafsson <daniel(at)yesql(dot)se> writes:
> They are known to be zero, but that's not entirely equivalent though is it?
> NIL is defined as ((List *) NULL) and NULL is typically defined as ((void *)
> 0), so sizeof(0) would be the size of an int and sizeof(NULL) would be the size
> of a void pointer.

There are other places where we assume that a memset-to-zero will
produce null pointers, so I don't think that that objection has
a lot of force. My real answer is that this is our coding style
and we are not going to change it: our normal convention is to
initialize struct fields in declaration order, and that's what
we're doing here. If some particular version of some particular
compiler fails to make an entirely-negligible optimization in
consequence, that is not something we are going to care about.

Maybe we would care if the missed optimization were a serious
performance loss in a very hot code path. But this is neither.

I'd also say that this is pretty clearly a compiler bug.
If it'd normally optimize away a null-pointer-store following
a memset-to-zero, but does not in

memset(&dpns, 0, sizeof(dpns));
dpns.rtable = rtable;
dpns.subplans = NIL;
dpns.ctes = NIL;
dpns.appendrels = NULL;

that would seem to indicate that the optimizer doesn't
really understand that dpns.rtable is a distinct field
from the others. How is that our problem? (I kind of
wonder if what's actually blocking the optimization is
the casts inside the NIL macros. Still not our problem.)

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2024-05-22 17:10:19 Re: search_path and SET ROLE
Previous Message David G. Johnston 2024-05-22 16:53:31 Re: search_path wildcard?