Storing Hierarchical Data (MySQL) for Referral Marketing

后端 未结 4 828
长发绾君心
长发绾君心 2021-01-12 23:20

I need to have a 5 levels hierarchy for the users registered to a website. Every user is invited by another, and I need to know all descendants for a user. And also ancestor

4条回答
  •  天涯浪人
    2021-01-13 00:02

    Managing Hierarchical Data in MySQL

    In general, I like the "nested set", esp. in MySQL which doesn't really have language support for hierarchical data. It's fast, but you'll need to make sure your developers read that article if ease of maintenance is a big deal. It's very flexible - which doesn't seem to matter much in your case.

    It seems a good fit for your problem - in the referral model, you need to find the tree of referrers, which is fast in the nested set model; you also need to know who are the ~children@ of a given user, and the depth of their relationship; this is also fast.

提交回复
热议问题