[Beginner Question]What's the use of ResTarget?

From: Wen Yi <wen-yi(at)qq(dot)com>
To: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: [Beginner Question]What's the use of ResTarget?
Date: 2023-07-02 11:19:41
Message-ID: tencent_0349E3BB34D43DADCE985640CAC52DB9C10A@qq.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi community
When I read the Internals document (41.1. The Query Tree),
the introduction of&nbsp; the 'the result relation' confuse me.

In the document, it says

&gt; This is an index into the range table that identifies the relation where the results of the query go.

And I cheak the corresponding code:

In parsenodes.h (A part)

typedef struct ResTarget
{
&nbsp;&nbsp; &nbsp;NodeTag&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; type;
&nbsp;&nbsp; &nbsp;char&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; *name;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /* column name or NULL */
&nbsp;&nbsp; &nbsp;List&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; *indirection;&nbsp;&nbsp;&nbsp; /* subscripts, field names, and '*', or NIL */
&nbsp;&nbsp; &nbsp;Node&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; *val;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /* the value expression to compute or assign */
&nbsp;&nbsp; &nbsp;int&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; location;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; /* token location, or -1 if unknown */
} ResTarget;

In gram.y (A part)

insert_column_item:
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ColId opt_indirection
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; $$ = makeNode(ResTarget);

My question is:

I really don't the the use of ResTarget, in my original understand, I guess the use of ResTarget is to store the columns of the result, like:

SELECT row_1, row_2 FROM table;

After the parse, the ResTarget will store the row_1, row_2 in the ResTarget.

But the turth is, it also be used in the another clause, like INSERT, far from what I imagined.
So what's the use of ResTarget?

Can someone give me some advice?
Thanks in advance!

Yours,
Wen Yi

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Rowley 2023-07-02 22:06:03 Re: need explanation about an explain plan
Previous Message Wen Yi 2023-07-02 11:06:25 Re: [Beginner Question] How to print the call link graph?