Add system column support to the USING clause

From: Denis Garsh <d(dot)garsh(at)arenadata(dot)io>
To: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Add system column support to the USING clause
Date: 2024-09-13 08:03:42
Message-ID: 333431726204057@mail.yandex.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers



Hello. This is my first patch to the project.


 


The patch adds support for system columns in JOIN USING clause.  The problem


can be demonstrated with this code:


 


```sql


CREATE TABLE t  (id int);


CREATE TABLE tt (id int);


 


-- Works:


SELECT * FROM t JOIN tt ON t.xmin = tt.xmin;


-- Doesn't work:


SELECT * FROM t JOIN tt USING (xmin);


```


 


Solution:


1. Use the scanNSItemForColumn() function instead of buildVarFromNSColumn() for


constructing Var objects, as it correctly handles system columns.


2. Remove extra calls to markVarForSelectPriv(), since this function is already


invoked in scanNSItemForColumn().


3. For system columns, collect their negative attribute numbers along with


user-defined column indices into l_colnos and r_colnos.


4. Create a buildVarFromSystemAttribute() function for rebuilding Var objects


with system attributes, analogous to buildVarFromNSColumn(), since


scanNSItemForColumn() is complex and has side effects.


5. Implement a fillNSColumnParametersFromVar() function for building NS columns


with system attributes.



6. Add SystemAttributeTotalNumber() function to heap.c to ensure memory for


res_nscolumns is allocated with system columns in mind.



 


Link to PR on GitHub: https://github.com/hilltracer/postgres/pull/3

-- 

Best regards,  

Denis Garsh,  

d(dot)garsh(at)arenadata(dot)io

 

Attachment Content-Type Size
unknown_filename text/html 1.7 KB
v1-0001-Add-system-column-support-to-the-USING-clause.patch text/x-diff 16.7 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Mats Kindahl 2024-09-13 08:10:13 Re: Use streaming read API in ANALYZE
Previous Message jian he 2024-09-13 08:02:00 Re: Add column name to error description