You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
3.9 KiB

  1. # ==== Purpose ====
  2. #
  3. # Test if statements used temporary tables are binlogged correctly
  4. #
  5. # ==== Method ====
  6. #
  7. # Use two connections, use temporary tables on both of them, and by
  8. # switching connections between statements, the test can check if the
  9. # statements are logged with the correct thread id.
  10. #
  11. # The statements current tested include:
  12. # CREATE TEMPORARY TABLE
  13. # CREATE TEMPORARY TABLE LIKE
  14. # INSERT
  15. # REPLACE
  16. # UPDATE
  17. # INSERT SELECT
  18. # TRUNCATE
  19. #
  20. # Note: When adding new query statements, please add them between the
  21. # two 'flush logs'. And aslo please make sure the connection is
  22. # switched between each statement.
  23. #
  24. # ==== Related bugs ====
  25. #
  26. # BUG#35583 mysqlbinlog replay fails with ERROR 1146 when temp tables are used
  27. #
  28. source include/have_log_bin.inc;
  29. source include/have_binlog_format_mixed_or_statement.inc;
  30. connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,);
  31. connect (master1,127.0.0.1,root,,test,$MASTER_MYPORT,);
  32. RESET MASTER;
  33. create table foo (a int);
  34. flush logs;
  35. connection master;
  36. create temporary table tmp1_foo like foo;
  37. connection master1;
  38. create temporary table tmp2_foo (a int);
  39. connection master;
  40. insert into tmp1_foo values (1), (2), (3), (4);
  41. connection master1;
  42. replace into tmp2_foo values (1), (2), (3), (4);
  43. connection master;
  44. update tmp1_foo set a=2*a-1;
  45. connection master1;
  46. update tmp2_foo set a=2*a;
  47. connection master;
  48. delete from tmp1_foo where a < 5;
  49. connection master1;
  50. delete from tmp2_foo where a < 5;
  51. connection master;
  52. insert into foo select * from tmp1_foo;
  53. connection master1;
  54. insert into foo select * from tmp2_foo;
  55. connection master;
  56. truncate table tmp1_foo;
  57. connection master1;
  58. truncate table tmp2_foo;
  59. flush logs;
  60. connection default;
  61. select * from foo;
  62. # prepare for the replay
  63. drop table foo;
  64. create table foo (a int);
  65. # replay from binary log
  66. let $MYSQLD_DATADIR= `select @@datadir`;
  67. exec $MYSQL_BINLOG $MYSQLD_DATADIR/master-bin.000002 | $MYSQL;
  68. select * from foo;
  69. # clean up
  70. drop table foo;
  71. #################################################################
  72. # BUG#51226
  73. #################################################################
  74. RESET MASTER;
  75. -- let $dbname=b51226
  76. connect (con1,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
  77. connect (con2,localhost,root,,test,$MASTER_MYPORT,$MASTER_MYSOCK);
  78. #
  79. # action: on con1 create the database and the tmp table
  80. #
  81. -- connection con1
  82. -- eval create database $dbname
  83. -- eval use $dbname
  84. create temporary table t1(i int);
  85. #
  86. # action: on con1 create the tmp table
  87. #
  88. -- connection con2
  89. -- eval use $dbname
  90. create temporary table t1(i int);
  91. # action: at this point, the last event binlogged contains the
  92. # pseudo_thread_id from con2. So now we switch to con1, issue
  93. # a statement that fails and close the connection (which logs
  94. # implicitely a DROP TEMPORARY TABLE).
  95. #
  96. # Before the patch this would not log con1's pseudo_thread_id
  97. # because the failing statement would reset THD context
  98. # (unsetting the thread_specific_used flag, and consequently,
  99. # causing the DROP event to be logged without pseudo_thread_id
  100. # in its header).
  101. -- connection con1
  102. -- error 1050
  103. create temporary table t1(i int);
  104. -- disconnect con1
  105. -- connection default
  106. -- let $wait_binlog_event= DROP
  107. -- source include/wait_for_binlog_event.inc
  108. # action: insert in the t1. This would cause the the test to fail,
  109. # because when replaying the binlog the previous implicit drop
  110. # temp table would have been executed under the wrong
  111. # pseudo_thread_id, dropping the tmp table on con2.
  112. -- connection con2
  113. insert into t1 values(1);
  114. -- disconnect con2
  115. -- connection default
  116. -- let $wait_binlog_event= DROP
  117. -- source include/wait_for_binlog_event.inc
  118. -- eval DROP DATABASE $dbname
  119. FLUSH LOGS;
  120. # assertion: assert that when replaying the binary log will succeed,
  121. # instead of failing with "Table 'XXX.YYY' doesn't exist"
  122. -- let $MYSQLD_DATADIR= `select @@datadir`
  123. -- exec $MYSQL_BINLOG $MYSQLD_DATADIR/master-bin.000001 | $MYSQL