From 367f21c5c0081454d280717206ed55f3d1eba0a3 Mon Sep 17 00:00:00 2001 From: Xiaofan Hu Date: Mon, 9 Sep 2024 22:04:59 +0800 Subject: [PATCH] fix: add a subquery comment in *workflowArchive.ListWorkflows related to 9856df7e116efb943f5c9e1f0cc12435b860dbc3 Signed-off-by: Xiaofan Hu --- persist/sqldb/workflow_archive.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/persist/sqldb/workflow_archive.go b/persist/sqldb/workflow_archive.go index 618c3d836bab..e8139ead03ef 100644 --- a/persist/sqldb/workflow_archive.go +++ b/persist/sqldb/workflow_archive.go @@ -184,6 +184,14 @@ func (r *workflowArchive) ListWorkflows(options sutils.ListOptions) (wfv1.Workfl subSelector = r.session.SQL().Select(db.Raw("*")).From(subSelector).As("x") } + // why using a subquery: the json unmarshaling process of coalesce + // (workflow) is always triggered for every records in the filtering query + // in postgres (and maybe mysql as well). by first filtering out uid first + // without trying to unmarshal the workflow, it kinda teach the database to + // delay the json parsing operation and thus speed up the query (could be + // up to 257 times faster for some deployments). + // + // more context: https://github.com/argoproj/argo-workflows/pull/13566 selector := r.session.SQL().Select(selectQuery).From(archiveTableName).Where( r.clusterManagedNamespaceAndInstanceID().And(db.Cond{"uid IN": subSelector}), )