Loading

mysql EXPLAIN type列的system值

mysql官方文档:https://dev.mysql.com/doc/refman/5.7/en/explain-output.html#jointype_system

system

The table has only one row (= system table). This is a special case of the const join type.

翻译过来是: 该表只有一行(=系统表)。

但是创建一张只有一条记录的表执行 exlpain 后 type 值却是 const

创建表并插入一条数据:

DROP TABLE IF EXISTS `test_system`;
CREATE TABLE `test_system`  (
  `id` int(11) NOT NULL,
  `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

INSERT INTO `test_system` VALUES (1, 'name');

执行查询分析:

image

上面执行结果 type = const,与mysql文档说的不一样。

这是因为 test_system 使用的是 InnoDB 引擎。InnoDB 不能可靠地维护表大小,因此查询优化器不能确定表正好有 1 行。

当使用 MyISAM 时,它返回的是 type=system 而不是 type=const.

image

posted @ 2022-04-14 15:09  头牌彭鱼宴、  阅读(160)  评论(0编辑  收藏  举报