diff options
author | Jon Olav Hauglid <jon.hauglid@sun.com> | 2010-05-18 14:52:51 +0200 |
---|---|---|
committer | Jon Olav Hauglid <jon.hauglid@sun.com> | 2010-05-18 14:52:51 +0200 |
commit | 198d51efe7a7bcd9ffceb2953faccc39d6df55d6 (patch) | |
tree | 7a7d548b20b27bd6b1cdb29f4052ffd1b406f39b /sql/sql_lex.cc | |
parent | d1dd2d11c4207b8e75931b9c575ea51273185b4b (diff) | |
parent | 21643fb22e527f4328b1dde1d21193b5e80455e3 (diff) | |
download | mariadb-git-198d51efe7a7bcd9ffceb2953faccc39d6df55d6.tar.gz |
manual merge from mysql-trunk-bugfixing
Diffstat (limited to 'sql/sql_lex.cc')
-rw-r--r-- | sql/sql_lex.cc | 79 |
1 files changed, 53 insertions, 26 deletions
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 6bd6a374883..1795bc272f1 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -142,37 +142,64 @@ st_parsing_options::reset() allows_derived= TRUE; } + +/** + Perform initialization of Lex_input_stream instance. + + Basically, a buffer for pre-processed query. This buffer should be large + enough to keep multi-statement query. The allocation is done once in the + Lex_input_stream constructor in order to prevent memory pollution when + the server is processing large multi-statement queries. + + @todo Check return value of THD::alloc(). +*/ + Lex_input_stream::Lex_input_stream(THD *thd, const char* buffer, unsigned int length) -: m_thd(thd), - yylineno(1), - yytoklen(0), - yylval(NULL), - lookahead_token(-1), - lookahead_yylval(NULL), - m_ptr(buffer), - m_tok_start(NULL), - m_tok_end(NULL), - m_end_of_query(buffer + length), - m_tok_start_prev(NULL), - m_buf(buffer), - m_buf_length(length), - m_echo(TRUE), - m_cpp_tok_start(NULL), - m_cpp_tok_start_prev(NULL), - m_cpp_tok_end(NULL), - m_body_utf8(NULL), - m_cpp_utf8_processed_ptr(NULL), - next_state(MY_LEX_START), - found_semicolon(NULL), - ignore_space(test(thd->variables.sql_mode & MODE_IGNORE_SPACE)), - stmt_prepare_mode(FALSE), - multi_statements(TRUE), - in_comment(NO_COMMENT), - m_underscore_cs(NULL) + :m_thd(thd) { m_cpp_buf= (char*) thd->alloc(length + 1); + reset(buffer, length); +} + + +/** + Prepare Lex_input_stream instance state for use for handling next SQL statement. + + It should be called between two statements in a multi-statement query. + The operation resets the input stream to the beginning-of-parse state, + but does not reallocate m_cpp_buf. +*/ + +void +Lex_input_stream::reset(const char *buffer, unsigned int length) +{ + yylineno= 1; + yytoklen= 0; + yylval= NULL; + lookahead_token= -1; + lookahead_yylval= NULL; + m_ptr= buffer; + m_tok_start= NULL; + m_tok_end= NULL; + m_end_of_query= buffer + length; + m_tok_start_prev= NULL; + m_buf= buffer; + m_buf_length= length; + m_echo= TRUE; + m_cpp_tok_start= NULL; + m_cpp_tok_start_prev= NULL; + m_cpp_tok_end= NULL; + m_body_utf8= NULL; + m_cpp_utf8_processed_ptr= NULL; + next_state= MY_LEX_START; + found_semicolon= NULL; + ignore_space= test(m_thd->variables.sql_mode & MODE_IGNORE_SPACE); + stmt_prepare_mode= FALSE; + multi_statements= TRUE; + in_comment=NO_COMMENT; + m_underscore_cs= NULL; m_cpp_ptr= m_cpp_buf; } |