Updates from 十月, 2009 Toggle Comment Threads | 键盘快捷键

  • admin 15:32 on 2009-10-30 链接地址 | 回复
    Tags: , , 优化   

    mysql的LEFT JOIN的使用时的注意事项和优化 

    1. SELECT 语句的执行过程
    2. LEFT JOIN 中的ON中的条件和 WHERE中的条件的区别
    3. LEFT JOIN的右表要尽可能的小,如果表太大要用子查询把表缩小

    SQL书写标准:
    SELECT部分做最终结果的计算,不执行数据筛选工作
    FROM部分负责数据表的连接,不负责数据筛选,如果LEFT JOIN时右表太大,用子查询的where缩小表的大小,ON的条件不能较小该表的大小,造成效率地下
    WHERE部分负责数据筛选,而表之间的链接不应该放在这个部分

     
  • admin 15:21 on 2009-10-30 链接地址 | 回复
    Tags: mysql bug, mysql date   

    Mysql的date函数在不同版本下执行结果不一样 

    select if(date(a) = '2009-09-09', b,0) as res
    from (
    select null as a,1 as b union
    select '2009-09-09' as a, 2 as b union
    select null as a, 3 as b
    ) t;

    Linux下mysql的执行结果截图:
    mysql版本:mysql Ver 14.12 Distrib 5.0.45, for redhat-linux-gnu (i686) using readline 5.0
    linux
    mysql版本:mysql Ver 14.12 Distrib 5.0.18, for pc-linux-gnu (i686) using readline 5.0
    linux2
    Windows下mysql的执行结果截图:
    mysql版本:mysql Ver 14.12 Distrib 5.0.67, for Win32 (ia32)
    windws

     
c
写新的
j
下一篇文章/下一个回复
k
前一篇文章/以前的回复
r
回复
e
编辑
o
显示/隐藏 回复
t
回到顶部
l
go to login
h
show/hide help
shift + esc
取消