Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h7y8F-0006wu-3U for pgsql-general@arkaria.postgresql.org; Sun, 24 Mar 2019 08:05:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h7y8D-00085H-R3 for pgsql-general@arkaria.postgresql.org; Sun, 24 Mar 2019 08:05:25 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1h7y8D-00085A-Io for pgsql-general@lists.postgresql.org; Sun, 24 Mar 2019 08:05:25 +0000 Received: from securemail-pl-omx11.synaq.com ([196.35.198.108]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h7y86-00081P-Bv for pgsql-general@lists.postgresql.org; Sun, 24 Mar 2019 08:05:25 +0000 Received: from [197.90.32.26] (helo=[192.168.0.8]) by securemail-pl-omx11.synaq.com with esmtpa (Exim 4.90_1) (envelope-from ) id 1h7y7t-0006oQ-A5 for pgsql-general@lists.postgresql.org; Sun, 24 Mar 2019 10:05:08 +0200 Subject: Re: When to store data that could be derived To: pgsql-general@lists.postgresql.org References: <835132f4-e1c6-d362-1b13-ad48671afe39@gmail.com> From: Frank Message-ID: <6dcf59be-2029-8554-88de-88587368b50d@chagford.com> Date: Sun, 24 Mar 2019 10:05:02 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.0 MIME-Version: 1.0 In-Reply-To: <835132f4-e1c6-d362-1b13-ad48671afe39@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-SYNAQ-Pinpoint-Information: Please contact SYNAQ for more information X-SYNAQ-Pinpoint-ID: 1h7y7t-0006oQ-A5 X-SYNAQ-Pinpoint: Found to be clean X-SYNAQ-Pinpoint-SpamCheck: not spam, SpamAssassin (not cached, score=-1.8, required 9, autolearn=disabled, ALL_TRUSTED -1.00, DCC_REPUT_00_12 -0.80) X-Pinpoint-From: frank@chagford.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2019-03-24 9:25 AM, Ron wrote: > On 3/24/19 1:42 AM, Frank wrote: >> Hi all >> >> As I understand it, a  general rule of thumb is that you should never >> create a physical column if the data could be derived from existing >> columns. A possible reason for breaking this rule is for performance >> reasons. >> >> I have a situation where I am considering breaking the rule, but I am >> not experienced enough in SQL to know if my reason is valid. I would >> appreciate it if someone could glance at my 'before' and 'after' >> scenarios and see if, from a 'gut-feel' point of view, I should proceed. >> [snip] > > Sure the second query joins a lot of tables, but is pretty straightforward. > > What REALLY worries me is whether or not the query optimiser would look > at the WHERE CASE, run away screaming and then make it use sequential > scans. Thus, even query #1 would be slow. > I had not realised that. I hope someone else chimes in on this. > > Is this a historical data set that's never updated, or current data > that's constantly added to? > It is the latter - current data constantly added to. Frank