douyanxing6054 2015-08-13 15:03 采纳率: 0%
浏览 25

具有三元树结构的DB的逻辑

Currently I need to build a structure for a MLM company. The structure they wanted is something like a ternary tree structure, which have one parent node links to 3 child node.

But for the top most node (root), it can have more than 3 child nodes while all other node will stick to the limit of three. Currently my idea for the structure was storing one ancestor parent node (the parent of the parent node) and also 3 child node as a row of record in DB. The method of keeping track is to store the depth and also node number of the user currently in. The node number will start from 1, left to right on new depth.

But the problem arise when i tried to insert, as I have no optimize solution to identify the root user from other user when inserting to available node (unused node number) as I only keeping track the nodes of depth one, I will need to loop the query to select the next depth level to get the list of empty node (and the loop goes on if no available node found). Currently every info is stored in a single table, 1 to 1 relation. I'd like to know if there is any other effective way of doing this ?

Currently coding is done in php and MySql.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ESP8266连接阿里云出现问题
    • ¥15 被蓝屏搞吐了,有偿求帮解答,Ai回复直接拉黑
    • ¥15 BP神经网络控制倒立摆
    • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
    • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
    • ¥30 Unity接入微信SDK 无法开启摄像头
    • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
    • ¥20 cad图纸,chx-3六轴码垛机器人
    • ¥15 移动摄像头专网需要解vlan
    • ¥20 access多表提取相同字段数据并合并