Re: Problem with SQL query (eats swap) - Mailing list pgsql-sql

From Tom Lane
Subject Re: Problem with SQL query (eats swap)
Date
Msg-id 2538.966009235@sss.pgh.pa.us
Whole thread Raw
In response to Problem with SQL query (eats swap)  (pgsql-sql@ruby.sartorelli.gen.nz (Mailing List Expander))
List pgsql-sql
pgsql-sql@ruby.sartorelli.gen.nz (Mailing List Expander) writes:
> select count(*) from attachments a where a.id in (select m.id from
> mail m where m.date < now()-62);

> but ran out of swap.

The problem is that "now()-62" leaks memory to the tune of a few dozen
bytes per evaluation.  In existing releases that memory won't be
reclaimed till end of query.  (This problem is fixed for 7.1, but that
won't help you today.)  Since the inner select is re-executed for each
iteration of the outer select, you have a lot of executions of the
inner WHERE clause, and so even a small leak is a problem.
        regards, tom lane


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Rules aren't doing what I expect
Next
From: Mark Volpe
Date:
Subject: Re: Rules aren't doing what I expect