diff options
author | Nikita Malyavin <nikitamalyavin@gmail.com> | 2022-01-29 22:21:32 +0300 |
---|---|---|
committer | Nikita Malyavin <nikitamalyavin@gmail.com> | 2022-01-29 22:21:32 +0300 |
commit | d388b7ae8adde451928cf93d47b6e30bee8dc5ab (patch) | |
tree | 24047f0d0b19058a2296a4065b6e8794e3c4d379 | |
parent | cf7cc376bacb3f49f5afa2cce144dace82602546 (diff) | |
download | mariadb-git-nikita/MDEV-25774.tar.gz |
MDEV-25774 profile build speed of the server code basenikita/MDEV-25774
using precompiled headers was tried here
37 files changed, 1348 insertions, 978 deletions
diff --git a/include/m_string.h b/include/m_string.h index 7130a41438f..8377d58caf1 100644 --- a/include/m_string.h +++ b/include/m_string.h @@ -23,6 +23,7 @@ #ifndef _m_string_h #define _m_string_h +#include "my_global.h" #include "my_decimal_limits.h" #ifndef __USE_GNU diff --git a/mysql-test/suite/versioning/t/partition.test b/mysql-test/suite/versioning/t/partition.test index ce41e0c96b3..8d4bb7d365a 100644 --- a/mysql-test/suite/versioning/t/partition.test +++ b/mysql-test/suite/versioning/t/partition.test @@ -1309,4 +1309,36 @@ show create table t1; drop tables t1, tp1; } + +--echo # +--echo # MDEV-27328 Change of SYSTEM_TIME partitioning options is not possible without data copy +--echo # + +create or replace table t1 (x int) with system versioning + partition by system_time limit 33; +--replace_result $default_engine DEFAULT_ENGINE +show create table t1; +set timestamp= unix_timestamp('2000-01-01 00:00:00'); +insert t1 values (0); +set timestamp= unix_timestamp('2000-01-01 00:10:00'); +update t1 set x= x + 1; +set timestamp= unix_timestamp('2000-01-01 01:00:00'); +update t1 set x= x + 1; +set timestamp= unix_timestamp('2000-01-01 01:30:00'); +update t1 set x= x + 1; +set timestamp= unix_timestamp('2000-01-01 02:00:00'); +update t1 set x= x + 1; + +# When we switch to INTERVAL we must reorganize partitions. +# Otherwise pruning won't work correctly. +alter table t1 partition by system_time interval 1 hour + starts '2000-01-01 00:00:00'; +--replace_result $default_engine DEFAULT_ENGINE +show create table t1; +select * from t1 partition (p0); +select * from t1 partition (p1); +select * from t1 partition (p2); +select * from t1 partition (pn); +set timestamp= default; + --source suite/versioning/common_finish.inc diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 972cc0b736c..66ff5970ada 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -179,6 +179,259 @@ SET (SQL_SOURCE ${GEN_SOURCES} ${MYSYS_LIBWRAP_SOURCE} ) +set (SQL_HEADERS + sql_plugin.h + ../mysql/plugin.h + sql_type_fixedbin.h + sql_lex.h + sql_class.h + + # authors.h + backup.h + bounded_queue.h + # client_settings.h + compat56.h + # contributors.h + create_options.h + create_tmp_table.h + custom_conf.h + datadict.h + ddl_log.h + debug.h + debug_sync.h + derived_handler.h + derror.h + des_key_file.h + discover.h + event_data_objects.h + event_db_repository.h + event_parse_data.h + event_queue.h + event_scheduler.h + events.h + field_comp.h + field.h + filesort.h + filesort_utils.h + gcalc_slicescan.h + gcalc_tools.h + grant.h + group_by_handler.h + gstream.h + handle_connections_win.h + handler.h + ha_partition.h + ha_sequence.h + hash_filo.h + hostname.h + init.h + innodb_priv.h + item_cmpfunc.h + item_create.h + item_func.h + item_geofunc.h + item.h + item_jsonfunc.h + item_row.h + item_strfunc.h + item_subselect.h + item_sum.h + item_timefunc.h + item_vers.h + item_windowfunc.h + item_xmlfunc.h + json_table.h + keycaches.h + key.h + #lex.h + #lex_string.h + #lex_symbol.h + lock.h + log_event.h + log_event_old.h + log.h + log_slow.h + mariadb.h + mdl.h + mem_root_array.h + message.h + multi_range_read.h + my_apc.h + my_decimal.h + my_json_writer.h + mysqld.h + mysqld_suffix.h + opt_range.h + opt_subselect.h + opt_trace_context.h + opt_trace.h + parse_file.h + partition_element.h + partition_info.h + privilege.h + procedure.h + protocol.h + # proxy_protocol.h + records.h + repl_failsafe.h + replication.h + rowid_filter.h + rpl_constants.h + rpl_filter.h + rpl_gtid.h + rpl_injector.h + rpl_mi.h + rpl_parallel.h + rpl_record.h + rpl_record_old.h + rpl_reporting.h + rpl_rli.h + rpl_tblmap.h + rpl_utility.h + scheduler.h + select_handler.h + semisync.h + semisync_master_ack_receiver.h + semisync_master.h + semisync_slave.h + session_tracker.h + set_var.h + slave.h + spatial.h + sp_cache.h + sp.h + sp_head.h + sp_pcontext.h + sp_rcontext.h + sql_acl.h + sql_admin.h + sql_alloc.h + sql_alter.h + sql_analyse.h + sql_analyze_stmt.h + sql_array.h + sql_audit.h + sql_base.h + sql_basic_types.h + sql_binlog.h + sql_bitmap.h + sql_bootstrap.h + sql_cache.h + sql_callback.h + + # sql_class.h + + sql_cmd.h + sql_connect.h + sql_const.h + sql_crypt.h + sql_cte.h + sql_cursor.h + sql_db.h + sql_delete.h + sql_derived.h + sql_digest.h + sql_digest_stream.h + sql_do.h + sql_error.h + sql_explain.h + sql_expression_cache.h + sql_get_diagnostics.h + sql_handler.h + sql_help.h + sql_hset.h + sql_insert.h + sql_i_s.h + sql_join_cache.h + # sql_lex.h + sql_lifo_buffer.h + sql_limit.h + sql_list.h + sql_load.h + sql_locale.h + sql_manager.h + sql_mode.h + sql_parse.h + # sql_partition_admin.h + sql_partition.h + sql_plist.h + # sql_plugin_compat.h + # sql_plugin.h + sql_prepare.h + sql_priv.h + sql_profile.h + sql_reload.h + sql_rename.h + sql_repl.h + sql_schema.h + sql_select.h + sql_sequence.h + sql_servers.h + sql_show.h + sql_signal.h + sql_sort.h + sql_statistics.h + sql_string.h + sql_table.h + sql_test.h + sql_time.h + sql_trigger.h + sql_truncate.h + sql_tvc.h +# sql_type_fixedbin.h + sql_type_fixedbin_storage.h + sql_type_geom.h + sql_type.h + sql_type_int.h + sql_type_json.h + sql_type_real.h + sql_type_string.h + sql_udf.h + sql_union.h + sql_update.h + sql_view.h + sql_window.h + strfunc.h + structs.h + sys_vars_shared.h + table_cache.h + table.h + # thread_cache.h + threadpool_generic.h + threadpool.h + # threadpool_winsockets.h + thr_malloc.h + transaction.h + tzfile.h + tztime.h + uniques.h + unireg.h + vers_string.h + # winservice.h + # win_tzname_data.h + wsrep_applier.h + wsrep_binlog.h + wsrep_client_service.h + wsrep_client_state.h + wsrep_condition_variable.h + wsrep_high_priority_service.h + wsrep_mutex.h + wsrep_mysqld_c.h + wsrep_mysqld.h + wsrep_priv.h + wsrep_schema.h + wsrep_server_service.h + wsrep_server_state.h + wsrep_sst.h + wsrep_storage_service.h + wsrep_thd.h +# wsrep_trans_observer.h + wsrep_types.h + wsrep_utils.h + wsrep_var.h + wsrep_xid.h + xa.h) + IF ((CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "SunOS" OR @@ -213,6 +466,9 @@ TARGET_LINK_LIBRARIES(sql ${SSL_LIBRARIES} ${LIBSYSTEMD}) +target_precompile_headers(sql PRIVATE + "$<$<COMPILE_LANGUAGE:CXX>:${SQL_HEADERS}>") + IF(TARGET pcre2) ADD_DEPENDENCIES(sql pcre2) ENDIF() diff --git a/sql/bounded_queue.h b/sql/bounded_queue.h index 07ab6dbaab9..978e6990945 100644 --- a/sql/bounded_queue.h +++ b/sql/bounded_queue.h @@ -16,6 +16,7 @@ #ifndef BOUNDED_QUEUE_INCLUDED #define BOUNDED_QUEUE_INCLUDED +#include "my_global.h" #include "my_base.h" #include <my_sys.h> #include "queues.h" diff --git a/sql/event_data_objects.cc b/sql/event_data_objects.cc index 247df87235d..92e0fba1528 100644 --- a/sql/event_data_objects.cc +++ b/sql/event_data_objects.cc @@ -32,6 +32,7 @@ #include "sp_head.h" #include "sql_show.h" // append_definer, append_identifier #include "mysql/psi/mysql_sp.h" +#include "lex_state.h" #ifdef WITH_WSREP #include "wsrep_trans_observer.h" #endif /* WITH_WSREP */ diff --git a/sql/item.cc b/sql/item.cc index e0456edfee0..78f134ec2e9 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1601,52 +1601,6 @@ bool Item_field::check_vcol_func_processor(void *arg) return mark_unsupported_function(field_name.str, arg, VCOL_FIELD_REF); } - -Query_fragment::Query_fragment(THD *thd, sp_head *sphead, - const char *start, const char *end) -{ - DBUG_ASSERT(start <= end); - if (thd->lex->clone_spec_offset) - { - Lex_input_stream *lip= (& thd->m_parser_state->m_lip); - DBUG_ASSERT(lip->get_buf() <= start); - DBUG_ASSERT(end <= lip->get_end_of_query()); - set(start - lip->get_buf(), end - start); - } - else if (sphead) - { - if (sphead->m_tmp_query) - { - // Normal SP statement - DBUG_ASSERT(sphead->m_tmp_query <= start); - set(start - sphead->m_tmp_query, end - start); - } - else - { - /* - We're in the "if" expression of a compound query: - if (expr) - do_something; - end if; - sphead->m_tmp_query is not set yet at this point, because - the "if" part of such statements is never put into the binary log. - Values of Rewritable_query_parameter::pos_in_query and - Rewritable_query_parameter:len_in_query will not be important, - so setting both to 0 should be fine. - */ - set(0, 0); - } - } - else - { - // Non-SP statement - DBUG_ASSERT(thd->query() <= start); - DBUG_ASSERT(end <= thd->query_end()); - set(start - thd->query(), end - start); - } -} - - /***************************************************************************** Item_sp_variable methods *****************************************************************************/ diff --git a/sql/lex_state.h b/sql/lex_state.h new file mode 100644 index 00000000000..bde574f3530 --- /dev/null +++ b/sql/lex_state.h @@ -0,0 +1,718 @@ +/* + Copyright (c) 2009, 2022, MariaDB Corporation. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#ifndef SQL_YYSTYPE_INCLUDED +#define SQL_YYSTYPE_INCLUDED + +#include <my_global.h> +#include <m_ctype.h> +#include "mysqld.h" +#include "lock.h" +#include "mdl.h" +#include "sql_signal.h" + + +/* + The following hack is needed because yy_*.cc do not define + YYSTYPE before including this file +*/ +#ifdef MYSQL_YACC +#define LEX_YYSTYPE void * +#else +#include "lex_symbol.h" +#ifdef MYSQL_LEX +#include "item_func.h" /* Cast_target used in yy_mariadb.hh */ +#include "sql_get_diagnostics.h" /* Types used in yy_mariadb.hh */ +#include "sp_pcontext.h" +#include "yy_mariadb.hh" +#define LEX_YYSTYPE YYSTYPE * +#else +#define LEX_YYSTYPE void * +#endif +#endif + +class Lex_string_with_metadata_st; +class Lex_ident_cli_st; +struct sql_digest_state; +/** + The state of the lexical parser, when parsing comments. +*/ +enum enum_comment_state +{ + /** + Not parsing comments. + */ + NO_COMMENT, + /** + Parsing comments that need to be preserved. + Typically, these are user comments '/' '*' ... '*' '/'. + */ + PRESERVE_COMMENT, + /** + Parsing comments that need to be discarded. + Typically, these are special comments '/' '*' '!' ... '*' '/', + or '/' '*' '!' 'M' 'M' 'm' 'm' 'm' ... '*' '/', where the comment + markers should not be expanded. + */ + DISCARD_COMMENT +}; + + +/** + @brief This class represents the character input stream consumed during + lexical analysis. + + In addition to consuming the input stream, this class performs some + comment pre processing, by filtering out out of bound special text + from the query input stream. + Two buffers, with pointers inside each buffers, are maintained in + parallel. The 'raw' buffer is the original query text, which may + contain out-of-bound comments. The 'cpp' (for comments pre processor) + is the pre-processed buffer that contains only the query text that + should be seen once out-of-bound data is removed. +*/ + +class Lex_input_stream +{ + size_t unescape(CHARSET_INFO *cs, char *to, + const char *str, const char *end, int sep); + my_charset_conv_wc_mb get_escape_func(THD *thd, my_wc_t sep) const; +public: + Lex_input_stream() + { + } + + ~Lex_input_stream() + { + } + + /** + Object initializer. Must be called before usage. + + @retval FALSE OK + @retval TRUE Error + */ + bool init(THD *thd, char *buff, size_t length); + + void reset(char *buff, size_t length); + + /** + The main method to scan the next token, with token contraction processing + for LALR(2) resolution, e.g. translate "WITH" followed by "ROLLUP" + to a single token WITH_ROLLUP_SYM. + */ + int lex_token(union YYSTYPE *yylval, THD *thd); + + void reduce_digest_token(uint token_left, uint token_right); + +private: + /** + Set the echo mode. + + When echo is true, characters parsed from the raw input stream are + preserved. When false, characters parsed are silently ignored. + @param echo the echo mode. + */ + void set_echo(bool echo) + { + m_echo= echo; + } + + void save_in_comment_state() + { + m_echo_saved= m_echo; + in_comment_saved= in_comment; + } + + void restore_in_comment_state() + { + m_echo= m_echo_saved; + in_comment= in_comment_saved; + } + + /** + Skip binary from the input stream. + @param n number of bytes to accept. + */ + void skip_binary(int n) + { + if (m_echo) + { + memcpy(m_cpp_ptr, m_ptr, n); + m_cpp_ptr += n; + } + m_ptr += n; + } + + /** + Get a character, and advance in the stream. + @return the next character to parse. + */ + unsigned char yyGet() + { + char c= *m_ptr++; + if (m_echo) + *m_cpp_ptr++ = c; + return c; + } + + /** + Get the last character accepted. + @return the last character accepted. + */ + unsigned char yyGetLast() + { + return m_ptr[-1]; + } + + /** + Look at the next character to parse, but do not accept it. + */ + unsigned char yyPeek() + { + return m_ptr[0]; + } + + /** + Look ahead at some character to parse. + @param n offset of the character to look up + */ + unsigned char yyPeekn(int n) + { + return m_ptr[n]; + } + + /** + Cancel the effect of the last yyGet() or yySkip(). + Note that the echo mode should not change between calls to yyGet / yySkip + and yyUnget. The caller is responsible for ensuring that. + */ + void yyUnget() + { + m_ptr--; + if (m_echo) + m_cpp_ptr--; + } + + /** + Accept a character, by advancing the input stream. + */ + void yySkip() + { + if (m_echo) + *m_cpp_ptr++ = *m_ptr++; + else + m_ptr++; + } + + /** + Accept multiple characters at once. + @param n the number of characters to accept. + */ + void yySkipn(int n) + { + if (m_echo) + { + memcpy(m_cpp_ptr, m_ptr, n); + m_cpp_ptr += n; + } + m_ptr += n; + } + + /** + Puts a character back into the stream, canceling + the effect of the last yyGet() or yySkip(). + Note that the echo mode should not change between calls + to unput, get, or skip from the stream. + */ + char *yyUnput(char ch) + { + *--m_ptr= ch; + if (m_echo) + m_cpp_ptr--; + return m_ptr; + } + + /** + End of file indicator for the query text to parse. + @param n number of characters expected + @return true if there are less than n characters to parse + */ + bool eof(int n) + { + return ((m_ptr + n) >= m_end_of_query); + } + + /** Mark the stream position as the start of a new token. */ + void start_token() + { + m_tok_start_prev= m_tok_start; + m_tok_start= m_ptr; + m_tok_end= m_ptr; + + m_cpp_tok_start_prev= m_cpp_tok_start; + m_cpp_tok_start= m_cpp_ptr; + m_cpp_tok_end= m_cpp_ptr; + } + + /** + Adjust the starting position of the current token. + This is used to compensate for starting whitespace. + */ + void restart_token() + { + m_tok_start= m_ptr; + m_cpp_tok_start= m_cpp_ptr; + } + + /** + Get the maximum length of the utf8-body buffer. + The utf8 body can grow because of the character set conversion and escaping. + */ + size_t get_body_utf8_maximum_length(THD *thd); + + /** Get the length of the current token, in the raw buffer. */ + uint yyLength() + { + /* + The assumption is that the lexical analyser is always 1 character ahead, + which the -1 account for. + */ + DBUG_ASSERT(m_ptr > m_tok_start); + return (uint) ((m_ptr - m_tok_start) - 1); + } + + /** + Test if a lookahead token was already scanned by lex_token(), + for LALR(2) resolution. + */ + bool has_lookahead() const + { + return lookahead_token >= 0; + } + +public: + + /** + End of file indicator for the query text to parse. + @return true if there are no more characters to parse + */ + bool eof() + { + return (m_ptr >= m_end_of_query); + } + + /** Get the raw query buffer. */ + const char *get_buf() + { + return m_buf; + } + + /** Get the pre-processed query buffer. */ + const char *get_cpp_buf() + { + return m_cpp_buf; + } + + /** Get the end of the raw query buffer. */ + const char *get_end_of_query() + { + return m_end_of_query; + } + + /** Get the token start position, in the raw buffer. */ + const char *get_tok_start() + { + return has_lookahead() ? m_tok_start_prev : m_tok_start; + } + + void set_cpp_tok_start(const char *pos) + { + m_cpp_tok_start= pos; + } + + /** Get the token end position, in the raw buffer. */ + const char *get_tok_end() + { + return m_tok_end; + } + + /** Get the current stream pointer, in the raw buffer. */ + const char *get_ptr() + { + return m_ptr; + } + + /** Get the token start position, in the pre-processed buffer. */ + const char *get_cpp_tok_start() + { + return has_lookahead() ? m_cpp_tok_start_prev : m_cpp_tok_start; + } + + /** Get the token end position, in the pre-processed buffer. */ + const char *get_cpp_tok_end() + { + return m_cpp_tok_end; + } + + /** + Get the token end position in the pre-processed buffer, + with trailing spaces removed. + */ + const char *get_cpp_tok_end_rtrim() + { + const char *p; + for (p= m_cpp_tok_end; + p > m_cpp_buf && my_isspace(system_charset_info, p[-1]); + p--) + { } + return p; + } + + /** Get the current stream pointer, in the pre-processed buffer. */ + const char *get_cpp_ptr() + { + return m_cpp_ptr; + } + + /** + Get the current stream pointer, in the pre-processed buffer, + with traling spaces removed. + */ + const char *get_cpp_ptr_rtrim() + { + const char *p; + for (p= m_cpp_ptr; + p > m_cpp_buf && my_isspace(system_charset_info, p[-1]); + p--) + { } + return p; + } + /** Get the utf8-body string. */ + const char *get_body_utf8_str() + { + return m_body_utf8; + } + + /** Get the utf8-body length. */ + size_t get_body_utf8_length() + { + return (size_t) (m_body_utf8_ptr - m_body_utf8); + } + + void body_utf8_start(THD *thd, const char *begin_ptr); + void body_utf8_append(const char *ptr); + void body_utf8_append(const char *ptr, const char *end_ptr); + void body_utf8_append_ident(THD *thd, + const Lex_string_with_metadata_st *txt, + const char *end_ptr); + void body_utf8_append_escape(THD *thd, + const LEX_CSTRING *txt, + CHARSET_INFO *txt_cs, + const char *end_ptr, + my_wc_t sep); + +private: + /** + LALR(2) resolution, look ahead token. + Value of the next token to return, if any, + or -1, if no token was parsed in advance. + Note: 0 is a legal token, and represents YYEOF. + */ + int lookahead_token; + + /** LALR(2) resolution, value of the look ahead token.*/ + LEX_YYSTYPE lookahead_yylval; + + bool get_text(Lex_string_with_metadata_st *to, + uint sep, int pre_skip, int post_skip); + + void add_digest_token(uint token, LEX_YYSTYPE yylval); + + bool consume_comment(int remaining_recursions_permitted); + int lex_one_token(union YYSTYPE *yylval, THD *thd); + int find_keyword(Lex_ident_cli_st *str, uint len, bool function); + LEX_CSTRING get_token(uint skip, uint length); + int scan_ident_sysvar(THD *thd, Lex_ident_cli_st *str); + int scan_ident_start(THD *thd, Lex_ident_cli_st *str); + int scan_ident_middle(THD *thd, Lex_ident_cli_st *str, + CHARSET_INFO **cs, my_lex_states *); + int scan_ident_delimited(THD *thd, Lex_ident_cli_st *str, uchar quote_char); + bool get_7bit_or_8bit_ident(THD *thd, uchar *last_char); + + /** Current thread. */ + THD *m_thd; + + /** Pointer to the current position in the raw input stream. */ + char *m_ptr; + + /** Starting position of the last token parsed, in the raw buffer. */ + const char *m_tok_start; + + /** Ending position of the previous token parsed, in the raw buffer. */ + const char *m_tok_end; + + /** End of the query text in the input stream, in the raw buffer. */ + const char *m_end_of_query; + + /** Starting position of the previous token parsed, in the raw buffer. */ + const char *m_tok_start_prev; + + /** Begining of the query text in the input stream, in the raw buffer. */ + const char *m_buf; + + /** Length of the raw buffer. */ + size_t m_buf_length; + + /** Echo the parsed stream to the pre-processed buffer. */ + bool m_echo:1; + bool m_echo_saved:1; + + /** Pre-processed buffer. */ + char *m_cpp_buf; + + /** Pointer to the current position in the pre-processed input stream. */ + char *m_cpp_ptr; + + /** + Starting position of the last token parsed, + in the pre-processed buffer. + */ + const char *m_cpp_tok_start; + + /** + Starting position of the previous token parsed, + in the pre-procedded buffer. + */ + const char *m_cpp_tok_start_prev; + + /** + Ending position of the previous token parsed, + in the pre-processed buffer. + */ + const char *m_cpp_tok_end; + + /** UTF8-body buffer created during parsing. */ + char *m_body_utf8; + + /** Pointer to the current position in the UTF8-body buffer. */ + char *m_body_utf8_ptr; + + /** + Position in the pre-processed buffer. The query from m_cpp_buf to + m_cpp_utf_processed_ptr is converted to UTF8-body. + */ + const char *m_cpp_utf8_processed_ptr; + +public: + + /** Current state of the lexical analyser. */ + enum my_lex_states next_state; + + /** + Position of ';' in the stream, to delimit multiple queries. + This delimiter is in the raw buffer. + */ + const char *found_semicolon; + + /** SQL_MODE = IGNORE_SPACE. */ + bool ignore_space:1; + + /** + TRUE if we're parsing a prepared statement: in this mode + we should allow placeholders. + */ + bool stmt_prepare_mode:1; + /** + TRUE if we should allow multi-statements. + */ + bool multi_statements:1; + + /** Current line number. */ + uint yylineno; + + /** + Current statement digest instrumentation. + */ + sql_digest_state* m_digest; + +private: + /** State of the lexical analyser for comments. */ + enum_comment_state in_comment; + enum_comment_state in_comment_saved; + + /** + Starting position of the TEXT_STRING or IDENT in the pre-processed + buffer. + + NOTE: this member must be used within MYSQLlex() function only. + */ + const char *m_cpp_text_start; + + /** + Ending position of the TEXT_STRING or IDENT in the pre-processed + buffer. + + NOTE: this member must be used within MYSQLlex() function only. + */ + const char *m_cpp_text_end; + + /** + Character set specified by the character-set-introducer. + + NOTE: this member must be used within MYSQLlex() function only. + */ + CHARSET_INFO *m_underscore_cs; +}; + + + +/** + The internal state of the syntax parser. + This object is only available during parsing, + and is private to the syntax parser implementation (sql_yacc.yy). +*/ +class Yacc_state +{ +public: + Yacc_state() : yacc_yyss(NULL), yacc_yyvs(NULL) { reset(); } + + void reset() + { + if (yacc_yyss != NULL) { + my_free(yacc_yyss); + yacc_yyss = NULL; + } + if (yacc_yyvs != NULL) { + my_free(yacc_yyvs); + yacc_yyvs = NULL; + } + m_set_signal_info.clear(); + m_lock_type= TL_READ_DEFAULT; + m_mdl_type= MDL_SHARED_READ; + } + + ~Yacc_state(); + + /** + Reset part of the state which needs resetting before parsing + substatement. + */ + void reset_before_substatement() + { + m_lock_type= TL_READ_DEFAULT; + m_mdl_type= MDL_SHARED_READ; + } + + /** + Bison internal state stack, yyss, when dynamically allocated using + my_yyoverflow(). + */ + uchar *yacc_yyss; + + /** + Bison internal semantic value stack, yyvs, when dynamically allocated using + my_yyoverflow(). + */ + uchar *yacc_yyvs; + + /** + Fragments of parsed tree, + used during the parsing of SIGNAL and RESIGNAL. + */ + Set_signal_information m_set_signal_info; + + /** + Type of lock to be used for tables being added to the statement's + table list in table_factor, table_alias_ref, single_multi and + table_wild_one rules. + Statements which use these rules but require lock type different + from one specified by this member have to override it by using + st_select_lex::set_lock_for_tables() method. + + The default value of this member is TL_READ_DEFAULT. The only two + cases in which we change it are: + - When parsing SELECT HIGH_PRIORITY. + - Rule for DELETE. In which we use this member to pass information + about type of lock from delete to single_multi part of rule. + + We should try to avoid introducing new use cases as we would like + to get rid of this member eventually. + */ + thr_lock_type m_lock_type; + + /** + The type of requested metadata lock for tables added to + the statement table list. + */ + enum_mdl_type m_mdl_type; + + /* + TODO: move more attributes from the LEX structure here. + */ +}; + + +/** + Internal state of the parser. + The complete state consist of: + - state data used during lexical parsing, + - state data used during syntactic parsing. +*/ +class Parser_state +{ +public: + Parser_state() + : m_yacc() + {} + + /** + Object initializer. Must be called before usage. + + @retval FALSE OK + @retval TRUE Error + */ + bool init(THD *thd, char *buff, size_t length) + { + return m_lip.init(thd, buff, length); + } + + ~Parser_state() + {} + + Lex_input_stream m_lip; + Yacc_state m_yacc; + + /** + Current performance digest instrumentation. + */ + PSI_digest_locker* m_digest_psi; + + void reset(char *found_semicolon, unsigned int length) + { + m_lip.reset(found_semicolon, length); + m_yacc.reset(); + } +}; + + +extern sql_digest_state * +digest_add_token(sql_digest_state *state, uint token, LEX_YYSTYPE yylval); + +extern sql_digest_state * +digest_reduce_token(sql_digest_state *state, uint token_left, uint token_right); + +#endif // SQL_YYSTYPE_INCLUDED diff --git a/sql/log_event_server.cc b/sql/log_event_server.cc index 6942e328704..fbf1034af55 100644 --- a/sql/log_event_server.cc +++ b/sql/log_event_server.cc @@ -52,6 +52,7 @@ #include "compat56.h" #include "wsrep_mysqld.h" #include "sql_insert.h" +#include "lex_state.h" #include <my_bitmap.h> #include "rpl_utility.h" diff --git a/sql/multi_range_read.h b/sql/multi_range_read.h index 37a00e3086f..5556c70922e 100644 --- a/sql/multi_range_read.h +++ b/sql/multi_range_read.h @@ -62,6 +62,9 @@ storage and has better performance when reading data in rowid order. */ +#ifndef MULTI_RANGE_READ_INCLUDED +#define MULTI_RANGE_READ_INCLUDED + #include "sql_lifo_buffer.h" class DsMrr_impl; @@ -668,3 +671,4 @@ private: @} (end of group DS-MRR declarations) */ +#endif // MULTI_RANGE_READ_INCLUDED diff --git a/sql/net_serv.cc b/sql/net_serv.cc index 39b4290a161..63805d5d2b8 100644 --- a/sql/net_serv.cc +++ b/sql/net_serv.cc @@ -722,7 +722,7 @@ net_real_write(NET *net,const uchar *packet, size_t len) if ((long) (length= vio_write(net->vio,pos,(size_t) (end-pos))) <= 0) { my_bool interrupted = vio_should_retry(net->vio); -#if !defined(_WIN32) +#if !defined(_WIN32) && !defined(NO_ALARM) if ((interrupted || length == 0) && !thr_alarm_in_use(&alarmed)) { if (!thr_alarm(&alarmed, net->write_timeout, &alarm_buff)) diff --git a/sql/opt_subselect.h b/sql/opt_subselect.h index abd37f1e98e..65d9e19025c 100644 --- a/sql/opt_subselect.h +++ b/sql/opt_subselect.h @@ -18,6 +18,8 @@ Semi-join subquery optimization code definitions */ +#pragma once + #ifdef USE_PRAGMA_INTERFACE #pragma interface /* gcc class implementation */ #endif diff --git a/sql/slave.cc b/sql/slave.cc index 3c5b830fbe2..dd50549b18b 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -52,6 +52,7 @@ #include "log_event.h" // Rotate_log_event, // Create_file_log_event, // Format_description_log_event +#include "lex_state.h" #include "wsrep_mysqld.h" #ifdef WITH_WSREP #include "wsrep_trans_observer.h" diff --git a/sql/sp.cc b/sql/sp.cc index 4ef23983f78..bd5662be14c 100644 --- a/sql/sp.cc +++ b/sql/sp.cc @@ -35,6 +35,7 @@ #include <my_user.h> #include "mysql/psi/mysql_sp.h" +#include "lex_state.h" sp_cache **Sp_handler_procedure::get_cache(THD *thd) const { diff --git a/sql/sp_head.cc b/sql/sp_head.cc index 641c88de826..f5c1d3627ef 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -30,6 +30,7 @@ #include "sql_select.h" // Virtual_tmp_table #include "opt_trace.h" #include "my_json_writer.h" +#include "lex_state.h" #ifdef USE_PRAGMA_IMPLEMENTATION #pragma implementation diff --git a/sql/sql_analyse.cc b/sql/sql_analyse.cc index d609fff5487..c1f97566a51 100644 --- a/sql/sql_analyse.cc +++ b/sql/sql_analyse.cc @@ -34,6 +34,7 @@ #include "procedure.h" #include "sql_analyse.h" #include <m_ctype.h> +#include "lex_state.h" #define MAX_TREEMEM 8192 #define MAX_TREE_ELEMENTS 256 diff --git a/sql/sql_analyze_stmt.h b/sql/sql_analyze_stmt.h index 990c79fb9ad..6df7de4530b 100644 --- a/sql/sql_analyze_stmt.h +++ b/sql/sql_analyze_stmt.h @@ -37,7 +37,7 @@ overhead. Because of that, we measure the time only when running "ANALYZE $stmt"). */ - +#pragma once class Gap_time_tracker; void attach_gap_time_tracker(THD *thd, Gap_time_tracker *gap_tracker, ulonglong timeval); void process_gap_time_tracker(THD *thd, ulonglong timeval); diff --git a/sql/sql_class.cc b/sql/sql_class.cc index f3d4710ff41..2aec255ed06 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -64,6 +64,7 @@ #include "lock.h" #include "wsrep_mysqld.h" #include "sql_connect.h" +#include "lex_state.h" #ifdef WITH_WSREP #include "wsrep_thd.h" #include "wsrep_trans_observer.h" @@ -1035,6 +1036,25 @@ void THD::raise_note_printf(uint sql_errno, ...) DBUG_VOID_RETURN; } +void THD::parse_error(const char *err_text, const char *yytext) +{ + Lex_input_stream *lip= &m_parser_state->m_lip; + if (!yytext && !(yytext= lip->get_tok_start())) + yytext= ""; + /* Push an error into the error stack */ + ErrConvString err(yytext, strlen(yytext), variables.character_set_client); + my_printf_error(ER_PARSE_ERROR, ER_THD(this, ER_PARSE_ERROR), MYF(0), + err_text, err.ptr(), lip->yylineno); +} + +void THD::set_local_lex(sp_lex_local *sublex) +{ + DBUG_ASSERT(lex->sphead); + lex= sublex; + /* Reset part of parser state which needs this. */ + m_parser_state->m_yacc.reset_before_substatement(); +} + Sql_condition* THD::raise_condition(const Sql_condition *cond) { uint sql_errno= cond->get_sql_errno(); diff --git a/sql/sql_class.h b/sql/sql_class.h index a9299bf984a..735c52c624e 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -4753,16 +4753,7 @@ public: a parse error is discovered internally by the Bison generated parser. */ - void parse_error(const char *err_text, const char *yytext) - { - Lex_input_stream *lip= &m_parser_state->m_lip; - if (!yytext && !(yytext= lip->get_tok_start())) - yytext= ""; - /* Push an error into the error stack */ - ErrConvString err(yytext, strlen(yytext), variables.character_set_client); - my_printf_error(ER_PARSE_ERROR, ER_THD(this, ER_PARSE_ERROR), MYF(0), - err_text, err.ptr(), lip->yylineno); - } + void parse_error(const char *err_text, const char *yytext); void parse_error(uint err_number, const char *yytext= 0) { parse_error(ER_THD(this, err_number), yytext); @@ -5413,13 +5404,7 @@ public: /** Switch to a sublex, to parse a substatement or an expression. */ - void set_local_lex(sp_lex_local *sublex) - { - DBUG_ASSERT(lex->sphead); - lex= sublex; - /* Reset part of parser state which needs this. */ - m_parser_state->m_yacc.reset_before_substatement(); - } + void set_local_lex(sp_lex_local *sublex); /** Switch back from a sublex (currently pointed by this->lex) to the old lex. diff --git a/sql/sql_cte.cc b/sql/sql_cte.cc index 445bc97a3b5..4277a8e2b33 100644 --- a/sql/sql_cte.cc +++ b/sql/sql_cte.cc @@ -22,6 +22,7 @@ #include "sql_parse.h" #include "sql_select.h" #include "sql_show.h" // append_definer, append_identifier +#include "lex_state.h" /** diff --git a/sql/sql_join_cache.h b/sql/sql_join_cache.h index 2c3bf4022ca..439bebe5676 100644 --- a/sql/sql_join_cache.h +++ b/sql/sql_join_cache.h @@ -18,6 +18,7 @@ This file contains declarations for implementations of block based join algorithms */ +#pragma once #define JOIN_CACHE_INCREMENTAL_BIT 1 #define JOIN_CACHE_HASHED_BIT 2 diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index b5f8cf4a886..b04b14740e7 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -37,6 +37,7 @@ #include "sql_partition.h" #include "sql_partition_admin.h" // Sql_cmd_alter_table_*_part #include "event_parse_data.h" +#include "lex_state.h" void LEX::parse_error(uint err_number) { @@ -7965,6 +7966,50 @@ static bool param_push_or_clone(THD *thd, LEX *lex, Item_param *item) } +Query_fragment::Query_fragment(THD *thd, sp_head *sphead, + const char *start, const char *end) +{ + DBUG_ASSERT(start <= end); + if (thd->lex->clone_spec_offset) + { + Lex_input_stream *lip= (& thd->m_parser_state->m_lip); + DBUG_ASSERT(lip->get_buf() <= start); + DBUG_ASSERT(end <= lip->get_end_of_query()); + set(start - lip->get_buf(), end - start); + } + else if (sphead) + { + if (sphead->m_tmp_query) + { + // Normal SP statement + DBUG_ASSERT(sphead->m_tmp_query <= start); + set(start - sphead->m_tmp_query, end - start); + } + else + { + /* + We're in the "if" expression of a compound query: + if (expr) + do_something; + end if; + sphead->m_tmp_query is not set yet at this point, because + the "if" part of such statements is never put into the binary log. + Values of Rewritable_query_parameter::pos_in_query and + Rewritable_query_parameter:len_in_query will not be important, + so setting both to 0 should be fine. + */ + set(0, 0); + } + } + else + { + // Non-SP statement + DBUG_ASSERT(thd->query() <= start); + DBUG_ASSERT(end <= thd->query_end()); + set(start - thd->query(), end - start); + } +} + Item_param *LEX::add_placeholder(THD *thd, const LEX_CSTRING *name, const char *start, const char *end) { diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 14cf90caa04..63d81bd6de0 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -354,24 +354,6 @@ void binlog_unsafe_map_init(); #endif #ifdef MYSQL_SERVER -/* - The following hack is needed because yy_*.cc do not define - YYSTYPE before including this file -*/ -#ifdef MYSQL_YACC -#define LEX_YYSTYPE void * -#else -#include "lex_symbol.h" -#ifdef MYSQL_LEX -#include "item_func.h" /* Cast_target used in yy_mariadb.hh */ -#include "sql_get_diagnostics.h" /* Types used in yy_mariadb.hh */ -#include "sp_pcontext.h" -#include "yy_mariadb.hh" -#define LEX_YYSTYPE YYSTYPE * -#else -#define LEX_YYSTYPE void * -#endif -#endif #endif // describe/explain types @@ -2377,538 +2359,6 @@ struct st_parsing_options /** - The state of the lexical parser, when parsing comments. -*/ -enum enum_comment_state -{ - /** - Not parsing comments. - */ - NO_COMMENT, - /** - Parsing comments that need to be preserved. - Typically, these are user comments '/' '*' ... '*' '/'. - */ - PRESERVE_COMMENT, - /** - Parsing comments that need to be discarded. - Typically, these are special comments '/' '*' '!' ... '*' '/', - or '/' '*' '!' 'M' 'M' 'm' 'm' 'm' ... '*' '/', where the comment - markers should not be expanded. - */ - DISCARD_COMMENT -}; - - -/** - @brief This class represents the character input stream consumed during - lexical analysis. - - In addition to consuming the input stream, this class performs some - comment pre processing, by filtering out out of bound special text - from the query input stream. - Two buffers, with pointers inside each buffers, are maintained in - parallel. The 'raw' buffer is the original query text, which may - contain out-of-bound comments. The 'cpp' (for comments pre processor) - is the pre-processed buffer that contains only the query text that - should be seen once out-of-bound data is removed. -*/ - -class Lex_input_stream -{ - size_t unescape(CHARSET_INFO *cs, char *to, - const char *str, const char *end, int sep); - my_charset_conv_wc_mb get_escape_func(THD *thd, my_wc_t sep) const; -public: - Lex_input_stream() - { - } - - ~Lex_input_stream() - { - } - - /** - Object initializer. Must be called before usage. - - @retval FALSE OK - @retval TRUE Error - */ - bool init(THD *thd, char *buff, size_t length); - - void reset(char *buff, size_t length); - - /** - The main method to scan the next token, with token contraction processing - for LALR(2) resolution, e.g. translate "WITH" followed by "ROLLUP" - to a single token WITH_ROLLUP_SYM. - */ - int lex_token(union YYSTYPE *yylval, THD *thd); - - void reduce_digest_token(uint token_left, uint token_right); - -private: - /** - Set the echo mode. - - When echo is true, characters parsed from the raw input stream are - preserved. When false, characters parsed are silently ignored. - @param echo the echo mode. - */ - void set_echo(bool echo) - { - m_echo= echo; - } - - void save_in_comment_state() - { - m_echo_saved= m_echo; - in_comment_saved= in_comment; - } - - void restore_in_comment_state() - { - m_echo= m_echo_saved; - in_comment= in_comment_saved; - } - - /** - Skip binary from the input stream. - @param n number of bytes to accept. - */ - void skip_binary(int n) - { - if (m_echo) - { - memcpy(m_cpp_ptr, m_ptr, n); - m_cpp_ptr += n; - } - m_ptr += n; - } - - /** - Get a character, and advance in the stream. - @return the next character to parse. - */ - unsigned char yyGet() - { - char c= *m_ptr++; - if (m_echo) - *m_cpp_ptr++ = c; - return c; - } - - /** - Get the last character accepted. - @return the last character accepted. - */ - unsigned char yyGetLast() - { - return m_ptr[-1]; - } - - /** - Look at the next character to parse, but do not accept it. - */ - unsigned char yyPeek() - { - return m_ptr[0]; - } - - /** - Look ahead at some character to parse. - @param n offset of the character to look up - */ - unsigned char yyPeekn(int n) - { - return m_ptr[n]; - } - - /** - Cancel the effect of the last yyGet() or yySkip(). - Note that the echo mode should not change between calls to yyGet / yySkip - and yyUnget. The caller is responsible for ensuring that. - */ - void yyUnget() - { - m_ptr--; - if (m_echo) - m_cpp_ptr--; - } - - /** - Accept a character, by advancing the input stream. - */ - void yySkip() - { - if (m_echo) - *m_cpp_ptr++ = *m_ptr++; - else - m_ptr++; - } - - /** - Accept multiple characters at once. - @param n the number of characters to accept. - */ - void yySkipn(int n) - { - if (m_echo) - { - memcpy(m_cpp_ptr, m_ptr, n); - m_cpp_ptr += n; - } - m_ptr += n; - } - - /** - Puts a character back into the stream, canceling - the effect of the last yyGet() or yySkip(). - Note that the echo mode should not change between calls - to unput, get, or skip from the stream. - */ - char *yyUnput(char ch) - { - *--m_ptr= ch; - if (m_echo) - m_cpp_ptr--; - return m_ptr; - } - - /** - End of file indicator for the query text to parse. - @param n number of characters expected - @return true if there are less than n characters to parse - */ - bool eof(int n) - { - return ((m_ptr + n) >= m_end_of_query); - } - - /** Mark the stream position as the start of a new token. */ - void start_token() - { - m_tok_start_prev= m_tok_start; - m_tok_start= m_ptr; - m_tok_end= m_ptr; - - m_cpp_tok_start_prev= m_cpp_tok_start; - m_cpp_tok_start= m_cpp_ptr; - m_cpp_tok_end= m_cpp_ptr; - } - - /** - Adjust the starting position of the current token. - This is used to compensate for starting whitespace. - */ - void restart_token() - { - m_tok_start= m_ptr; - m_cpp_tok_start= m_cpp_ptr; - } - - /** - Get the maximum length of the utf8-body buffer. - The utf8 body can grow because of the character set conversion and escaping. - */ - size_t get_body_utf8_maximum_length(THD *thd); - - /** Get the length of the current token, in the raw buffer. */ - uint yyLength() - { - /* - The assumption is that the lexical analyser is always 1 character ahead, - which the -1 account for. - */ - DBUG_ASSERT(m_ptr > m_tok_start); - return (uint) ((m_ptr - m_tok_start) - 1); - } - - /** - Test if a lookahead token was already scanned by lex_token(), - for LALR(2) resolution. - */ - bool has_lookahead() const - { - return lookahead_token >= 0; - } - -public: - - /** - End of file indicator for the query text to parse. - @return true if there are no more characters to parse - */ - bool eof() - { - return (m_ptr >= m_end_of_query); - } - - /** Get the raw query buffer. */ - const char *get_buf() - { - return m_buf; - } - - /** Get the pre-processed query buffer. */ - const char *get_cpp_buf() - { - return m_cpp_buf; - } - - /** Get the end of the raw query buffer. */ - const char *get_end_of_query() - { - return m_end_of_query; - } - - /** Get the token start position, in the raw buffer. */ - const char *get_tok_start() - { - return has_lookahead() ? m_tok_start_prev : m_tok_start; - } - - void set_cpp_tok_start(const char *pos) - { - m_cpp_tok_start= pos; - } - - /** Get the token end position, in the raw buffer. */ - const char *get_tok_end() - { - return m_tok_end; - } - - /** Get the current stream pointer, in the raw buffer. */ - const char *get_ptr() - { - return m_ptr; - } - - /** Get the token start position, in the pre-processed buffer. */ - const char *get_cpp_tok_start() - { - return has_lookahead() ? m_cpp_tok_start_prev : m_cpp_tok_start; - } - - /** Get the token end position, in the pre-processed buffer. */ - const char *get_cpp_tok_end() - { - return m_cpp_tok_end; - } - - /** - Get the token end position in the pre-processed buffer, - with trailing spaces removed. - */ - const char *get_cpp_tok_end_rtrim() - { - const char *p; - for (p= m_cpp_tok_end; - p > m_cpp_buf && my_isspace(system_charset_info, p[-1]); - p--) - { } - return p; - } - - /** Get the current stream pointer, in the pre-processed buffer. */ - const char *get_cpp_ptr() - { - return m_cpp_ptr; - } - - /** - Get the current stream pointer, in the pre-processed buffer, - with traling spaces removed. - */ - const char *get_cpp_ptr_rtrim() - { - const char *p; - for (p= m_cpp_ptr; - p > m_cpp_buf && my_isspace(system_charset_info, p[-1]); - p--) - { } - return p; - } - /** Get the utf8-body string. */ - const char *get_body_utf8_str() - { - return m_body_utf8; - } - - /** Get the utf8-body length. */ - size_t get_body_utf8_length() - { - return (size_t) (m_body_utf8_ptr - m_body_utf8); - } - - void body_utf8_start(THD *thd, const char *begin_ptr); - void body_utf8_append(const char *ptr); - void body_utf8_append(const char *ptr, const char *end_ptr); - void body_utf8_append_ident(THD *thd, - const Lex_string_with_metadata_st *txt, - const char *end_ptr); - void body_utf8_append_escape(THD *thd, - const LEX_CSTRING *txt, - CHARSET_INFO *txt_cs, - const char *end_ptr, - my_wc_t sep); - -private: - /** - LALR(2) resolution, look ahead token. - Value of the next token to return, if any, - or -1, if no token was parsed in advance. - Note: 0 is a legal token, and represents YYEOF. - */ - int lookahead_token; - - /** LALR(2) resolution, value of the look ahead token.*/ - LEX_YYSTYPE lookahead_yylval; - - bool get_text(Lex_string_with_metadata_st *to, - uint sep, int pre_skip, int post_skip); - - void add_digest_token(uint token, LEX_YYSTYPE yylval); - - bool consume_comment(int remaining_recursions_permitted); - int lex_one_token(union YYSTYPE *yylval, THD *thd); - int find_keyword(Lex_ident_cli_st *str, uint len, bool function); - LEX_CSTRING get_token(uint skip, uint length); - int scan_ident_sysvar(THD *thd, Lex_ident_cli_st *str); - int scan_ident_start(THD *thd, Lex_ident_cli_st *str); - int scan_ident_middle(THD *thd, Lex_ident_cli_st *str, - CHARSET_INFO **cs, my_lex_states *); - int scan_ident_delimited(THD *thd, Lex_ident_cli_st *str, uchar quote_char); - bool get_7bit_or_8bit_ident(THD *thd, uchar *last_char); - - /** Current thread. */ - THD *m_thd; - - /** Pointer to the current position in the raw input stream. */ - char *m_ptr; - - /** Starting position of the last token parsed, in the raw buffer. */ - const char *m_tok_start; - - /** Ending position of the previous token parsed, in the raw buffer. */ - const char *m_tok_end; - - /** End of the query text in the input stream, in the raw buffer. */ - const char *m_end_of_query; - - /** Starting position of the previous token parsed, in the raw buffer. */ - const char *m_tok_start_prev; - - /** Begining of the query text in the input stream, in the raw buffer. */ - const char *m_buf; - - /** Length of the raw buffer. */ - size_t m_buf_length; - - /** Echo the parsed stream to the pre-processed buffer. */ - bool m_echo:1; - bool m_echo_saved:1; - - /** Pre-processed buffer. */ - char *m_cpp_buf; - - /** Pointer to the current position in the pre-processed input stream. */ - char *m_cpp_ptr; - - /** - Starting position of the last token parsed, - in the pre-processed buffer. - */ - const char *m_cpp_tok_start; - - /** - Starting position of the previous token parsed, - in the pre-procedded buffer. - */ - const char *m_cpp_tok_start_prev; - - /** - Ending position of the previous token parsed, - in the pre-processed buffer. - */ - const char *m_cpp_tok_end; - - /** UTF8-body buffer created during parsing. */ - char *m_body_utf8; - - /** Pointer to the current position in the UTF8-body buffer. */ - char *m_body_utf8_ptr; - - /** - Position in the pre-processed buffer. The query from m_cpp_buf to - m_cpp_utf_processed_ptr is converted to UTF8-body. - */ - const char *m_cpp_utf8_processed_ptr; - -public: - - /** Current state of the lexical analyser. */ - enum my_lex_states next_state; - - /** - Position of ';' in the stream, to delimit multiple queries. - This delimiter is in the raw buffer. - */ - const char *found_semicolon; - - /** SQL_MODE = IGNORE_SPACE. */ - bool ignore_space:1; - - /** - TRUE if we're parsing a prepared statement: in this mode - we should allow placeholders. - */ - bool stmt_prepare_mode:1; - /** - TRUE if we should allow multi-statements. - */ - bool multi_statements:1; - - /** Current line number. */ - uint yylineno; - - /** - Current statement digest instrumentation. - */ - sql_digest_state* m_digest; - -private: - /** State of the lexical analyser for comments. */ - enum_comment_state in_comment; - enum_comment_state in_comment_saved; - - /** - Starting position of the TEXT_STRING or IDENT in the pre-processed - buffer. - - NOTE: this member must be used within MYSQLlex() function only. - */ - const char *m_cpp_text_start; - - /** - Ending position of the TEXT_STRING or IDENT in the pre-processed - buffer. - - NOTE: this member must be used within MYSQLlex() function only. - */ - const char *m_cpp_text_end; - - /** - Character set specified by the character-set-introducer. - - NOTE: this member must be used within MYSQLlex() function only. - */ - CHARSET_INFO *m_underscore_cs; -}; - - -/** Abstract representation of a statement. This class is an interface between the parser and the runtime. The parser builds the appropriate sub classes of Sql_statement @@ -4770,170 +4220,6 @@ public: }; -/** - Set_signal_information is a container used in the parsed tree to represent - the collection of assignments to condition items in the SIGNAL and RESIGNAL - statements. -*/ -class Set_signal_information -{ -public: - /** Empty default constructor, use clear() */ - Set_signal_information() {} - - /** Copy constructor. */ - Set_signal_information(const Set_signal_information& set); - - /** Destructor. */ - ~Set_signal_information() - {} - - /** Clear all items. */ - void clear(); - - /** - For each condition item assignment, m_item[] contains the parsed tree - that represents the expression assigned, if any. - m_item[] is an array indexed by Diag_condition_item_name. - */ - Item *m_item[LAST_DIAG_SET_PROPERTY+1]; -}; - - -/** - The internal state of the syntax parser. - This object is only available during parsing, - and is private to the syntax parser implementation (sql_yacc.yy). -*/ -class Yacc_state -{ -public: - Yacc_state() : yacc_yyss(NULL), yacc_yyvs(NULL) { reset(); } - - void reset() - { - if (yacc_yyss != NULL) { - my_free(yacc_yyss); - yacc_yyss = NULL; - } - if (yacc_yyvs != NULL) { - my_free(yacc_yyvs); - yacc_yyvs = NULL; - } - m_set_signal_info.clear(); - m_lock_type= TL_READ_DEFAULT; - m_mdl_type= MDL_SHARED_READ; - } - - ~Yacc_state(); - - /** - Reset part of the state which needs resetting before parsing - substatement. - */ - void reset_before_substatement() - { - m_lock_type= TL_READ_DEFAULT; - m_mdl_type= MDL_SHARED_READ; - } - - /** - Bison internal state stack, yyss, when dynamically allocated using - my_yyoverflow(). - */ - uchar *yacc_yyss; - - /** - Bison internal semantic value stack, yyvs, when dynamically allocated using - my_yyoverflow(). - */ - uchar *yacc_yyvs; - - /** - Fragments of parsed tree, - used during the parsing of SIGNAL and RESIGNAL. - */ - Set_signal_information m_set_signal_info; - - /** - Type of lock to be used for tables being added to the statement's - table list in table_factor, table_alias_ref, single_multi and - table_wild_one rules. - Statements which use these rules but require lock type different - from one specified by this member have to override it by using - st_select_lex::set_lock_for_tables() method. - - The default value of this member is TL_READ_DEFAULT. The only two - cases in which we change it are: - - When parsing SELECT HIGH_PRIORITY. - - Rule for DELETE. In which we use this member to pass information - about type of lock from delete to single_multi part of rule. - - We should try to avoid introducing new use cases as we would like - to get rid of this member eventually. - */ - thr_lock_type m_lock_type; - - /** - The type of requested metadata lock for tables added to - the statement table list. - */ - enum_mdl_type m_mdl_type; - - /* - TODO: move more attributes from the LEX structure here. - */ -}; - -/** - Internal state of the parser. - The complete state consist of: - - state data used during lexical parsing, - - state data used during syntactic parsing. -*/ -class Parser_state -{ -public: - Parser_state() - : m_yacc() - {} - - /** - Object initializer. Must be called before usage. - - @retval FALSE OK - @retval TRUE Error - */ - bool init(THD *thd, char *buff, size_t length) - { - return m_lip.init(thd, buff, length); - } - - ~Parser_state() - {} - - Lex_input_stream m_lip; - Yacc_state m_yacc; - - /** - Current performance digest instrumentation. - */ - PSI_digest_locker* m_digest_psi; - - void reset(char *found_semicolon, unsigned int length) - { - m_lip.reset(found_semicolon, length); - m_yacc.reset(); - } -}; - - -extern sql_digest_state * -digest_add_token(sql_digest_state *state, uint token, LEX_YYSTYPE yylval); - -extern sql_digest_state * -digest_reduce_token(sql_digest_state *state, uint token_left, uint token_right); - struct st_lex_local: public LEX, public Sql_alloc { }; diff --git a/sql/sql_lifo_buffer.h b/sql/sql_lifo_buffer.h index 0347030e4c6..b4c7ab3a0c4 100644 --- a/sql/sql_lifo_buffer.h +++ b/sql/sql_lifo_buffer.h @@ -13,7 +13,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA */ - +#pragma once /** @defgroup Bi-directional LIFO buffers used by DS-MRR implementation @{ diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index b9d3eec5a60..9605854e98c 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -95,7 +95,8 @@ #include "opt_trace.h" #include "mysql/psi/mysql_sp.h" -#include "my_json_writer.h" +#include "my_json_writer.h" +#include "lex_state.h" #define FLAGSTR(V,F) ((V)&(F)?#F" ":"") diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index b75a318ab65..5383819bc8b 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -69,6 +69,7 @@ #include "sql_select.h" #include "ddl_log.h" #include "tztime.h" // my_tz_OFFSET0 +#include "lex_state.h" #include <algorithm> using std::max; diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index cc6f572ea64..459ad588363 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -134,6 +134,7 @@ static const uint PARAMETER_FLAG_UNSIGNED= 128U << 8; #endif /* WITH_WSREP */ #include "xa.h" // xa_recover_get_fields #include "sql_audit.h" // mysql_audit_release +#include "lex_state.h" /** A result class used to send cursor rows using the binary protocol. diff --git a/sql/sql_signal.h b/sql/sql_signal.h index 433cee21d58..092c917942c 100644 --- a/sql/sql_signal.h +++ b/sql/sql_signal.h @@ -18,6 +18,35 @@ #define SQL_SIGNAL_H /** + Set_signal_information is a container used in the parsed tree to represent + the collection of assignments to condition items in the SIGNAL and RESIGNAL + statements. +*/ +class Set_signal_information +{ +public: + /** Empty default constructor, use clear() */ + Set_signal_information() {} + + /** Copy constructor. */ + Set_signal_information(const Set_signal_information& set); + + /** Destructor. */ + ~Set_signal_information() + {} + + /** Clear all items. */ + void clear(); + + /** + For each condition item assignment, m_item[] contains the parsed tree + that represents the expression assigned, if any. + m_item[] is an array indexed by Diag_condition_item_name. + */ + Item *m_item[LAST_DIAG_SET_PROPERTY+1]; +}; + +/** Sql_cmd_common_signal represents the common properties of the SIGNAL and RESIGNAL statements. */ diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 9dfe2178667..f6b1da53943 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2324,7 +2324,11 @@ static void check_duplicate_key(THD *thd, const Key *key, const KEY *key_info, } if (std::equal(key->columns.begin(), key->columns.end(), k.columns.begin(), - key_cmp)) + [](const Key_part_spec &a, const Key_part_spec &b) + { + return a.length == b.length && + !lex_string_cmp(system_charset_info, &a.field_name, &b.field_name); + })) { push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE, ER_DUP_INDEX, ER_THD(thd, ER_DUP_INDEX), key_info->name.str); diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index 7b3db324db7..1794c411dd7 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -37,6 +37,7 @@ #include "debug_sync.h" // DEBUG_SYNC #include "debug.h" // debug_crash_here #include "mysql/psi/mysql_sp.h" +#include "lex_state.h" /*************************************************************************/ diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 20ac4b086bb..742843d0e86 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -38,6 +38,7 @@ #include "ddl_log.h" #include "debug.h" // debug_crash_here #include "wsrep_mysqld.h" +#include "lex_state.h" #define MD5_BUFF_LENGTH 33 diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 442644eddd6..96b030c5416 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -69,6 +69,7 @@ #include "my_base.h" #include "sql_type_json.h" #include "json_table.h" +#include "lex_state.h" /* this is to get the bison compilation windows warnings out */ #ifdef _MSC_VER diff --git a/sql/table.cc b/sql/table.cc index b1a7b6bfe2b..643e52c190e 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -45,6 +45,7 @@ #include "ha_sequence.h" #include "sql_show.h" #include "opt_trace.h" +#include "lex_state.h" /* For MySQL 5.7 virtual fields */ #define MYSQL57_GENERATED_FIELD 128 diff --git a/sql/threadpool_generic.h b/sql/threadpool_generic.h index b7a35b7cbf0..f254a38bc3a 100644 --- a/sql/threadpool_generic.h +++ b/sql/threadpool_generic.h @@ -13,6 +13,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 - 1301 USA*/ +#pragma once + #if defined (HAVE_POOL_OF_THREADS) #include <my_global.h> #include <sql_plist.h> diff --git a/sql/wsrep_schema.cc b/sql/wsrep_schema.cc index 48077040f88..4d85d8a3cf0 100644 --- a/sql/wsrep_schema.cc +++ b/sql/wsrep_schema.cc @@ -21,6 +21,7 @@ #include "sql_parse.h" #include "sql_update.h" #include "transaction.h" +#include "lex_state.h" #include "mysql/service_wsrep.h" #include "wsrep_schema.h" diff --git a/sql/wsrep_sst.cc b/sql/wsrep_sst.cc index 2adc893c131..275fcd94e99 100644 --- a/sql/wsrep_sst.cc +++ b/sql/wsrep_sst.cc @@ -25,6 +25,7 @@ #include <sql_acl.h> #include <sql_reload.h> #include <sql_parse.h> +#include <lex_state.h> #include "wsrep_priv.h" #include "wsrep_utils.h" #include "wsrep_xid.h" diff --git a/storage/innobase/CMakeLists.txt b/storage/innobase/CMakeLists.txt index 5c138d41f58..239751c0ce5 100644 --- a/storage/innobase/CMakeLists.txt +++ b/storage/innobase/CMakeLists.txt @@ -77,202 +77,6 @@ SET(INNOBASE_SOURCES handler/handler0alter.cc handler/i_s.cc ibuf/ibuf0ibuf.cc - include/btr0btr.h - include/btr0btr.ic - include/btr0bulk.h - include/btr0cur.h - include/btr0cur.ic - include/btr0defragment.h - include/btr0pcur.h - include/btr0pcur.ic - include/btr0sea.h - include/btr0sea.ic - include/btr0types.h - include/buf0buddy.h - include/buf0buf.h - include/buf0buf.ic - include/buf0checksum.h - include/buf0dblwr.h - include/buf0dump.h - include/buf0flu.h - include/buf0lru.h - include/buf0rea.h - include/buf0types.h - include/data0data.h - include/data0data.ic - include/data0type.h - include/data0type.ic - include/data0types.h - include/db0err.h - include/dict0boot.h - include/dict0crea.h - include/dict0crea.ic - include/dict0defrag_bg.h - include/dict0dict.h - include/dict0dict.ic - include/dict0load.h - include/dict0mem.h - include/dict0mem.ic - include/dict0pagecompress.h - include/dict0pagecompress.ic - include/dict0stats.h - include/dict0stats.ic - include/dict0stats_bg.h - include/dict0types.h - include/dyn0buf.h - include/dyn0types.h - include/eval0eval.h - include/eval0eval.ic - include/eval0proc.h - include/eval0proc.ic - include/fil0crypt.h - include/fil0crypt.ic - include/fil0fil.h - include/fil0fil.ic - include/fil0pagecompress.h - include/fsp0file.h - include/fsp0fsp.h - include/fsp0space.h - include/fsp0sysspace.h - include/fsp0types.h - include/fts0ast.h - include/fts0blex.h - include/fts0fts.h - include/fts0opt.h - include/fts0pars.h - include/fts0plugin.h - include/fts0priv.h - include/fts0priv.ic - include/fts0tlex.h - include/fts0tokenize.h - include/fts0types.h - include/fts0types.ic - include/fts0vlc.h - include/fut0fut.h - include/fut0lst.h - include/gis0geo.h - include/gis0rtree.h - include/gis0rtree.ic - include/gis0type.h - include/ha_prototypes.h - include/ha0ha.h - include/ha0ha.ic - include/ha0storage.h - include/ha0storage.ic - include/handler0alter.h - include/hash0hash.h - include/ibuf0ibuf.h - include/ibuf0ibuf.ic - include/ibuf0types.h - include/lock0iter.h - include/lock0lock.h - include/lock0lock.ic - include/lock0prdt.h - include/lock0priv.h - include/lock0priv.ic - include/lock0types.h - include/log0crypt.h - include/log0log.h - include/log0log.ic - include/log0recv.h - include/log0types.h - include/mach0data.h - include/mach0data.ic - include/mem0mem.h - include/mem0mem.ic - include/mtr0log.h - include/mtr0mtr.h - include/mtr0mtr.ic - include/mtr0types.h - include/os0file.h - include/os0file.ic - include/os0thread.h - include/page0cur.h - include/page0cur.ic - include/page0page.h - include/page0page.ic - include/page0types.h - include/page0zip.h - include/page0zip.ic - include/pars0grm.h - include/pars0opt.h - include/pars0pars.h - include/pars0sym.h - include/pars0types.h - include/que0que.h - include/que0que.ic - include/que0types.h - include/read0types.h - include/rem0cmp.h - include/rem0cmp.ic - include/rem0rec.h - include/rem0rec.ic - include/rem0types.h - include/row0ext.h - include/row0ext.ic - include/row0ftsort.h - include/row0import.h - include/row0ins.h - include/row0log.h - include/row0log.ic - include/row0merge.h - include/row0mysql.h - include/row0purge.h - include/row0quiesce.h - include/row0row.h - include/row0row.ic - include/row0sel.h - include/row0sel.ic - include/row0types.h - include/row0uins.h - include/row0umod.h - include/row0undo.h - include/row0upd.h - include/row0upd.ic - include/row0vers.h - include/rw_lock.h - include/srv0mon.h - include/srv0mon.ic - include/srv0srv.h - include/srv0start.h - include/srw_lock.h - include/sux_lock.h - include/trx0i_s.h - include/trx0purge.h - include/trx0rec.h - include/trx0rec.ic - include/trx0roll.h - include/trx0rseg.h - include/trx0rseg.ic - include/trx0sys.h - include/trx0trx.h - include/trx0trx.ic - include/trx0types.h - include/trx0undo.h - include/trx0undo.ic - include/trx0xa.h - include/univ.i - include/ut0byte.h - include/ut0byte.ic - include/ut0counter.h - include/ut0dbg.h - include/ut0list.h - include/ut0list.ic - include/ut0lst.h - include/ut0mem.h - include/ut0mem.ic - include/ut0new.h - include/ut0pool.h - include/ut0rbt.h - include/ut0rnd.h - include/ut0rnd.ic - include/ut0sort.h - include/ut0stage.h - include/ut0ut.h - include/ut0ut.ic - include/ut0vec.h - include/ut0vec.ic - include/ut0wqueue.h lock/lock0iter.cc lock/lock0prdt.cc lock/lock0lock.cc @@ -334,6 +138,207 @@ SET(INNOBASE_SOURCES ut/ut0vec.cc ut/ut0wqueue.cc) +set (INNOBASE_HEADERS + # fts0blex.h + # fts0pars.h + # fts0tlex.h + # fts0tokenize.h + # pars0grm.h + # fts0vlc.h # missing pragma once + # handler0alter.h # missing pragma once + + btr0btr.h + btr0bulk.h + btr0cur.h + buf0block_hint.h +# btr0defragment.h +# btr0pcur.h +# btr0sea.h +# btr0types.h +# buf0buddy.h + buf0buf.h +# buf0checksum.h +# buf0dblwr.h +# buf0dump.h +# buf0flu.h +# buf0lru.h +# buf0rea.h +# buf0types.h +# data0data.h +# data0type.h +# data0types.h +# db0err.h +# dict0boot.h +# dict0crea.h +# dict0defrag_bg.h + dict0dict.h +# dict0load.h + dict0mem.h +# dict0pagecompress.h +# dict0stats.h +# dict0stats_bg.h +# dict0types.h + dyn0buf.h +# dyn0types.h +# eval0eval.h +# eval0proc.h +# fil0crypt.h + fil0fil.h +# fil0pagecompress.h +# fsp0file.h +# fsp0fsp.h +# fsp0space.h +# fsp0sysspace.h +# fsp0types.h +# fts0ast.h +# fts0fts.h +# fts0opt.h +# fts0plugin.h +# fts0priv.h +# fts0types.h +# fut0fut.h +# fut0lst.h +# gis0geo.h +# gis0rtree.h +# gis0type.h +# ha_prototypes.h +# ha0ha.h +# ha0storage.h +# hash0hash.h +# ibuf0ibuf.h +# ibuf0types.h +# lock0iter.h + lock0lock.h +# lock0prdt.h +# lock0types.h +# log0crypt.h +# log0log.h +# log0recv.h +# log0types.h +# mach0data.h +# mem0mem.h + mtr0log.h + mtr0mtr.h +# mtr0types.h +# os0file.h +# os0thread.h +# page0cur.h + page0page.h +# page0types.h +# page0zip.h +# pars0opt.h +# pars0pars.h +# pars0sym.h +# pars0types.h +# que0que.h +# que0types.h +# read0types.h +# rem0cmp.h + rem0rec.h +# rem0types.h +# row0ext.h +# row0ftsort.h +# row0import.h +# row0ins.h +# row0log.h +# row0merge.h + row0mysql.h +# row0purge.h +# row0quiesce.h +# row0row.h +# row0sel.h +# row0types.h +# row0uins.h +# row0umod.h +# row0undo.h +# row0upd.h +# row0vers.h + rw_lock.h +# srv0mon.h + srv0srv.h +# srv0start.h + srw_lock.h + sux_lock.h + transactional_lock_guard.h +# trx0i_s.h +# trx0purge.h +# trx0rec.h +# trx0roll.h + trx0rseg.h + trx0sys.h +# trx0trx.h +# trx0types.h +# trx0undo.h +# trx0xa.h +# univ.i +# ut0byte.h + ut0counter.h +# ut0dbg.h +# ut0list.h + ut0lst.h +# ut0mem.h +# ut0new.h +# ut0pool.h +# ut0rbt.h +# ut0rnd.h +# ut0sort.h +# ut0stage.h +# ut0ut.h +# ut0vec.h +# ut0wqueue.h + ) + # data0data.ic + # btr0btr.ic + # btr0cur.ic + # btr0pcur.ic + # btr0sea.ic + # buf0buf.ic + # data0type.ic + # dict0crea.ic + # dict0dict.ic + # dict0mem.ic + # dict0pagecompress.ic + # dict0stats.ic + # eval0eval.ic + # eval0proc.ic + # fil0crypt.ic + # fil0fil.ic + # fts0priv.ic + # fts0types.ic + # gis0rtree.ic + # ha0ha.ic + # ha0storage.ic + # ibuf0ibuf.ic + # dict0stats.ic + # lock0lock.ic + # log0log.ic + # mach0data.ic + # mem0mem.ic + # mtr0mtr.ic + # os0file.ic + # page0cur.ic + # page0page.ic + # page0zip.ic + # que0que.ic + # rem0cmp.ic + # rem0rec.ic + # row0ext.ic + # row0log.ic + # row0row.ic + # row0sel.ic + # row0upd.ic + # srv0mon.ic + # trx0rseg.ic + # trx0trx.ic + # trx0undo.ic + # ut0byte.ic + # ut0list.ic + # ut0mem.ic + # ut0rnd.ic + # ut0ut.ic + # ut0vec.ic + # trx0rec.ic + OPTION(WITH_PMEM "Support redo log in persistent memory" OFF) FIND_PACKAGE(PMEM) IF(PMEM_FOUND) @@ -360,6 +365,12 @@ IF(NOT TARGET innobase) RETURN() ENDIF() +target_precompile_headers(innobase PRIVATE + "$<$<COMPILE_LANGUAGE:CXX>:${INNOBASE_HEADERS}>") +set_property(SOURCE + fts/fts0pars.cc fts/fts0blex.cc fts/fts0tlex.cc + pars/pars0grm.cc pars/lexyy.cc sync/srw_lock.cc + PROPERTY SKIP_PRECOMPILE_HEADERS yes) ADD_DEFINITIONS(${SSL_DEFINES} ${TPOOL_DEFINES}) # A GCC bug causes crash when compiling these files on ARM64 with -O1+ diff --git a/storage/innobase/handler/ha_innodb.h b/storage/innobase/handler/ha_innodb.h index fac725709db..19fadfe65ff 100644 --- a/storage/innobase/handler/ha_innodb.h +++ b/storage/innobase/handler/ha_innodb.h @@ -16,6 +16,9 @@ this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA *****************************************************************************/ + +#pragma once + #ifdef WITH_WSREP #include "wsrep_api.h" #include <mysql/service_wsrep.h> |