diff --git a/test/testdrive/statistics-cpu.td b/test/testdrive/statistics-cpu.td new file mode 100644 index 0000000000000..7b1af9861c892 --- /dev/null +++ b/test/testdrive/statistics-cpu.td @@ -0,0 +1,78 @@ +# Copyright Materialize, Inc. and contributors. All rights reserved. +# +# Use of this software is governed by the Business Source License +# included in the LICENSE file at the root of this repository. +# +# As of the Change Date specified in that file, in accordance with +# the Business Source License, use of this software will be governed +# by the Apache License, Version 2.0. + +# Reproducer for database-issues#8893 + +$ postgres-execute connection=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr} +ALTER SYSTEM SET storage_statistics_collection_interval = 1000 +ALTER SYSTEM SET storage_statistics_interval = 2000 + +> CREATE CLUSTER stats_cluster SIZE '4-4' + +> CREATE SECRET pgpass AS 'postgres' +> CREATE CONNECTION pg TO POSTGRES ( + HOST postgres, + DATABASE postgres, + USER postgres, + PASSWORD SECRET pgpass + ) + +$ postgres-execute connection=postgres://postgres:postgres@postgres +ALTER USER postgres WITH replication; +DROP SCHEMA IF EXISTS public CASCADE; +DROP PUBLICATION IF EXISTS mz_source; +CREATE SCHEMA public; + +CREATE TABLE t1 (f1 TEXT); +ALTER TABLE t1 REPLICA IDENTITY FULL; +INSERT INTO t1 VALUES ('one'); +INSERT INTO t1 VALUES ('two'); + +CREATE PUBLICATION mz_source FOR ALL TABLES; + +> CREATE SOURCE mz_source + IN CLUSTER stats_cluster + FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source'); + +$ set-from-sql var=previous-offset-committed +SELECT + (SUM(u.offset_committed))::text + FROM mz_sources s + JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id + WHERE s.name IN ('mz_source') + +> CREATE TABLE t1 FROM SOURCE mz_source (REFERENCE t1); + +> SELECT COUNT(*) > 0 FROM t1; +true + +$ postgres-execute connection=postgres://postgres:postgres@postgres +INSERT INTO t1 VALUES ('three'); + +> SELECT + s.name, + SUM(u.offset_committed) > ${previous-offset-committed}, + SUM(u.offset_known) >= SUM(u.offset_committed), + SUM(u.snapshot_records_known), + SUM(u.snapshot_records_staged) + FROM mz_sources s + JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id + WHERE s.name IN ('mz_source') + GROUP BY s.name + ORDER BY s.name +mz_source true true 2 2 + +$ set-from-sql var=pre-restart-offset-committed +SELECT + (SUM(u.offset_committed))::text + FROM mz_sources s + JOIN mz_internal.mz_source_statistics_raw u ON s.id = u.id + WHERE s.name IN ('mz_source') + +> SELECT mz_unsafe.mz_sleep(3600);