alter-table-irrelevant.td 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. $ set-sql-timeout duration=1s
  10. #
  11. # Test ALTER TABLE -- tables that are created after the source are irrelevant
  12. #
  13. > CREATE SECRET mysqlpass AS '${arg.mysql-root-password}'
  14. > CREATE CONNECTION mysql_conn TO MYSQL (
  15. HOST mysql,
  16. USER root,
  17. PASSWORD SECRET mysqlpass
  18. )
  19. $ mysql-connect name=mysql url=mysql://root@mysql password=${arg.mysql-root-password}
  20. $ mysql-execute name=mysql
  21. DROP DATABASE IF EXISTS public;
  22. CREATE DATABASE public;
  23. USE public;
  24. CREATE TABLE base_table (f1 INTEGER);
  25. INSERT INTO base_table VALUES (1);
  26. > CREATE SOURCE mz_source
  27. FROM MYSQL CONNECTION mysql_conn
  28. FOR ALL TABLES;
  29. > SELECT * FROM base_table;
  30. 1
  31. # Create "irrelevant" table after the materialized source took a snapshot of the publication
  32. $ mysql-execute name=mysql
  33. CREATE TABLE irrelevant_table (f1 INTEGER);
  34. INSERT INTO irrelevant_table VALUES (1);
  35. INSERT INTO base_table VALUES (2);
  36. # A new table arriving does not prevent queries on existing views for this materialized source
  37. > SELECT * FROM base_table;
  38. 1
  39. 2
  40. # Alter the irrelevant table and insert a row to force a second relation message that would be incompatible
  41. $ mysql-execute name=mysql
  42. ALTER TABLE irrelevant_table ADD COLUMN f2 varchar(2);
  43. ALTER TABLE irrelevant_table DROP COLUMN f1;
  44. INSERT INTO irrelevant_table VALUES ('ab');
  45. # Query still works because the relation was ignored for being irrelevant
  46. > SELECT * FROM base_table;
  47. 1
  48. 2
  49. # Recreate the source and views to verify the irrelevant_table is part of the publication
  50. > DROP SOURCE mz_source CASCADE;
  51. > CREATE SOURCE mz_source
  52. FROM MYSQL CONNECTION mysql_conn
  53. FOR ALL TABLES;
  54. # Check the first view still works
  55. > SELECT * FROM base_table;
  56. 1
  57. 2
  58. # Confirm the second table now has a corresponding view and it has the expected data
  59. > SELECT * FROM irrelevant_table
  60. <null>
  61. ab
  62. # Alter the irrelevant_table now that it is relevant
  63. $ mysql-execute name=mysql
  64. ALTER TABLE irrelevant_table ADD COLUMN f3 char(2);
  65. INSERT INTO irrelevant_table VALUES ('bc', 'de');
  66. > SELECT * FROM base_table;
  67. 1
  68. 2
  69. > SELECT * FROM irrelevant_table
  70. <null>
  71. ab
  72. bc
  73. # Alter in an incompatible way and ensure replication error does not occur
  74. $ mysql-execute name=mysql
  75. ALTER TABLE irrelevant_table DROP COLUMN f2;
  76. INSERT INTO irrelevant_table VALUES ('gh');
  77. > SELECT * FROM base_table;
  78. 1
  79. 2
  80. # Drop source since sanity check restart requires it is in a good state
  81. > DROP SOURCE mz_source CASCADE;