somewhat slow query with subselect

From: Marcus Engene <mengpg2(at)engene(dot)se>
To: pgsql-general(at)postgresql(dot)org
Subject: somewhat slow query with subselect
Date: 2009-08-25 16:16:51
Message-ID: 4A940E73.5040308@engene.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi list,

I have a table, not that many rows (400k) but with about 55 columns.
There are some maintenance selects I want to do (every now and then)
that I don't want to add indexes for.

select
...
from
quite_big_table qbt
where
qbt.owner = 123 AND
exists (
select null
from quite_big_table qbt2
where
qbt2.owner = qbt.owner AND
qbt2.id <> qbt.id AND
qbt2.filelength = qbt.filelength
)

In a case with some 5000 rows belonging to owner 123, this select really
takes a long time. Way longer than without the subselect and order by
filelength. I agree that with the subselect it would take some extra
juice, but in my mind it would do some hash in memory which wouldn't be
too slow to lookup in.

shared_buffers = 16GB
temp_buffers = 1GB
work_mem = 32MB
maintenance_work_mem = 1GB
#server has 64GB (64bit)

I guess there is some penalty because of the size (# columns) of the
table since it has to go thru more blocks on the disk. Would it have
been beneficial if filelength was in a joined child table instead?

How would you do this? Create a temporary table with owner+filelenght?

Thanks!
Marcus

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2009-08-25 16:24:00 Re: Invalid memory alloc request
Previous Message Sébastien Lardière 2009-08-25 16:11:28 WAL Shipping + checkpoint