From 70255684c5711a065b4412e94ed7c5401b9435db Mon Sep 17 00:00:00 2001 From: "stonezdj(Daojun Zhang)" Date: Tue, 4 Jun 2024 18:29:53 +0800 Subject: [PATCH] =?UTF-8?q?[cherry-pick]=20Adjust=20the=20query=20by=20UUI?= =?UTF-8?q?D=20sql=20so=20that=20it=20can=20use=20the=20idx=5Ftask=5Fextra?= =?UTF-8?q?=5Fat=E2=80=A6=20(#20546)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adjust the query by UUID sql so that it can use the idx_task_extra_attrs_report_uuids fixes #20505 Signed-off-by: stonezdj --- src/pkg/task/dao/task.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pkg/task/dao/task.go b/src/pkg/task/dao/task.go index 177738561..b42781c17 100644 --- a/src/pkg/task/dao/task.go +++ b/src/pkg/task/dao/task.go @@ -114,8 +114,8 @@ func (t *taskDAO) ListScanTasksByReportUUID(ctx context.Context, uuid string) ([ } var tasks []*Task - param := fmt.Sprintf(`{"report_uuids":["%s"]}`, uuid) - sql := `SELECT * FROM task WHERE extra_attrs::jsonb @> cast( ? as jsonb )` + param := fmt.Sprintf(`"%s"`, uuid) + sql := `SELECT * FROM task WHERE extra_attrs::jsonb -> 'report_uuids' @> ?` _, err = ormer.Raw(sql, param).QueryRows(&tasks) if err != nil { return nil, err