2003-09-13 18:44:49 +02:00
|
|
|
--
|
2022-04-06 22:56:06 +02:00
|
|
|
-- Test cumulative stats system
|
2003-09-13 18:44:49 +02:00
|
|
|
--
|
|
|
|
-- Must be run after tenk2 has been created (by create_table),
|
|
|
|
-- populated (by create_misc) and indexed (by create_index).
|
|
|
|
--
|
|
|
|
-- conditio sine qua non
|
2007-09-24 05:12:23 +02:00
|
|
|
SHOW track_counts; -- must be on
|
|
|
|
track_counts
|
|
|
|
--------------
|
2003-09-13 18:44:49 +02:00
|
|
|
on
|
|
|
|
(1 row)
|
|
|
|
|
2011-10-09 05:45:58 +02:00
|
|
|
-- ensure that both seqscan and indexscan plans are allowed
|
|
|
|
SET enable_seqscan TO on;
|
|
|
|
SET enable_indexscan TO on;
|
|
|
|
-- for the moment, we don't want index-only scans here
|
|
|
|
SET enable_indexonlyscan TO off;
|
2022-04-07 09:03:58 +02:00
|
|
|
-- not enabled by default, but we want to test it...
|
|
|
|
SET track_functions TO 'all';
|
2003-09-13 18:44:49 +02:00
|
|
|
-- save counters
|
2022-04-07 06:29:46 +02:00
|
|
|
BEGIN;
|
|
|
|
SET LOCAL stats_fetch_consistency = snapshot;
|
2017-05-13 15:42:12 +02:00
|
|
|
CREATE TABLE prevstats AS
|
2003-09-13 18:44:49 +02:00
|
|
|
SELECT t.seq_scan, t.seq_tup_read, t.idx_scan, t.idx_tup_fetch,
|
|
|
|
(b.heap_blks_read + b.heap_blks_hit) AS heap_blks,
|
2015-02-20 03:36:50 +01:00
|
|
|
(b.idx_blks_read + b.idx_blks_hit) AS idx_blks,
|
|
|
|
pg_stat_get_snapshot_timestamp() as snap_ts
|
2003-09-13 18:44:49 +02:00
|
|
|
FROM pg_catalog.pg_stat_user_tables AS t,
|
|
|
|
pg_catalog.pg_statio_user_tables AS b
|
|
|
|
WHERE t.relname='tenk2' AND b.relname='tenk2';
|
2022-04-07 06:29:46 +02:00
|
|
|
COMMIT;
|
2015-02-20 16:10:01 +01:00
|
|
|
-- test effects of TRUNCATE on n_live_tup/n_dead_tup counters
|
|
|
|
CREATE TABLE trunc_stats_test(id serial);
|
2018-12-07 18:11:59 +01:00
|
|
|
CREATE TABLE trunc_stats_test1(id serial, stuff text);
|
2015-02-20 16:10:01 +01:00
|
|
|
CREATE TABLE trunc_stats_test2(id serial);
|
2018-12-07 18:11:59 +01:00
|
|
|
CREATE TABLE trunc_stats_test3(id serial, stuff text);
|
2015-02-20 16:10:01 +01:00
|
|
|
CREATE TABLE trunc_stats_test4(id serial);
|
|
|
|
-- check that n_live_tup is reset to 0 after truncate
|
|
|
|
INSERT INTO trunc_stats_test DEFAULT VALUES;
|
|
|
|
INSERT INTO trunc_stats_test DEFAULT VALUES;
|
|
|
|
INSERT INTO trunc_stats_test DEFAULT VALUES;
|
|
|
|
TRUNCATE trunc_stats_test;
|
|
|
|
-- test involving a truncate in a transaction; 4 ins but only 1 live
|
|
|
|
INSERT INTO trunc_stats_test1 DEFAULT VALUES;
|
|
|
|
INSERT INTO trunc_stats_test1 DEFAULT VALUES;
|
|
|
|
INSERT INTO trunc_stats_test1 DEFAULT VALUES;
|
|
|
|
UPDATE trunc_stats_test1 SET id = id + 10 WHERE id IN (1, 2);
|
|
|
|
DELETE FROM trunc_stats_test1 WHERE id = 3;
|
|
|
|
BEGIN;
|
|
|
|
UPDATE trunc_stats_test1 SET id = id + 100;
|
|
|
|
TRUNCATE trunc_stats_test1;
|
|
|
|
INSERT INTO trunc_stats_test1 DEFAULT VALUES;
|
|
|
|
COMMIT;
|
|
|
|
-- use a savepoint: 1 insert, 1 live
|
|
|
|
BEGIN;
|
|
|
|
INSERT INTO trunc_stats_test2 DEFAULT VALUES;
|
|
|
|
INSERT INTO trunc_stats_test2 DEFAULT VALUES;
|
|
|
|
SAVEPOINT p1;
|
|
|
|
INSERT INTO trunc_stats_test2 DEFAULT VALUES;
|
|
|
|
TRUNCATE trunc_stats_test2;
|
|
|
|
INSERT INTO trunc_stats_test2 DEFAULT VALUES;
|
|
|
|
RELEASE SAVEPOINT p1;
|
|
|
|
COMMIT;
|
|
|
|
-- rollback a savepoint: this should count 4 inserts and have 2
|
|
|
|
-- live tuples after commit (and 2 dead ones due to aborted subxact)
|
|
|
|
BEGIN;
|
|
|
|
INSERT INTO trunc_stats_test3 DEFAULT VALUES;
|
|
|
|
INSERT INTO trunc_stats_test3 DEFAULT VALUES;
|
|
|
|
SAVEPOINT p1;
|
|
|
|
INSERT INTO trunc_stats_test3 DEFAULT VALUES;
|
|
|
|
INSERT INTO trunc_stats_test3 DEFAULT VALUES;
|
|
|
|
TRUNCATE trunc_stats_test3;
|
|
|
|
INSERT INTO trunc_stats_test3 DEFAULT VALUES;
|
|
|
|
ROLLBACK TO SAVEPOINT p1;
|
|
|
|
COMMIT;
|
|
|
|
-- rollback a truncate: this should count 2 inserts and produce 2 dead tuples
|
|
|
|
BEGIN;
|
|
|
|
INSERT INTO trunc_stats_test4 DEFAULT VALUES;
|
|
|
|
INSERT INTO trunc_stats_test4 DEFAULT VALUES;
|
|
|
|
TRUNCATE trunc_stats_test4;
|
|
|
|
INSERT INTO trunc_stats_test4 DEFAULT VALUES;
|
|
|
|
ROLLBACK;
|
2007-02-08 00:11:30 +01:00
|
|
|
-- do a seqscan
|
|
|
|
SELECT count(*) FROM tenk2;
|
|
|
|
count
|
|
|
|
-------
|
|
|
|
10000
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- do an indexscan
|
Allow bitmap scans to operate as index-only scans when possible.
If we don't have to return any columns from heap tuples, and there's
no need to recheck qual conditions, and the heap page is all-visible,
then we can skip fetching the heap page altogether.
Skip prefetching pages too, when possible, on the assumption that the
recheck flag will remain the same from one page to the next. While that
assumption is hardly bulletproof, it seems like a good bet most of the
time, and better than prefetching pages we don't need.
This commit installs the executor infrastructure, but doesn't change
any planner cost estimates, thus possibly causing bitmap scans to
not be chosen in cases where this change renders them the best choice.
I (tgl) am not entirely convinced that we need to account for this
behavior in the planner, because I think typically the bitmap scan would
get chosen anyway if it's the best bet. In any case the submitted patch
took way too many shortcuts, resulting in too many clearly-bad choices,
to be committable.
Alexander Kuzmenkov, reviewed by Alexey Chernyshov, and whacked around
rather heavily by me.
Discussion: https://postgr.es/m/239a8955-c0fc-f506-026d-c837e86c827b@postgrespro.ru
2017-11-01 22:38:12 +01:00
|
|
|
-- make sure it is not a bitmap scan, which might skip fetching heap tuples
|
|
|
|
SET enable_bitmapscan TO off;
|
2007-02-08 00:11:30 +01:00
|
|
|
SELECT count(*) FROM tenk2 WHERE unique1 = 1;
|
|
|
|
count
|
|
|
|
-------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
Allow bitmap scans to operate as index-only scans when possible.
If we don't have to return any columns from heap tuples, and there's
no need to recheck qual conditions, and the heap page is all-visible,
then we can skip fetching the heap page altogether.
Skip prefetching pages too, when possible, on the assumption that the
recheck flag will remain the same from one page to the next. While that
assumption is hardly bulletproof, it seems like a good bet most of the
time, and better than prefetching pages we don't need.
This commit installs the executor infrastructure, but doesn't change
any planner cost estimates, thus possibly causing bitmap scans to
not be chosen in cases where this change renders them the best choice.
I (tgl) am not entirely convinced that we need to account for this
behavior in the planner, because I think typically the bitmap scan would
get chosen anyway if it's the best bet. In any case the submitted patch
took way too many shortcuts, resulting in too many clearly-bad choices,
to be committable.
Alexander Kuzmenkov, reviewed by Alexey Chernyshov, and whacked around
rather heavily by me.
Discussion: https://postgr.es/m/239a8955-c0fc-f506-026d-c837e86c827b@postgrespro.ru
2017-11-01 22:38:12 +01:00
|
|
|
RESET enable_bitmapscan;
|
2022-04-07 08:35:56 +02:00
|
|
|
-- ensure pending stats are flushed
|
|
|
|
SELECT pg_stat_force_next_flush();
|
|
|
|
pg_stat_force_next_flush
|
|
|
|
--------------------------
|
2005-07-23 16:18:57 +02:00
|
|
|
|
2003-09-13 18:44:49 +02:00
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- check effects
|
2022-04-07 06:29:46 +02:00
|
|
|
BEGIN;
|
|
|
|
SET LOCAL stats_fetch_consistency = snapshot;
|
2015-02-20 16:10:01 +01:00
|
|
|
SELECT relname, n_tup_ins, n_tup_upd, n_tup_del, n_live_tup, n_dead_tup
|
|
|
|
FROM pg_stat_user_tables
|
|
|
|
WHERE relname like 'trunc_stats_test%' order by relname;
|
|
|
|
relname | n_tup_ins | n_tup_upd | n_tup_del | n_live_tup | n_dead_tup
|
|
|
|
-------------------+-----------+-----------+-----------+------------+------------
|
|
|
|
trunc_stats_test | 3 | 0 | 0 | 0 | 0
|
|
|
|
trunc_stats_test1 | 4 | 2 | 1 | 1 | 0
|
|
|
|
trunc_stats_test2 | 1 | 0 | 0 | 1 | 0
|
|
|
|
trunc_stats_test3 | 4 | 0 | 0 | 2 | 2
|
|
|
|
trunc_stats_test4 | 2 | 0 | 0 | 0 | 2
|
|
|
|
(5 rows)
|
|
|
|
|
2003-09-13 18:44:49 +02:00
|
|
|
SELECT st.seq_scan >= pr.seq_scan + 1,
|
|
|
|
st.seq_tup_read >= pr.seq_tup_read + cl.reltuples,
|
|
|
|
st.idx_scan >= pr.idx_scan + 1,
|
|
|
|
st.idx_tup_fetch >= pr.idx_tup_fetch + 1
|
|
|
|
FROM pg_stat_user_tables AS st, pg_class AS cl, prevstats AS pr
|
|
|
|
WHERE st.relname='tenk2' AND cl.relname='tenk2';
|
2003-11-01 04:18:20 +01:00
|
|
|
?column? | ?column? | ?column? | ?column?
|
2003-09-13 18:44:49 +02:00
|
|
|
----------+----------+----------+----------
|
|
|
|
t | t | t | t
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT st.heap_blks_read + st.heap_blks_hit >= pr.heap_blks + cl.relpages,
|
|
|
|
st.idx_blks_read + st.idx_blks_hit >= pr.idx_blks + 1
|
|
|
|
FROM pg_statio_user_tables AS st, pg_class AS cl, prevstats AS pr
|
|
|
|
WHERE st.relname='tenk2' AND cl.relname='tenk2';
|
2003-11-01 04:18:20 +01:00
|
|
|
?column? | ?column?
|
2003-09-13 18:44:49 +02:00
|
|
|
----------+----------
|
|
|
|
t | t
|
|
|
|
(1 row)
|
|
|
|
|
2015-02-20 03:36:50 +01:00
|
|
|
SELECT pr.snap_ts < pg_stat_get_snapshot_timestamp() as snapshot_newer
|
|
|
|
FROM prevstats AS pr;
|
|
|
|
snapshot_newer
|
|
|
|
----------------
|
|
|
|
t
|
|
|
|
(1 row)
|
|
|
|
|
2022-04-07 06:29:46 +02:00
|
|
|
COMMIT;
|
2022-04-07 09:03:58 +02:00
|
|
|
----
|
|
|
|
-- Basic tests for track_functions
|
|
|
|
---
|
|
|
|
CREATE FUNCTION stats_test_func1() RETURNS VOID LANGUAGE plpgsql AS $$BEGIN END;$$;
|
|
|
|
SELECT 'stats_test_func1()'::regprocedure::oid AS stats_test_func1_oid \gset
|
|
|
|
CREATE FUNCTION stats_test_func2() RETURNS VOID LANGUAGE plpgsql AS $$BEGIN END;$$;
|
|
|
|
SELECT 'stats_test_func2()'::regprocedure::oid AS stats_test_func2_oid \gset
|
|
|
|
-- test that stats are accumulated
|
|
|
|
BEGIN;
|
|
|
|
SET LOCAL stats_fetch_consistency = none;
|
|
|
|
SELECT pg_stat_get_function_calls(:stats_test_func1_oid);
|
|
|
|
pg_stat_get_function_calls
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT pg_stat_get_xact_function_calls(:stats_test_func1_oid);
|
|
|
|
pg_stat_get_xact_function_calls
|
|
|
|
---------------------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT stats_test_func1();
|
|
|
|
stats_test_func1
|
|
|
|
------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT pg_stat_get_xact_function_calls(:stats_test_func1_oid);
|
|
|
|
pg_stat_get_xact_function_calls
|
|
|
|
---------------------------------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT stats_test_func1();
|
|
|
|
stats_test_func1
|
|
|
|
------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT pg_stat_get_xact_function_calls(:stats_test_func1_oid);
|
|
|
|
pg_stat_get_xact_function_calls
|
|
|
|
---------------------------------
|
|
|
|
2
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT pg_stat_get_function_calls(:stats_test_func1_oid);
|
|
|
|
pg_stat_get_function_calls
|
|
|
|
----------------------------
|
|
|
|
0
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
COMMIT;
|
|
|
|
-- Verify that function stats are not transactional
|
|
|
|
-- rolled back savepoint in committing transaction
|
|
|
|
BEGIN;
|
|
|
|
SELECT stats_test_func2();
|
|
|
|
stats_test_func2
|
|
|
|
------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SAVEPOINT foo;
|
|
|
|
SELECT stats_test_func2();
|
|
|
|
stats_test_func2
|
|
|
|
------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
ROLLBACK TO SAVEPOINT foo;
|
|
|
|
SELECT pg_stat_get_xact_function_calls(:stats_test_func2_oid);
|
|
|
|
pg_stat_get_xact_function_calls
|
|
|
|
---------------------------------
|
|
|
|
2
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT stats_test_func2();
|
|
|
|
stats_test_func2
|
|
|
|
------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
COMMIT;
|
|
|
|
-- rolled back transaction
|
|
|
|
BEGIN;
|
|
|
|
SELECT stats_test_func2();
|
|
|
|
stats_test_func2
|
|
|
|
------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
ROLLBACK;
|
|
|
|
SELECT pg_stat_force_next_flush();
|
|
|
|
pg_stat_force_next_flush
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- check collected stats
|
|
|
|
SELECT funcname, calls FROM pg_stat_user_functions WHERE funcid = :stats_test_func1_oid;
|
|
|
|
funcname | calls
|
|
|
|
------------------+-------
|
|
|
|
stats_test_func1 | 2
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT funcname, calls FROM pg_stat_user_functions WHERE funcid = :stats_test_func2_oid;
|
|
|
|
funcname | calls
|
|
|
|
------------------+-------
|
|
|
|
stats_test_func2 | 4
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- check that a rolled back drop function stats leaves stats alive
|
|
|
|
BEGIN;
|
|
|
|
SELECT funcname, calls FROM pg_stat_user_functions WHERE funcid = :stats_test_func1_oid;
|
|
|
|
funcname | calls
|
|
|
|
------------------+-------
|
|
|
|
stats_test_func1 | 2
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
DROP FUNCTION stats_test_func1();
|
|
|
|
-- shouldn't be visible via view
|
|
|
|
SELECT funcname, calls FROM pg_stat_user_functions WHERE funcid = :stats_test_func1_oid;
|
|
|
|
funcname | calls
|
|
|
|
----------+-------
|
|
|
|
(0 rows)
|
|
|
|
|
|
|
|
-- but still via oid access
|
|
|
|
SELECT pg_stat_get_function_calls(:stats_test_func1_oid);
|
|
|
|
pg_stat_get_function_calls
|
|
|
|
----------------------------
|
|
|
|
2
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
ROLLBACK;
|
|
|
|
SELECT funcname, calls FROM pg_stat_user_functions WHERE funcid = :stats_test_func1_oid;
|
|
|
|
funcname | calls
|
|
|
|
------------------+-------
|
|
|
|
stats_test_func1 | 2
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT pg_stat_get_function_calls(:stats_test_func1_oid);
|
|
|
|
pg_stat_get_function_calls
|
|
|
|
----------------------------
|
|
|
|
2
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- check that function dropped in main transaction leaves no stats behind
|
|
|
|
BEGIN;
|
|
|
|
DROP FUNCTION stats_test_func1();
|
|
|
|
COMMIT;
|
|
|
|
SELECT funcname, calls FROM pg_stat_user_functions WHERE funcid = :stats_test_func1_oid;
|
|
|
|
funcname | calls
|
|
|
|
----------+-------
|
|
|
|
(0 rows)
|
|
|
|
|
|
|
|
SELECT pg_stat_get_function_calls(:stats_test_func1_oid);
|
|
|
|
pg_stat_get_function_calls
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- check that function dropped in a subtransaction leaves no stats behind
|
|
|
|
BEGIN;
|
|
|
|
SELECT stats_test_func2();
|
|
|
|
stats_test_func2
|
|
|
|
------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SAVEPOINT a;
|
|
|
|
SELECT stats_test_func2();
|
|
|
|
stats_test_func2
|
|
|
|
------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SAVEPOINT b;
|
|
|
|
DROP FUNCTION stats_test_func2();
|
|
|
|
COMMIT;
|
|
|
|
SELECT funcname, calls FROM pg_stat_user_functions WHERE funcid = :stats_test_func2_oid;
|
|
|
|
funcname | calls
|
|
|
|
----------+-------
|
|
|
|
(0 rows)
|
|
|
|
|
|
|
|
SELECT pg_stat_get_function_calls(:stats_test_func2_oid);
|
|
|
|
pg_stat_get_function_calls
|
|
|
|
----------------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- Check that stats for relations are dropped. For that we need to access stats
|
|
|
|
-- by oid after the DROP TABLE. Save oids.
|
|
|
|
CREATE TABLE drop_stats_test();
|
|
|
|
INSERT INTO drop_stats_test DEFAULT VALUES;
|
|
|
|
SELECT 'drop_stats_test'::regclass::oid AS drop_stats_test_oid \gset
|
|
|
|
CREATE TABLE drop_stats_test_xact();
|
|
|
|
INSERT INTO drop_stats_test_xact DEFAULT VALUES;
|
|
|
|
SELECT 'drop_stats_test_xact'::regclass::oid AS drop_stats_test_xact_oid \gset
|
|
|
|
CREATE TABLE drop_stats_test_subxact();
|
|
|
|
INSERT INTO drop_stats_test_subxact DEFAULT VALUES;
|
|
|
|
SELECT 'drop_stats_test_subxact'::regclass::oid AS drop_stats_test_subxact_oid \gset
|
|
|
|
SELECT pg_stat_force_next_flush();
|
|
|
|
pg_stat_force_next_flush
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT pg_stat_get_live_tuples(:drop_stats_test_oid);
|
|
|
|
pg_stat_get_live_tuples
|
|
|
|
-------------------------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
DROP TABLE drop_stats_test;
|
|
|
|
SELECT pg_stat_get_live_tuples(:drop_stats_test_oid);
|
|
|
|
pg_stat_get_live_tuples
|
|
|
|
-------------------------
|
|
|
|
0
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT pg_stat_get_xact_tuples_inserted(:drop_stats_test_oid);
|
|
|
|
pg_stat_get_xact_tuples_inserted
|
|
|
|
----------------------------------
|
|
|
|
0
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- check that rollback protects against having stats dropped and that local
|
|
|
|
-- modifications don't pose a problem
|
|
|
|
SELECT pg_stat_get_live_tuples(:drop_stats_test_xact_oid);
|
|
|
|
pg_stat_get_live_tuples
|
|
|
|
-------------------------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT pg_stat_get_tuples_inserted(:drop_stats_test_xact_oid);
|
|
|
|
pg_stat_get_tuples_inserted
|
|
|
|
-----------------------------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT pg_stat_get_xact_tuples_inserted(:drop_stats_test_xact_oid);
|
|
|
|
pg_stat_get_xact_tuples_inserted
|
|
|
|
----------------------------------
|
|
|
|
0
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
BEGIN;
|
|
|
|
INSERT INTO drop_stats_test_xact DEFAULT VALUES;
|
|
|
|
SELECT pg_stat_get_xact_tuples_inserted(:drop_stats_test_xact_oid);
|
|
|
|
pg_stat_get_xact_tuples_inserted
|
|
|
|
----------------------------------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
DROP TABLE drop_stats_test_xact;
|
|
|
|
SELECT pg_stat_get_xact_tuples_inserted(:drop_stats_test_xact_oid);
|
|
|
|
pg_stat_get_xact_tuples_inserted
|
|
|
|
----------------------------------
|
|
|
|
0
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
ROLLBACK;
|
|
|
|
SELECT pg_stat_force_next_flush();
|
|
|
|
pg_stat_force_next_flush
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT pg_stat_get_live_tuples(:drop_stats_test_xact_oid);
|
|
|
|
pg_stat_get_live_tuples
|
|
|
|
-------------------------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT pg_stat_get_tuples_inserted(:drop_stats_test_xact_oid);
|
|
|
|
pg_stat_get_tuples_inserted
|
|
|
|
-----------------------------
|
|
|
|
2
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- transactional drop
|
|
|
|
SELECT pg_stat_get_live_tuples(:drop_stats_test_xact_oid);
|
|
|
|
pg_stat_get_live_tuples
|
|
|
|
-------------------------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT pg_stat_get_tuples_inserted(:drop_stats_test_xact_oid);
|
|
|
|
pg_stat_get_tuples_inserted
|
|
|
|
-----------------------------
|
|
|
|
2
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
BEGIN;
|
|
|
|
INSERT INTO drop_stats_test_xact DEFAULT VALUES;
|
|
|
|
SELECT pg_stat_get_xact_tuples_inserted(:drop_stats_test_xact_oid);
|
|
|
|
pg_stat_get_xact_tuples_inserted
|
|
|
|
----------------------------------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
DROP TABLE drop_stats_test_xact;
|
|
|
|
SELECT pg_stat_get_xact_tuples_inserted(:drop_stats_test_xact_oid);
|
|
|
|
pg_stat_get_xact_tuples_inserted
|
|
|
|
----------------------------------
|
|
|
|
0
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
COMMIT;
|
|
|
|
SELECT pg_stat_force_next_flush();
|
|
|
|
pg_stat_force_next_flush
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT pg_stat_get_live_tuples(:drop_stats_test_xact_oid);
|
|
|
|
pg_stat_get_live_tuples
|
|
|
|
-------------------------
|
|
|
|
0
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT pg_stat_get_tuples_inserted(:drop_stats_test_xact_oid);
|
|
|
|
pg_stat_get_tuples_inserted
|
|
|
|
-----------------------------
|
|
|
|
0
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- savepoint rollback (2 levels)
|
|
|
|
SELECT pg_stat_get_live_tuples(:drop_stats_test_subxact_oid);
|
|
|
|
pg_stat_get_live_tuples
|
|
|
|
-------------------------
|
|
|
|
1
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
BEGIN;
|
|
|
|
INSERT INTO drop_stats_test_subxact DEFAULT VALUES;
|
|
|
|
SAVEPOINT sp1;
|
|
|
|
INSERT INTO drop_stats_test_subxact DEFAULT VALUES;
|
|
|
|
SELECT pg_stat_get_xact_tuples_inserted(:drop_stats_test_subxact_oid);
|
|
|
|
pg_stat_get_xact_tuples_inserted
|
|
|
|
----------------------------------
|
|
|
|
2
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SAVEPOINT sp2;
|
|
|
|
DROP TABLE drop_stats_test_subxact;
|
|
|
|
ROLLBACK TO SAVEPOINT sp2;
|
|
|
|
SELECT pg_stat_get_xact_tuples_inserted(:drop_stats_test_subxact_oid);
|
|
|
|
pg_stat_get_xact_tuples_inserted
|
|
|
|
----------------------------------
|
|
|
|
2
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
COMMIT;
|
|
|
|
SELECT pg_stat_force_next_flush();
|
|
|
|
pg_stat_force_next_flush
|
|
|
|
--------------------------
|
|
|
|
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
SELECT pg_stat_get_live_tuples(:drop_stats_test_subxact_oid);
|
|
|
|
pg_stat_get_live_tuples
|
|
|
|
-------------------------
|
|
|
|
3
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- savepoint rolback (1 level)
|
|
|
|
SELECT pg_stat_get_live_tuples(:drop_stats_test_subxact_oid);
|
|
|
|
pg_stat_get_live_tuples
|
|
|
|
-------------------------
|
|
|
|
3
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
BEGIN;
|
|
|
|
SAVEPOINT sp1;
|
|
|
|
DROP TABLE drop_stats_test_subxact;
|
|
|
|
SAVEPOINT sp2;
|
|
|
|
ROLLBACK TO SAVEPOINT sp1;
|
|
|
|
COMMIT;
|
|
|
|
SELECT pg_stat_get_live_tuples(:drop_stats_test_subxact_oid);
|
|
|
|
pg_stat_get_live_tuples
|
|
|
|
-------------------------
|
|
|
|
3
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
-- and now actually drop
|
|
|
|
SELECT pg_stat_get_live_tuples(:drop_stats_test_subxact_oid);
|
|
|
|
pg_stat_get_live_tuples
|
|
|
|
-------------------------
|
|
|
|
3
|
|
|
|
(1 row)
|
|
|
|
|
|
|
|
BEGIN;
|
|
|
|
SAVEPOINT sp1;
|
|
|
|
DROP TABLE drop_stats_test_subxact;
|
|
|
|
SAVEPOINT sp2;
|
|
|
|
RELEASE SAVEPOINT sp1;
|
|
|
|
COMMIT;
|
|
|
|
SELECT pg_stat_get_live_tuples(:drop_stats_test_subxact_oid);
|
|
|
|
pg_stat_get_live_tuples
|
|
|
|
-------------------------
|
|
|
|
0
|
|
|
|
(1 row)
|
|
|
|
|
2015-02-20 16:10:01 +01:00
|
|
|
DROP TABLE trunc_stats_test, trunc_stats_test1, trunc_stats_test2, trunc_stats_test3, trunc_stats_test4;
|
2017-05-13 15:42:12 +02:00
|
|
|
DROP TABLE prevstats;
|
2003-09-13 18:44:49 +02:00
|
|
|
-- End of Stats Test
|