資料庫分割槽表關聯

2021-08-03 04:21:30 字數 4586 閱讀 2516

場景:現實業務中有兩個表關係比較緊密,而且資料量比較大的時候,需要對兩個表都進行分割槽,並能很好的發揮分表作用

注意:資料庫表最好是在建立的時候就進行分割槽,不能對已經建立的普通表(堆表)再進行分割槽變為分割槽表,否則轉換起來比較麻煩。

create

table ocs_collect_people

( collect_id varchar2(32) not

null,

people_id varchar2(20) not

null,

people_version number(2) not

null,

account_version number(2),

project_id varchar2(20) not

null,

region_id varchar2(12) not

null,

batch_id varchar2(32) not

null,

money number(12,3) not

null,

operator_id varchar2(16) not

null,

operator_time date

notnull,

assign_id varchar2(30),

audit_id varchar2(25),

pay_id varchar2(30),

status number(2) not

null

) partition by range(operator_time)

(partition cp_2012 values less than (to_date('2013-01-01','yyyy-mm-dd')) tablespace xt_test_p1,

partition cp_2013 values less than (to_date('2014-01-01','yyyy-mm-dd')) tablespace xt_test_p2

);create

table ocs_collect_people_prop

( collect_id varchar2(32) not

null,

float_value number(12,3),

int_value integer,

str_value varchar2(100),

date_value date,

prop_name varchar2(20) not

null,

operator_time date

notnull

) partition by range(operator_time)

(partition cpp_2012 values less than (to_date('2013-01-01','yyyy-mm-dd')) tablespace xt_test_p1,

partition cpp_2013 values less than (to_date('2014-01-01','yyyy-mm-dd')) tablespace xt_test_p2

);

結論:如果想使用兩個表的分割槽功能,必須把兩個表的分割槽字段使用上,才能達到最好效果,如果只使用乙個表的分割槽字段,那麼有乙個表會使用分割槽優勢,如下:

select * from ocs_collect_people p,ocs_collect_people_prop pp 

where pp.operator_time=p.operator_time and p.collect_id=pp.collect_id

and p.operator_time>to_date('2013-01-01','yyyy-mm-dd');

--比下面的sql好,從執行計畫上看cardinality值和bytes值都小了許多

select * from ocs_collect_people p,ocs_collect_people_prop pp 

where pp.operator_time>to_date('2013-01-01','yyyy-mm-dd') and p.collect_id=pp.collect_id

and p.operator_time>to_date('2013-01-01','yyyy-mm-dd')

場景:現實業務中有兩個表關係比較緊密,而且資料量比較大的時候,需要對兩個表都進行分割槽,並能很好的發揮分表作用

注意:資料庫表最好是在建立的時候就進行分割槽,不能對已經建立的普通表(堆表)再進行分割槽變為分割槽表,否則轉換起來比較麻煩。

create

table ocs_collect_people

( collect_id varchar2(32) not

null,

people_id varchar2(20) not

null,

people_version number(2) not

null,

account_version number(2),

project_id varchar2(20) not

null,

region_id varchar2(12) not

null,

batch_id varchar2(32) not

null,

money number(12,3) not

null,

operator_id varchar2(16) not

null,

operator_time date

notnull,

assign_id varchar2(30),

audit_id varchar2(25),

pay_id varchar2(30),

status number(2) not

null

) partition by range(operator_time)

(partition cp_2012 values less than (to_date('2013-01-01','yyyy-mm-dd')) tablespace xt_test_p1,

partition cp_2013 values less than (to_date('2014-01-01','yyyy-mm-dd')) tablespace xt_test_p2

);create

table ocs_collect_people_prop

( collect_id varchar2(32) not

null,

float_value number(12,3),

int_value integer,

str_value varchar2(100),

date_value date,

prop_name varchar2(20) not

null,

operator_time date

notnull

) partition by range(operator_time)

(partition cpp_2012 values less than (to_date('2013-01-01','yyyy-mm-dd')) tablespace xt_test_p1,

partition cpp_2013 values less than (to_date('2014-01-01','yyyy-mm-dd')) tablespace xt_test_p2

);

結論:如果想使用兩個表的分割槽功能,必須把兩個表的分割槽字段使用上,才能達到最好效果,如果只使用乙個表的分割槽字段,那麼有乙個表會使用分割槽優勢,如下:

select * from ocs_collect_people p,ocs_collect_people_prop pp 

where pp.operator_time=p.operator_time and p.collect_id=pp.collect_id

and p.operator_time>to_date('2013-01-01','yyyy-mm-dd');

--比下面的sql好,從執行計畫上看cardinality值和bytes值都小了許多

select * from ocs_collect_people p,ocs_collect_people_prop pp 

where pp.operator_time>to_date('2013-01-01','yyyy-mm-dd') and p.collect_id=pp.collect_id

and p.operator_time>to_date('2013-01-01','yyyy-mm-dd')

資料庫 分割槽表

步驟 先建立分割槽函式,在建立分割槽方案,最後使用分割槽方案建立表 首先熟悉一下建立分割槽函式 1 在int列上建立左側分割槽函式,下列分割槽函式將表分為四個分割槽。2 在int列上建立右側分割槽函式 3 在datatime列上建立右側分割槽函式,將資料表分為12個分割槽,每個分割槽對應dateti...

資料庫之分割槽表

如果一張表的資料量太大的話,那麼myd,myi就會變得很大,查詢資料就會變得很慢,這個時候我們可以利用mysql的分割槽功能,在物理上將這一張表對應的三個檔案,分割成許多個小塊,這樣呢,我們查詢一條資料時,就不用全部查詢了,只要知道這條資料在哪一塊,然後在那一塊找就行了。如果表的資料太大,可能乙個c...

資料庫分割槽表的使用

第一部分 sql server分割槽表 參考官方文件鏈結為 1.建立分割槽表步驟,參考官方文件為佳 建立分割槽表的第一步,先建立資料庫檔案組 建立了檔案組之後,還要再建立幾個資料庫檔案 建立乙個分割槽函式 建立乙個分割槽方案 2.新增 查詢 修改分割槽表中的資料 在建立完分割槽表後,可以向分割槽表中...