91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

mysql 5.6分區表應用

發布時間:2020-08-18 11:58:54 來源:ITPUB博客 閱讀:172 作者:wzgchen 欄目:MySQL數據庫

mysql 5.6分區表測試:
DROP TABLE IF EXISTS `my_orders`;
CREATE TABLE `my_orders` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '表主鍵',
  `pid` int(10) unsigned NOT NULL COMMENT '產品ID',
  `price` decimal(15,2) NOT NULL COMMENT '單價',
  `num` int(11) NOT NULL COMMENT '購買數量',
  `uid` int(10) unsigned NOT NULL COMMENT '客戶ID',
  `atime` datetime NOT NULL COMMENT '下單時間',
  `utime` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '修改時間',
  `isdel` tinyint(4) NOT NULL DEFAULT '0' COMMENT '軟刪除標識',
  PRIMARY KEY (`id`,`atime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8


/*********分區信息**************/

PARTITION BY RANGE (YEAR(atime))
(
   PARTITION p0 VALUES LESS THAN (2016),
   PARTITION p1 VALUES LESS THAN (2017),
   PARTITION p2 VALUES LESS THAN MAXVALUE
);

DROP TABLE IF EXISTS `my_order`;
CREATE TABLE `my_order` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT '表主鍵',
  `pid` int(10) unsigned NOT NULL COMMENT '產品ID',
  `price` decimal(15,2) NOT NULL COMMENT '單價',
  `num` int(11) NOT NULL COMMENT '購買數量',
  `uid` int(10) unsigned NOT NULL COMMENT '客戶ID',
  `atime` datetime NOT NULL COMMENT '下單時間',
  `utime` int(10) unsigned NOT NULL DEFAULT 0 COMMENT '修改時間',
  `isdel` tinyint(4) NOT NULL DEFAULT '0' COMMENT '軟刪除標識',
  PRIMARY KEY (`id`,`atime`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/**************************向分區表插入數據****************************/

INSERT INTO my_orders(`pid`,`price`,`num`,`uid`,`atime`) VALUES(1,12.23,1,89757,CURRENT_TIMESTAMP());
INSERT INTO my_orders(`pid`,`price`,`num`,`uid`,`atime`) VALUES(1,12.23,1,89757,'2016-05-01 00:00:00');
INSERT INTO my_orders(`pid`,`price`,`num`,`uid`,`atime`) VALUES(1,12.23,1,89757,'2017-05-01 00:00:00');
INSERT INTO my_orders(`pid`,`price`,`num`,`uid`,`atime`) VALUES(1,12.23,1,89757,'2018-05-01 00:00:00');
INSERT INTO my_orders(`pid`,`price`,`num`,`uid`,`atime`) VALUES(1,12.23,1,89756,'2015-05-01 00:00:00');
INSERT INTO my_orders(`pid`,`price`,`num`,`uid`,`atime`) VALUES(1,12.23,1,89756,'2016-05-01 00:00:00');
INSERT INTO my_orders(`pid`,`price`,`num`,`uid`,`atime`) VALUES(1,12.23,1,89756,'2017-05-01 00:00:00');
INSERT INTO my_orders(`pid`,`price`,`num`,`uid`,`atime`) VALUES(1,12.23,1,89756,'2018-05-01 00:00:00');

/**************************向未分區表插入數據****************************/

INSERT INTO my_order(`pid`,`price`,`num`,`uid`,`atime`) VALUES(1,12.23,1,89757,CURRENT_TIMESTAMP());
INSERT INTO my_order(`pid`,`price`,`num`,`uid`,`atime`) VALUES(1,12.23,1,89757,'2016-05-01 00:00:00');
INSERT INTO my_order(`pid`,`price`,`num`,`uid`,`atime`) VALUES(1,12.23,1,89757,'2017-05-01 00:00:00');
INSERT INTO my_order(`pid`,`price`,`num`,`uid`,`atime`) VALUES(1,12.23,1,89757,'2018-05-01 00:00:00');
INSERT INTO my_order(`pid`,`price`,`num`,`uid`,`atime`) VALUES(1,12.23,1,89756,'2015-05-01 00:00:00');
INSERT INTO my_order(`pid`,`price`,`num`,`uid`,`atime`) VALUES(1,12.23,1,89756,'2016-05-01 00:00:00');
INSERT INTO my_order(`pid`,`price`,`num`,`uid`,`atime`) VALUES(1,12.23,1,89756,'2017-05-01 00:00:00');
INSERT INTO my_order(`pid`,`price`,`num`,`uid`,`atime`) VALUES(1,12.23,1,89756,'2018-05-01 00:00:00';

/**********************************主從復制大量數據******************************/

INSERT INTO `my_orders`(`pid`,`price`,`num`,`uid`,`atime`) SELECT `pid`,`price`,`num`,`uid`,`atime` FROM `my_orders`;
INSERT INTO `my_order`(`pid`,`price`,`num`,`uid`,`atime`) SELECT `pid`,`price`,`num`,`uid`,`atime` FROM `my_order`;

/***************************查詢性能分析**************************************/

SELECT * FROM `my_orders` WHERE `uid`=89757 AND `atime`< CURRENT_TIMESTAMP();
/****用時0.084s****/
SELECT * FROM `my_order` WHERE `uid`=89757 AND `atime`< CURRENT_TIMESTAMP();
/****用時0.284s****/
EXPLAIN PARTITIONS SELECT * FROM `my_orders` WHERE `uid`=89757 AND `atime`< CURRENT_TIMESTAMP();
+----+-------------+-----------+------------+------+---------------+------+---------+------+-------+-------------+
| id | select_type | table     | partitions | type | possible_keys | key  | key_len | ref  | rows  | Extra       |
+----+-------------+-----------+------------+------+---------------+------+---------+------+-------+-------------+
|  1 | SIMPLE      | my_orders | p0,p1      | ALL  | NULL          | NULL | NULL    | NULL | 16419 | Using where |
+----+-------------+-----------+------------+------+---------------+------+---------+------+-------+-------------+
EXPLAIN PARTITIONS SELECT * FROM `my_order` WHERE `uid`=89757 AND `atime`< '2018-05-01 00:00:00';
+----+-------------+----------+------------+------+---------------+------+---------+------+-------+-------------+
| id | select_type | table    | partitions | type | possible_keys | key  | key_len | ref  | rows  | Extra       |
+----+-------------+----------+------------+------+---------------+------+---------+------+-------+-------------+
|  1 | SIMPLE      | my_order | NULL       | ALL  | NULL          | NULL | NULL    | NULL | 32099 | Using where |
+----+-------------+----------+------------+------+---------------+------+---------+------+-------+-------------+
如果查詢只有分區鍵,也可以用到分區裁剪,但沒有用到索引
EXPLAIN PARTITIONS SELECT * FROM `my_orders` WHERE `id`=36 AND `atime`< CURRENT_TIMESTAMP();;
+----+-------------+-----------+------------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table     | partitions | type  | possible_keys | key     | key_len | ref  | rows | Extra       |
+----+-------------+-----------+------------+-------+---------------+---------+---------+------+------+-------------+
|  1 | SIMPLE      | my_orders | p0,p1      | range | PRIMARY       | PRIMARY | 9       | NULL |    2 | Using where |
+----+-------------+-----------+------------+-------+---------------+---------+---------+------+------+-------------+
EXPLAIN PARTITIONS SELECT * FROM `my_order` WHERE `id`=36 AND `atime`< CURRENT_TIMESTAMP();;
+----+-------------+----------+------------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table    | partitions | type  | possible_keys | key     | key_len | ref  | rows | Extra       |
+----+-------------+----------+------------+-------+---------------+---------+---------+------+------+-------------+
|  1 | SIMPLE      | my_order | NULL       | range | PRIMARY       | PRIMARY | 9       | NULL |    1 | Using where |
+----+-------------+----------+------------+-------+---------------+---------+---------+------+------+-------------+


如果采用where id and atime查詢,則通過主鍵索引可以查詢,且可以用到分區

/*****************HASH 分區表*****************/

CREATE TABLE `msgs` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '表主鍵',
  `sender` int(10) unsigned NOT NULL COMMENT '發送者ID',
  `reciver` int(10) unsigned NOT NULL COMMENT '接收者ID',
  `msg_type` tinyint(3) unsigned NOT NULL COMMENT '消息類型',
  `msg` varchar(225) NOT NULL COMMENT '消息內容',
  `atime` int(10) unsigned NOT NULL COMMENT '發送時間',
  `sub_id` tinyint(3) unsigned NOT NULL COMMENT '部門ID',
  PRIMARY KEY (`id`,`sub_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

/*********分區信息**************/

PARTITION BY HASH(sub_id)
PARTITIONS 10;

/*****************LIST分區表*********************/

CREATE TABLE `products` (
`id`  bigint UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '表主鍵' ,
`name`  varchar(64) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '產品名稱' ,
`metrial`  tinyint UNSIGNED NOT NULL COMMENT '材質' ,
`weight`  double UNSIGNED NOT NULL DEFAULT 0 COMMENT '重量' ,
`vol`  double UNSIGNED NOT NULL DEFAULT 0 COMMENT '容積' ,
`c_id`  tinyint UNSIGNED NOT NULL COMMENT '供貨公司ID' ,
PRIMARY KEY (`id`,`c_id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8

/*********分區信息**************/

PARTITION BY LIST(c_id)
(
    PARTITION pA VALUES IN (1,3,11,13),
    PARTITION pB VALUES IN (2,4,12,14),
    PARTITION pC VALUES IN (5,7,15,17),
    PARTITION pD VALUES IN (6,8,16,18),
    PARTITION pE VALUES IN (9,10,19,20)
);
創建分區表:主鍵索引是分區鍵的一部分

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

潼关县| 驻马店市| 琼结县| 长阳| 会宁县| 牡丹江市| 邯郸市| 武鸣县| 南城县| 肇东市| 宁城县| 南雄市| 金山区| 南川市| 清河县| 花垣县| 临漳县| 松溪县| 红原县| 隆子县| 连南| 墨江| 库伦旗| 浙江省| 浦东新区| 十堰市| 宁化县| 汤阴县| 西林县| 当雄县| 信阳市| 舒城县| 霍州市| 台南县| 平顶山市| 太谷县| 高碑店市| 吉隆县| 左云县| 呈贡县| 平泉县|