Adjust the query by UUID sql so that it can use the idx_task_extra_at… (#20545)

Adjust the query by UUID sql so that it can use the idx_task_extra_attrs_report_uuids

 fixes #20505

Signed-off-by: stonezdj <stone.zhang@broadcom.com>
This commit is contained in:
stonezdj(Daojun Zhang) 2024-06-11 14:37:53 +08:00 committed by GitHub
parent cea7ed0b04
commit b5f7a61e36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -114,8 +114,8 @@ func (t *taskDAO) ListScanTasksByReportUUID(ctx context.Context, uuid string) ([
} }
var tasks []*Task var tasks []*Task
param := fmt.Sprintf(`{"report_uuids":["%s"]}`, uuid) param := fmt.Sprintf(`"%s"`, uuid)
sql := `SELECT * FROM task WHERE extra_attrs::jsonb @> cast( ? as jsonb )` sql := `SELECT * FROM task WHERE extra_attrs::jsonb -> 'report_uuids' @> ?`
_, err = ormer.Raw(sql, param).QueryRows(&tasks) _, err = ormer.Raw(sql, param).QueryRows(&tasks)
if err != nil { if err != nil {
return nil, err return nil, err