<#6428 [BUG] Not using DB index to list executions...
# flyte-github
c
#6428 [BUG] Not using DB index to list executions (slow workflows page in UI) Issue created by mruoss ### Describe the bug ## Summary Loading the workflow page in the Flyte UI can take up to minutes to load if a DB holds many workflows. At the same time one can see CPU spikes on the database with every hit of such a page. ## How to reproduce On a project with >50000 registered workflows, in the Flyte UI select "Workflows" in the left navbar and select a workflow. This page takes ages to load. ## Debugging We have enabled slow_query logs and have discovered the following query as a suspect: SELECT "executions"."id", "executions"."created_at", "executions"."updated_at", "executions"."deleted_at", "executions"."execution_project", "executions"."execution_domain", "executions"."execution_name", "executions"."launch_plan_id", "executions"."workflow_id", "executions"."task_id", "executions"."phase", "executions"."closure", "executions"."spec", "executions"."started_at", "executions"."execution_created_at", "executions"."execution_updated_at", "executions"."duration", "executions"."abort_cause", "executions"."mode", "executions"."source_execution_id", "executions"."parent_node_execution_id", "executions"."cluster", "executions"."inputs_uri", "executions"."user_inputs_uri", "executions"."error_kind", "executions"."error_code", "executions"."user", "executions"."state", "executions"."launch_entity" FROM "executions" INNER JOIN workflows ON executions.workflow_id = workflows.id WHERE executions.execution_project = $1 AND executions.execution_domain = $2 AND workflows.name = $3 AND executions.state = $4 ORDER BY created_at DESC LIMIT 1 The problem here is that in the database there is no index over JUST the column
workflows.name
. However, there is an index
workflow_project_domain_name_idx" btree (project, domain, name)
. The performence for above query could be improved significantlyby filtering
project
and
domain
on the
workflows
table instead of the
executions
table: SELECT "executions"."id", "executions"."created_at", "executions"."updated_at", "executions"."deleted_at", "executions"."execution_project", "executions"."execution_domain", "executions"."execution_name", "executions"."launch_plan_id", "executions"."workflow_id", "executions"."task_id", "executions"."phase", "executions"."closure", "executions"."spec", "executions"."started_at", "executions"."execution_created_at", "executions"."execution_updated_at", "executions"."duration", "executions"."abort_cause", "executions"."mode", "executions"."source_execution_id", "executions"."parent_node_execution_id", "executions"."cluster", "executions"."inputs_uri", "executions"."user_inputs_uri", "executions"."error_kind", "executions"."error_code", "executions"."user", "executions"."state", "executions"."launch_entity" FROM "executions" INNER JOIN workflows ON executions.workflow_id = workflows.id WHERE workflows.project = $1 AND workflows.domain = $2 AND workflows.name = $3 AND executions.state = $4 ORDER BY created_at DESC LIMIT 1 ### Expected behavior I'd expect the UI page to be much faster and the queries to leverage existing indexes (or otherwise an index over
workflows.name
to be created). ### Additional context to reproduce No response ### Screenshots No response ### Are you sure this issue hasn't been raised already? • Yes ### Have you read the Code of Conduct? • Yes flyteorg/flyte