Skip to content


PostgreSQL Strange Timings

A very simple query. PostgreSQL 8.4. I have no idea why the simple query is 7 times faster than the EXPLAIN ANALYZE version. Any ideas? Anyone?

test_counters=# SELECT COUNT(*), xtype FROM test GROUP BY xtype ORDER BY xtype;
  count  | xtype
---------+-------
  669000 | A
   84000 | B
   63000 | D
   15000 | E
  159000 | G
 7866000 | H
 1000000 | N
  144000 | NI
(8 rows)

Time: 3366,822 ms
test_counters=# explain analyze SELECT COUNT(*), xtype FROM test GROUP BY xtype ORDER BY xtype;
                                                           QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------------
 Sort  (cost=243136.22..243136.24 rows=8 width=2) (actual time=24544.883..24544.889 rows=8 loops=1)
   Sort Key: xtype
   Sort Method:  quicksort  Memory: 25kB
   ->  HashAggregate  (cost=243136.00..243136.10 rows=8 width=2) (actual time=24544.838..24544.848 rows=8 loops=1)
         ->  Seq Scan on test  (cost=0.00..193136.00 rows=10000000 width=2) (actual time=0.012..11501.738 rows=10000000 loops=1)
 Total runtime: 24544.980 ms
(6 rows)

Edition:
It turned out that there is a problem with the gettimeofday() function as Tom Lane wrote:

You’ve got a machine where gettimeofday() is really slow. This is common on cheap PC hardware :-(

http://archives.postgresql.org/pgsql-general/2010-03/msg00770.php

And I really have no idea what to do.

Related posts:

  1. Are SQL Database Joins So Bad? Last time on many forums there were endless discussions about...
  2. PostGIS and Small Number of Huge Geometries The Problem A couple of weeks ago I had a...
  3. How to Allow For Max 4 Rows in Update (PostgreSQL) The Problem Question found on the net: how to restrict...
  4. Common Problem with random(min, max) There is a common problem with many homemade random functions....
  5. Why Is Query Slow? A couple of days ago a colleague of mine had...
  6. PostgreSQL FOUND Problem FOUND is a global variable that exists in the plpgsql...

Posted in database.

Tagged with , , .


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.



Better Tag Cloud