Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(api): optimise archived list query. Fixes #13295 #13566

Merged
merged 3 commits into from
Sep 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions persist/sqldb/workflow_archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,37 @@ func (r *workflowArchive) ListWorkflows(options sutils.ListOptions) (wfv1.Workfl
return nil, err
}

selector := r.session.SQL().
Select(selectQuery).
subSelector := r.session.SQL().
Select(db.Raw("uid")).
From(archiveTableName).
Where(r.clusterManagedNamespaceAndInstanceID())

selector, err = BuildArchivedWorkflowSelector(selector, archiveTableName, archiveLabelsTableName, r.dbType, options, false)
subSelector, err = BuildArchivedWorkflowSelector(subSelector, archiveTableName, archiveLabelsTableName, r.dbType, options, false)
if err != nil {
return nil, err
}

if r.dbType == MySQL {
// workaround for mysql 42000 error (Unsupported subquery syntax):
//
// Error 1235 (42000): This version of MySQL doesn't yet support 'LIMIT \u0026 IN/ALL/ANY/SOME subquery'
//
// more context:
// * https://dev.mysql.com/doc/refman/8.0/en/subquery-errors.html
// * https://dev.to/gkoniaris/limit-mysql-subquery-results-inside-a-where-in-clause-using-laravel-s-eloquent-orm-26en
subSelector = r.session.SQL().Select(db.Raw("*")).From(subSelector).As("x")
}

agilgur5 marked this conversation as resolved.
Show resolved Hide resolved
// why a subquery? the json unmarshal triggers for every row in the filter
// query. by filtering on uid first, we delay json parsing until a single
// row, speeding up the query(e.g. 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}),
)

err = selector.All(&archivedWfs)
if err != nil {
return nil, err
Expand Down
Loading