DELIMITER $$ CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`zoneGeo_calcTree`() BEGIN /** * Calculates the #path, #lft, #rgt, #sons and #depth columns of * the #zoneGeo table. To build the tree, it uses the #parentFk * column. */ DECLARE vIndex INT DEFAULT 0; DECLARE vSons INT; DROP TEMPORARY TABLE IF EXISTS tNestedTree; CREATE TEMPORARY TABLE tNestedTree SELECT id, path, lft, rgt, depth, sons FROM zoneGeo LIMIT 0; SET max_sp_recursion_depth = 5; CALL zoneGeo_calcTreeRec(NULL, '/', 0, vIndex, vSons); SET max_sp_recursion_depth = 0; UPDATE zoneGeo z JOIN tNestedTree t ON t.id = z.id SET z.path = t.path, z.lft = t.lft, z.rgt = t.rgt, z.depth = t.depth, z.sons = t.sons; DROP TEMPORARY TABLE tNestedTree; END$$ DELIMITER ;