Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 043E66327DE for ; Fri, 21 May 2010 01:12:01 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 50807-02 for ; Fri, 21 May 2010 04:11:53 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-gw0-f46.google.com (mail-gw0-f46.google.com [74.125.83.46]) by mail.postgresql.org (Postfix) with ESMTP id AADE16326A1 for ; Fri, 21 May 2010 01:11:53 -0300 (ADT) Received: by gwaa20 with SMTP id a20so292004gwa.19 for ; Thu, 20 May 2010 21:11:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type; bh=SCPQ7Uxk4xjOisVe4dvJqkxM1yXuDGVYaTjTOtPhl+8=; b=RdPXDMNzVL5Us3do0yUe8mnfUHy6l2eBNQMQBybKEsBFA7PEpYNvuLlWE06Q8fGw8P 1sGU4lnHAcBZJa+G7ece7Fh3OLj8Agxb7lpzI7FyVMhjx8EoNVaeeE4d4cIC2fhQGvuA wZ0TH/Pe8a5ri5AFzPwAYrQbAq8yYCcffrt5I= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=UYlkIZFheFDpXHRzsmYBNnizxd0ctb+AfNDTX8LpkcmNMttAiEbyMLRqMZ7kQOyR8h T4Icua2WML56NOh/Ou8NOPpPgPdiBTyZeC2etHLGQ2PxbRL624y7oqrv4nDRQnkCZN5/ 0edRe4gFyrTDIsdi3U8AsUL7FXQKIs8KEV4uA= MIME-Version: 1.0 Received: by 10.150.63.21 with SMTP id l21mr2265107yba.138.1274415112672; Thu, 20 May 2010 21:11:52 -0700 (PDT) Received: by 10.151.50.3 with HTTP; Thu, 20 May 2010 21:11:52 -0700 (PDT) In-Reply-To: References: <7767.1274385170@sss.pgh.pa.us> <7917.1274385834@sss.pgh.pa.us> <8132.1274386738@sss.pgh.pa.us> Date: Thu, 20 May 2010 21:11:52 -0700 Message-ID: Subject: Re: Optimize date query for large child tables: GiST or GIN? From: David Jarvis To: Matthew Wakeling Cc: Tom Lane , Thom Brown , pgsql-performance@postgresql.org Content-Type: multipart/alternative; boundary=000e0cd48f0a16564d048712e4ac X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.801 tagged_above=-10 required=5 tests=BAYES_50=0.8, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201005/137 X-Sequence-Number: 38721 --000e0cd48f0a16564d048712e4ac Content-Type: text/plain; charset=ISO-8859-1 Hi, (An EXPLAIN ANALYSE would be better here). Look at the expected number of > stations "Nested Loop (cost=0.00..994.94 rows=4046 width=4) (actual time=0.053..41.173 rows=78 loops=1)" " Join Filter: ((6371.009::double precision * sqrt((pow(radians(((c.latitude_decimal - s.latitude_decimal))::double precision), 2::double precision) + (cos((radians(((c.latitude_decimal + s.latitude_decimal))::double precision) / 2::double precision)) * pow(radians(((c.longitude_decimal - s.longitude_decimal))::double precision), 2::double precision))))) <= 25::double precision)" " -> Index Scan using city_pkey1 on city c (cost=0.00..6.27 rows=1 width=16) (actual time=0.014..0.016 rows=1 loops=1)" " Index Cond: (id = 5182)" " -> Seq Scan on station s (cost=0.00..321.08 rows=12138 width=20) (actual time=0.007..5.256 rows=12139 loops=1)" " Filter: ((s.elevation >= 0) AND (s.elevation <= 3000))" "Total runtime: 41.235 ms" expects to have to touch a large proportion of the measurement table, > therefore it thinks that it will be fastest to do a seq scan. In actual > fact, for 78 stations, the index would be faster, but for 4046 it wouldn't. > This is rather unexpected. I'd have figured it would use the actual number. > If you will be querying by season quite regularly, had you considered > partitioning by season? > I have no idea what the "regular" queries will be. The purpose of the system is to open the data up to the public using a simple user interface so that they can generate their own custom reports. That user interface allows people to pick year intervals, day ranges, elevations, categories (temperature, precipitation, snow depth, etc.), and lat/long perimeter coordinates (encompassing any number of stations) or a city and radius. Dave --000e0cd48f0a16564d048712e4ac Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi,

(An EXPLAIN ANALYSE would be better here). Look at the= expected number of stations

"Nested Loop=A0 (cost=3D0.00..994.94 rows=3D4046 width=3D4) (= actual time=3D0.053..41.173 rows=3D78 loops=3D1)"
"=A0 Join Fi= lter: ((6371.009::double precision * sqrt((pow(radians(((c.latitude_decimal= - s.latitude_decimal))::double precision), 2::double precision) + (cos((ra= dians(((c.latitude_decimal + s.latitude_decimal))::double precision) / 2::d= ouble precision)) * pow(radians(((c.longitude_decimal - s.longitude_decimal= ))::double precision), 2::double precision))))) <=3D 25::double precisio= n)"
"=A0 ->=A0 Index Scan using city_pkey1 on city c=A0 (cost=3D0.00..6= .27 rows=3D1 width=3D16) (actual time=3D0.014..0.016 rows=3D1 loops=3D1)&qu= ot;
"=A0=A0=A0=A0=A0=A0=A0 Index Cond: (id =3D 5182)"
"= ;=A0 ->=A0 Seq Scan on station s=A0 (cost=3D0.00..321.08 rows=3D12138 wi= dth=3D20) (actual time=3D0.007..5.256 rows=3D12139 loops=3D1)"
"=A0=A0=A0=A0=A0=A0=A0 Filter: ((s.elevation >=3D 0) AND (s.elevati= on <=3D 3000))"
"Total runtime: 41.235 ms"

expects to have to touch a large proportion of the measurement table, there= fore it thinks that it will be fastest to do a seq scan. In actual fact, fo= r 78 stations, the index would be faster, but for 4046 it wouldn't.

This is rather unexpected. I'd have figured it wo= uld use the actual number.
=A0
If you will be querying by season quite regularly, had you considered parti= tioning by season?

I have no idea what= the "regular" queries will be. The purpose of the system is to o= pen the data up to the public using a simple user interface so that they ca= n generate their own custom reports. That user interface allows people to p= ick year intervals, day ranges, elevations, categories (temperature, precip= itation, snow depth, etc.), and lat/long perimeter coordinates (encompassin= g any number of stations) or a city and radius.

Dave

--000e0cd48f0a16564d048712e4ac--