github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/logictest/testdata/logic_test/txn_stats (about) 1 # LogicTest: local 2 3 # Some sanity checks for node_txn_stats virtual table. 4 5 statement ok 6 SET application_name = test; SELECT 1 7 8 query B 9 SELECT count(*) > 0 10 FROM crdb_internal.node_txn_stats 11 WHERE application_name = 'test' 12 ---- 13 true 14 15 # We shouldn't have any aborted transactions. 16 query B 17 SELECT txn_count - committed_count = 0 18 FROM crdb_internal.node_txn_stats 19 WHERE application_name = 'test' 20 ---- 21 true 22 23 # We haven't executed any explicit transactions yet. 24 query B 25 SELECT txn_count = implicit_count 26 FROM crdb_internal.node_txn_stats 27 WHERE application_name = 'test' 28 ---- 29 true 30 31 statement ok 32 BEGIN TRANSACTION; SELECT 1; COMMIT TRANSACTION 33 34 # Now we should have exactly one explicit transaction. 35 query B 36 SELECT txn_count - implicit_count = 1 37 FROM crdb_internal.node_txn_stats 38 WHERE application_name = 'test' 39 ---- 40 true 41 42 # All transactions so far should be extremely fast, so we check that the 43 # average transaction time is in [0s, 0.1s] range. 44 query B 45 SELECT count(*) = 0 46 FROM crdb_internal.node_txn_stats 47 WHERE application_name = 'test' 48 AND ( 49 txn_time_avg_sec < 0 50 OR txn_time_avg_sec > 0.1 51 ) 52 ---- 53 true