X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id AD047D1B1CA for ; Tue, 18 May 2004 14:19:34 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 99216-09 for ; Tue, 18 May 2004 14:19:10 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by svr1.postgresql.org (Postfix) with ESMTP id 24BF0D1B265 for ; Tue, 18 May 2004 14:19:09 -0300 (ADT) Received: from news.hub.org (news.hub.org [200.46.204.72]) by news.hub.org (8.12.9/8.12.9) with ESMTP id i4IHJ8Sx078697 for ; Tue, 18 May 2004 17:19:08 GMT (envelope-from news@news.hub.org) Received: (from news@localhost) by news.hub.org (8.12.9/8.12.9/Submit) id i4IGujdH052489 for pgsql-sql@postgresql.org; Tue, 18 May 2004 16:56:45 GMT Date: Tue, 18 May 2004 18:56:45 +0200 From: Hans de Bruin User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 X-Accept-Language: en-us, en MIME-Version: 1.0 X-Newsgroups: comp.databases.postgresql.sql Subject: Re: How to speed up a time dimension query References: <40a3ea79$0$568$e4fe514c@news.xs4all.nl> <40A75392.90309@bigfoot.com> In-Reply-To: <40A75392.90309@bigfoot.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Lines: 71 Message-ID: <40aa404d$0$559$e4fe514c@news.xs4all.nl> X-Complaints-To: abuse@xs4all.nl To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=1.1 tagged_above=0.0 required=5.0 tests=NO_DNS_FOR_FROM X-Spam-Level: * X-Archive-Number: 200405/192 X-Sequence-Number: 17906 Gaetano Mendola wrote: > Hans de Bruin wrote: > ... > > > This is not what I get with a table similiars to your: > > test=# select count(*) from user_logs; > count > --------- > 3025880 > (1 row) > > > empdb=# explain analyze > empdb-# select * > empdb-# from user_logs > empdb-# where login_time between (now()-interval '25 hours') and > empdb-# (now()-interval '1 hour') > empdb-# order by login_time; > QUERY PLAN > --------------------------------------------------------------------------------------------------------------------------------------------- > > Index Scan using idx_user_logs_login_time on user_logs > (cost=0.00..502.67 rows=15130 width=47) (actual time=61.433..61.433 > rows=0 loops=1) > Index Cond: ((login_time >= (now() - '1 day 01:00:00'::interval)) AND > (login_time <= (now() - '01:00:00'::interval))) > Total runtime: 61.557 ms > (3 rows) > > what do you obtain if you disable the sequential scan ? > > do it in this way: > set enable_seqscan = off; > The runtime increased a litle, so the optimizer made the most efficient choice. Although the query now scans the index it stil seems to use table. In the first itempt the pkey index was used, which only contains the id field. Using the composite index dit not improve. Just selectig the table gives these results: news2=> explain analyze select id,year from dim_time; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Seq Scan on dim_time (cost=0.00..300.00 rows=14400 width=48) (actual time=0.017..49.797 rows=14400 loops=1) Total runtime: 67.788 ms (2 rows) explain analyze select id,year from dim_time order by id,year; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------- Index Scan using ix_dim_time_id_year_month_day_hour on dim_time (cost=0.00..866.68 rows=14400 width=12) (actual time=0.048..139.381 rows=14400 loops=1) Total runtime: 168.210 ms (2 rows) Maybe I am expecting to much from my mini-itx. -- Hans de Bruin http://eratosthenes.xs4all.nl