X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id D6EC99FA3A6 for ; Fri, 26 May 2006 11:53:53 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 56672-07-4 for ; Fri, 26 May 2006 11:53:42 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.234]) by postgresql.org (Postfix) with ESMTP id 708F99FA279 for ; Fri, 26 May 2006 11:53:42 -0300 (ADT) Received: by wr-out-0506.google.com with SMTP id 50so83628wri for ; Fri, 26 May 2006 07:53:40 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=CAzNfvatJtE0pE5FRJgEqoLHcZL1s5wqHpiHhEtC4Cmk6CnqFwSgkJpf2ddZysyaNJ3aD5gS8CaqZjm2UGHcLftgqeYhkjrBcY0iqDWHMHHaCk9qkvH2DOEnEY6p2xKXjB1KvuXeJb/OrS9mqlEMUFoXoBEjJ4fs5hO7R4OFSqg= Received: by 10.64.220.7 with SMTP id s7mr416427qbg; Fri, 26 May 2006 07:53:38 -0700 (PDT) Received: by 10.65.137.19 with HTTP; Fri, 26 May 2006 07:53:38 -0700 (PDT) Message-ID: Date: Fri, 26 May 2006 10:53:38 -0400 From: "Merlin Moncure" To: "Alban Hertroys" Subject: Re: [SQL] (Ab)Using schemas and inheritance Cc: "Jorge Godoy" , "Jim C. Nasby" , pgsql-general@postgresql.org In-Reply-To: <4476C991.5060707@magproductions.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <200605231716.58784.jgodoy@gmail.com> <200605241221.55060.jgodoy@gmail.com> <44748493.5090107@magproductions.nl> <200605241410.46202.jgodoy@gmail.com> <4476C991.5060707@magproductions.nl> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/1303 X-Sequence-Number: 96095 to all: maybe I can be of some help here. I think schemas are definately the way to go. I've used them quite a bit, previously with an accounting application which used schemas to separate company. Right now I am in development of a major project which will use them even more extensively, following an evalution of other methods of isloating data for scalability reasons. The mammoth table approach (company id in every table) is very clean and the best approach from a academic perspective but unfortunately you can run into scalability problems if your tables are very large. An ideal SQL database would automagically do everything for you without having to worry about it (no such database exists AFAIK). The major downsides of using schemas in an application can be mitigated...for example clever use of dynamic sql functions and scripts can go a long way in helping with updates that have to run across mutiple schemas. The benifits of schemas are pretty nice, you get the performance advantages of partitioning and you can manipulate the search path for easy switching...just make sure to force a reconnect to get all those stored procedures to relearn all the tables they use if you keep your functions in a shared area (usually a good idea). Table partitioning and inheritance look good on the surface but there are a number of 'gotchas' that can hold you back from using them effectively. Foreign keys are a mess, and compelex queries can be problematic...the new constraint exclusion feature helps, but there is a way to go IMO. by the way, the \d query in psql maps to a fairly complex sql statement, you can beat it by going right to the pg catalogs if performance is an issue, or materialize your catalogs to an indexed table. If you have a lot of tables (1000s) you will definately want to prepare everything, meaning use views, procedures, and prepared statements liberally. I would also take careful note of Jim's FSM comments and keep a careful eye on that. Merlin