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

Commit6c61b0d

Browse files
committed
In the stats test, delay for the stats collector to catch up using a
function that actually sleeps, instead of busy-waiting. Perhaps thiswill resolve some of the intermittent stats failures we keep seeing.
1 parent5ddeffb commit6c61b0d

File tree

5 files changed

+42
-44
lines changed

5 files changed

+42
-44
lines changed

‎src/test/regress/expected/stats.out

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,6 @@ SELECT t.seq_scan, t.seq_tup_read, t.idx_scan, t.idx_tup_fetch,
2424
-- enable statistics
2525
SET stats_block_level = on;
2626
SET stats_row_level = on;
27-
-- helper function
28-
CREATE FUNCTION sleep(interval) RETURNS integer AS '
29-
DECLARE
30-
endtime timestamp;
31-
BEGIN
32-
endtime := timeofday()::timestamp + $1;
33-
WHILE timeofday()::timestamp < endtime LOOP
34-
END LOOP;
35-
RETURN 0;
36-
END;
37-
' LANGUAGE 'plpgsql';
3827
-- do something
3928
SELECT count(*) FROM tenk2;
4029
count
@@ -49,10 +38,10 @@ SELECT count(*) FROM tenk2 WHERE unique1 = 1;
4938
(1 row)
5039

5140
-- let stats collector catch up
52-
SELECTsleep('0:0:2'::interval);
53-
sleep
54-
-------
55-
0
41+
SELECTdo_sleep(2);
42+
do_sleep
43+
----------
44+
5645
(1 row)
5746

5847
-- check effects
@@ -76,6 +65,4 @@ SELECT st.heap_blks_read + st.heap_blks_hit >= pr.heap_blks + cl.relpages,
7665
t | t
7766
(1 row)
7867

79-
-- clean up
80-
DROP FUNCTION sleep(interval);
8168
-- End of Stats Test

‎src/test/regress/input/create_function_1.source

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
CREATE FUNCTION widget_in(cstring)
66
RETURNS widget
77
AS '@abs_builddir@/regress@DLSUFFIX@'
8-
LANGUAGE 'c';
8+
LANGUAGE 'C' STRICT;
99

1010
CREATE FUNCTION widget_out(widget)
1111
RETURNS cstring
1212
AS '@abs_builddir@/regress@DLSUFFIX@'
13-
LANGUAGE 'c';
13+
LANGUAGE 'C' STRICT;
1414

1515
CREATE FUNCTION int44in(cstring)
1616
RETURNS city_budget
1717
AS '@abs_builddir@/regress@DLSUFFIX@'
18-
LANGUAGE 'c';
18+
LANGUAGE 'C' STRICT;
1919

2020
CREATE FUNCTION int44out(city_budget)
2121
RETURNS cstring
2222
AS '@abs_builddir@/regress@DLSUFFIX@'
23-
LANGUAGE 'c';
23+
LANGUAGE 'C' STRICT;
2424

2525
CREATE FUNCTION check_primary_key ()
2626
RETURNS trigger
@@ -50,7 +50,12 @@ CREATE FUNCTION ttdummy ()
5050
CREATE FUNCTION set_ttdummy (int4)
5151
RETURNS int4
5252
AS '@abs_builddir@/regress@DLSUFFIX@'
53-
LANGUAGE 'C';
53+
LANGUAGE 'C' STRICT;
54+
55+
CREATE FUNCTION do_sleep (int4)
56+
RETURNS void
57+
AS '@abs_builddir@/regress@DLSUFFIX@'
58+
LANGUAGE 'C' STRICT;
5459

5560
-- Things that shouldn't work:
5661

‎src/test/regress/output/create_function_1.source

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@
44
CREATE FUNCTION widget_in(cstring)
55
RETURNS widget
66
AS '@abs_builddir@/regress@DLSUFFIX@'
7-
LANGUAGE 'c';
7+
LANGUAGE 'C' STRICT;
88
NOTICE: type "widget" is not yet defined
99
DETAIL: Creating a shell type definition.
1010
CREATE FUNCTION widget_out(widget)
1111
RETURNS cstring
1212
AS '@abs_builddir@/regress@DLSUFFIX@'
13-
LANGUAGE 'c';
13+
LANGUAGE 'C' STRICT;
1414
NOTICE: argument type widget is only a shell
1515
CREATE FUNCTION int44in(cstring)
1616
RETURNS city_budget
1717
AS '@abs_builddir@/regress@DLSUFFIX@'
18-
LANGUAGE 'c';
18+
LANGUAGE 'C' STRICT;
1919
NOTICE: type "city_budget" is not yet defined
2020
DETAIL: Creating a shell type definition.
2121
CREATE FUNCTION int44out(city_budget)
2222
RETURNS cstring
2323
AS '@abs_builddir@/regress@DLSUFFIX@'
24-
LANGUAGE 'c';
24+
LANGUAGE 'C' STRICT;
2525
NOTICE: argument type city_budget is only a shell
2626
CREATE FUNCTION check_primary_key ()
2727
RETURNS trigger
@@ -46,7 +46,11 @@ CREATE FUNCTION ttdummy ()
4646
CREATE FUNCTION set_ttdummy (int4)
4747
RETURNS int4
4848
AS '@abs_builddir@/regress@DLSUFFIX@'
49-
LANGUAGE 'C';
49+
LANGUAGE 'C' STRICT;
50+
CREATE FUNCTION do_sleep (int4)
51+
RETURNS void
52+
AS '@abs_builddir@/regress@DLSUFFIX@'
53+
LANGUAGE 'C' STRICT;
5054
-- Things that shouldn't work:
5155
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE sql
5256
AS 'SELECT ''not an integer'';';

‎src/test/regress/regress.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* $PostgreSQL: pgsql/src/test/regress/regress.c,v 1.62 2004/10/21 19:28:36 tgl Exp $
2+
* $PostgreSQL: pgsql/src/test/regress/regress.c,v 1.63 2005/07/23 14:18:56 tgl Exp $
33
*/
44

55
#include"postgres.h"
@@ -26,6 +26,8 @@ extern char *reverse_name(char *string);
2626
externintoldstyle_length(intn,text*t);
2727
externDatumint44in(PG_FUNCTION_ARGS);
2828
externDatumint44out(PG_FUNCTION_ARGS);
29+
externDatumdo_sleep(PG_FUNCTION_ARGS);
30+
2931

3032
/*
3133
* Distance from a point to a path
@@ -733,3 +735,18 @@ int44out(PG_FUNCTION_ARGS)
733735
*--walk='\0';
734736
PG_RETURN_CSTRING(result);
735737
}
738+
739+
/*
740+
* do_sleep - delay for N seconds
741+
*/
742+
PG_FUNCTION_INFO_V1(do_sleep);
743+
744+
Datum
745+
do_sleep(PG_FUNCTION_ARGS)
746+
{
747+
int32secs=PG_GETARG_INT32(0);
748+
749+
pg_usleep(secs*1000000L);
750+
751+
PG_RETURN_VOID();
752+
}

‎src/test/regress/sql/stats.sql

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,12 @@ SELECT t.seq_scan, t.seq_tup_read, t.idx_scan, t.idx_tup_fetch,
2424
SET stats_block_level=on;
2525
SET stats_row_level=on;
2626

27-
-- helper function
28-
CREATEFUNCTIONsleep(interval) RETURNSintegerAS'
29-
DECLARE
30-
endtime timestamp;
31-
BEGIN
32-
endtime := timeofday()::timestamp + $1;
33-
WHILE timeofday()::timestamp < endtime LOOP
34-
END LOOP;
35-
RETURN 0;
36-
END;
37-
' LANGUAGE'plpgsql';
38-
3927
-- do something
4028
SELECTcount(*)FROM tenk2;
4129
SELECTcount(*)FROM tenk2WHERE unique1=1;
4230

4331
-- let stats collector catch up
44-
SELECTsleep('0:0:2'::interval);
32+
SELECTdo_sleep(2);
4533

4634
-- check effects
4735
SELECTst.seq_scan>=pr.seq_scan+1,
@@ -55,7 +43,4 @@ SELECT st.heap_blks_read + st.heap_blks_hit >= pr.heap_blks + cl.relpages,
5543
FROM pg_statio_user_tablesAS st, pg_classAS cl, prevstatsAS pr
5644
WHEREst.relname='tenk2'ANDcl.relname='tenk2';
5745

58-
-- clean up
59-
DROPFUNCTION sleep(interval);
60-
6146
-- End of Stats Test

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp