Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VK84G-0007Mh-5N for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Sep 2013 14:40:24 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VK84F-0006tX-Lo for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Sep 2013 14:40:23 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VK7Xx-0004SR-JG for pgsql-bugs@postgresql.org; Thu, 12 Sep 2013 14:07:01 +0000 Received: from mahout.postgresql.org ([2001:4800:7903:4::123]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VK7Xu-00052S-Sg for pgsql-bugs@postgresql.org; Thu, 12 Sep 2013 14:07:00 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VK7Xu-0001C1-7u for pgsql-bugs@postgresql.org; Thu, 12 Sep 2013 14:06:58 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.80) (envelope-from ) id 1VK7Xo-0003tv-Py for pgsql-bugs@postgresql.org; Thu, 12 Sep 2013 14:06:52 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: BUG #8447: With table inheritance, indexes seems to be ignored when looking over indexed fields in base table To: pgsql-bugs@postgresql.org From: stormbyte@gmail.com Message-Id: Date: Thu, 12 Sep 2013 14:06:52 +0000 X-Pg-Spam-Score: 0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 8447 Logged by: David Carlos Manuelda Email address: stormbyte@gmail.com PostgreSQL version: 9.3.0 Operating system: Gentoo Linux Description: In a simple table inheritance model, indexes seem to be ignored when looking at base table, this is a testcase: Table schema: CREATE TABLE base ( id SERIAL, email TEXT NOT NULL, PRIMARY KEY (id) ); CREATE TABLE derived1 ( otherData INTEGER, PRIMARY KEY (id) -- It is not inherited ) INHERITS (base); CREATE TABLE derived2 ( otherData2 BIGINT, PRIMARY KEY (id) -- It is not inherited ) INHERITS (base); Without any indexes the result is as expected: EXPLAIN SELECT id FROM base WHERE email='foo@foo.com'; QUERY PLAN --------------------------------------------------------------- Append (cost=0.00..48.25 rows=13 width=4) -> Seq Scan on base (cost=0.00..0.00 rows=1 width=4) Filter: (email = 'foo@foo.com'::text) -> Seq Scan on derived1 (cost=0.00..24.50 rows=6 width=4) Filter: (email = 'foo@foo.com'::text) -> Seq Scan on derived2 (cost=0.00..23.75 rows=6 width=4) Filter: (email = 'foo@foo.com'::text) Now I create triggers on each table (since it is a common field), to demonstrate how it is ignored: CREATE UNIQUE INDEX email_base_idx ON base(email); CREATE UNIQUE INDEX email_derived1_idx ON derived1(email); CREATE UNIQUE INDEX email_derived2_idx ON derived2(email); And now, see what the same select does: EXPLAIN SELECT id FROM base WHERE email='foo@foo.com'; QUERY PLAN ----------------------------------------------------------------------------------------- Append (cost=0.00..16.34 rows=3 width=4) -> Seq Scan on base (cost=0.00..0.00 rows=1 width=4) Filter: (email = 'foo@foo.com'::text) -> Index Scan using email_derived1_idx on derived1 (cost=0.15..8.17 rows=1 width=4) Index Cond: (email = 'foo@foo.com'::text) -> Index Scan using email_derived2_idx on derived2 (cost=0.15..8.17 rows=1 width=4) Index Cond: (email = 'foo@foo.com'::text) This is not the expected result. It can be seen that on base table, it is still using sequential scan rather than what would be expected: Index Scan -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs