Add indexes on update_time (#3974)

* Add indexes on update_time

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Co-authored-by: Michael Gaffney <mike@gaffney.cc>
This commit is contained in:
authored and Johan Brandhorst-Satzkorn committed 2024-01-05 07:43:20 -08:00
1 parent 43cff11865
commit 5bfc8a88b1
3 files changed
+68 -1

No files matched your search

@@ -0,0 +1,39 @@
-- Copyright (c) HashiCorp, Inc.
-- SPDX-License-Identifier: BUSL-1.1
begin;
create index auth_ldap_account_update_time_idx on auth_ldap_account (update_time);
create index auth_ldap_managed_group_update_time_idx on auth_ldap_managed_group (update_time);
create index auth_ldap_method_update_time_idx on auth_ldap_method (update_time);
create index auth_oidc_account_update_time_idx on auth_oidc_account (update_time);
create index auth_oidc_managed_group_update_time_idx on auth_oidc_managed_group (update_time);
create index auth_oidc_method_update_time_idx on auth_oidc_method (update_time);
create index auth_password_account_update_time_idx on auth_password_account (update_time);
create index auth_password_method_update_time_idx on auth_password_method (update_time);
create index auth_token_update_time_idx on auth_token (update_time);
create index credential_static_json_credential_update_time_idx on credential_static_json_credential (update_time);
create index credential_static_ssh_private_key_credential_update_time_idx on credential_static_ssh_private_key_credential (update_time);
create index credential_static_store_update_time_idx on credential_static_store (update_time);
create index credential_static_username_password_credential_update_time_idx on credential_static_username_password_credential (update_time);
create index credential_vault_library_update_time_idx on credential_vault_library (update_time);
create index credential_vault_ssh_cert_library_update_time_idx on credential_vault_ssh_cert_library (update_time);
create index credential_vault_store_update_time_idx on credential_vault_store (update_time);
create index host_plugin_catalog_update_time_idx on host_plugin_catalog (update_time);
create index host_plugin_host_update_time_idx on host_plugin_host (update_time);
create index host_plugin_set_update_time_idx on host_plugin_set (update_time);
create index iam_group_update_time_idx on iam_group (update_time);
create index iam_role_update_time_idx on iam_role (update_time);
create index iam_scope_update_time_idx on iam_scope (update_time);
create index iam_user_update_time_idx on iam_user (update_time);
create index recording_session_update_time_idx on recording_session (update_time);
create index server_worker_update_time_idx on server_worker (update_time);
create index session_update_time_idx on session (update_time);
create index static_host_catalog_update_time_idx on static_host_catalog (update_time);
create index static_host_update_time_idx on static_host (update_time);
create index static_host_set_update_time_idx on static_host_set (update_time);
create index storage_plugin_storage_bucket_update_time_idx on storage_plugin_storage_bucket (update_time);
create index target_ssh_update_time_idx on target_ssh (update_time);
create index target_tcp_update_time_idx on target_tcp (update_time);
commit;
+2 -1
View File
@@ -34,7 +34,8 @@ TESTS ?= tests/setup/*.sql \
tests/history/*.sql \
tests/recording/*.sql \
tests/auth/*/*.sql \
tests/purge/*sql
tests/purge/*sql \
tests/index/*sql
POSTGRES_DOCKER_IMAGE_BASE ?= postgres
@@ -0,0 +1,27 @@
-- Copyright (c) HashiCorp, Inc.
-- SPDX-License-Identifier: BUSL-1.1
begin;
create function op_table(deletion_table_name name) returns text
as $$
select split_part(deletion_table_name, '_deleted', 1);
$$ language sql;
create function has_update_time_index(table_name name) returns text
as $$
select * from collect_tap(
has_index(table_name, table_name || '_update_time_idx', 'update_time')
);
$$ language sql;
-- the op table for each deletion table should be tested for the index
select plan(a.table_count::integer)
from (
select count(*) as table_count
from get_deletion_tables()
) as a;
select has_update_time_index(op_table(a))
from get_deletion_tables() a;
select * from finish();
rollback;