Re: Slow counting on v9.3

From: Guillaume Cottenceau <gc(at)mnc(dot)ch>
To: Kai Sellgren <kaisellgren(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Slow counting on v9.3
Date: 2014-01-16 08:42:57
Message-ID: m3sisojp0u.fsf@mnc.ch
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Kai Sellgren <kaisellgren 'at' gmail.com> writes:

> Hi,
>
> I'm experiecing slow count performance:
>
> SELECT COUNT(*) AS "count"
> FROM "NewsArticle"
>
> Takes 210 ms. I've run analyze and vacuum. I'm on 9.3. Here're the stats http:/
> /d.pr/i/6YoB
>
> I don't understand why is it that slow. It returns 1 integer, and counts
> without filters.

You might actually have a lot more dead tuples than reported in
statistic. Last vacuum is old according to your screenshot. Try
"VACUUM FULL ANALYZE" on your table, then try again counting.

> This performs quickly:
>
> SELECT reltuples AS count
> FROM pg_class
> WHERE relname = 'NewsArticle';

This is not the same. This one uses precomputed statistics, and
doesn't scan the actual table data.

> But I'd like to add conditions so I don't like the last method.
>
>
> --
> Yours sincerely,
> Kai Sellgren

--
Guillaume Cottenceau

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Igor Neyman 2014-01-16 15:41:49 Re: Issue with query scanning through all data even with indexes
Previous Message Mehmet Çakoğlu 2014-01-16 08:37:52 Re: Slow counting on v9.3