ãããããªããã£ãã€ã¶ãã¯ãšãªã®å®è¡ã«å¿ èŠãªã³ã¹ããéžææ§ãããã³ãã®ä»ã®å¿ èŠãªãã©ã¡ãŒã¿ã®å®éã®å€ãä¿åãããããå床å®è¡ãããšãåéãããæšæºã®çµ±èšã ãã§ãªããååã®å®è¡åŸã«ä¿åãããçµ±èšã«ãã£ãŠãã¬ã€ããããå Žåã¯ã©ããªããŸããïŒ
ããã¯é©å¿ã¯ãšãªæé©åãšåŒã°ããææã§ããäžéšã®DBMSã¯ãã§ã«ãã®ãããªãã¯ãããžãŒã䜿çšããŠããŸããPostgres Professional
瀟ã¯ãæ°å¹ŽéãPostgreSQLã®AQOæ¡åŒµã«åãçµãã§ãããïŒäœããã®åœ¢ã§ïŒé©å¿æé©åãå®è£ ããŠããŸããäœæ¥ã¯ãŸã é²è¡äžã§ããããã§ã«ãã¹ãããå¿ èŠããããŸãã æåã«ãã¯ãšãªæé©åã®äž»é¡é åã詳ããèŠãŠã¿ãŸãããã
ãã©ã³ããŒã次åã®èšç»ãéžæã§ããçç±
SQLã¯ãšãªã¯ãããŸããŸãªæ¹æ³ã§å®è¡ã§ããŸããããšãã°ã2ã€ã®ããŒãã«ã®çµåãããå Žåããã¹ããããã«ãŒãã®äœ¿çšãããŒãžãããã·ã¥ãªã©ãããã€ãã®ç°ãªãæ¹æ³ã§å®è¡ã§ããŸããã¯ãšãªã«åå ããããŒãã«ãå€ãã»ã©ãçµåã®ããªãšãŒã·ã§ã³ãå€ããªããŸããã¹ã±ãžã¥ãŒã©ã®ã¿ã¹ã¯ã¯ãå€ãã®ããªãšãŒã·ã§ã³ããæå°ã³ã¹ãã®ã¯ãšãªå®è¡ãã©ã³ãéžæããããšã§ãã
ãã§ã«è¿°ã¹ãããã«ã圌ãã®ä»äºã§ã¯ãå€ãã®DBMSã®ã¹ã±ãžã¥ãŒã©ã¯ãèªåãŸãã¯æåã§åéãããçµ±èšæ å ±ã䜿çšããŸãããã©ã³ããŒã¯ããããã®çµ±èšã«åºã¥ããŠèŠç©ããã³ã¹ããèšç®ããŸãã
äžè¬ã«ãææ°ã®DBMSã¹ã±ãžã¥ãŒã©ã¯ã»ãšãã©ã®ç¶æ³ã§ããŸãæ©èœããŸãããã ããå Žåã«ãã£ãŠã¯ãéžæããèšç»ãæé©ãšã¯ã»ã©é ãããšããããŸãã
äŸãã°ãé¢é£ããçµ±èšæ å ±ã®æ¬ åŠã¯ããã©ã³ããçµåãããããŒãã«ã®è¡æ°ã«é¢ããïŒããããïŒæ£ãããªãããŒã¿ã«çŠç¹ãåããããšããäºå®ã«ã€ãªãããŸããã«ãŒãã£ããªãã£ã®é床ã®éå°è©äŸ¡ïŒãŸãã¯é倧è©äŸ¡ïŒã¯ãããŒãã«å ã®ããŒã¿ã«ã¢ã¯ã»ã¹ããããã®éæé©ãªæ¹æ³ã®éžæã«ã€ãªãããŸãã
ãã1ã€ã®éèŠãªçç±ã¯ãå¿ èŠãªã€ã³ããã¯ã¹ããªãããšã§ããã€ã³ããã¯ã¹ããªãå Žåãã¹ã±ãžã¥ãŒã©ãŒã¯ããŒã¿ã¢ã¯ã»ã¹æ¹æ³ã®éžæã«å¶éããããŸãã
äŸåïŒçžé¢ïŒæ¡ä»¶ã®äœ¿çšãŸããDBMSã®åäœã«æªåœ±é¿ãäžããå¯èœæ§ããããŸããã¹ã±ãžã¥ãŒã©ãŒïŒããã©ã«ãïŒã¯ãã¯ãšãªå ã®ãã¹ãŠã®æ¡ä»¶ãäºãã«ç¬ç«ããŠããããšãåæãšããŠããŸããã€ãŸãã1ã€ã®æ¡ä»¶ã®å€ãä»ã®æ¡ä»¶ã«åœ±é¿ãäžããããšã¯ãããŸãããããã¯åžžã«ããã§ãããšã¯éããŸãããäŸåæ¡ä»¶ïŒéµäŸ¿çªå·ãéœåžãªã©ïŒã䜿çšãããŠããå Žåããã©ã³ããŒã¯æ¥ç¶ã®ééã£ãã³ã¹ããšã«ãŒãã£ããªãã£ãèšç®ããŸããæ¡ä»¶ã§ã®é¢æ°
ã®äœ¿çšãã¹ã±ãžã¥ãŒã©ã«åœ±é¿ãäžããå¯èœæ§ããããŸããã¹ã±ãžã¥ãŒã©ãŒã®é¢æ°ã¯ããã©ãã¯ããã¯ã¹ãã§ãããé¢æ°ãè¿ãè¡ã®æ°ãããããªããããèšç»ã®èª€ã£ãã³ã¹ãã«ã€ãªããå¯èœæ§ããããŸãã
ã¹ã±ãžã¥ãŒã©ãŒã«åœ±é¿ãäžããæ¹æ³
å®éã®çµ±èšã¯ãã¹ã±ãžã¥ãŒã©ã®é©åãªäœæ¥ã«äžå¯æ¬ ãªæ¡ä»¶ã§ãããŸããçµ±èšæ å ±ãå®æçã«åéããããã«ã·ã¹ãã ãæ§æãããŠããããšã確èªããŠãã ããã
äžèšã®ç¶æ³ãä¿®æ£ãããã©ã³ããããæé©ãªã¯ãšãªå®è¡ãã©ã³ãéžæã§ããããã«ããã«ã¯ãããã€ãã®æ¹æ³ããããŸãã
ã€ã³ããã¯ã¹ããªããšããã©ã³ããŒã¯ããŒã¿ãååŸãã1ã€ã®æ¹æ³ãããããŸãã-é 次ããŒãã«ã¹ãã£ã³ïŒãããŠããã¯åžžã«æªããŠé«äŸ¡ãªããã§ã¯ãããŸããïŒãå Žåã«ãã£ãŠã¯ãå¿ èŠãªã€ã³ããã¯ã¹ãäœæãããšãããŒã¿ã¢ã¯ã»ã¹ãé«éåã§ããŸããããŒãã«å šäœãã¹ãã£ã³ããå¿ èŠã¯ãããŸãããããããã€ã³ããã¯ã¹ã®äœ¿çšïŒå¿ èŠãªã€ã³ããã¯ã¹ã®æ€çŽ¢ãäœæãä¿å®ïŒã¯èªç±ãªåã³ã§ã¯ãããŸãããçæ³çã«ã¯ãå¿ èŠãªå Žæã§æ£ç¢ºã«äœ¿çšããå¿ èŠããããŸãããããŠãå¿ èŠã®ãªãå Žæ-䜿çšããªãã§ãã ããã
ã¯ãšãªã§çžé¢çµåæ¡ä»¶ã䜿çšãããšãæ¡åŒµçµ±èšãçæã§ããŸã-æ¡ä»¶ãäºãã«é¢é£ããŠããããšããªããã£ãã€ã¶ã«æ瀺çã«ãããã³ãããããŸãããããè¡ãã«ã¯ãåŸå±åã®çµã¿åããã®æ°ãäºåã«äºæž¬ããããšãé£ãããããDBAïŒãŸãã¯éçºè ïŒã¯ããŒã¿ãããç解ããã¯ãšãªã®åŸå±æ¡ä»¶ãç£èŠããå¿ èŠããããŸãããã®ãããªãªãã·ã§ã³ããšã«ãæ¡åŒµçµ±èšãæåã§äœæããå¿ èŠããããŸãã
é¢æ°ãäœæãããšãã«ãããããã®å®è¡ã³ã¹ãããé¢æ°ã«ãã£ãŠçæãããè¡æ°ã®èŠç©ãããæå®ã§ããŸããããŒãžã§ã³12 ã§ã¯ããã«ããŒé¢æ°ã䜿çšããŠãåŒæ°ã«å¿ããŠãã©ã³ããŒã®æšå®ãæ¹åããããšãå¯èœã«ãªããŸããããããæåã®æ¹æ³ã§ãããåžžã«æé©ãªçµæãåŸããããšã¯éããŸããã
ä»ã®ãã¹ãŠã倱æããå Žåã¯ãæåã§ã¯ãšãªãæžãæããããšãã§ããŸãããšãã°ããããªã¢ã©ã€ãºããã¥ãŒãCommon Table ExpressionsïŒCTEïŒã䜿çšããŸãããŸãã¯ããµããžã§ã¯ãé åã®èŠä»¶ãæ確ã«ããå Žåã«ãã£ãŠã¯ãã¯ãšãªããžãã¯ãæ ¹æ¬çã«æžãæããŸãã
é©å¿ã¯ãšãªã®æé©åïŒ -ãšã¹ã±ãžã¥ãŒã©ã«ããã³ããã®ããäžã€ã®æ¹æ³ãããdaptive Q ueryã§O ptimizationãïŒããã®æ¹æ³ã®èãæ¹ã¯ãã¯ãšãªãå®è¡ãããåŸãå®éã®çµ±èšæ å ±ãä¿åãããæå®ãããïŒãŸãã¯åæ§ã®ïŒã¯ãšãªãç¹°ãè¿ããããšãã«ããªããã£ãã€ã¶ãããã«äŸåã§ãããšããããšã§ãã DBMS Postgres Pro Enterpriseã¯ãAQOãšåŒã°ããé©å¿ã¯ãšãªæé©åã®æ¡åŒµæ©èœã§ã
ããã®æ¡åŒµæ©èœã¯githubã«æçš¿ãããŠããŸãïŒgithub.com/postgrespro/aqoãããã©PostgreSQLã§è©Šãããšãã§ããŸãã
ã¢ãžã¥ãŒã«ã®ä»çµã¿
AQOã¢ãžã¥ãŒã«ã¯ããã®äœæ¥ã§æ©æ¢°åŠç¿ã䜿çšããŸããåäœåçã®è©³çŽ°ã«ã€ããŠã¯ãOleg Ivanovã«ããèšäºã§æ©æ¢°åŠç¿ã䜿çšããŠPostgreSQLã®ããã©ãŒãã³ã¹ãåäžãããããšãããã«è©³ããã¯ãã¢ãããã£ãã¯ãšãªã®æé©åïŒYouTubeã®ã¬ããŒãïŒã®ãã¬ãŒã³ããŒã·ã§ã³ãåç §ããŠãã ããã
ãã®æ¹æ³ã®æ¬è³ªã以äžã«ç°¡åã«èª¬æããŸãã
ã³ã¹ããèŠç©ããã«ã¯ããã©ã³ããã«ãŒãã£ããªãã£ã®èŠç©ãããå¿ èŠãšããŸããããã«ã¯ãæ¡ä»¶ã®éžææ§ã®èŠç©ãããå¿ èŠã§ãã
åçŽãªæ¡ä»¶ïŒ "attribute = constant"ã "attribute> constant"ãªã©ïŒã®å Žåããã©ã³ãã«ã¯éžææ§ãæšå®ããã¢ãã«ããããŸãããããè¡ãããã«ã圌ã¯çµ±èšæ å ±ã䜿çšããŸãïŒäžæã®å±æ§å€ããã¹ãã°ã©ã ãªã©ã®æ°ã
è«çæ¥ç¶è©ã䜿çšããåçŽãªèŠçŽ ã§æ§æãããæ¡ä»¶ã®å Žåããã©ã³ããŒã¯ç°¡åã«èšç®ãããåŒã䜿çšããŸãã
- selïŒAã§ã¯ãªãïŒ= 1-selïŒAïŒ
- selïŒAã§ã¯ãªãïŒ= 1-selïŒAïŒ
- selïŒAããã³BïŒ= selïŒAïŒ* selïŒBïŒ
- selïŒAãŸãã¯BïŒ= selïŒnotïŒnot Aããã³not BïŒïŒ= 1-ïŒ1-selïŒAïŒïŒ*ïŒ1-selïŒBïŒïŒ
ãããã®åŒã¯ãæ¡ä»¶AãšBã®ç¬ç«æ§ïŒç¡çžé¢ïŒãæ³å®ããŠããããããã®æ³å®ã«éåããå Žåã«èª€ã£ãæšå®å€ãåŸãããŸãã
AQOã¯åŒãè€éã«ããŸããåçŽãªæ¡ä»¶ããšã«ç¬èªã®ä¿æ°ãå°å ¥ãããŸããæ©æ¢°åŠç¿ã䜿çšããŠïŒæè¿åååž°ã䜿çšããŠïŒãAQOã¯ãããã®ä¿æ°ã調æŽããŠãåŒã«ãã£ãŠèšç®ãããéžææ§ããAQOã以åã«èŠ³å¯ããå®éã®éžææ§ãšæãããäžèŽããããã«ããŸãã
ãã®ãããã¢ãžã¥ãŒã«ã¯ä»¥äžãä¿åããŸãã
- , ;
- .
ãã®äœæ¥ã§ã¯ãAQOã¯å®æ°ãŸã§ã®æ¡ä»¶ãåºå¥ããŸããããã«ããã解決ãããåé¡ã®è€éãã軜æžã§ããããã«-ã»ãšãã©ã®å Žå-æ å ±ã¯äŸç¶ãšããŠå€±ãããŸãããAQOã¯å®æ°ã®å€ããèªèãããŸããããæ¡ä»¶ã®éžææ§ããèªèãããŸãã
æ倱ãçºçããç¶æ³ããããã¯ãç¹å®ã®å€ã«é¢ä¿ãªãå®æ°ã«ãã£ãŠè©äŸ¡ãããæ¡ä»¶ã§ããããšãã°ãäžéšã®æ¡ä»¶ã§ã¯ãã¹ã±ãžã¥ãŒã©ã¯åŠ¥åœãªèŠç©ãããè¡ãããšãã§ãããããã©ã«ãã®å®æ°ãéžæããŸãïŒããšãã°ãæ¡ä»¶ãåŒ1 =åŒ2ãã®éžææ§ã¯åžžã«0.005ãšããŠè©äŸ¡ããããåŒ1>åŒ2ãã¯1/3ãšããŠè©äŸ¡ãããŸãïŒã
ãããã£ãŠãAQOã¯è€éãªæ¡ä»¶ã®éžææ§ã®èŠç©ãããæ¹åããŸãïŒãã®çµæãã³ã¹ãèŠç©ãããæ¹åãããããé©åãªå®è¡èšç»ã®éžæã«ã€ãªããå¯èœæ§ããããŸãïŒã
ã¢ãžã¥ãŒã«ã®ã€ã³ã¹ããŒã«
ããã©PostgreSQLã§ã¢ãžã¥ãŒã«ã®æ©èœãè©Šãã«ã¯ãç¹å¥ãªãããã䜿çšããŠããœãŒã¹ã³ãŒãããã·ã¹ãã ãã¢ã»ã³ãã«ããå¿ èŠããããŸãã詳现ã«ã€ããŠã¯ãgithub ã®READMEãã¡ã€ã«ãåç §ããŠãã ããã
Postgres Pro Enterpriseã䜿çšããå ŽåãAQOã¢ãžã¥ãŒã«ã®ã€ã³ã¹ããŒã«ã¯æšæºã¢ãŒãã§ç¶è¡ãããŸãã
shared_preload_libraries = 'aqo'
ãã®åŸãå¿ èŠãªããŒã¿ããŒã¹ã«æ¡åŒµæ©èœãäœæã§ããŸãã
ããŒã¿ããŒã¹ã®æºå
AQOã¢ãžã¥ãŒã«ããã¢ããŒã¿ããŒã¹ã§ã©ã®ããã«æ©èœãããã®å ·äœäŸãèŠãŠã¿ãŸãããã2016幎9æãã2017幎9æãŸã§ã®å¹Žéã®ãã©ã€ãæ å ±ãå«ã倧ããªããŒã¿ããŒã¹ã䜿çšããŸãã
ãŸããæ¡åŒµæ©èœãäœæããŸãã
CREATE EXTENSION aqo;
次ã«ã䞊åã¯ãšãªã®åŠçããªãã«ããŠã䞊åãã©ã³ã®è¡šç€ºãã¡ã€ã³ã¿ã¹ã¯ã®éªéã«ãªããªãããã«ã
max_parallel_workers_per_gather = 0;
ãŸããPostgreSQLã¹ã±ãžã¥ãŒã©ãŒãããŒãã«ãçµåããããã®ãªãã·ã§ã³ãå¢ããã«ã¯ã2ã€ã®ã€ã³ããã¯ã¹ãäœæããŸãã
CREATE INDEX ON flights (scheduled_departure );
CREATE INDEX ON ticket_flights (fare_conditions );
çµæãåæãããšãã¯ããžã§ããå®è¡ããããã«èªã¿åãå¿ èŠãããããŒãžæ°ãšããŠãBUFFERSã®å€ã«çŠç¹ãåœãŠãŸããå®è¡æéãèŠãŠã¿ãŸãããïŒãã ããããŒããããã·ã¹ãã ãšèªå® ã®ã©ãããããã®æéã¯å€§ããç°ãªãå ŽåããããŸãïŒã
ãããã¡ãã£ãã·ã¥ãšwork_memãå¢ãããŠããã¹ãŠã®äœæ¥ãRAMã§å®è¡ãããããã«ããŸãã
shared_buffers = '256MB';
work_mem = '256MB';
AQOã¢ãžã¥ãŒã«ã®äœ¿çš
ãªã¯ãšã¹ããäœæããŠã¿ãŸããããç¹å®ã®æ¥ä»ããããžãã¹ã¯ã©ã¹ã«é£ãã§ã1æé以å ã®é 延ã§å°çããä¹å®¢ãååŸããå¿ èŠããããŸãã
AQOã䜿çšããã«ãªã¯ãšã¹ããå®è¡ããŠã¿ãŸãããïŒä»¥äžãã¢ãžã¥ãŒã«ã®åäœã®ç解ã«åœ±é¿ããªãæ å ±ã®äžéšã¯èšç»ããåé€ãããŠããŸãïŒã
EXPLAIN (ANALYZE, BUFFERS, TIMING OFF) SELECT t.ticket_no
FROM flights f
JOIN ticket_flights tf ON f.flight_id = tf.flight_id
JOIN tickets t ON tf.ticket_no = t.ticket_no
WHERE f.scheduled_departure > '2017-08-01'::timestamptz
AND f.actual_arrival < f.scheduled_arrival + interval '1 hour'
AND tf.fare_conditions = 'Business';
ãããŠãçµæã®èšç»ãèŠãŠã¿ãŸããã ããã®å Žåãã¹ã±ãžã¥ãŒã©ã¯æé©ãªèšç»ãæ€èšããŸãããæåã«ãããããããïŒïŒãã¹ãã£ã³ããããšã«ããããã©ã€ãããŒãã«ããè¡ã®ã»ãããååŸããŸããããã¯ãã€ã³ããã¯ã¹ã䜿çšããŠååŸããticket_flightsããŒãã«ããã®è¡ã®ã»ãããšããã·ã¥ïŒããŒãïŒã§æ¥ç¶ããŸããã¹ãã£ã³ïŒïŒãçµæã®çµæã¯ãæåŸã®ãã¹ããããã«ãŒãçµåïŒnode ïŒã®å€éšè¡ã»ãããšããŠäœ¿çšãããŸãããã®çµåã®å éšã»ããã¯ãticketsïŒïŒããŒãã«ã®æä»ã€ã³ããã¯ã¹ã¹ãã£ã³ã䜿çšããŠååŸãããŸãã æããããé«ããæäœã¯ããã¹ããããã«ãŒãã®å éšè¡ã»ãããååŸããããšã§ã-106 205ãããã¡ãŒãããã«èªã¿èŸŒãŸããŸãã
Nested Loop (rows=33210) (actual rows=31677)
Buffers: shared hit=116830 read=1
-> Hash Join (rows=33210) (actual rows=31677)
Hash Cond: (tf.flight_id = f.flight_id)
-> Index Scan ... on ticket_flights tf
Index Cond: fare_conditions = 'Business'
-> Hash
-> Bitmap Heap Scan on flights f (rows=8331) (actual rows=7673)
Recheck Cond: scheduled_departure > '2017-08-01'
Filter: actual_arrival < scheduled_arrival + '01:00:00'::interval
-> Bitmap Index Scan on ... [flights]
Index Cond: scheduled_departure > '2017-08-01'
Buffers: shared hit=44 read=1
-> Index Only Scan ... on tickets t (rows=1 width=14) (actual rows=1 loops=31677)
Index Cond: (ticket_no = tf.ticket_no)
Buffers: shared hit=106205
Planning Time: 9.326 ms
Execution Time: 675.836 ms
Bitmap Heap Scan on flights
Hash Join
Index Scan ... on ticket_flights
Nested Loop
Index Only Scan ... on tickets
ãã¹ããããã«ãŒããå€éšã»ããã®æ¯èŒçå°æ°ã®è¡ãçµåããããããã®ãã©ã³ã¯æ¯èŒçåªãããã©ã³ãšèšããŸãã
次ã«ãå®éšãè¡ãããªã¯ãšã¹ãå ã®æ¥ä»ã®å€æŽã«å¿ããŠãææ¡ãããèšç»ãã©ã®ããã«å€æŽããããïŒå€æŽãããªããïŒã確èªããŸããæ¥ä»ã¯ãæ¡ä»¶ãæºãããã©ã€ãããŒãã«ã®è¡ã®ç¯å²ãé 次å¢ããããã«éžæãããŸããããã«ããããã®ããŒãã«ãžã®ã¢ã¯ã»ã¹ã®ã«ãŒãã£ããªãã£ãè©äŸ¡ãããšãã«ãã©ã³ããŒãšã©ãŒãçºçããŸããäžèšã®èšç»ã§ã¯ãæåã®æ¥ä»ã§ããªããã£ãã€ã¶ã®ã«ãŒãã£ããªãã£ãã»ãšãã©ééããããŠããªãããšãããããŸãïŒïŒã ãªã¯ãšã¹ãã§æ¬¡ã®æ¥ä»ã«çœ®ãæããŸãã
Bitmap Heap Scan on flights f (rows=8331) (actual rows=7673)
- 2017-04-01
- 2017-01-01
- 2016-08-01
ãããŠçµæãèŠãŠãã ããïŒ
AQOãªãã®ã¯ãšãªãã©ã³
2017-04-01
Nested Loop (rows=31677) (actual rows=292392)
Buffers: shared hit=991756
-> Hash Join (rows=31677) (actual rows=292392)
Hash Cond: (tf.flight_id = f.flight_id)
-> Index Scan ⊠on ticket_flights tf
Index Cond: fare_conditions = 'Business')
-> Hash
-> Bitmap Heap Scan on flights f (rows=7673) (actual rows=70553)
Recheck Cond: scheduled_departure > '2017-04-01'
Filter: actual_arrival < (scheduled_arrival + '01:00:00'::interval)
-> Bitmap Index Scan on ... [flights]
Index Cond: scheduled_departure > '2017-04-01'
Buffers: shared hit=160
-> Index Only Scan ... on tickets t ( rows=1 width=14) (actual rows=1 loops=292392)
Index Cond: (ticket_no = tf.ticket_no)
Buffers: shared hit=980995
Planning Time: 5.980 ms
Execution Time: 2771.563 ms
, . . , (
() â Flights , ( , ).
2017-01-01
Nested Loop (rows=187710) (actual rows=484569)
Buffers: shared hit=1640723 read=49
-> Hash Join (rows=187738) (actual rows=484569)
Hash Cond: (tf.flight_id = f.flight_id)
-> Index Scan ... on ticket_flights tf
Index Cond: fare_conditions = 'Business'
-> Hash
-> Seq Scan on flights f (rows=45352) (actual rows=116985)
Filter: scheduled_departure > '2017-01-01'::date
AND actual_arrival < scheduled_arrival + '01:00:00'::interval
-> Index Only Scan ... on tickets t (rows=1) (actual rows=1 loops=484569)
Index Cond: (ticket_no = tf.ticket_no)
Buffers: shared hit=1630118 read=49
Planning Time: 6.225 ms
Execution Time: 4498.741 ms
, . flights, ( ) .
tickets â (1 630 118).
2016-08-01
Hash Join (rows=302200) (actual rows=771441)
Hash Cond: (t.ticket_no = tf.ticket_no)
Buffers: shared hit=25499 read=34643
-> Seq Scan on tickets t (rows=2949857) (actual rows=2949857)
-> Hash
-> Hash Join (rows=302236) (actual rows=771441)
Hash Cond: (tf.flight_id = f.flight_id)
-> Index Scan on ticket_flights tf
Index Cond: fare_conditions = 'Business'
-> Hash
-> Seq Scan on flights f (rows=73005) (actual rows=188563)
Filter: scheduled_departure > '2016-08-01'::date)
AND actual_arrival < scheduled_arrival + '01:00:00'::interval
Planning Time: 9.990 ms
Execution Time: 3014.577 ms
(
Nested Loop (rows=31677) (actual rows=292392)
Buffers: shared hit=991756
-> Hash Join (rows=31677) (actual rows=292392)
Hash Cond: (tf.flight_id = f.flight_id)
-> Index Scan ⊠on ticket_flights tf
Index Cond: fare_conditions = 'Business')
-> Hash
-> Bitmap Heap Scan on flights f (rows=7673) (actual rows=70553)
Recheck Cond: scheduled_departure > '2017-04-01'
Filter: actual_arrival < (scheduled_arrival + '01:00:00'::interval)
-> Bitmap Index Scan on ... [flights]
Index Cond: scheduled_departure > '2017-04-01'
Buffers: shared hit=160
-> Index Only Scan ... on tickets t ( rows=1 width=14) (actual rows=1 loops=292392)
Index Cond: (ticket_no = tf.ticket_no)
Buffers: shared hit=980995
Planning Time: 5.980 ms
Execution Time: 2771.563 ms
, . . , (
Bitmap Heap Scan on flights f (rows=7673) (actual rows=70553)
), , Nested Loop, , .
() â Flights , ( , ).
2017-01-01
Nested Loop (rows=187710) (actual rows=484569)
Buffers: shared hit=1640723 read=49
-> Hash Join (rows=187738) (actual rows=484569)
Hash Cond: (tf.flight_id = f.flight_id)
-> Index Scan ... on ticket_flights tf
Index Cond: fare_conditions = 'Business'
-> Hash
-> Seq Scan on flights f (rows=45352) (actual rows=116985)
Filter: scheduled_departure > '2017-01-01'::date
AND actual_arrival < scheduled_arrival + '01:00:00'::interval
-> Index Only Scan ... on tickets t (rows=1) (actual rows=1 loops=484569)
Index Cond: (ticket_no = tf.ticket_no)
Buffers: shared hit=1630118 read=49
Planning Time: 6.225 ms
Execution Time: 4498.741 ms
, . flights, ( ) .
tickets â (1 630 118).
2016-08-01
Hash Join (rows=302200) (actual rows=771441)
Hash Cond: (t.ticket_no = tf.ticket_no)
Buffers: shared hit=25499 read=34643
-> Seq Scan on tickets t (rows=2949857) (actual rows=2949857)
-> Hash
-> Hash Join (rows=302236) (actual rows=771441)
Hash Cond: (tf.flight_id = f.flight_id)
-> Index Scan on ticket_flights tf
Index Cond: fare_conditions = 'Business'
-> Hash
-> Seq Scan on flights f (rows=73005) (actual rows=188563)
Filter: scheduled_departure > '2016-08-01'::date)
AND actual_arrival < scheduled_arrival + '01:00:00'::interval
Planning Time: 9.990 ms
Execution Time: 3014.577 ms
(
(rows=302236) (actual rows=771441)
). , , : Hash Join Nested Loop.
èŠçŽãããšãAQOã¢ãžã¥ãŒã«ã䜿çšããªãå Žåããã©ã³ããŒã¯æ¬¡ã®ããã«æ©èœããŸãã
æ¥ä» | ãããã¡ãŒ | æéãããªç§ | ã³ã¡ã³ã |
2017-08-01 | 116 831 | 675.836 | ãã¹ããããã«ãŒããšããã·ã¥çµåã䜿çšããããã©ã€ããšãã±ããã®ããŒãã«ãã€ã³ããã¯ã¹ã«ãã£ãŠã¹ãã£ã³ãããŸã |
2017-04-01 | 991 756 | 2771.563 | åãèšç»ã§ãããæé©ã§ã¯ãããŸããããã©ã€ãããŒãã«ãšãã±ããããŒãã«ã®ã€ã³ããã¯ã¹ã«ããã¢ã¯ã»ã¹ãéžæãããšããã©ã³ããã«ãŒãã£ããªãã£ãèšç®ãããšãã«å€§ããªééããç¯ããŠããããšãããããŸã |
2017-01-01 | 1,640,772 | 4498.741 | åã次åã®èšç»ãããããèšç»æ åœè ã¯ããã©ã€ãããŒãã«ã®é 次ã¹ãã£ã³ã«åãæ¿ããããšã«ããŸããã |
2016-08-01 | 60 142 | 3014.577 | èšç»ãæçµçã«å€æŽãããŸãã-ãªããã£ãã€ã¶ã¯ããŒãã«ããå€ãã®è¡ãéžæããå¿ èŠãããããšãç解ããŠããããããã©ã€ããšãã±ããã®ããŒãã«ãé 次ã¹ãã£ã³ããŸããéå¹çãªïŒãã®å ŽåïŒãã¹ããããã«ãŒãã¯ãããã·ã¥çµåã«çœ®ãæããŸãã |
AQOã䜿çšããã¯ãšãªãã©ã³
AQO. :
, :
2017-08-01
, , . AQO .
2017-04-01
Hash Join (rows=293891) (actual rows=292392)
Hash Cond: (t.ticket_no = tf.ticket_no)
Buffers: shared hit=25658 read=34640
-> Seq Scan on tickets t (rows=2949857) (actual rows=2949857)
-> Hash
-> Hash Join (rows=293734) (actual rows=292392)
Hash Cond: (tf.flight_id = f.flight_id)
-> Index Scan ... on ticket_flights tf
Index Cond: (fare_conditions)::text = 'Business'::text
-> Hash
-> Bitmap Heap Scan on flights f
Recheck Cond: scheduled_departure > '2017-04-01'::date
Filter: actual_arrival < scheduled_arrival + '01:00:00'::interval
-> Bitmap Index Scan on ... [flights]
Index Cond: scheduled_departure > '2017-04-01'::date
Buffers: shared hit=160
Planning Time: 9.652 ms
Execution Time: 2218.074 ms
ââ, AQO â . Tickets . . , AQO.
2017-01-01
Hash Join (rows=484452) (actual rows=484569)
Hash Cond: (t.ticket_no = tf.ticket_no)
Buffers: shared hit=25534 read=34608
-> Seq Scan on tickets t (rows=2949857) (actual rows=2949857)
-> Hash (rows=484464) (actual rows=484569)
-> Hash Join (rows=484464) (actual rows=484569)
Hash Cond: (tf.flight_id = f.flight_id)
-> Index Scan ... on ticket_flights tf
Index Cond: fare_conditions::text = 'Business'::text
-> Hash
-> Seq Scan on flights f (rows=116971) (actual rows=116985)
Filter: scheduled_departure > '2017-01-01'::date
AND actual_arrival < scheduled_arrival + '01:00:00'::interval
Planning Time: 6.264 ms
Execution Time: 2746.485 ms
â Flights .
2016-08-01
.
SET aqo.mode = 'learn';
, :
2017-08-01
, , . AQO .
2017-04-01
Hash Join (rows=293891) (actual rows=292392)
Hash Cond: (t.ticket_no = tf.ticket_no)
Buffers: shared hit=25658 read=34640
-> Seq Scan on tickets t (rows=2949857) (actual rows=2949857)
-> Hash
-> Hash Join (rows=293734) (actual rows=292392)
Hash Cond: (tf.flight_id = f.flight_id)
-> Index Scan ... on ticket_flights tf
Index Cond: (fare_conditions)::text = 'Business'::text
-> Hash
-> Bitmap Heap Scan on flights f
Recheck Cond: scheduled_departure > '2017-04-01'::date
Filter: actual_arrival < scheduled_arrival + '01:00:00'::interval
-> Bitmap Index Scan on ... [flights]
Index Cond: scheduled_departure > '2017-04-01'::date
Buffers: shared hit=160
Planning Time: 9.652 ms
Execution Time: 2218.074 ms
ââ, AQO â . Tickets . . , AQO.
2017-01-01
Hash Join (rows=484452) (actual rows=484569)
Hash Cond: (t.ticket_no = tf.ticket_no)
Buffers: shared hit=25534 read=34608
-> Seq Scan on tickets t (rows=2949857) (actual rows=2949857)
-> Hash (rows=484464) (actual rows=484569)
-> Hash Join (rows=484464) (actual rows=484569)
Hash Cond: (tf.flight_id = f.flight_id)
-> Index Scan ... on ticket_flights tf
Index Cond: fare_conditions::text = 'Business'::text
-> Hash
-> Seq Scan on flights f (rows=116971) (actual rows=116985)
Filter: scheduled_departure > '2017-01-01'::date
AND actual_arrival < scheduled_arrival + '01:00:00'::interval
Planning Time: 6.264 ms
Execution Time: 2746.485 ms
â Flights .
2016-08-01
.
çµæãããäžåºŠèŠãŠã¿ãŸãããã
æ¥ä» | ãããã¡ãŒ | æéãããªç§ | ã³ã¡ã³ã |
2017-08-01 | 116 831 | 662.966 | èšç»ã¯ã¢ãžã¥ãŒã«ã䜿çšããªãå Žåãšåãã§ã |
2017-04-01 | 60298 | 2218.074 | ã¢ãžã¥ãŒã«ãã³ãã䜿çšããŠããªããã£ãã€ã¶ã¯å€æ°ã®æååãçµåãããäºå®ã§ããããšãç解ãããã§ã«ãã®ã¹ãããã§ãã¹ããããã«ãŒããããã·ã¥çµåã«çœ®ãæããããšã§èšç»ãæ¹åããŸã |
2017-01-01 | 60142 | 2746.485 | èšç»ã¯å°ãæ¹åãããŸãã-ãã©ã€ãããŒãã«ãžã®ããããããã«ã¢ã¯ã»ã¹ãã代ããã«ããã®é 次ã¹ãã£ã³ã䜿çšãããŸã |
2016-08-01 | 60142 | 3253.861 | èšç»ã¯å€æŽãããŠããŸãã-ãã®å Žåã®æè¯ã®èšç» |
ãŸãšãã
ã¢ãããã£ãã¯ãšãªæé©åã«AQOã¢ãžã¥ãŒã«ã䜿çšããããšã«ã¯ãå©ç¹ãšæ¬ ç¹ã®äž¡æ¹ããããŸãã
ã¢ãžã¥ãŒã«ã䜿çšããå©ç¹ã®1ã€ã¯ãã¯ãšãªã®äŸåæ¡ä»¶ã远跡ããå¿ èŠããªãããšã§ããå Žåã«ãã£ãŠã¯ãã¯ãšãªã®å®è¡é床ãåäžããããšããããŸãããŸããã¢ãžã¥ãŒã«ã®äœ¿çšã«ã¯ããŸããŸãªã¢ãŒãããããŸããããšãã°ãAQOã䜿çšããŠãç¹å®ã®ã¿ã€ãã®ã¯ãšãªã®ã¿ãæé©åã§ããŸãã
ã¢ãžã¥ãŒã«ã®æ¬ ç¹ã®ãã¡ãã¢ãžã¥ãŒã«æ§é ã§çµ±èšããã¬ãŒãã³ã°ããã³ä¿åããããã®è¿œå ã®ãªãŒããŒãããã³ã¹ããåºå¥ã§ããŸãããŸããã¢ãžã¥ãŒã«ã«ãã£ãŠåéãããçµ±èšæ å ±ã¯ã¬ããªã«ã«éä¿¡ãããŸããã
AQOã¢ãžã¥ãŒã«ã¯ãã¹ã±ãžã¥ãŒã©ãŒã®èãããããã¹ãŠã®åé¡ã®ãç¹å¹è¬ãã§ã¯ãããŸãããããšãã°ãäžéšã®ç¶æ³ã§ã¯ãã¢ãžã¥ãŒã«ã¯æ¡åŒµçµ±èšã眮ãæããããšãã§ããŸãïŒæåã§äœæãããŠããªãå ŽåïŒããŸãã¯ç¡é¢ä¿ãªçµ±èšã«æ³šæãæããŸããããã ããã¢ãžã¥ãŒã«ã¯å¿ èŠãªã€ã³ããã¯ã¹ãäœæãããããã«ã¯ãšãªããã¹ããæžãæããŸããã
ãããã£ãŠããã¹ãŠã®ãªã¯ãšã¹ãã«å¯ŸããŠã¢ãžã¥ãŒã«ãæå¹ã«ããã¹ãã§ã¯ãããŸãããAQOã®çæ³çãªæé©ååè£ã¯ãããŒãã®ã«ãŒãã£ããªãã£ãŒã®èšç®ã«ããããã©ã³ããŒã®ãšã©ãŒãæªãèšç»ã«ã€ãªããã¯ãšãªã§ãããããŠãäœããã®çç±ã§ããã®èŠç©ããã®ââ粟床ã«åœ±é¿ãäžããããšã¯ã§ããŸããã