Bug #43746 YACC return wrong query string when parse 'load data infile' sql statement
Submitted: 19 Mar 2009 9:52 Modified: 1 Aug 2010 22:25
Reporter: li zhou Email Updates:
Status: Closed Impact on me:
Category:MySQL Server: Parser Severity:S3 (Non-critical)
Version:5.1 OS:Any
Assigned to: Tatiana Azundris Nuernberg
Triage: Triaged: D3 (Medium)

[19 Mar 2009 9:52] li zhou
When we execute 'load data  LOCAL INFILE '/tmp/t1' INTO table test1', binlog thread write wrong 'fn_pos_start' and 'fn_pos_stop' into binlog.

In mysql_load(), we write binlog with write_execute_load_query_log_event().
write_execute_load_query_log_event initialize 'fn_pos_start' with 'thd->lex-fname_start-(char*)thd->query' and  'fn_pos_stop' with 'thd->lex-fname_end-(char*)thd->query'.

In the same test case ,if we set different sql_mode, 'thd->lex-fname_start' and 'thd->lex-fname_end' are not the same.

1: set sql_mode = 

thd->lex-fname_start is ' local infile.....' and 
thd->lex-fname_end is   ' table t1' . but

2:  set sql_mode='oracle,traditional';
thd->lex-fname_start is 'local infile.....' and 
thd->lex-fname_end is   'table t1' . 
This two variable lost one *space* at beginning.

So we miss one space when sql thread parse binlog event, that cause the event failed. see bug#22504.

How to repeat:
See bug#22504

Suggested fix:
Yacc should return the same query string in any sql_modes after parse sql statement.
[19 Mar 2009 9:55] li zhou
My test case:


source include/master-slave.inc;

--echo ==== Bug22504 Initialize ====

--echo [on master]
--connection master
let $MYSQLD_DATADIR= `select @@datadir`;

SET sql_mode='ignore_space';
CREATE TABLE t1(a int);
insert into t1 values (1), (2), (3), (4);
eval select * into outfile '$MYSQLD_DATADIR/rpl_loaddatalocal.select_outfile' from t1;
truncate table t1;
eval load data local infile '$MYSQLD_DATADIR/rpl_loaddatalocal.select_outfile' into table
--remove_file $MYSQLD_DATADIR/rpl_loaddatalocal.select_outfile

--echo [on slave]

--echo ==== Clean up ====

--echo [on master]
connection master;

--echo [on slave]


Do this test case and print out '(char*)thd->lex->fname_start,(char*)thd->lex->fname_end ' in write_execute_load_query_log_event().
[19 Mar 2009 10:39] Sveta Smirnova
Thank you for the report.

Verified as described.
[29 Sep 2009 14:16] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:


3124 Tatiana A. Nurnberg	2009-09-28
      Bug#43746: YACC return wrong query string when parse 'load data infile' sql statement
      "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.
[30 Sep 2009 21:31] Tatiana Azundris Nuernberg
queued for 6.0.14/pe, 5.1.40 in -bugteam.
[6 Oct 2009 9:00] Bugs System
Pushed into 5.1.40 (revid:joro@sun.com-20091006073316-lea2cpijh9r6on7c) (version source revid:ingo.struewing@sun.com-20091002112748-2xmjv846dk323nc3) (merge vers: 5.1.40) (pib:11)
[8 Oct 2009 0:19] Paul Dubois
Noted in 5.1.40 changelog.

LOAD DATA INFILE statements were written to the binary log in such a
way that parsing problems could occur when re-executing the statement
from the log. 

Setting report to NDI pending push into 5.4.x.
[22 Oct 2009 7:07] Bugs System
Pushed into 5.5.0-beta (revid:alik@sun.com-20091022060553-znkmxm0g0gm6ckvw) (version source revid:alik@sun.com-20091013094238-g67x6tgdm9a7uik0) (merge vers: 5.5.0-beta) (pib:13)
[22 Oct 2009 19:32] Paul Dubois
Noted in 5.5.0 changelog.

Setting report to NDI pending push into 6.0.x.
[18 Dec 2009 10:31] Bugs System
Pushed into 5.1.41-ndb-7.1.0 (revid:jonas@mysql.com-20091218102229-64tk47xonu3dv6r6) (version source revid:jonas@mysql.com-20091218095730-26gwjidfsdw45dto) (merge vers: 5.1.41-ndb-7.1.0) (pib:15)
[18 Dec 2009 10:47] Bugs System
Pushed into 5.1.41-ndb-6.2.19 (revid:jonas@mysql.com-20091218100224-vtzr0fahhsuhjsmt) (version source revid:jonas@mysql.com-20091217101452-qwzyaig50w74xmye) (merge vers: 5.1.41-ndb-6.2.19) (pib:15)
[18 Dec 2009 11:02] Bugs System
Pushed into 5.1.41-ndb-6.3.31 (revid:jonas@mysql.com-20091218100616-75d9tek96o6ob6k0) (version source revid:jonas@mysql.com-20091217154335-290no45qdins5bwo) (merge vers: 5.1.41-ndb-6.3.31) (pib:15)
[18 Dec 2009 11:16] Bugs System
Pushed into 5.1.41-ndb-7.0.11 (revid:jonas@mysql.com-20091218101303-ga32mrnr15jsa606) (version source revid:jonas@mysql.com-20091218064304-ezreonykd9f4kelk) (merge vers: 5.1.41-ndb-7.0.11) (pib:15)
[18 Dec 2009 20:47] Paul Dubois
Setting report to NDI pending push into 6.0.x.
[14 Jan 2010 22:37] Roel Van de Paar
See bug #49479
[2 Feb 2013 9:07] Shane Bester
bug #68242 is a duplicate