Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XqeXi-0002CE-Br for pgsql-sql@arkaria.postgresql.org; Tue, 18 Nov 2014 08:53:46 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XqeXh-0004xx-Mb for pgsql-sql@arkaria.postgresql.org; Tue, 18 Nov 2014 08:53:45 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XqeXg-0004wE-Kv for pgsql-sql@postgresql.org; Tue, 18 Nov 2014 08:53:44 +0000 Received: from mail-wg0-x229.google.com ([2a00:1450:400c:c00::229]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XqeXd-0000wW-AV for pgsql-sql@postgresql.org; Tue, 18 Nov 2014 08:53:43 +0000 Received: by mail-wg0-f41.google.com with SMTP id y19so7729852wgg.14 for ; Tue, 18 Nov 2014 00:53:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=vm8yW+copGmi+pIEDfPjuGsois+zNwshh2klPNvUlnc=; b=UCWQQRV78/tU4ijpjD0GoBCJIAq8Hwr8APpEQHYvxe2MWR7uGOCp0h77tt8c/IhkX1 lurmOhWSJ+S1wTPUIbGmsRD0ZpwS5RmCHrqPymiRJ4cuLXM6bKzUu7IjZnFrmloiPLh7 qeJ8ay9SrCalSTRBs9xNFzyJEgcHhndV9FTtT5uEEy5OnYzdyicktyKSrncwyXuAwVGF /Btz4kL4dItLc390ox1/pjDGrqVW9YsNRMDm2uorGZ2202ArSugbK09xousnov9xA1J4 2yjB1ckEgpWZoHvpeD8E47XqeF/WjLs6RWRscb/ijGswBL09KNvpv2gmkz4U1rSnvtnx mrng== X-Received: by 10.194.3.45 with SMTP id 13mr44448374wjz.47.1416300820502; Tue, 18 Nov 2014 00:53:40 -0800 (PST) Received: from [192.168.1.64] (host217-43-225-174.range217-43.btcentralplus.com. [217.43.225.174]) by mx.google.com with ESMTPSA id t7sm54894437wjy.24.2014.11.18.00.53.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Nov 2014 00:53:39 -0800 (PST) Message-ID: <546B0912.7090206@gmail.com> Date: Tue, 18 Nov 2014 08:53:38 +0000 From: Tim Dudgeon User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: slow sub-query problem References: <546A3FBA.9020901@gmail.com> <23343.1416255046@sss.pgh.pa.us> In-Reply-To: <23343.1416255046@sss.pgh.pa.us> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Tom, thanks. I did a vacuum of the table and unfortunately it didn't help. But a good spot. Tim On 17/11/2014 20:10, Tom Lane wrote: > Tim Dudgeon writes: >> I'm having problems optimising a query that's very slow due to a sub-query. > I think it might get better if you could fix this misestimate: > >> " -> Bitmap Index Scan on idx_sp_property_id >> (cost=0.00..33.90 rows=1146 width=0) (actual time=51.656..51.656 rows=811892 loops=366)" >> " Index Cond: (property_id = ANY ('{1,643413,1106201}'::integer[]))" > 1146 estimated vs 811892 actual is pretty bad, and it doesn't seem like > this is a very hard case to estimate. Are the stats for structure_props > up to date? Maybe you need to increase the statistics target for the > property_id column. > > Another component of the bad plan choice is this misestimate: > >> " -> HashAggregate (cost=1091.73..1091.75 rows=2 width=4) (actual time=2.829..3.212 rows=366 loops=1)" >> " Group Key: structure_props_1.structure_id" > but it might be harder to do anything about that one, since the result > depends on the property_id being probed; without cross-column statistics > it may be impossible to do much better. > > regards, tom lane -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql