In the stats test, delay for the stats collector to catch up using a

function that actually sleeps, instead of busy-waiting.  Perhaps this
will resolve some of the intermittent stats failures we keep seeing.
This commit is contained in:
Tom Lane 2005-07-23 14:18:57 +00:00
parent 5ddeffb676
commit 6c61b0d93c
5 changed files with 42 additions and 44 deletions

View File

@ -24,17 +24,6 @@ SELECT t.seq_scan, t.seq_tup_read, t.idx_scan, t.idx_tup_fetch,
-- enable statistics
SET stats_block_level = on;
SET stats_row_level = on;
-- helper function
CREATE FUNCTION sleep(interval) RETURNS integer AS '
DECLARE
endtime timestamp;
BEGIN
endtime := timeofday()::timestamp + $1;
WHILE timeofday()::timestamp < endtime LOOP
END LOOP;
RETURN 0;
END;
' LANGUAGE 'plpgsql';
-- do something
SELECT count(*) FROM tenk2;
count
@ -49,10 +38,10 @@ SELECT count(*) FROM tenk2 WHERE unique1 = 1;
(1 row)
-- let stats collector catch up
SELECT sleep('0:0:2'::interval);
sleep
-------
0
SELECT do_sleep(2);
do_sleep
----------
(1 row)
-- check effects
@ -76,6 +65,4 @@ SELECT st.heap_blks_read + st.heap_blks_hit >= pr.heap_blks + cl.relpages,
t | t
(1 row)
-- clean up
DROP FUNCTION sleep(interval);
-- End of Stats Test

View File

@ -5,22 +5,22 @@
CREATE FUNCTION widget_in(cstring)
RETURNS widget
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'c';
LANGUAGE 'C' STRICT;
CREATE FUNCTION widget_out(widget)
RETURNS cstring
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'c';
LANGUAGE 'C' STRICT;
CREATE FUNCTION int44in(cstring)
RETURNS city_budget
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'c';
LANGUAGE 'C' STRICT;
CREATE FUNCTION int44out(city_budget)
RETURNS cstring
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'c';
LANGUAGE 'C' STRICT;
CREATE FUNCTION check_primary_key ()
RETURNS trigger
@ -50,7 +50,12 @@ CREATE FUNCTION ttdummy ()
CREATE FUNCTION set_ttdummy (int4)
RETURNS int4
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'C';
LANGUAGE 'C' STRICT;
CREATE FUNCTION do_sleep (int4)
RETURNS void
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'C' STRICT;
-- Things that shouldn't work:

View File

@ -4,24 +4,24 @@
CREATE FUNCTION widget_in(cstring)
RETURNS widget
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'c';
LANGUAGE 'C' STRICT;
NOTICE: type "widget" is not yet defined
DETAIL: Creating a shell type definition.
CREATE FUNCTION widget_out(widget)
RETURNS cstring
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'c';
LANGUAGE 'C' STRICT;
NOTICE: argument type widget is only a shell
CREATE FUNCTION int44in(cstring)
RETURNS city_budget
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'c';
LANGUAGE 'C' STRICT;
NOTICE: type "city_budget" is not yet defined
DETAIL: Creating a shell type definition.
CREATE FUNCTION int44out(city_budget)
RETURNS cstring
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'c';
LANGUAGE 'C' STRICT;
NOTICE: argument type city_budget is only a shell
CREATE FUNCTION check_primary_key ()
RETURNS trigger
@ -46,7 +46,11 @@ CREATE FUNCTION ttdummy ()
CREATE FUNCTION set_ttdummy (int4)
RETURNS int4
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'C';
LANGUAGE 'C' STRICT;
CREATE FUNCTION do_sleep (int4)
RETURNS void
AS '@abs_builddir@/regress@DLSUFFIX@'
LANGUAGE 'C' STRICT;
-- Things that shouldn't work:
CREATE FUNCTION test1 (int) RETURNS int LANGUAGE sql
AS 'SELECT ''not an integer'';';

View File

@ -1,5 +1,5 @@
/*
* $PostgreSQL: pgsql/src/test/regress/regress.c,v 1.62 2004/10/21 19:28:36 tgl Exp $
* $PostgreSQL: pgsql/src/test/regress/regress.c,v 1.63 2005/07/23 14:18:56 tgl Exp $
*/
#include "postgres.h"
@ -26,6 +26,8 @@ extern char *reverse_name(char *string);
extern int oldstyle_length(int n, text *t);
extern Datum int44in(PG_FUNCTION_ARGS);
extern Datum int44out(PG_FUNCTION_ARGS);
extern Datum do_sleep(PG_FUNCTION_ARGS);
/*
* Distance from a point to a path
@ -733,3 +735,18 @@ int44out(PG_FUNCTION_ARGS)
*--walk = '\0';
PG_RETURN_CSTRING(result);
}
/*
* do_sleep - delay for N seconds
*/
PG_FUNCTION_INFO_V1(do_sleep);
Datum
do_sleep(PG_FUNCTION_ARGS)
{
int32 secs = PG_GETARG_INT32(0);
pg_usleep(secs * 1000000L);
PG_RETURN_VOID();
}

View File

@ -24,24 +24,12 @@ SELECT t.seq_scan, t.seq_tup_read, t.idx_scan, t.idx_tup_fetch,
SET stats_block_level = on;
SET stats_row_level = on;
-- helper function
CREATE FUNCTION sleep(interval) RETURNS integer AS '
DECLARE
endtime timestamp;
BEGIN
endtime := timeofday()::timestamp + $1;
WHILE timeofday()::timestamp < endtime LOOP
END LOOP;
RETURN 0;
END;
' LANGUAGE 'plpgsql';
-- do something
SELECT count(*) FROM tenk2;
SELECT count(*) FROM tenk2 WHERE unique1 = 1;
-- let stats collector catch up
SELECT sleep('0:0:2'::interval);
SELECT do_sleep(2);
-- check effects
SELECT st.seq_scan >= pr.seq_scan + 1,
@ -55,7 +43,4 @@ SELECT st.heap_blks_read + st.heap_blks_hit >= pr.heap_blks + cl.relpages,
FROM pg_statio_user_tables AS st, pg_class AS cl, prevstats AS pr
WHERE st.relname='tenk2' AND cl.relname='tenk2';
-- clean up
DROP FUNCTION sleep(interval);
-- End of Stats Test