Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 170E86338A4 for ; Mon, 30 Mar 2009 13:33:39 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 07934-06 for ; Mon, 30 Mar 2009 13:33:36 -0300 (ADT) X-Greylist: delayed 00:07:58.017066 by SQLgrey-1.7.6 Received: from ey-out-2122.google.com (ey-out-2122.google.com [74.125.78.24]) by mail.postgresql.org (Postfix) with ESMTP id 4D1C8633771 for ; Mon, 30 Mar 2009 13:33:36 -0300 (ADT) Received: by ey-out-2122.google.com with SMTP id 22so394785eye.61 for ; Mon, 30 Mar 2009 09:33:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=g9hVwtVkos7s+PbDv+5JWLWLnmhwl+NFnNcDZFnqdDg=; b=ERHYlnMhUJlsbpyhHuF5VUiT6fJ5AdPwaQzKDraisHJ2duTzx5xSn8puSyx5r3Nq2X 7t9IqOj+DQR911Tu+Itfkn4nnnNnRKoX9Lc9Dr1PgJC/I/ciHgmyj0d1W1wNgsQbRfSZ Jki+XcR7ZWZRxih6jAM+C9pY9J8f17J3Yg/YA= 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:content-transfer-encoding; b=wsXCSxNIeNU34RMWmp3zfp7iqjPJwU3+ofBPSMjPm5uFHswRImTaPt3xd0EDrKh69R uhS42xDGBi6rejjoA7VqRNN83fXP1tnvlVRCOyMXB+mm1JWDVllOgwcnWCGYLg6w4tYQ s6NDMUkKvo89ZPYRfPKAxcluP/8AtJQyY7YvE= MIME-Version: 1.0 Received: by 10.210.111.17 with SMTP id j17mr664391ebc.13.1238430336374; Mon, 30 Mar 2009 09:25:36 -0700 (PDT) In-Reply-To: <49D0E687.50605@megafon.hr> References: <49D0D237.7020308@megafon.hr> <3028.1238422571@sss.pgh.pa.us> <49D0E687.50605@megafon.hr> Date: Mon, 30 Mar 2009 10:25:36 -0600 Message-ID: Subject: Re: Forcing seq_scan off for large table joined with tiny table yeilds improved performance From: Scott Marlowe To: Mario Splivalo Cc: Tom Lane , pgsql-performance@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200903/413 X-Sequence-Number: 33335 On Mon, Mar 30, 2009 at 9:34 AM, Mario Splivalo wrote: > =A0 =A0 =A0 =A0 -> =A0Bitmap Heap Scan on photo_info_data u (cost=3D2193.= 50..26798.74 > rows=3D109024 width=3D9) (actual time=3D0.025..0.030 rows=3D3 loops=3D2) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 Recheck Cond: ((u.field_name)::text =3D (t.ke= y)::text) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 -> =A0Bitmap Index Scan on photo_info_data_ix= __field_name > =A0(cost=3D0.00..2166.24 rows=3D109024 width=3D0) (actual time=3D0.019..0= .019 rows=3D3 > loops=3D2) > So, I guess I solved my problem! :) The explain analyze still shows that = row > estimate is 'quite off' (109024 estimated vs only 3 actuall), but the que= ry > is light-speeded :) It's not really solved, it's just a happy coincidence that the current plan runs well. In order to keep the query planner making good choices you need to increase stats target for the field in the index above. The easiest way to do so is to do this: alter database mydb set default_statistics_target=3D100; and run analyze again: analyze; > I tought that having primary key (and auto-index because of primary key) = on > (photo_id, field_name) should be enough. Now I have two indexes on > field_name, but that seems to do good. Nope, it's about the stats collected that let the planner make the right ch= oice.