Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3441
  • 博文数量: 3
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 40
  • 用 户 组: 普通用户
  • 注册时间: 2015-08-19 21:56
文章分类
文章存档

2017年(3)

我的朋友
最近访客

分类: Mysql/postgreSQL

2017-06-15 23:05:34

 语句1:
 select tb1.* from tb1 left join tb2 on tb1.ids=tb2.ids left join tb3 on tb1.ids=tb3.ids
 此语句在调用转化前:
                  TOP_JOIN_LIST
                      |
                  TABLE_LIST(nested_last)
                  nested_join
                  join_list
                  /       \    
                 /         tb3 on (tb1.ids=tb3.ids) 
        TABLE_LIST(nested_last)
        nested_join
        join_list
        /     \
       tb1   tb2 on (tb1.ids=tb2.ids)
       在simplify_joins()中的代码
        else if (nested_join && !table->join_cond())
        {
            因为两个nested_last的都没有join_cond,所以nested_last最终都会被移除,上拉到最上层:
            top_join_list
            /    |      \
          tb1   tb2(on..)   tb3(on..)
        }

 语句2:
 select tb1.* from tb1 left join (tb2,tb3) on tb1.ids=tb2.ids
 在此语句调用前结构:
            TOP_JOIN_LIST
                |
          TABLE_LIST(nested_last)
          join_list
         /      \
        tb1     TABLE_LIST(nested_join) on (tb1.ids=tb2.ids)
                   join_list
                  /      \
                tb2        tb3
同样在simplify_joins()代码中
else if (nested_join && !table->join_cond())
{
nested_last因为没有join_cond,所以tb1与nested_join都会被上拉到TOP_JOIN_LIST中,tb1.embedding为NULL,
nested_join的join_cond不能转移到WHERE 中,且也不能转为内联接,所以tb2,tb3并不能像上一条语句一样直接上拉到TOP_JOIN_LIST,
tb2,tb3位于嵌套中,估计表的记录数时只能是全表扫描
}

阅读(505) | 评论(0) | 转发(0) |
0

上一篇:simplify_joins 外联接消除、嵌套消除

下一篇:没有了

给主人留下些什么吧!~~