달력

3

« 2024/3 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

'실행계획'에 해당되는 글 1

  1. 2013.03.13 Postgresql 9.2 Install 및 pg_hint_plan 적용

Overview

 

Installation

USER
Commad
Description
root  
 yum updateOS Update
 rpm -Uvh http://yum.postgresql.org/9.2/redhat/rhel-6-x86_64/pgdg-centos92-9.2-6.noarch.rpmPostgresql 9.2 repository 등록
 yum install postgresql92 postgresql92-server postgresql92-contribPostgresql 9.2 install
 service postgresql-9.2 initdbPostgresql 데이터베이스 초기화
postgres  
 postgresql.conf, pg_hba.conf 수정기본 설정
root  
 service postgresql-9.2 startPostgresql Servcie 실행
 wget "http://en.sourceforge.jp/frs/redir.php?m=iij&f=%2Fpghintplan%2F57713%2Fpg_hint_plan92-1.0.0-1.el6.x86_64.rpm"pg_hint_plan download
 yum localinstall pg_hint_plan92-1.0.0-1.el6.x86_64.rpmpg_hint_plan install
postgres  
 postgresql.conf 수정 : shared_preload_libraries = 'pg_hint_plan' 추가pg_hint_plan 환경 설정 변경
root  
 service postgresql-9.2 restartPostgresql 재시작
postgres  
 psqlpsql 실행
 

CREATE TABLE tbl (i int, j int);
INSERT INTO tbl SELECT x, x * 2 FROM generate_series (1, 10) x;
CREATE INDEX idx ON tbl (i);
VACUUM ANALYZE tbl;
EXPLAIN SELECT * FROM tbl WHERE i = 7;
/*+ IndexScan (tbl) */ EXPLAIN SELECT * FROM tbl WHERE i = 7;

실행계획 비교.

 

실행계획 확인

실행계획 확인
-bash-4.1$ psql
psql (9.2.3)
Type "help" for help.
postgres=# EXPLAIN SELECT * FROM tbl WHERE i = 7;
                    QUERY PLAN                    
---------------------------------------------------
 Seq Scan on tbl  (cost=0.00..1.12 rows=1 width=8)
   Filter: (i = 7)
(2 rows)
postgres=# /*+ IndexScan (tbl) */ EXPLAIN SELECT * FROM tbl WHERE i = 7;
                          QUERY PLAN                          
---------------------------------------------------------------
 Index Scan using idx on tbl  (cost=0.00..8.27 rows=1 width=8)
   Index Cond: (i = 7)
(2 rows)
postgres=# \q
-bash-4.1$


개인적 감상 : 이제 postgresql에서도 hint를 사용할 수 있다!!!


Hint List

  • 스캔 방식
    • SeqScan (table) 
      • 지정된 table에 대해 Seq Scan을 선택합니다.
    • TidScan (table) 
      • 지정된 table에 대해 Tid Scan을 선택합니다. 검색 조건에 ctid을 지정한 경우에만 유효합니다.
    • IndexScan (table index ...) 
      • 지정된 table에 대한 Index Scan을 선택합니다. index를 지정하면, 지정한 index에 비용이 최소가되는 Index Scan을 선택합니다. 
        그러나 index가 존재하지 않거나 지정된 index가 WHERE 절이나 JOIN 조건 등에 관련 않으면 Seq Scan을 선택합니다.
    • IndexOnlyScan (table index ...) 
      • 지정된 table에 대한 Index Onl??y Scan과 Index Scan 중 비용이 최소가되는 스캔 방식을 선택합니다.
         index를 지정하면, 지정한 index에서 Index Onl??y Scan과 Index Scan 중 비용이 최소가되는 스캔 방식을 선택합니다. 
        그러나 index가 존재하지 않거나 지정된 index가 WHERE 절이나 JOIN 조건 등에 관련 않으면 Seq Scan을 선택합니다. 
        또한 이러한 경우 외에도 index가 가지는 값뿐만 아니라 table의 값이 필요한 경우는 Index Scan을 선택합니다. PostgreSQL 9.2 이상이 필요합니다.
    • BitmapScan (table index ...) 
      • 지정된 table에 대해 Bitmap Scan을 선택합니다. 
        index를 지정하면, 지정한 index에 비용이 최소가되는 index를 선택합니다. 
        그러나 index가 존재하지 않거나 지정된 index가 WHERE 절이나 JOIN 조건 등에 관련 않으면 Seq Scan을 선택합니다.
    • NoSeqScan (table) 
      • 지정된 table에 대해 Seq Scan 이외 비용을 최소화하는 스캔 방식을 선택합니다. 
        그러나 다른 검색 방식을 선택할 수없는 경우는 Seq Scan을 선택합니다.
    • NoTidScan (table) 
      • 지정된 table에 대해 Tid Scan 이외 비용을 최소화하는 스캔 방식을 선택합니다.
    • NoIndexScan (table) 
      • 지정된 table에 대한 Index Scan 및 Index Onl??y Scan을 제외한 스캔 방식에서 비용을 최소화하는 스캔 방식을 선택합니다.
    • NoIndexOnlyScan (table) 
      • 지정된 table에 대한 Index Onl??y Scan 이외 비용을 최소화하는 스캔 방식을 선택합니다. (PostgreSQL 9.2 이상)
    • NoBitmapScan (table) 
      • 지정된 table에 대해 Bitmap Scan 이외 비용을 최소화하는 스캔 방식을 선택합니다.
  • 결합 방식
    • NestLoop (table table table ...) 지정된 table 간의 조인에 Nested Loop을 선택합니다.
    • HashJoin (table table table ...) 지정된 table 간의 조인에 Hash Join을 선택합니다.
    • MergeJoin (table table table ...) 지정된 table 간의 조인에 Merge Join을 선택합니다.
    • NoNestLoop (table table table ...) 지정된 table 간의 조인에 Nested Loop 이외의 결합 방식을 선택합니다.
    • NoHashJoin (table table table ...) 지정된 table 간의 조인에 Hash Join 이외의 결합 방식을 선택합니다.
    • NoMergeJoin (table table table ...) 지정된 table 간의 조인에 Merge Join 이외의 결합 방식을 선택합니다.
  • 조인 순서
    • Leading (table table table ...) 지정된 table을 지정한 순서대로 결합합니다.
  • GUC 매개 변수
    • Set (GUC 매개 변수 값) 쿼리 실행 계획을 작성하고있는 동안 만 지정된 GUC 매개 변수 값으로 변경합니다.


:
Posted by Elick