pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #8447: With table inheritance, indexes seems to be ignored when looking over indexed fields in base table
2+ messages / 2 participants
[nested] [flat]

* BUG #8447: With table inheritance, indexes seems to be ignored when looking over indexed fields in base table
@ 2013-09-12 14:06 stormbyte@gmail.com
  2013-09-12 15:19 ` Re: BUG #8447: With table inheritance, indexes seems to be ignored when looking over indexed fields in base table Kevin Grittner <kgrittn@ymail.com>
  0 siblings, 1 reply; 2+ messages in thread

From: stormbyte@gmail.com @ 2013-09-12 14:06 UTC (permalink / raw)
  To: pgsql-bugs

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



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #8447: With table inheritance, indexes seems to be ignored when looking over indexed fields in base table
  2013-09-12 14:06 BUG #8447: With table inheritance, indexes seems to be ignored when looking over indexed fields in base table stormbyte@gmail.com
@ 2013-09-12 15:19 ` Kevin Grittner <kgrittn@ymail.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Kevin Grittner @ 2013-09-12 15:19 UTC (permalink / raw)
  To: stormbyte@gmail.com <stormbyte@gmail.com>; pgsql-bugs

"stormbyte@gmail.com" <stormbyte@gmail.com> wrote:

> [ Seq Scan is used on empty relation, rather than Index Scan ]

> This is not the expected result.  [ ... ] it is still using
> sequential scan rather than what would be expected: Index Scan

This is not a bug.

If statistics indicate that all rows can be accessed with one page
access (to the heap) why should it use an index?

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2013-09-12 15:19 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-09-12 14:06 BUG #8447: With table inheritance, indexes seems to be ignored when looking over indexed fields in base table stormbyte@gmail.com
2013-09-12 15:19 ` Kevin Grittner <kgrittn@ymail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox