21700: Install Bundler system-wide in Rails postinst
[arvados.git] / services / api / db / migrate / 20231013000000_compute_permission_index.rb
1 # Copyright (C) The Arvados Authors. All rights reserved.
2 #
3 # SPDX-License-Identifier: AGPL-3.0
4
5 class ComputePermissionIndex < ActiveRecord::Migration[5.2]
6   def up
7     # The inner part of compute_permission_subgraph has a query clause like this:
8     #
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-_______________')
11     #
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.
17     #
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-_______________'));
21 }
22   end
23
24   def down
25     ActiveRecord::Base.connection.execute "drop index if exists index_materialized_permissions_target_is_not_user"
26   end
27 end