Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fOvZi-0004ki-Ga for pgsql-general@arkaria.postgresql.org; Sat, 02 Jun 2018 01:43:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fOvZg-0006Oz-VW for pgsql-general@arkaria.postgresql.org; Sat, 02 Jun 2018 01:43:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fOvZg-0006Oq-Kv for pgsql-general@lists.postgresql.org; Sat, 02 Jun 2018 01:43:20 +0000 Received: from mail-pl0-x244.google.com ([2607:f8b0:400e:c01::244]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fOvZd-0007JF-8q for pgsql-general@lists.postgresql.org; Sat, 02 Jun 2018 01:43:19 +0000 Received: by mail-pl0-x244.google.com with SMTP id 30-v6so16259212pld.13 for ; Fri, 01 Jun 2018 18:43:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=references:user-agent:from:to:cc:subject:in-reply-to:date :message-id:mime-version:content-transfer-encoding; bh=2Zv1mTCxNLVdZGG77aaGBTRpILK87JyaV4XxYT/eruk=; b=P1LQkMiyciOCFQWWgem+yNzITB0tIRcPIHJrhbmsNGR6JllwWvZ9W8Kq/KsF6CEQlI buWBPO/iLBvdCfxwPLT1a24hI3RPamQqOW4vJfPyQwMx9yOB1Bow+jpYxmU1wUTZjJfW /qb3coY0/R/2bVN3UQOO6Mpo1ZggbugUP/5KvXScaB6zOFCAXy8rU/GgLP9tccI0bzKA IGZgYs5LyKjNywtqNNZpgZ933GUab/3ZX7urbGwUQVJ9uKtQaFsR+XqYUf7UeWYEySVS YINQeOJSkuvPI5OY8dh4j2TG+AuBG+MiEObfN/Fg/EyisFwkLDJAyBeGt/aX5F4zwPfT mUjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject :in-reply-to:date:message-id:mime-version:content-transfer-encoding; bh=2Zv1mTCxNLVdZGG77aaGBTRpILK87JyaV4XxYT/eruk=; b=FF1xik44vrJwGLIyxxSKO2fhtZwTgCBqoHY0J1K5kB5jXhX/WzhttHTWW9yb4pVRaZ xazHsAkqZr/N/A7CR8xi+aqnbRSDRtjzOmcBmnrdqZTS2zqsBiV1W4wNcX27kdg+/HZn vjfaAQcymuKOca90SfbrezfBhknEJV2d6xDEgBnc8hfmH2GqM+1NA/iX9x/JIbguwATI Mzjx0Gz1dkBeki25/HH3778qIHi9cS2Dc0R98fOfLiKrm45E+KFDNcXd0IRashO49Xx4 GQ7tEXLvkpCFcIZDHp0DPm2oM/EI1JRQmxfl2wYQULcSTJhGjpRn2taVKHZeWCedjf4j Ao7Q== X-Gm-Message-State: ALKqPwcL9SvjZzH/4cIX+50gCThHu/ex1oxgvwpH7xOW1jtGeOyZUc4A QRqJ72oJ0f8T1MVSEK39LuuLE3Og X-Google-Smtp-Source: ADUXVKJoJb1oQtM1cnjoNwFzVIOd2KFAzwiaFFxsMSSvctHwPLPsTRk6JZBTCGiLOzL8n9DLeBbr5Q== X-Received: by 2002:a17:902:a703:: with SMTP id w3-v6mr13565303plq.111.1527903794838; Fri, 01 Jun 2018 18:43:14 -0700 (PDT) Received: from tim-desktop (2001-44b8-31f2-bb00-3990-3d4c-e497-ff01.static.ipv6.internode.on.net. [2001:44b8:31f2:bb00:3990:3d4c:e497:ff01]) by smtp.gmail.com with ESMTPSA id v186-v6sm70235727pfb.45.2018.06.01.18.43.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 01 Jun 2018 18:43:13 -0700 (PDT) References: User-agent: mu4e 0.9.18; emacs 26.1 From: Tim Cross To: Olivier Gautherot Cc: Guyren Howe , pgsql-general@lists.postgresql.org Subject: Re: Whither 1:1? In-reply-to: Date: Sat, 02 Jun 2018 11:43:09 +1000 Message-ID: <87woviufo2.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Olivier Gautherot writes: > On Fri, Jun 1, 2018 at 12:52 PM, Guyren Howe wrote: > >> It=E2=80=99s come to my attention that what seems an obvious and useful = database >> design pattern =E2=80=94 1:1 relations between tables by having a shared= primary >> key =E2=80=94 is hardly discussed or used. >> >> It would seem to be a very simple pattern, and useful to avoid storing >> nulls or for groups of fields that tend to be used together. >> >> Thoughts? Is there some downside I can=E2=80=99t see? >> > > You will get a benefit in terms of space only if the optional fields in t= he > second table exist in a reduced number of instances - and the second table > is significantly wider. This can make a difference on big tables but this > gain may be offset by the cost of the join. In this perspective, I don't > think that there is a clear benefit or drawback: it should be evaluated on > a case-by-case basis. > Well said. Like many database design decisions, there are more guidelines than rules. Nearly all decisions have pros and cons. Therefore, you need to assess on a per project basis. In addition to the structure of data (size, null frequency etc), you also need to consider how the data is used. It is also important to consider who will be using the data, how they will access it and what level of sophistication/understanding they have. The clarity of your data model is also important as future decisions may be made by others and the better they understand the design/model, the higher the likelihood the system will evolve in a sane and maintainable manner. There other point to remember is that all designs often have an element of surprise - you make a decision under an assumption which turns out not to hold due to variables you didn't consider or don't have control over. Sometimes there are alternatives which may actually perform better because they are optimised within the system - for example, some of the benefits for this approach could be realised using partitions.=20 I have used this technique, but from memory, this was done as the system evolved and we found there was a benefit from having a smaller 'main' table. It isn't a design decision I recall adopting during an initial modelling of the system, but it may be something to consider once you find a performance problem (along with other options) which needs to be addressed.=20 I'm not aware of any guideline or school of thought which rules out this as an option. Possibly the reason it appears to be used infrequently is because it doesn't realise the benefits you might expect or is simply not an problem in a majority of use cases.=20 Tim --=20 Tim Cross