小编典典

mysql fix使用where;

mysql

我的SQL查询:

SELECT *
FROM updates_cats
WHERE uid =118697835834
ORDER BY created_date ASC

当前指数:

index1(uid, created_date)

说明扩展结果:

1 SIMPLE updates_cats ref index1 index1 8 const 2 100.00 Using where

如何在“使用位置”处固定“额外”字段,以便可以改为使用索引?

编辑:显示创建表:

CREATE TABLE `updates_cats` (
 `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
 `u_cat_id` bigint(20) NOT NULL DEFAULT '0',
 `uid` bigint(20) NOT NULL,
 `u_cat_name` text COLLATE utf8_unicode_ci NOT NULL,
 `total_updates` int(11) unsigned NOT NULL DEFAULT '0',
 `created_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
 PRIMARY KEY (`id`),
 KEY `index1` (`uid`,`created_date`)
) ENGINE=MyISAM AUTO_INCREMENT=23522 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

阅读 342

收藏
2020-05-17

共1个答案

小编典典

这将是好过的唯一的事情Using whereUsing where; Using index一个“覆盖索引”。尝试选择公正uidcreated_date

Using where很好 这意味着它将指示的索引应用于WHERE子句并减少返回的行。要摆脱它,您必须摆脱该WHERE子句。

您应该注意以下事项:

  • Using filesort
  • Using temporary
  • 不使用索引:NULL在的“键”列中EXPLAIN,在“行”列中包含大量行。

您的EXPLAIN结果表明MySQL正在应用index1WHERE子句并返回2行:

1 SIMPLE updates_cats ref index1 index1 8 const 2 100.00 Using where
2020-05-17