Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id F06829FB93E for ; Wed, 14 Feb 2007 15:12:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-new, port 10024) with ESMTP id 76637-04 for ; Wed, 14 Feb 2007 15:12:44 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from k2smtpout01-01.prod.mesa1.secureserver.net (k2smtpout01-02.prod.mesa1.secureserver.net [64.202.189.89]) by postgresql.org (Postfix) with SMTP id 850619FB931 for ; Wed, 14 Feb 2007 15:12:45 -0400 (AST) Received: (qmail 650 invoked from network); 14 Feb 2007 19:12:44 -0000 Received: from unknown (HELO mail.servantwebhosting.com) (68.178.159.82) by k2smtpout01-01.prod.mesa1.secureserver.net (64.202.189.88) with ESMTP; 14 Feb 2007 19:12:44 -0000 Received: (qmail 10433 invoked by uid 2527); 14 Feb 2007 12:12:39 -0700 Received: from 70.64.210.50 by jonah.prod.phx1.secureserver.net (envelope-from , uid 2525) with qmail-scanner-1.25-st-qms (clamdscan: 0.86.2/989. spamassassin: 3.1.7. perlscan: 1.25-st-qms. Clear:RC:0(70.64.210.50):SA:0(-0.6/5.0):. Processed in 3.575709 secs); 14 Feb 2007 19:12:39 -0000 X-Antivirus-MYDOMAIN-Mail-From: pgsql-performance@nullmx.com via jonah.prod.phx1.secureserver.net X-Antivirus-MYDOMAIN: 1.25-st-qms (Clear:RC:0(70.64.210.50):SA:0(-0.6/5.0):. Processed in 3.575709 secs Process 8192) X-Envelope-From: pgsql-performance@nullmx.com Received: from s010600e0296eec95.mj.shawcable.net (HELO shach) (rob@nullmx.com@70.64.210.50) by mail.servantwebhosting.com with SMTP; 14 Feb 2007 12:12:35 -0700 From: "Chuck D." Reply-To: pgsql-performance@nullmx.com To: pgsql-performance@postgresql.org Subject: Re: JOIN to a VIEW makes a real slow query Date: Wed, 14 Feb 2007 13:12:22 -0600 User-Agent: KMail/1.9.5 References: <200702131253.55486.pgsql-performance@nullmx.com> <200702131417.32154.pgsql-performance@nullmx.com> <11207.1171399908@sss.pgh.pa.us> In-Reply-To: <11207.1171399908@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200702141312.23437.pgsql-performance@nullmx.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200702/160 X-Sequence-Number: 23214 On Tuesday 13 February 2007 14:51, Tom Lane wrote: > "Chuck D." writes: > > It is still using that sequence scan on the view after the APPEND for t= he > > us_city and world_city table. Any reason why the view won't use the > > indexes when it is JOINed to another table but it will when the view is > > queried without a JOIN? I should have mentioned this is v8.1.4. > > 8.1 isn't bright enough for that. Should work in 8.2 though. > > regards, tom lane Upgraded to 8.2.3 in my spare time here - went from the packaged binary tha= t=20 came with Ubuntu to compiling from source. Haven't tuned it yet, but what = do=20 you think about this join on the view? cmi=3D# explain analyze cmi-# select user_id, username, city_name cmi-# FROM m_user AS mu cmi-# LEFT JOIN geo.city_vw AS ci ON (mu.city_id =3D ci.city_id) cmi-# ; QUERY PLAN =2D------------------------------------------------------------------------= =2D-------------------------------------------------------------- Nested Loop Left Join (cost=3D0.00..17.76 rows=3D10614 width=3D486) (actu= al=20 time=3D0.109..0.113 rows=3D1 loops=3D1) Join Filter: (mu.city_id =3D ci.city_id) -> Seq Scan on m_user mu (cost=3D0.00..1.01 rows=3D1 width=3D72) (actu= al=20 time=3D0.015..0.017 rows=3D1 loops=3D1) -> Append (cost=3D0.00..16.72 rows=3D2 width=3D422) (actual time=3D0.0= 73..0.075=20 rows=3D1 loops=3D1) -> Index Scan using pk_us_city on us_city (cost=3D0.00..8.28 row= s=3D1=20 width=3D222) (actual time=3D0.032..0.032 rows=3D0 loops=3D1) Index Cond: (mu.city_id =3D us_city.city_id) -> Index Scan using world_city_pk on world_city (cost=3D0.00..8.= 44=20 rows=3D1 width=3D422) (actual time=3D0.040..0.042 rows=3D1 loops=3D1) Index Cond: (mu.city_id =3D world_city.city_id) Total runtime: 0.359 ms (9 rows) =46rom 65 seconds down to less than 1 ms. Pretty good huh? Nice call Tom.= =20 Now I'll have to find some time to do the production server before this app= =20 goes up.