æè¿ã®CPUã«ã¯å€ãã®ã³ã¢ããããŸãã é·å¹Žãã¢ããªã±ãŒã·ã§ã³ã¯ã¯ãšãªãããŒã¿ããŒã¹ã«äžŠè¡ããŠéä¿¡ããŠããŸããã ãããããŒãã«å
ã®è€æ°ã®è¡ã®ã¬ããŒãã¯ãšãªã§ããå Žåãè€æ°ã®CPUã䜿çšãããšããé«éã«å®è¡ãããPostgreSQLã§ã¯ããŒãžã§ã³9.6以éã§å¯èœã§ãã
䞊åã¯ãšãªæ©èœã®å®è£
ã«ã¯3幎ããããŸãããã¯ãšãªå®è¡ã®ããŸããŸãªæ®µéã§ã³ãŒããæžãæããå¿
èŠããããŸããã PostgreSQL 9.6ã¯ãã³ãŒããããã«æ¹åããããã®ã€ã³ãã©ã¹ãã©ã¯ãã£ãå°å
¥ããŸããã ãã以éã®ããŒãžã§ã³ã§ã¯ãä»ã®çš®é¡ã®ã¯ãšãªã䞊è¡ããŠå®è¡ãããŸãã
å¶éäºé
- ãã¹ãŠã®ã³ã¢ãæ¢ã«äœ¿çšãããŠããå Žåã¯ã䞊åå®è¡ãæå¹ã«ããªãã§ãã ãããæå¹ã«ããªããšãä»ã®èŠæ±ãé
ããªããŸãã
- æãéèŠãªããšã¯ãé«ãWORK_MEMå€ã§ã®äžŠååŠçã¯å€§éã®ã¡ã¢ãªãæ¶è²»ããããšã§ããåããã·ã¥çµåãŸãã¯ãœãŒãã¯ãwork_memã®éã§ã¡ã¢ãªãå æããŸãã
- äœã¬ã€ãã³ã·ã®OLTPãªã¯ãšã¹ãã¯ããã©ã¬ã«å®è¡ã«ãã£ãŠé«éåã§ããŸããã ãŸããã¯ãšãªã1ã€ã®è¡ãè¿ãå Žåã䞊ååŠçã«ãã£ãŠé床ãäœäžããã ãã§ãã
- éçºè
ã¯TPC-Hãã³ãããŒã¯ã®äœ¿çšã奜ã¿ãŸãã ãã¶ããããªãã¯å®ç§ãªäžŠåå®è¡ã®ããã®åæ§ã®ã¯ãšãªãæã£ãŠããã§ãããã
- è¿°èªããã¯ã®ãªãSELECTã¯ãšãªã®ã¿ã䞊è¡ããŠå®è¡ãããŸãã
- å Žåã«ãã£ãŠã¯ãæ£ããã€ã³ããã¯ã¹äœæãã䞊åã®ããŒãã«ã¹ãã£ã³ãããåªããŠããå ŽåããããŸãã
- ã¯ãšãªãšã«ãŒãœã«ã®äžæåæ¢ã¯ãµããŒããããŠããŸããã
- é åºä»ãã»ããã®ãŠã£ã³ããŠé¢æ°ãšéèšé¢æ°ã¯äžŠåã§ã¯ãããŸããã
- I / Oã¯ãŒã¯ããŒãã§ã¯äœãåŸãããŸããã
- 䞊åãœãŒãã¢ã«ãŽãªãºã ã¯ååšããŸããã ãã ããããã€ãã®åŽé¢ã§ã¯ã䞊ã¹æ¿ããããã¯ãšãªã䞊åã«å®è¡ã§ããŸãã
- CTEïŒWITH ...ïŒããã¹ããããSELECTã«çœ®ãæããŠã䞊ååŠçãæå¹ã«ããŸãã
- ãµãŒãããŒãã£ã®ããŒã¿ã©ãããŒã¯ãŸã 䞊ååŠçããµããŒãããŠããŸããïŒãã ããå¯èœã§ãïŒïŒ
- FULL OUTER JOINã¯ãµããŒããããŠããŸããã
- max_rowsã¯ã䞊ååŠçãç¡å¹ã«ããŸãã
- ãªã¯ãšã¹ãã«PARALLEL SAFEãšããŠããŒã¯ãããŠããªãæ©èœãããå Žåãã·ã³ã°ã«ã¹ã¬ããã«ãªããŸãã
- ãã©ã³ã¶ã¯ã·ã§ã³åé¢ã¬ãã«SERIALIZABLEã¯ã䞊ååŠçãç¡å¹ã«ããŸãã
ãã¹ãç°å¢
PostgreSQLéçºè
ã¯ãTPC-Hãã³ãããŒã¯ã¯ãšãªã®å¿çæéãççž®ããããšããŸããã ãã³ãããŒã¯ãããŠã³ããŒãããŠã PostgreSQLã«é©åãããŸã ã ããã¯TPC-Hãã³ãããŒã¯ã®éå
¬åŒãªäœ¿çšæ³ã§ãããããŒã¿ããŒã¹ãããŒããŠã§ã¢ã®æ¯èŒçšã§ã¯ãããŸããã
- ãªããµã€ãã®TPCãã TPC-H_Tools_v2.17.3.zipïŒãŸãã¯æ°ããããŒãžã§ã³ïŒ ãããŠã³ããŒãããŸãã
- makefile.suiteã®ååãMakefileã«å€æŽãã https ïŒ //github.com/tvondra/pg_tpchã®èª¬æã«åŸã£ãŠå€æŽããŸã ã makeã³ãã³ãã§ã³ãŒããã³ã³ãã€ã«ããŸãã
- ããŒã¿ã®çæïŒ
./dbgen -s 10
ã¯23 GBã®ããŒã¿ããŒã¹ãäœæããŸãã ããã¯ã䞊åã¯ãšãªãšé䞊åã¯ãšãªã®ããã©ãŒãã³ã¹ã®éãã確èªããã®ã«ååã§ãã csv for
ããã³sed
csv for
ã tbl
ãã¡ã€ã«ãcsv for
å€æããŸãã- pg_tpchãªããžããªã®ã¯ããŒã³ãäœæãã
csv
ãpg_tpch/dss/data
ã³ããŒãpg_tpch/dss/data
ã qgen
ã³ãã³ãã§ã¯ãšãªãäœæããŸãã./tpch.sh
ã³ãã³ãã䜿çšããŠãããŒã¿ããŒã¹ã«ããŒã¿ãã¢ããããŒãããŸãã
䞊åé 次ã¹ãã£ã³
䞊åèªã¿åãã§ã¯ãªããå€ãã®CPUã³ã¢ã«ããŒã¿ãåæ£ããŠãããããé«éã«ãªãå¯èœæ§ããããŸãã ææ°ã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã§ã¯ãPostgreSQLããŒã¿ãã¡ã€ã«ã¯é©åã«ãã£ãã·ã¥ãããŸãã å
èªã¿ã䜿çšãããšãPGããŒã¢ã³ãèŠæ±ãããããå€ããã¹ãã¬ãŒãžããååŸã§ããŸãã ãããã£ãŠãã¯ãšãªã®ããã©ãŒãã³ã¹ã¯ãã£ã¹ã¯I / Oã«ãã£ãŠå¶éãããŸããã 以äžã®ããã«CPUãµã€ã¯ã«ãæ¶è²»ããŸãã
- ããŒãã«ã®ããŒãžãã1è¡ãã€èªã¿åããŸãã
- æååå€ãš
WHERE
å¥ãæ¯èŒããŸãã
ç°¡åãªselect
ã¯ãšãªãå®è¡ããŠã¿ãŸãããã
tpch=# explain analyze select l_quantity as sum_qty from lineitem where l_shipdate <= date '1998-12-01' - interval '105' day; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------- Seq Scan on lineitem (cost=0.00..1964772.00 rows=58856235 width=5) (actual time=0.014..16951.669 rows=58839715 loops=1) Filter: (l_shipdate <= '1998-08-18 00:00:00'::timestamp without time zone) Rows Removed by Filter: 1146337 Planning Time: 0.203 ms Execution Time: 19035.100 ms
é 次ã¹ãã£ã³ã§ã¯ãéçŽããã«è¡ãå€ããããããèŠæ±ã¯åäžã®CPUã³ã¢ã«ãã£ãŠå®è¡ãããŸãã
SUM()
ãè¿œå ãããšã2ã€ã®ã¯ãŒã¯ãããŒããªã¯ãšã¹ãã®é«éåã«åœ¹ç«ã€ããšãããããŸãã
explain analyze select sum(l_quantity) as sum_qty from lineitem where l_shipdate <= date '1998-12-01' - interval '105' day; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------- Finalize Aggregate (cost=1589702.14..1589702.15 rows=1 width=32) (actual time=8553.365..8553.365 rows=1 loops=1) -> Gather (cost=1589701.91..1589702.12 rows=2 width=32) (actual time=8553.241..8555.067 rows=3 loops=1) Workers Planned: 2 Workers Launched: 2 -> Partial Aggregate (cost=1588701.91..1588701.92 rows=1 width=32) (actual time=8547.546..8547.546 rows=1 loops=3) -> Parallel Seq Scan on lineitem (cost=0.00..1527393.33 rows=24523431 width=5) (actual time=0.038..5998.417 rows=19613238 loops=3) Filter: (l_shipdate <= '1998-08-18 00:00:00'::timestamp without time zone) Rows Removed by Filter: 382112 Planning Time: 0.241 ms Execution Time: 8555.131 ms
䞊åéçŽ
Parallel Seq ScanããŒãã¯ãéšåéçŽçšã®è¡ãçæããŸãã éšåéçŽããŒãã¯ã SUM()
ã䜿çšããŠãããã®è¡ãåãæšãŠãŸãã æåŸã«ãåã¯ãŒã¯ãããŒã®SUMã«ãŠã³ã¿ãŒãGatherããŒãã«ãã£ãŠåéãããŸãã
æçµçµæã¯ããFinalize AggregateãããŒãã«ãã£ãŠèšç®ãããŸãã ç¬èªã®éèšé¢æ°ãæã£ãŠããå Žåã¯ãããããã䞊åå®å
šããšããŠããŒã¯ããŠãã ããã
ã¯ãŒã¯ãããŒã®æ°
ãµãŒããŒãåèµ·åããã«ãã¯ãŒã¯ãããŒã®æ°ãå¢ããããšãã§ããŸãã
alter system set max_parallel_workers_per_gather=4; select * from pg_reload_conf();
ããã§ãExplainåºåã«4人ã®ã¯ãŒã«ãŒã衚瀺ãããŸãã
tpch=# explain analyze select sum(l_quantity) as sum_qty from lineitem where l_shipdate <= date '1998-12-01' - interval '105' day; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------- Finalize Aggregate (cost=1440213.58..1440213.59 rows=1 width=32) (actual time=5152.072..5152.072 rows=1 loops=1) -> Gather (cost=1440213.15..1440213.56 rows=4 width=32) (actual time=5151.807..5153.900 rows=5 loops=1) Workers Planned: 4 Workers Launched: 4 -> Partial Aggregate (cost=1439213.15..1439213.16 rows=1 width=32) (actual time=5147.238..5147.239 rows=1 loops=5) -> Parallel Seq Scan on lineitem (cost=0.00..1402428.00 rows=14714059 width=5) (actual time=0.037..3601.882 rows=11767943 loops=5) Filter: (l_shipdate <= '1998-08-18 00:00:00'::timestamp without time zone) Rows Removed by Filter: 229267 Planning Time: 0.218 ms Execution Time: 5153.967 ms
ããã§äœãèµ·ãã£ãŠããŸããïŒ ã¯ãŒã¯ãããŒã¯2åããããªã¯ãšã¹ãã¯1.6599åããéããããŸããã§ããã èšç®ã¯èå³æ·±ãã§ãã 2ã€ã®äœæ¥ããã»ã¹ãš1人ã®ãªãŒããŒãããŸããã å€æŽåŸã4 + 1ã«ãªããŸããã
䞊ååŠçããã®æ倧å éïŒ5/3 = 1.66ïŒ6ïŒåã
ã©ã®ããã«æ©èœããŸããïŒ
ããã»ã¹
ãªã¯ãšã¹ãã®å®è¡ã¯åžžã«å
é ã®ããã»ã¹ããå§ãŸããŸãã ãªãŒããŒã¯ãé䞊ååŠçãšäžŠååŠçã®äžéšããã¹ãŠè¡ããŸãã åããªã¯ãšã¹ããå®è¡ããä»ã®ããã»ã¹ã¯ãã¯ãŒã¯ãããŒãšåŒã°ããŸãã 䞊ååŠçã§ã¯ã åçããã¯ã°ã©ãŠã³ãã¯ãŒã¯ãããŒã®ã€ã³ãã©ã¹ãã©ã¯ãã£ã䜿çšããŸã ïŒããŒãžã§ã³9.4以éïŒã PostgreSQLã®ä»ã®éšåã¯ã¹ã¬ããã§ã¯ãªãããã»ã¹ã䜿çšããããã3ã€ã®ã¯ãŒã¯ãããŒã䜿çšããã¯ãšãªã¯ãåŸæ¥ã®åŠçããã4åé«éã«ãªãå ŽåããããŸãã
çžäºäœçš
ã¯ãŒã¯ãããŒã¯ãã¡ãã»ãŒãžãã¥ãŒïŒå
±æã¡ã¢ãªã«åºã¥ãïŒãä»ããŠãªãŒããŒãšéä¿¡ããŸãã åããã»ã¹ã«ã¯ããšã©ãŒçšãšã¿ãã«çšã®2ã€ã®ãã¥ãŒããããŸãã
ããã€ã®äœæ¥ããã»ã¹ãå¿
èŠã§ããïŒ
æå°å¶éã¯ã max_parallel_workers_per_gather
ãã©ã¡ãŒã¿ãŒã«ãã£ãŠèšå®ãããŸãã 次ã«ãã¯ãšãªå®è¡max_parallel_workers size
ã¯ã max_parallel_workers size
ãã©ã¡ãŒã¿ã«ãã£ãŠå¶éãããããŒã«ããã¯ãŒã¯ãããŒãmax_parallel_workers size
ãŸãã æåŸã®å¶éã¯max_worker_processes
ãã€ãŸãããã¯ã°ã©ãŠã³ãããã»ã¹ã®ç·æ°ã§ãã
ã¯ãŒã¯ãããŒãå²ãåœãŠãããšãã§ããªãã£ãå ŽåãåŠçã¯åäžããã»ã¹ã«ãªããŸãã
ã¯ãšãªãã©ã³ããŒã¯ãããŒãã«ãŸãã¯ã€ã³ããã¯ã¹ã®ãµã€ãºã«å¿ããŠã¯ãŒã¯ãããŒãççž®ã§ããŸãã ããã«ã¯min_parallel_table_scan_size
ããã³min_parallel_index_scan_size
ãã©ã¡ãŒã¿ãŒããããŸãã
set min_parallel_table_scan_size='8MB' 8MB table => 1 worker 24MB table => 2 workers 72MB table => 3 workers x => log(x / min_parallel_table_scan_size) / log(3) + 1 worker
ããŒãã«ãmin_parallel_(index|table)_scan_size
3åã«ãªãmin_parallel_(index|table)_scan_size
ãPostgresã¯ã¯ãŒã¯ãããŒãè¿œå ããŸãã ã¯ãŒã¯ããã»ã¹ã®æ°ã¯ã³ã¹ãããŒã¹ã§ã¯ãããŸããã 埪ç°äŸåé¢ä¿ã¯è€éãªå®è£
ãè€éã«ããŸãã 代ããã«ãã¹ã±ãžã¥ãŒã©ã¯åçŽãªã«ãŒã«ã䜿çšããŸãã
å®éã«ã¯ããããã®ã«ãŒã«ã¯æ¬çªç°å¢ã«åžžã«é©ããŠããããã§ã¯ãªããããç¹å®ã®ããŒãã«ã®ã¯ãŒã¯ãããŒã®æ°ãå€æŽã§ããŸãïŒALTER TABLE ... SETïŒ parallel_workers = N
ïŒã
䞊ååŠçã䜿çšãããªãã®ã¯ãªãã§ããïŒ
å¶éã®é·ããªã¹ãã«å ããŠãã³ã¹ããã§ãã¯ããããŸãã
parallel_setup_cost
çããªã¯ãšã¹ãã®äžŠååŠçãªãã§å®è¡ããŸãã ãã®ãã©ã¡ãŒã¿ãŒã¯ãã¡ã¢ãªãŒã®æºåãããã»ã¹ã®éå§ãããã³åæããŒã¿äº€æã®æéãæšå®ããŸãã
parallel_tuple_cost
ïŒãªãŒããŒãšã¯ãŒã«ãŒéã®éä¿¡ã¯ãã¯ãŒã¯ããã»ã¹ããã®ã¿ãã«ã®æ°ã«æ¯äŸããŠé
延ãããããšãã§ããŸãã ãã®ãã©ã¡ãŒã¿ãŒã¯ãããŒã¿äº€æã³ã¹ããèšç®ããŸãã
å
¥ãåã«ãŒãçµå
PostgreSQL 9.6+ â . explain (costs off) select c_custkey, count(o_orderkey) from customer left outer join orders on c_custkey = o_custkey and o_comment not like '%special%deposits%' group by c_custkey; QUERY PLAN -------------------------------------------------------------------------------------- Finalize GroupAggregate Group Key: customer.c_custkey -> Gather Merge Workers Planned: 4 -> Partial GroupAggregate Group Key: customer.c_custkey -> Nested Loop Left Join -> Parallel Index Only Scan using customer_pkey on customer -> Index Scan using idx_orders_custkey on orders Index Cond: (customer.c_custkey = o_custkey) Filter: ((o_comment)::text !~~ '%special%deposits%'::text)
åéã¯æåŸã®æ®µéã§è¡ãããããããã¹ããããã«ãŒãã®å·Šçµåã¯äžŠåæäœã§ãã Parallel Index Only Scanã¯ããŒãžã§ã³10ã§ã®ã¿ç»å ŽããŸããããã©ã¬ã«ã·ãªã¢ã«ã¹ãã£ã³ãšåæ§ã«æ©èœããŸãã æ¡ä»¶c_custkey = o_custkey
ã¯ãã¯ã©ã€ã¢ã³ãè¡ããšã«1ã€ã®æ³šæãèªã¿åããŸãã ãããã£ãŠãå¹³è¡ã§ã¯ãããŸããã
ããã·ã¥çµå-ããã·ã¥çµå
åã¯ãŒã¯ãããŒã¯ãPostgreSQL 11ãŸã§ã®ç¬èªã®ããã·ã¥ããŒãã«ãäœæããŸãããŸãããããã®ããã»ã¹ã4ã€ä»¥äžããå Žåãããã©ãŒãã³ã¹ã¯åäžããŸããã æ°ããããŒãžã§ã³ã§ã¯ãããã·ã¥ããŒãã«ãäžè¬çã§ãã åã¯ãŒã¯ãããŒã¯ãWORK_MEMã䜿çšããŠããã·ã¥ããŒãã«ãäœæã§ããŸãã
select l_shipmode, sum(case when o_orderpriority = '1-URGENT' or o_orderpriority = '2-HIGH' then 1 else 0 end) as high_line_count, sum(case when o_orderpriority <> '1-URGENT' and o_orderpriority <> '2-HIGH' then 1 else 0 end) as low_line_count from orders, lineitem where o_orderkey = l_orderkey and l_shipmode in ('MAIL', 'AIR') and l_commitdate < l_receiptdate and l_shipdate < l_commitdate and l_receiptdate >= date '1996-01-01' and l_receiptdate < date '1996-01-01' + interval '1' year group by l_shipmode order by l_shipmode LIMIT 1; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=1964755.66..1964961.44 rows=1 width=27) (actual time=7579.592..7922.997 rows=1 loops=1) -> Finalize GroupAggregate (cost=1964755.66..1966196.11 rows=7 width=27) (actual time=7579.590..7579.591 rows=1 loops=1) Group Key: lineitem.l_shipmode -> Gather Merge (cost=1964755.66..1966195.83 rows=28 width=27) (actual time=7559.593..7922.319 rows=6 loops=1) Workers Planned: 4 Workers Launched: 4 -> Partial GroupAggregate (cost=1963755.61..1965192.44 rows=7 width=27) (actual time=7548.103..7564.592 rows=2 loops=5) Group Key: lineitem.l_shipmode -> Sort (cost=1963755.61..1963935.20 rows=71838 width=27) (actual time=7530.280..7539.688 rows=62519 loops=5) Sort Key: lineitem.l_shipmode Sort Method: external merge Disk: 2304kB Worker 0: Sort Method: external merge Disk: 2064kB Worker 1: Sort Method: external merge Disk: 2384kB Worker 2: Sort Method: external merge Disk: 2264kB Worker 3: Sort Method: external merge Disk: 2336kB -> Parallel Hash Join (cost=382571.01..1957960.99 rows=71838 width=27) (actual time=7036.917..7499.692 rows=62519 loops=5) Hash Cond: (lineitem.l_orderkey = orders.o_orderkey) -> Parallel Seq Scan on lineitem (cost=0.00..1552386.40 rows=71838 width=19) (actual time=0.583..4901.063 rows=62519 loops=5) Filter: ((l_shipmode = ANY ('{MAIL,AIR}'::bpchar[])) AND (l_commitdate < l_receiptdate) AND (l_shipdate < l_commitdate) AND (l_receiptdate >= '1996-01-01'::date) AND (l_receiptdate < '1997-01-01 00:00:00'::timestamp without time zone)) Rows Removed by Filter: 11934691 -> Parallel Hash (cost=313722.45..313722.45 rows=3750045 width=20) (actual time=2011.518..2011.518 rows=3000000 loops=5) Buckets: 65536 Batches: 256 Memory Usage: 3840kB -> Parallel Seq Scan on orders (cost=0.00..313722.45 rows=3750045 width=20) (actual time=0.029..995.948 rows=3000000 loops=5) Planning Time: 0.977 ms Execution Time: 7923.770 ms
TPC-Hããã®èŠæ±12ã¯ã䞊åããã·ã¥æ¥ç¶ã瀺ããŠããŸãã åã¯ãŒã¯ãããŒã¯ãå
±æããã·ã¥ããŒãã«ã®äœæã«é¢äžããŸãã
çµåãçµå
ããŒãžçµåã¯æ¬è³ªçã«äžŠåã§ã¯ãããŸããã ããããªã¯ãšã¹ãã®æåŸã®æ®µéã§ãããã©ããå¿é
ããªãã§ãã ãã-ãŸã 䞊è¡ããŠå®è¡ã§ããŸãã
-- Query 2 from TPC-H explain (costs off) select s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment from part, supplier, partsupp, nation, region where p_partkey = ps_partkey and s_suppkey = ps_suppkey and p_size = 36 and p_type like '%BRASS' and s_nationkey = n_nationkey and n_regionkey = r_regionkey and r_name = 'AMERICA' and ps_supplycost = ( select min(ps_supplycost) from partsupp, supplier, nation, region where p_partkey = ps_partkey and s_suppkey = ps_suppkey and s_nationkey = n_nationkey and n_regionkey = r_regionkey and r_name = 'AMERICA' ) order by s_acctbal desc, n_name, s_name, p_partkey LIMIT 100; QUERY PLAN ---------------------------------------------------------------------------------------------------------- Limit -> Sort Sort Key: supplier.s_acctbal DESC, nation.n_name, supplier.s_name, part.p_partkey -> Merge Join Merge Cond: (part.p_partkey = partsupp.ps_partkey) Join Filter: (partsupp.ps_supplycost = (SubPlan 1)) -> Gather Merge Workers Planned: 4 -> Parallel Index Scan using <strong>part_pkey</strong> on part Filter: (((p_type)::text ~~ '%BRASS'::text) AND (p_size = 36)) -> Materialize -> Sort Sort Key: partsupp.ps_partkey -> Nested Loop -> Nested Loop Join Filter: (nation.n_regionkey = region.r_regionkey) -> Seq Scan on region Filter: (r_name = 'AMERICA'::bpchar) -> Hash Join Hash Cond: (supplier.s_nationkey = nation.n_nationkey) -> Seq Scan on supplier -> Hash -> Seq Scan on nation -> Index Scan using idx_partsupp_suppkey on partsupp Index Cond: (ps_suppkey = supplier.s_suppkey) SubPlan 1 -> Aggregate -> Nested Loop Join Filter: (nation_1.n_regionkey = region_1.r_regionkey) -> Seq Scan on region region_1 Filter: (r_name = 'AMERICA'::bpchar) -> Nested Loop -> Nested Loop -> Index Scan using idx_partsupp_partkey on partsupp partsupp_1 Index Cond: (part.p_partkey = ps_partkey) -> Index Scan using supplier_pkey on supplier supplier_1 Index Cond: (s_suppkey = partsupp_1.ps_suppkey) -> Index Scan using nation_pkey on nation nation_1 Index Cond: (n_nationkey = supplier_1.s_nationkey)
Merge JoinããŒãã¯Gather Mergeã®äžã«ãããŸãã ãããã£ãŠãããŒãžã§ã¯äžŠååŠçã¯äœ¿çšãããŸããã ãã ããParallel Index ScanããŒãã¯åŒãç¶ãpart_pkey
ã»ã°ã¡ã³ãã«åœ¹ç«ã¡ãŸãã
ã»ã¯ã·ã§ã³æ¥ç¶
PostgreSQL 11ã§ã¯ãããŒãã£ã·ã§ã³åå²ã¯ããã©ã«ãã§ç¡å¹ã«ãªã£ãŠããŸããéåžžã«é«äŸ¡ãªã¹ã±ãžã¥ãŒãªã³ã°ãå¿
èŠã§ãã åæ§ã®ããŒãã£ã·ã§ãã³ã°ãæã€ããŒãã«ã¯ãã»ã¯ã·ã§ã³ããšã«çµåã§ããŸãã ãããã£ãŠãPostgresã¯ããå°ããªããã·ã¥ããŒãã«ã䜿çšããŸãã åã»ã¯ã·ã§ã³æ¥ç¶ã¯äžŠåã«ã§ããŸãã
tpch=# set enable_partitionwise_join=t; tpch=# explain (costs off) select * from prt1 t1, prt2 t2 where t1.a = t2.b and t1.b = 0 and t2.b between 0 and 10000; QUERY PLAN --------------------------------------------------- Append -> Hash Join Hash Cond: (t2.b = t1.a) -> Seq Scan on prt2_p1 t2 Filter: ((b >= 0) AND (b <= 10000)) -> Hash -> Seq Scan on prt1_p1 t1 Filter: (b = 0) -> Hash Join Hash Cond: (t2_1.b = t1_1.a) -> Seq Scan on prt2_p2 t2_1 Filter: ((b >= 0) AND (b <= 10000)) -> Hash -> Seq Scan on prt1_p2 t1_1 Filter: (b = 0) tpch=# set parallel_setup_cost = 1; tpch=# set parallel_tuple_cost = 0.01; tpch=# explain (costs off) select * from prt1 t1, prt2 t2 where t1.a = t2.b and t1.b = 0 and t2.b between 0 and 10000; QUERY PLAN ----------------------------------------------------------- Gather Workers Planned: 4 -> Parallel Append -> Parallel Hash Join Hash Cond: (t2_1.b = t1_1.a) -> Parallel Seq Scan on prt2_p2 t2_1 Filter: ((b >= 0) AND (b <= 10000)) -> Parallel Hash -> Parallel Seq Scan on prt1_p2 t1_1 Filter: (b = 0) -> Parallel Hash Join Hash Cond: (t2.b = t1.a) -> Parallel Seq Scan on prt2_p1 t2 Filter: ((b >= 0) AND (b <= 10000)) -> Parallel Hash -> Parallel Seq Scan on prt1_p1 t1 Filter: (b = 0)
äž»ãªããšã¯ãã»ã¯ã·ã§ã³å
ã®æ¥ç¶ã¯ããããã®ã»ã¯ã·ã§ã³ãååã«å€§ããå Žåã«ã®ã¿äžŠåã§ãããšããããšã§ãã
䞊åè¿œå -䞊åè¿œå
ç°ãªãã¯ãŒã¯ãããŒã®ç°ãªããããã¯ã®ä»£ããã«ã 䞊åè¿œå ã䜿çšã§ããŸãã ããã¯éåžžãUNION ALLã¯ãšãªã§çºçããŸãã æ¬ ç¹ã¯ãåã¯ãŒã¯ãããŒã1ã€ã®èŠæ±ã®ã¿ãåŠçããããã䞊ååŠçãå°ãªããªãããšã§ãã
ããã«ã¯2ã€ã®ã¯ãŒã¯ãããŒãå®è¡ãããŠããŸããã4ã€ãå«ãŸããŠããŸãã
tpch=# explain (costs off) select sum(l_quantity) as sum_qty from lineitem where l_shipdate <= date '1998-12-01' - interval '105' day union all select sum(l_quantity) as sum_qty from lineitem where l_shipdate <= date '2000-12-01' - interval '105' day; QUERY PLAN ------------------------------------------------------------------------------------------------ Gather Workers Planned: 2 -> Parallel Append -> Aggregate -> Seq Scan on lineitem Filter: (l_shipdate <= '2000-08-18 00:00:00'::timestamp without time zone) -> Aggregate -> Seq Scan on lineitem lineitem_1 Filter: (l_shipdate <= '1998-08-18 00:00:00'::timestamp without time zone)
æãéèŠãªå€æ°
- WORK_MEMã¯ãèŠæ±ã ãã§ãªããåããã»ã¹ã®ã¡ã¢ãªéãå¶éããŸããwork_memæ¥ç¶ããã»ã¹ =倧éã®ã¡ã¢ãªã
max_parallel_workers_per_gather
å®è¡ããã°ã©ã ããã©ã³ããã®äžŠååŠçã«äœ¿çšããäœæ¥ããã»ã¹ã®æ°ãmax_worker_processes
ã¯ãŒã¯ããã»ã¹ã®åèšæ°ããµãŒããŒäžã®CPUã³ã¢ã®æ°ã«èª¿æŽããŸããmax_parallel_workers
ã¯åãã§ããã䞊åã¯ãŒã¯ãããŒçšã§ãã
ãŸãšã
ããŒãžã§ã³9.6以éã䞊ååŠçã«ãããå€ãã®è¡ãŸãã¯ã€ã³ããã¯ã¹ãã¹ãã£ã³ããè€éãªã¯ãšãªã®ããã©ãŒãã³ã¹ã倧å¹
ã«åäžããŸãã PostgreSQL 10ã§ã¯ãããã©ã«ãã§äžŠååŠçãæå¹ã«ãªã£ãŠããŸãã OLTPã¯ãŒã¯ããŒãã倧ãããµãŒããŒã§ã¯å¿ããã«ç¡å¹ã«ããŠãã ããã é 次ã¹ãã£ã³ãŸãã¯ã€ã³ããã¯ã¹ã¹ãã£ã³ã¯å€ãã®ãªãœãŒã¹ãæ¶è²»ããŸãã ããŒã¿ã»ããå
šäœãã¬ããŒãããŠããªãå Žåã¯ãæ¬ èœããŠããã€ã³ããã¯ã¹ãè¿œå ããããæ£ããããŒãã£ã·ã§ã³ã䜿çšããã ãã§ãã¯ãšãªãå¹çåã§ããŸãã
åç
§è³æ