我跟着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_5
和g09_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 = 5
或select * from gtab09 where acyrid = 6
时,花时间执行(我认为选择在子表中进行选择)inherits
真的会拆分表吗?