Re: Query is stuck

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: <pgsql-admin(at)postgresql(dot)org>, "Lewis Kapell" <lkapell(at)setonhome(dot)org>
Subject: Re: Query is stuck
Date: 2010-04-15 17:27:31
Message-ID: 4BC70633020000250003095B@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general

Lewis Kapell <lkapell(at)setonhome(dot)org> wrote:

> The fact that it is doing a sequential scan ("Seq Scan") tells us
> why it takes so long.

Well, that and the fact that for each row in one scan of the table,
it scans the entire table again. :-(

>> select report_id, dm_ip, dm_mac, dm_user, dm_os, report_time,
>> sys_name, sys_user, sys_user_domain, ss_key, login_time, role_id,
>> new_vlan_id from repcopy as a where report_time = (select
>> max(report_time) from repcopy as b where a.dm_ip = b.dm_ip and
>> a.dm_user=b.dm_user and b.ss_key != '') and report_status = 0 and
>> dm_user = 'u1';

I *think* that's equivalent to the following, which might be faster:

select
report_id, a.dm_ip, dm_mac, dm_user, dm_os, a.report_time,
sys_name, sys_user, sys_user_domain, ss_key, login_time,
role_id, new_vlan_id
from repcopy a
join (
select dm_ip, max(report_time) as report_time
from repcopy
where b.ss_key != '' and b.dm_user = 'u1'
group by dm_ip
) b
on (b.dm_ip = a.dm_ip and b.report_time = a.report_time)
where a.report_status = 0 and a.dm_user = 'u1'
;

-Kevin

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Khangelani Gama 2010-04-15 17:41:34 ERROR: cannot read block 15157 of hp_tran: Success
Previous Message Vitaly Burshteyn 2010-04-15 16:07:34 Re: archived WALL files question

Browse pgsql-general by date

  From Date Subject
Next Message Howard Yeh 2010-04-15 17:30:15 Byte Escape Syntax
Previous Message Greg Smith 2010-04-15 17:12:18 Re: solaris tarballs and pl/java