pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mark Lewis <mark.lewis@mir3.com>
To: Cox, Brian <Brian.Cox@ca.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: "stack depth limit exceeded" executing DELETE FROM
Date: Tue, 05 Sep 2006 12:00:33 -0700
Message-ID: <1157482833.9657.737.camel@archimedes> (raw)
In-Reply-To: <3240464A2687334E92AAB86DAB6504530132D21B@USILMS13.ca.com>
References: <3240464A2687334E92AAB86DAB6504530132D21B@USILMS13.ca.com>

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
> 
> 



view thread (5+ messages)  latest in thread

Message-ID: <1157482833.9657.737.camel@archimedes>
Permalink:  ../1157482833.9657.737.camel@archimedes/
Also on:    postgresql.org/message-id/1157482833.9657.737.camel@archimedes

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: mark.lewis@mir3.com, Brian.Cox@ca.com
  Subject: Re: "stack depth limit exceeded" executing DELETE FROM
  In-Reply-To: <1157482833.9657.737.camel@archimedes>
  References: <3240464A2687334E92AAB86DAB6504530132D21B@USILMS13.ca.com> <1157482833.9657.737.camel@archimedes>

* 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