pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Replace remaining castNode(…, lfirst(…)) and friends calls with l*_node()
Date: Tue, 13 Jul 2021 15:55:48 +0200
Message-ID: <4c9836e2-ed0b-28a4-1cae-fb448a1af362@enterprisedb.com> (raw)
In-Reply-To: <202107081817.mkd7in7le6qr@alvherre.pgsql>
References: <202107081817.mkd7in7le6qr@alvherre.pgsql>


On 08.07.21 20:17, Alvaro Herrera wrote:
>> diff --git a/src/backend/rewrite/rewriteSearchCycle.c b/src/backend/rewrite/rewriteSearchCycle.c
>> index 599fe8e735..c50ebdba24 100644
>> --- a/src/backend/rewrite/rewriteSearchCycle.c
>> +++ b/src/backend/rewrite/rewriteSearchCycle.c
>> @@ -307,8 +307,8 @@ rewriteSearchAndCycle(CommonTableExpr *cte)
>>   					  list_nth_oid(cte->ctecolcollations, i),
>>   					  0);
>>   		tle = makeTargetEntry((Expr *) var, i + 1, strVal(list_nth(cte->ctecolnames, i)), false);
>> -		tle->resorigtbl = castNode(TargetEntry, list_nth(rte1->subquery->targetList, i))->resorigtbl;
>> -		tle->resorigcol = castNode(TargetEntry, list_nth(rte1->subquery->targetList, i))->resorigcol;
>> +		tle->resorigtbl = list_nth_node(TargetEntry, rte1->subquery->targetList, i)->resorigtbl;
>> +		tle->resorigcol = list_nth_node(TargetEntry, rte1->subquery->targetList, i)->resorigcol;
> This seems a bit surprising to me.  I mean, clearly we trust our List
> implementation to be so good that we can just fetch the same node twice,
> one for each member of the same struct, and the compiler will optimize
> everything so that it's a single access to the n'th list entry.  Is this
> true?  I would have expected there to be a single fetch of the struct,
> followed by an access of each of the two struct members.

Lists are arrays now internally, so accessing an element by number is 
pretty cheap.





view thread (9+ messages)  latest in thread

Message-ID: <4c9836e2-ed0b-28a4-1cae-fb448a1af362@enterprisedb.com>
Permalink:  ../4c9836e2-ed0b-28a4-1cae-fb448a1af362@enterprisedb.com/
Also on:    postgresql.org/message-id/4c9836e2-ed0b-28a4-1cae-fb448a1af362@enterprisedb.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: peter.eisentraut@enterprisedb.com, alvherre@alvh.no-ip.org, ilmari@ilmari.org
  Subject: Re: Replace remaining castNode(…, lfirst(…)) and friends calls with l*_node()
  In-Reply-To: <4c9836e2-ed0b-28a4-1cae-fb448a1af362@enterprisedb.com>
  References: <202107081817.mkd7in7le6qr@alvherre.pgsql> <4c9836e2-ed0b-28a4-1cae-fb448a1af362@enterprisedb.com>

* 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