Re: Inheritance vs child tables (Was Domains)

From: Ron Johnson <ron(dot)l(dot)johnson(at)cox(dot)net>
To: pgsql General List <pgsql-general(at)postgresql(dot)org>
Subject: Re: Inheritance vs child tables (Was Domains)
Date: 2003-08-02 21:50:33
Message-ID: 1059861033.24817.57.camel@haggis
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-performance

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(dot)l(dot)johnson(at)cox(dot)net |
| Jefferson, LA USA |
| |
| "I'm not a vegetarian because I love animals, I'm a vegetarian |
| because I hate vegetables!" |
| unknown |
+-----------------------------------------------------------------+

Attachment Content-Type Size
oj_example.zip application/zip 2.5 KB

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ron Johnson 2003-08-02 22:02:46 Re: Domains (Was [PERFORM] Views With Unions)
Previous Message Ron Johnson 2003-08-02 21:14:28 Re: How to do?

Browse pgsql-performance by date

  From Date Subject
Next Message Ron Johnson 2003-08-03 07:09:51 testing
Previous Message Francisco J Reyes 2003-08-02 18:22:39 Inheritance vs child tables (Was Domains)