2019년 1월 17일 목요일

DB - sybase Query 측정



1. 모니터링
    1.1 Historical data
         1.1.1 monSysStatement -> v$sql에 대응
         1.1.2 monSysSQLText -> v$sqltext
         1.1.3 monSysPlanText -> v$sqlplan
    1.2 Query
         select S.SPID, S.CPUTIME, S.LINENUMBER, T.SQLTEXT
         from    monProcessStatement S, monProcesSQLText t
         where  s.SPID = T.SPID
         and    S.CPUTIME = (select max(cputime) from monProcessStatement)
     1.3 Locking
          1.3.1 sp_who, sp_lock, sp_familylock을 이용하여 모니터링
                  -> sp_who에 user명을 주면 해당 user것만 모니터링 안주면 전체

     1.4 sysquerymetrics(version 15 이후)
          1.4.1 most expensive statement query
                 -> select lio_avg, qtext from sysquermetrics order by lio_avg
          1.4.2 most frequently used statement query
                 -> select elap_avg, cnt, qtext from sysquerymetrics order by cnt

2. SQL PLAN 확인
    2.1 set showplan on/set showplan off
    2.2 SQL PLAN 메시지 해석
         2.2.1 worktable -> oracle의 temp 영역에 임시 데이터 쓰는 것을 의미
         2.2.2 GETSORTED -> worktable을 만들어서 sorting할 경우에만 메시지가 나타남. index를 이용하여 sorting 한 경우에는 나타나지 않음
        2.2.3 Auxiliary scan descriptors ->  referential integrity check 를 의미
        2.2.4 Positioning -> table이나 index의 leaf level에 access를 시작하는 부분
        2.2.5 Index covering -> base table은 읽지 않고 index scan만으로 끝나는 것
        2.2.6 Matching Index Scans -> or clause or in list 일때 인덱스를 각각 스캔할 경우 나타남
        2.2.7 Dynamic Index -> or 조건일때 해당 row들을 읽어서 중복된 row는 제거한 후 worktable을 만든 다음 그 worktable의 rowid를 access하는 것을 의미한다.
        2.2.8 Reformatting -> 테이블이 크면서 조인 컬럼에 인덱스가 없는 경우 해당 row의 필요컬럼을 worktable에 insert한 후에 join 컬럼에 clustered index를 생성한 다음에 join을 수행한다.
        2.2.9 Log scan -> insert, update, delete 수행에 따라 transaction log에서 data를 읽는 것
        2.2.10 I/O size -> optimizer가 선택한 I/O size
    2.3 dbcc traceon
        -> 10046과 10053 evet trace를 포함
        2.3.1 사용법 -> dbcc traceon(3604, 302) / dbcc traceoff(3604, 302)
                              dbcc traceon(3604, 302, 310) / dbcc traceoff(3604, 302, 310)
               *3604는 client에 log가 생성되게 함. 없으면 error log에 보임
   

3. Object 분석 (Table, Index 확인)
    3.1 table 정보확인 방법
         - sp_help [table] : argument가 없으면 해당 DB의 전체가 보이며 index 정보도 같이 보여줌
         - Sybase Central에서 확인 가능
         - select name from sysobjects where type = "U" 를 통해서는 사용자 table 목록을 확인 가능
    3.2 index 정보확인 방법
         - sp_helpindex [index]
 

4. 통계 정보 확인
   4.1 optdiag를 이용하여 통계정보가 최신 것으로 변경되었는지 확인
   4.2 통계정보의 보관
        4.2.1 systabstats -> table, index의 size, rows count 등이 저장, basic statistics
                - Number of data pages for a table, the number oof leav level pages for an index
                - Number of rows in the table
                - Height of the index
                - Average length of data rows and leaf rows
                - Number of forwared and deleted rows
                - Number of empty pages
        4.2.2 sysstatistics -> specific column의 value가 저장
   4.3 optdiag의 사용법
        optdiag statistics pubtune -Usa -Ppasswd -o pubtune.opt
      -> optdiag statistics <dbname> -U<username> -P<passworkd> -o <outputfile>
        optdiag statistics pubtune..titles -Usa -Ppasswd -o titles.opt
      -> pubtune DB의 titles 라는 table과 그 테이블의 인덱스에 대한 정보를 display

5. Plan 변경
   5.1 optimizer mode
        1. fastfirstrow -> first_rows(n)
        2. allrows_oltp
        3. allrows_mixed -> default mode,
        4. allrows_dss -> all_rows
      example ) select * from A order by A.a plan "(use optgoal allrows_dss)"
   5.2 set forceplan [on|off]
        join order 변경 시 사용가능 그러나 join type 변경은 사용할 수 없음. abstract plan을 이용해야 join order 및 join type 변경이 가능함.
   5.3 Abstract Plans
        -> Oracle의 stored outline과 같은 기능, sysqueryplans에 저장됨
       5.3.1 creating partial plan
             -> partial plan은 특정부분만 plan 수정할 경우
         ex) create plan
              "select t1.c11, t2.c21 from t1, t2, t3
               where t1.c11 = t2.c21 and t.c11 = t3.c31"
              "(i_scan t3_c31_ix t3)"
        5.3.2 abstract plan 사용
               set plan dump [on|off] -> plan capture
               set plan load [on|off] -> abstract plan의 사용
               set plan replace [on|off] -> 기존에 capture된 plan이 있을 경우에 사용
   5.4 Index 변경
     select pub_name, title
     from publishers p, titles t (index date_type)
     where p.pub_id = t.pub_id
     and type = "business"
     and pubdate > "1/1/93"


6. 통계 정보 관리
   6.1 통계정보 생성 및 변경
        update statistics authors(auth_id) with sampling = 5 percent
        update statistics titles (price) -> titles의 price 컬럼에 통계정보 생성
        update statistics titles (price) using 50 values -> titles의 price 컬럼에 50개의 히스토그램 생성
        update all statistics <table_name> -> 모든 column에 통계정보 생성

7. set command -> set autotrace on과 유사함
    7.1 set statistics time ->  set timing on
    7.2 set statistics io
     
8. 참고
    8.1 용어
         8.1.1 MRU와 LRU의 존재는 개발계에서 QUERY 성능 측정시 cache 영향을 최소화하기 위함




댓글 없음:

댓글 쓰기

javascript - SQL 예약어 제거

  <script language="javascript"> //특수문자, 특정문자열(sql예약어) 제거 function checkSearchedWord(obj){ obj.value = obj.value+&quo...