mysql explain key为空_mysql已经设置主键, 但explain显示key=null, type=all?

在navicat里检查, 确实id已经被设置为主键了.

explain显示key=null, type=all? 问题出在哪?

该怎么优化呢?

这个是wordpress网站, 按道理说这里的表和数据库结构都是wordpress自动生成的, 我这怎么会有这样问题呢?

MariaDB [jinz]> explain select * from wp_posts;

+------+-------------+----------+------+---------------+------+---------+------+------+-------+

| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |

+------+-------------+----------+------+---------------+------+---------+------+------+-------+

| 1 | SIMPLE | wp_posts | ALL | NULL | NULL | NULL | NULL | 413 | |

+------+-------------+----------+------+---------------+------+---------+------+------+-------+

1 row in set (0.00 sec)

MariaDB [jinz]> explain select * from wp_posts where id =1;

+------+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+

| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |

+------+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+

| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Impossible WHERE noticed after reading const tables |

+------+-------------+-------+------+---------------+------+---------+------+------+-----------------------------------------------------+

1 row in set (0.00 sec)

wp_posts | CREATE TABLE `wp_posts` (

`ID` bigint(20) unsigned NOT NULL AUTO_INCREMENT,

`post_author` bigint(20) unsigned NOT NULL DEFAULT '0',

`post_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',

`post_date_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',

`post_content` longtext COLLATE utf8mb4_unicode_ci NOT NULL,

`post_title` text COLLATE utf8mb4_unicode_ci NOT NULL,

`post_excerpt` text COLLATE utf8mb4_unicode_ci NOT NULL,

`post_status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'publish',

`comment_status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'open',

`ping_status` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'open',

`post_password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',

`post_name` varchar(200) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',

`to_ping` text COLLATE utf8mb4_unicode_ci NOT NULL,

`pinged` text COLLATE utf8mb4_unicode_ci NOT NULL,

`post_modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',

`post_modified_gmt` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',

`post_content_filtered` longtext COLLATE utf8mb4_unicode_ci NOT NULL,

`post_parent` bigint(20) unsigned NOT NULL DEFAULT '0',

`guid` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',

`menu_order` int(11) NOT NULL DEFAULT '0',

`post_type` varchar(20) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'post',

`post_mime_type` varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '',

`comment_count` bigint(20) NOT NULL DEFAULT '0',

PRIMARY KEY (`ID`),

KEY `post_name` (`post_name`(191)),

KEY `type_status_date` (`post_type`,`post_status`,`post_date`,`ID`),

KEY `post_parent` (`post_parent`),

KEY `post_author` (`post_author`)

) ENGINE=InnoDB AUTO_INCREMENT=843 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |

ad1f28e90e937dc4a2761dac70a81abb.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值