SQL statements under Big data are used

Source: Internet
Author: User

AMySQL limit large data volume paging optimization method

First create a table

CREATE TABLE ' Ipdatas ' (  ' id ' int (one) not null auto_increment,  ' uid ' int (8) is not null DEFAULT ' 0 '  , ' IPAddress ' varchar () Not NULL,  ' source ' varchar (255) default NULL,  ' track ' varchar (255) default NULL,  ' entrance ' varchar (255) DEFAULT null,  ' createdtime ' datetime NOT NULL DEFAULT ' 0000-00-00 00:00:00 ',  ' createddate ' date not NULL DEFAULT ' 0000-00-00 ',  PRIMARY key (' id '),  key ' uid ' (' uid ')) Engine=myisam auto_increment=68293856 DEFAULT Charset=utf8;


Inserting large amounts of data 1 million

begindeclare I int; Set i = 10001;   Myloop:loop                      If i = 100000 then           leave Myloop;          End If;                    /* Do something */          --loop output information insert INTO ' ipdatas ' (' uid ', ' ipaddress ', ' source ', ' track ', ' Entrance ', ' createdtime ', ' CreatedDate ') VALUES (i, ' 127.0.0.1 ', ' Wanglitao ', ' Guoyanhui ', ' 127.0.0.1 ', now (), now ());      Set i = i +1;    /* Loop End */end      loop myloop; end


Optimization statements

Original statement

SELECT * from Ipdatas ORDER by ID limit 900000,100

Rows affected: 0
Time: 16.408s


Optimization statements

Select * from Ipdatas Where id>= (
Select ID from Ipdatas ORDER by ID limit 900000,1
) limit 100;



SQL statements under Big Data use

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.