mysql - mysql中三个表的内连接花费太长时间

标签 mysql query-optimization inner-join

我正在查询 mysql 中的 3 个表。

SELECT t1.some_col
,t2.some_col
,t3.some_col

FROM t1, t2, t3
WHERE t1.a_col = t2.a_col AND t2.a_col = t3.a_col
AND a filter on t1
AND a filter on t2
AND a filter on t3

这花费了太多时间。 (10 分钟后甚至没有给出结果)。任何优化建议都会很棒。

表 t1(0.3m 行)、t2(1.1m)和 t3(258 行)。没有表有索引,即使我也不允许创建索引。

编辑(顺便说一句,嗯?):

SELECT t2.parent_customerID ,
aggregate(t1.some_columns) 
FROM t1, t2, t3 
WHERE t1.customerID = t2.customerID 
AND t2.parent_customerID = t3.parent_customerID 

AND t1_where_entity_type_customer 
AND t2_parent_customer_belonging_a_region_filter 
AND t3_a_flag_check_on_parent_customer 
GROUP BY t2.parent_customer

最佳答案

尝试这种方法。

SELECT t1.some_col
,t2.some_col
,t3.some_col
FROM t1 
INNER JOIN t2 ON t1.a_col = t2.a_col
INNER JOIN t3 ON t2.a_col = t3.a_col
WHERE a filter on t1 AND a filter on t2 AND a filter on t3

关于mysql - mysql中三个表的内连接花费太长时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32176824/

相关文章:

MySql EF Code First 迁移 VB.NET

c# - 如何使用来自文本框的输入并在 C# 的 mysql 查询中使用它

php - 在关联数组中搜索值,php

sql - 摆脱 "Using temporary; Using filesort"

mysql - 奇怪的查询速度问题

laravel - 分页计数(*)查询问题

mysql - 来自多个 JOINed 表 MSSQL 的 SUM

php - INNER JOIN 与 mysql 中带有 max 和 where 子句的子查询

mysql - 在 MySQL 中通过内部连接使用更新语句查找和替换

mysql - 如何通过检查两列值来获取每组的最高值