Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id CFD1C633479 for ; Wed, 7 Apr 2010 04:19:04 -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 46894-08 for ; Wed, 7 Apr 2010 07:18:50 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from ey-out-2122.google.com (ey-out-2122.google.com [74.125.78.26]) by mail.postgresql.org (Postfix) with ESMTP id 0AD1A63344C for ; Wed, 7 Apr 2010 04:18:53 -0300 (ADT) Received: by ey-out-2122.google.com with SMTP id d26so70073eyd.33 for ; Wed, 07 Apr 2010 00:18:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:cc:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=O1VsJKQT7BbSVVV69fBnlQfjutB2t/FhYlyvPosA/6A=; b=u8NUyXpQdqT1lJJTHANtGbnXvoZuTx6sOBh1Y1BhLcJ54jQ2I6WnjY584HPFgmb7X6 NpJ0BIBOj5Lza6HZoR1QitXNKh/X44AwI5UraWLX05Vkf9Ej0F2RXwNbhAwFLZvXbS4L 28qzFHaZrCthqqFAPVWkY3zovl+Z1Z0EYJ0xQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; b=DIzc8t4pbBqas/KzSbCJ7oApyJUKtGqIt64EExhDbscgfTNDVGz8vcktWk/DnDfPrY HQBxMZrnPseT/vpc/jjglratk7YkaWqFecdFcFgJn1heWPPuRh4ZhNVXikUNqz8CNIB3 k7O5eFQuVaEzO6jpFqdrSwfc1zc5rVhb2CiYc= Received: by 10.213.50.195 with SMTP id a3mr1547866ebg.19.1270624732504; Wed, 07 Apr 2010 00:18:52 -0700 (PDT) Received: from [0.0.0.0] (5357DA75.cable.casema.nl [83.87.218.117]) by mx.google.com with ESMTPS id 14sm7971473ewy.2.2010.04.07.00.18.50 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 07 Apr 2010 00:18:51 -0700 (PDT) Message-ID: <4BBC31DC.1080605@gmail.com> Date: Wed, 07 Apr 2010 09:18:52 +0200 From: Yeb Havinga User-Agent: Thunderbird 2.0.0.24 (Windows/20100228) MIME-Version: 1.0 To: Scott Marlowe CC: luvar@plaintext.sk, pgsql-performance@postgresql.org Subject: Re: Some question References: <201003311746.38192.luvar@plaintext.sk> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.384 tagged_above=-10 required=5 tests=AWL=0.215, BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 201004/63 X-Sequence-Number: 38313 Scott Marlowe wrote: > 2010/3/31 Ľubomír Varga : > >> Hi, stright to my "problem": >> If I try to select constant 1 from table with two rows, it will be something >> like this: >> >> explain >> SELECT * FROM t_route >> WHERE t_route.route_type_fk = (SELECT id FROM t_route_type WHERE type = 2) >> limit 4; >> >> "Limit (cost=1.02..1.91 rows=4 width=2640)" >> " InitPlan" >> " -> Seq Scan on t_route_type (cost=0.00..1.02 rows=1 width=8)" >> " Filter: ("type" = 2)" >> " -> Seq Scan on t_route (cost=0.00..118115.25 rows=535090 width=2640)" >> " Filter: (route_type_fk = $0)" >> >> > > Looking at this it looks like you're using prepared queries, which > can't make as good of a decision as regular queries because the values > are opaque to the planner. > > Can you provide us with the output of explain analyze of that query? > ISTM that the initplan 'outputs' id as $0, so it is not a prepared query. Maybe EXPLAIN VERBOSE ANALYZE of the query reveals that better. But both plans show seqscans of the large table, so it is surprising that the performance is different, if the filter expression uses the same values. Are you sure the output SELECT id FROM t_route_type WHERE type = 2 is equal to 1? regards, Yeb Havinga