pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feed"stack depth limit exceeded" executing DELETE FROM
5+ messages / 5 participants
[nested] [flat]
* "stack depth limit exceeded" executing DELETE FROM
@ 2006-09-05 18:18 Cox, Brian <Brian.Cox@ca.com>
2006-09-05 18:44 ` Re: "stack depth limit exceeded" executing DELETE FROM Michael Fuhr <mike@fuhr.org>
2006-09-05 18:59 ` Re: "stack depth limit exceeded" executing DELETE FROM Tom Lane <tgl@sss.pgh.pa.us>
2006-09-05 19:00 ` Re: "stack depth limit exceeded" executing DELETE FROM Mark Lewis <mark.lewis@mir3.com>
0 siblings, 3 replies; 5+ messages in thread
From: Cox, Brian @ 2006-09-05 18:18 UTC (permalink / raw)
To: pgsql-jdbc
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
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: "stack depth limit exceeded" executing DELETE FROM
2006-09-05 18:18 "stack depth limit exceeded" executing DELETE FROM Cox, Brian <Brian.Cox@ca.com>
@ 2006-09-05 18:44 ` Michael Fuhr <mike@fuhr.org>
2006-09-05 19:18 ` Re: "stack depth limit exceeded" executing DELETE FROM AgentM <agentm@themactionfaction.com>
2 siblings, 1 reply; 5+ messages in thread
From: Michael Fuhr @ 2006-09-05 18:44 UTC (permalink / raw)
To: Cox, Brian <Brian.Cox@ca.com>; +Cc: pgsql-jdbc
On Tue, Sep 05, 2006 at 02:18:05PM -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?
The error isn't due to the number of rows being deleted but rather
from parsing the large number of items in the IN list. See the
following thread:
http://archives.postgresql.org/pgsql-general/2006-01/msg00959.php
How are you obtaining the N values? A subquery that returns the
equivalent list should work. You could also try increasing
max_stack_depth (or max_expr_depth in 7.4 and earlier), but be sure
to stay within your system's stack depth resource limit.
--
Michael Fuhr
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: "stack depth limit exceeded" executing DELETE FROM
2006-09-05 18:18 "stack depth limit exceeded" executing DELETE FROM Cox, Brian <Brian.Cox@ca.com>
2006-09-05 18:44 ` Re: "stack depth limit exceeded" executing DELETE FROM Michael Fuhr <mike@fuhr.org>
@ 2006-09-05 19:18 ` AgentM <agentm@themactionfaction.com>
0 siblings, 0 replies; 5+ messages in thread
From: AgentM @ 2006-09-05 19:18 UTC (permalink / raw)
To: pgsql-jdbc
On Sep 5, 2006, at 14:44 , Michael Fuhr wrote:
> On Tue, Sep 05, 2006 at 02:18:05PM -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?
>
> The error isn't due to the number of rows being deleted but rather
> from parsing the large number of items in the IN list. See the
> following thread:
>
> http://archives.postgresql.org/pgsql-general/2006-01/msg00959.php
You have been receiving great advice from the other guys, but another
thing to try is to use some middleware to determine which ranges your
delete set covers and use WHERE pk BETWEEN x AND y, potentially
improving index usage performance.
-M
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: "stack depth limit exceeded" executing DELETE FROM
2006-09-05 18:18 "stack depth limit exceeded" executing DELETE FROM Cox, Brian <Brian.Cox@ca.com>
@ 2006-09-05 18:59 ` Tom Lane <tgl@sss.pgh.pa.us>
2 siblings, 0 replies; 5+ messages in thread
From: Tom Lane @ 2006-09-05 18:59 UTC (permalink / raw)
To: Cox, Brian <Brian.Cox@ca.com>; +Cc: pgsql-jdbc
"Cox, Brian" <Brian.Cox@ca.com> writes:
> 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?
Not as such, but there's a limit on the complexity of WHERE clauses.
Raising max_stack_depth might help you, but you'll run out of RAM
eventually.
(FWIW, 8.2 will cope a lot better with this particular construct.)
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: "stack depth limit exceeded" executing DELETE FROM
2006-09-05 18:18 "stack depth limit exceeded" executing DELETE FROM Cox, Brian <Brian.Cox@ca.com>
@ 2006-09-05 19:00 ` Mark Lewis <mark.lewis@mir3.com>
2 siblings, 0 replies; 5+ messages in thread
From: Mark Lewis @ 2006-09-05 19:00 UTC (permalink / raw)
To: Cox, Brian <Brian.Cox@ca.com>; +Cc: pgsql-jdbc
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
>
>
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2006-09-05 19:18 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-09-05 18:18 "stack depth limit exceeded" executing DELETE FROM Cox, Brian <Brian.Cox@ca.com>
2006-09-05 18:44 ` Michael Fuhr <mike@fuhr.org>
2006-09-05 19:18 ` AgentM <agentm@themactionfaction.com>
2006-09-05 18:59 ` Tom Lane <tgl@sss.pgh.pa.us>
2006-09-05 19:00 ` Mark Lewis <mark.lewis@mir3.com>
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