I'm using MySQL and I'm wondering if it's a good strategy to presort my data so when a user accessed the information, it's not having to sort it on the fly?
Basically, I have an HTML table with is being populated with paginated data from the database, this is ordered by a particular column and can sometimes be a little sluggish - I was thinking about reordering the table on a nightly basis so the order by can be removed from the query.
Is this general practice or should I avoid this?
Update
My query is as follows:
'select keyword, position, impressions, clicks, ctr
from keywords where profile_id=%s
order by impressions desc limit %s, %s', (profile_id, start, end))
My table looks like this:
+---------------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+---------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| profile_id | int(11) | YES | MUL | NULL | |
| landing_page_id | int(11) | YES | MUL | NULL | |
| keyword | varchar(2083) | YES | | NULL | |
| position | int(11) | YES | MUL | NULL | |
| impressions | int(11) | YES | MUL | NULL | |
| ctr | float | YES | MUL | NULL | |
| clicks | int(11) | YES | MUL | NULL | |
| unique_key | varchar(200) | YES | UNI | NULL | |
| position_30_days | int(11) | YES | | NULL | |
| impressions_30_days | int(11) | YES | | NULL | |
| clicks_30_days | int(11) | YES | | NULL | |
| ctr_30_days | float | YES | | NULL | |
| position_60_days | int(11) | YES | | NULL | |
| impressions_60_days | int(11) | YES | | NULL | |
| clicks_60_days | int(11) | YES | | NULL | |
| ctr_60_days | float | YES | | NULL | |
| position_90_days | int(11) | YES | | NULL | |
| impressions_90_days | int(11) | YES | | NULL | |
| clicks_90_days | int(11) | YES | | NULL | |
| ctr_90_days | float | YES | | NULL | |
+---------------------+---------------+------+-----+---------+----------------+
order by– Adders Feb 15 '17 at 20:37ORDER BY field LIMIT x, y, and this is a major source of slowness. Could please post the query and the table structure:SHOW CREATE TABLE table_name– Jehad Keriaki Feb 16 '17 at 23:23SHOW CREATE TABLEand the statement with theORDER BY. – Rick James Feb 17 '17 at 01:11