index-source-stuck.td 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. > DROP CLUSTER IF EXISTS cluster1 CASCADE;
  10. > DROP CLUSTER IF EXISTS cluster2 CASCADE;
  11. > CREATE CLUSTER cluster1 REPLICAS (replica1 (SIZE '1'));
  12. > CREATE CLUSTER cluster2 REPLICAS (replica1 (SIZE '1'));
  13. > CREATE SOURCE src IN CLUSTER cluster1 FROM LOAD GENERATOR counter (UP TO 100);
  14. > CREATE MATERIALIZED VIEW mv IN CLUSTER cluster2 AS SELECT * FROM src;
  15. > SET cluster = cluster2;
  16. # Prevent us from getting stuck, see database-issues#8300
  17. > SELECT min(counter) FROM src
  18. 1
  19. > SELECT min(counter) FROM mv
  20. 1
  21. # Dropping the replica will make the load generator be out of date from now on
  22. > DROP CLUSTER REPLICA cluster1.replica1;
  23. # Wait a bit to let Mz realize that
  24. > SELECT mz_unsafe.mz_sleep(3)
  25. <null>
  26. # Strict serializable is expected to fail, but serializable isolation should still be able to return (out of date) results
  27. > SET transaction_isolation = serializable;
  28. # Should return instantly since we have selected serializable isolation
  29. > SELECT min(counter) FROM src;
  30. 1
  31. # Should return instantly, even inside of a transaction
  32. # > BEGIN
  33. # > SELECT * FROM src;
  34. # > COMMIT
  35. # Should return instantly since it only uses the materialized view and we have selected serializable isolation
  36. > SELECT min(counter) FROM mv;
  37. 1
  38. # Should return instantly, even inside of a transaction
  39. # TODO(def-): Enable once incident 78 is fixed:
  40. # > BEGIN
  41. # > SELECT * FROM mv;
  42. # > COMMIT
  43. > CREATE INDEX IN CLUSTER cluster2 ON mv (counter);
  44. # Check that index is actually used
  45. ? EXPLAIN OPTIMIZED PLAN AS VERBOSE TEXT FOR SELECT min(counter) FROM mv;
  46. Explained Query:
  47. With
  48. cte l0 =
  49. Reduce aggregates=[min(#0{counter})]
  50. ReadIndex on=mv mv_counter_idx=[*** full scan ***]
  51. Return
  52. Union
  53. Get l0
  54. Map (null)
  55. Union
  56. Negate
  57. Project ()
  58. Get l0
  59. Constant
  60. - ()
  61. Used Indexes:
  62. - materialize.public.mv_counter_idx (*** full scan ***)
  63. Target cluster: cluster2
  64. > SELECT 1
  65. 1
  66. # Should return instantly since it only uses the index and we have selected serializable isolation
  67. > SELECT min(counter) FROM mv;
  68. 1
  69. # TODO(def-): Enable once incident 78 is fixed:
  70. # > BEGIN
  71. # > SELECT * FROM mv;
  72. # > COMMIT
  73. > DROP CLUSTER IF EXISTS cluster1 CASCADE;
  74. > DROP CLUSTER IF EXISTS cluster2 CASCADE;