From: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
To: David Rowley <david.rowley@2ndquadrant.com>
Cc: digoal@126.com, pgsql-bugs@lists.postgresql.org, PG Bug reporting form <noreply@postgresql.org>
Subject: Re: BUG #15565: truncate bug with tables which have temp table inherited
Date: Tue, 25 Dec 2018 17:03:37 +0900
Message-ID: <496ce153-fb3b-c8b1-65bd-8a376a88dbc2@lab.ntt.co.jp> (raw)
In-Reply-To: <CAKJS1f_pDqUvyWeiUufRUJ2nUHvD4-rYvjHr2ZiPLsvQ6UQkUg@mail.gmail.com>
References: <15565-ce67a48d0244436a@postgresql.org>
<0285c6d1-2d11-2f2c-6fae-d4575cdc3c7b@lab.ntt.co.jp>
<CAKJS1f_pDqUvyWeiUufRUJ2nUHvD4-rYvjHr2ZiPLsvQ6UQkUg@mail.gmail.com>
On 2018/12/25 16:27, David Rowley wrote:
> On Tue, 25 Dec 2018 at 13:50, Amit Langote
> <Langote_Amit_f8@lab.ntt.co.jp> wrote:
>> I'm not sure if the error being shown is a bug, but maybe we could remove
>> the error by making truncate do the same thing as select/update/delete,
>> that is, ignore child tables that are temporary of tables of other
>> sessions. Attached patch to do that.
>
> I glanced at this and was confused at where "newrelation" comes from
> and also the single parameter heap_close(). It does not look like it
> would compile.
Sorry, that was pretty negligent of me. Here's the updated patch.
Thanks,
Amit
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.cindex 588c1ec536..bad698c125 100644--- a/src/backend/commands/tablecmds.c+++ b/src/backend/commands/tablecmds.c@@ -1416,6 +1416,20 @@ ExecuteTruncate(TruncateStmt *stmt)
/* find_all_inheritors already got lock */
rel = heap_open(childrelid, NoLock);
++ /*+ * It is possible that the parent table has children that are+ * temp tables of other backends. We cannot safely access+ * such tables (because of buffering issues), and the best+ * thing to do seems to be to silently ignore them. No point+ * in holding onto the lock either.+ */+ if (RELATION_IS_OTHER_TEMP(rel))+ {+ heap_close(rel, AccessExclusiveLock);+ continue;+ }+
truncate_check_rel(RelationGetRelid(rel), rel->rd_rel);
truncate_check_activity(rel);
Attachments:truncate-ignore-other-session-temp-children-v2.patch (text/plain, 880B) downloaddiff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.cindex 588c1ec536..bad698c125 100644--- a/src/backend/commands/tablecmds.c+++ b/src/backend/commands/tablecmds.c@@ -1416,6 +1416,20 @@ ExecuteTruncate(TruncateStmt *stmt)
/* find_all_inheritors already got lock */
rel = heap_open(childrelid, NoLock);
++ /*+ * It is possible that the parent table has children that are+ * temp tables of other backends. We cannot safely access+ * such tables (because of buffering issues), and the best+ * thing to do seems to be to silently ignore them. No point+ * in holding onto the lock either.+ */+ if (RELATION_IS_OTHER_TEMP(rel))+ {+ heap_close(rel, AccessExclusiveLock);+ continue;+ }+
truncate_check_rel(RelationGetRelid(rel), rel->rd_rel);
truncate_check_activity(rel);
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 using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: Langote_Amit_f8@lab.ntt.co.jp, david.rowley@2ndquadrant.com, noreply@postgresql.org
Subject: Re: BUG #15565: truncate bug with tables which have temp table inherited
In-Reply-To: <496ce153-fb3b-c8b1-65bd-8a376a88dbc2@lab.ntt.co.jp>
* 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