internal/db: optimize session list indexes
This commit is contained in:
1 parent
c28a8ecfeb
commit
b6fe9824ab
4 files changed
+35
-9
No files matched your search
@@ -4,6 +4,7 @@
|
||||
begin;
|
||||
-- Session list queries always use an order by on create_time.
|
||||
-- This index can aide in performing this order by.
|
||||
-- Dropped in 81/05_session_base_table_updates.up.sql.
|
||||
create index
|
||||
session_create_time
|
||||
on
|
||||
|
||||
@@ -9,6 +9,7 @@ begin;
|
||||
-- it will include where clauses that:
|
||||
-- * include a project_id paired with a user_id
|
||||
-- * and where termination_reason is null
|
||||
-- Dropped in 81/05_session_base_table_updates.up.sql.
|
||||
create index session_list_pix on session (project_id, user_id, termination_reason) where termination_reason is null;
|
||||
analyze session;
|
||||
end;
|
||||
@@ -3,11 +3,33 @@
|
||||
|
||||
begin;
|
||||
|
||||
-- Add new indexes for the create time and update time queries.
|
||||
create index session_create_time_public_id_idx
|
||||
on session (create_time desc, public_id desc);
|
||||
create index session_update_time_public_id_idx
|
||||
on session (update_time desc, public_id desc);
|
||||
-- Drop old list indexes that interfere with the new list requests.
|
||||
drop index session_create_time, session_list_pix;
|
||||
|
||||
-- Add new indexes for the list queries. These indexes have been
|
||||
-- carefully tested to cover the different expected queries.
|
||||
create index session_project_id_create_time_list_idx
|
||||
on session (project_id,
|
||||
create_time desc,
|
||||
public_id desc,
|
||||
termination_reason);
|
||||
create index session_project_id_update_time_list_idx
|
||||
on session (project_id,
|
||||
update_time desc,
|
||||
public_id desc,
|
||||
termination_reason);
|
||||
create index session_user_id_project_id_create_time_list_idx
|
||||
on session (user_id,
|
||||
project_id,
|
||||
create_time desc,
|
||||
public_id desc,
|
||||
termination_reason);
|
||||
create index session_user_id_project_id_update_time_list_idx
|
||||
on session (user_id,
|
||||
project_id,
|
||||
update_time desc,
|
||||
public_id desc,
|
||||
termination_reason);
|
||||
|
||||
analyze session;
|
||||
|
||||
|
||||
@@ -2,11 +2,13 @@
|
||||
-- SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
begin;
|
||||
select plan(2);
|
||||
select plan(4);
|
||||
|
||||
select has_index('session', 'session_create_time_public_id_idx', array['create_time', 'public_id']);
|
||||
select has_index('session', 'session_update_time_public_id_idx', array['update_time', 'public_id']);
|
||||
select has_index('session', 'session_project_id_create_time_list_idx', array['project_id', 'create_time', 'public_id', 'termination_reason']);
|
||||
select has_index('session', 'session_project_id_update_time_list_idx', array['project_id', 'update_time', 'public_id', 'termination_reason']);
|
||||
select has_index('session', 'session_user_id_project_id_create_time_list_idx', array['user_id', 'project_id', 'create_time', 'public_id', 'termination_reason']);
|
||||
select has_index('session', 'session_user_id_project_id_update_time_list_idx', array['user_id', 'project_id', 'update_time', 'public_id', 'termination_reason']);
|
||||
|
||||
select * from finish();
|
||||
|
||||
rollback;
|
||||
rollback;
|
||||
Reference in new issue
Block a user