Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit60c87d4

Browse files
committed
Add wait function for background cleanup procedure. It makes
the cleanup_bgworker regression test much more stable:don't forget, that bgworker process needs time to start and make cleanoperations.We may do even better if will invent some cleanup tag and checking function.
1 parent5b21e68 commit60c87d4

File tree

2 files changed

+81
-25
lines changed

2 files changed

+81
-25
lines changed

‎expected/cleanup_bgworker.out

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,36 @@ AS (
88
CREATE INDEX aqo_test0_idx_a ON aqo_test0 (a);
99
ANALYZE aqo_test0;
1010
CREATE EXTENSION aqo;
11+
SELECT true FROM aqo_reset();
12+
?column?
13+
----------
14+
t
15+
(1 row)
16+
1117
SET aqo.join_threshold = 0;
1218
SET aqo.mode = 'learn';
1319
SET 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;
1441
EXPLAIN SELECT t1.a, t2.b FROM aqo_test0 AS t1, aqo_test0 AS t2
1542
WHERE t1.a < 1 AND t1.b < 1 AND t2.c < 1 AND t2.d < 1;
1643
QUERY PLAN
@@ -49,10 +76,11 @@ AS (
4976
) INSERT INTO aqo_test1 (SELECT * FROM t);
5077
CREATE INDEX aqo_test1_idx_a ON aqo_test1 (a);
5178
ANALYZE 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

5886
EXPLAIN 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

82111
DROP TABLE aqo_test1;
@@ -89,10 +118,11 @@ AS (
89118
) INSERT INTO aqo_test1 (SELECT * FROM t);
90119
CREATE INDEX aqo_test1_idx_a ON aqo_test1 (a);
91120
ANALYZE 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

98128
EXPLAIN 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

122153
DROP TABLE aqo_test0;
123154
DROP 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

130162
SET aqo.cleanup_bgworker = 'false';

‎sql/cleanup_bgworker.sql

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,33 @@ CREATE INDEX aqo_test0_idx_a ON aqo_test0 (a);
99
ANALYZE aqo_test0;
1010

1111
CREATE EXTENSION aqo;
12+
SELECT trueFROM aqo_reset();
1213
SETaqo.join_threshold=0;
1314
SETaqo.mode='learn';
1415
SETaqo.cleanup_bgworker='true';
1516

17+
CREATE OR REPLACEFUNCTIONwait_bgworker(valueint, timeout_msint)
18+
RETURNS void
19+
AS $$
20+
DECLARE
21+
cntint;
22+
endtimetimestamp;
23+
curtimetimestamp;
24+
BEGIN
25+
SELECT now()+ make_interval(secs := timeout_ms*1000) INTO endtime;
26+
SELECTcount(*)FROM aqo_queries INTO cnt;
27+
WHILE (cnt<> value) LOOP
28+
SELECTcount(*)FROM aqo_queries INTO cnt;
29+
SELECT now() INTO curtime;
30+
IF (curtime> endtime) THEN
31+
raise EXCEPTION'Wait inturrupted because of timeout';
32+
EXIT;
33+
END IF;
34+
END LOOP;
35+
raise NOTICE'Successful AQO cleanup of bgworker process';
36+
END;
37+
$$ LANGUAGE PLPGSQL VOLATILE;
38+
1639
EXPLAINSELECTt1.a,t2.bFROM aqo_test0AS t1, aqo_test0AS t2
1740
WHEREt1.a<1ANDt1.b<1ANDt2.c<1ANDt2.d<1;
1841

@@ -40,7 +63,7 @@ AS (
4063
CREATEINDEXaqo_test1_idx_aON aqo_test1 (a);
4164
ANALYZE aqo_test1;
4265

43-
SELECTcount(*)FROM aqo_queries;
66+
SELECTwait_bgworker(1,100);
4467

4568
EXPLAINSELECT*FROM aqo_test0
4669
WHERE a<3AND b<3AND c<3AND d<3;
@@ -49,7 +72,7 @@ EXPLAIN SELECT * FROM aqo_test1
4972
WHERE a<4AND b<4;
5073

5174
-- Test2: Must delete 1 out of 2 entries
52-
SELECTcount(*)FROM aqo_queries;
75+
SELECTwait_bgworker(3,100);
5376
DROPTABLE aqo_test1;
5477

5578
CREATETABLEIF NOT EXISTS aqo_test1(aint, bint);
@@ -62,7 +85,7 @@ AS (
6285
CREATEINDEXaqo_test1_idx_aON aqo_test1 (a);
6386
ANALYZE aqo_test1;
6487

65-
SELECTcount(*)FROM aqo_queries;
88+
SELECTwait_bgworker(1,100);
6689

6790
EXPLAINSELECT*FROM aqo_test0
6891
WHERE a<3AND b<3AND c<3AND d<3;
@@ -71,10 +94,11 @@ EXPLAIN SELECT * FROM aqo_test1
7194
WHERE a<4AND b<4;
7295

7396
-- Test3: delete 2 out of 2 entries
74-
SELECTcount(*)FROM aqo_queries;
97+
SELECTwait_bgworker(3,100);
7598
DROPTABLE aqo_test0;
7699
DROPTABLE aqo_test1;
77-
SELECTcount(*)FROM aqo_queries;
100+
101+
SELECT wait_bgworker(1,100);
78102

79103
SETaqo.cleanup_bgworker='false';
80104
DROP EXTENSION aqo;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp