Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2gb table with 10 million rows, late pagination select is slow

I have table in MySQL with 10 million rows with 2 GB data selecting IN LIFO format data is slow

Table engine is = InnoDB

table has one primary key and one unique key

SELECT * FROM link LIMIT 999999 , 50;

how I improve the performance of the table. ?

table structure

id  int(11) NO  PRI NULL    auto_increment
url varchar(255)    NO  UNI NULL    
website varchar(100)    NO      NULL    
state   varchar(10) NO      NULL    
type    varchar(100)    NO      NULL    
prio    varchar(100)    YES     NULL    
change  varchar(100)    YES     NULL    
last    varchar(100)    YES     NULL

NOTE: SELECT * FROM link LIMIT 1 , 50; is taking .9ms but current sql is taking 1000ms its 1000 time taking more

like image 408
Saurabh Chandra Patel Avatar asked Mar 24 '16 03:03

Saurabh Chandra Patel


People also ask

How do you optimize select query timing for million records?

1:- Check Indexes. 2:- There should be indexes on all fields used in the WHERE and JOIN portions of the SQL statement 3:- Limit Size of Your Working Data Set. 4:- Only Select Fields You select as Need. 5:- Remove Unnecessary Table and index 6:- Remove OUTER JOINS.

What is the best way to paginate results in SQL Server?

The best way for paging in sql server 2012 is by using offset and fetch next in a stored procedure. OFFSET Keyword - If we use offset with the order by clause then the query will skip the number of records we specified in OFFSET n Rows.

How can I get last 10 rows of a table in SQL?

Let us now implement the above query. mysql> SELECT * FROM ( -> SELECT * FROM Last10RecordsDemo ORDER BY id DESC LIMIT 10 -> )Var1 -> -> ORDER BY id ASC; The following is the output that displays the last 10 records. We can match both records with the help of the SELECT statement.


1 Answers

This most likely is due to "early row lookup"

MySQL can be forced to do "late row lookup". Try below query

SELECT  l.*
FROM    (
        SELECT  id
        FROM    link
        ORDER BY
                id
        LIMIT 999999 , 50
        ) q
JOIN    link l
ON      l.id = q.id

Check this article

MySQL limit clause and rate low lookups

like image 60
Sanj Avatar answered Sep 22 '22 12:09

Sanj