- 论坛徽章:
- 3
|
本帖最后由 osdba 于 2011-04-11 14:08 编辑
建分区表的语句如下:
CREATE TABLE BMS_FEE_SUM
( SERIALNO VARCHAR(17) NOT NULL,
OFFICE_ID VARCHAR(10) NOT NULL,
COUNTY_ID VARCHAR(3) NOT NULL,
REGION_ID VARCHAR(1) NOT NULL,
CLOSE_BALANCE_TIME DATE,
SERVICE_KEY VARCHAR(30)
);
--注意建分区表,要加check,这样保证select * from bms_fee_sum where region_id='A'这样的语句只扫描特定的分区,而不会扫描所有的分区
create table bms_fee_sum_b() inherits(bms_fee_sum);
alter table bms_fee_sum_b add check(region_id<'B');
create table bms_fee_sum_c() inherits(bms_fee_sum);
alter table bms_fee_sum_c add check(region_id>='B' and region_id<'C');
create table bms_fee_sum_d() inherits(bms_fee_sum);
alter table bms_fee_sum_d add check(region_id>='C' and region_id<'D');
create table bms_fee_sum_e() inherits(bms_fee_sum);
alter table bms_fee_sum_e add check(region_id>='D' and region_id<'E');
create table bms_fee_sum_f() inherits(bms_fee_sum);
alter table bms_fee_sum_f add check(region_id>='E' and region_id<'F');
create table bms_fee_sum_max() inherits(bms_fee_sum);
alter table bms_fee_sum_max add check(region_id>='F');
CREATE RULE bms_fee_sum_insert_b AS
ON INSERT TO bms_fee_sum WHERE ( REGION_ID <'B')
DO INSTEAD INSERT INTO bms_fee_sum_b VALUES ( NEW.* );
CREATE RULE bms_fee_sum_insert_c AS
ON INSERT TO bms_fee_sum WHERE ( REGION_ID >='B' and REGION_ID <'C')
DO INSTEAD INSERT INTO bms_fee_sum_c VALUES ( NEW.* );
CREATE RULE bms_fee_sum_insert_d AS
ON INSERT TO bms_fee_sum WHERE ( REGION_ID >='C' and REGION_ID <'D')
DO INSTEAD INSERT INTO bms_fee_sum_d VALUES ( NEW.* );
CREATE RULE bms_fee_sum_insert_e AS
ON INSERT TO bms_fee_sum WHERE ( REGION_ID >='D' and REGION_ID <'E')
DO INSTEAD INSERT INTO bms_fee_sum_e VALUES ( NEW.* );
CREATE RULE bms_fee_sum_insert_f AS
ON INSERT TO bms_fee_sum WHERE ( REGION_ID >='E' and REGION_ID <'F')
DO INSTEAD INSERT INTO bms_fee_sum_f VALUES ( NEW.* );
CREATE RULE bms_fee_sum_insert_max AS
ON INSERT TO bms_fee_sum WHERE ( REGION_ID >='F')
DO INSTEAD INSERT INTO bms_fee_sum_max VALUES ( NEW.* ); |
|