zoukankan      html  css  js  c++  java
  • oracle psql 调优

    1 不一定sql越长反倒性能越差,尽量多where条件使得初始结果集最小,然后再和其他表相连

    2 使用patition

    3 同一个结果集被多次使用,可以使用with table

    4 谓词推进

    --分页 第一种写法会有stopkey
    (1)
    select y.*
      from (select z.*, rownum as startRow
              from (
                   select * from tbaa where customerno='asdf' order by accessdate desc
              ) z
                      where rownum <= 20
            ) y
     where y.startRow > 2
     
    (2) 
     select z.*
       from (select * from tbaa where customerno = 'asdf' order by accessdate desc) z
      where rownum <= 20
        and rownum > 1 
      select z.*
       from (select * from tbaa where customerno = 'asdf' order by accessdate desc) z
      where rownum between 0 and 20
     
     
       --我想要指出我在这个例子中使用了一技巧阻止谓词推进。在第二个查询中使用rownum伪列(我加谓词WHERE rownum > 1)用于禁止谓词推进。
    事实上,rownum不仅禁止谓词推进也禁止视图合并。 使用rownum就好像在查询中加了NO_MERGE和NO_PUSH_PRED 提示。在本例中,
    它让我指出谓词推进没有发生时的负面效果,我还想确保你知道:当确定执行计划时,使用rownum将影响优化器的有效选择。
    当你使用rownum时要小心--它将使得它所在的任何查询块变得非可合并且不能把谓词推进入其中。
     
    5 left join加where条件的不同情况
    --channel是cardMemory的才会和右表连接
    with ta as
     (select customerno, channel, pv
        from tbaa
       where accessdate = '2017-06-20'
         and customerno = 'dd'),
    tb as
     (select customerid, machineid
        from tbbb
       where stat_date = '2017-06-20'
         and customerid = 'dd')
    select ta.customerno, ta.channel, ta.pv, tb.machineid
      from ta
      left join tb
        on ta.customerno = tb.customerid
       and ta.channel = 'cardMemory'
     
    with ta as
     (select customerno, channel, pv
        from tbaa
       where accessdate = '2017-06-20'
         and customerno = 'dd'),
    tb as
     (select customerid, machineid
        from tbbb
       where stat_date = '2017-06-20'
         and customerid = 'dd')
    select ta.customerno, ta.channel, ta.pv, tb.machineid
      from ta, tb
     where ta.customerno = case
             when ta.channel = 'cardMemory' then
              tb.customerid(+)
             else
              null
           end
    http://www.oracle.com/technetwork/java/javase/downloads/index.html
  • 相关阅读:
    关于CSS自文档的思考_css声明式语言式代码注释
    html5中contenteditable属性如果过滤标签,过滤富文本样式
    web前端工程化/构建自动化
    Python连载19-装饰器
    Java连载1-概述&常用的dos命令
    HTML连载18-id选择器与class区别&class选择器使用思路&后代选择器
    Python连载18-closure闭包解释及其注意点
    HTML连载17-id选择器&类选择器
    Python连载17-排序函数&返回函数的函数
    HTML连载16-颜色控制属性2&标签选择器
  • 原文地址:https://www.cnblogs.com/ai464068163/p/3224509.html
Copyright © 2011-2022 走看看