0
0
Snowflakecloud~5 mins

System-defined roles (ACCOUNTADMIN, SYSADMIN, etc.) in Snowflake - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: System-defined roles (ACCOUNTADMIN, SYSADMIN, etc.)
O(n)
Understanding Time Complexity

We want to understand how the time to check or assign system-defined roles changes as the number of users or roles grows.

How does the system handle these roles efficiently as more users or permissions are involved?

Scenario Under Consideration

Analyze the time complexity of querying role grants for users.


-- List roles granted to a user
SHOW GRANTS TO USER some_user;

-- List users granted a system-defined role
SHOW GRANTS OF ROLE SYSADMIN;

-- Assign a system-defined role to a user
GRANT ROLE SYSADMIN TO USER some_user;
    

This sequence shows checking and assigning system-defined roles to users.

Identify Repeating Operations

Look at the main operations that happen repeatedly when managing roles.

  • Primary operation: Checking role grants involves scanning role assignments.
  • How many times: Once per user or role queried, but can involve multiple role entries.
How Execution Grows With Input

As the number of users or roles grows, the system checks more entries.

Input Size (n)Approx. API Calls/Operations
10 users/rolesAbout 10 role checks
100 users/rolesAbout 100 role checks
1000 users/rolesAbout 1000 role checks

Pattern observation: The number of checks grows roughly in direct proportion to the number of users or roles involved.

Final Time Complexity

Time Complexity: O(n)

This means the time to check or assign system-defined roles grows linearly with the number of users or roles.

Common Mistake

[X] Wrong: "Assigning a system-defined role is instant no matter how many users exist."

[OK] Correct: Even though the command is simple, the system must update and verify role assignments, which takes longer as more users or roles exist.

Interview Connect

Understanding how role management scales helps you design secure and efficient access controls in cloud systems.

Self-Check

"What if we cached role assignments? How would the time complexity change when checking roles for many users?"