Re: Optimizing select count query which often takes over 10 seconds - Mailing list pgsql-general

From Alexander Farber
Subject Re: Optimizing select count query which often takes over 10 seconds
Date
Msg-id CAADeyWiLz_QsOYyF2RgZPoyB6nFLreopvn57ZyBW24AxcExbqg@mail.gmail.com
Whole thread Raw
In response to Re: Optimizing select count query which often takes over 10 seconds  (Alexander Farber <alexander.farber@gmail.com>)
Responses Re: Optimizing select count query which often takes over 10 seconds  (Kevin Grittner <kgrittn@ymail.com>)
List 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


pgsql-general by date:

Previous
From: Bartosz Dmytrak
Date:
Subject: Fwd: Functions not visible in pg_stat_user_functions view
Next
From: Chris Angelico
Date:
Subject: Re: inet/cidr ipv6 operations