BubikolRamios
06-26-2011, 02:02 AM
CREATE TABLE tree (CHILD_ID INTEGER NOT NULL,PARENT_ID INTEGER,TOP_PRIORITY_ORDER INTEGER DEFAULT NULL, INDEX (CHILD_ID,PARENT_ID)) ENGINE=MYISAM;
CREATE INDEX myIndex ON tree (parent_id);
CREATE TABLE tmp_NestedSetModel
(NestedSetModel_top INTEGER NOT NULL,
CHILD_ID INTEGER NOT NULL,
lft INTEGER,
rgt INTEGER,
PARENT_ID INTEGER,
ORDER_BY INTEGER,
INDEX (CHILD_ID,NestedSetModel_top)) ENGINE=MYISAM;
Slow part of proc.
Basicaly takes one record from tree tab and puts one into
tmp_NestedSetModel table.
It was all ok until I putted like 130.000 records into tree table.
It takes like 1-2 or more sec per one while loop.
WHILE @counter <= (@max_counter) DO
SELECT count(*) into v1
FROM tmp_NestedSetModel AS S1, tree AS T1
WHERE S1.CHILD_ID = T1.PARENT_ID
AND S1.NestedSetModel_top = @current_top;
/*call debug_insert('t',@current_top);*/
IF (v1 > 0) THEN
INSERT INTO tmp_NestedSetModel
SELECT (@current_top + 1),
MIN(T1.CHILD_ID),
@counter,
NULL,
NULL,
t1.top_priority_order
FROM tmp_NestedSetModel AS S1, tree AS T1
WHERE S1.CHILD_ID = T1.PARENT_ID
AND S1.NestedSetModel_top = @current_top;
DELETE FROM tree WHERE CHILD_ID = (SELECT CHILD_ID FROM tmp_NestedSetModel WHERE NestedSetModel_top = @current_top + 1);
SET @counter = @counter + 1;
SET @current_top = @current_top + 1;
ELSE
UPDATE tmp_NestedSetModel
SET rgt = @counter, NestedSetModel_top = -NestedSetModel_top
WHERE NestedSetModel_top = @current_top;
SET @counter = @counter + 1;
SET @current_top = @current_top - 1;
END IF;
END WHILE;
Any thought ?
CREATE INDEX myIndex ON tree (parent_id);
CREATE TABLE tmp_NestedSetModel
(NestedSetModel_top INTEGER NOT NULL,
CHILD_ID INTEGER NOT NULL,
lft INTEGER,
rgt INTEGER,
PARENT_ID INTEGER,
ORDER_BY INTEGER,
INDEX (CHILD_ID,NestedSetModel_top)) ENGINE=MYISAM;
Slow part of proc.
Basicaly takes one record from tree tab and puts one into
tmp_NestedSetModel table.
It was all ok until I putted like 130.000 records into tree table.
It takes like 1-2 or more sec per one while loop.
WHILE @counter <= (@max_counter) DO
SELECT count(*) into v1
FROM tmp_NestedSetModel AS S1, tree AS T1
WHERE S1.CHILD_ID = T1.PARENT_ID
AND S1.NestedSetModel_top = @current_top;
/*call debug_insert('t',@current_top);*/
IF (v1 > 0) THEN
INSERT INTO tmp_NestedSetModel
SELECT (@current_top + 1),
MIN(T1.CHILD_ID),
@counter,
NULL,
NULL,
t1.top_priority_order
FROM tmp_NestedSetModel AS S1, tree AS T1
WHERE S1.CHILD_ID = T1.PARENT_ID
AND S1.NestedSetModel_top = @current_top;
DELETE FROM tree WHERE CHILD_ID = (SELECT CHILD_ID FROM tmp_NestedSetModel WHERE NestedSetModel_top = @current_top + 1);
SET @counter = @counter + 1;
SET @current_top = @current_top + 1;
ELSE
UPDATE tmp_NestedSetModel
SET rgt = @counter, NestedSetModel_top = -NestedSetModel_top
WHERE NestedSetModel_top = @current_top;
SET @counter = @counter + 1;
SET @current_top = @current_top - 1;
END IF;
END WHILE;
Any thought ?