'覦貎朱Μ'朱 蟆 れ 覺る螳? 襷 DB覦 譬 襾轟る れ企瓦 蟆企. 襷 襷 'xx 貉ろ' 襷 . 蠏 覿れ 覿覈 讌 蠍磯 襭 蠍磯 襭(貉れ)覲企 覿覿 襴一 蠍一誤 蟆狩. 譴 蟆 '覿覿 襴讌 覈 蟆曙一 襴 蟆 '朱 襷 蠏 覿れ 讌 蟆企. DBMS襷 螳 蟆郁骸朱 焔ル覿 るゼ . 覯 螳 朱襦 企 襭 襴讌 100% 蟆 襷 .
Oracle Server 螳 譬 襷 蟇一 覿覿 讌 蠍磯 襭 襴. 讌襷 MS-SQL Server 蟆曙 讌 Oracle Server 覲企 讌 覩誤″. 蠏碁蠍 覓語 MS-SQL Server 螳覲企 襷 蟆曙 蠍磯 襭 襴 蟆曙郁 襷 . 覯 蟆曙 豌襴襯 伎 蠍磯 襭螻 觜訣蟆 豌襴襯 蟆 襴 蟆曙郁 .
蠍磯 豌襴襯 ろ れ螻讌 讌 襷. 一碁慨螻 壱 谿企ゼ 企 蠏碁 '願碓 企蟆 覦蠑碁 蟆 企至 螳語?'手 覓殊企.
2 Oracle vs MS-SQL #
蠍一旧朱 Oracle 8.1.6覿 覿 襯 . 蠏碁 螳ロ 襯 襷 讌伎 Query 讌蠍郁 覿 豢朱 螳覦 覓企 譟. 蠏碁
Oracle (http://databaser.net/moniwiki/wiki.php/%EB%B6%84%EC%84%9D%EC%9A%A9%ED%95%A8%EC%88%98%EC%9D%98%EC%9D%B4%EC%9A%A9#s-3) 蟲 蟆曙磯 所 觜襯願 蟲 蟆 . 讌襷 MS-SQL 蠏碁 螳 譟伎讌 SELF JOIN 伎 . 譟一 一一 <, >, <=, <= 譴 蟆企. 蠏碁覩襦 Merge Join Hash Join . る讌 Loop Join襷(SQL Server 2005覿磯 蠎 '=' 朱 Hash Join 蟆 襷 覲伎. 襷 企朱 '='襦 覦蠖 蟆 覦蠑語 Hash Join 覲企. 碁 覦 .) 蟆 伎 , 蟲 覯螳 企襦 貎朱Μ 豌襴觜 X
2 蠏碁襦 企 蟆 覲 . 襯 れ れ螻 螳 蟲 貎朱Μ 一危郁 襷朱 襷襦 焔レ 蠍蟆 觜讌.
with temp
as
(
select 1 num union all
select 2 union all
select 3
)
select
b.num
, sum(a.num)
from temp a
inner join temp b
on a.num <= b.num
group by
b.num
4 覦貎朱Μ vs 貉れ #
覦貎朱Μ
DECLARE
@DateUnit char(1) --D, W, M
, @CurrDT char(8)
, @BeginDT char(8)
, @EndDT char(8);
SET @DateUnit = 'D';
SET @CurrDT = '20091101';
DECLARE
@BeginDT char(8)
, @EndDT char(8);
SET @BeginDT =
CASE
WHEN @DateUnit = 'D' THEN @CurrDT
WHEN @DateUnit = 'W' THEN
CONVERT(int, CONVERT(char(8), DATEADD(dd, -(DATEPART(weekday, @CurrDT) - 1) , @CurrDT), 112))
WHEN @DateUnit = 'M' THEN CONVERT(int, CONVERT(char(6), @CurrDT, 112) + '01')
END
SET @EndDT =
CASE
WHEN @DateUnit = 'D' THEN @CurrDT
WHEN @DateUnit = 'W' THEN
CONVERT(int, CONVERT(char(8), DATEADD(dd, 7- DATEPART(weekday, @CurrDT), @CurrDT), 112))
WHEN @DateUnit = 'M' THEN
CONVERT(int, CONVERT(char(8), DATEADD(mm, 1, CONVERT(char(6), @CurrDT, 112) + '01') - 1, 112))
END;
--SELECT @BeginDT, @EndDT;
INSERT Common.Agg_ReiterationUU_ConnectHistory
(DateKey, BasisServiceKey, ReiterationServiceKey, UU, AggUnit)
SELECT
@BeginDT DateKey
, B.BasisServiceKey
, B.ReiterationServiceKey
, B.UU
, @DateUnit AggUnit
FROM Common.Dim_Service OutTable
CROSS APPLY (
SELECT
A.ServiceKey BasisServiceKey
, B.ServiceKey ReiterationServiceKey
, COUNT(DISTINCT B.AccountKey) UU
FROM
(
SELECT
AccountKey
, OutTable.Service_CD ServiceKey
FROM Common.Fact_ConnectHistory
WHERE DateKey BETWEEN @BeginDT AND @EndDT
AND ServiceKey = OutTable.Service_CD
GROUP BY
AccountKey
) A
INNER JOIN Common.Fact_ConnectHistory B
ON A.AccountKey = B.AccountKey
WHERE B.DateKey BETWEEN @BeginDT AND @EndDT
GROUP BY
A.ServiceKey
, B.ServiceKey
) B
WHERE Service_CD > 0
AND Site_CD = 1
AND @DateUnit IN ('D', 'W', 'M')
貉れ
/*
DECLARE
@DateUnit char(1) --D, W, M
, @CurrDT char(8)
, @BeginDT char(8)
, @EndDT char(8);
SET @DateUnit = 'D';
SET @CurrDT = '20091101';
*/
DECLARE
@BeginDT char(8)
, @EndDT char(8);
SET @BeginDT =
CASE
WHEN @DateUnit = 'D' THEN @CurrDT
WHEN @DateUnit = 'W' THEN
CONVERT(int, CONVERT(char(8), DATEADD(dd, -(DATEPART(weekday, @CurrDT) - 1) , @CurrDT), 112))
WHEN @DateUnit = 'M' THEN CONVERT(int, CONVERT(char(6), @CurrDT, 112) + '01')
END
SET @EndDT =
CASE
WHEN @DateUnit = 'D' THEN @CurrDT
WHEN @DateUnit = 'W' THEN
CONVERT(int, CONVERT(char(8), DATEADD(dd, 7- DATEPART(weekday, @CurrDT), @CurrDT), 112))
WHEN @DateUnit = 'M' THEN
CONVERT(int, CONVERT(char(8), DATEADD(mm, 1, CONVERT(char(6), @CurrDT, 112) + '01') - 1, 112))
END;
--SELECT @BeginDT, @EndDT;
DECLARE
@ServiceKey int;
DECLARE cur CURSOR FOR
SELECT Service_CD ServiceKey
FROM Common.Dim_Service
WHERE Service_CD > 0
AND Site_CD = 1
AND @DateUnit IN ('D', 'W', 'M');
CREATE TABLE #AccountKey(AccountKey bigint);
OPEN Cur;
FETCH NEXT FROM cur INTO @ServiceKey;
WHILE @@FETCH_STATUS not in (-1, -2)
BEGIN
INSERT #AccountKey
SELECT
AccountKey
FROM Common.Fact_ConnectHistory
WHERE DateKey BETWEEN @BeginDT AND @EndDT
AND ServiceKey = @ServiceKey
GROUP BY
AccountKey;
INSERT Common.Agg_ReiterationUU_ConnectHistory
(DateKey, BasisServiceKey, ReiterationServiceKey, UU, AggUnit)
SELECT
@BeginDT DateKey
, @ServiceKey BasisServiceKey
, A.ServiceKey ReiterationServiceKey
, COUNT(DISTINCT A.AccountKey) UU
, @DateUnit AggUnit
FROM Common.Fact_ConnectHistory A
INNER JOIN #AccountKey B
ON A.AccountKey = B.AccountKey
WHERE A.DateKey BETWEEN @BeginDT AND @EndDT
GROUP BY
A.ServiceKey
TRUNCATE TABLE #AccountKey
FETCH NEXT FROM cur INTO @ServiceKey
END
CLOSE cur;
DEALLOCATE cur;
蟆曙 貉れ襯 伎 覿襴 豌襴 蟆 觜 覦貎朱Μ螳 碁. 螳 覃覈襴螳 企 覓伎 伎 殊企 蟆企. れ 朱襦 豌襴 譯朱襦 豌襴 谿伎企.
豌襴 | 豌襴覦 | 豌襴螳 |
1 | 覦貎朱Μ | 120豐 |
1 | 貉れ | 40豐 |
7 | 覦貎朱Μ | 1200豐 |
7 | 貉れ | 330豐 |
* 谿瑚: 8cpu, 8GB ram
豌襴覯螳 伎襦 覦貎朱Μ 豌襴螳 蠍壱蠍朱 企 蟆企. 覲覈蟆 覦貎朱Μ襯 讌 蟆 焔レ 譴 蟆.
襷 譬 蟆襷 . 覯暑 1豸旧 5豸旧朱 100レ 襯企 蟆 螳企慨. 蠏碁Μ螻 螳碁螻 讌 れ. 螳碁 100レ 1 5豸糾讌 襯 讌襷, 讌 3覯 蟇語 襯 覦 企ゼ 螳讌 蟆 谿企. 覦 貎朱Μ れ 螻ろ伎 .
覦 貎朱Μ 螳 覦 貎朱Μ襯 讌 襷 豢覿伎朱 譬 襭 . 覲旧″伎 讌覲伎螳 る 蠏瑚 譬 襭 .
る 蠍伎襷 襷 給. 襷讌襷 蠍蠏螳 酔給. -- achiara 2017-05-05 18:23:38