88CREATE INDEX aqo_test0_idx_a ON aqo_test0 (a);
99ANALYZE aqo_test0;
1010CREATE EXTENSION aqo;
11+ SELECT true FROM aqo_reset();
12+ ?column?
13+ ----------
14+ t
15+ (1 row)
16+
1117SET aqo.join_threshold = 0;
1218SET aqo.mode = 'learn';
1319SET aqo.cleanup_bgworker = 'true';
20+ CREATE OR REPLACE FUNCTION wait_bgworker(value int, timeout_ms int)
21+ RETURNS void
22+ AS $$
23+ DECLARE
24+ cnt int;
25+ endtime timestamp;
26+ curtime timestamp;
27+ BEGIN
28+ SELECT now() + make_interval(secs := timeout_ms * 1000) INTO endtime;
29+ SELECT count(*) FROM aqo_queries INTO cnt;
30+ WHILE (cnt <> value) LOOP
31+ SELECT count(*) FROM aqo_queries INTO cnt;
32+ SELECT now() INTO curtime;
33+ IF (curtime > endtime) THEN
34+ raise EXCEPTION 'Wait inturrupted because of timeout';
35+ EXIT;
36+ END IF;
37+ END LOOP;
38+ raise NOTICE 'Successful AQO cleanup of bgworker process';
39+ END;
40+ $$ LANGUAGE PLPGSQL VOLATILE;
1441EXPLAIN SELECT t1.a, t2.b FROM aqo_test0 AS t1, aqo_test0 AS t2
1542WHERE t1.a < 1 AND t1.b < 1 AND t2.c < 1 AND t2.d < 1;
1643 QUERY PLAN
4976) INSERT INTO aqo_test1 (SELECT * FROM t);
5077CREATE INDEX aqo_test1_idx_a ON aqo_test1 (a);
5178ANALYZE aqo_test1;
52- SELECT count(*) FROM aqo_queries;
53- count
54- -------
55- 1
79+ SELECT wait_bgworker(1, 100);
80+ NOTICE: Successful AQO cleanup of bgworker process
81+ wait_bgworker
82+ ---------------
83+
5684(1 row)
5785
5886EXPLAIN SELECT * FROM aqo_test0
@@ -73,10 +101,11 @@ WHERE a < 4 AND b < 4;
73101(2 rows)
74102
75103-- Test2: Must delete 1 out of 2 entries
76- SELECT count(*) FROM aqo_queries;
77- count
78- -------
79- 3
104+ SELECT wait_bgworker(3, 100);
105+ NOTICE: Successful AQO cleanup of bgworker process
106+ wait_bgworker
107+ ---------------
108+
80109(1 row)
81110
82111DROP TABLE aqo_test1;
@@ -89,10 +118,11 @@ AS (
89118) INSERT INTO aqo_test1 (SELECT * FROM t);
90119CREATE INDEX aqo_test1_idx_a ON aqo_test1 (a);
91120ANALYZE aqo_test1;
92- SELECT count(*) FROM aqo_queries;
93- count
94- -------
95- 1
121+ SELECT wait_bgworker(1, 100);
122+ NOTICE: Successful AQO cleanup of bgworker process
123+ wait_bgworker
124+ ---------------
125+
96126(1 row)
97127
98128EXPLAIN SELECT * FROM aqo_test0
@@ -113,18 +143,20 @@ WHERE a < 4 AND b < 4;
113143(2 rows)
114144
115145-- Test3: delete 2 out of 2 entries
116- SELECT count(*) FROM aqo_queries;
117- count
118- -------
119- 3
146+ SELECT wait_bgworker(3, 100);
147+ NOTICE: Successful AQO cleanup of bgworker process
148+ wait_bgworker
149+ ---------------
150+
120151(1 row)
121152
122153DROP TABLE aqo_test0;
123154DROP TABLE aqo_test1;
124- SELECT count(*) FROM aqo_queries;
125- count
126- -------
127- 1
155+ SELECT wait_bgworker(1, 100);
156+ NOTICE: Successful AQO cleanup of bgworker process
157+ wait_bgworker
158+ ---------------
159+
128160(1 row)
129161
130162SET aqo.cleanup_bgworker = 'false';
0 commit comments