summaryrefslogtreecommitdiffstats
path: root/src/test/isolation/specs/stats.spec
blob: 5b922d788cc0b83bacc8051380b4c373e5d70966 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
setup
{
    CREATE TABLE test_stat_oid(name text NOT NULL, oid oid);

    CREATE TABLE test_stat_tab(key text not null, value int);
    INSERT INTO test_stat_tab(key, value) VALUES('k0', 1);
    INSERT INTO test_stat_oid(name, oid) VALUES('test_stat_tab', 'test_stat_tab'::regclass);

    CREATE FUNCTION test_stat_func() RETURNS VOID LANGUAGE plpgsql AS $$BEGIN END;$$;
    INSERT INTO test_stat_oid(name, oid) VALUES('test_stat_func', 'test_stat_func'::regproc);

    CREATE FUNCTION test_stat_func2() RETURNS VOID LANGUAGE plpgsql AS $$BEGIN END;$$;
    INSERT INTO test_stat_oid(name, oid) VALUES('test_stat_func2', 'test_stat_func2'::regproc);

    CREATE TABLE test_slru_stats(slru TEXT, stat TEXT, value INT);

    -- calls test_stat_func, but hides error if it doesn't exist
    CREATE FUNCTION test_stat_func_ifexists() RETURNS VOID LANGUAGE plpgsql AS $$
    BEGIN
        PERFORM test_stat_func();
    EXCEPTION WHEN undefined_function THEN
    END;$$;

    SELECT pg_stat_force_next_flush();
}

teardown
{
    DROP TABLE test_stat_oid;
    DROP TABLE test_slru_stats;

    DROP TABLE IF EXISTS test_stat_tab;
    DROP FUNCTION IF EXISTS test_stat_func();
    DROP FUNCTION IF EXISTS test_stat_func2();
    DROP FUNCTION test_stat_func_ifexists();
}

session s1
setup { SET stats_fetch_consistency = 'none'; }
step s1_fetch_consistency_none { SET stats_fetch_consistency = 'none'; }
step s1_fetch_consistency_cache { SET stats_fetch_consistency = 'cache'; }
step s1_fetch_consistency_snapshot { SET stats_fetch_consistency = 'snapshot'; }
step s1_clear_snapshot { SELECT pg_stat_clear_snapshot(); }
step s1_begin { BEGIN; }
step s1_commit { COMMIT; }
step s1_rollback { ROLLBACK; }
step s1_prepare_a { PREPARE TRANSACTION 'a'; }
step s1_commit_prepared_a { COMMIT PREPARED 'a'; }
step s1_rollback_prepared_a { ROLLBACK PREPARED 'a'; }

# Function stats steps
step s1_ff { SELECT pg_stat_force_next_flush(); }
step s1_track_funcs_all { SET track_functions = 'all'; }
step s1_track_funcs_none { SET track_functions = 'none'; }
step s1_func_call { SELECT test_stat_func(); }
step s1_func_drop { DROP FUNCTION test_stat_func(); }
step s1_func_stats_reset { SELECT pg_stat_reset_single_function_counters('test_stat_func'::regproc); }
step s1_func_stats_reset_nonexistent { SELECT pg_stat_reset_single_function_counters(12000); }
step s1_reset { SELECT pg_stat_reset(); }
step s1_func_stats {
    SELECT
        tso.name,
        pg_stat_get_function_calls(tso.oid),
        pg_stat_get_function_total_time(tso.oid) > 0 total_above_zero,
        pg_stat_get_function_self_time(tso.oid) > 0 self_above_zero
    FROM test_stat_oid AS tso
    WHERE tso.name = 'test_stat_func'
}
step s1_func_stats2 {
    SELECT
        tso.name,
        pg_stat_get_function_calls(tso.oid),
        pg_stat_get_function_total_time(tso.oid) > 0 total_above_zero,
        pg_stat_get_function_self_time(tso.oid) > 0 self_above_zero
    FROM test_stat_oid AS tso
    WHERE tso.name = 'test_stat_func2'
}
step s1_func_stats_nonexistent {
    SELECT pg_stat_get_function_calls(12000);
}

# Relation stats steps
step s1_track_counts_on { SET track_counts = on; }
step s1_track_counts_off { SET track_counts = off; }
step s1_table_select { SELECT * FROM test_stat_tab ORDER BY key, value; }
step s1_table_insert { INSERT INTO test_stat_tab(key, value) VALUES('k1', 1), ('k2', 1), ('k3', 1);}
step s1_table_insert_k1 { INSERT INTO test_stat_tab(key, value) VALUES('k1', 1);}
step s1_table_update_k1 { UPDATE test_stat_tab SET value = value + 1 WHERE key = 'k1';}
step s1_table_update_k2 { UPDATE test_stat_tab SET value = value + 1 WHERE key = 'k2';}
step s1_table_delete_k1 { DELETE FROM test_stat_tab WHERE key = 'k1';}
step s1_table_truncate { TRUNCATE test_stat_tab; }
step s1_table_drop { DROP TABLE test_stat_tab; }

step s1_table_stats {
    SELECT
        pg_stat_get_numscans(tso.oid) AS seq_scan,
        pg_stat_get_tuples_returned(tso.oid) AS seq_tup_read,
        pg_stat_get_tuples_inserted(tso.oid) AS n_tup_ins,
        pg_stat_get_tuples_updated(tso.oid) AS n_tup_upd,
        pg_stat_get_tuples_deleted(tso.oid) AS n_tup_del,
        pg_stat_get_live_tuples(tso.oid) AS n_live_tup,
        pg_stat_get_dead_tuples(tso.oid) AS n_dead_tup,
        pg_stat_get_vacuum_count(tso.oid) AS vacuum_count
    FROM test_stat_oid AS tso
    WHERE tso.name = 'test_stat_tab'
}

# SLRU stats steps
step s1_slru_save_stats {
	INSERT INTO test_slru_stats VALUES('Notify', 'blks_zeroed',
    (SELECT blks_zeroed FROM pg_stat_slru WHERE name = 'Notify'));
}
step s1_listen { LISTEN stats_test_nothing; }
step s1_big_notify { SELECT pg_notify('stats_test_use',
                repeat(i::text, current_setting('block_size')::int / 2)) FROM generate_series(1, 3) g(i);
                }

step s1_slru_check_stats {
	SELECT current.blks_zeroed > before.value
  FROM test_slru_stats before
  INNER JOIN pg_stat_slru current
  ON before.slru = current.name
  WHERE before.stat = 'blks_zeroed';
	}


session s2
setup { SET stats_fetch_consistency = 'none'; }
step s2_begin { BEGIN; }
step s2_commit { COMMIT; }
step s2_commit_prepared_a { COMMIT PREPARED 'a'; }
step s2_rollback_prepared_a { ROLLBACK PREPARED 'a'; }
step s2_ff { SELECT pg_stat_force_next_flush(); }

# Function stats steps
step s2_track_funcs_all { SET track_functions = 'all'; }
step s2_track_funcs_none { SET track_functions = 'none'; }
step s2_func_call { SELECT test_stat_func() }
step s2_func_call_ifexists { SELECT test_stat_func_ifexists(); }
step s2_func_call2 { SELECT test_stat_func2() }
step s2_func_stats {
    SELECT
        tso.name,
        pg_stat_get_function_calls(tso.oid),
        pg_stat_get_function_total_time(tso.oid) > 0 total_above_zero,
        pg_stat_get_function_self_time(tso.oid) > 0 self_above_zero
    FROM test_stat_oid AS tso
    WHERE tso.name = 'test_stat_func'
}

# Relation stats steps
step s2_table_select { SELECT * FROM test_stat_tab ORDER BY key, value; }
step s2_table_update_k1 { UPDATE test_stat_tab SET value = value + 1 WHERE key = 'k1';}

# SLRU stats steps
step s2_big_notify { SELECT pg_notify('stats_test_use',
                repeat(i::text, current_setting('block_size')::int / 2)) FROM generate_series(1, 3) g(i);
                }


######################
# Function stats tests
######################

# check that stats are collected iff enabled
permutation
  s1_track_funcs_none s1_func_stats s1_func_call s1_func_call s1_ff s1_func_stats
permutation
  s1_track_funcs_all s1_func_stats s1_func_call s1_func_call s1_ff s1_func_stats

# multiple function calls are accurately reported, across separate connections
permutation
  s1_track_funcs_all s2_track_funcs_all s1_func_stats s2_func_stats
  s1_func_call s2_func_call s1_func_call s2_func_call s2_func_call s1_ff s2_ff s1_func_stats s2_func_stats
permutation
  s1_track_funcs_all s2_track_funcs_all s1_func_stats s2_func_stats
  s1_func_call s1_ff s2_func_call s2_func_call s2_ff s1_func_stats s2_func_stats
permutation
  s1_track_funcs_all s2_track_funcs_all s1_func_stats s2_func_stats
  s1_begin s1_func_call s1_func_call s1_commit s1_ff s1_func_stats s2_func_stats


### Check interaction between dropping and stats reporting

# Some of these tests try to test behavior in cases where no invalidation
# processing is triggered. To prevent output changes when
# debug_discard_caches, CATCACHE_FORCE_RELEASE or RELCACHE_FORCE_RELEASE are
# used (which trigger invalidation processing in paths that normally don't),
# test_stat_func_ifexists() can be used, which tries to call test_stat_func(),
# but doesn't raise an error if the function doesn't exist.

# dropping a table remove stats iff committed
permutation
  s1_track_funcs_all s2_track_funcs_all s1_func_stats s2_func_stats
  s1_begin s1_func_call s2_func_call s1_func_drop s2_func_call s2_ff s2_func_stats s1_commit s1_ff s1_func_stats s2_func_stats
permutation
  s1_track_funcs_all s2_track_funcs_all s1_func_stats s2_func_stats
  s1_begin s1_func_call s2_func_call s1_func_drop s2_func_call s2_ff s2_func_stats s1_rollback s1_ff s1_func_stats s2_func_stats

# Verify that pending stats from before a drop do not lead to
# reviving stats for a dropped object
permutation
  s1_track_funcs_all s2_track_funcs_all
  s2_func_call s2_ff # this access increments refcount, preventing the shared entry from being dropped
  s2_begin s2_func_call_ifexists s1_func_drop s1_func_stats s2_commit s2_ff s1_func_stats s2_func_stats
permutation
  s1_track_funcs_all s2_track_funcs_all
  s2_begin s2_func_call_ifexists s1_func_drop s1_func_stats s2_commit s2_ff s1_func_stats s2_func_stats
permutation
  s1_track_funcs_all s2_track_funcs_all
  s1_func_call s2_begin s2_func_call_ifexists s1_func_drop s2_func_call_ifexists s2_commit s2_ff s1_func_stats s2_func_stats

# Function calls don't necessarily trigger cache invalidation processing. The
# default handling of dropped stats could therefore end up with stats getting
# revived by a function call done after stats processing - but
# pgstat_init_function_usage() protects against that if track_functions is
# on. Verify that the stats are indeed dropped, and document the behavioral
# difference between track_functions settings.
permutation
  s1_track_funcs_all s2_track_funcs_none
  s1_func_call s2_begin s2_func_call_ifexists s1_ff s1_func_stats s1_func_drop s2_track_funcs_none s1_func_stats s2_func_call_ifexists s2_commit s2_ff s1_func_stats s2_func_stats
permutation
  s1_track_funcs_all s2_track_funcs_none
  s1_func_call s2_begin s2_func_call_ifexists s1_ff s1_func_stats s1_func_drop s2_track_funcs_all s1_func_stats s2_func_call_ifexists s2_commit s2_ff s1_func_stats s2_func_stats

# test pg_stat_reset_single_function_counters
permutation
  s1_track_funcs_all s2_track_funcs_all
  s1_func_call
  s2_func_call
  s2_func_call2
  s1_ff s2_ff
  s1_func_stats
  s2_func_call s2_func_call2 s2_ff
  s1_func_stats s1_func_stats2 s1_func_stats
  s1_func_stats_reset
  s1_func_stats s1_func_stats2 s1_func_stats

# test pg_stat_reset_single_function_counters of non-existing function
permutation
  s1_func_stats_nonexistent
  s1_func_stats_reset_nonexistent
  s1_func_stats_nonexistent

# test pg_stat_reset
permutation
  s1_track_funcs_all s2_track_funcs_all
  s1_func_call
  s2_func_call
  s2_func_call2
  s1_ff s2_ff
  s1_func_stats s1_func_stats2 s1_func_stats
  s1_reset
  s1_func_stats s1_func_stats2 s1_func_stats


### Check the different snapshot consistency models

# First just some dead-trivial test verifying each model doesn't crash
permutation
  s1_track_funcs_all s1_fetch_consistency_none s1_func_call s1_ff s1_func_stats
permutation
  s1_track_funcs_all s1_fetch_consistency_cache s1_func_call s1_ff s1_func_stats
permutation
  s1_track_funcs_all s1_fetch_consistency_snapshot s1_func_call s1_ff s1_func_stats

# with stats_fetch_consistency=none s1 should see flushed changes in s2, despite being in a transaction
permutation
  s1_track_funcs_all s2_track_funcs_all
  s1_fetch_consistency_none
  s2_func_call s2_ff
  s1_begin
  s1_func_stats
  s2_func_call s2_ff
  s1_func_stats
  s1_commit

# with stats_fetch_consistency=cache s1 should not see concurrent
# changes to the same object after the first access, but a separate
# object should show changes
permutation
  s1_track_funcs_all s2_track_funcs_all
  s1_fetch_consistency_cache
  s2_func_call s2_func_call2 s2_ff
  s1_begin
  s1_func_stats
  s2_func_call s2_func_call2 s2_ff
  s1_func_stats s1_func_stats2
  s1_commit

# with stats_fetch_consistency=snapshot s1 should not see any
# concurrent changes after the first access
permutation
  s1_track_funcs_all s2_track_funcs_all
  s1_fetch_consistency_snapshot
  s2_func_call s2_func_call2 s2_ff
  s1_begin
  s1_func_stats
  s2_func_call s2_func_call2 s2_ff
  s1_func_stats s1_func_stats2
  s1_commit

# Check access to non-existing stats works correctly and repeatedly
permutation
  s1_fetch_consistency_none
  s1_begin
  s1_func_stats_nonexistent
  s1_func_stats_nonexistent
  s1_commit
permutation
  s1_fetch_consistency_cache
  s1_begin
  s1_func_stats_nonexistent
  s1_func_stats_nonexistent
  s1_commit
permutation
  s1_fetch_consistency_snapshot
  s1_begin
  s1_func_stats_nonexistent
  s1_func_stats_nonexistent
  s1_commit


### Check 2PC handling of stat drops

# S1 prepared, S1 commits prepared
permutation
  s1_track_funcs_all s2_track_funcs_all
  s1_begin
  s1_func_call
  s2_func_call
  s1_func_drop
  s2_func_call
  s2_ff
  s1_prepare_a
  s2_func_call
  s2_ff
  s1_func_call
  s1_ff
  s1_func_stats
  s1_commit_prepared_a
  s1_func_stats

# S1 prepared, S1 aborts prepared
permutation
  s1_track_funcs_all s2_track_funcs_all
  s1_begin
  s1_func_call
  s2_func_call
  s1_func_drop
  s2_func_call
  s2_ff
  s1_prepare_a
  s2_func_call
  s2_ff
  s1_func_call
  s1_ff
  s1_func_stats
  s1_rollback_prepared_a
  s1_func_stats

# S1 prepares, S2 commits prepared
permutation
  s1_track_funcs_all s2_track_funcs_all
  s1_begin
  s1_func_call
  s2_func_call
  s1_func_drop
  s2_func_call
  s2_ff
  s1_prepare_a
  s2_func_call
  s2_ff
  s1_func_call
  s1_ff
  s1_func_stats
  s2_commit_prepared_a
  s1_func_stats

# S1 prepared, S2 aborts prepared
permutation
  s1_track_funcs_all s2_track_funcs_all
  s1_begin
  s1_func_call
  s2_func_call
  s1_func_drop
  s2_func_call
  s2_ff
  s1_prepare_a
  s2_func_call
  s2_ff
  s1_func_call
  s1_ff
  s1_func_stats
  s2_rollback_prepared_a
  s1_func_stats


######################
# Table stats tests
######################

# Most of the stats handling mechanism has already been tested in the function
# stats tests above - that's cheaper than testing with relations. But
# particularly for 2PC there are special cases


### Verify that pending stats from before a drop do not lead to reviving
### of stats for a dropped object

permutation
  s1_table_select
  s1_table_insert
  s2_table_select
  s2_table_update_k1
  s1_ff
  s2_table_update_k1
  s1_table_drop
  s2_ff
  s1_table_stats

permutation
  s1_table_select
  s1_table_insert
  s2_table_select
  s2_table_update_k1
  s2_table_update_k1
  s1_table_drop
  s1_table_stats


### Check that we don't count changes with track counts off, but allow access
### to prior stats

# simple read access with stats off
permutation
  s1_track_counts_off
  s1_table_stats
  s1_track_counts_on

# simple read access with stats off, previously accessed
permutation
  s1_table_select
  s1_track_counts_off
  s1_ff
  s1_table_stats
  s1_track_counts_on
permutation
  s1_table_select
  s1_ff
  s1_track_counts_off
  s1_table_stats
  s1_track_counts_on

# ensure we don't count anything with stats off
permutation
  s1_track_counts_off
  s1_table_select
  s1_table_insert_k1
  s1_table_update_k1
  s2_table_select
  s1_track_counts_on
  s1_ff s2_ff
  s1_table_stats
  # but can count again after
  s1_table_select
  s1_table_update_k1
  s1_ff
  s1_table_stats
permutation
  s1_table_select
  s1_table_insert_k1
  s1_table_delete_k1
  s1_track_counts_off
  s1_table_select
  s1_table_insert_k1
  s1_table_update_k1
  s2_table_select
  s1_track_counts_on
  s1_ff s2_ff
  s1_table_stats
  s1_table_select
  s1_table_update_k1
  s1_ff
  s1_table_stats


### 2PC: transactional and non-transactional counters work correctly

# S1 prepares, S2 commits prepared
permutation
  s1_begin
  s1_table_insert s1_table_update_k1 s1_table_update_k1 s1_table_update_k2 s1_table_update_k2 s1_table_update_k2 s1_table_delete_k1
  s1_table_select
  s1_prepare_a
  s1_table_select
  s1_commit_prepared_a
  s1_table_select
  s1_ff
  s1_table_stats

# S1 prepares, S2 commits prepared
permutation
  s1_begin
  s1_table_insert s1_table_update_k1 s1_table_update_k1 s1_table_update_k2 s1_table_update_k2 s1_table_update_k2 s1_table_delete_k1
  s1_table_select
  s1_prepare_a
  s1_table_select
  s2_commit_prepared_a
  s1_table_select
  s1_ff s2_ff
  s1_table_stats

# S1 prepares, S2 commits prepared
permutation
  s1_begin
  s1_table_insert s1_table_update_k1 s1_table_update_k1 s1_table_update_k2 s1_table_update_k2 s1_table_update_k2 s1_table_delete_k1
  s1_table_select
  s1_prepare_a
  s1_table_select
  s1_rollback_prepared_a
  s1_table_select
  s1_ff
  s1_table_stats

# S1 prepares, S1 aborts prepared
permutation
  s1_begin
  s1_table_insert s1_table_update_k1 s1_table_update_k1 s1_table_update_k2 s1_table_update_k2 s1_table_update_k2 s1_table_delete_k1
  s1_table_select
  s1_prepare_a
  s1_table_select
  s2_rollback_prepared_a
  s1_table_select
  s1_ff s2_ff
  s1_table_stats


### 2PC: truncate handling

# S1 prepares, S1 commits prepared
permutation
  s1_table_insert
  s1_begin
  s1_table_update_k1 # should *not* be counted, different rel
  s1_table_update_k1 # dito
  s1_table_truncate
  s1_table_insert_k1 # should be counted
  s1_table_update_k1 # dito
  s1_prepare_a
  s1_commit_prepared_a
  s1_ff
  s1_table_stats

# S1 prepares, S2 commits prepared
permutation
  s1_table_insert
  s1_begin
  s1_table_update_k1 # should *not* be counted, different rel
  s1_table_update_k1 # dito
  s1_table_truncate
  s1_table_insert_k1 # should be counted
  s1_table_update_k1 # dito
  s1_prepare_a
  s1_ff # flush out non-transactional stats, might happen anyway
  s2_commit_prepared_a
  s2_ff
  s1_table_stats

# S1 prepares, S1 aborts prepared
permutation
  s1_table_insert
  s1_begin
  s1_table_update_k1 # should be counted
  s1_table_update_k1 # dito
  s1_table_truncate
  s1_table_insert_k1 # should *not* be counted, different rel
  s1_table_update_k1 # dito
  s1_prepare_a
  s1_rollback_prepared_a
  s1_ff
  s1_table_stats

# S1 prepares, S2 aborts prepared
permutation
  s1_table_insert
  s1_begin
  s1_table_update_k1 # should be counted
  s1_table_update_k1 # dito
  s1_table_truncate
  s1_table_insert_k1 # should *not* be counted, different rel
  s1_table_update_k1 # dito
  s1_prepare_a
  s2_rollback_prepared_a
  s1_ff s2_ff
  s1_table_stats


### 2PC: rolled back drop maintains live / dead counters

# S1 prepares, S1 aborts prepared
permutation
  s1_table_insert
  s1_table_update_k1
  s1_begin
  # should all be counted
  s1_table_delete_k1
  s1_table_insert_k1
  s1_table_update_k1
  s1_table_update_k1
  s1_table_drop
  s1_prepare_a
  s1_rollback_prepared_a
  s1_ff
  s1_table_stats

# S1 prepares, S1 aborts prepared
permutation
  s1_table_insert
  s1_table_update_k1
  s1_begin
  # should all be counted
  s1_table_delete_k1
  s1_table_insert_k1
  s1_table_update_k1
  s1_table_update_k1
  s1_table_drop
  s1_prepare_a
  s2_rollback_prepared_a
  s1_ff s2_ff
  s1_table_stats


######################
# SLRU stats tests
######################

# Verify SLRU stats generated in own transaction
permutation
  s1_slru_save_stats
  s1_listen
  s1_begin
  s1_big_notify
  s1_ff
  s1_slru_check_stats
  s1_commit
  s1_slru_check_stats

# Verify SLRU stats generated in separate transaction
permutation
  s1_slru_save_stats
  s1_listen
  s2_big_notify
  s2_ff
  s1_slru_check_stats

# shouldn't see stats yet, not committed
permutation
  s1_slru_save_stats
  s1_listen
  s2_begin
  s2_big_notify
  s2_ff
  s1_slru_check_stats
  s2_commit


### Check the different snapshot consistency models for fixed-amount statistics

permutation
  s1_fetch_consistency_none
  s1_slru_save_stats s1_listen
  s1_begin
  s1_slru_check_stats
  s2_big_notify
  s2_ff
  s1_slru_check_stats
  s1_commit
  s1_slru_check_stats
permutation
  s1_fetch_consistency_cache
  s1_slru_save_stats s1_listen
  s1_begin
  s1_slru_check_stats
  s2_big_notify
  s2_ff
  s1_slru_check_stats
  s1_commit
  s1_slru_check_stats
permutation
  s1_fetch_consistency_snapshot
  s1_slru_save_stats s1_listen
  s1_begin
  s1_slru_check_stats
  s2_big_notify
  s2_ff
  s1_slru_check_stats
  s1_commit
  s1_slru_check_stats

# check that pg_stat_clear_snapshot(), well ...
permutation
  s1_fetch_consistency_none
  s1_slru_save_stats s1_listen
  s1_begin
  s1_slru_check_stats
  s2_big_notify
  s2_ff
  s1_slru_check_stats
  s1_clear_snapshot
  s1_slru_check_stats
  s1_commit
permutation
  s1_fetch_consistency_cache
  s1_slru_save_stats s1_listen
  s1_begin
  s1_slru_check_stats
  s2_big_notify
  s2_ff
  s1_slru_check_stats
  s1_clear_snapshot
  s1_slru_check_stats
  s1_commit
permutation
  s1_fetch_consistency_snapshot
  s1_slru_save_stats s1_listen
  s1_begin
  s1_slru_check_stats
  s2_big_notify
  s2_ff
  s1_slru_check_stats
  s1_clear_snapshot
  s1_slru_check_stats
  s1_commit

# check that a variable-amount stats access caches fixed-amount stat too
permutation
  s1_fetch_consistency_snapshot
  s1_slru_save_stats s1_listen
  s1_begin
  s1_func_stats
  s2_big_notify
  s2_ff
  s1_slru_check_stats
  s1_commit

# and the other way round
permutation
  s1_fetch_consistency_snapshot
  s1_slru_save_stats s1_listen
  s1_begin
  s2_big_notify
  s2_ff
  s1_slru_check_stats
  s2_func_call
  s2_ff
  s1_func_stats
  s1_clear_snapshot
  s1_func_stats
  s1_commit