Re: Optimizing select count query which often takes over 10 seconds

From: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>
To:
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Optimizing select count query which often takes over 10 seconds
Date: 2013-01-29 13:03:39
Message-ID: CAADeyWiLz_QsOYyF2RgZPoyB6nFLreopvn57ZyBW24AxcExbqg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thank you, I've ended up with this cronjob
(yes I'm unfrotunately having week numbers as strings):

/* reset and then update medals count */

update pref_users set medals = 0;
UPDATE 223456

update pref_users u
set medals = s.medals
from (
select id, count(id) medals
from (
select id,
row_number() over(partition by yw order by money desc) as ranking
from pref_money where yw <> to_char(CURRENT_TIMESTAMP, 'IYYY-IW')
) x
where ranking = 1
group by id
) s
where u.id = s.id;
UPDATE 65

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2013-01-29 14:54:04 Re: BUG #7493: Postmaster messages unreadable in a Windows console
Previous Message DANIEL CRISTIAN CRUZ 2013-01-29 13:03:34 Is there a way to add a detail message in a warning with pl/Python?