From: Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>
To: 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 09:49:43 +0900
Message-ID: <0285c6d1-2d11-2f2c-6fae-d4575cdc3c7b@lab.ntt.co.jp> (raw)
In-Reply-To: <15565-ce67a48d0244436a@postgresql.org>
References: <15565-ce67a48d0244436a@postgresql.org>
Hi,
On 2018/12/24 18:17, PG Bug reporting form wrote:
> The following bug has been logged on the website:
>
> Bug reference: 15565
> Logged by: Zhou Digoal
> Email address: digoal@126.com
> PostgreSQL version: 11.1
> Operating system: CentOS 7.x x64
> Description:
>
> ```
> create table public.a (id int);
> ```
>
> sesssion a:
>
> ```
> create temp table a (like public.a) inherits(public.a);
> ```
>
> session b:
> ```
> create temp table a (like public.a) inherits(public.a);
> ```
>
> any session:
>
> ```
> postgres=# truncate public.a;
> ERROR: cannot truncate temporary tables of other sessions
> ```
>
> but delete,select,update is ok;
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.
Thanks,
Amit
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.cindex ad8c176793..9dabfc0d36 100644--- a/src/backend/commands/tablecmds.c+++ b/src/backend/commands/tablecmds.c@@ -1416,6 +1416,19 @@ 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.+ */+ if (RELATION_IS_OTHER_TEMP(newrelation))+ {+ heap_close(rel);+ continue;+ }+
truncate_check_rel(RelationGetRelid(rel), rel->rd_rel);
truncate_check_activity(rel);
Attachments:
[text/plain] truncate-ignore-other-session-temp-children.patch (816B, ../0285c6d1-2d11-2f2c-6fae-d4575cdc3c7b@lab.ntt.co.jp/2-truncate-ignore-other-session-temp-children.patch)
download | inline diff:diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.cindex ad8c176793..9dabfc0d36 100644--- a/src/backend/commands/tablecmds.c+++ b/src/backend/commands/tablecmds.c@@ -1416,6 +1416,19 @@ 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.+ */+ if (RELATION_IS_OTHER_TEMP(newrelation))+ {+ heap_close(rel);+ 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, noreply@postgresql.org
Subject: Re: BUG #15565: truncate bug with tables which have temp table inherited
In-Reply-To: <0285c6d1-2d11-2f2c-6fae-d4575cdc3c7b@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