X-Original-To: pgsql-jdbc-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 02ABD9FB2BF for ; Tue, 5 Sep 2006 16:00:50 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 46020-01-3 for ; Tue, 5 Sep 2006 16:00:41 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mir3-fs.mir3.com (mail.mir3.com [65.208.188.100]) by postgresql.org (Postfix) with ESMTP id 080679FB3A1 for ; Tue, 5 Sep 2006 16:00:34 -0300 (ADT) Received: mir3-fs.mir3.com 172.16.1.11 from 172.16.2.68 172.16.2.68 via HTTP with MS-WebStorage 6.0.6249 Received: from archimedes.mirlogic.com by mir3-fs.mir3.com; 05 Sep 2006 12:00:33 -0700 Subject: Re: "stack depth limit exceeded" executing DELETE FROM From: Mark Lewis To: "Cox, Brian" Cc: pgsql-jdbc@postgresql.org In-Reply-To: <3240464A2687334E92AAB86DAB6504530132D21B@USILMS13.ca.com> References: <3240464A2687334E92AAB86DAB6504530132D21B@USILMS13.ca.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: MIR3, Inc. Date: Tue, 05 Sep 2006 12:00:33 -0700 Message-Id: <1157482833.9657.737.camel@archimedes> Mime-Version: 1.0 X-Mailer: Evolution 2.0.2 (2.0.2-27) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.371 tagged_above=0 required=5 tests=AWL, SARE_MILLIONSOF, UNPARSEABLE_RELAY X-Spam-Level: X-Archive-Number: 200609/8 X-Sequence-Number: 15726 Not a limit to a single DELETE per se, a single delete could remove millions of rows, but you can't specify that many individual entries in an IN (..) section. This isn't a PG-specific issue by the way; Oracle limits you to about 1000 entries IIRC, and SQL Server limits it to 512 or thereabouts. It's just a bad approach. You want to refactor this to use a transaction and JDBC update batches, to gain the benefits of batching without the stack overrun problems. If you're concerned about speed you could try benchmarking to find the optimum size for the number of items in the "IN (...)" clause, but in our testing the optimum number for most databases was 1. For PG I think it was 2. Moral of the story: it's hard to beat individual batch deletes. An alternative approach would be to add these doomed PK's to a temporary table and then do "DELETE FROM myTable WHERE pk IN (SELECT victimId FROM temp_doomed_table)" -- Mark On Tue, 2006-09-05 at 14:18 -0400, Cox, Brian wrote: > The following fails with a "stack depth limit exceeded": > > DELETE FROM some-table WHERE pk IN (pk1, pk2, ..., pkN) > > where pk = primary key and N is large, may be > 50000. > > Is there some limit as to the number of rows that can > be deleted in a single DELETE? > > Thanks, > Brian > >