Re: Really really slow select count(*)

From: Shaun Thomas <sthomas(at)peak6(dot)com>
To: felix <crucialfelix(at)gmail(dot)com>
Cc: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>, "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Really really slow select count(*)
Date: 2011-02-04 20:37:56
Message-ID: 4D4C63A4.6090109@peak6.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On 02/04/2011 02:14 PM, felix wrote:

> oh and there in the footnotes to django they say "dont' forget to run
> the delete expired sessions management every once in a while".
> thanks guys.

Oh Django... :)

> it won't run now because its too big, I can delete them from psql though

You might be better off deleting the inverse. You know, start a
transaction, select all the sessions that *aren't* expired, truncate the
table, insert them back into the session table, and commit.

BEGIN;
CREATE TEMP TABLE foo_1 AS
SELECT * FROM django_session WHERE date_expired < CURRENT_DATE;
TRUNCATE django_session;
INSERT INTO django_session SELECT * from foo_1;
COMMIT;

Except I don't actually know what the expired column is. You can figure
that out pretty quick, I assume. That'll also have the benefit of
cleaning up the indexes and the table all at once. If you just do a
delete, the table won't change at all, except that it'll have less
active records.

> well just think how sprightly my website will run tomorrow once I fix
> these.

Maybe. :)

--
Shaun Thomas
OptionsHouse | 141 W. Jackson Blvd. | Suite 800 | Chicago IL, 60604
312-676-8870
sthomas(at)peak6(dot)com

______________________________________________

See http://www.peak6.com/email_disclaimer.php
for terms and conditions related to this email

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Mark Stosberg 2011-02-04 21:18:18 Re: getting the most of out multi-core systems for repeated complex SELECT statements
Previous Message felix 2011-02-04 20:14:22 Re: Really really slow select count(*)