æ°ããããŒã¿ããŒã¹ç®¡çè ãæåã«è³ã«ããããšã®1ã€ã¯ããEXPLAINã䜿çšãã§ãã ãããŠãæåã®è©Šã¿ã§ã圌ã¯ç解ã§ããªãããšã«çŽé¢ããŠããŸãïŒ
QUERY PLAN --------------------------------------------------------------------------------------------------------------------------- Sort (cost=146.63..148.65 rows=808 width=138) (actual time=55.009..55.012 rows=71 loops=1) Sort Key: n.nspname, p.proname, (pg_get_function_arguments(p.oid)) Sort Method: quicksort Memory: 43kB -> Hash Join (cost=1.14..107.61 rows=808 width=138) (actual time=42.495..54.854 rows=71 loops=1) Hash Cond: (p.pronamespace = n.oid) -> Seq Scan on pg_proc p (cost=0.00..89.30 rows=808 width=78) (actual time=0.052..53.465 rows=2402 loops=1) Filter: pg_function_is_visible(oid) -> Hash (cost=1.09..1.09 rows=4 width=68) (actual time=0.011..0.011 rows=4 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 1kB -> Seq Scan on pg_namespace n (cost=0.00..1.09 rows=4 width=68) (actual time=0.005..0.007 rows=4 loops=1) Filter: ((nspname <> 'pg_catalog'::name) AND (nspname <> 'information_schema'::name))
ããã¯ã©ãããæå³ã§ããïŒ
äžèšã®èª¬æãããã«ç解ããããšããã®ã¯ç¡çã§ãã ãã£ãšã·ã³ãã«ãªãã®ããå§ããŸãããã ãããããã®åã«ã1ã€ã®éèŠãªããšãç解ããŠã»ããïŒ
PostgreSQLã¯èŠããŠããŸã
ããã¯ãPostgreSQLãããã€ãã®ã¡ã¿æ å ±ïŒæ å ±ã«é¢ããæ å ±ïŒãä¿åããããšãæå³ããŸãã è¡æ°ãç°ãªãå€ã®æ°ãæãäžè¬çãªå€ãªã©ã 倧ããªããŒãã«ã®å Žåããã®æ å ±ã¯ã©ã³ãã ãµã³ããªã³ã°ã«åºã¥ããŠããŸãããPostgreså šäœã§ã¯ããŒã¿ã«ã€ããŠå€ãã®ããšãæ¬åœã«ç¥ã£ãŠããŸãã
ããã§ã¯ãç°¡åãªã¯ãšãªãèŠãŠèª¬æããŸãããã
$ explain select * from test where i = 1; QUERY PLAN ------------------------------------------------------ Seq Scan on test (cost=0.00..40.00 rows=12 width=4) Filter: (i = 1) (2 rows)
ãªã¯ãšã¹ãã¯éåžžã«ã·ã³ãã«ã§ãç§ã«ã¯ãè¿œå ã®ã³ã¡ã³ãã¯å¿ èŠãªããšæãããŸãã
Explainã§ã¯ãæåã®è¡ãšã->ãã§å§ãŸããã¹ãŠã®è¡ãæäœã§ããæ®ãã®è¡ã¯ãäžèšã®æäœã«é¢ããè¿œå æ å ±ã§ãã
ç§ãã¡ã®å Žåããã¹ãããŒãã«ã®é 次ã¹ãã£ã³ãšãã1ã€ã®æäœãããããŸããã
ãã£ã«ã¿ãŒã«é¢ããè¿œå æ å ±ããããŸãã
é 次ã¹ãã£ã³ãšã¯ãPostgreSQLãããŒãã«ããããŒã¿ããéãããèªã¿åãããšãæå³ããŸãã çè«çã«ã¯ãè¡ããã£ã«ã¿ãªã³ã°ïŒåé€ïŒã§ããŸãããäžè¬çã«ã¯ãããŒãã«å šäœãèªã¿åã£ãŠè¿ãæºåãã§ããŠããŸãã
ãªãæºåãã§ããŠããã®ã§ããïŒ ããã«èª¬æããŸãã
ãããã£ãŠãSeqscanè¡ã¯ãã·ãŒã±ã³ã·ã£ã«ã¢ãŒãã§ããŒãã«ãã¹ãã£ã³ããŠããããšã瀺ããŠããŸãã ãããŠããã®ããŒãã«ã¯ããã¹ãããšåŒã°ããŸãïŒãã ããããã§æ倧ã®åé¡ã®1ã€ã¯ãåè·¯ã衚瀺ãããªãããšã§ããããããäœåºŠã泚ç®ãããŠããŸãïŒã
ãããŠãæè¡åŸã®æ¬åŒ§å ã®ãããã®æ°åã¯äœã§ããïŒ
質åãããã§ãã 次ã®è¡šããããŸãã
Table "public.t" Column | Type | Modifiers -------------+---------+------------------------------------------------ id | integer | not null default nextval('t_id_seq'::regclass) some_column | integer | something | text | Indexes: "t_pkey" PRIMARY KEY, btree (id) "q" btree (some_column)
ãã®ããŒãã«ãšã¯ãšãªã®å®çŸ©ïŒ
SELECT * FROM t where some_column = 123;
ãã®ã¯ãšãªãæºããããã®æè¯ã®æ¹æ³ã¯äœã ãšæããŸããïŒ ããŒãã«ãé 次ã¹ãã£ã³ããããã€ã³ããã¯ã¹ã䜿çšããŸããïŒ
ããªãã®çãïŒãã¡ãããã€ã³ããã¯ã¹ã䜿çšãããã®åã«ã€ã³ããã¯ã¹ãããã®ã§ããã®ã¡ãœããã¯ããé«éã«ãªããŸãã次ã«ãããŒãã«ã«è¡ã1ã€ãããªããsome_columnå€ã123ã«çããå Žåã¯ã©ãã§ããããã
é 次ã¹ãã£ã³ãå®è¡ããã«ã¯ãããŒãã«ã®1ããŒãžïŒ8192ãã€ãïŒã®ã¿ãèªã¿åãå¿ èŠããããè¡ãååŸããŸãã ã€ã³ããã¯ã¹ã䜿çšããã«ã¯ãã€ã³ããã¯ã¹ããããŒãžãèªã¿åããæ¡ä»¶ã«äžèŽããè¡ãããŒãã«ã«ãããã©ããã確èªããŠãããããŒãã«ããããŒãžãèªã¿åãå¿ èŠããããŸãã
çµæã¯2åã®ä»äºã§ãïŒ
ããã¡ããã§ãããç§ãã¡ã¯éåžžã«å°ããªããŒãã«ã«ã€ããŠè©±ããŠããã®ã§ãé床ã¯éèŠã§ã¯ãããŸãããã ããã 次ã«ã100åè¡ããããåè¡ã«some_column = 123ãããããŒãã«ãæ³åããŠã¿ãŸããããããã®ã€ã³ããã¯ã¹ã¯ééããªã圹ã«ç«ã¡ãŸããããå®éã«ã¯ç¶æ³ãæ·±å»ã«æªåãããŸãã
ãã¡ããã100äžè¡ããããã®ãã¡ã®1ã€ã ããsome_column = 123ã§ããå Žåãã€ã³ããã¯ã¹ã¹ãã£ã³ãæãæ£ãããœãªã¥ãŒã·ã§ã³ã«ãªããŸãã
ãããã£ãŠãäžããããã¯ãšãªãã€ã³ããã¯ã¹ã䜿çšãããã©ããããããŠã€ã³ããã¯ã¹ã䜿çšããå¿ èŠããããã©ãããèšãããšã¯äžå¯èœã§ãïŒäžè¬çãªã±ãŒã¹ã«ã€ããŠè©±ããŠããïŒã ãããç解ããã«ã¯ãããã«æ å ±ãå¿ èŠã§ãã ãããŠããã®äºå®ã¯åçŽãªçµè«ã«ã€ãªãããŸããç¶æ³ã«å¿ããŠãããŒã¿ãååŸãã1ã€ã®æ¹æ³ã¯å¥ã®æ¹æ³ãããåªããŠããããæªããã§ãã
PostgreSQLïŒããæç¹ãŸã§ïŒã¯ãèãããããã¹ãŠã®ã·ããªãªããã§ãã¯ããŸãã 圌ã¯ãããªããæã£ãŠããè¡æ°ãšãäžããããåºæºã«è©²åœããè¡æ°ïŒã»ãšãã©ã®å ŽåïŒãç¥ã£ãŠããã®ã§ãéåžžã«è³¢æãªæ±ºå®ãäžãããšãã§ããŸãã
ãããããããã®æ±ºå®ã¯ã©ã®ããã«è¡ãããŸããïŒ ããã¯ãexplainã®æåã®æ°åã»ããã瀺ããã®ã§ãã ããã¯ã³ã¹ãã§ãã
äžéšã®äººã ã¯ãã³ã¹ãã¯æ°ç§ã§æšå®ããããšèããŠããŸãã ããã§ã¯ãããŸããã 枬å®åäœã¯ã1ããŒãžãé çªã«æœåºãããã§ãã ã€ãŸããæéãšãªãœãŒã¹ã®äž¡æ¹ã®äœ¿çšãæšå®ãããŸãã
postgresql.confã§ã¯ã次ã®ãã©ã¡ãŒã¿ãŒã«æ°ä»ããããããŸããã
seq_page_cost = 1.0 # measured on an arbitrary scale random_page_cost = 4.0 # same scale as above cpu_tuple_cost = 0.01 # same scale as above cpu_index_tuple_cost = 0.005 # same scale as above cpu_operator_cost = 0.0025 # same scale as above
ã€ãŸããã·ãŒã±ã³ã·ã£ã«ããŒãžãèªã¿åãã³ã¹ããå€æŽããããšããã§ããŸãã ãããã®ãã©ã¡ãŒã¿ã¯ãåãã¯ãšãªãå®è¡ããããã®ç°ãªãã¡ãœãããå®è£ ããããã«PostgreSQLãå¿ èŠãšæ³å®ããã³ã¹ããèšå®ããŸãã
ããšãã°ãããã¹ããšã€ã³ããã¯ã¹ãå«ã1000è¡ã®åçŽãªããŒãã«ãäœæããŠã¿ãŸãããã
create table test (id serial primary key, some_text text); CREATE TABLE insert into test (some_text) select 'whatever' from generate_series(1,1000); INSERT 0 1000
idã«ããæ¡ä»¶ã§Explainãå®è¡ãããšã以äžãçæãããããšãããããŸãã
explain select * from test where id = 50; QUERY PLAN ----------------------------------------------------------------------- Index Scan using test_pkey on test (cost=0.28..8.29 rows=1 width=36) Index Cond: (id = 50) (2 rows)
ããããã©ã®ãããªç¶æ³ã§ãã€ã³ããã¯ã¹ã¹ãã£ã³ã䜿çšã§ããªããšpostgresã«äŒããå Žåã¯ã©ãã§ããããã
explain select * from test where id = 50; QUERY PLAN ------------------------------------------------------------------------ Bitmap Heap Scan on test (cost=4.28..8.30 rows=1 width=13) Recheck Cond: (id = 50) -> Bitmap Index Scan on test_pkey (cost=0.00..4.28 rows=1 width=0) Index Cond: (id = 50) (4 rows)
ãããŠãããããªãã«ããŸãããïŒ
explain select * from test where id = 50; QUERY PLAN ------------------------------------------------------ Seq Scan on test (cost=0.00..18.50 rows=1 width=13) Filter: (id = 50) (2 rows)
OKããããŠããããé£å士ã«å°å·ããŸãããïŒ
Index Scan using test_pkey on test (cost=0.28..8.29 rows=1 width=36) Bitmap Heap Scan on test (cost=4.28..8.30 rows=1 width=13) Seq Scan on test (cost=0.00..18.50 rows=1 width=13)
ããã©ã«ãã§ã¯ãpostgresã¯IndexScanã䜿çšããŸãã ãªãã§ïŒ ç°¡åã§ã-ãã®å Žåãæãå®äŸ¡ãªæ¹æ³ã§ãã ã³ã¹ãã¯8.29ã«ãªããŸãããããããããããŒãã¹ãã£ã³ïŒãããäœã§ããïŒã«ã¯8.30ãããããã·ãŒã±ã³ã¹ã¹ãã£ã³ã«ã¯18.5ãããããŸãã
ããããŸãããããªãŒããŒãããã¯2ã€ã®æ°åã§ç€ºãããŸãïŒnumber..numberã ããã¯äœã§ããããããŠãªãç§ã¯2çªç®ã®æ°åã«ã€ããŠã ã話ããŠããã®ã§ããïŒ æåã®æ°ãèæ ®ãããšãåè ã¯seqã¹ãã£ã³ã«ãªããŸããããã¯ããã®å€ããŒãã«çãããindexscanã®å Žåã¯0.28ã§ãããããããããããŒãã¹ãã£ã³ã®å Žåã¯4.28ã§ããããã§ãã
ã³ã¹ãå€ã¯ãç¯å²ïŒæ°å€..numberïŒã«è¡šç€ºãããŸããããã¯ãæäœã®éå§ã®è¡ã®ã³ã¹ããšããã¹ãŠã®è¡ãååŸããããã®ã³ã¹ãã瀺ããŠããããã§ãïŒãã¹ãŠãããŒãã«å ã®ãã¹ãŠã§ã¯ãªãããã®æäœã«ãã£ãŠè¿ããããã®ãæå³ããŸãïŒã
åæè²»çšã¯ãããã§ããïŒ seqscanã«ã¯äœããããŸãã-ããŒãžãèªãã§è¡ãè¿ãã ãã§ãã ããã ãã§ãã ãã ããããšãã°ãããŒã¿ã»ããã䞊ã¹æ¿ããã«ã¯ããã¹ãŠã®ããŒã¿ãèªã¿åã£ãŠå®éã«äžŠã¹æ¿ããŠãããæåã®è¡ãæ€èšããå¿ èŠããããŸãã ããã¯ã以äžã®èª¬æã§æ確ã«èŠãããŸãã
QUERY PLAN ------------------------------------------------------------------- Sort (cost=22.88..23.61 rows=292 width=202) Sort Key: relfilenode -> Seq Scan on pg_class (cost=0.00..10.92 rows=292 width=202) (3 rows)
ãœãŒãã®åæã³ã¹ãã¯22.88ã§ãããåèšã³ã¹ãã¯23.61ã«éããªãããšã«æ³šæããŠãã ããã ãããã£ãŠãSortããè¡ãè¿ãããšã¯ã³ã¹ãã®ç¹ã§ã¯éèŠã§ã¯ãããŸããããè¡ã䞊ã¹æ¿ããããšã¯ã§ããŸãã
Explainã®æ¬¡ã®æ å ±ã¯ãè¡ãã§ããããã¯ãPostgreSQLãè¿ãããšãã§ãããšèããããããã®è¡æ°ã§ãïŒããšãã°ãLIMITãããå Žåãããå°ãªãè¡ãè¿ãããšãã§ããŸãïŒãããã¯ãçµåãªã©ã®äžéšã®æäœã§ãéåžžã«éèŠã§ãïŒçµåïŒåèš20è¡ã®2ã€ã®ããŒãã«ã®çµåã¯ããŸããŸãªæ¹æ³ã§å®è¡ã§ããŸãããäžè¬çã«ã¯ã©ã¡ãã䜿çšããŠãããŸããŸãããã100äžè¡ã®ããŒãã«ãš10åè¡ã®ããŒãã«ãçµã¿åãããå Žåã¯ãè¡ãããšã¯éåžžã«éèŠã§ãïŒç§ã¯è©±ããŠãã å éšçµå/å·Šçµåã§ã¯ãªããããã·ã¥çµåããã¹ããããã«ãŒããããŒãžçµåã«é¢ãããã®ã§ãããã®å 容ãããããªãå Žåã¯å¿é ããªãã§ãåŸã§ãã¹ãŠèª¬æããŸãïŒã
ãã¡ããããã®æ°ã¯ããŸããŸãªçç±ã§èª€ã£ãŠæšå®ãããå¯èœæ§ããããŸãã æã ããã¯éèŠã§ã¯ãªããæã«ã¯ããã¯éèŠã§ãã ãããã誀ã£ãè©äŸ¡ã«ã€ããŠã¯åŸã§èª¬æããŸãã
æåŸã®æ å ±ã¯å¹ ã§ãã ããã¯ããã®æäœã®äžéšãšããŠè¿ãããåäžã®è¡ã«å«ãŸãããã€ãæ°ã®å¹³åçãªPostgreSQLã®æšå®å€ã§ãã äŸïŒ
explain select * from pg_class; QUERY PLAN ------------------------------------------------------------- Seq Scan on pg_class (cost=0.00..10.92 rows=292 width=202) (1 row) explain select relname, relkind from pg_class; QUERY PLAN ------------------------------------------------------------ Seq Scan on pg_class (cost=0.00..10.92 rows=292 width=65) (1 row)
ã芧ã®ãšããããã£ãŒã«ãæ°ã®å¶éã«ããå¹ ãå€æŽããããã®çµæããªã¯ãšã¹ãã®å®è¡ãééããå¿ èŠãããããŒã¿ã®éãå€æŽãããŸããã
ãããŠä»ã泚æãæãéèŠãªæ å ±ïŒèª¬æã¯æšã§ãã æäžäœããŒãã«ã¯ããã®äžã®ããŒãããã®ããŒã¿ãå¿ èŠã§ãã
ãã®èšç»ãèŠãŠã¿ãŸãããã
ãœãŒããããã·ã¥çµåãseqã¹ãã£ã³ãããã·ã¥ããããŠåã³seqã¹ãã£ã³ã®5ã€ã®æäœããããŸãã PostgreSQLã¯æäžäœã®æäœãå®è¡ããŸã-ãœãŒãã¯ããã®çŽäžã«ãã次ã®æäœïŒããã·ã¥çµåïŒãå®è¡ããããããããŒã¿ãåãåããŸãã ãœãŒãããããŒã¿ãè¿ãããã·ã¥çµåã§ã¯ãseq scanïŒpg_procã«ããïŒãšhashïŒïŒ4ïŒãå®è¡ããå¿ èŠããããŸãã æåŸã«ãããã·ã¥ã¯ãããŒã¿ãè¿ãããã«ãpg_namespaceã«ãã£ãŠseq scanãå®è¡ããå¿ èŠããããŸãã
äžéšã®æäœã§ã¯ãããŒã¿ãå³åº§ã«ããŸãã¯ããã«éèŠãªããšãšããŠåŸã ã«è¿ãããšãã§ããããšãç解ããããšãéåžžã«éèŠã§ãã ããšãã°ãSeq Scanã ãããŠãããã€ãã¯ã§ããŸããã ããšãã°ãããã§ã¯ãããã·ã¥ïŒïŒ4ïŒã®åæãªãŒããŒããããããã¹ãŠã®è¡ãã®ããµããªãã¬ãŒã·ã§ã³ãã·ãŒã±ã³ã¹ã¹ãã£ã³ãšåãã§ããããšãããããŸãã ã€ãŸããããã·ã¥æäœãéå§ããã«ã¯ïŒå°ãªããšã1è¡è¿ãããšãã§ããããã«ïŒããã®ãµãæäœãããã¹ãŠã®è¡ãèªã¿åãå¿ èŠããããŸãã
ç·©ãããªæ¹è¡éšåã¯ãé¢æ°ã®äœæãéå§ãããšãã«ç¹ã«éèŠã«ãªããŸãã ãã®é¢æ°ãèŠãŠã¿ãŸãããïŒ
CREATE OR REPLACE FUNCTION public.test() RETURNS SETOF integer LANGUAGE plpgsql AS $function$ declare i int4; begin for i in 1..3 loop return next i; perform pg_sleep(1); end loop; return; end; $function$;
äœãããããªããŠãå¿é ããªãã§ãã ããã ãã®é¢æ°ã¯3è¡ãè¿ããŸããåè¡ã«ã¯1ã2ã3ã®æŽæ°ãå«ãŸããŸããéèŠãªããšã¯ãåè¡ãæ»ã£ãŠãã1ç§éã¹ãªãŒãç¶æ ã«ãªãããšã§ãã
ããã¯ãç§ãããã奜ããªãïŒ
select * from test();
çµæãåºããŸã§3ç§åŸ ããªããã°ãªããŸããã
ãããããã®ç¶æ³ã§åŸ©åž°ãåŸ ã€ã®ã«ã©ããããæéãããããŸããïŒ
select * from test() limit 1;
èŠãŠã¿ãŸãããïŒ
\timing Timing is on. select * from test() limit 1; test ------ 1 (1 row) Time: 3005.334 ms
åã3ç§ã ãªãã§ïŒ PL / pgSQLïŒããã³ãã¹ãŠã§ã¯ãªãã«ããŠãã»ãšãã©ã®PL / *èšèªïŒã¯éšåçãªçµæãè¿ãããšãã§ããªãããã§ãã ã次ãžæ»ããã®å©ããåããŠ-圌ãã¯ã§ããããã§ãããå®éã«ã¯ãã¹ãŠã®çµæã¯ãããã¡ã«ä¿åãããé¢æ°ã®å®è¡ãçµäºãããšãã«äžç·ã«è¿ãããŸãã
äžæ¹ããéåžžã®ãæäœã§ã¯éåžžãéšåçãªããŒã¿ãè¿ãããšãã§ããŸãã ããã¯ãé£ããããŒãã«ã§ã·ãŒã±ã³ã·ã£ã«ã¹ãã£ã³ãªã©ã®ç°¡åãªæäœãå®è¡ããå Žåã«èŠãããŸãã
create table t as select i as id, repeat('depesz', 100)::text as payload from generate_series(1,1000000) i;
ãã®è¡šã¯ããã瀺ããŠããŸãïŒ
explain analyze select * from t; QUERY PLAN ---------------------------------------------------------------------------------------------------------------- Seq Scan on t (cost=0.00..185834.82 rows=10250082 width=36) (actual time=0.015..232.380 rows=1000000 loops=1) Total runtime: 269.666 ms (2 rows) explain analyze select * from t limit 1; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Limit (cost=0.00..0.02 rows=1 width=36) (actual time=0.003..0.003 rows=1 loops=1) -> Seq Scan on t (cost=0.00..185834.82 rows=10250082 width=36) (actual time=0.003..0.003 rows=1 loops=1) Total runtime: 0.016 ms (3 rows)
ïŒãããŸã§ã¯ãåèšã©ã³ã¿ã€ã ïŒ..ãã®ã¿ãã芧ãã ããïŒ
ã芧ã®ãšãããã·ãŒã±ã³ã·ã£ã«ã¹ãã£ã³ã¯éåžžã«è¿ éã«çµäºããŸãã-LIMITé£æ¬²ãã¡ããã©1è¡ã§æºãããããšããã«ã
ããã§ããªãŒããŒãããïŒã¯ãšãªãæ¯èŒããããã®æè¯ã®åºæºã§ã¯ãªãïŒã§ãããæäžäœããŒãïŒæåã®ã¯ãšãªã§ã®seqã¹ãã£ã³ãš2çªç®ã®å¶éïŒããã¹ãŠã®è¡ãè¿ãããã®å€ãéåžžã«ç°ãªãããšã瀺ããŠããããšã«æ³šæããŠãã ãã-185834.82察0.02
ãããã£ãŠãä»»æã®æäœã®æåã®4ã€ã®æ°å€ïŒ2ã€ã®ã³ã¹ãèŠç©ãããè¡æ°ãšå¹ ïŒã¯è¿äŒŒå€ã§ãã ãããã¯æ£ããå Žåãšããã§ãªãå ŽåããããŸãã
ãEXPLAIN ANALYZEã¯ãšãªããŸãã¯ãEXPLAINïŒANALYZE onïŒã¯ãšãªããå®è¡ãããšåŸãããä»ã®4ã€ã®æ°å€ã¯ãå®éã®çµæã瀺ããŠããŸãã
æéã¯ãŸã ç¯å²ã§ç€ºãããŸãããä»åã¯ãªã¢ã«ã¿ã€ã ã§ãã ããã¯ãPostgreSQLããã®æäœã®åŠçã«è²»ãããæéã§ãïŒåãæäœãäœåºŠãå®è¡ããå¯èœæ§ãããããïŒã ã³ã¹ããšåæ§ã«ãæéã¯ç¯å²ã§è¡šãããŸããæäœãéå§ããæéãšãã¹ãŠã®ããŒã¿ãè¿ãæéã§ãã ãã®èšç»ã確èªããŸãããïŒ
$ explain analyze select * from t limit 100; QUERY PLAN -------------------------------------------------------------------------------------------------------------- Limit (cost=0.00..9.33 rows=100 width=608) (actual time=0.008..0.152 rows=100 loops=1) -> Seq Scan on t (cost=0.00..93333.86 rows=999986 width=608) (actual time=0.007..0.133 rows=100 loops=1) Total runtime: 0.181 ms (3 rows)
ã芧ã®ãšãããLimitã®æäœéå§æéã¯0.008ã§ãïŒããã§ã®æž¬å®åäœã¯ããªç§ã§ãïŒã ããã¯ãSeqã¹ãã£ã³ïŒããŒã¿ãååŸããããã«LimitãåŒã³åºãïŒãæåã®è¡ãè¿ãã®ã«0.007msãããããã®åŸãããã«0.001msãå¶éå ã§åŠçãéå§ããããã«çºçããŸãã
ããã«ïŒæåã®è¡ãæ»ã£ãåŸïŒã100è¡ãåä¿¡ãããŸã§ãå¶éã¯Seqã¹ãã£ã³ããããŒã¿ãåä¿¡ãç¶ããŸããã ãã®åŸã圌ã¯ã·ãŒã±ã³ã·ã£ã«ã¹ãã£ã³ãåæ¢ãïŒããã¯ãªã¯ãšã¹ãã®éå§ãã0.133msåŸã«èµ·ãããŸããïŒãããã«0.019msåŸã«çµäºããŸããã
ååã瀺ãããã«ãå®éã®è¡æ°ã¯ããã®æäœã§è¿ãããïŒå¹³åïŒè¡æ°ã瀺ããŸãã ã«ãŒãã¯ããã®æäœãå®è¡ãããåæ°ã瀺ããŸãã
ã©ã®å Žåãæäœã¯è€æ°ååŒã³åºãããŸããïŒ ããšãã°ãå Žåã«ãã£ãŠã¯ãçµåã¯ãšãªãŸãã¯ãã¹ããããã¯ãšãªã䜿çšããŸãã ãã®èšç»ã®ããã«ãªããŸãã
3çªç®ã®æäœã§ã¯2ãµã€ã¯ã«ãããªãããšã«æ³šæããŠãã ããã ã€ãŸãããã®seqã¹ãã£ã³ã¯2åå®è¡ãããå¹³åã§1è¡ãè¿ãããå¹³åã§0.160msãå¿ èŠã§ããã ãããã£ãŠããã®ç¹å®ã®æäœã«è²»ããããåèšæéïŒ2 * 0.160ms = 0.32msïŒexplain.depesz.comã®æä»ç/å æ¬çåã«ç€ºãããŠããããã«ïŒã
éåžžã«å€ãã®å Žåãã¯ãšãªã®ããã©ãŒãã³ã¹ãäœãã®ã¯ãäœããã®ãµãã¯ãšãªãäœåºŠãç¹°ãè¿ãå¿ èŠãããããã§ãã ããšãã°ã次ã®ããã«ãªããŸã ã
ïŒãã¡ãããããã¯ããã®ãããªèšç»ãéžãã postgresããã¹ãŠã責ããããšãæå³ãããã®ã§ã¯ãããŸããããããããä»ã«éžæè¢ããªãã£ãããããã«ã³ã¹ããé«ãããšãå€æããã®ã§ãããïŒã
äžèšã®äŸã§ã¯ãæäœ3ã®å®éã®æéã¯ããã0.003msã§ããããã®æäœã¯26,000å以äžå®è¡ãããæçµçã«ã»ãŒ79msã®æéãè²»ãããããšããäºå®ã«æ³šæãã䟡å€ããããŸãã
ããã¯ãexplain'ovãèªãã®ã«å¿ èŠãªçè«çãªæ å ±ã ãšæããŸãã ã»ãšãã©ã®å Žåãæäœããã®ä»ã®æ å ±ã®æå³ã¯ãŸã ããããŸããããå°ãªããšãæ°åã®æå³ãšèª¬æã®éãã¯ããããŸãïŒã©ã³ãã ãªæŠç®ã«åºã¥ããŠæœè±¡çãªæž¬å®åäœã§ã³ã¹ãã衚瀺ãããŸãïŒ ïŒäŸïŒããã³åæã®èª¬æïŒå®éã®æéãè¡æ°ãå®è¡æéã枬å®åäœã§è¡šç€ºããç°ãªãã¯ãšãªãæ¯èŒã§ããããã«ããŸãïŒã
ãã€ãã®ããã«ãéèŠãªããšãããããéããã®ã§ã¯ãªãããšå¿é ããŠããŸãããç®ãåŒãããšã¯ã§ããŸããã§ããããŸãã¯ïŒããã«æªãããšã«ïŒãããããèªæãã ãšèããŸããã äœãäžè¶³ããŠãããšæãããå Žåã¯ãç¥ãããã ããããã¿ããã«ã®ã£ãããåããããšããŸãã
ãã ãããã®ããã¹ããããã«2ã3åã®åºçç©ã§éçºããäºå®ã§ãããããã«è©³ãã説æããŸãã
- æäœãäœã§ããããã©ã®ããã«æ©èœããããExplainåºåã§ããããèŠããšãã«äœãæåŸ ããã
- çµ±èšãšã¯ãPgãããããååŸããæ¹æ³ããããã衚瀺ããæ¹æ³ãããã³ããããæ倧éã«æŽ»çšããæ¹æ³ã§ãã
ãã®èšäºãã圹ã«ç«ãŠã°å¹žãã§ãã 賌èªããåºçç©ã«åŸã£ãŠãã ããã ããã«ããã°ã§æ¬¡ã®ãšããœãŒãã®ç¿»èš³ããããŸãïŒ ãã€ãã®ããã«ããã£ãŒãããã¯ãææ¡ããæ°è»œã«ãå¯ããã ããã æãèå³æ·±ãã®ã¯ã次ã®PG Day'16ãã·ã¢ã®ããã°ã©ã ã«å«ãŸããŸãïŒ :)