MySQL千万级别表数据中提高RAND随机查询的实验

1,准备测试数据

DELIMITER $$

USE `hwdb`$$

DROP PROCEDURE IF EXISTS `pro_insert_hw`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE`pro_insert_hw`(num INT)

BEGIN

DECLARE var1 INT DEFAULT 0;

WHILE var1<num DO

SET var1=var1+1;

INSERT INTO hwdb.t_huawei(hwid,content,TYPE,creator_id,create_time)

VALUES (var1,CONCAT(var1,’ – ‘,’Players supposedly said they”d avoidteam facility this summer if Thibodeau remained the ‘),

0,10013,NOW());

END WHILE;

END$$

DELIMITER ;

mysql> show create table t_huawei;

+———-+—————————————————————————————————————————————————————————————————————————————————–+

| Table| Create Table|

+———-+—————————————————————————————————————————————————————————————————————————————————–+

| t_huawei | CREATE TABLE `t_huawei` (

`hwid` int(11) DEFAULT NULL,

`content` varchar(4000) DEFAULT NULL,

`TYPE` char(2) DEFAULT NULL,

`creator_id`varchar(30) DEFAULT NULL,

`create_time` datetime DEFAULT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8 |

+———-+—————————————————————————————————————————————————————————————————————————————————–+

1 row in set (0.00 sec)

mysql>

mysql> SELECT SQL_NO_CACHE * FROM `t_huawei` AS t1 ORDER BY RAND() LIMIT 5;

+———+—————————————————————————————————–+——+————+———————+

| hwid| content| TYPE |creator_id | create_time |

+———+—————————————————————————————————–+——+————+———————+

| 3743323 | 3743323 – Players supposedlysaid they’d avoid team facility this summer if Thibodeau remained the | 0| 10013 | 2015-06-08 20:43:01|

| 2418491 | 2418491 – Players supposedlysaid they’d avoid team facility this summer if Thibodeau remained the | 0| 10013 | 2015-06-08 20:19:31|

| 1224667 | 1224667 – Players supposedlysaid they’d avoid team facility this summer if Thibodeau remained the | 0| 10013 | 2015-06-08 19:58:35|

没有一种不通过蔑视、忍受和奋斗就可以征服的命运。

MySQL千万级别表数据中提高RAND随机查询的实验

相关文章:

你感兴趣的文章:

标签云: