Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-26-2011, 02:02 AM   PM User | #1
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
stored proc slow while ...

Code:
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);
Code:
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.




Code:
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 ?
__________________
Found a flower or bug and don't know what it is ?
agrozoo.net galery
if you don't spot search button at once, there is search form:
agrozoo.net galery search

Last edited by BubikolRamios; 06-26-2011 at 02:06 AM..
BubikolRamios is offline   Reply With Quote
Old 06-26-2011, 05:35 PM   PM User | #2
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
Even vorse. After various indexs trial/error/esplain/sucess, I noticed that this processes like 100 records in a couple of seconds, then it slows down exponentialy. So 1000 records comes up like in 2 -3 hours !!!
__________________
Found a flower or bug and don't know what it is ?
agrozoo.net galery
if you don't spot search button at once, there is search form:
agrozoo.net galery search
BubikolRamios is offline   Reply With Quote
Old 06-26-2011, 10:37 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,210
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Maybe if you told us what the purpose of this is?
Old Pedant is offline   Reply With Quote
Old 06-26-2011, 11:36 PM   PM User | #4
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
converting adjacent to nested set hirearchical model
like here:
http://data.bangtech.com/sql/nested_set_treeview.htm

doh I doubt that info will make any difference.I fill like mysql is eating up memory predefined/not defined/default in various variables in my.cnf, with repeated delete, insert,update ...
__________________
Found a flower or bug and don't know what it is ?
agrozoo.net galery
if you don't spot search button at once, there is search form:
agrozoo.net galery search

Last edited by BubikolRamios; 06-26-2011 at 11:41 PM..
BubikolRamios is offline   Reply With Quote
Old 06-28-2011, 12:55 PM   PM User | #5
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
so I added this into upper while, trying to do something on every 100 records
processed. No effect.
Code:
  IF (MOD(@counter, 100) = 0) then
    RESET QUERY CACHE;
    FLUSH TABLES tree,tmp_NestedSetModel;
    // adds some info into debug table
    call debug_insert('convert_adjacent_to_nested','RESET QUERY CACHE');
  END IF;
this is the result of upper call debug ....

You see how time needed to process 100 records is increasing.
__________________
Found a flower or bug and don't know what it is ?
agrozoo.net galery
if you don't spot search button at once, there is search form:
agrozoo.net galery search
BubikolRamios is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:55 AM.


Advertisement
Log in to turn off these ads.