Redbrick中所有的資料物件,Tableindex的資料儲存體稱為segment,每一個Data Object都可以對應一個以上的segment , segment在資料庫中是邏輯物件,每一個Segment都可對應一個以上的PSU(Physical Storage Unit),PUS在資料庫中是實體物件,用來collect OS Level的資料載體最小單位-Data block,為了達成連續data block的目標,採用了extend元件。每一個extend中的data block均為連續的block , extendextend間可以不為連續,一個PSU所對應的所有extend背後代表的是這些data block並不連續


 




資料庫物件架構圖


Star Model:


Data warehouse最常使用的Data ModelStar Model,OLTP系統不同的是,OLTP主要是為了減少maintain DataLoading,OLAP主要是為了減少資料查詢上的Loading,因此會將OLTP中的資料結構用反正規化的方式展開,並將相關的參照欄位縮減為一層,如下圖所示。



OLTP系統資料模型


 




OLTP資料模型


 


 



Star Index


1.      假如你的資料模型中你的fact table透過Primary-key參照到多個dimension table上的foreign-key欄位,你可以再這P-keyF-key欄位上建立一個或多個star index


2.      Star index只能存在於P-keyF-key關係成立時才能建立。


3.      假如資料模型中擁有很多的參照關係,也在這之上建立了star index,但在查詢的時候查詢效能並沒有明顯的提升,你可以考慮在foreign-key鎖在欄位上建立target index,query的時候採用target join進行查詢。


4.      假如資料是時續性資料,因為index建立時,index存放在不同的segment,故在當你進行資料移動的時候(例如由daily搬移到month),需重整index(rebuild index),以改善資料查詢的速度。


 


EX:


Table script:



create table table1 (



pk int not null unique,


fk1 int not null,


fk2 char (3),


fk3 char(2),


fk4 char(6),


fk5 int,


col1 char(8),


col2 char(10),


constraint table1_pkc1 primary key (pk, fk1, fk2)


constraint tabled1_fkc3 foreign key (fk3) references tabled1 (pk),


constraint tabled2_fkc2 foreign key (fk2) references tabled2 (pk),


constraint tabled3_fkc1 foreign key (fk1) references tabled3 (pk),


constraint tabled4_fkc4 foreign key (fk4) references tabled4 (pk),


constraint tabled5_fkc5 foreign key (fk5) references tabled5 (pk) ) ;



 


Star index script



create star index star1 on table1 (



tabled1_fkc3,


tabled2_fkc2,


tabled3_fkc1,


tabled4_fkc4,


abled5_fkc5) ;



 



create star index star2 on table1 (



tabled4_fkc4,


tabled5_fkc5) ;



 


如果你的查詢條件分為tabled1_fkc3tabled2_fkc2tabled3_fkc1tabled4_fkc4 abled5_fkc5tabled4_fkc4tabled5_fkc5這兩種,你可以分別為這兩種查詢條件建立不同的star index


 


Target index


Target index以兩種形式執行:


1.      參照到dimension table 欄位上的target index會將查詢限制住。


2.      foreign key 欄位上並參照到fact tabletarget index,將以target join方式查詢。


Target index可以減少一半以上的查詢時間。


 


Weakly Data & Domain


當下了where條件後回傳的資料筆數>總筆數的1/3時稱為Weakly Data。我們可以歸納出這些資料相異的程度,這個相異幅度我們稱之為Domain.


 


Domain Size Type如下:



 


 



EX:


如果daily table包括10年中的每一天,所以他的變數就有3650,但是databasefact table中只有1年的資料,365天的唯一值資料。在這個案例中,我們選擇的domain sizeMedium


 


 


B-tree Index


Table中任何一個non null欄位都可以建立B-tree index,如果你的jointable中沒有建立任何適合的star indextarget index,卻只有B-tree index,這個時候join將會是以loop join將資料join出來,join的筆數為:


A table row counts * B table row counts


 


jointable越來越多的時候,可想而知的是這個查詢的效能將會造成系統龐大的負擔。



 
arrow
arrow
    全站熱搜

    噗噗噗的潛水珽 發表在 痞客邦 留言(0) 人氣()