Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 6770A2E01A4 for ; Fri, 14 Mar 2008 15:59:23 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 40683-07 for ; Fri, 14 Mar 2008 15:59:09 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sn.sai.msu.ru (sn.sai.msu.ru [195.208.220.215]) by postgresql.org (Postfix) with ESMTP id 5C49E2E0177 for ; Fri, 14 Mar 2008 15:59:09 -0300 (ADT) Received: from sn.sai.msu.ru (localhost [127.0.0.1]) by sn.sai.msu.ru (8.14.1/8.12.8) with ESMTP id m2EIx5Gk025990; Fri, 14 Mar 2008 21:59:05 +0300 Received: from localhost (megera@localhost) by sn.sai.msu.ru (8.14.1/8.12.8/Submit) with ESMTP id m2EIx5qe025987; Fri, 14 Mar 2008 21:59:05 +0300 X-Authentication-Warning: sn.sai.msu.ru: megera owned process doing -bs Date: Fri, 14 Mar 2008 21:59:05 +0300 (MSK) From: Oleg Bartunov X-X-Sender: megera@sn.sai.msu.ru To: Kynn Jones cc: pgsql-performance@postgresql.org Subject: Re: The "many nulls" problem In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.568 tagged_above=0 required=5 tests=AWL=-1.557, DNS_FROM_RFC_BOGUSMX=2.125 X-Spam-Level: X-Archive-Number: 200803/312 X-Sequence-Number: 29266 Kynn, have you seen contrib/hstore ? You can have one table with common attributes and hide others in hstore Oleg On Fri, 14 Mar 2008, Kynn Jones wrote: > It often happens that a particular pieces of information is non-null for a > small minority of cases. A superficially different manifestation of this is > when two pieces of information are identical in all but a small minority of > cases. This can be easily mapped to the previous description by defining a > null in one column to mean that its contents should be obtained from those > of another column. A further variant of this is when one piece of > information is a simple function of another one in all but a small minority > of cases. > > (BTW, I vaguely recall that RDb theorists have a technical term for this > particular design issue, but I don't remember it.) > > In all these cases, the design choice, at least according to RDb's 101, is > between including a column in the table that will be NULL most of the time, > or defining a second auxiliary column that references the first one and > holds the non-redundant information for the minority of cases for which this > is necessary (and maybe define a VIEW that includes all the columns). > > But for me it is a frequent occurrence that my quaint and simple RDb's 101 > reasoning doesn't really apply for PostgreSQL. Basically, Pg is too smart > for it! For example, does a large proportion of NULLs really imply a lot of > wasted space? Maybe this is true for fixed-length data types, but what > about for type TEXT or VARCHAR? > > Just to be concrete, consider the case of a customers database for some home > shopping website. Suppose that, as it happens, for the majority of this > site's customers, the shipping and billing addresses are identical. Or > consider the scenario of a company in which, for most employees, the email > address can be readily computed from the first and last name using the rule > First M. Last => first_last@acme.com, but the company allows some > flexibility for special cases (e.g. for people like Yasuhiro Tanaka who's > known to everyone by his nickname, Yaz, the email is > yaz_tanaka@acme.combecause hardly anyone remembers or even knows his > full name.) > > What's your schema design approach for such situations? How would you go > about deciding whether the number of exceptional cases is small enough to > warrant a second table? Of course, one could do a systematic profiling of > various possible scenarios, but as a first approximation what's your > rule-of-thumb? > > TIA! > > Kynn > Regards, Oleg _____________________________________________________________ Oleg Bartunov, Research Scientist, Head of AstroNet (www.astronet.ru), Sternberg Astronomical Institute, Moscow University, Russia Internet: oleg@sai.msu.su, http://www.sai.msu.su/~megera/ phone: +007(495)939-16-83, +007(495)939-23-83