美文网首页
cross join + where vs join + on

cross join + where vs join + on

作者: 黑山老水 | 来源:发表于2018-04-19 04:43 被阅读13次

    以下两种query会产生相同结果:

    select *
    from t1, t2
    where t1.xx = t2.xx and t1.yy = t2.yy
    

    select *
    from t1 inner join t2
    on t1.xx = t2.xx and t1.yy = t2.yy
    

    第一种是cross join,所以也可以写成from t1 cross join t2,cross join会先产生笛卡尔积,然后再根据where的情况筛选符合的rows。这样效率比直接inner join + on的效率低。但是以大O计数来看,他们的时间复杂度都是O(n^2)

    相关文章

      网友评论

          本文标题:cross join + where vs join + on

          本文链接:https://www.haomeiwen.com/subject/mvjikftx.html