extract(field from timestamp) vs date dimension

Поиск
Список
Период
Сортировка
От Tobias Brox
Тема extract(field from timestamp) vs date dimension
Дата
Msg-id 20070123124937.GA13122@oppetid.no
обсуждение исходный текст
Ответы Re: extract(field from timestamp) vs date dimension  ("Chad Wagner" <chad.wagner@gmail.com>)
Re: extract(field from timestamp) vs date dimension  ("Merlin Moncure" <mmoncure@gmail.com>)
Список pgsql-performance
Does anyone have experience with using postgres for data warehousing?
Right, I saw one post suggestion to use mysql for a mostly read-only
database ... but anyway, I think it's not a question to change the
database platform for this project, at least not today ;-)

Ralph Kimball seems to be some kind of guru on data warehousing, and
in his books he's strongly recommending to have a date dimension -
simply a table describing all dates in the system, and having
attributes for what day of the week it is, month, day of the month,
week number, bank holiday, anything special, etc.  Well, it does make
sense if adding lots of information there that cannot easily be pulled
out from elsewhere - but as for now, I'm mostly only interessted in
grouping turnover/profit by weeks/months/quarters/years/weekdays.  It
seems so much bloated to store this information, my gut feeling tells it
should be better to generate them on the fly.  Postgres even allows to
create an index on an expression.

The question is ... I'm curious about what would yield the highest
performance - when choosing between:

  select extract(week from created), ...
  from some_table
  where ...
  group by extract(week from created), ...
  sort by extract(week from created), ...

and:

  select date_dim.week_num, ...
  from some_table join date_dim ...
  where ...
  group by date_dim.week_num, ...
  sort by date_dim, week_num, ...

The date_dim table would eventually cover ~3 years of operation, that
is less than 1000 rows.


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

Предыдущее
От: "A. Kretschmer"
Дата:
Сообщение: Re: slow result
Следующее
От: "Chad Wagner"
Дата:
Сообщение: Re: extract(field from timestamp) vs date dimension