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条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!