Skip to content
  • Tim Hunt's avatar
    482ca720
    MDL-47426 assign local roles: rewrite query for better performance. · 482ca720
    Tim Hunt authored
    This is an extremely dangerous query, because it includes the user
    table twice, along-side two other potentially large tables,
    role_assignments and user_enrolments.
    
    The solution is to rewrite the query so that:
    
    1. The subquery is JOINed, not WHERE ... INed. Typically query
       optimisers handle the JOIN case better.
    
    2. Before the join was role-assignments <-> users <-> subquery.
       That is, everything was linked to u.id.
    
       Now the linking is role-assignments <-> subquery <-> users,
       so the SELECT DISTINT eu1_u.id FROM {enrolled users} is central.
       That seems to send a strong hint to the query optimiser about
       a good order to execute the query.
    482ca720
    MDL-47426 assign local roles: rewrite query for better performance.
    Tim Hunt authored
    This is an extremely dangerous query, because it includes the user
    table twice, along-side two other potentially large tables,
    role_assignments and user_enrolments.
    
    The solution is to rewrite the query so that:
    
    1. The subquery is JOINed, not WHERE ... INed. Typically query
       optimisers handle the JOIN case better.
    
    2. Before the join was role-assignments <-> users <-> subquery.
       That is, everything was linked to u.id.
    
       Now the linking is role-assignments <-> subquery <-> users,
       so the SELECT DISTINT eu1_u.id FROM {enrolled users} is central.
       That seems to send a strong hint to the query optimiser about
       a good order to execute the query.
Loading