Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 0558B9FB6CE for ; Wed, 20 Jun 2007 13:01:11 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 34023-02 for ; Wed, 20 Jun 2007 13:01:03 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from lists.commandprompt.com (host-254.commandprompt.net [207.173.203.254]) by postgresql.org (Postfix) with ESMTP id 239C99FB719 for ; Wed, 20 Jun 2007 13:01:02 -0300 (ADT) Received: from [192.168.1.50] (or-67-76-146-141.sta.embarqhsd.net [67.76.146.141]) (authenticated bits=0) by lists.commandprompt.com (8.13.7/8.13.6) with ESMTP id l5KG0tgC007506; Wed, 20 Jun 2007 09:00:58 -0700 Message-ID: <46794F73.5010201@commandprompt.com> Date: Wed, 20 Jun 2007 09:01:55 -0700 From: "Joshua D. Drake" User-Agent: Thunderbird 1.5.0.12 (X11/20070604) MIME-Version: 1.0 To: Mikko Partio CC: Tom Lane , pgsql-performance@postgresql.org Subject: Re: Slow indexscan References: <2ca799770706200702y1074f066s61279b67f93315d0@mail.gmail.com> <17907.1182352197@sss.pgh.pa.us> <2ca799770706200855w1a6b6a7cy8526b9be0ef9c97c@mail.gmail.com> In-Reply-To: <2ca799770706200855w1a6b6a7cy8526b9be0ef9c97c@mail.gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: ClamAV version 0.88.5, clamav-milter version 0.88.5 on projects.commandprompt.com X-Virus-Status: Clean X-Greylist: Sender succeded SMTP AUTH authentication, not delayed by milter-greylist-1.6 (lists.commandprompt.com [192.168.2.159]); Wed, 20 Jun 2007 09:00:59 -0700 (PDT) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200706/423 X-Sequence-Number: 25456 Mikko Partio wrote: > > > On 6/20/07, *Tom Lane* > wrote: > > "Mikko Partio" > writes: > > > Index Scan using tbl_20070601_pkey on tbl_20070601 t1 > > (cost=0.00..365.13rows=13 width=137) (actual time= > > 120.83..10752.64 rows=539 loops=1) > > Index Cond: ((validtime >= 20070602000000::bigint) AND > (validtime <= > > 20070602235500::bigint) AND (latitude = 60.2744::double > precision) AND > > (longitude = 26.4417::double precision)) > > Filter: (parname = 'temperature'::character varying) > > You do realize that's going to scan the entire index range from > 20070602000000 to 20070602235500? > > If this is a typical query you'd be better off putting the lat/long > columns first in the index. > > regards, tom lane > > > > Thanks for the reply. > > Adding a new index does not speed up the query (although the planner > decides to use the index): > > db=# create index tbl_20070601_latlonvalidpar_index on tbl_20070601 > (latitude,longitude,validtime,parname); > CREATE INDEX > > db=# explain analyze select * from tbl_20070601 where validtime between > 20070602000000 and 20070602235500 and latitude= 60.2744 and > longitude=26.4417 and parname in ('temperature'); > > QUERY PLAN > ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- > > Index Scan using tbl_20070601_latlonvalidpar_index on tbl_20070601 t1 > (cost=0.00..29.18 rows=13 width=137) (actual time=3471.94..31542.90 > rows=539 loops=1) > Index Cond: ((latitude = 60.2744::double precision) AND (longitude = > 26.4417::double precision) AND (validtime >= 20070602000000::bigint) AND > (validtime <= 20070602235500::bigint) AND (parname = > 'temperature'::character varying)) > Total runtime: 31544.48 msec > (3 rows) > > > This is a very typical query and therefore it should be made as fast as > possible. There are several tables like this rowcount ranging from 3 > million to 13 million. I have some possibilities to modify the queries > as well as the tables, but the actual table structure is hard coded. > > Any other suggestions? Try increasing your default_statistics_target and rerunning explain analyze. Secondly try increasing your work_mem. Joshua D. Drake > > Regards > > MP > > -- === The PostgreSQL Company: Command Prompt, Inc. === Sales/Support: +1.503.667.4564 || 24x7/Emergency: +1.800.492.2240 Providing the most comprehensive PostgreSQL solutions since 1997 http://www.commandprompt.com/ Donate to the PostgreSQL Project: http://www.postgresql.org/about/donate PostgreSQL Replication: http://www.commandprompt.com/products/