pg.ddx.io pgsql-performance@postgresql.org mailing list archive
help / color / mirror / Atom feedInheritance vs child tables (Was Domains)
3+ messages / 2 participants
[nested] [flat]
* Inheritance vs child tables (Was Domains)
@ 2003-08-02 18:22 Francisco J Reyes <fran@natserv.net>
2003-08-02 21:50 ` Re: Inheritance vs child tables (Was Domains) Ron Johnson <ron.l.johnson@cox.net>
0 siblings, 1 reply; 3+ messages in thread
From: Francisco J Reyes @ 2003-08-02 18:22 UTC (permalink / raw)
To: Ron Johnson <ron.l.johnson@cox.net>; +Cc: pgsql General List <pgsql-general@postgresql.org>
On Fri, 1 Aug 2003, Ron Johnson wrote:
> On Fri, 2003-08-01 at 12:26, Francisco J Reyes wrote:
> > On Fri, 1 Aug 2003, Tom Lane wrote:
> [snip]
> > Currently I used inheritance to enforce the consitency
> > since a good number of fields needed to be common among the tables AND the
> > inheritted tables are basically a supperset of the data, so some times I
> > would want to access the inheritted tables and other times the parent/main
> > table.
>
> Isn't this when you'd really want child tables, instead?
I think both ways can accomplish the same (if not very simmilar
functionality), however I find using inherittance easier.
Not really sure about efficiency though.
A simple example of the type of design I am planning to do would be:
Table A
Userid
date entered
last changed
Table B inherited from A(additional fields)
person name
birthday
Table C inherited from A(additional fields)
book
isbn
comment
I plan to keep track of how many records a user has so with inherittance
it's easy to do this. I can count for the user in Table A and find out how
many records he/she has or I can count in each of the inheritted tables
and see how many there are for that particular table.
Inheritance makes it easier to see everything for a userid or just a
particular type of records.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Inheritance vs child tables (Was Domains)
2003-08-02 18:22 Inheritance vs child tables (Was Domains) Francisco J Reyes <fran@natserv.net>
@ 2003-08-02 21:50 ` Ron Johnson <ron.l.johnson@cox.net>
2003-08-03 14:27 ` Re: Inheritance vs child tables (Was Domains) Francisco J Reyes <fran@natserv.net>
0 siblings, 1 reply; 3+ messages in thread
From: Ron Johnson @ 2003-08-02 21:50 UTC (permalink / raw)
To: pgsql General List <pgsql-general@postgresql.org>
On Sat, 2003-08-02 at 13:22, Francisco J Reyes wrote:
> On Fri, 1 Aug 2003, Ron Johnson wrote:
>
> > On Fri, 2003-08-01 at 12:26, Francisco J Reyes wrote:
> > > On Fri, 1 Aug 2003, Tom Lane wrote:
> > [snip]
> > > Currently I used inheritance to enforce the consitency
> > > since a good number of fields needed to be common among the tables AND the
> > > inheritted tables are basically a supperset of the data, so some times I
> > > would want to access the inheritted tables and other times the parent/main
> > > table.
> >
> > Isn't this when you'd really want child tables, instead?
>
>
> I think both ways can accomplish the same (if not very simmilar
> functionality), however I find using inherittance easier.
> Not really sure about efficiency though.
>
> A simple example of the type of design I am planning to do would be:
>
> Table A
> Userid
> date entered
> last changed
>
>
> Table B inherited from A(additional fields)
> person name
> birthday
>
> Table C inherited from A(additional fields)
> book
> isbn
> comment
>
> I plan to keep track of how many records a user has so with inherittance
> it's easy to do this. I can count for the user in Table A and find out how
> many records he/she has or I can count in each of the inheritted tables
> and see how many there are for that particular table.
>
> Inheritance makes it easier to see everything for a userid or just a
> particular type of records.
But isn't this what LEFT OUTER JOIN is for?
Attached is a zip of the sql and results of what I mean.
Plain inner joins or LOJ with "WHERE {B|C}.whatever IS NOT NULL"
also pare things dawn.
Of course, just yesterday, in a post on -general or -performance,
I read that LEFT OUTER JOIN isn't particularly efficient in PG.
Also, wouldn't it be odd to have a userid without a name? So,
why isn't table_b combined with table_a? But all circumstances
are different, I guess...
--
+-----------------------------------------------------------------+
| Ron Johnson, Jr. Home: ron.l.johnson@cox.net |
| Jefferson, LA USA |
| |
| "I'm not a vegetarian because I love animals, I'm a vegetarian |
| because I hate vegetables!" |
| unknown |
+-----------------------------------------------------------------+
Attachments:
oj_example.zip (application/zip, 2.5K) download
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Inheritance vs child tables (Was Domains)
2003-08-02 18:22 Inheritance vs child tables (Was Domains) Francisco J Reyes <fran@natserv.net>
2003-08-02 21:50 ` Re: Inheritance vs child tables (Was Domains) Ron Johnson <ron.l.johnson@cox.net>
@ 2003-08-03 14:27 ` Francisco J Reyes <fran@natserv.net>
0 siblings, 0 replies; 3+ messages in thread
From: Francisco J Reyes @ 2003-08-03 14:27 UTC (permalink / raw)
To: Ron Johnson <ron.l.johnson@cox.net>; +Cc: pgsql General List <pgsql-general@postgresql.org>
On Sat, 2 Aug 2003, Ron Johnson wrote:
> > Inheritance makes it easier to see everything for a userid or just a
> > particular type of records.
>
> But isn't this what LEFT OUTER JOIN is for?
Yes but the more tables you have the more cumbersome it would become to do
with outer joins.
Imagine a parent table and 20 children tables. To get a count of all
records the user has I either have to do a nasty/ugly union or do 20
counts and then add them (ie doing the separate counts and keeping
track of them with a language like PHP)
> Of course, just yesterday, in a post on -general or -performance,
> I read that LEFT OUTER JOIN isn't particularly efficient in PG.
And it's probably worse when many tables are involved.
> Also, wouldn't it be odd to have a userid without a name? So,
> why isn't table_b combined with table_a?
I have a separate table with user information.
The main reason I thought of inherittance was because I need to do
accounting and keep track of how many records a user has for certain type
of data or in total. Inheritance makes this really easy.
Table A, B and C are not combined because B, C and onward have totally
different type of data and they are not one to one.
There are times when children tables make more sense like:
*person table
-person id
-name
-address
*phones
-person id
-phone type (ie fax, home, work)
-area
-phone
*emails
-person id
-email type (home, work)
-email
In my opinion a case like that is best handled with children tables.
Specially if there are only a couple of childre tables.
On my case I have about 8 inherited tables and what I believe inheritance
does for me is:
* Easy way to count both a grand total or a table per inherited table.
* Easy to work with each inheritted table, which will be very often.
* Much simpler queries/reporting
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2003-08-03 14:27 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-08-02 18:22 Inheritance vs child tables (Was Domains) Francisco J Reyes <fran@natserv.net>
2003-08-02 21:50 ` Ron Johnson <ron.l.johnson@cox.net>
2003-08-03 14:27 ` Francisco J Reyes <fran@natserv.net>
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