fixed for #7803(pkgagent too slow on large uploads), optimize the unefficient query.