我们的数据仓库中有很多星型模式。我认为我可以创建视图以简化对数据的 SQL 分析。
损益星的示例 SQL:
select
month_number,
sum(amount)
from
bizdata.dw_daily_pl_fact dwdpf
join bizdata.dw_distance dwdis on (dwdis.distance_key= dwdpf.distance_key)
join bizdata.dw_ledger_account dwled on (dwled.ledger_account_key= dwdpf.ledger_account_key)
join bizdata.dw_party dwpar on (dwpar.party_key= dwdpf.company_key)
join bizdata.dw_party dwpar2 on (dwpar2.party_key= dwdpf.supplier_key)
join bizdata.dw_budget_code dwbud on (dwbud.budget_code_key= dwdpf.budget_code_key)
join bizdata.dw_time dwtim on (dwtim.time_key= dwdpf.time_key)
join bizdata.dw_project dwpro on (dwpro.project_key= dwdpf.project_key)
where
year_number = 2012
and budget_code = 'SALARIES'
group by
month_number
(这颗星大约有 200 列和 100k 行)
如果我有看法:
create or replace view bizdata.dwv_pl_fact as (
select
*
from
bizdata.dw_daily_pl_fact dwdpf
join bizdata.dw_distance dwdis on (dwdis.distance_key= dwdpf.distance_key)
join bizdata.dw_ledger_account dwled on (dwled.ledger_account_key= dwdpf.ledger_account_key)
join bizdata.dw_party dwpar on (dwpar.party_key= dwdpf.company_key)
join bizdata.dw_party dwpar2 on (dwpar2.party_key= dwdpf.supplier_key)
join bizdata.dw_budget_code dwbud on (dwbud.budget_code_key= dwdpf.budget_code_key)
join bizdata.dw_time dwtim on (dwtim.time_key= dwdpf.time_key)
join bizdata.dw_project dwpro on (dwpro.project_key= dwdpf.project_key)
);
我可以将语句简化为以下内容:
select
month_number,
sum(amount)
from
bizdata.dwv_pl_fact
where
year_number = 2012
and budget_code = 'SALARIES'
group by
month_number
我的问题是 - 这种方法是否存在任何性能或其他问题?