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
운영게시판
최근게시물
PostgreSQL Q&A 6378 게시물 읽기
No. 6378
같은 쿼리와 다른 쿼리플랜
작성자
신기배(소타)
작성일
2005-10-20 17:48ⓒ
2005-10-20 17:52ⓜ
조회수
2,607
MagicHome=# EXPLAIN ANALYZE SELECT gid, s.domain, s.name,
sp.intro,  sp.regist_time, r.public, r.publish, p.pid, c.fax_id,
c.category, c.address, c.edited from view_site s join
external.tb_tax_category c using(gid) join view_site_profile sp
using(gid) join view_work_release r using(gid) join view_page p
using(gid) where p.parent is null and gid not in (9198) order by
r.public desc limit 10 offset 0;
QUERY PLAN ------------------------- Limit (cost=0.00..287.76 rows=10 width=251) (actual time=0.206..1.082 rows=10 loops=1)
-> Nested Loop (cost=0.00..277576.88 rows=9646 width=251) (actual time=0.203..1.068 rows=10 loops=1)
-> Nested Loop (cost=0.00..95023.85 rows=8358 width=259) (actual time=0.154..0.632 rows=10 loops=1)
-> Nested Loop (cost=0.00..58909.89 rows=8678 width=155) (actual time=0.082..0.442 rows=12 loops=1)
-> Nested Loop (cost=0.00..30432.77 rows=8678 width=98) (actual time=0.055..0.257 rows=12 loops=1)
-> Index Scan Backward using idx_tb_work_release_public on tb_work_release (cost=0.00..515.32 rows=8718 width=9) (actual time=0.026..0.056 rows=12 loops=1)
-> Index Scan using tb_site_pkey on tb_site (cost=0.00..3.42 rows=1 width=89) (actual time=0.010..0.011 rows=1 loops=12)
Index Cond: (tb_site.gid = "outer".gid)
Filter: ((able = true) AND (gid <> 9198))
-> Index Scan using tb_site_profile_pkey on tb_site_profile (cost=0.00..3.27 rows=1 width=57) (actual time=0.008..0.009 rows=1 loops=12)
Index Cond: ("outer".gid = tb_site_profile.gid)
-> Index Scan using tb_tax_category_pkey on tb_tax_category c (cost=0.00..4.15 rows=1 width=104) (actual time=0.009..0.010 rows=1 loops=12)
Index Cond: ("outer".gid = c.gid)
-> Index Scan using index_tb_page_gid_pageid on tb_page (cost=0.00..21.78 rows=5 width=8) (actual time=0.016..0.035 rows=1 loops=10)
Index Cond: (tb_page.gid = "outer".gid)
Filter: (parent IS NULL)
Total runtime: 1.305 ms
(17건 있음)

작업시간: 8.438 ms

이런 쿼리가 있습니다..

 

MagicHome=# CREATE VIEW external.view_site_list as
MagicHome-# SELECT gid, s.domain, s.name, sp.intro, sp.regist_time, r.public, r.publish, p.pid, c.fax_id, c.category, c.address, c.edited from view_site s join external.tb_tax_category c using(gid) join view_site_profile sp using(gid) join view_work_release r using(gid) join view_page p using(gid) where p.parent is null order by r.public desc;

저 쿼리를 이용하여 뷰를 만들었습니다. 검색조건인 gid not in (9198) 부분과 limit 부분만 빼고 뷰를 만들었습니다.

만들어진 뷰에 같은 조건이 되도록 아래와 같이 쿼리하면 플랜도 많이 다르고 시간도 많이 차이납니다..

 

MagicHome=# EXPLAIN ANALYZE select gid, domain, name,
regist_time, pid, category from external.view_site_list where gid
not in (9198) limit 10 offset 0;
QUERY PLAN
----------------- Limit (cost=16201.40..16201.53 rows=10 width=258) (actual time=691.545..691.583 rows=10 loops=1)
-> Subquery Scan view_site_list (cost=16201.40..16321.95 rows=9644 width=258) (actual time=691.543..691.575 rows=10 loops=1)
-> Sort (cost=16201.40..16225.51 rows=9644 width=251) (actual time=691.532..691.535 rows=10 loops=1)
Sort Key: tb_work_release.public
-> Merge Join (cost=0.00..15563.19 rows=9644 width=251) (actual time=32.076..678.323 rows=6159 loops=1)
Merge Cond: ("outer".gid = "inner".gid)
-> Merge Join (cost=0.00..27770.58 rows=9287 width=210) (actual time=29.572..618.421 rows=6159 loops=1)
Merge Cond: ("outer".gid = "inner".gid)
-> Merge Join (cost=0.00..27060.75 rows=10612 width=201) (actual time=26.835..560.550 rows=6159 loops=1)
Merge Cond: ("outer".gid = "inner".gid)
-> Merge Join (cost=0.00..32366.95 rows=10611 width=97) (actual time=0.329..502.846 rows=8679 loops=1)
Merge Cond: ("outer".gid = "inner".gid)
-> Index Scan using tb_site_pkey on tb_site (cost=0.00..988.93 rows=12522 width=89) (actual time=0.065..28.151 rows=8676 loops=1)
Filter: ((able = true) AND (gid <> 9198))
-> Index Scan using index_tb_page_gid_pageid on tb_page (cost=0.00..31371.60 rows=10660 width=8) (actual time=0.086..421.481 rows=8721 loops=1)
Filter: (parent IS NULL) -> Index Scan using tb_tax_category_pkey on tb_tax_category c (cost=0.00..209.11 rows=9962 width=104) (actual time=0.014..21.975 rows=6161 loops=1) -> Index Scan using tb_work_release_pkey on tb_work_release (cost=0.00..568.05 rows=8718 width=9) (actual time=0.039..19.559 rows=8718 loops=1)
-> Index Scan using tb_site_profile_pkey on tb_site_profile (cost=0.00..327.33 rows=9593 width=57) (actual time=0.012..18.192 rows=8718 loops=1)
Total runtime: 692.991 ms
(20건 있음)
작업시간: 698.630 ms
이 글에 대한 댓글이 총 2건 있습니다.

pgsql의 옵티마이저가 많이 똑똑해 지기는 했지만 여전히 사람 손을 타야 한다는 것을 나타내는 듯 하군요. ^^

 

뭐... 오라클도 이런 경우는 종종 있으니 탓할 수는 없을 것 같구요.

view를 쓰지 않을 수 밖에 없겠네요.

 

enable_mergejoin, enable_hashjoin, enable_seqscan을 모두 false로 해보시면 어떨까요?

박성철(gyumee)님이 2005-10-21 16:36에 작성한 댓글입니다.
이 댓글은 2005-10-21 16:37에 마지막으로 수정되었습니다.

넹 그렇게 해보면 다시 인덱스를 잘 타는 플랜으로 변신합니당 ㅎ;

어쩧수 없이 걍 뷰를 안쓰고 쿼리를 하고 있네용~

뷰가 편한데 -.-

신기배(소타)님이 2005-10-22 12:01에 작성한 댓글입니다.
[Top]
No.
제목
작성자
작성일
조회
6381php에서 쿼리를 날려 테이블의 필드 코멘트를 볼 수 있는 방법이 있습니까? [2]
김창욱
2005-10-22
2162
6380DB 서버 다운에 대비한 해결방법은? [1]
가우나라
2005-10-21
2672
6379initdb 할때요..... [1]
백성기
2005-10-21
2506
6378같은 쿼리와 다른 쿼리플랜 [2]
신기배
2005-10-20
2607
6377지난주 특정요일의 날짜를 뽑을려면 어떻게 할까요? [1]
webper
2005-10-20
2710
6376시퀀스 기존 시퀀스에서 추가로 증가하게 설정하기? [2]
이강성
2005-10-18
2311
6375Point In Time Recovery 사용해보고있던중... [1]
백진수
2005-10-17
1845
Valid XHTML 1.0!
All about the DATABASE... Copyleft 1999-2024 DSN, All rights reserved.
작업시간: 0.020초, 이곳 서비스는
	PostgreSQL v16.2로 자료를 관리합니다