database.sarang.net
UserID
Passwd
Database
DBMS
MySQL
PostgreSQL
Firebird
Oracle
Informix
ㆍSybase
MS-SQL
DB2
Cache
CUBRID
LDAP
ALTIBASE
Tibero
DB 문서들
스터디
Community
공지사항
자유게시판
구인|구직
DSN 갤러리
도움주신분들
Admin
운영게시판
최근게시물
Sybase Q&A 2288 게시물 읽기
No. 2288
index 에 대해서.[다시 한번만]
작성자
경호선
작성일
2008-09-03 13:35ⓒ
2008-09-03 14:24ⓜ
조회수
8,113

안녕하세요. 


버전 (11.9.2)


같은 쿼리인데 아큐먼트에 따라서 index가 다른걸 탈 수 있나요?


예를 들어서 


saa010ms  이 테이블에는 index 가 3개 있습니다.  saa010ms_pk(clustered, unique) agency_cd, saa010ms_nk1(nonclustered) headquarter, team_major


select *

    from sca010ts a, sca010ds b, saa010ms d

   where a.order_no             =       b.order_no

     and a.del_order_sign_yn    =       'N'

     and d.headquarter          =        'A'

     and d.team_major           like    'A%' 

     and a.agency_cd            =       d.agency_cd


Query Plan


QUERY PLAN FOR STATEMENT 1 (at line 1). 

    STEP 1

        The type of query is SELECT.

        FROM TABLE

            sca010ts

            a

        Nested iteration.

        Table Scan.

        Forward scan.

        Positioning at start of table.

        Using I/O Size 16 Kbytes for data pages.

        With LRU Buffer Replacement Strategy for data pages.

        FROM TABLE

            saa010ms

            d

        Nested iteration.

        Using Clustered Index.

        Index : saa010ms_pk

        Forward scan.

        Positioning by key.

        Keys are:

            agency_cd  ASC

        Using I/O Size 2 Kbytes for data pages.

        With LRU Buffer Replacement Strategy for data pages.


        FROM TABLE

            sca010ds

            b

        Nested iteration.

        Using Clustered Index.

        Index : sca010ds_pk

        Forward scan.

        Positioning by key.

        Keys are:

            order_no  ASC

        Using I/O Size 16 Kbytes for data pages.

        With LRU Buffer Replacement Strategy for data pages.

--------------------------------------------------------------

select *

    from sca010ts a, sca010ds b, saa010ms d

   where a.order_no             =       b.order_no

     and a.del_order_sign_yn    =       'N'

     and d.headquarter          =        'J'

     and d.team_major           like    'A%' 

     and a.agency_cd            =       d.agency_cd


QUERY PLAN FOR STATEMENT 1 (at line 1).

    STEP 1

        The type of query is SELECT.

        FROM TABLE

            saa010ms

            d

        Nested iteration.

        Index : saa010ms_nk1

        Forward scan.

        Positioning by key.

        Keys are:

            headquarter  ASC

            team_major  ASC

        Using I/O Size 2 Kbytes for index leaf pages.

        With LRU Buffer Replacement Strategy for index leaf pages.

        Using I/O Size 2 Kbytes for data pages. 

        With LRU Buffer Replacement Strategy for data pages.

        FROM TABLE

            sca010ts

            a

        Nested iteration.

        Table Scan.

        Forward scan.

        Positioning at start of table.

        Using I/O Size 16 Kbytes for data pages.

        With LRU Buffer Replacement Strategy for data pages.


        FROM TABLE

            sca010ds

            b

        Nested iteration.

        Using Clustered Index.

        Index : sca010ds_pk

        Forward scan.

        Positioning by key.

        Keys are:

            order_no  ASC

        Using I/O Size 16 Kbytes for data pages.

        With LRU Buffer Replacement Strategy for data pages.

 



두번째 쿼리가 많이 늦어서 확인해 보니깐, index를 틀리게 타고 있드라구요.

이런게 되는 원인이 무엇인지 궁금합니다. 

이 글에 대한 댓글이 총 5건 있습니다.

index key 값을 적어 주셔야줘~~그래야 판단이 되겠죠?

지연님이 2008-09-03 14:00에 작성한 댓글입니다. Edit

우선 


update all statistics 를 먼저 수행 하고 해보세요~



지연님이 2008-09-08 16:50에 작성한 댓글입니다. Edit

update index statistics table_name 을 각 테이블 별로 실행하시고 돌려도 동일하면

d.headquarter          =        'J' 과 and d.headquarter          =        'A'의 결롸 값의 

rowcount의 차이가 많을것 같습니다.

rowcount의 결과가 많다면 인덱스로 찾는 것보다 table full scan이 더 빠를수 있거든요..

이로 인해 Query Plan 정보도 가변적입니다.   사이베이스거 똑똑하게 처리한다 

할수 있겠지요


갈매기(갈매기)님이 2008-09-09 14:22에 작성한 댓글입니다.
이 댓글은 2008-09-09 14:23에 마지막으로 수정되었습니다.

고맙습니다.... ^^

경호선님이 2008-09-12 10:47에 작성한 댓글입니다. Edit

optimizer에 영향을 주는 다른 요소로 table fragmentation(DOL) 과 Cache IO도 있습니다.  update index statistics한 후 sp_recompile잊지 마시구요.
그리고 정녕 그 인덱스를 쓰고 싶다면 Force index쓰셔도 되고, 또 테이블을  LRU앞에 지정시키는 방법도 있습니다.

select a.col1, b.col2
from table_a a (index a_ix1)
       ,table_b b
where ....

민디님이 2008-09-17 05:38에 작성한 댓글입니다.
이 댓글은 2008-09-17 06:17에 마지막으로 수정되었습니다. Edit
[Top]
No.
제목
작성자
작성일
조회
2291sybase ase 설치후, 서버시작 문의 [1]
카즈머스
2008-09-16
7859
2290너무답답해서 글을올립니다.ㅠ [3]
홍종진
2008-09-03
10193
2289배치파일 만드는 법좀 알려주세요... [1]
송효순
2008-09-03
7044
2288index 에 대해서.[다시 한번만] [5]
경호선
2008-09-03
8113
2287user defind function 보는 방법좀 알려주세요 [2]
초보
2008-09-03
7520
2286카운트 타입 .. int가 안먹히는데;; [2]
홍종진
2008-09-02
6634
2285er윈이라는 곳에서 만들었는데싸이베이스에선 타입을어떻게... [1]
홍종진
2008-09-02
7058
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.017초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다