Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 536211337B49 for ; Fri, 18 Mar 2011 08:41:56 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 74148-03 for ; Fri, 18 Mar 2011 11:41:47 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mailout.thl.fi (mailout.thl.fi [193.167.195.59]) by mail.postgresql.org (Postfix) with ESMTP id 80A611337B69 for ; Fri, 18 Mar 2011 08:41:45 -0300 (ADT) Received: from mailout (localhost.localdomain [127.0.0.1]) by mailout.thl.fi (8.13.1/8.13.1) with SMTP id p2IBfhvc001000; Fri, 18 Mar 2011 13:41:43 +0200 Received: from 172.24.32.92 (172.24.32.92) by mailout (F-Secure/fsigk_smtp/580/mailout); Fri, 18 Mar 2011 13:41:43 +0200 (EET) X-Virus-Status: clean(F-Secure/fsigk_smtp/580/mailout) Received: from exhub1.stakes.fi (exhub1.stakes.fi [10.10.3.203]) by mail-hub.thl.fi (8.13.8/8.13.8) with ESMTP id p2IBfhc3031509; Fri, 18 Mar 2011 13:41:43 +0200 Received: from [172.22.12.109] (172.22.12.109) by exhub1.stakes.fi (10.10.3.203) with Microsoft SMTP Server id 8.2.176.0; Fri, 18 Mar 2011 13:41:43 +0200 Message-ID: <4D834921.6060705@thl.fi> Date: Fri, 18 Mar 2011 13:59:29 +0200 From: =?UTF-8?B?QW5zc2kgS8Okw6RyacOkaW5lbg==?= User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.14) Gecko/20110223 Thunderbird/3.1.8 MIME-Version: 1.0 To: Vitalii Tymchyshyn CC: "pgsql-performance@postgresql.org" Subject: Re: Disabling nested loops - worst case performance References: <4D8306A7.7020205@thl.fi> <4D833953.7080607@gmail.com> In-Reply-To: <4D833953.7080607@gmail.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-10 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201103/210 X-Sequence-Number: 42889 On 03/18/2011 12:52 PM, Vitalii Tymchyshyn wrote: > If your queries work on single attribute, you can try adding partial > indexes for different attributes. Note that in this case parameterized > statements may prevent index usage, so check also with attribute id inlined. > > Best regards, Vitalii Tymchyshyn Unfortunately this does not help for the statistics, and (I guess) nested loops will still be used when joining: hot2=> explain analyze select * from attr_value where attr_tunniste = 'suhde_hyvaksytty' and arvo_text = 't'; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------- Index Scan using attr_value_arvo_text_idx1 on attr_value (cost=0.00..343.59 rows=152 width=118) (actual time=0.076..7.768 rows=3096 loops=1) Index Cond: (arvo_text = 't'::text) Filter: ((attr_tunniste)::text = 'suhde_hyvaksytty'::text) Total runtime: 10.855 ms (4 rows) hot2=> create index suhde_hyvaksytty_idx on attr_value(arvo_text) where attr_tunniste = 'suhde_hyvaksytty'; CREATE INDEX hot2=> analyze attr_value; hot2=> explain analyze select * from attr_value where attr_tunniste = 'suhde_hyvaksytty' and arvo_text = 't'; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------- Index Scan using suhde_hyvaksytty_idx on attr_value (cost=0.00..43.72 rows=152 width=118) (actual time=0.093..4.776 rows=3096 loops=1) Index Cond: (arvo_text = 't'::text) Total runtime: 7.817 ms (3 rows) - Anssi