Re: Slow delete

From: Doug Hall <doughalldev(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Slow delete
Date: 2005-07-13 18:26:28
Message-ID: c0d0bf19998d2e956a4942527f490d64@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Jul 13, 2005, at 12:46 PM, Tom Lane wrote:

> Doug Hall <doughalldev(at)gmail(dot)com> writes:
>> delete from citizen where id not in (select citizenid from
>> citizen_stage);
>
>> The explain select tells me that there is a sequential select of
>> citizen_stage records. (??) There are 75009 citizen records and 14778
>> records, and it's taking more than half an hour. How can I speed this
>> up?
>
> How old is your Postgres? I'd expect 7.4 and up to do this with a
> hashed
> IN, which'd be reasonably fast.

My boss is using 8.0.0 beta4! (Yikes) I'll upgrade him just to make
sure.

> If the EXPLAIN output doesn't say
> anything about a "hashed subplan", then either you've got an old
> version
> or there's some sort of estimation problem.

No, the EXPLAIN doesn't mention "hashed subplan". I suspect it was a
bug in the beta.

> If it is a hashed IN and it's still slow, I'd wonder about unindexed
> foreign key references to the citizen table.
>

The foreign key is indexed without specifying the method, so it's
B-tree by default.

Does PostgreSQL automatically create a hashed index for primary keys?
If not, then we need to drop the index and create it using...

CREATE INDEX name ON table USING HASH (column);

However, the documentation says:

Note: Testing has shown PostgreSQL's hash indexes to perform no better
than B-tree indexes, and the index size and build time for hash indexes
is much worse. For these reasons, hash index use is presently
discouraged.

So, why have hashed indexes?

Thanks,
Doug

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jason Tesser 2005-07-13 18:28:45 stored proc help
Previous Message Tom Lane 2005-07-13 18:25:35 Re: Nulls in timestamps