【发布时间】:2020-06-09 12:38:57
【问题描述】:
我有 2 张桌子。
- special_order(订单表)- 有 420 000 个数据
- special_order_product(产品表)与 order_id 链接到 special_order 表。有 1 000 000 条数据
数据库存储引擎:InnoDB
我试图找到具有左连接关键字的产品的订单。查询需要 10-15 秒。另外,我对 product_link 列的其他索引(special_order.id, special_order_product.order_id)使用全文索引
SPECIAL_ORDER 表: Table structure
特殊订购产品表: Table structure
查询:
SELECT distinct(special_order.id), special_order.admin_id, special_order.user_id,
special_order.total_price, special_order.created_at, special_order.updated_at
FROM special_order LEFT JOIN special_order_product
ON special_order.id = special_order_product.order_id
WHERE MATCH(product_link) AGAINST ('trendyol' IN BOOLEAN MODE)
order by created_at desc limit 30
结果:30 行(15.730 秒)
查询说明: Explain of the query
special_order 表的索引: Special order table indexes
special_order_product 表的索引: enter image description here
【问题讨论】:
-
正确信息,只是作为图片链接很难阅读。
SHOW CREATE TABLE {tablename}是一种更简单的读取表/索引结构的方法。 sqlformat.org 使更长的查询实际上可读。欢迎来到 SO。这可能会移至 dba.stackexchange.com。握紧,您可以编辑您的问题。 -
你能在问题中添加查询信息吗?
-
@danblack 我添加了你想要的图片。
-
@Vidal 添加了查询信息和查询说明
-
不明确 -- 两个表都有
created_at,那么应该是哪个ORDER BY??
标签: mysql optimization full-text-search innodb