create function wait_for_stats() returns void as $$
declare
start_time timestamptz := clock_timestamp();
- updated bool;
+ updated1 bool;
+ updated2 bool;
+ updated3 bool;
begin
-- we don't want to wait forever; loop will exit after 30 seconds
for i in 1 .. 300 loop
+ -- With parallel query, the seqscan and indexscan on tenk2 might be done
+ -- in parallel worker processes, which will send their stats counters
+ -- asynchronously to what our own session does. So we must check for
+ -- those counts to be registered separately from the update counts.
+
+ -- check to see if seqscan has been sensed
+ SELECT (st.seq_scan >= pr.seq_scan + 1) INTO updated1
+ FROM pg_stat_user_tables AS st, pg_class AS cl, prevstats AS pr
+ WHERE st.relname='tenk2' AND cl.relname='tenk2';
+
-- check to see if indexscan has been sensed
- SELECT (st.idx_scan >= pr.idx_scan + 1) INTO updated
+ SELECT (st.idx_scan >= pr.idx_scan + 1) INTO updated2
FROM pg_stat_user_tables AS st, pg_class AS cl, prevstats AS pr
WHERE st.relname='tenk2' AND cl.relname='tenk2';
- exit when updated;
+ -- check to see if updates have been sensed
+ SELECT (n_tup_ins > 0) INTO updated3
+ FROM pg_stat_user_tables WHERE relname='trunc_stats_test';
+
+ exit when updated1 and updated2 and updated3;
-- wait a little
perform pg_sleep(0.1);
1
(1 row)
--- force the rate-limiting logic in pgstat_report_tabstat() to time out
+-- force the rate-limiting logic in pgstat_report_stat() to time out
-- and send a message
SELECT pg_sleep(1.0);
pg_sleep
create function wait_for_stats() returns void as $$
declare
start_time timestamptz := clock_timestamp();
- updated bool;
+ updated1 bool;
+ updated2 bool;
+ updated3 bool;
begin
-- we don't want to wait forever; loop will exit after 30 seconds
for i in 1 .. 300 loop
+ -- With parallel query, the seqscan and indexscan on tenk2 might be done
+ -- in parallel worker processes, which will send their stats counters
+ -- asynchronously to what our own session does. So we must check for
+ -- those counts to be registered separately from the update counts.
+
+ -- check to see if seqscan has been sensed
+ SELECT (st.seq_scan >= pr.seq_scan + 1) INTO updated1
+ FROM pg_stat_user_tables AS st, pg_class AS cl, prevstats AS pr
+ WHERE st.relname='tenk2' AND cl.relname='tenk2';
+
-- check to see if indexscan has been sensed
- SELECT (st.idx_scan >= pr.idx_scan + 1) INTO updated
+ SELECT (st.idx_scan >= pr.idx_scan + 1) INTO updated2
FROM pg_stat_user_tables AS st, pg_class AS cl, prevstats AS pr
WHERE st.relname='tenk2' AND cl.relname='tenk2';
- exit when updated;
+ -- check to see if updates have been sensed
+ SELECT (n_tup_ins > 0) INTO updated3
+ FROM pg_stat_user_tables WHERE relname='trunc_stats_test';
+
+ exit when updated1 and updated2 and updated3;
-- wait a little
perform pg_sleep(0.1);
-- do an indexscan
SELECT count(*) FROM tenk2 WHERE unique1 = 1;
--- force the rate-limiting logic in pgstat_report_tabstat() to time out
+-- force the rate-limiting logic in pgstat_report_stat() to time out
-- and send a message
SELECT pg_sleep(1.0);