Skip to content

Commit

Permalink
Merge pull request #323 from kinvolk/query_optim
Browse files Browse the repository at this point in the history
backend: Improve sql query performances
  • Loading branch information
joaquimrocha authored Jan 21, 2021
2 parents dc65fe0 + 116bcdb commit 00aa799
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 45 deletions.
89 changes: 56 additions & 33 deletions pkg/api/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions pkg/api/db/migrations/0011_add_composite_indexes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- +migrate Up

create index if not exists instance_application_instance_id_application_id_idx on instance_application (instance_id,application_id);

create index if not exists activity_class_created_ts_severity_version_group_id_applica_idx on activity (class,created_ts,severity,"version",group_id,application_id);

create index if not exists instance_application_application_id_group_id_last_check_for_idx on instance_application(application_id,group_id,last_check_for_updates,instance_id);

-- +migrate Down

drop index if exists instance_application_instance_id_application_id_idx;

drop index if exists activity_class_created_ts_severity_version_group_id_applica_idx;

drop index if exists instance_application_application_id_group_id_last_check_for_idx;
11 changes: 0 additions & 11 deletions pkg/api/db/migrations/0011_add_index_instance_application.sql

This file was deleted.

23 changes: 23 additions & 0 deletions pkg/api/db/migrations/0012_drop_unused_indexes.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
-- +migrate Up

drop index if exists users_team_id_idx;

drop index if exists instance_status_history_application_id_idx;

drop index if exists event_event_type_id_idx;

drop index if exists event_application_id_idx;

drop index if exists channel_package_id_idx;

-- +migrate Down

create index if not exists users_team_id_idx on users (team_id);

create index if not exists instance_status_history_application_id_idx on instance_status_history (application_id);

create index if not exists event_event_type_id_idx on event (event_type_id);

create index if not exists event_application_id_idx on event (application_id);

create index if not exists channel_package_id_idx on channel (package_id);
2 changes: 1 addition & 1 deletion pkg/api/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func (api *API) instanceAppQuery(appID, instanceID string, duration postgresDura
}

func ignoreFakeInstanceCondition(instanceIDField string) string {
return fmt.Sprintf(`(%[1]s IS NULL OR %[1]s NOT SIMILAR TO '\{[a-fA-F0-9-]{36}\}')`, instanceIDField)
return fmt.Sprintf(`(%[1]s IS NULL OR %[1]s NOT LIKE '{________-____-____-____-____________}')`, instanceIDField)
}

func (api *API) getFilterInstancesQuery(selectPart exp.LiteralExpression, p InstancesQueryParams, duration postgresDuration) *goqu.SelectDataset {
Expand Down

0 comments on commit 00aa799

Please sign in to comment.