MySQL Forums
Forum List  »  Perl

PHP-MySQL takes a Long Time to Run
Posted by: Senator Mike
Date: February 12, 2010 07:35AM

I just finished an application using hierarchical table in mysql DB for a network business.One of my main function that helps determine node depth is displayed below

<?php
##function to determine the depth of a node
function node_depth($netm_id) {
$depth ="SELECT node.netm_id, (COUNT(parent.netm_id) - (sub_tree.depth + 1)) AS depth
FROM tree AS node,
tree AS parent,
tree AS sub_parent,
(
SELECT node.netm_id, (COUNT(parent.netm_id) - 1) AS depth
FROM tree AS node,
tree AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
AND node.netm_id = '".$netm_id."'
GROUP BY node.netm_id
ORDER BY node.lft
)AS sub_tree
WHERE node.lft BETWEEN parent.lft AND parent.rgt
AND node.lft BETWEEN sub_parent.lft AND sub_parent.rgt
AND sub_parent.netm_id = sub_tree.netm_id
GROUP BY node.netm_id
ORDER BY depth ASC";
return $depth;
}
?>

which will return the tree depth of the node passed to the function. However, my problem is that for example when i want to read through the entire network tree to do e.g bonus calculations....it takes a lot of time (because i think the system has to go through the above function to for every tree node). At 200-300 records, the system is using close to 5-7 mins..

What do i do?

Options: ReplyQuote


Subject
Written By
Posted
PHP-MySQL takes a Long Time to Run
February 12, 2010 07:35AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.