【发布时间】:2020-03-05 11:13:43
【问题描述】:
我有两张桌子propeties_1 和properties_2。
表propeties_1 有350,000 条记录,而表propeties_2 有400,000 条记录。
我使用如下查询:
Select union_table.* FROM
(
(select col1 as c1, col2 as c2, col3 as c3 from `propeties_1` where status='A')
union
(select colm1 as c1, colm2 as c2, colm3 as c3 from `propeties_2` where status='A')
) as union_table
limit 12 offset 0 order by c1;
此查询的执行时间过长。
如何优化这个查询?
【问题讨论】:
-
您希望每个表的结果中有多少行
-
@Nick 13,但谁在数;-)
-
@HarpalSingh 请在发布前测试所有代码。
-
@RiggsFolly,我一次需要 12 条记录,但结果应该来自表的联合
-
@HarpalSingh 有多个因素在优化中发挥作用。我建议通过此链接更好地理解。 stackoverflow.com/questions/60015018/laravel-use-mysql-indexing/…
标签: mysql query-optimization union sql-optimization