X-Original-To: pgsql-performance@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 95FAC475458 for ; Thu, 17 Apr 2003 13:48:17 -0400 (EDT) Received: from smtp.kocks.com (adsl-66-124-90-234.dsl.snfc21.pacbell.net [66.124.90.234]) by postgresql.org (Postfix) with ESMTP id 4205A4758F1 for ; Thu, 17 Apr 2003 13:48:16 -0400 (EDT) Received: from GARP (fwinside.kocks.com [10.10.10.1]) by smtp.kocks.com (mail) with SMTP id 2208128BDA for ; Thu, 17 Apr 2003 10:48:16 -0700 (PDT) Reply-To: From: "dex" To: Subject: Performance of Inherits versus Views Date: Thu, 17 Apr 2003 10:48:16 -0700 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Importance: Normal X-Spam-Status: No, hits=-8.8 required=5.0 tests=BAYES_20,MSGID_GOOD_EXCHANGE autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/156 X-Sequence-Number: 1662 Hello, Is it more efficient to use a schema with Inherits or schema with Views. I can see logically how to use both for my case and I'm trying to make a decision. I would guess that the overhead of the queries against inherited tables is higher than queries against views, but I don't know. At the bottom of this message, I've included the cities / capitals examples implemented both as schema using inheritance and as schema using views. Using the example, I could make queries such as: SELECT name FROM capitals; -- capitals in inherited or SELECT name FROM capital_cities; -- capital cities is a view But which one would be faster? In my real world example, I will either have one small base class 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). Or, it could be implemented as one larger (but not huge) lookup table with many views against that lookup table. What would you do? 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);