<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Java進行時

    程序人生
    數據加載中……
    關于SQL調優的一些途徑
    1 有兩個表,A表800多萬,B表900多萬,這兩個表要做關聯查詢,沒有GROUP BY等操作,只是普通的查詢,如何提高速度?
    [1]把能限制范圍最小的條件放在最前面,此條件對應的列加一下索引
    [2]盡量把Where后面給出的條件所要用的字段建立索引,
    避免使用like, 避免在where中使用is null或者is not null,
    另外,先要限制從兩張表取的數據,最后才寫兩表關聯的字段(兩表連接的條件)
    [3]索引是提升速度的關鍵。可以考慮分成幾個查詢,每個查詢對應一個最佳的索引
    [4]強制索引;少用IN,用EXISTS;可以的話,多建臨時表;
    [5]技術上提高查詢辦法:建立合適的索引,避免用影響查詢速度的條件,比如in、%等,如果可以作partition的,就作partition,盡量分段查詢。
    兩個大表關聯查詢,屬于業務問題:數據量巨大,本身就是很費時間的事。像移動、電信,基本上不給打印1年的帳單,就是避免數度太慢影響業務。
    [6]關鍵看你做什么樣的關聯操作,where條件很重要(是否用了in/not in,like等條件),還有是否用了union(因為union all 的執行要比union快很多)
    [7]關鍵字建立索引
    ID采用LONG型而不采用varchar,對于海量數據的查詢可以提速很多
    其它的,有待樓下進一步提供
    [8]表空間分配合理,回滾段空間分配250M左右
    [9]建立索引之后 分批查詢
    [10]優化查詢條件,應該是比較實際的辦法,將返回的結果縮小在最小的范圍內的查詢放到前面,依次
    [11]應先進行表空間的優化,回滾段的優化,索引優化,再進行查詢語句的優化
    如果還是不行可試試建個視圖,建立視圖快照
    2 Transitive predicate generation
    如果想查出某一段時間的有效的單據中(或者某些產品)的明細資料,一般的做法:
    select 所需字段
    from detail_tab a,main_tab b
    where a.prod_id = b.prod_id
    and a.yyyymmdd = b.yyyymmdd
    and a.paper_no = b.paper_no
    and a.io = b.io
    and b.yyyymmdd = 指定日期
    and a.io = 進倉
    and b.code = 有效的;
    這個查詢的速度會因為這兩個表過于巨大而非常的緩慢,    
    現在有一個解決辦法,就是給兩個表都加上條件,即使是兩個表關聯的字段也加:
    select 所需字段
    from detail_tab a,main_tab b
    where a.prod_id = b.prod_id
    and a.yyyymmdd = b.yyyymmdd
    and a.paper_no = b.paper_no
    and a.io = b.io
    and b.yyyymmdd = 指定日期
    and a.yyyymmdd = 指定日期
    and a.io = 進倉
    and b.io = 進倉
    and b.code = 有效的;

    這樣的速度要比前一種快了至少10倍以上。
    人工調優,特別對于索引,條件順序。
    3
    http://www.componentace.com/help/absdb_manual/increasesqlperformance.htm
    Absolute Database search and filter optimizations are based on the use of available indexes.
     
    Always create unique (primary) indexes when possible, as the unique index allow much better optimization then non-unique index.
     
    To improve peformance of a LIKE condition, you can create an appropriate index, but note that this index can improve performance for patterns like 'str%' only。
     
    Available indexes for JOIN conditions。To improve a JOIN query, please check that each field from JOIN conditions has an index.
     
    Rewriting query with OR conditions as a UNION
     
    Available indexes for ORDER BY clause If you want to speed up a "live" SELECT from a single table with ORDER BY clause, you can create a compound index for ORDER BY fields.
     
    Available indexes for GROUP BY clause。To get a better performance for SELECT from a single table with GROUP BY clause, you can create a compound index for GROUP BY fields.
     
    Select from in-memory tables。Your query perofrmance could be increased also if you will move all data from disk tables to in-memory tables and you will perform a query using in-memory copies of the disk tables
     
    4
    The fastest way of inserting and updating
    The fastest way of batch inserting / updating / deleting is a buffered transaction.
    We recommend to call TABSDatabase.StartTransaction before bulk inserts and
    TABSDatabase.Commit(False) after the end of the batch operation. The use of transaction can significantly increase performance of the batch operation
     
    How to speed up an UPDATE query
    If you are using several subqueries in an UPDATE query, you could try to transform your query like pair values, not separated.
     
    5
    Common subexpression elimination
     Subquery “flattening”
     Complex/simple view merging
     Predicate pushdown and pullup
    OR-expansion 等等。這些參考http://www.oracle.com/technology/products/bi/db/10g/pdf/twp_general_query_optimization_10gr2_0605.pdf
    總之查詢首先考慮查詢自身的優化,將記錄數盡可能減少,即where條件要盡可能充分(特別注意可推導和重復的區別),投影優先于聯接,時刻以減少聯接數為分析的主要原則。然后是對索引的分析。至于量化分析,則是對多種策略的評價的直接方法。

    posted on 2008-12-19 17:26 davma 閱讀(190) 評論(0)  編輯  收藏 所屬分類: 數據庫


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲视频网站在线观看| 亚洲欧洲日产专区| 美女视频黄a视频全免费网站一区| 成全视频在线观看免费高清动漫视频下载 | 无码av免费毛片一区二区| 亚洲成人免费在线观看| 综合在线免费视频| 亚洲国产中文在线二区三区免| 18女人毛片水真多免费| 亚洲1234区乱码| 国产精品色午夜免费视频| 黄色三级三级三级免费看| 亚洲一区日韩高清中文字幕亚洲| 色费女人18女人毛片免费视频| 亚洲Av无码乱码在线znlu| 一个人看的免费观看日本视频www 一个人看的免费视频www在线高清动漫 | 亚洲成a人片7777| 久久精品女人天堂AV免费观看| 亚洲AV无码一区二区三区网址 | 羞羞视频网站免费入口| 久久精品国产精品亚洲| 国产精品区免费视频| 亚洲午夜电影在线观看高清| 性感美女视频在线观看免费精品 | 亚洲国产成人影院播放| 永久免费A∨片在线观看| 亚洲国产综合人成综合网站00| 成人免费无码大片A毛片抽搐色欲 成人免费无码大片a毛片 | 亚洲人色婷婷成人网站在线观看| 久久这里只精品热免费99| 亚洲一区电影在线观看| 亚洲精品成a人在线观看| 120秒男女动态视频免费| 久久精品国产亚洲av瑜伽| 国产成人亚洲综合无码精品| 免费在线观看h片| 一区免费在线观看| 亚洲春色另类小说| 亚洲一区二区三区无码影院| 亚洲精品在线免费观看| eeuss在线兵区免费观看|