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
  • 相关阅读:
    屏幕的真实分辨率大小
    CCConfiguration::sharedConfiguration()->loadConfigFile cocos2d-x 中文乱码问题及国际化解决方案
    git 放弃提交到提交之前
    cocos2d-x 输出debug信息
    Ubuntu设置环境变量
    有时候需要统计手机的型号和版本号,利用程序可以获取到相应的手机信息.
    读取 android sys/下的信息
    android 读取 raw 中的文件。
    C/C++中结构体(struct)
    异步图片下载引擎(升级版——ExecutorService+handler)
  • 原文地址:https://www.cnblogs.com/ai464068163/p/3224509.html
Copyright © 2011-2022 走看看