I have a table with a million of records, i need to select the distinct values of log_type. In other queries i also need to filter log_types result of the distinct and limit the result. But the query is really slow, also this simple one
select distinct log_type
from app_logs;
log_type has an index but nothing change without index, query always use Seq Scan
This is the explain
Aggregate (cost) 119007.80 - 119008.03 (rows) 29 (time) 1923.251
|- Seq Scan (cost) 0.00 - 115796.84 (rows) 1284384 (time) 1300.025
I read other posts but not helped me to find a solution (if exists).
There is any way to improve the performace? Maybe the only my solution is cache the complete distinct results in server application.
ps. i can't define custom functions on db server
log_type
sound much like an enum, and I would expectselect distinct log_type
to return more or less the same result each time.log_type
values do you have? How often do you update the table statistics?