setup.td 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. $ postgres-execute connection=postgres://mz_system:materialize@${testdrive.materialize-internal-sql-addr}
  10. ALTER SYSTEM SET unsafe_enable_unorchestrated_cluster_replicas = true;
  11. # Create a cluster that we can make unavailable.
  12. > CREATE CLUSTER compute REPLICAS (
  13. r1 (
  14. STORAGECTL ADDRESSES ['clusterd1:2100'],
  15. COMPUTECTL ADDRESSES ['clusterd1:2101'],
  16. STORAGE ADDRESSES ['clusterd1:2103'],
  17. COMPUTE ADDRESSES ['clusterd1:2102'],
  18. WORKERS 1
  19. )
  20. )
  21. # Create a serving cluster that should still respond to queries.
  22. > CREATE CLUSTER serving SIZE '1'
  23. # Create an MV maintained on the compute cluster and indexed on the serving
  24. # cluster. It's important that the MV reads from an index too, to reproduce
  25. # the bug.
  26. > CREATE TABLE source (a int)
  27. > CREATE INDEX source_idx IN CLUSTER compute ON source (a)
  28. > CREATE MATERIALIZED VIEW mv1 IN CLUSTER compute AS SELECT * FROM source
  29. > CREATE INDEX mv1_idx IN CLUSTER serving ON mv1 (a)
  30. # Create a second MV that transitively depends on several indexes, to also test
  31. # this case.
  32. > CREATE VIEW v1 AS SELECT a + 1 AS b FROM source;
  33. > CREATE INDEX v1_idx IN CLUSTER compute ON v1 (b);
  34. > CREATE VIEW v2 AS SELECT b + 1 AS c FROM v1;
  35. > CREATE INDEX v2_idx IN CLUSTER compute ON v2 (c);
  36. > CREATE VIEW v3 AS SELECT c + 1 AS d FROM v2;
  37. > CREATE INDEX v3_idx IN CLUSTER compute ON v3 (d);
  38. > CREATE MATERIALIZED VIEW mv2 IN CLUSTER compute AS SELECT * FROM v3
  39. > CREATE INDEX mv2_idx IN CLUSTER serving ON mv2 (d)
  40. # ... and an MV that depends on multiple indexes directly.
  41. > CREATE VIEW v4 AS SELECT a + 1 AS e FROM source;
  42. > CREATE INDEX v4_idx IN CLUSTER compute ON v4 (e);
  43. > CREATE VIEW v5 AS SELECT a + 1 AS f FROM source;
  44. > CREATE INDEX v5_idx IN CLUSTER compute ON v5 (f);
  45. > CREATE MATERIALIZED VIEW mv3 IN CLUSTER compute AS SELECT e + f AS g FROM v4, v5
  46. > CREATE INDEX mv3_idx IN CLUSTER serving ON mv3 (g)
  47. # Let things hydrate.
  48. > INSERT INTO source VALUES (1)
  49. > SET cluster = serving
  50. > SELECT * FROM mv1
  51. 1
  52. > SELECT * FROM mv2
  53. 4
  54. > SELECT * FROM mv3
  55. 4