我目前有5个表:
trialSum
-------------
id total
-------------
1 2000
2 1000
3 500
trialLand
-------------
id total
-------------
1 1000
2 250
3 500
trialImp
-------------
id total
-------------
2 250
trialBldg
-------------
id total
-------------
1 1000
2 500
trial
---------------------
id name info
---------------------
1 xxxxx xxxxx
2 xxxxx xxxxx
3 xxxxx xxxxx
4 xxxxx xxxxx试用表将具有最多的条目,并且所有"id“字段彼此匹配。每个表中将有超过7000个条目。我正在尝试创建一个很大的表,如下所示:
trial
----------------------------------------------------------------------
id name info totalSum totalLand totalImp totalBldg
----------------------------------------------------------------------
1 xxxxx xxxxx 2000 1000 0 1000
2 xxxxx xxxxx 1000 250 250 500
3 xxxxx xxxxx 500 500 0 0
4 xxxxx xxxxx 0 0 0 0如果我执行一个包含4个左连接的大型MySQL查询,则需要40多分钟才能完成。必须有一种更简单的方法。谢谢!
发布于 2013-01-05 00:23:08
我想说,left join确实是一个很好的方法。你有那些id列的索引吗?尝试添加索引,速度应该会提高。请记住使用EXPLAIN来确认索引的使用是否正确。更多关于解释http://www.dbtuna.com/article.asp?id=14的信息。
https://stackoverflow.com/questions/14160700
复制相似问题