I am working on a MLM project in which i have more than 30,000 members followed by the root member,i have to store member automatically in binary tree form like
1 is root
2 is child of 1
3 is child of 1
Then 4 is child of 2
5 is child of 2
and so on …
I have calculate each members left count and right count in downline, calculation takes 30minutes for 10,000 members, now i have more than 30,000 members it takes more time… How to avoid this…
#1 explain your query, and add the necessary indexes.
#2 if you do it in php, it will take under a few sec. 30k records is not much.
Say you select 3 INT fields, that’s 4 Bytes each, for 30k records, that’s ~360,000 Bytes (2.74MB) of transfer from your sql server to your web server.
Once you have the data, you make yourself a nice recursive function, that will take all that data, and find out how many people you have on your left/right.
Then, you update the database (update 2 INT fields where 1 INT).
There’s no way that should take you more than a minute or two.
Pretty sure there’s an algorithm you can apply. For it to be taking that long, I would suspect your making multiple calls to the database to resolve relationships.