문제

I'm planning a system where users will be stored in a Nested Set Hierarchy of groups (e.g. Board Members, Regions, Divisions, Teams), that will be used to determine what level of data they can see. I need to plan for the Hierarchy to contain potentially thousands of users.

Data to be reported on is stored in a SQL Server 2008 database, with each applicable record linked to the ID of the user who performed that action (e.g., a telephone call)

I'll need to query the database to gather totals that apply to either an individual user, or, a collection of users from the Hierarchy (e.g., Gather the count of all Calls made for a day by members of Division X, or, all calls made across the entire Company).

Assuming the following query:

    SELECT Count(Id) FROM Calls 
    JOIN
    (
        SELECT Heirarchy.UserId 
        FROM Heirarchy
        {nested set joins}
        WHERE {nested set conditions to get relevant UserIds}
    ) H1
    ON Calls.UserId = H1.UserId 
    WHERE {conditions}

As the hierarchy will contain thousands of users, if a Top Level group user (e.g., a Board Member) runs the above query, all user records will be returned by the sub query and matched on.

1) Is this the correct approach to model such a system?

2) Can anyone see any issues and if so, suggest improvements?

3) Can anyone suggest alternative methods to achieve the above?

도움이 되었습니까?

해결책

This approach worked fine - system's been live since Jan '13 with no issues.

Still interested if anyone has an alternative

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top