From 35462dc96dc73f3fdd633d836a26e268fa60cf97 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Wed, 8 May 2024 18:33:21 +0530 Subject: [PATCH] server: fix full table scanning for listHosts API The type parameter isn't keyword, but a simple listHosts API call with type=Routing, runs SELECT COUNT(*) FROM host WHERE host.type LIKE '%Routing' AND host.removed IS NULL; ... which causes an unnecessary full table scan. Signed-off-by: Rohit Yadav --- .../src/main/java/com/cloud/api/query/QueryManagerImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java index e4bd7f99de5..e654207c615 100644 --- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java @@ -2146,7 +2146,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q // ids hostSearchBuilder.and("id", hostSearchBuilder.entity().getId(), SearchCriteria.Op.EQ); hostSearchBuilder.and("name", hostSearchBuilder.entity().getName(), SearchCriteria.Op.EQ); - hostSearchBuilder.and("type", hostSearchBuilder.entity().getType(), SearchCriteria.Op.LIKE); + hostSearchBuilder.and("type", hostSearchBuilder.entity().getType(), SearchCriteria.Op.EQ); hostSearchBuilder.and("status", hostSearchBuilder.entity().getStatus(), SearchCriteria.Op.EQ); hostSearchBuilder.and("dataCenterId", hostSearchBuilder.entity().getDataCenterId(), SearchCriteria.Op.EQ); hostSearchBuilder.and("podId", hostSearchBuilder.entity().getPodId(), SearchCriteria.Op.EQ); @@ -2198,7 +2198,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q sc.setParameters("name", name); } if (type != null) { - sc.setParameters("type", "%" + type); + sc.setParameters("type", type); } if (state != null) { sc.setParameters("status", state);