Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 8746858F4B7 for ; Wed, 9 Nov 2011 22:41:59 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 62633-02 for ; Thu, 10 Nov 2011 02:41:53 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mail-yw0-f46.google.com (mail-yw0-f46.google.com [209.85.213.46]) by mail.postgresql.org (Postfix) with ESMTP id E8D5058F4B6 for ; Wed, 9 Nov 2011 22:41:52 -0400 (AST) Received: by ywf7 with SMTP id 7so2424992ywf.19 for ; Wed, 09 Nov 2011 18:41:53 -0800 (PST) Received: by 10.146.124.10 with SMTP id w10mr2337293yac.13.1320892913064; Wed, 09 Nov 2011 18:41:53 -0800 (PST) Received: from ?IPv6:2001:44b8:6109:9f00:2a0:c9ff:fe6e:ed8f? (2001-44b8-6109-9f00-02a0-c9ff-fe6e-ed8f.static.ipv6.internode.on.net. [2001:44b8:6109:9f00:2a0:c9ff:fe6e:ed8f]) by mx.google.com with ESMTPS id n5sm10428957yhk.1.2011.11.09.18.41.49 (version=SSLv3 cipher=OTHER); Wed, 09 Nov 2011 18:41:51 -0800 (PST) Message-ID: <4EBB39BA.5090102@ringerc.id.au> Date: Thu, 10 Nov 2011 10:40:58 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (X11; Linux i686; rv:7.0.1) Gecko/20110929 Thunderbird/7.0.1 MIME-Version: 1.0 To: "Ruslan A. Bondar" CC: Silvio Brandani , pgsql-admin@postgresql.org Subject: Re: database not using indexes References: <4EBA9AAC.9030900@tech.sdb.it> <20111109195838.237a4470@list.ru> In-Reply-To: <20111109195838.237a4470@list.ru> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201111/39 X-Sequence-Number: 38633 On 09/11/11 23:58, Ruslan A. Bondar wrote: > > Why have you decided it isn't using indexes? > If index exists - postgres will use it. Actually that's not necessarily the case. PostgreSQL will only use an index if (a) the index can be used for that kind of query and (b) using the index will be faster than doing a sequential scan. If a query requires all the data in a table, PostgreSQL is quite likely to do a sequential scan of the table, because it'll need to read every block anyway. Reading just the table (without reading the index) in order is much faster than reading the index then doing semi-random reads of the table. Additionally, not all indexes can be used for all operations. For example, a LIKE query with a prefix wildcard eg "%FRED" cannot use a btree index, so any btree index on the searched field will be ignored. -- Craig Ringer