X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id C843032A0EC for ; Tue, 19 Oct 2004 17:53:07 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 64106-02 for ; Tue, 19 Oct 2004 16:53:05 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id DE92E32A0A2 for ; Tue, 19 Oct 2004 17:53:04 +0100 (BST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id i9JGqnaR016866; Tue, 19 Oct 2004 12:52:50 -0400 (EDT) To: "Andrei Bintintan" Cc: pgsql-performance@postgresql.org Subject: Re: Index not used in query. Why? In-reply-to: <0bef01c4b5f8$70026ae0$0b00a8c0@forge> References: <0bef01c4b5f8$70026ae0$0b00a8c0@forge> Comments: In-reply-to "Andrei Bintintan" message dated "Tue, 19 Oct 2004 19:26:49 +0300" Date: Tue, 19 Oct 2004 12:52:49 -0400 Message-ID: <16865.1098204769@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/280 X-Sequence-Number: 8756 "Andrei Bintintan" writes: > Hi to all! I have the following query. The execution time is very big, it > doesn't use the indexes and I don't understand why... Indexes are not necessarily the best way to do a large join. > If I use the following query the indexes are used: The key reason this wins seems to be that the id_status = 4 condition is far more selective than id_status > 3 (the estimates are 52 and 36967 rows respectively ... is that accurate?) which means that the second query is inherently about 1/700th as much work. This, and not the use of indexes, is the fundamental reason why it's faster. regards, tom lane