1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
|
################################################################################
# WL#4618 RBR: extended table metadata in the binary log
#
# Below metadata is logged into Table_map_log_event
# - signedness of numeric columns
# - charsets of character columns
# - column names
# - set/enum character sets and string values
# - primary key
#
# The first two are always logged. The others are controlled by system
# variable --binlog-row-metadata
#
# The test will verify if the metadata can be logged and printed by mysqlbinlog
# correctly.
# mysqlbinlog --print-table-metadata will print the extra metadata
################################################################################
--source include/have_debug.inc
--source include/have_binlog_format_row.inc
--source include/test_db_charset_latin1.inc
RESET MASTER;
SET GLOBAL binlog_row_metadata = MINIMAL;
--let $MYSQLD_DATADIR= `select @@datadir`
--let $binlog_file= $MYSQLD_DATADIR/master-bin.000001
--echo #
--echo # Temporal types can be printed correctly
--echo #
CREATE TABLE t1(c_year YEAR, c_date DATE, c_time TIME, c_time_f TIME(3),
c_datetime DATETIME, c_datetime_f DATETIME(3),
c_timestamp TIMESTAMP NOT NULL DEFAULT NOW(),
c_timestamp_f TIMESTAMP(3) DEFAULT "2017-1-1 10:10:10");
INSERT INTO t1(c_year) VALUES(2017);
--source include/print_optional_metadata.inc
DROP TABLE t1;
RESET MASTER;
--echo #
--echo # Geometry types can be printed correctly
--echo #
CREATE TABLE t1 (c_geo GEOMETRY, c_point POINT, c_linestring LINESTRING,
c_polygon POLYGON, c_multi_point MULTIPOINT,
c_multi_linestring MULTILINESTRING, c_multi_polygon MULTIPOLYGON,
c_geometrycollection GEOMETRYCOLLECTION, c_char CHAR(100));
INSERT INTO t1(c_point) VALUES(ST_PointFromText('POINT(10 10)'));
--source include/print_optional_metadata.inc
RESET MASTER;
SET GLOBAL binlog_row_metadata = FULL;
# geometry type is binlogged, the real geometry types are printed
INSERT INTO t1(c_point) VALUES(ST_PointFromText('POINT(10 10)'));
--source include/print_optional_metadata.inc
DROP TABLE t1;
RESET MASTER;
--echo #
--echo # Numeric types can be printed correctly
--echo #
CREATE TABLE t1(c_bit BIT(10), c_bool BOOL, c_smallint SMALLINT,
c_mediumint MEDIUMINT, c_int INT UNSIGNED, c_bigint BIGINT,
c_float FLOAT UNSIGNED, c_double DOUBLE, c_decimal DECIMAL(10, 2));
SET GLOBAL binlog_row_metadata = MINIMAL;
INSERT INTO t1(c_bool) VALUES(1);
--echo # UNSIGNED flag should be printed
--source include/print_optional_metadata.inc
RESET MASTER;
SET GLOBAL binlog_row_metadata = FULL;
INSERT INTO t1(c_bool) VALUES(1);
--source include/print_optional_metadata.inc
DROP TABLE t1;
RESET MASTER;
--echo #
--echo # Character types can be printed correctly
--echo #
CREATE TABLE t1(c_char CHAR(10), c_varchar VARCHAR(500),
c_tinytext TINYTEXT, c_text TEXT,
c_mediumtext MEDIUMTEXT, c_longtext LONGTEXT CHARSET utf8);
SET GLOBAL binlog_row_metadata = MINIMAL;
INSERT INTO t1(c_char) VALUES("1");
# Charset set is printed with default charset
--source include/print_optional_metadata.inc
RESET MASTER;
SET GLOBAL binlog_row_metadata = FULL;
INSERT INTO t1(c_char) VALUES("1");
--source include/print_optional_metadata.inc
DROP TABLE t1;
RESET MASTER;
--echo #
--echo # Column names with non-ascii characters and escape characters can be printed correctly
--echo #
set names utf8;
CREATE TABLE t1(`åäö表\a'``"` INT);
SHOW CREATE TABLE t1;
INSERT INTO t1 VALUES(1);
--source include/print_optional_metadata.inc
DROP TABLE t1;
RESET MASTER;
--echo #
--echo # Charsets can be printed correctly
--echo #
CREATE TABLE t1(c_char_utf8 CHAR(10) CHARSET utf8,
c_varchar_utf8 VARCHAR(10) CHARSET utf8,
c_text_utf8 TEXT CHARSET utf8);
INSERT INTO t1 VALUES("1", "2", "3");
# Charset set is printed with Default charset
--source include/print_optional_metadata.inc
DROP TABLE t1;
RESET MASTER;
# Test collation number less than 250 and collation number greater than 250
CREATE TABLE t1(c_utf8mb4_520 CHAR(10) CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci,
c_utf8mb4_0900 VARCHAR(10) CHARSET utf8mb4 COLLATE utf8mb4_polish_ci,
c_utf8mb4_def TEXT CHARSET utf8mb4);
INSERT INTO t1 VALUES("1", "2", "3");
# Charset set is printed without default charset
--source include/print_optional_metadata.inc
DROP TABLE t1;
RESET MASTER;
--echo #
--echo # Blob and binary columns can be printed correctly
--echo #
CREATE TABLE t1(c_binary BINARY(10), c_varbinary VARBINARY(10),
c_tinyblob TINYBLOB, c_blob BLOB,
c_mediumblob MEDIUMBLOB, c_longblob LONGBLOB);
INSERT INTO t1 VALUES("1", "2", "3", "4", "5", "6");
--source include/print_optional_metadata.inc
DROP TABLE t1;
RESET MASTER;
--echo #
--echo # Verify that SET string values and character sets can be printed correctly
--echo #
set names utf8;
CREATE TABLE t1(
c_set_1 SET("set1_v1_å", "set1_v2_ä", "set1_v3_ö"),
c_set_2 SET("set2_v1_å", "set2_v2_ä", "set2_v3_ö") CHARACTER SET latin1,
c_set_4 SET("set3_v1_å", "set3_v2_ä", "set3_v3_ö") CHARACTER SET swe7 COLLATE swe7_bin);
SET GLOBAL binlog_row_metadata = MINIMAL;
INSERT INTO t1 VALUES("set1_v1_å", "set2_v3_ö", "set3_v1_å");
--source include/print_optional_metadata.inc
RESET MASTER;
SET GLOBAL binlog_row_metadata = FULL;
INSERT INTO t1 VALUES("set1_v1_å", "set2_v3_ö", "set3_v1_å");
--source include/print_optional_metadata.inc
DROP TABLE t1;
RESET MASTER;
--echo #
--echo # Verify that ENUM string values and character sets can be printed correctly
--echo #
CREATE TABLE t1(
c_enum_1 ENUM("enum1_v1_å", "enum1_v2_ä", "enum1_v3_ö"),
c_enum_3 ENUM("enum2_v1_å", "enum2_v2_ä", "enum2_v3_ö") CHARACTER SET latin1,
c_enum_4 ENUM("enum3_v1_å", "enum3_v2_ä", "enum3_v3_ö") CHARACTER SET swe7 COLLATE swe7_bin);
SET GLOBAL binlog_row_metadata = MINIMAL;
INSERT INTO t1 VALUES("enum1_v1_å", "enum2_v3_ö", "enum3_v1_å");
--source include/print_optional_metadata.inc
RESET MASTER;
SET GLOBAL binlog_row_metadata = FULL;
INSERT INTO t1 VALUES("enum1_v1_å", "enum2_v3_ö", "enum3_v1_å");
--source include/print_optional_metadata.inc
DROP TABLE t1;
RESET MASTER;
--echo #
--echo # Verify that explicit NOT NULL can be printed correctly
--echo #
CREATE TABLE t1(c_not_null1 INT NOT NULL, c_null1 INT, c_not_null2 INT NOT NULL,
c_null2 INT);
INSERT INTO t1 VALUES(1, 2, 3, 4);
--source include/print_optional_metadata.inc
DROP TABLE t1;
RESET MASTER;
--echo #
--echo # Verify that primary key can be printed correctly
--echo #
CREATE TABLE t1(c_key1 INT, c_key3 INT, c_not_key INT, c_key2 INT,
PRIMARY KEY(c_key1, c_key2, c_key3));
INSERT INTO t1 VALUES(1, 2, 3, 4);
--let $print_primary_key= 1
--source include/print_optional_metadata.inc
DROP TABLE t1;
RESET MASTER;
# Key has prefix
CREATE TABLE t1(c_key1 CHAR(100), c_key3 CHAR(100), c_not_key INT, c_key2 CHAR(10),
PRIMARY KEY(c_key1(5), c_key2, c_key3(10)));
INSERT INTO t1 VALUES("1", "2", 3, "4");
--source include/print_optional_metadata.inc
RESET MASTER;
# Primary key should not be printed
SET GLOBAL binlog_row_metadata = MINIMAL;
INSERT INTO t1 VALUES("2", "2", 3, "4");
--source include/print_optional_metadata.inc
RESET MASTER;
--echo #
--echo # Coverage test: Print column index instead of column name if column name
--echo # is not binlogged.
--echo #
SET GLOBAL binlog_row_metadata = FULL;
SET SESSION debug_dbug = 'd, dont_log_column_name';
INSERT INTO t1 VALUES("3", "2", 3, "4");
--source include/print_optional_metadata.inc
--let $print_primary_key=
DROP TABLE t1;
RESET MASTER;
--echo #
--echo # Coverage test: Inject an invalid column type
--echo #
CREATE TABLE t1(c1 int, c2 BLOB);
SET SESSION debug_dbug = 'd,inject_invalid_column_type';
INSERT INTO t1 VALUES(1, "a");
# It prints an error
--source include/print_optional_metadata.inc
RESET MASTER;
--echo #
--echo # Coverage test: Inject an invalid BLOB metadata
--echo #
--let $start_pos= query_get_value(SHOW MASTER STATUS, Position, 1)
SET SESSION debug_dbug = 'd,inject_invalid_blob_size';
INSERT INTO t1 VALUES(2, "b");
# The invalid metadata will case assertion failure on Write_rows_log_event
# So we need to stop mysqlbinlog before reading Write_rows_log_event.
--let $stop_position= query_get_value(SHOW BINLOG EVENTS FROM $start_pos LIMIT 4, Pos, 4)
--source include/print_optional_metadata.inc
--echo #
--echo # Coverage test: Inject an invalid Geometry type
--echo #
DROP TABLE t1;
CREATE TABLE t1(c_geometry GEOMETRY, c_point POINT, c_multilinestring MULTILINESTRING);
RESET MASTER;
--let $start_pos= query_get_value(SHOW MASTER STATUS, Position, 1)
SET SESSION debug_dbug = 'd,inject_invalid_geometry_type';
INSERT INTO t1(c_point) VALUES(ST_PointFromText('POINT(10 10)'));
# The invalid metadata will case assertion failure on Write_rows_log_event
# So we need to stop mysqlbinlog before reading Write_rows_log_event.
--let $stop_position= query_get_value(SHOW BINLOG EVENTS FROM $start_pos LIMIT 4, Pos, 4)
--source include/print_optional_metadata.inc
DROP TABLE t1;
RESET MASTER;
--echo #
--echo # Comptibility Test: Verify mysqlbinlog can print OLD table_map_log_event
--echo # without any optional metadata
--echo #
CREATE TABLE t1(c_int INT, c_tiny_int_unsigned TINYINT UNSIGNED,
c_binary BINARY(10), c_text TEXT, c_point POINT);
SET session debug_dbug='d,simulate_no_optional_metadata';
INSERT INTO t1(c_int) VALUES(1);
# TINYINT will be printed without UNSIGNED flag,
# CHAR will be printed as BINARY(10)
# POINT will be printed as GEOMETRY
--let $stop_position=
--source include/print_optional_metadata.inc
DROP TABLE t1;
RESET MASTER;
--echo #
--echo # Simulate error on initializing charset and primary key metadata
--echo #
CREATE TABLE t1(c1 char(10) PRIMARY KEY);
SET session debug_dbug='d,simulate_init_charset_field_error';
INSERT INTO t1 VALUES("a");
SET GLOBAL binlog_row_metadata = FULL;
SET session debug_dbug='d,simulate_init_primary_key_field_error';
INSERT INTO t1 VALUES("b");
--let $print_primary_key= 1
--source include/print_optional_metadata.inc
SET SESSION debug_dbug = '';
SET GLOBAL binlog_row_metadata = NO_LOG;
DROP TABLE t1;
RESET MASTER;
--source include/test_db_charset_restore.inc
|