我目前有5台:优化的MySQL 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个左连接,它需要在40分钟内完成一个巨大的MySQL查询。必须有一个更简单的方法。谢谢!
这听起来像你没有索引。如果所有'id'列都是'PRIMARY'索引,则查询应该几乎是即时的。请张贴您的表格结构和示例长时间运行查询的'EXPLAIN'。 –
你可以给一个sqlfiddle创建表和插入值的例子吗? –
您是否试过'EXPLAIN PLAN'?您可能会发现它很有帮助。更多[here](http://dev.mysql.com/doc/refman/5.0/en/using-explain.html)。 –