pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: dex <dex@bridge3.com>
To: pgsql-performance@postgresql.org
Subject: Is there a performance between Inherits and Views?
Date: Tue, 15 Apr 2003 23:10:44 -0700
Message-ID: <AIEFJBJIIGJICIKAMAAIAECGCFAA.dex@bridge3.com> (raw)

Hello,

In building a schema, I'd like to know if it makes sense
from a performance standpoint to use views instead of
an object oriented structure (i.e. inherits).

I would guess that the overhead of the queries against
inherited tables is higher than queries against views,
but I don't know.

In the cities / capitals example below, I could make
queries such as:

SELECT name FROM capitals;

or

SELECT name FROM capital_cities;

But which one would be faster?  In my real world example,
I will have one small base object table (i.e. cities in 
the example) and many direct descendents of that base
table (e.g. capitals, beaches, national parks, suburbs
in the example).  This could be implemented as one
small base table and with many tables inheriting from
the base.  Or, it could be implemented as one larger 
(but not huge) lookup table with many views.

What's the better choice from a performance standpoint?

Thanks!

--dex


--
--  Schema with Inherits
--
CREATE TABLE cities (
    name            text,
    population      float,
    altitude        int     -- (in ft)
  );

  CREATE TABLE capitals (
    state           char(2)
  ) INHERITS (cities);


--
--  Schema with View
--
CREATE TABLE all_cities (
    name            text,
    population      float,
    altitude        int,
    state           char(2)
);

CREATE VIEW just_cities AS SELECT 
	all_cities.name, 
	all_cities.population, 
	all_cities.altitude 
FROM all_cities;

-- or perhaps with a where clause, as in
CREATE VIEW capital_cities AS SELECT 
	all_cities.name, 
	all_cities.population, 
	all_cities.altitude 
FROM all_cities WHERE (all_cities.state IS NOT NULL);




Message-ID: <AIEFJBJIIGJICIKAMAAIAECGCFAA.dex@bridge3.com>
Permalink:  ../AIEFJBJIIGJICIKAMAAIAECGCFAA.dex@bridge3.com/
Also on:    postgresql.org/message-id/AIEFJBJIIGJICIKAMAAIAECGCFAA.dex@bridge3.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: dex@bridge3.com
  Subject: Re: Is there a performance between Inherits and Views?
  In-Reply-To: <AIEFJBJIIGJICIKAMAAIAECGCFAA.dex@bridge3.com>
  References: <AIEFJBJIIGJICIKAMAAIAECGCFAA.dex@bridge3.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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