Re: View vs Constantly Updated Table

Поиск
Список
Период
Сортировка
От Raymond O'Donnell
Тема Re: View vs Constantly Updated Table
Дата
Msg-id 49468515.2000904@iol.ie
обсуждение исходный текст
Ответ на View vs Constantly Updated Table  (Ketema Harris <ketema@ketema.net>)
Список pgsql-general
On 15/12/2008 16:14, Ketema Harris wrote:
> if i have a "column" that is a calculation, say a bank balance -> sum of
> all the debits and credits...is it more efficient to make a view that
> executes the underlying calc query doing the math, or to create a table
> that has a column called balance that is updated for each transaction?
>
> so in the end "select balance from view" or "select balance from table" ?

It would depend on how much calculation is involved in calculating the
balance..... If you had to query tens of millions of rows to get the
balance, I'd imagine you'd do better to have a trigger updating the
balance every time a row is inserted into the account ledger table.

If there's only a small number of rows to be queried, then it's easier
and probably more robust to do the calculation in a view or a function.
I've done this with ledger containing about 500 rows with no noticeable
delay (on my laptop).

Ray.

------------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod@iol.ie
Galway Cathedral Recitals: http://www.galwaycathedral.org/recitals
------------------------------------------------------------------

В списке pgsql-general по дате отправления:

Предыдущее
От: "Adam Rich"
Дата:
Сообщение: Re: View vs Constantly Updated Table
Следующее
От: Ivan Sergio Borgonovo
Дата:
Сообщение: [SOLVED] Re: from 2 keys to serial