由于分区的MySQL数据库目前不支持外键,因此我希望听到一些针对阅读量较大的应用程序的优缺点,每个表格将处理约1-400,000行。不幸的是,我在这个领域还没有足够的经验来做出自己的结论...
非常感谢!
参考资料:
由于分区的MySQL数据库目前不支持外键,因此我希望听到一些针对阅读量较大的应用程序的优缺点,每个表格将处理约1-400,000行。不幸的是,我在这个领域还没有足够的经验来做出自己的结论...
非常感谢!
参考资料:
如果您需要对包含400,000行的表进行分区,请选择除MySQL之外的其他数据库。说真的,按照现代标准,任何不到1,000,000行的表都可以忽略不计(甚至不算小),除非您也没有任何索引等。在这方面,现代标准已经有大约10年的历史了。
create or replace function audittransaction_insert_function()
returns trigger as $$
DECLARE
tablepartition varchar;
tablename varchar;
startbounds timestamp;
endbounds timestamp;
BEGIN
tablepartition := to_char(date_trunc('month', NEW.whendone), 'YYYYMMDD');
tablename := 'audittransaction_' || tablepartition ;
if not exists(select * from information_schema.tables where table_name = tablename) then
startbounds := date_trunc('month', NEW.whendone);
endbounds := startbounds + cast('1 months' as interval);
execute 'create table ' || tablename || ' ( CHECK (whendone >= ' || quote_literal(startbounds) || ' and whendone < ' || quote_literal(endbounds)|| ') ) inherits (audittransaction)';
execute 'ALTER TABLE '|| tablename ||' ADD CONSTRAINT '||tablename||'_unique_id UNIQUE (id)';
end if;
execute 'insert into ' || tablename || ' (id, operationid, whendone, "comment", ticketid ,transactionid, userid ) values (' || quote_literal(NEW.id) || ',' || quote_literal(NEW.operationid) || ',' || quote_literal(NEW.whendone) || ')';
return null;
END; $$
LANGUAGE plpgsql;
create trigger insert_audittrans
----- 然后,为自动输入创建触发器
create or replace function auditentry_insert_function()
returns trigger as $$
DECLARE
tablepartition varchar;
tablename varchar;
startbounds timestamp;
endbounds timestamp;
BEGIN
tablepartition := to_char(date_trunc('month', NEW.transactiontimestampgmt), 'YYYYMMDD');
tablename := 'auditentry_' || tablepartition ;
if not exists(select * from information_schema.tables where table_name = tablename) then
startbounds := date_trunc('month', NEW.transactiontimestampgmt);
endbounds := startbounds + cast('1 months' as interval);
execute 'create table ' || tablename || ' ( CHECK (transactiontimestampgmt >= ' || quote_literal(startbounds) || ' and transactiontimestampgmt < ' || quote_literal(endbounds)|| ') ) inherits (auditentry)';
execute 'ALTER TABLE '|| tablename ||' ADD CONSTRAINT '||tablename||'_unique_id UNIQUE (id)';
execute 'ALTER TABLE ' || tablename ||' ADD CONSTRAINT auditentry FOREIGN KEY (audit_transaction_id) REFERENCES audittransaction_'||tablepartition ||'(id)';
end if;
execute 'insert into ' || tablename || ' (id, audit_transaction_id, eventid, transactiontimestampgmt,timestampgmt, acknowledged, resolved, acknowledgedbyusername, acknowledgeddate, notificationlevel, resolvedbyusername, resolveddate, severity, parentauditentry_id ) values (' || quote_literal(NEW.id) || ',' || quote_literal(NEW.audit_transaction_id) || ',' || quote_literal(NEW.eventid) || ','||quote_literal(NEW.transactiontimestampgmt)||')';
return null;
END; $$
LANGUAGE plpgsql;
create trigger insert_auditentry before insert on auditentry for each row execute procedure auditentry_insert_function();