Ron537
Ron537

Reputation: 990

Optimizing Permission-Based Filtering for Entities in Azure SQL Server

I'm working with Azure SQL Server (2019) and need to design an efficient way to filter entities based on user permissions.

Scenario:

Example:

Attempts and Issues

  1. Bitwise Representation:

    • Encode areas as bits and store a combined areaBits for each entity.
    • Query using: entities.areaBits & userExposedAreaBits = entities.areaBits.
    • Issue: Bitwise operations do not leverage indexes efficiently, leading to slow queries.
    • Tried precomputing permutations of area combinations, but this scales poorly (exponential growth).
  2. Join with Relationship Table (EntityAreas):

    • Store (EntityId, AreaId) pairs in a mapping table.
    • Filter entities by checking if the user has access to all required areas.
    • Issue: The query becomes complex and struggles with performance at scale.

Additional Considerations

Question

What is the best way to model and implement the main query to efficiently filter entities while ensuring a good execution plan? Looking for a solution that scales well with large datasets.

Upvotes: 0

Views: 44

Answers (0)

Related Questions