Skip to content

Commit 1149568

Browse files
Fix unstable case of auto_explain. (#1127)
This case rely on sql "SELECT relname FROM pg_class WHERE relname='pg_class';" could finish in 1ms. Debug build for some platform may fail. Add pg_sleep for sql to make sure running more than 1s. Signed-off-by: Dongxiao Song <songdongxiao@hashdata.cn>
1 parent 94a8176 commit 1149568

3 files changed

Lines changed: 20 additions & 20 deletions

File tree

contrib/auto_explain/expected/auto_explain.out

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ Memory used: 128000kB
6868
1002001
6969
(1 row)
7070

71-
SET auto_explain.log_min_duration = 1;
72-
LOG: statement: SET auto_explain.log_min_duration = 1;
71+
SET auto_explain.log_min_duration = 1000;
72+
LOG: statement: SET auto_explain.log_min_duration = 1000;
7373
SET auto_explain.log_triggers = FALSE;
7474
LOG: statement: SET auto_explain.log_triggers = FALSE;
7575
SET auto_explain.log_verbose = TRUE;
@@ -83,12 +83,12 @@ LOG: statement: SELECT relname FROM pg_class WHERE relname='pg_class';
8383
(1 row)
8484

8585
-- this select should also dump plan, since it takes too much time to run
86-
SELECT count(*) FROM auto_explain_test.t1, auto_explain_test.t2;
87-
LOG: statement: SELECT count(*) FROM auto_explain_test.t1, auto_explain_test.t2;
86+
SELECT count(*), pg_sleep(1) FROM auto_explain_test.t1, auto_explain_test.t2;
87+
LOG: statement: SELECT count(*), pg_sleep(1) FROM auto_explain_test.t1, auto_explain_test.t2;
8888
LOG: duration: 208.523 ms plan:
89-
Query Text: SELECT count(*) FROM auto_explain_test.t1, auto_explain_test.t2;
89+
Query Text: SELECT count(*), pg_sleep(1) FROM auto_explain_test.t1, auto_explain_test.t2;
9090
Finalize Aggregate (cost=35148.64..35148.65 rows=1 width=8) (actual rows=1 loops=1)
91-
Output: count(*)
91+
Output: count(*), pg_sleep('1'::double precision)
9292
-> Gather Motion 3:1 (slice1; segments: 3) (cost=35148.61..35148.64 rows=1 width=8) (actual rows=3 loops=1)
9393
Output: (PARTIAL count(*))
9494
-> Partial Aggregate (cost=35148.61..35148.62 rows=1 width=8) (actual rows=1 loops=1)
@@ -106,9 +106,9 @@ Settings: enable_nestloop = 'on', optimizer = 'off'
106106
(slice1) Executor memory: 152K bytes avg x 3 workers, 152K bytes max (seg0).
107107
(slice2) Executor memory: 42K bytes avg x 3 workers, 42K bytes max (seg0).
108108
Memory used: 128000kB
109-
count
110-
---------
111-
1002001
109+
count | pg_sleep
110+
---------+----------
111+
1002001 |
112112
(1 row)
113113

114114
-- clean jobs

contrib/auto_explain/expected/auto_explain_optimizer.out

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ Memory used: 128000kB
6767
1002001
6868
(1 row)
6969

70-
SET auto_explain.log_min_duration = 1;
71-
LOG: statement: SET auto_explain.log_min_duration = 1;
70+
SET auto_explain.log_min_duration = 1000;
71+
LOG: statement: SET auto_explain.log_min_duration = 1000;
7272
SET auto_explain.log_triggers = FALSE;
7373
LOG: statement: SET auto_explain.log_triggers = FALSE;
7474
SET auto_explain.log_verbose = TRUE;
@@ -83,12 +83,12 @@ LOG: statement: SELECT relname FROM pg_class WHERE relname='pg_class';
8383
(1 row)
8484

8585
-- this select should also dump plan, since it takes too much time to run
86-
SELECT count(*) FROM auto_explain_test.t1, auto_explain_test.t2;
87-
LOG: statement: SELECT count(*) FROM auto_explain_test.t1, auto_explain_test.t2;
86+
SELECT count(*), pg_sleep(1) FROM auto_explain_test.t1, auto_explain_test.t2;
87+
LOG: statement: SELECT count(*), pg_sleep(1) FROM auto_explain_test.t1, auto_explain_test.t2;
8888
LOG: duration: 180.126 ms plan:
89-
Query Text: SELECT count(*) FROM auto_explain_test.t1, auto_explain_test.t2;
89+
Query Text: SELECT count(*), pg_sleep(1) FROM auto_explain_test.t1, auto_explain_test.t2;
9090
Finalize Aggregate (cost=0.00..1326086.34 rows=1 width=8) (actual rows=1 loops=1)
91-
Output: count(*)
91+
Output: count(*), pg_sleep('1'::double precision)
9292
-> Gather Motion 3:1 (slice1; segments: 3) (cost=0.00..1326086.34 rows=1 width=8) (actual rows=3 loops=1)
9393
Output: (PARTIAL count(*))
9494
-> Partial Aggregate (cost=0.00..1326086.34 rows=1 width=8) (actual rows=1 loops=1)
@@ -103,9 +103,9 @@ Settings: enable_nestloop = 'on'
103103
(slice1) Executor memory: 119K bytes avg x 3 workers, 119K bytes max (seg0).
104104
(slice2) Executor memory: 42K bytes avg x 3 workers, 42K bytes max (seg0).
105105
Memory used: 128000kB
106-
count
107-
---------
108-
1002001
106+
count | pg_sleep
107+
---------+----------
108+
1002001 |
109109
(1 row)
110110

111111
-- clean jobs

contrib/auto_explain/sql/auto_explain.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ SET auto_explain.log_verbose = FALSE;
2525
SELECT relname FROM pg_class WHERE relname='pg_class';
2626
SELECT count(*) FROM auto_explain_test.t1, auto_explain_test.t2;
2727

28-
SET auto_explain.log_min_duration = 1;
28+
SET auto_explain.log_min_duration = 1000;
2929
SET auto_explain.log_triggers = FALSE;
3030
SET auto_explain.log_verbose = TRUE;
3131

3232
-- this select should not dump execution plan
3333
SELECT relname FROM pg_class WHERE relname='pg_class';
3434
-- this select should also dump plan, since it takes too much time to run
35-
SELECT count(*) FROM auto_explain_test.t1, auto_explain_test.t2;
35+
SELECT count(*), pg_sleep(1) FROM auto_explain_test.t1, auto_explain_test.t2;
3636

3737
-- clean jobs
3838
DROP TABLE auto_explain_test.t1;

0 commit comments

Comments
 (0)