左连接优化
我有一个类似于下面简化的数据库。我需要检索列:col8、col9、col10、col11、col12(我圈出的列
目前,我使用左联接来联接每个表,但这会导致查询花费很长时间(有很多分析时,最大的影响是写入 tmp 表
由于左连接,它仍然将数千条记录复制到 tmp 表。
,但 href="http://oberto.co.nz/demo/assets/db2.jpeg" rel="nofollow noreferrer">http://oberto.co.nz/demo/assets/db2.jpeg
可以这是否可以优化以仍然使用 pk 连接从每个表中检索圈出的列?
谢谢。
I have a database similar to the simplified one below. I need to retrieve columns: col8, col9, col10, col11, col12 (the ones I've circled
Currently, I;m using a left join to join each table but this results in the query taking a very long (there are lots of records). Upon profiling, the biggest impact is writing to the tmp table.
I'm limiting the result to 24, but because of the left joins it's still copying thousands of records to the tmp table.
http://oberto.co.nz/demo/assets/db2.jpeg
Can this be optimised to still retrieve the circled column from each table using joining by the pk?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
现在您将不再有重复的行。
您可能必须尝试使用
LEFT
而不是INNER
连接。如果您不需要子选择,您应该消除它,因为它会减慢速度。
Now you will have no more duplicate rows.
You may have to experiment with
LEFT
instead ofINNER
joins.And if you don't need a subselect you should eliminate it, because it slows things down.
在当前最简单的形式中,我将查询为...
但是,一旦我读回其他标准、过滤器、条件、左/内连接“要求”,将进行调整,这可能有助于进一步优化。
in its current and simplest form, I would have the query as...
However, will adjust once I read back on other criteria, filters, conditions, left/inner join "requirements" that may help optimize further.