mysql - 加速 MySQL 查询

标签 mysql

这是我的查询的简短版本:

SELECT product.* FROM product_list product
LEFT JOIN language_item language ON (product.title=language.languageVariable)
WHERE language.languageID = 1
ORDER BY language.languageValue ASC

当我使用它时,查询有 3 秒。当我通过查询删除订单时有 0.3 秒。你能推荐一个改变来加速它吗?

product.titlelanguage.languageVariable 是一个语言变量,比如global.product.title1,languageValue 是title,比如car,洋娃娃或其他东西。

CREATE TABLE `language_item` (
  `languageItemID` int(10) UNSIGNED NOT NULL,
  `languageID` int(10) UNSIGNED NOT NULL DEFAULT '0',
  `languageVariable` varchar(255) NOT NULL DEFAULT '',
  `languageValue` mediumtext NOT NULL,
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
ALTER TABLE `language_item`
  ADD PRIMARY KEY (`languageItemID`),
  ADD UNIQUE KEY `languageVariable` (`languageVariable`,`languageID`),
  ADD KEY `languageValue` (`languageValue`(300));

id | select_type | table    | partitions | type | possible_keys                              | key              | key_len | ref              | rows | filtered | Extra 
 1 | SIMPLE      | product  | NULL       | ALL  | PRIMARY,inactive,archive,productCategoryID | NULL             | NULL    | NULL             | 1475 |    88.27 | Using where; Using temporary; Using filesort 
 1 | SIMPLE      | language | NULL       | ref  | languageVariable                           | languageVariable | 767     | db.product.title |  136 |     1.00 | Using index condition

最佳答案

这是来自 language_item 的结构,其索引为:

CREATE TABLE `language_item` (
  `languageItemID` int(10) UNSIGNED NOT NULL,
  `languageID` int(10) UNSIGNED NOT NULL DEFAULT '0',
  `languageVariable` varchar(255) NOT NULL DEFAULT '',
  `languageValue` mediumtext NOT NULL,
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
ALTER TABLE `language_item`
  ADD PRIMARY KEY (`languageItemID`),
  ADD UNIQUE KEY `languageVariable` (`languageVariable`,`languageID`),
  ADD KEY `languageValue` (`languageValue`(300));

解释:

id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra 1 | SIMPLE | product | NULL | ALL | PRIMARY,inactive,archive,productCategoryID | NULL | NULL | NULL | 1475 | 88.27 | Using where; Using temporary; Using filesort 1 | SIMPLE | language | NULL | ref | languageVariable | languageVariable | 767 | db.product.title | 136 | 1.00 | Using index condition

关于mysql - 加速 MySQL 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39167190/

相关文章:

android - 增量 SQLite <-> MySQL 复制 Android

mysql - SQL - 选择在特定日期只购买了一种产品的客户

用于搜索两个表的子集的 MySQL 查询

php - 在 mysql 和 php 中查找重复的条目,并在下面列出所有条目

PHP 和 MySQL - 排序或分组 - 在 ID 之后

php - 批量sql更新一个字段有多个值?

php - 需要在数据库表中再添加一个文本字段

mysql客户端端口

php - 在 SQL 中存储大量文本?

php - 检查 PHP 或 MySQL 中的一个数字范围是否在另一个范围内