From: | Mehmet Çakoğlu <mehmetcakoglu(at)gmail(dot)com> |
---|---|
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:37:52 |
Message-ID: | CAJX_To_eu__QRAy8EnzFmnYCU8LQ1xPCfAVoUstU3oOkvNRjVQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
Hi Kai,
You are right, postgresql Count() function is slow, because; It's
physically count the rows one by one.
Other database systems using indexes for counting, but postgresql walk
through all rows in multiple transactions with different row states for
calculating the real row count. This is about architecture of postgresql.
If you use WHERE condition on indexed column in your query, this will be
much faster.
Source: http://wiki.postgresql.org/wiki/Slow_Counting<http://wiki.postgresql.org/wiki/Slow_Counting>
On Mon, Jan 13, 2014 at 11:57 PM, Kai Sellgren <kaisellgren(at)gmail(dot)com>wrote:
> 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.
>
> This performs quickly:
>
> SELECT reltuples AS count
> FROM pg_class
> WHERE relname = 'NewsArticle';
>
> But I'd like to add conditions so I don't like the last method.
>
>
> --
> Yours sincerely,
> Kai Sellgren
>
From | Date | Subject | |
---|---|---|---|
Next Message | Guillaume Cottenceau | 2014-01-16 08:42:57 | Re: Slow counting on v9.3 |
Previous Message | Josh Kupershmidt | 2014-01-14 18:24:55 | Re: COMMIT stuck for days after bulk delete |