Re: [HACKERS] ExecuteTruncate quirk: expects a unique list of relations

2008-07-16 Thread Bruce Momjian
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  [EMAIL PROTECTED]http://momjian.us
  EnterpriseDB http://enterprisedb.com

  + If your life is a hard drive, Christ can be your backup. +
Index: src/backend/commands/tablecmds.c
===
RCS file: /cvsroot/pgsql/src/backend/commands/tablecmds.c,v
retrieving revision 1.259
diff -c -c -r1.259 tablecmds.c
*** src/backend/commands/tablecmds.c	19 Jun 2008 00:46:04 -	1.259
--- src/backend/commands/tablecmds.c	16 Jul 2008 16:35:28 -
***
*** 762,767 
--- 762,770 
  	ResultRelInfo *resultRelInfo;
  	ListCell   *cell;
  
+ 	/* make list unique */
+ 	stmt-relations = list_union(NIL, stmt-relations);
+ 
  	/*
  	 * Open, exclusive-lock, and check all the explicitly-specified relations
  	 */

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


[HACKERS] ExecuteTruncate quirk: expects a unique list of relations

2008-06-05 Thread Nikhils
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