2012-06-15 32 views
1

在一個簡單的分區表:,可以將提示優化用於分區嗎?

-- note: no records stored in base, only inheritors of base 
create table base(
    base_id  bigint, 
    base_tp  char(3) not null, 
    ...); 

create table base_abc(
    base_id  bigserial primary key, 
    base_tp  default 'abc' 
       check(base_tp = 'abc'), 
    ... 
) inherits(base); 


create table base_efg(
    base_id  bigserial primary key, 
    base_tp  default 'efg' 
       check(base_tp = 'efg'), 
    ... 
) inherits(base); 

如果其中一個查詢子句是在該使用base_tp,例如,

select * from base where ... and base_tp='abc' 

將9.2下的查詢進行優化,只選擇表base_abc或是否會像目前一樣查詢basebase_abcbase_efg

回答

3

那麼,這個行爲可以通過constraint_exclusion配置選項來設置。如果它是on,那麼只有具有匹配約束的分區纔會被訪問。但您應該小心,並選擇partition以避免重擊性能。考慮到分區表也是一樣,但其他人不受影響。

看看它的documentation

+0

很好的參考。似乎只是醫生的命令。謝謝! –