pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
inheritance performance
8+ messages / 5 participants
[nested] [flat]

* inheritance performance
@ 2005-01-21 08:19 ken <southerland@samsixedd.com>
  2005-01-21 16:14 ` Re: inheritance performance Greg Stark <gsstark@mit.edu>
  0 siblings, 1 reply; 8+ messages in thread

From: ken @ 2005-01-21 08:19 UTC (permalink / raw)
  To: pgsql-performance

Wondering ...

From a performance standpoint, is it a bad idea to use inheritance
simply as a tool for easy database building.  That is for creating
tables that share the same columns but otherwise are unrelated.

For example, let's say I have the following set of columns that are
common to many of my tables.

objectid       int,
createdby      varchar(32),
createddate    timestamp

... and let's say I create a table with these columns just so that I can
then create other tables that inherit this table so that I have these
columns in it without having to respecify them over and over again
separately for each table that contains them.

From my understanding, all the data for these columns in all the child
tables will be stored in this one parent table and that, furthermore,
there is a "hidden" column in the parent table called tableoid that
allows postgres to determine which row is stored in which child table.

Given that, is there a performance hit for queries on the child tables
because postgres has to effectively put a condition on every query based
on the tableoid of the given child table?

In other words, if say child table A has 10 million rows in it and child
B has 2 rows in it.  Will a query on child table B be slowed down by the
fact that it inherits from the same table as A.  I'm sure the answer is
absolutely yes, and so I guess I'm just looking for corroboration.

Maybe I'll be surprised!

Thanks a bunch,

Ken






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

* Re: inheritance performance
  2005-01-21 08:19 inheritance performance ken <southerland@samsixedd.com>
@ 2005-01-21 16:14 ` Greg Stark <gsstark@mit.edu>
  2005-01-21 17:58   ` Re: inheritance performance ken <southerland@samsixedd.com>
  2005-01-22 01:09   ` Re: inheritance performance Ioannis Theoharis <theohari@ics.forth.gr>
  2005-01-22 20:22   ` Re: inheritance performance Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 3 replies; 8+ messages in thread

From: Greg Stark @ 2005-01-21 16:14 UTC (permalink / raw)
  To: ken <southerland@samsixedd.com>; +Cc: pgsql-performance


ken <southerland@samsixedd.com> writes:

> >From my understanding, all the data for these columns in all the child
> tables will be stored in this one parent table 

No, all the data is stored in the child table.

> and that, furthermore, there is a "hidden" column in the parent table called
> tableoid that allows postgres to determine which row is stored in which
> child table.

That's true.

> Given that, is there a performance hit for queries on the child tables
> because postgres has to effectively put a condition on every query based on
> the tableoid of the given child table?

There's a performance hit for the extra space required to store the tableoid.
This means slightly fewer records will fit on a page and i/o requirements will
be slightly higher. This will probably only be noticeable on narrow tables,
and even then probably only on large sequential scans.

There's also a slight performance hit because there's an optimization that the
planner does normally for simple queries that isn't currently done for either
UNION ALL or inherited tables. I think it's planned to fix that soon.

> In other words, if say child table A has 10 million rows in it and child
> B has 2 rows in it.  Will a query on child table B be slowed down by the
> fact that it inherits from the same table as A.  I'm sure the answer is
> absolutely yes, and so I guess I'm just looking for corroboration.

No, it isn't slowed down by the records in A. It's slightly slower because it
is an inherited table, but that impact is the same regardless of what other
tables inherit from the same parent and how many records are in them.

-- 
greg




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

* Re: inheritance performance
  2005-01-21 08:19 inheritance performance ken <southerland@samsixedd.com>
  2005-01-21 16:14 ` Re: inheritance performance Greg Stark <gsstark@mit.edu>
@ 2005-01-21 17:58   ` ken <southerland@samsixedd.com>
  2005-01-21 18:15     ` Re: inheritance performance Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  2005-01-21 18:16     ` Re: inheritance performance Greg Stark <gsstark@mit.edu>
  2 siblings, 2 replies; 8+ messages in thread

From: ken @ 2005-01-21 17:58 UTC (permalink / raw)
  To: Greg Stark <gsstark@mit.edu>; +Cc: pgsql-performance

On Fri, 2005-01-21 at 08:14, Greg Stark wrote:
> ken <southerland@samsixedd.com> writes:
> 
> > >From my understanding, all the data for these columns in all the child
> > tables will be stored in this one parent table 
> 
> No, all the data is stored in the child table.

So if you perform a "select * from parent" then does postgres internally
create a union between all the child tables and return you the results
of that?

ken





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

* Re: inheritance performance
  2005-01-21 08:19 inheritance performance ken <southerland@samsixedd.com>
  2005-01-21 16:14 ` Re: inheritance performance Greg Stark <gsstark@mit.edu>
  2005-01-21 17:58   ` Re: inheritance performance ken <southerland@samsixedd.com>
@ 2005-01-21 18:15     ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
  1 sibling, 0 replies; 8+ messages in thread

From: Christopher Kings-Lynne @ 2005-01-21 18:15 UTC (permalink / raw)
  To: ken <southerland@samsixedd.com>; +Cc: Greg Stark <gsstark@mit.edu>; pgsql-performance

> So if you perform a "select * from parent" then does postgres internally
> create a union between all the child tables and return you the results
> of that?

Basically, yes.  Kind of.

Chris



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

* Re: inheritance performance
  2005-01-21 08:19 inheritance performance ken <southerland@samsixedd.com>
  2005-01-21 16:14 ` Re: inheritance performance Greg Stark <gsstark@mit.edu>
  2005-01-21 17:58   ` Re: inheritance performance ken <southerland@samsixedd.com>
@ 2005-01-21 18:16     ` Greg Stark <gsstark@mit.edu>
  1 sibling, 0 replies; 8+ messages in thread

From: Greg Stark @ 2005-01-21 18:16 UTC (permalink / raw)
  To: ken <southerland@samsixedd.com>; +Cc: Greg Stark <gsstark@mit.edu>; pgsql-performance

ken <southerland@samsixedd.com> writes:

> On Fri, 2005-01-21 at 08:14, Greg Stark wrote:
> > ken <southerland@samsixedd.com> writes:
> > 
> > > >From my understanding, all the data for these columns in all the child
> > > tables will be stored in this one parent table 
> > 
> > No, all the data is stored in the child table.
> 
> So if you perform a "select * from parent" then does postgres internally
> create a union between all the child tables and return you the results
> of that?

Essentially, yes.

-- 
greg




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

* Re: inheritance performance
  2005-01-21 08:19 inheritance performance ken <southerland@samsixedd.com>
  2005-01-21 16:14 ` Re: inheritance performance Greg Stark <gsstark@mit.edu>
@ 2005-01-22 01:09   ` Ioannis Theoharis <theohari@ics.forth.gr>
  2005-01-22 04:22     ` Re: inheritance performance Greg Stark <gsstark@mit.edu>
  2 siblings, 1 reply; 8+ messages in thread

From: Ioannis Theoharis @ 2005-01-22 01:09 UTC (permalink / raw)
  To: Greg Stark <gsstark@mit.edu>; +Cc: ken <southerland@samsixedd.com>; pgsql-performance



On Fri, 21 Jan 2005, Greg Stark wrote:

> There's also a slight performance hit because there's an optimization that the
> planner does normally for simple queries that isn't currently done for either
> UNION ALL or inherited tables. I think it's planned to fix that soon.

Can you explain me in more details what kind of optimization is missing in
that case?



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

* Re: inheritance performance
  2005-01-21 08:19 inheritance performance ken <southerland@samsixedd.com>
  2005-01-21 16:14 ` Re: inheritance performance Greg Stark <gsstark@mit.edu>
  2005-01-22 01:09   ` Re: inheritance performance Ioannis Theoharis <theohari@ics.forth.gr>
@ 2005-01-22 04:22     ` Greg Stark <gsstark@mit.edu>
  0 siblings, 0 replies; 8+ messages in thread

From: Greg Stark @ 2005-01-22 04:22 UTC (permalink / raw)
  To: Ioannis Theoharis <theohari@ics.forth.gr>; +Cc: Greg Stark <gsstark@mit.edu>; ken <southerland@samsixedd.com>; pgsql-performance

Ioannis Theoharis <theohari@ics.forth.gr> writes:

> Can you explain me in more details what kind of optimization is missing in
> that case?

Uh, no I can't really. It was mentioned on the mailing list with regards to
UNION ALL specifically. I think it applied to inherited tables as well but I
wouldn't know for sure. You could search the mailing list archives for recent
discussions of partitioned tables.

In any acse it was a purely technical detail. Some step in the processing of
the data that could be skipped if there weren't any actual changes to the data
being done or something like that. It made a small but noticeable difference
in the runtime but nothing that made the technique infeasible.

-- 
greg




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

* Re: inheritance performance
  2005-01-21 08:19 inheritance performance ken <southerland@samsixedd.com>
  2005-01-21 16:14 ` Re: inheritance performance Greg Stark <gsstark@mit.edu>
@ 2005-01-22 20:22   ` Tom Lane <tgl@sss.pgh.pa.us>
  2 siblings, 0 replies; 8+ messages in thread

From: Tom Lane @ 2005-01-22 20:22 UTC (permalink / raw)
  To: Greg Stark <gsstark@mit.edu>; +Cc: ken <southerland@samsixedd.com>; pgsql-performance

Greg Stark <gsstark@mit.edu> writes:
> ken <southerland@samsixedd.com> writes:
>> From my understanding, all the data for these columns in all the child
>> tables will be stored in this one parent table 

> No, all the data is stored in the child table.

Correct ...

>> and that, furthermore, there is a "hidden" column in the parent table called
>> tableoid that allows postgres to determine which row is stored in which
>> child table.

> That's true.
> There's a performance hit for the extra space required to store the tableoid.

Bzzzt ...

tableoid isn't actually stored anywhere on disk.  It's a pseudo-column
that is generated during row fetch.  (It works for all tables, not only
inheritance children.)

>> Given that, is there a performance hit for queries on the child tables
>> because postgres has to effectively put a condition on every query based on
>> the tableoid of the given child table?

AFAIR, a query directed specifically to a child table is *completely*
unaware of the fact that that table is a child.  Only queries directed
to a parent table, which have to implicitly UNION in the children, pay
any price for inheritance.

			regards, tom lane



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


end of thread, other threads:[~2005-01-22 20:22 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-01-21 08:19 inheritance performance ken <southerland@samsixedd.com>
2005-01-21 16:14 ` Greg Stark <gsstark@mit.edu>
2005-01-21 17:58   ` ken <southerland@samsixedd.com>
2005-01-21 18:15     ` Christopher Kings-Lynne <chriskl@familyhealth.com.au>
2005-01-21 18:16     ` Greg Stark <gsstark@mit.edu>
2005-01-22 01:09   ` Ioannis Theoharis <theohari@ics.forth.gr>
2005-01-22 04:22     ` Greg Stark <gsstark@mit.edu>
2005-01-22 20:22   ` Tom Lane <tgl@sss.pgh.pa.us>

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