我正在查询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(.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
答案 0 :(得分:1)
尝试这种方法。
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
答案 1 :(得分:0)
尝试更改where条件的顺序。
SELECT t1.some_col
,t2.some_col
,t3.some_col
FROM t1, t2, t3
WHERE a filter on t1
AND a filter on t2
AND a filter on t3
AND t1.a_col = t2.a_col
AND t2.a_col = t3.a_col;