Unlimited pole promotion, how to quickly get the total number of subordinate users of a user?

Source: Internet
Author: User
At present, in the user table with the PID relationship between the subordinate, the statistics of a user's subordinate total number of the recursive query to 19, but later found in the number of users subordinate to the site directly to drag the dead, how should we deal with? Thank you..

Reply content:

At present, in the user table with the PID relationship between the subordinate, the statistics of a user's subordinate total number of the recursive query to 19, but later found in the number of users subordinate to the site directly to drag the dead, how should we deal with? Thank you..

Add a path field

This is actually in a lot of e-commerce station also encounter this kind of infinite class classification problem, design we sometimes why add a PID to identify sub-class, to the final query all have to kill themselves.

This is the time to modify the database table structure, allowing data redundancy to solve the problem.

Add:

The current table can be added to a column called Pid_list, which is stored in the format of 1 for the highest level of 2 is on-line, 3 for their own ID.

You can also add a level number that identifies the level at which you belong to depth,1 level 1, corresponding to pid_list.

After adding these, we will be more convenient to inquire.

Reference no series classification

You can add a path field

Increase the total number of children directly on each user record, a->b->c->d if C invites D, update the ABC three plus 1. This task can be processed asynchronously if it is not real-time.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.