Redbrick中所有的資料物件,如Table、index的資料儲存體稱為segment,每一個Data Object都可以對應一個以上的segment , segment在資料庫中是邏輯物件,每一個Segment都可對應一個以上的PSU(Physical Storage Unit),PUS在資料庫中是實體物件,用來collect OS Level的資料載體最小單位-Data block-,為了達成連續data block的目標,採用了extend元件。每一個extend中的data block均為連續的block , extend與extend間可以不為連續,一個PSU所對應的所有extend背後代表的是這些data block並不連續…
資料庫物件架構圖
Star Model:
Data warehouse最常使用的Data Model為Star Model,何OLTP系統不同的是,OLTP主要是為了減少maintain Data的Loading,而OLAP主要是為了減少資料查詢上的Loading,因此會將OLTP中的資料結構用反正規化的方式展開,並將相關的參照欄位縮減為一層,如下圖所示。
OLTP系統資料模型
OLTP資料模型
Star Index
1. 假如你的資料模型中你的fact table透過Primary-key參照到多個dimension table上的foreign-key欄位,你可以再這P-key與F-key欄位上建立一個或多個star index。
2. Star index只能存在於P-key與F-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_fkc3、tabled2_fkc2、tabled3_fkc1、tabled4_fkc4、 abled5_fkc5及tabled4_fkc4、tabled5_fkc5這兩種,你可以分別為這兩種查詢條件建立不同的star index。
Target index
Target index以兩種形式執行:
1. 參照到dimension table 欄位上的target index會將查詢限制住。
2. foreign key 欄位上並參照到fact table的target index,將以target join方式查詢。
Target index可以減少一半以上的查詢時間。
Weakly Data & Domain
當下了where條件後回傳的資料筆數>總筆數的1/3時稱為Weakly Data。我們可以歸納出這些資料相異的程度,這個相異幅度我們稱之為Domain.
Domain Size Type如下:
EX:
如果daily table包括10年中的每一天,所以他的變數就有3650種,但是database中fact table中只有1年的資料,365天的唯一值資料。在這個案例中,我們選擇的domain size為Medium。
B-tree Index
Table中任何一個non null欄位都可以建立B-tree index,如果你的join的table中沒有建立任何適合的star index、target index,卻只有B-tree index,這個時候join將會是以loop join將資料join出來,其join的筆數為:
A table row counts * B table row counts
當join的table越來越多的時候,可想而知的是這個查詢的效能將會造成系統龐大的負擔。