大資料下的sql語句使用,資料sql語句使用

來源:互聯網
上載者:User

大資料下的sql語句使用,資料sql語句使用

(一) mysql limit大資料量分頁最佳化方法

首先建立一個表 

CREATE TABLE `ipdatas` (  `id` int(11) NOT NULL AUTO_INCREMENT,  `uid` int(8) NOT NULL DEFAULT '0',  `ipaddress` varchar(50) 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;


插入大量資料100萬

begindeclare i int; set i = 10001 ;   myLoop: LOOP                      if i = 100000 then           leave myLoop;          end if;                    /* do something */          -- 迴圈輸出資訊 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;    /* 迴圈結束 */      end loop myLoop; end


最佳化語句 

原語句

 select * from ipdatas order by id limit 900000,100

受影響的行: 0
時間: 16.408s


最佳化語句

 Select * From ipdatas Where id>=( 
   Select id from ipdatas order by id limit 900000,1
    )limit 100; 



相關文章

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.