MYSQL表分区测试命令
本篇内容主要讲解“MySQL表分区测试命令”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“MYSQL表分区测试命令”吧!
站在用户的角度思考问题,与客户深入沟通,找到河西网站设计与河西网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站建设、网站建设、企业官网、英文网站、手机端网站、网站推广、域名注册、网站空间、企业邮箱。业务覆盖河西地区。
参考:https://blog.csdn.net/fengnp/article/details/81239286
-- 1. 创建分区表
CREATE TABLE part_tab(
c1 INT DEFAULT NULL,
c2 VARCHAR(30) DEFAULT NULL,
c3 DATE NOT NULL
) PARTITION BY RANGE(YEAR(c3)) (
PARTITION p0 VALUES LESS THAN (1995),
PARTITION p1 VALUES LESS THAN (1996) ,
PARTITION p2 VALUES LESS THAN (1997) ,
PARTITION p3 VALUES LESS THAN (1998) ,
PARTITION p4 VALUES LESS THAN (1999) ,
PARTITION p5 VALUES LESS THAN (2000) ,
PARTITION p6 VALUES LESS THAN (2001) ,
PARTITION p7 VALUES LESS THAN (2002) ,
PARTITION p8 VALUES LESS THAN (2003) ,
PARTITION p9 VALUES LESS THAN (2004) ,
PARTITION p10 VALUES LESS THAN (2010),
PARTITION p11 VALUES LESS THAN (MAXVALUE)
);
-- 2. 创建不分区表
CREATE TABLE no_part_tab(
c1 INT DEFAULT NULL,
c2 VARCHAR(30) DEFAULT NULL,
c3 DATE NOT NULL
);
-- 3. 查询
SELECT * FROM part_tab;
SELECT * FROM no_part_tab;
-- 4. 存储过程插入数据
DROP PROCEDURE IF EXISTS load_part_tab;
DELIMITER //
CREATE PROCEDURE load_part_tab()
BEGIN
DECLARE v INT DEFAULT 0;
WHILE v < 8000000
DO
INSERT INTO part_tab VALUES (v, 'testing partitions', ADDDATE('1995-01-01', (RAND(v)*36520)MOD 3652));
SET v = v + 1;
END WHILE;
END;
//
CALL load_part_tab;
INSERT INTO no_part_tab SELECT * FROM part_tab;
-- 5. 测试查询效率
SELECT COUNT(*) FROM part_tab WHERE c3 > DATE '1995-01-01'AND c3 < DATE '1995-12-31';
SELECT COUNT(*) FROM no_part_tab WHERE c3 > DATE '1995-01-01'AND c3 < DATE '1995-12-31';
-- 6. 通过explain语句来分析执行情况
EXPLAIN SELECT COUNT(*) FROM part_tab WHERE c3 > DATE '1995-01-01'AND c3 < DATE '1995-12-31';
EXPLAIN SELECT COUNT(*) FROM no_part_tab WHERE c3 > DATE '1995-01-01'AND c3 < DATE '1995-12-31';
到此,相信大家对“MYSQL表分区测试命令”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
网页标题:MYSQL表分区测试命令
网页路径:http://pwwzsj.com/article/gohdco.html