dataflow-cleanup.td 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. # This test confirms that dataflow operators are cleaned up when they are not
  10. # needed anymore.
  11. #
  12. # This test relies on testdrive's automatic retries, since it queries
  13. # introspection sources that take a while to update.
  14. # Introspection subscribes add noise to the introspection sources, so disable them.
  15. $ postgres-execute connection=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
  16. ALTER SYSTEM SET enable_introspection_subscribes = false
  17. # Create a clean replica to inspect dataflow state on.
  18. > DROP CLUSTER IF EXISTS test
  19. > CREATE CLUSTER test REPLICAS (r1 (SIZE '1', INTROSPECTION INTERVAL '10ms'))
  20. > SET cluster = test
  21. > SELECT count(*) > 0 FROM mz_introspection.mz_dataflow_operators
  22. false
  23. # Verify that an index dataflow is cleaned up when the index is dropped.
  24. > CREATE TABLE t (a int)
  25. > CREATE INDEX test_index ON t (a)
  26. > SELECT count(*) > 0 FROM mz_introspection.mz_dataflow_operators
  27. true
  28. > DROP INDEX test_index
  29. > SELECT count(*) > 0 FROM mz_introspection.mz_dataflow_operators
  30. false
  31. # Verify that an index dataflow is cleaned up when its input advances to the
  32. # empty frontier.
  33. # To make sure that we don't query mz_dataflow_operators before the dataflow
  34. # was created, we query the index once and then wait for a bit as well.
  35. > CREATE VIEW constant_view AS SELECT generate_series(1, 1000) AS a
  36. > CREATE INDEX test_index ON constant_view (a)
  37. > SELECT count(*) FROM constant_view
  38. 1000
  39. > SELECT mz_unsafe.mz_sleep(1)
  40. <null>
  41. > SELECT count(*) > 0 FROM mz_introspection.mz_dataflow_operators
  42. false
  43. > DROP INDEX test_index
  44. > SELECT count(*) > 0 FROM mz_introspection.mz_dataflow_operators
  45. false
  46. # Verify that an MV dataflow is cleaned up when the MV is dropped.
  47. > CREATE MATERIALIZED VIEW test_mv AS SELECT a FROM t
  48. > SELECT count(*) > 0 FROM mz_introspection.mz_dataflow_operators
  49. true
  50. > DROP MATERIALIZED VIEW test_mv
  51. > SELECT count(*) > 0 FROM mz_introspection.mz_dataflow_operators
  52. false
  53. # Verify that an MV dataflow is cleaned up when its input advances to the
  54. # empty frontier.
  55. # To make sure that we don't query mz_dataflow_operators before the dataflow
  56. # was created, we query the MV once and then wait for a bit as well.
  57. > CREATE MATERIALIZED VIEW test_mv AS SELECT generate_series(1, 1000)
  58. > SELECT count(*) FROM test_mv
  59. 1000
  60. > SELECT mz_unsafe.mz_sleep(1)
  61. <null>
  62. > SELECT count(*) > 0 FROM mz_introspection.mz_dataflow_operators
  63. false
  64. > DROP MATERIALIZED VIEW test_mv
  65. > SELECT count(*) > 0 FROM mz_introspection.mz_dataflow_operators
  66. false
  67. # Regression test for https://github.com/MaterializeInc/database-issues/issues/4712
  68. > CREATE CLUSTER lgtpch_cluster_cleanup SIZE '1';
  69. > CREATE SOURCE lgtpch IN CLUSTER lgtpch_cluster_cleanup FROM LOAD GENERATOR TPCH (SCALE FACTOR 0.1, UP TO 100);
  70. > CREATE TABLE customer FROM SOURCE lgtpch (REFERENCE customer);
  71. > CREATE TABLE lineitem FROM SOURCE lgtpch (REFERENCE lineitem);
  72. > CREATE TABLE nation FROM SOURCE lgtpch (REFERENCE nation);
  73. > CREATE TABLE orders FROM SOURCE lgtpch (REFERENCE orders);
  74. > CREATE TABLE part FROM SOURCE lgtpch (REFERENCE part);
  75. > CREATE TABLE partsupp FROM SOURCE lgtpch (REFERENCE partsupp);
  76. > CREATE TABLE region FROM SOURCE lgtpch (REFERENCE region);
  77. > CREATE TABLE supplier FROM SOURCE lgtpch (REFERENCE supplier);
  78. > CREATE MATERIALIZED VIEW q14 AS
  79. SELECT
  80. 100.00 * sum(case
  81. when p_type like 'PROMO%'
  82. then l_extendedprice * (1 - l_discount)
  83. else 0
  84. end) / sum(l_extendedprice * (1 - l_discount)) AS promo_revenue
  85. FROM
  86. lineitem,
  87. part
  88. WHERE
  89. l_partkey = p_partkey
  90. AND l_shipdate >= DATE '1995-09-01'
  91. AND l_shipdate < DATE '1995-09-01' + INTERVAL '1' month
  92. > SELECT count(*) > 0 FROM q14
  93. true
  94. > SELECT mz_unsafe.mz_sleep(1)
  95. <null>
  96. > SELECT count(*) FROM mz_introspection.mz_dataflow_operators
  97. 0
  98. > DROP MATERIALIZED VIEW q14
  99. > SELECT count(*) FROM mz_introspection.mz_dataflow_operators
  100. 0