hi guys i got stuck on this, can someone give me some solution?
so the scenario issue like this
i have rows data more than 5 millions ,
so i make query for (count result found) example
i make 3 different search :
1.search byname
example data name
(Laptop asus tuf gaming adm ryzen 5)
because data long, so i use "ILIKE" for search
-
2.filter by shop name
example data shop name (tufStore) -
3.filter by country
example data country (maroko)
the issue is query for count result found so slowly (>20s)
so this query will run if user click button search / enter on keyboard
for the database part already indexing but still slowly for query count result found
so the main issue is query for count result found so slowly (>20s)
and I took the initiative to compare several queries (5 queri) for count result found
in this comparison i use the same keyword
-
- QUERY 1 (24.4s)
this the query :
- QUERY 1 (24.4s)
SELECT COUNT(p.id) as total_rows
FROM
products p
LEFT JOIN
stores s ON tp.store_id = s.id
LEFT JOIN
countries c ON p.country_id = c.id
WHERE
(
c.name ILIKE '%' || COALESCE({{FilterByCountryy.selectedLabel}}, '') || '%'
)
AND (
p.name ILIKE '%' || COALESCE({{InputName.value}}, '') || '%'
)
AND (
s.shop_name ILIKE '%' || COALESCE({{FilterByShop.selectedLabel}}, '') || '%'
)
-
- **QUERI 2 ** (24.7s)
this the query :
- **QUERI 2 ** (24.7s)
SELECT COUNT(p.id) as total_rows
FROM
products p
WHERE
(
p.name ILIKE '%' || COALESCE({{InputName.value}}, '') || '%'
)
AND
p.country_id = {{FilterByCountryy.value}}
-
- QUERI 3 (25.3s)
this the queri:
- QUERI 3 (25.3s)
SELECT COUNT(p.id) as total_rows
FROM
products p
WHERE
p.name ILIKE '%' || COALESCE({{InputName.value}}, '') || '%'
- 4 . QUERI 4 (22s)
this the query :
SELECT COUNT(p.id) as total_rows
FROM
products p
WHERE
(
p.name ILIKE '%' || COALESCE({{InputName.value}}, '') || '%'
)
AND
p.store_id = {{FilterByShop.value}}
-
- QUERI 5 (19.8s)
this the queri :
SELECT COUNT(p.id) as total_rows
FROM products p
WHERE
(
p.name ILIKE '%' || COALESCE({{InputName.value}}, '') || '%'
)
AND p.store_id = {{FilterByShop.value}}
AND p.country_id = {{FilterByCountryy.value}};