From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: When to store data that could be derived
Date: Sun, 24 Mar 2019 03:45:27 -0500
Message-ID: <6d9e9fc2-cfd9-c36f-b813-0f2f4492da8f@gmail.com> (raw)
In-Reply-To: <6dcf59be-2029-8554-88de-88587368b50d@chagford.com>
References: <a2b19f30-9e1d-aea5-7b33-427047522461@chagford.com>
<835132f4-e1c6-d362-1b13-ad48671afe39@gmail.com>
<6dcf59be-2029-8554-88de-88587368b50d@chagford.com>
On 3/24/19 3:05 AM, Frank wrote:
>
>
> 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.
In every DBMS that I've used, the lside (left side) needs to be static (not
"a" static) instead of variable (like a function).
For example, this always leads to a sequential scan:
WHERE EXTRACT(DAY FROM DATE_FIELD) = 5
>
>>
>> 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
>
--
Angular momentum makes the world go 'round.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: ronljohnsonjr@gmail.com
Subject: Re: When to store data that could be derived
In-Reply-To: <6d9e9fc2-cfd9-c36f-b813-0f2f4492da8f@gmail.com>
References: <a2b19f30-9e1d-aea5-7b33-427047522461@chagford.com> <835132f4-e1c6-d362-1b13-ad48671afe39@gmail.com> <6dcf59be-2029-8554-88de-88587368b50d@chagford.com> <6d9e9fc2-cfd9-c36f-b813-0f2f4492da8f@gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox