1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 class ComputePermissionIndex < ActiveRecord::Migration[5.2]
7 # The inner part of compute_permission_subgraph has a query clause like this:
9 # where u.perm_origin_uuid = m.target_uuid AND m.traverse_owned
10 # AND (m.user_uuid = m.target_uuid or m.target_uuid not like '_____-tpzed-_______________')
12 # This will end up doing a sequential scan on
13 # materialized_permissions, which can easily have millions of
14 # rows, unless we fully index the table for this query. In one test,
15 # this brought the compute_permission_subgraph query from over 6
16 # seconds down to 250ms.
18 ActiveRecord::Base.connection.execute "drop index if exists index_materialized_permissions_target_is_not_user"
19 ActiveRecord::Base.connection.execute %{
20 create index index_materialized_permissions_target_is_not_user on materialized_permissions (target_uuid, traverse_owned, (user_uuid = target_uuid or target_uuid not like '_____-tpzed-_______________'));
25 ActiveRecord::Base.connection.execute "drop index if exists index_materialized_permissions_target_is_not_user"