X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 72E1B9DC805 for ; Fri, 10 Mar 2006 12:45:54 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 99057-10 for ; Fri, 10 Mar 2006 12:45:49 -0400 (AST) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 7391C9DC8A3 for ; Fri, 10 Mar 2006 12:45:48 -0400 (AST) Received: from office1.i-free.ru (office1.i-free.ru [81.222.216.82]) by svr4.postgresql.org (Postfix) with ESMTP id 6D7D95AF09C for ; Fri, 10 Mar 2006 16:45:48 +0000 (GMT) Received: from [192.168.0.250] (helo=deepcore.i-free.ru) by office1.i-free.ru with smtp (Exim 3.36 #1 (Debian)) id 1FHkkK-0008EB-00 for ; Fri, 10 Mar 2006 19:45:44 +0300 Date: Fri, 10 Mar 2006 19:45:45 +0300 From: Evgeny Gridasov To: pgsql-performance@postgresql.org Subject: one-field index vs. multi-field index planner estimates Message-Id: <20060310194545.be002083.eugrid@fpm.kubsu.ru> In-Reply-To: <200603101113.35868.jdevisser@digitalfairway.com> References: <6BCB9D8A16AC4241919521715F4D8BCEA35109@algol.sollentuna.se> <200603101113.35868.jdevisser@digitalfairway.com> X-Mailer: Sylpheed version 2.2.1 (GTK+ 2.6.2; i686-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.103 required=5 tests=[AWL=0.103] X-Spam-Score: 0.103 X-Spam-Level: X-Archive-Number: 200603/134 X-Sequence-Number: 17571 Hello. Recently I've discovered an interesting thing (Postgres version 8.1.3): example table: CREATE TABLE test ( id INT, name TEXT, comment TEXT, phone TEXT, visible BOOLEAN ); then, CREATE INDEX i1 ON test(phone); CREATE INDEX i2 ON test(phone, visible); CREATE INDEX i3 ON test(phone, visible) WHERE visible; then insert lot's of data and try to execute query like: SELECT * FROM test WHERE phone='12345' AND visible; uses index i1, and filters all visible fields. When I drop index i1, postgres starts to use index i2 and the query began to work much more faster. When I drop index i2, postgres uses index i3 which is faster than i2 ofcourse. I've noticed that planner estimated all queries for all three cases with the same cost. So, is it a planner bad estimate or what? -- Evgeny Gridasov Software Engineer I-Free, Russia