mirror of
https://github.com/MariaDB/server.git
synced 2025-01-21 06:22:28 +01:00
4102363f37
"load data" statements were written to the binlog as a mix of the original statement and bits recreated from parse-info. This relied on implementation details and broke with IGNORE_SPACES and versioned comments. We now completely resynthesize the query for LOAD DATA for binlog (which among other things normalizes them somewhat with regard to case, spaces, etc.). We have already parsed the query properly, so we make use of that rather than mix-and-match string literals and parsed items. This should make us safe with regard to versioned comments, even those spanning multiple tokens. Also no longer affected by IGNORE_SPACES. mysql-test/r/mysqlbinlog.result: LOAD DATA INFILE normalized mysql-test/suite/binlog/r/binlog_killed_simulate.result: LOAD DATA INFILE normalized mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result: LOAD DATA INFILE normalized mysql-test/suite/binlog/r/binlog_stm_blackhole.result: LOAD DATA INFILE normalized mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result: LOAD DATA INFILE normalized mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result: LOAD DATA INFILE normalized mysql-test/suite/rpl/r/rpl_loaddata.result: LOAD DATA INFILE normalized mysql-test/suite/rpl/r/rpl_loaddata_fatal.result: LOAD DATA INFILE normalized; offsets adjusted to reflect that mysql-test/suite/rpl/r/rpl_loaddata_map.result: LOAD DATA INFILE normalized mysql-test/suite/rpl/r/rpl_loaddatalocal.result: test for #43746 - trying to break LOAD DATA part of parser mysql-test/suite/rpl/r/rpl_stm_log.result: LOAD DATA INFILE normalized mysql-test/suite/rpl/t/rpl_loaddatalocal.test: try to break the LOAD DATA part of the parser (test for #43746) mysql-test/t/mysqlbinlog.test: LOAD DATA INFILE normalized; adjust offsets to reflect that sql/log_event.cc: clean up Load_log_event::print_query and friends so they don't print excess spaces. add support for printing charset names to print_query. sql/log_event.h: We already have three places where we synthesize LOAD DATA queries. Better use one of those! sql/sql_lex.h: When binlogging LOAD DATA statements, we make up the statement to be logged (from the parse-info, rather than substrings of the original query) now. Consequently, we no longer need (string-) pointers into the original query. sql/sql_load.cc: Completely rewrote write_execute_load_query_log_event() to synthesize the LOAD DATA statement wholesale, rather than piece it together from synthesized bits and literal excerpts from the original query. This will not only give us a nice, normalized statement (all uppercase, no excess spaces, etc.), it will also handle comments, including versioned comments right, which is certainly more than we can say about the previous incarnation. sql/sql_yacc.yy: We're no longer assembling LOAD DATA statements from bodyparts of the original query, so some bookkeeping in the parser can go.
170 lines
5.5 KiB
Text
170 lines
5.5 KiB
Text
# See if "LOAD DATA LOCAL INFILE" is well replicated
|
|
# (LOAD DATA LOCAL INFILE is not written to the binlog
|
|
# the same way as LOAD DATA INFILE : Append_blocks are smaller).
|
|
# In MySQL 4.0 <4.0.12 there were 2 bugs with LOAD DATA LOCAL INFILE :
|
|
# - the loaded file was not written entirely to the master's binlog,
|
|
# only the first 4KB, 8KB or 16KB usually.
|
|
# - the loaded file's first line was not written entirely to the
|
|
# master's binlog (1st char was absent)
|
|
source include/master-slave.inc;
|
|
|
|
create table t1(a int);
|
|
let $1=10000;
|
|
disable_query_log;
|
|
set SQL_LOG_BIN=0;
|
|
while ($1)
|
|
{
|
|
insert into t1 values(1);
|
|
dec $1;
|
|
}
|
|
set SQL_LOG_BIN=1;
|
|
enable_query_log;
|
|
let $MYSQLD_DATADIR= `select @@datadir`;
|
|
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
|
|
eval select * into outfile '$MYSQLD_DATADIR/rpl_loaddatalocal.select_outfile' from t1;
|
|
#This will generate a 20KB file, now test LOAD DATA LOCAL
|
|
truncate table t1;
|
|
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
|
|
eval load data local infile '$MYSQLD_DATADIR/rpl_loaddatalocal.select_outfile' into table t1;
|
|
--remove_file $MYSQLD_DATADIR/rpl_loaddatalocal.select_outfile
|
|
save_master_pos;
|
|
connection slave;
|
|
sync_with_master;
|
|
select a,count(*) from t1 group by a;
|
|
connection master;
|
|
drop table t1;
|
|
save_master_pos;
|
|
connection slave;
|
|
sync_with_master;
|
|
|
|
# End of 4.1 tests
|
|
|
|
#
|
|
# Now let us test how well we replicate LOAD DATA LOCAL in situation when
|
|
# we met duplicates in tables to which we are adding rows.
|
|
# (It supposed that LOAD DATA LOCAL ignores such errors)
|
|
#
|
|
connection master;
|
|
create table t1(a int);
|
|
insert into t1 values (1), (2), (2), (3);
|
|
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
|
|
eval select * into outfile '$MYSQLD_DATADIR/rpl_loaddatalocal.select_outfile' from t1;
|
|
drop table t1;
|
|
create table t1(a int primary key);
|
|
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
|
|
eval load data local infile '$MYSQLD_DATADIR/rpl_loaddatalocal.select_outfile' into table t1;
|
|
--remove_file $MYSQLD_DATADIR/rpl_loaddatalocal.select_outfile
|
|
SELECT * FROM t1 ORDER BY a;
|
|
save_master_pos;
|
|
connection slave;
|
|
sync_with_master;
|
|
SELECT * FROM t1 ORDER BY a;
|
|
connection master;
|
|
drop table t1;
|
|
save_master_pos;
|
|
connection slave;
|
|
sync_with_master;
|
|
|
|
|
|
#
|
|
# Bug22504 load data infile sql statement in replication architecture get error
|
|
#
|
|
--echo ==== Bug22504 Initialize ====
|
|
|
|
--echo [on master]
|
|
--connection master
|
|
|
|
SET sql_mode='ignore_space';
|
|
CREATE TABLE t1(a int);
|
|
insert into t1 values (1), (2), (3), (4);
|
|
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
|
|
eval select * into outfile '$MYSQLD_DATADIR/rpl_loaddatalocal.select_outfile' from t1;
|
|
truncate table t1;
|
|
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
|
|
eval load data local infile '$MYSQLD_DATADIR/rpl_loaddatalocal.select_outfile' into table t1;
|
|
--remove_file $MYSQLD_DATADIR/rpl_loaddatalocal.select_outfile
|
|
SELECT * FROM t1 ORDER BY a;
|
|
|
|
--echo [on slave]
|
|
sync_slave_with_master;
|
|
SELECT * FROM t1 ORDER BY a;
|
|
|
|
--echo ==== Clean up ====
|
|
|
|
--echo [on master]
|
|
connection master;
|
|
DROP TABLE t1;
|
|
|
|
--echo [on slave]
|
|
sync_slave_with_master;
|
|
|
|
--echo
|
|
--echo Bug #43746:
|
|
--echo "return wrong query string when parse 'load data infile' sql statement"
|
|
--echo
|
|
|
|
--echo [master]
|
|
connection master;
|
|
let $MYSQLD_DATADIR= `select @@datadir`;
|
|
SELECT @@SESSION.sql_mode INTO @old_mode;
|
|
|
|
SET sql_mode='ignore_space';
|
|
|
|
CREATE TABLE t1(a int);
|
|
INSERT INTO t1 VALUES (1), (2), (3), (4);
|
|
|
|
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
|
|
eval SELECT * INTO OUTFILE '$MYSQLD_DATADIR/bug43746.sql' FROM t1;
|
|
TRUNCATE TABLE t1;
|
|
|
|
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
|
|
eval LOAD DATA LOCAL INFILE '$MYSQLD_DATADIR/bug43746.sql' INTO TABLE t1;
|
|
|
|
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
|
|
eval LOAD/* look mum, with comments in weird places! */DATA/* oh hai */LOCAL INFILE '$MYSQLD_DATADIR/bug43746.sql'/* we are */INTO/* from the internets */TABLE t1;
|
|
|
|
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
|
|
eval LOAD DATA/*!10000 LOCAL */INFILE '$MYSQLD_DATADIR/bug43746.sql' INTO TABLE t1;
|
|
|
|
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
|
|
eval LOAD DATA LOCAL INFILE '$MYSQLD_DATADIR/bug43746.sql' /*!10000 INTO */ TABLE t1;
|
|
|
|
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
|
|
eval LOAD DATA LOCAL INFILE '$MYSQLD_DATADIR/bug43746.sql' /*!10000 INTO TABLE */ t1;
|
|
|
|
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
|
|
eval LOAD DATA /*!10000 LOCAL INFILE '$MYSQLD_DATADIR/bug43746.sql' INTO TABLE */ t1;
|
|
|
|
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
|
|
eval LOAD DATA/*!10000 LOCAL */INFILE '$MYSQLD_DATADIR/bug43746.sql'/*!10000 INTO*/TABLE t1;
|
|
|
|
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
|
|
eval LOAD DATA/*!10000 LOCAL */INFILE '$MYSQLD_DATADIR/bug43746.sql'/* empty */INTO TABLE t1;
|
|
|
|
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
|
|
eval LOAD DATA/*!10000 LOCAL */INFILE '$MYSQLD_DATADIR/bug43746.sql' INTO/* empty */TABLE t1;
|
|
|
|
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
|
|
eval LOAD/*!99999 special comments that do not expand */DATA/*!99999 code from the future */LOCAL INFILE '$MYSQLD_DATADIR/bug43746.sql'/*!99999 have flux capacitor */INTO/*!99999 will travel */TABLE t1;
|
|
|
|
SET sql_mode='PIPES_AS_CONCAT,ANSI_QUOTES,NO_KEY_OPTIONS,NO_TABLE_OPTIONS,NO_FIELD_OPTIONS,STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER';
|
|
|
|
--replace_result $MYSQLD_DATADIR MYSQLD_DATADIR
|
|
eval LOAD DATA LOCAL INFILE '$MYSQLD_DATADIR/bug43746.sql' INTO TABLE t1;
|
|
|
|
--echo [slave]
|
|
sync_slave_with_master;
|
|
|
|
# cleanup
|
|
|
|
--remove_file $MYSQLD_DATADIR/bug43746.sql
|
|
|
|
--echo [master]
|
|
connection master;
|
|
DROP TABLE t1;
|
|
SET SESSION sql_mode=@old_mode;
|
|
|
|
--echo [slave]
|
|
sync_slave_with_master;
|
|
|
|
connection master;
|