From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: When to store data that could be derived
Date: Mon, 25 Mar 2019 09:06:16 -0500
Message-ID: <25f76700-bb5c-c3fb-6de3-53055fe4dffa@gmail.com> (raw)
In-Reply-To: <3b9874b0-1e69-d273-9be5-b3cf65811b54@chagford.com>
References: <a2b19f30-9e1d-aea5-7b33-427047522461@chagford.com>
<835132f4-e1c6-d362-1b13-ad48671afe39@gmail.com>
<6dcf59be-2029-8554-88de-88587368b50d@chagford.com>
<20190324124109.77rvmuzzaftf73fw@hjp.at>
<3b9874b0-1e69-d273-9be5-b3cf65811b54@chagford.com>
On 3/25/19 8:15 AM, Frank wrote:
> On 2019-03-24 2:41 PM, Peter J. Holzer wrote:
>> On 2019-03-24 10:05:02 +0200, Frank wrote:
>
> Many thanks to Peter et al for their valuable insights. I have learned a lot.
>
> > So the important part here is not whether data is added, but whether
> > data is changed. Sure, new transactions are added all the time. But is
> > it expected that the data used to derive amount_cust and amount_local
> > (e.g. the exchange rate) is changed retroactively, and if it is should
> > the computed amount change? (I'm a bit worried about the join with the
> > customers table here - what happens when a customer moves their
> > headquarters to a country with a different currency?)
>
> I think I have got both of those covered. I store the exchange rates in
> physical columns on the transaction, so the compute expressions will
> always return the same values. I have separate tables for 'organisations'
> (O) and for 'customers' (C). C has a foreign key reference to O, and most
> static data such as addresses and contact details are stored on O. So if a
> customer moved, I would create a new C record with the new currency, and
> flag the old C record as inactive. They can happily co-exist, so receipts
> can be processed against the old C record until it is paid up.
>
> I have started doing some volume tests, and at this stage, for the kind of
> volumes I am concerned about, it looks as if performance is a non-issue.
>
> I generated about 22000 invoices and 22000 receipts, over 12 customers and
> 6 months. Invoices and receipts are stored in separate tables, and a VIEW
> presents them as a single table.
>
> Using the VIEW, I selected all transactions for a given customer for a
> given month. It returned 620 rows and (on my slow desktop computer) it
> took 20ms. I can live with that.
>
> I will generate some higher volumes overnight, and see if it makes a big
> difference. If you do not hear from me, you can consider it 'problem
> solved' :-)
It would be interesting to see what the query planner tries to do with this:
WHERE
CASE
WHEN a.tran_type = 'ar_rec' THEN y.posted
WHEN a.tran_type = 'cb_rec' THEN w.posted
END = '1'
--
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: <25f76700-bb5c-c3fb-6de3-53055fe4dffa@gmail.com>
References: <a2b19f30-9e1d-aea5-7b33-427047522461@chagford.com> <835132f4-e1c6-d362-1b13-ad48671afe39@gmail.com> <6dcf59be-2029-8554-88de-88587368b50d@chagford.com> <20190324124109.77rvmuzzaftf73fw@hjp.at> <3b9874b0-1e69-d273-9be5-b3cf65811b54@chagford.com> <25f76700-bb5c-c3fb-6de3-53055fe4dffa@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