Re: posgres 12 bug (partitioned table)
Soumyadeep Chakraborty <soumyadeep2007@gmail.com>
From: Soumyadeep Chakraborty <soumyadeep2007@gmail.com>
To: Pavel Biryukov <79166341370@yandex.ru>
Cc: David Rowley <dgrowleyml@gmail.com>, Tom Lane <tgl@sss.pgh.pa.us>, PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>,
Andres Freund <andres@anarazel.de>, pgsql-hackers <pgsql-hackers@postgresql.org>, daniel@yesql.se
Date: 2020-07-06T22:45:23Z
Lists: pgsql-bugs, pgsql-hackers
Attachments
- v1-0001-Explicitly-supply-system-columns-for-INSERT.RETUR.patch (application/x-patch) patch v1-0001
- v1-0001-Use-table_tuple_fetch_row_version-to-supply-INSER.patch (application/octet-stream) patch v1-0001
Hello, ccing pgsql-hackers@postgresql.org Upon investigation, it seems that the problem is caused by the following: The slot passed to the call to ExecProcessReturning() inside ExecInsert() is often a virtual tuple table slot. If there are system columns other than ctid and tableOid referenced in the RETURNING clause (not only xmin as in the bug report), it will lead to the ERROR as mentioned in this thread as virtual tuple table slots don't really store such columns. (ctid and tableOid are present directly in the TupleTableSlot struct and can be satisfied from there: refer: slot_getsysattr())) I have attached two alternate patches to solve the problem. Both patches use and share a mechanism to detect if there are any such system columns. This is done inside ExecBuildProjectionInfo() and we store this info inside the ProjectionInfo struct. Then based on this info, system columns are populated in a suitable slot, which is then passed on to ExecProcessReturning(). (If it is deemed that this operation only be done for RETURNING, we can just as easily do it in the callsite for ExecBuildProjectionInfo() in ExecInitModifyTable() for RETURNING instead of doing it inside ExecBuildProjectionInfo()) The first patch [1] explicitly creates a heap tuple table slot, fills in the system column values as we would do during heap_prepare_insert() and then passes that slot to ExecProcessReturning(). (We use a heap tuple table slot as it is guaranteed to support these attributes). The second patch [2] instead of relying on a heap tuple table slot, relies on ExecGetReturningSlot() for the right slot and table_tuple_fetch_row_version() to supply the system column values. It does make the assumption that the AM would supply a slot that will have these system columns. [1] v1-0001-Explicitly-supply-system-columns-for-INSERT.RETUR.patch [2] v1-0001-Use-table_tuple_fetch_row_version-to-supply-INSER.patch Regards, Soumyadeep (VMware)
Commits
-
Don't crash on reference to an un-available system column.
- d479d0028525 14.0 landed
- 2602ee4689c7 13.3 landed
- 05ce4bf8b1d4 12.7 landed