Commit 6813d590 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

performance issue of migration script (100-fold speed up of the script)

parent c78d1b04
......@@ -16,11 +16,32 @@ alter table reaction_table add column product integer;
alter table reaction_table add column input_operator integer;
alter table reaction_table add column output_operator integer;
update reaction_table set reactant = (select id from reaction_node_table where node_type_db='REACTANT_NODE' and reaction_id=reaction_table.id order by id limit 1);
update reaction_table set product = (select id from reaction_node_table where node_type_db='PRODUCT_NODE' and reaction_id=reaction_table.id order by id limit 1);
--old version of computing first reactant, product, input and output operators (this version is ~100 slower than new one). This is an issue for big maps. For db with 30k reactions it toook 25minutes
--
--update reaction_table set reactant = (select id from reaction_node_table where node_type_db='REACTANT_NODE' and reaction_id=reaction_table.id order by id limit 1);
--update reaction_table set product = (select id from reaction_node_table where node_type_db='PRODUCT_NODE' and reaction_id=reaction_table.id order by id limit 1);
--update reaction_table set input_operator = (select id from reaction_node_table where node_type_db in ('AND_OPERATOR_NODE', 'ASSOCIATION_OPERATOR_NODE', 'NAND_OPERATOR_NODE', 'OR_OPERATOR_NODE', 'UNKNOWN_OPERATOR_NODE') and reaction_id=reaction_table.id order by id limit 1);
--update reaction_table set output_operator = (select id from reaction_node_table where node_type_db in ('DISSOCIATION_OPERATOR_NODE', 'SPLIT_OPERATOR_NODE', 'TRUNCATION_OPERATOR_NODE') and reaction_id=reaction_table.id order by id limit 1);
update reaction_table set input_operator = (select id from reaction_node_table where node_type_db in ('AND_OPERATOR_NODE', 'ASSOCIATION_OPERATOR_NODE', 'NAND_OPERATOR_NODE', 'OR_OPERATOR_NODE', 'UNKNOWN_OPERATOR_NODE') and reaction_id=reaction_table.id order by id limit 1);
update reaction_table set output_operator = (select id from reaction_node_table where node_type_db in ('DISSOCIATION_OPERATOR_NODE', 'SPLIT_OPERATOR_NODE', 'TRUNCATION_OPERATOR_NODE') and reaction_id=reaction_table.id order by id limit 1);
create table tmp_node (
node_id integer,
node_type_db varchar,
reaction_id integer,
CONSTRAINT tmp_fkey FOREIGN KEY (reaction_id)
REFERENCES reaction_table (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
);
insert into tmp_node select min(id), node_type_db, reaction_id from reaction_node_table group by node_type_db, reaction_id;
insert into tmp_node select min(id), 'INPUT_NODE', reaction_id from reaction_node_table where node_type_db in ('AND_OPERATOR_NODE', 'ASSOCIATION_OPERATOR_NODE', 'NAND_OPERATOR_NODE', 'OR_OPERATOR_NODE', 'UNKNOWN_OPERATOR_NODE') group by reaction_id;
insert into tmp_node select min(id), 'OUTPUT_NODE', reaction_id from reaction_node_table where node_type_db in ('DISSOCIATION_OPERATOR_NODE', 'SPLIT_OPERATOR_NODE', 'TRUNCATION_OPERATOR_NODE') group by reaction_id;
update reaction_table set reactant = tmp_node.node_id from tmp_node where tmp_node.reaction_id=reaction_table.id and tmp_node.node_type_db = 'REACTANT_NODE';
update reaction_table set product = tmp_node.node_id from tmp_node where tmp_node.reaction_id=reaction_table.id and tmp_node.node_type_db = 'PRODUCT_NODE';
update reaction_table set input_operator = tmp_node.node_id from tmp_node where tmp_node.reaction_id=reaction_table.id and tmp_node.node_type_db = 'INPUT_NODE';
update reaction_table set output_operator = tmp_node.node_id from tmp_node where tmp_node.reaction_id=reaction_table.id and tmp_node.node_type_db = 'OUTPUT_NODE';
drop table tmp_node;
update reaction_table set start_point = (select one_before_last_point from reaction_node_table, polyline_data_table where reaction_node_table.id = reaction_table.reactant and polyline_data_table.id = line_id);
update reaction_table set end_point = (select second_point from reaction_node_table, polyline_data_table where reaction_node_table.id = reaction_table.product and polyline_data_table.id = line_id);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment