alter-table-irrelevant.td 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 FROM MYSQL CONNECTION mysql_conn;
  27. > CREATE TABLE base_table FROM SOURCE mz_source (REFERENCE public.base_table);
  28. > SELECT * FROM base_table;
  29. 1
  30. # Create "irrelevant" table after the materialized source took a snapshot of the publication
  31. $ mysql-execute name=mysql
  32. CREATE TABLE irrelevant_table (f1 INTEGER);
  33. INSERT INTO irrelevant_table VALUES (1);
  34. INSERT INTO base_table VALUES (2);
  35. # A new table arriving does not prevent queries on existing views for this materialized source
  36. > SELECT * FROM base_table;
  37. 1
  38. 2
  39. # Alter the irrelevant table and insert a row to force a second relation message that would be incompatible
  40. $ mysql-execute name=mysql
  41. ALTER TABLE irrelevant_table ADD COLUMN f2 varchar(2);
  42. ALTER TABLE irrelevant_table DROP COLUMN f1;
  43. INSERT INTO irrelevant_table VALUES ('ab');
  44. # Query still works because the relation was ignored for being irrelevant
  45. > SELECT * FROM base_table;
  46. 1
  47. 2
  48. # Recreate the source and views to verify the irrelevant_table is part of the publication
  49. > DROP SOURCE mz_source CASCADE;
  50. > CREATE SOURCE mz_source FROM MYSQL CONNECTION mysql_conn;
  51. > CREATE TABLE base_table FROM SOURCE mz_source (REFERENCE public.base_table);
  52. > CREATE TABLE irrelevant_table FROM SOURCE mz_source (REFERENCE public.irrelevant_table);
  53. # Check the first view still works
  54. > SELECT * FROM base_table;
  55. 1
  56. 2
  57. # Confirm the second table now has a corresponding view and it has the expected data
  58. > SELECT * FROM irrelevant_table
  59. <null>
  60. ab
  61. # Alter the irrelevant_table now that it is relevant
  62. $ mysql-execute name=mysql
  63. ALTER TABLE irrelevant_table ADD COLUMN f3 char(2);
  64. INSERT INTO irrelevant_table VALUES ('bc', 'de');
  65. > SELECT * FROM base_table;
  66. 1
  67. 2
  68. > SELECT * FROM irrelevant_table
  69. <null>
  70. ab
  71. bc
  72. # Alter in an incompatible way and ensure replication error does not occur
  73. $ mysql-execute name=mysql
  74. ALTER TABLE irrelevant_table DROP COLUMN f2;
  75. INSERT INTO irrelevant_table VALUES ('gh');
  76. > SELECT * FROM base_table;
  77. 1
  78. 2
  79. # Drop source since sanity check restart requires it is in a good state
  80. > DROP SOURCE mz_source CASCADE;