sql - Postgres translate trigger into rule/ help optimize trigger -


i had partition our database performance. inserts slowed down 2-3 times.

we insert lot of data in 1 query, , read trigger run every row rule run every query. suspect issue.

i'm not sure possible in rules. need either optimizing trigger or translate rule.

create or replace function create_partition_and_insert() returns trigger     $body$       declare         partition_date text;         partition text;        begin         partition_date := to_char((select time timestamps id=new.timestamp_id),'yyyy_mm_dd');         partition := tg_relname || '_' || partition_date;         if to_regclass(partition) null           raise notice 'a partition has been created %',partition;           execute 'create table ' || partition ||'(             timestamp_id integer references timestamps(id),             channel_id integer references channels(id)           ) inherits (' || tg_relname || ');';           execute 'create index ' || partition ||'_timestamp_id_index on ' || partition || ' (timestamp_id);';           execute 'create index ' || partition ||'_channel_id_index on ' || partition || ' (channel_id);';         end if;         execute 'insert ' || partition || ' select ($1).*;' using new;          return null;       end;     $body$   language plpgsql volatile   cost 100;   " 


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -