looks good! :)
DROP TABLE IF EXISTS t_tree_insert; CREATE TABLE `t_tree_insert` ( `f_node_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `f_parent_id` INT(10) UNSIGNED NULL DEFAULT '0', `f_name` VARCHAR(200) NOT NULL, `f_sort` FLOAT NULL DEFAULT NULL, PRIMARY KEY (`f_node_id`), UNIQUE INDEX `sort` (`f_parent_id`, `f_sort`), INDEX `f_parent_id` (`f_parent_id`), FULLTEXT INDEX `f_name` (`f_name`) ) COMMENT='test tree move operations' COLLATE='utf8_general_ci' ENGINE=InnoDB AUTO_INCREMENT=0 ; insert into t_tree_insert values (130, 1, 'other array', 1) , (142, 2, 'B06', 1) , (143, 2, 'B2L', 2) , (144, 2, 'B2M', 3) , (200, 2, 'INSERT', 3.5) , (145, 2, 'B2N', 4) , (146, 2, 'B2O', 5) , (150, 3, 'other array', 1) ; select * from t_tree_insert order by f_parent_id, f_sort; set @sort=0; replace into t_tree_insert (f_node_id, f_parent_id, f_name, f_sort) select f_node_id, f_parent_id, f_name, (@sort:=@sort+1) as f_sort from t_tree_insert as T where f_parent_id = 2 order by T.f_sort ; select * from t_tree_insert order by f_parent_id, f_sort;
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Wikisyntax for the Monastery
But I'm suspecting that temporarily dropping the "unique index" constraint and only updating the row f_sort is considerably faster for larger tables.
In reply to Re^2: [OT] MySQL recalibrating a sort-index
by LanX
in thread [OT] MySQL recalibrating a sort-index
by LanX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |