Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 72C40632789 for ; Wed, 31 Mar 2010 12:54:03 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 46218-01 for ; Wed, 31 Mar 2010 15:53:34 +0000 (UTC) X-Greylist: delayed 00:06:37.159615 by SQLgrey-1.7.6 Received: from shiva.plaintext.sk (mail.plaintext.sk [81.0.124.6]) by mail.postgresql.org (Postfix) with ESMTP id BBFE36324BC for ; Wed, 31 Mar 2010 12:53:34 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by shiva.plaintext.sk (Postfix) with ESMTP id AF560269EC for ; Wed, 31 Mar 2010 17:46:54 +0200 (CEST) X-Virus-Scanned: amavisd-new at plaintext.sk Received: from shiva.plaintext.sk ([127.0.0.1]) by localhost (shiva.plaintext.sk [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dD2asW-luLrC for ; Wed, 31 Mar 2010 17:46:49 +0200 (CEST) Received: from blackhorse.local (unknown [84.245.72.18]) by shiva.plaintext.sk (Postfix) with ESMTP id CDF302633B for ; Wed, 31 Mar 2010 17:46:49 +0200 (CEST) From: =?utf-8?q?=C4=BDubom=C3=ADr_Varga?= Reply-To: luvar@plaintext.sk Organization: LuVar To: pgsql-performance@postgresql.org Subject: Some question Date: Wed, 31 Mar 2010 17:46:38 +0200 User-Agent: KMail/1.9.10 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <201003311746.38192.luvar@plaintext.sk> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.299 tagged_above=-10 required=5 tests=AWL=-1.300, BAYES_50=0.001 X-Spam-Level: X-Archive-Number: 201004/48 X-Sequence-Number: 38298 Hi, stright to my "problem": explain SELECT * FROM t_route WHERE t_route.route_type_fk =3D 1 limit 4; "Limit (cost=3D0.00..0.88 rows=3D4 width=3D2640)" " -> Seq Scan on t_route (cost=3D0.00..118115.25 rows=3D538301 width=3D2= 640)" " Filter: (route_type_fk =3D 1)" If I try to select constant 1 from table with two rows, it will be somethin= g=20 like this: explain SELECT * FROM t_route WHERE t_route.route_type_fk =3D (SELECT id FROM t_route_type WHERE type = =3D 2) limit 4; "Limit (cost=3D1.02..1.91 rows=3D4 width=3D2640)" " InitPlan" " -> Seq Scan on t_route_type (cost=3D0.00..1.02 rows=3D1 width=3D8)" " Filter: ("type" =3D 2)" " -> Seq Scan on t_route (cost=3D0.00..118115.25 rows=3D535090 width=3D2= 640)" " Filter: (route_type_fk =3D $0)" =46irst query is done in about milicesonds. Second is longer than 60 second= s.=20 t_route is bigger table (~10M rows). I think that it seq scans whole table. Is it bug? If no, how can I achieve= =20 that second select will not take time to end of world... Have a nice day and thanks for any reply. =2D-=20 Odborn=C3=ADk na v=C5=A1etko je zl=C3=BD odborn=C3=ADk. Ja sa sna=C5=BE=C3= =ADm by=C5=A5 v=C3=BDnimkou potvrdzuj=C3=BAcou=20 pravidlo.