Below query is taking long time - around 540 seconds.
The table did not have any indexes. I created indexes on columns in the
WHEREclause and other fields but the query is not using these indexes.- Please suggest good indexes for this query.
Query:
select
alias_to,
fake_uri,
concat(ifnull(parameters,''),ifnull(parameters2,''),ifnull(parameters3,'')) as parameters,
precedence,
template_name
from site_map_template
order by precedence, fake_uri desc;
Explain output:
+----+-------------+-------------------+------+---------------+------+---------+------+------+----------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------------------+------+---------------+------+---------+------+------+----------------+
| 1 | SIMPLE | site_map_template | ALL | NULL | NULL | NULL | NULL | 7616 | Using filesort |
+----+-------------+-------------------+------+---------------+------+---------+------+------+----------------+
1 row in set (0.00 sec)
site_map_template table:
CREATE TABLE `site_map_template` (
`row_mod` datetime DEFAULT NULL,
`row_create` datetime DEFAULT NULL,
`template_name` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`alias_to` varchar(100) COLLATE latin1_bin DEFAULT NULL,
`package` varchar(50) COLLATE latin1_bin DEFAULT NULL,
`fake_uri` varchar(255) COLLATE latin1_bin DEFAULT NULL,
`precedence` int(11) DEFAULT NULL,
`parameters` varchar(255) COLLATE latin1_bin DEFAULT NULL,
`parameters2` varchar(255) COLLATE latin1_bin DEFAULT NULL,
`parameters3` varchar(255) COLLATE latin1_bin DEFAULT NULL,
KEY `idx_1372` (`template_name`),
KEY `idx_n1` (`precedence`),
KEY `idx_n2` (`fake_uri`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin


WHEREclause in your query, and theORDER BYspecifies two columns which is not in your single index (idx_1372). – dezso Feb 18 at 9:38