diff --git a/GNUmakefile.in b/GNUmakefile.in index 65cf158d507d7f3b4c647c728b2e50f45b45998b..b9e22fccd34ffca7c4e92cbb6fcc258ff79599d4 100644 --- a/GNUmakefile.in +++ b/GNUmakefile.in @@ -11,6 +11,7 @@ include $(top_builddir)/src/Makefile.global $(call recurse,all install,src config) all: + $(MAKE) -C contrib/auto_explain all $(MAKE) -C contrib/file_fdw all $(MAKE) -C contrib/formatter all $(MAKE) -C contrib/formatter_fixedwidth all @@ -44,6 +45,7 @@ html man: $(MAKE) -C doc $@ install: + $(MAKE) -C contrib/auto_explain $@ #$(MAKE) -C contrib/file_fdw $@ # GPDB_91_MERGE_FIXME: disable installation until it's officially supported. $(MAKE) -C contrib/formatter $@ $(MAKE) -C contrib/formatter_fixedwidth $@ @@ -139,6 +141,7 @@ $(call recurse,installcheck-world, \ src/test/ \ src/pl \ src/interfaces/gppc \ + contrib/auto_explain \ contrib/formatter_fixedwidth \ contrib/extprotocol \ contrib/dblink \ diff --git a/contrib/auto_explain/Makefile b/contrib/auto_explain/Makefile index 2d1443fe48e260eb6bed64c2c9f65f49f2aade58..dafac97bb53cbd0e11cbe9baf6a97ee7f6f69fc6 100644 --- a/contrib/auto_explain/Makefile +++ b/contrib/auto_explain/Makefile @@ -3,6 +3,9 @@ MODULE_big = auto_explain OBJS = auto_explain.o +REGRESS = auto_explain +REGRESS_OPTS = --init-file=init_file + ifdef USE_PGXS PG_CONFIG = pg_config PGXS := $(shell $(PG_CONFIG) --pgxs) diff --git a/contrib/auto_explain/expected/auto_explain.out b/contrib/auto_explain/expected/auto_explain.out new file mode 100644 index 0000000000000000000000000000000000000000..f92148d9526a5fb0e6398a08fa36728a6975ca86 --- /dev/null +++ b/contrib/auto_explain/expected/auto_explain.out @@ -0,0 +1,92 @@ +SET CLIENT_MIN_MESSAGES = LOG; +LOAD 'auto_explain'; +LOG: statement: LOAD 'auto_explain'; +SET auto_explain.log_analyze = TRUE; +LOG: statement: SET auto_explain.log_analyze = TRUE; +SET auto_explain.log_min_duration = 0; +LOG: statement: SET auto_explain.log_min_duration = 0; +SET auto_explain.log_buffers = FALSE; +LOG: statement: SET auto_explain.log_buffers = FALSE; +SET auto_explain.log_triggers = TRUE; +LOG: statement: SET auto_explain.log_triggers = TRUE; +SET auto_explain.log_nested_statements = FALSE; +LOG: statement: SET auto_explain.log_nested_statements = FALSE; +SET auto_explain.log_timing = FALSE; +LOG: statement: SET auto_explain.log_timing = FALSE; +SET auto_explain.log_verbose = FALSE; +LOG: statement: SET auto_explain.log_verbose = FALSE; +SELECT relname FROM pg_class WHERE relname='pg_class'; +LOG: statement: SELECT relname FROM pg_class WHERE relname='pg_class'; +LOG: duration: 0.198 ms plan: +Query Text: SELECT relname FROM pg_class WHERE relname='pg_class'; +Seq Scan on pg_class (cost=0.00..11.46 rows=1 width=64) (actual rows=1 loops=1) + Filter: (relname = 'pg_class'::name) + Rows Removed by Filter: 436 + (slice0) Executor memory: 32K bytes. +Memory used: 128000kB + relname +---------- + pg_class +(1 row) + +SELECT count(*)>0 FROM pg_class, pg_index WHERE oid = indrelid AND indisunique; +LOG: statement: SELECT count(*)>0 FROM pg_class, pg_index WHERE oid = indrelid AND indisunique; +LOG: duration: 5.369 ms plan: +Query Text: SELECT count(*)>0 FROM pg_class, pg_index WHERE oid = indrelid AND indisunique; +Aggregate (cost=19.62..19.64 rows=1 width=1) (actual rows=1 loops=1) + -> Hash Join (cost=4.29..19.29 rows=135 width=0) (actual rows=135 loops=1) + Hash Cond: (pg_class.oid = pg_index.indrelid) + Extra Text: Hash chain length 1.5 avg, 3 max, using 91 of 524288 buckets. + -> Seq Scan on pg_class (cost=0.00..10.37 rows=437 width=4) (actual rows=437 loops=1) + -> Hash (cost=2.60..2.60 rows=45 width=4) (actual rows=135 loops=1) + Buckets: 524288 Batches: 1 Memory Usage: 4kB + -> Seq Scan on pg_index (cost=0.00..2.60 rows=135 width=4) (actual rows=135 loops=1) + Filter: indisunique + Rows Removed by Filter: 25 + (slice0) Executor memory: 4177K bytes. Work_mem: 4K bytes max. +Memory used: 128000kB + ?column? +---------- + t +(1 row) + +SET auto_explain.log_min_duration = 1; +LOG: statement: SET auto_explain.log_min_duration = 1; +SET auto_explain.log_triggers = FALSE; +LOG: statement: SET auto_explain.log_triggers = FALSE; +SET auto_explain.log_verbose = TRUE; +LOG: statement: SET auto_explain.log_verbose = TRUE; +SELECT relname FROM pg_class WHERE relname='pg_class'; +LOG: statement: SELECT relname FROM pg_class WHERE relname='pg_class'; + relname +---------- + pg_class +(1 row) + +SELECT count(*)>0 FROM pg_class, pg_index WHERE oid = indrelid AND indisunique; +LOG: statement: SELECT count(*)>0 FROM pg_class, pg_index WHERE oid = indrelid AND indisunique; +LOG: duration: 4.530 ms plan: +Query Text: SELECT count(*)>0 FROM pg_class, pg_index WHERE oid = indrelid AND indisunique; +Aggregate (cost=19.62..19.64 rows=1 width=1) (actual rows=1 loops=1) + Output: (count(*) > 0) + -> Hash Join (cost=4.29..19.29 rows=135 width=0) (actual rows=135 loops=1) + Hash Cond: (pg_class.oid = pg_index.indrelid) + Executor Memory: 4kB Segments: 1 Max: 4kB (segment -1) + work_mem: 4kB Segments: 1 Max: 4kB (segment -1) Workfile: (0 spilling) + Extra Text: Hash chain length 1.5 avg, 3 max, using 91 of 524288 buckets. + -> Seq Scan on pg_catalog.pg_class (cost=0.00..10.37 rows=437 width=4) (actual rows=437 loops=1) + Output: pg_class.oid + -> Hash (cost=2.60..2.60 rows=45 width=4) (actual rows=135 loops=1) + Output: pg_index.indrelid + Buckets: 524288 Batches: 1 Memory Usage: 4kB + -> Seq Scan on pg_catalog.pg_index (cost=0.00..2.60 rows=135 width=4) (actual rows=135 loops=1) + Output: pg_index.indrelid + Filter: pg_index.indisunique + Rows Removed by Filter: 25 + (slice0) Executor memory: 4177K bytes. Work_mem: 4K bytes max. +Memory used: 128000kB + ?column? +---------- + t +(1 row) + diff --git a/contrib/auto_explain/init_file b/contrib/auto_explain/init_file new file mode 100644 index 0000000000000000000000000000000000000000..59e0e156e89ec9d31d3a385a86a21a567f9faf70 --- /dev/null +++ b/contrib/auto_explain/init_file @@ -0,0 +1,31 @@ +-- start_matchsubs + +m/\(cost=[a-z_A-Z0-9. =]+\)\s+\([a-z_A-Z0-9. =]+\)/ +s/\(cost=[a-z_A-Z0-9. =]+\)\s+\([a-z_A-Z0-9. =]+\)// + +m/duration:.*$/ +s/duration:\s+[0-9.]+\s*ms.*/duration: ms/ + +m/Rows Removed by Filter: .*/ +s/Rows Removed by Filter: .*/Rows Removed by Filter: / + +m/Executor [mM]emory: .*/ +s/Executor [mM]emory: .*/Executor Memory: / + +m/Memory used:\s+[0-9kKmMgGB]+/ +s/Memory used:\s+[0-9kKmMgGB]+/Memory used:/ + +m/Buckets: [0-9]+\s+Batches: [0-9]+\s+Memory Usage:\s+[0-9kKmMgG]B/ +s/Buckets: [0-9]+\s+Batches: [0-9]+\s+Memory Usage:\s+[0-9kKmMgG]B/Buckets: 524288 Batches: 1 Memory Usage: 4kB/ + +m/Extra Text: Hash chain length [0-9.]+ avg, [0-9]+ max, using [0-9]+ of [0-9]+ buckets/ +s/Extra Text: Hash chain length [0-9.]+ avg, [0-9]+ max, using [0-9]+ of [0-9]+ buckets/Extra Text: Hash chain length 1.5 avg, 3 max, using 91 of 524288 buckets/ + +m/work_mem: [0-9kKmMgG]B Segments: [-0-9]+ Max: [0-9kKmMgG]+B.*/ +s/work_mem: [0-9kKmMgG]B Segments: [-0-9]+ Max: [0-9kKmMgG]+B.*/work_mem: 4kB Segments: 1 Max: 4kB/ +-- end_matchsubs + +-- start_matchignore +# orca failed to produce the expected plan, ignore this message +m/LOG: Planner produced plan :0/ +-- end_matchignore diff --git a/contrib/auto_explain/sql/auto_explain.sql b/contrib/auto_explain/sql/auto_explain.sql new file mode 100644 index 0000000000000000000000000000000000000000..087d37277d872201b5ea7ff054bd25283d271388 --- /dev/null +++ b/contrib/auto_explain/sql/auto_explain.sql @@ -0,0 +1,19 @@ +SET CLIENT_MIN_MESSAGES = LOG; +LOAD 'auto_explain'; +SET auto_explain.log_analyze = TRUE; +SET auto_explain.log_min_duration = 0; +SET auto_explain.log_buffers = FALSE; +SET auto_explain.log_triggers = TRUE; +SET auto_explain.log_nested_statements = FALSE; +SET auto_explain.log_timing = FALSE; +SET auto_explain.log_verbose = FALSE; + +SELECT relname FROM pg_class WHERE relname='pg_class'; +SELECT count(*)>0 FROM pg_class, pg_index WHERE oid = indrelid AND indisunique; + +SET auto_explain.log_min_duration = 1; +SET auto_explain.log_triggers = FALSE; +SET auto_explain.log_verbose = TRUE; + +SELECT relname FROM pg_class WHERE relname='pg_class'; +SELECT count(*)>0 FROM pg_class, pg_index WHERE oid = indrelid AND indisunique;