Domanda

i have very simple mysql table with 5 columns but 5 million data. earlier when data was less my server load was very less but now the load is increasing as the data is more than 5 million and i expect it to reach 10 million by this year end so server will be more slow.i have used indexed wisely

structure is very simple with id as auto increment and primary key and i am filtering the data based on id only which is automatically indexed as it is primary key(i tried indexing it as well but no benefit)

table A

   id   pid   title     app   get

my query is

    EXPLAIN SELECT * FROM tableA ORDER BY id DESC LIMIT 4061280 , 10

and explain says

 id      select_type    table    type   possible_keys   key    key_len    ref   rows            Extra
 1        SIMPLE       tableA    ALL      NULL         NULL      NULL     NULL  4700461       Using filesort

i dont want to go through all rows as it will slow down my server and create heavy load for file sorting as it will create temporary files either in buffer or in disc.

please advice any good idea to solve this issue.

when my id is indexed why it will go through all rows and reach to desired row.it can not jump directly to that row????

È stato utile?

Soluzione

Assuming you don't have "gaps" (read deleted records) in your id..

SELECT * FROM tableA WHERE id > 4061279 and id <= 4061290 ORDER BY id DESC

Ok next

SELECT * FROM tableA WHERE id <= 4061290 ORDER BY id DESC LIMIT 10
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top