the company does direct sales system, because of business needs, to customers to do a two-track membership system design. Inside the membership relationship uses the left and right value calculation.
double-track means that each node can only have at most two direct child nodes.
The left area is the list of nodes on the left under a node
right, and the list of nodes on the right under a node
to settle the collision bonus, I now need to calculate that with a layer as the root node, I can get the left or right node data of the N layer .
my table structure data is like this,
:kt_relation
relation_id :
user_id :id
Lft:
Rgt:
Lft_sub:id0
Rgt_sub:id0.
Level:
10001Nsql
:Lft+Rgt<=Lft+Rgt,<=3
now I want to query, such as the yellow user_id in the above picture is 10003. This node, which is the layer 3 in the left area, should be the green two nodes. It"s stuck here now. I can"t move it.
my own idea is that we should start from the root node with the above sql. The third layer of 10003 should be the fourth layer of 10001, and 10003 is in the right area of 10001. Then I will exclude all the left area of 10001, and only inquire how many nodes there are in the right area of layer 4 of 10001. 10013 is obviously included. This is blocked again, and it doesn"t feel like it will work. Even if it works, there is a problem. It takes many sql statements to complete the final result. Is there any way to use only one sentence like the one above to produce the result, and the query takes time in 0.035sjournal 0.02s.
because I don"t want to be too time-consuming here, there are a lot of bonus inquiries and updates that will take time. The query time should be as short as possible. I indexed it.
I don"t know if I made it clear. There are friends who have studied the left and right value algorithms, pointing and pointing.