dpc57092 2013-01-18 21:50
浏览 116
已采纳

我们可以使用IN语句在多个查询中分解SQL连接

The creator of No`orm shows that is possible to decompose a join of 3 tables into 3 faster queries: http://www.notorm.com/#performance.

Do you think that is possible to avoid joins and use multiple queries by putting the IDs in the IN statement?

That library (NoORM) do not support join for the above mentioned reason, do you think I could give up using joins and just use that library? It seems strange to me that it is so easy to avoid joins.

  • 写回答

2条回答 默认 最新

  • douchuoliu4422 2013-01-18 22:21
    关注

    One reason to use joins over individual queries is that it allows the database's optimizer to come up with the best plan for the tables involved, based on the existing data. If you break a joined query out into individual queries, you're effectively hard-coding the execution plan. Among other things, that assumes that you're going to spend some time thinking about the selectivity of your queries when you write your code and that the selectivity will remain the same for the lifetime of your application. Those are pretty big assumptions, in my opinion.

    Also, if you're using your database as more than a dumb receptacle, you'll likely find that there are queries that don't break down into individual queries quite so easily (e.g. just about anytime you use aggregate functions).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程