ExecuteTruncate quirk: expects a unique list of relations

Lists: pgsql-hackers
From: Nikhils <nikkhils(at)gmail(dot)com>
To: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: ExecuteTruncate quirk: expects a unique list of relations
Date: 2008-06-05 14:51:21
Message-ID: d3c4af540806050751v788fb730hd3d790e4b8482f13@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hi,

Consider this simple case:

postgres=# TRUNCATE foo, foo;
ERROR: cannot TRUNCATE "foo" because it is being used by active queries in
this session

The above occurs because the ExecuteTruncate() function invokes
truncate_check_rel() in a loop. Since the same table name appears twice, the
rd_refcnt for table "foo" is bumped up to 2, causing the above failure.

We might want to add a step to ExecuteTruncate(), or whatever calls it, to
make the list unique.

Regards,
Nikhils
--
EnterpriseDB http://www.enterprisedb.com


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Nikhils <nikkhils(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: ExecuteTruncate quirk: expects a unique list of relations
Date: 2008-07-16 16:55:00
Message-ID: 200807161655.m6GGt0K19653@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Nikhils wrote:
> Hi,
>
> Consider this simple case:
>
> postgres=# TRUNCATE foo, foo;
> ERROR: cannot TRUNCATE "foo" because it is being used by active queries in
> this session
>
> The above occurs because the ExecuteTruncate() function invokes
> truncate_check_rel() in a loop. Since the same table name appears twice, the
> rd_refcnt for table "foo" is bumped up to 2, causing the above failure.
>
> We might want to add a step to ExecuteTruncate(), or whatever calls it, to
> make the list unique.

Fixed with attached, applied patch. I didn't see any other cases that
need fixing; LOCK foo, foo already works fine.

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +

Attachment Content-Type Size
/rtmp/diff text/x-diff 640 bytes