PostgreSQL中的表分区

时间:2014-10-24 07:00:30

标签: postgresql partitioning

我跟着this分区我的大桌子,例如我所做的是

create table g09_6(check(acyrid = 6)) INHERITS (gtab09);
create table g09_5(check(acyrid = 5)) INHERITS (gtab09);
ALTER TABLE g09_6 ADD CONSTRAINT g09_6_pkey PRIMARY KEY (tranid);
ALTER TABLE g09_5 ADD CONSTRAINT g09_5_pkey PRIMARY KEY (tranid);
CREATE UNIQUE INDEX g09_5_tranid_idx ON g09_5 USING btree (tranid);
CREATE UNIQUE INDEX g09_6_tranid_idx ON g09_6 USING btree (tranid);
insert into g09_6 select * from gtab09 where acyrid= 6
insert into g09_5 select * from gtab09 where acyrid= 5 

此处gtab09父表g09_5g09_6子表。下面给出的是我的触发

CREATE OR REPLACE FUNCTION gtab09_func_insert_trigger()
RETURNS TRIGGER AS $$
BEGIN
    IF ( NEW.acyrid = 5 )THEN
        INSERT INTO g09_5 VALUES (NEW.*);
    ELSIF ( NEW.hashtime = 6 )THEN
        INSERT INTO g09_6 VALUES (NEW.*);
    ELSE
        RAISE EXCEPTION 'Error function!';
    END IF;
    RETURN NULL;
END;
$$
LANGUAGE plpgsql;

CREATE TRIGGER trigger_gtab09_insert
    BEFORE INSERT ON gtab09
    FOR EACH ROW EXECUTE PROCEDURE gtab09_func_insert_trigger();
  • 所以,当我执行select * from gtab09 where acyrid = 5select * from gtab09 where acyrid = 6时,花时间执行(我认为选择在子表中进行选择)
  • inherits真的会拆分表吗?

0 个答案:

没有答案