Commit 8075b05b authored by Michael Widenius's avatar Michael Widenius

More merge fixes:

- mdl.cc and mdl.h merged completely
- mysql_system_tables*.sql merged completely
- Fixed wrong merge of lock_tables
- Added some missing functions:
 - bool THD::notify_shared_lock()
 - Dynamic_array::pop, Dynamic_array::del
- Added MDL_context_owner to THD
- Added metadata_locks_hash_instances
parent 7c1abe15
......@@ -20,7 +20,7 @@ IF(NOT CMAKE_CROSSCOMPILING)
ENDIF()
# Build mysql_fix_privilege_tables.sql (concatenate 2 sql scripts)
# Build mysql_fix_privilege_tables.sql (concatenate 3 sql scripts)
IF(NOT WIN32 OR CMAKE_CROSSCOMPILING)
FIND_PROGRAM(CAT_EXECUTABLE cat DOC "path to the executable")
MARK_AS_ADVANCED(CAT_EXECUTABLE)
......
......@@ -80,7 +80,7 @@ DROP PREPARE stmt;
--
SET @cmd="CREATE TABLE performance_schema.events_waits_current("
"THREAD_ID INTEGER not null,"
"THREAD_ID BIGINT unsigned not null,"
"EVENT_ID BIGINT unsigned not null,"
"END_EVENT_ID BIGINT unsigned,"
"EVENT_NAME VARCHAR(128) not null,"
......@@ -111,7 +111,7 @@ DROP PREPARE stmt;
--
SET @cmd="CREATE TABLE performance_schema.events_waits_history("
"THREAD_ID INTEGER not null,"
"THREAD_ID BIGINT unsigned not null,"
"EVENT_ID BIGINT unsigned not null,"
"END_EVENT_ID BIGINT unsigned,"
"EVENT_NAME VARCHAR(128) not null,"
......@@ -142,7 +142,7 @@ DROP PREPARE stmt;
--
SET @cmd="CREATE TABLE performance_schema.events_waits_history_long("
"THREAD_ID INTEGER not null,"
"THREAD_ID BIGINT unsigned not null,"
"EVENT_ID BIGINT unsigned not null,"
"END_EVENT_ID BIGINT unsigned,"
"EVENT_NAME VARCHAR(128) not null,"
......@@ -250,7 +250,7 @@ DROP PREPARE stmt;
--
SET @cmd="CREATE TABLE performance_schema.events_waits_summary_by_thread_by_event_name("
"THREAD_ID INTEGER not null,"
"THREAD_ID BIGINT unsigned not null,"
"EVENT_NAME VARCHAR(128) not null,"
"COUNT_STAR BIGINT unsigned not null,"
"SUM_TIMER_WAIT BIGINT unsigned not null,"
......@@ -377,7 +377,7 @@ DROP PREPARE stmt;
SET @cmd="CREATE TABLE performance_schema.socket_instances("
"EVENT_NAME VARCHAR(128) not null,"
"OBJECT_INSTANCE_BEGIN BIGINT unsigned not null,"
"THREAD_ID INTEGER,"
"THREAD_ID BIGINT unsigned,"
"SOCKET_ID INTEGER not null,"
"IP VARCHAR(64) not null,"
"PORT INTEGER not null,"
......@@ -490,13 +490,14 @@ SET @cmd="CREATE TABLE performance_schema.host_cache("
"COUNT_INIT_CONNECT_ERRORS BIGINT not null,"
"COUNT_LOCAL_ERRORS BIGINT not null,"
"COUNT_UNKNOWN_ERRORS BIGINT not null,"
"FIRST_SEEN TIMESTAMP(0) default 0,"
"LAST_SEEN TIMESTAMP(0) default 0,"
"FIRST_SEEN TIMESTAMP(0) NOT NULL default 0,"
"LAST_SEEN TIMESTAMP(0) NOT NULL default 0,"
"FIRST_ERROR_SEEN TIMESTAMP(0) null default 0,"
"LAST_ERROR_SEEN TIMESTAMP(0) null default 0"
")ENGINE=PERFORMANCE_SCHEMA;";
SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0');
# Host cache is disable until host cache code is merged from 5.6
#PREPARE stmt FROM @str;
#EXECUTE stmt;
#DROP PREPARE stmt;
......@@ -508,7 +509,7 @@ SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0');
SET @cmd="CREATE TABLE performance_schema.mutex_instances("
"NAME VARCHAR(128) not null,"
"OBJECT_INSTANCE_BEGIN BIGINT unsigned not null,"
"LOCKED_BY_THREAD_ID INTEGER"
"LOCKED_BY_THREAD_ID BIGINT unsigned"
")ENGINE=PERFORMANCE_SCHEMA;";
SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0');
......@@ -559,7 +560,7 @@ DROP PREPARE stmt;
SET @cmd="CREATE TABLE performance_schema.rwlock_instances("
"NAME VARCHAR(128) not null,"
"OBJECT_INSTANCE_BEGIN BIGINT unsigned not null,"
"WRITE_LOCKED_BY_THREAD_ID INTEGER,"
"WRITE_LOCKED_BY_THREAD_ID BIGINT unsigned,"
"READ_LOCKED_BY_COUNT INTEGER unsigned not null"
")ENGINE=PERFORMANCE_SCHEMA;";
......@@ -834,10 +835,10 @@ DROP PREPARE stmt;
--
SET @cmd="CREATE TABLE performance_schema.threads("
"THREAD_ID INTEGER not null,"
"THREAD_ID BIGINT unsigned not null,"
"NAME VARCHAR(128) not null,"
"TYPE VARCHAR(10) not null,"
"PROCESSLIST_ID INTEGER,"
"PROCESSLIST_ID BIGINT unsigned,"
"PROCESSLIST_USER VARCHAR(16),"
"PROCESSLIST_HOST VARCHAR(60),"
"PROCESSLIST_DB VARCHAR(64),"
......@@ -845,7 +846,7 @@ SET @cmd="CREATE TABLE performance_schema.threads("
"PROCESSLIST_TIME BIGINT,"
"PROCESSLIST_STATE VARCHAR(64),"
"PROCESSLIST_INFO LONGTEXT,"
"PARENT_THREAD_ID INTEGER,"
"PARENT_THREAD_ID BIGINT unsigned,"
"ROLE VARCHAR(64),"
"INSTRUMENTED ENUM ('YES', 'NO') not null"
")ENGINE=PERFORMANCE_SCHEMA;";
......@@ -860,7 +861,7 @@ DROP PREPARE stmt;
--
SET @cmd="CREATE TABLE performance_schema.events_stages_current("
"THREAD_ID INTEGER not null,"
"THREAD_ID BIGINT unsigned not null,"
"EVENT_ID BIGINT unsigned not null,"
"END_EVENT_ID BIGINT unsigned,"
"EVENT_NAME VARCHAR(128) not null,"
......@@ -882,7 +883,7 @@ DROP PREPARE stmt;
--
SET @cmd="CREATE TABLE performance_schema.events_stages_history("
"THREAD_ID INTEGER not null,"
"THREAD_ID BIGINT unsigned not null,"
"EVENT_ID BIGINT unsigned not null,"
"END_EVENT_ID BIGINT unsigned,"
"EVENT_NAME VARCHAR(128) not null,"
......@@ -904,7 +905,7 @@ DROP PREPARE stmt;
--
SET @cmd="CREATE TABLE performance_schema.events_stages_history_long("
"THREAD_ID INTEGER not null,"
"THREAD_ID BIGINT unsigned not null,"
"EVENT_ID BIGINT unsigned not null,"
"END_EVENT_ID BIGINT unsigned,"
"EVENT_NAME VARCHAR(128) not null,"
......@@ -926,7 +927,7 @@ DROP PREPARE stmt;
--
SET @cmd="CREATE TABLE performance_schema.events_stages_summary_by_thread_by_event_name("
"THREAD_ID INTEGER not null,"
"THREAD_ID BIGINT unsigned not null,"
"EVENT_NAME VARCHAR(128) not null,"
"COUNT_STAR BIGINT unsigned not null,"
"SUM_TIMER_WAIT BIGINT unsigned not null,"
......@@ -1021,7 +1022,7 @@ DROP PREPARE stmt;
--
SET @cmd="CREATE TABLE performance_schema.events_statements_current("
"THREAD_ID INTEGER not null,"
"THREAD_ID BIGINT unsigned not null,"
"EVENT_ID BIGINT unsigned not null,"
"END_EVENT_ID BIGINT unsigned,"
"EVENT_NAME VARCHAR(128) not null,"
......@@ -1073,7 +1074,7 @@ DROP PREPARE stmt;
--
SET @cmd="CREATE TABLE performance_schema.events_statements_history("
"THREAD_ID INTEGER not null,"
"THREAD_ID BIGINT unsigned not null,"
"EVENT_ID BIGINT unsigned not null,"
"END_EVENT_ID BIGINT unsigned,"
"EVENT_NAME VARCHAR(128) not null,"
......@@ -1125,7 +1126,7 @@ DROP PREPARE stmt;
--
SET @cmd="CREATE TABLE performance_schema.events_statements_history_long("
"THREAD_ID INTEGER not null,"
"THREAD_ID BIGINT unsigned not null,"
"EVENT_ID BIGINT unsigned not null,"
"END_EVENT_ID BIGINT unsigned,"
"EVENT_NAME VARCHAR(128) not null,"
......@@ -1177,7 +1178,7 @@ DROP PREPARE stmt;
--
SET @cmd="CREATE TABLE performance_schema.events_statements_summary_by_thread_by_event_name("
"THREAD_ID INTEGER not null,"
"THREAD_ID BIGINT unsigned not null,"
"EVENT_NAME VARCHAR(128) not null,"
"COUNT_STAR BIGINT unsigned not null,"
"SUM_TIMER_WAIT BIGINT unsigned not null,"
......@@ -1413,6 +1414,7 @@ DROP PREPARE stmt;
--
SET @cmd="CREATE TABLE performance_schema.events_statements_summary_by_digest("
"SCHEMA_NAME VARCHAR(64),"
"DIGEST VARCHAR(32),"
"DIGEST_TEXT LONGTEXT,"
"COUNT_STAR BIGINT unsigned not null,"
......@@ -1439,8 +1441,8 @@ SET @cmd="CREATE TABLE performance_schema.events_statements_summary_by_digest("
"SUM_SORT_SCAN BIGINT unsigned not null,"
"SUM_NO_INDEX_USED BIGINT unsigned not null,"
"SUM_NO_GOOD_INDEX_USED BIGINT unsigned not null,"
"FIRST_SEEN TIMESTAMP(0) default 0,"
"LAST_SEEN TIMESTAMP(0) default 0"
"FIRST_SEEN TIMESTAMP(0) NOT NULL default 0,"
"LAST_SEEN TIMESTAMP(0) NOT NULL default 0"
")ENGINE=PERFORMANCE_SCHEMA;";
......@@ -1449,3 +1451,30 @@ PREPARE stmt FROM @str;
EXECUTE stmt;
DROP PREPARE stmt;
--
-- TABLE SESSION_CONNECT_ATTRS
--
SET @cmd="CREATE TABLE performance_schema.session_connect_attrs("
"PROCESSLIST_ID INT NOT NULL,"
"ATTR_NAME VARCHAR(32) NOT NULL,"
"ATTR_VALUE VARCHAR(1024),"
"ORDINAL_POSITION INT"
")ENGINE=PERFORMANCE_SCHEMA CHARACTER SET utf8 COLLATE utf8_bin;";
SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0');
PREPARE stmt FROM @str;
EXECUTE stmt;
DROP PREPARE stmt;
--
-- TABLE SESSION_ACCOUNT_CONNECT_ATTRS
--
SET @cmd="CREATE TABLE performance_schema.session_account_connect_attrs "
" LIKE performance_schema.session_connect_attrs;";
SET @str = IF(@have_pfs = 1, @cmd, 'SET @dummy = 0');
PREPARE stmt FROM @str;
EXECUTE stmt;
DROP PREPARE stmt;
-- Copyright (c) 2007, 2011, Oracle and/or its affiliates.
-- Copyright (c) 2007, 2008 MySQL AB, 2009 Sun Microsystems, Inc.
-- Copyright (c) 2008-2012 Monty Program Ab
-- Copyright (c) 2008-2013 Monty Program Ab & SkySQL Ab
--
-- 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
......@@ -21,7 +21,6 @@
set sql_mode='';
set storage_engine=myisam;
flush tables;
CREATE TABLE IF NOT EXISTS db ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db,User), KEY User (User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Database privileges';
......@@ -30,7 +29,7 @@ set @had_db_table= @@warning_count != 0;
CREATE TABLE IF NOT EXISTS host ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Host privileges; Merged with database privileges';
CREATE TABLE IF NOT EXISTS user ( Host char(60) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Password char(41) character set latin1 collate latin1_bin DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tablespace_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL, ssl_cipher BLOB NOT NULL, x509_issuer BLOB NOT NULL, x509_subject BLOB NOT NULL, max_questions int(11) unsigned DEFAULT 0 NOT NULL, max_updates int(11) unsigned DEFAULT 0 NOT NULL, max_connections int(11) unsigned DEFAULT 0 NOT NULL, max_user_connections int(11) DEFAULT 0 NOT NULL, plugin char(64) CHARACTER SET latin1 DEFAULT '' NOT NULL, authentication_string TEXT NOT NULL, PRIMARY KEY Host (Host,User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users and global privileges';
CREATE TABLE IF NOT EXISTS user ( Host char(60) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Password char(41) character set latin1 collate latin1_bin DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tablespace_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL, ssl_cipher BLOB NOT NULL, x509_issuer BLOB NOT NULL, x509_subject BLOB NOT NULL, max_questions int(11) unsigned DEFAULT 0 NOT NULL, max_updates int(11) unsigned DEFAULT 0 NOT NULL, max_connections int(11) unsigned DEFAULT 0 NOT NULL, max_user_connections int(11) DEFAULT 0 NOT NULL, plugin char(64) CHARACTER SET latin1 DEFAULT '' NOT NULL, authentication_string TEXT NOT NULL, password_expired ENUM('N', 'Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users and global privileges';
-- Remember for later if user table already existed
set @had_user_table= @@warning_count != 0;
......@@ -45,9 +44,9 @@ CREATE TABLE IF NOT EXISTS plugin ( name varchar(64) DEFAULT '' NOT NULL, dl var
CREATE TABLE IF NOT EXISTS servers ( Server_name char(64) NOT NULL DEFAULT '', Host char(64) NOT NULL DEFAULT '', Db char(64) NOT NULL DEFAULT '', Username char(64) NOT NULL DEFAULT '', Password char(64) NOT NULL DEFAULT '', Port INT(4) NOT NULL DEFAULT '0', Socket char(64) NOT NULL DEFAULT '', Wrapper char(64) NOT NULL DEFAULT '', Owner char(64) NOT NULL DEFAULT '', PRIMARY KEY (Server_name)) CHARACTER SET utf8 comment='MySQL Foreign Servers table';
CREATE TABLE IF NOT EXISTS tables_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Table_name char(64) binary DEFAULT '' NOT NULL, Grantor char(77) DEFAULT '' NOT NULL, Timestamp timestamp, Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter','Create View','Show view','Trigger') COLLATE utf8_general_ci DEFAULT '' NOT NULL, Column_priv set('Select','Insert','Update','References') COLLATE utf8_general_ci DEFAULT '' NOT NULL, PRIMARY KEY (Host,Db,User,Table_name), KEY Grantor (Grantor) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Table privileges';
CREATE TABLE IF NOT EXISTS tables_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Table_name char(64) binary DEFAULT '' NOT NULL, Grantor char(77) DEFAULT '' NOT NULL, Timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter','Create View','Show view','Trigger') COLLATE utf8_general_ci DEFAULT '' NOT NULL, Column_priv set('Select','Insert','Update','References') COLLATE utf8_general_ci DEFAULT '' NOT NULL, PRIMARY KEY (Host,Db,User,Table_name), KEY Grantor (Grantor) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Table privileges';
CREATE TABLE IF NOT EXISTS columns_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Table_name char(64) binary DEFAULT '' NOT NULL, Column_name char(64) binary DEFAULT '' NOT NULL, Timestamp timestamp, Column_priv set('Select','Insert','Update','References') COLLATE utf8_general_ci DEFAULT '' NOT NULL, PRIMARY KEY (Host,Db,User,Table_name,Column_name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Column privileges';
CREATE TABLE IF NOT EXISTS columns_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Table_name char(64) binary DEFAULT '' NOT NULL, Column_name char(64) binary DEFAULT '' NOT NULL, Timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, Column_priv set('Select','Insert','Update','References') COLLATE utf8_general_ci DEFAULT '' NOT NULL, PRIMARY KEY (Host,Db,User,Table_name,Column_name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Column privileges';
CREATE TABLE IF NOT EXISTS help_topic ( help_topic_id int unsigned not null, name char(64) not null, help_category_id smallint unsigned not null, description text not null, example text not null, url char(128) not null, primary key (help_topic_id), unique index (name) ) engine=MyISAM CHARACTER SET utf8 comment='help topics';
......@@ -76,13 +75,15 @@ CREATE TABLE IF NOT EXISTS time_zone_transition_type ( Time_zone_id int unsign
CREATE TABLE IF NOT EXISTS time_zone_leap_second ( Transition_time bigint signed NOT NULL, Correction int signed NOT NULL, PRIMARY KEY TranTime (Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Leap seconds information for time zones';
CREATE TABLE IF NOT EXISTS proc (db char(64) collate utf8_bin DEFAULT '' NOT NULL, name char(64) DEFAULT '' NOT NULL, type enum('FUNCTION','PROCEDURE') NOT NULL, specific_name char(64) DEFAULT '' NOT NULL, language enum('SQL') DEFAULT 'SQL' NOT NULL, sql_data_access enum( 'CONTAINS_SQL', 'NO_SQL', 'READS_SQL_DATA', 'MODIFIES_SQL_DATA') DEFAULT 'CONTAINS_SQL' NOT NULL, is_deterministic enum('YES','NO') DEFAULT 'NO' NOT NULL, security_type enum('INVOKER','DEFINER') DEFAULT 'DEFINER' NOT NULL, param_list blob NOT NULL, returns longblob DEFAULT '' NOT NULL, body longblob NOT NULL, definer char(77) collate utf8_bin DEFAULT '' NOT NULL, created timestamp, modified timestamp, sql_mode set( 'REAL_AS_FLOAT', 'PIPES_AS_CONCAT', 'ANSI_QUOTES', 'IGNORE_SPACE', 'IGNORE_BAD_TABLE_OPTIONS', 'ONLY_FULL_GROUP_BY', 'NO_UNSIGNED_SUBTRACTION', 'NO_DIR_IN_CREATE', 'POSTGRESQL', 'ORACLE', 'MSSQL', 'DB2', 'MAXDB', 'NO_KEY_OPTIONS', 'NO_TABLE_OPTIONS', 'NO_FIELD_OPTIONS', 'MYSQL323', 'MYSQL40', 'ANSI', 'NO_AUTO_VALUE_ON_ZERO', 'NO_BACKSLASH_ESCAPES', 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'NO_ZERO_IN_DATE', 'NO_ZERO_DATE', 'INVALID_DATES', 'ERROR_FOR_DIVISION_BY_ZERO', 'TRADITIONAL', 'NO_AUTO_CREATE_USER', 'HIGH_NOT_PRECEDENCE', 'NO_ENGINE_SUBSTITUTION', 'PAD_CHAR_TO_FULL_LENGTH') DEFAULT '' NOT NULL, comment text collate utf8_bin NOT NULL, character_set_client char(32) collate utf8_bin, collation_connection char(32) collate utf8_bin, db_collation char(32) collate utf8_bin, body_utf8 longblob, PRIMARY KEY (db,name,type)) engine=MyISAM character set utf8 comment='Stored Procedures';
CREATE TABLE IF NOT EXISTS proc (db char(64) collate utf8_bin DEFAULT '' NOT NULL, name char(64) DEFAULT '' NOT NULL, type enum('FUNCTION','PROCEDURE') NOT NULL, specific_name char(64) DEFAULT '' NOT NULL, language enum('SQL') DEFAULT 'SQL' NOT NULL, sql_data_access enum( 'CONTAINS_SQL', 'NO_SQL', 'READS_SQL_DATA', 'MODIFIES_SQL_DATA') DEFAULT 'CONTAINS_SQL' NOT NULL, is_deterministic enum('YES','NO') DEFAULT 'NO' NOT NULL, security_type enum('INVOKER','DEFINER') DEFAULT 'DEFINER' NOT NULL, param_list blob NOT NULL, returns longblob DEFAULT '' NOT NULL, body longblob NOT NULL, definer char(77) collate utf8_bin DEFAULT '' NOT NULL, created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, modified timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', sql_mode set( 'REAL_AS_FLOAT', 'PIPES_AS_CONCAT', 'ANSI_QUOTES', 'IGNORE_SPACE', 'IGNORE_BAD_TABLE_OPTIONS', 'ONLY_FULL_GROUP_BY', 'NO_UNSIGNED_SUBTRACTION', 'NO_DIR_IN_CREATE', 'POSTGRESQL', 'ORACLE', 'MSSQL', 'DB2', 'MAXDB', 'NO_KEY_OPTIONS', 'NO_TABLE_OPTIONS', 'NO_FIELD_OPTIONS', 'MYSQL323', 'MYSQL40', 'ANSI', 'NO_AUTO_VALUE_ON_ZERO', 'NO_BACKSLASH_ESCAPES', 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'NO_ZERO_IN_DATE', 'NO_ZERO_DATE', 'INVALID_DATES', 'ERROR_FOR_DIVISION_BY_ZERO', 'TRADITIONAL', 'NO_AUTO_CREATE_USER', 'HIGH_NOT_PRECEDENCE', 'NO_ENGINE_SUBSTITUTION', 'PAD_CHAR_TO_FULL_LENGTH') DEFAULT '' NOT NULL, comment text collate utf8_bin NOT NULL, character_set_client char(32) collate utf8_bin, collation_connection char(32) collate utf8_bin, db_collation char(32) collate utf8_bin, body_utf8 longblob, PRIMARY KEY (db,name,type)) engine=MyISAM character set utf8 comment='Stored Procedures';
CREATE TABLE IF NOT EXISTS procs_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Routine_name char(64) COLLATE utf8_general_ci DEFAULT '' NOT NULL, Routine_type enum('FUNCTION','PROCEDURE') NOT NULL, Grantor char(77) DEFAULT '' NOT NULL, Proc_priv set('Execute','Alter Routine','Grant') COLLATE utf8_general_ci DEFAULT '' NOT NULL, Timestamp timestamp, PRIMARY KEY (Host,Db,User,Routine_name,Routine_type), KEY Grantor (Grantor) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Procedure privileges';
CREATE TABLE IF NOT EXISTS procs_priv ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Routine_name char(64) COLLATE utf8_general_ci DEFAULT '' NOT NULL, Routine_type enum('FUNCTION','PROCEDURE') NOT NULL, Grantor char(77) DEFAULT '' NOT NULL, Proc_priv set('Execute','Alter Routine','Grant') COLLATE utf8_general_ci DEFAULT '' NOT NULL, Timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (Host,Db,User,Routine_name,Routine_type), KEY Grantor (Grantor) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Procedure privileges';
-- Create general_log if CSV is enabled.
SET @str = IF (@@have_csv = 'YES', 'CREATE TABLE IF NOT EXISTS general_log (event_time TIMESTAMP(6) NOT NULL, user_host MEDIUMTEXT NOT NULL, thread_id INTEGER NOT NULL, server_id INTEGER UNSIGNED NOT NULL, command_type VARCHAR(64) NOT NULL, argument MEDIUMTEXT NOT NULL) engine=CSV CHARACTER SET utf8 comment="General log"', 'SET @dummy = 0');
-- Create general_log if CSV is enabled.
SET @have_csv = (SELECT support FROM information_schema.engines WHERE engine = 'CSV');
SET @str = IF (@have_csv = 'YES', 'CREATE TABLE IF NOT EXISTS general_log (event_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, user_host MEDIUMTEXT NOT NULL, thread_id BIGINT(21) UNSIGNED NOT NULL, server_id INTEGER UNSIGNED NOT NULL, command_type VARCHAR(64) NOT NULL, argument MEDIUMTEXT NOT NULL) engine=CSV CHARACTER SET utf8 comment="General log"', 'SET @dummy = 0');
PREPARE stmt FROM @str;
EXECUTE stmt;
......@@ -90,22 +91,13 @@ DROP PREPARE stmt;
-- Create slow_log if CSV is enabled.
SET @str = IF (@@have_csv = 'YES', 'CREATE TABLE IF NOT EXISTS slow_log (start_time TIMESTAMP(6) NOT NULL, user_host MEDIUMTEXT NOT NULL, query_time TIME(6) NOT NULL, lock_time TIME(6) NOT NULL, rows_sent INTEGER NOT NULL, rows_examined INTEGER NOT NULL, db VARCHAR(512) NOT NULL, last_insert_id INTEGER NOT NULL, insert_id INTEGER NOT NULL, server_id INTEGER UNSIGNED NOT NULL, sql_text MEDIUMTEXT NOT NULL) engine=CSV CHARACTER SET utf8 comment="Slow log"', 'SET @dummy = 0');
SET @str = IF (@have_csv = 'YES', 'CREATE TABLE IF NOT EXISTS slow_log (start_time TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, user_host MEDIUMTEXT NOT NULL, query_time TIME(6) NOT NULL, lock_time TIME(6) NOT NULL, rows_sent INTEGER NOT NULL, rows_examined INTEGER NOT NULL, db VARCHAR(512) NOT NULL, last_insert_id INTEGER NOT NULL, insert_id INTEGER NOT NULL, server_id INTEGER UNSIGNED NOT NULL, sql_text MEDIUMTEXT NOT NULL, thread_id BIGINT(21) UNSIGNED NOT NULL) engine=CSV CHARACTER SET utf8 comment="Slow log"', 'SET @dummy = 0');
PREPARE stmt FROM @str;
EXECUTE stmt;
DROP PREPARE stmt;
CREATE TABLE IF NOT EXISTS event ( db char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', name char(64) CHARACTER SET utf8 NOT NULL default '', body longblob NOT NULL, definer char(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', execute_at DATETIME default NULL, interval_value int(11) default NULL, interval_field ENUM('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK','SECOND','MICROSECOND','YEAR_MONTH','DAY_HOUR','DAY_MINUTE','DAY_SECOND','HOUR_MINUTE','HOUR_SECOND','MINUTE_SECOND','DAY_MICROSECOND','HOUR_MICROSECOND','MINUTE_MICROSECOND','SECOND_MICROSECOND') default NULL, created TIMESTAMP NOT NULL, modified TIMESTAMP NOT NULL, last_executed DATETIME default NULL, starts DATETIME default NULL, ends DATETIME default NULL, status ENUM('ENABLED','DISABLED','SLAVESIDE_DISABLED') NOT NULL default 'ENABLED', on_completion ENUM('DROP','PRESERVE') NOT NULL default 'DROP', sql_mode set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','IGNORE_BAD_TABLE_OPTIONS','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE','NO_ENGINE_SUBSTITUTION','PAD_CHAR_TO_FULL_LENGTH') DEFAULT '' NOT NULL, comment char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', originator INTEGER UNSIGNED NOT NULL, time_zone char(64) CHARACTER SET latin1 NOT NULL DEFAULT 'SYSTEM', character_set_client char(32) collate utf8_bin, collation_connection char(32) collate utf8_bin, db_collation char(32) collate utf8_bin, body_utf8 longblob, PRIMARY KEY (db, name) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT 'Events';
CREATE TABLE IF NOT EXISTS ndb_binlog_index (Position BIGINT UNSIGNED NOT NULL, File VARCHAR(255) NOT NULL, epoch BIGINT UNSIGNED NOT NULL, inserts BIGINT UNSIGNED NOT NULL, updates BIGINT UNSIGNED NOT NULL, deletes BIGINT UNSIGNED NOT NULL, schemaops BIGINT UNSIGNED NOT NULL, PRIMARY KEY(epoch)) ENGINE=MYISAM;
CREATE TABLE IF NOT EXISTS slave_relay_log_info (Master_id INTEGER UNSIGNED NOT NULL, Number_of_lines INTEGER UNSIGNED NOT NULL COMMENT 'Number of lines in the file or rows in the table. Used to version table definitions.', Relay_log_name TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'The name of the current relay log file.', Relay_log_pos BIGINT UNSIGNED NOT NULL COMMENT 'The relay log position of the last executed event.', Master_log_name TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'The name of the master binary log file from which the events in the relay log file were read.', Master_log_pos BIGINT UNSIGNED NOT NULL COMMENT 'The master log position of the last executed event.', Sql_delay INTEGER NOT NULL COMMENT 'The number of seconds that the slave must lag behind the master.', Number_of_workers INTEGER UNSIGNED NOT NULL, PRIMARY KEY(Master_id)) ENGINE=MYISAM DEFAULT CHARSET=utf8 COMMENT 'Relay Log Information';
CREATE TABLE IF NOT EXISTS slave_master_info (Master_id INTEGER UNSIGNED NOT NULL, Number_of_lines INTEGER UNSIGNED NOT NULL COMMENT 'Number of lines in the file.', Master_log_name TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'The name of the master binary log currently being read from the master.', Master_log_pos BIGINT UNSIGNED NOT NULL COMMENT 'The master log position of the last read event.', Host TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The host name of the master.', User_name TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The user name used to connect to the master.', User_password TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The password used to connect to the master.', Port INTEGER UNSIGNED NOT NULL COMMENT 'The network port used to connect to the master.', Connect_retry INTEGER UNSIGNED NOT NULL COMMENT 'The period (in seconds) that the slave will wait before trying to reconnect to the master.', Enabled_ssl BOOLEAN NOT NULL COMMENT 'Indicates whether the server supports SSL connections.', Ssl_ca TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The file used for the Certificate Authority (CA) certificate.', Ssl_capath TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The path to the Certificate Authority (CA) certificates.', Ssl_cert TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The name of the SSL certificate file.', Ssl_cipher TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The name of the cipher in use for the SSL connection.', Ssl_key TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The name of the SSL key file.', Ssl_verify_server_cert BOOLEAN NOT NULL COMMENT 'Whether to verify the server certificate.', Heartbeat FLOAT NOT NULL COMMENT '', Bind TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'Displays which interface is employed when connecting to the MySQL server', Ignored_server_ids TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The number of server IDs to be ignored, followed by the actual server IDs', Uuid TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The master server uuid.', Retry_count BIGINT UNSIGNED NOT NULL COMMENT 'Number of reconnect attempts, to the master, before giving up.', Ssl_crl TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The file used for the Certificate Revocation List (CRL)', Ssl_crlpath TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The path used for Certificate Revocation List (CRL) files', PRIMARY KEY(Master_id)) ENGINE=MYISAM DEFAULT CHARSET=utf8 COMMENT 'Master Information';
CREATE TABLE IF NOT EXISTS slave_worker_info (Master_id INTEGER UNSIGNED NOT NULL, Worker_id INTEGER UNSIGNED NOT NULL, Relay_log_name TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, Relay_log_pos BIGINT UNSIGNED NOT NULL, Master_log_name TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, Master_log_pos BIGINT UNSIGNED NOT NULL, Checkpoint_relay_log_name TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, Checkpoint_relay_log_pos BIGINT UNSIGNED NOT NULL, Checkpoint_master_log_name TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, Checkpoint_master_log_pos BIGINT UNSIGNED NOT NULL, Checkpoint_seqno INT UNSIGNED NOT NULL, Checkpoint_group_size INTEGER UNSIGNED NOT NULL, Checkpoint_group_bitmap BLOB NOT NULL, PRIMARY KEY(Master_id, Worker_id)) ENGINE=MYISAM DEFAULT CHARSET=utf8 COMMENT 'Worker Information';
CREATE TABLE IF NOT EXISTS event ( db char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', name char(64) CHARACTER SET utf8 NOT NULL default '', body longblob NOT NULL, definer char(77) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', execute_at DATETIME default NULL, interval_value int(11) default NULL, interval_field ENUM('YEAR','QUARTER','MONTH','DAY','HOUR','MINUTE','WEEK','SECOND','MICROSECOND','YEAR_MONTH','DAY_HOUR','DAY_MINUTE','DAY_SECOND','HOUR_MINUTE','HOUR_SECOND','MINUTE_SECOND','DAY_MICROSECOND','HOUR_MICROSECOND','MINUTE_MICROSECOND','SECOND_MICROSECOND') default NULL, created TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, modified TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00', last_executed DATETIME default NULL, starts DATETIME default NULL, ends DATETIME default NULL, status ENUM('ENABLED','DISABLED','SLAVESIDE_DISABLED') NOT NULL default 'ENABLED', on_completion ENUM('DROP','PRESERVE') NOT NULL default 'DROP', sql_mode set('REAL_AS_FLOAT','PIPES_AS_CONCAT','ANSI_QUOTES','IGNORE_SPACE','IGNORE_BAD_TABLE_OPTIONS','ONLY_FULL_GROUP_BY','NO_UNSIGNED_SUBTRACTION','NO_DIR_IN_CREATE','POSTGRESQL','ORACLE','MSSQL','DB2','MAXDB','NO_KEY_OPTIONS','NO_TABLE_OPTIONS','NO_FIELD_OPTIONS','MYSQL323','MYSQL40','ANSI','NO_AUTO_VALUE_ON_ZERO','NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLES','STRICT_ALL_TABLES','NO_ZERO_IN_DATE','NO_ZERO_DATE','INVALID_DATES','ERROR_FOR_DIVISION_BY_ZERO','TRADITIONAL','NO_AUTO_CREATE_USER','HIGH_NOT_PRECEDENCE','NO_ENGINE_SUBSTITUTION','PAD_CHAR_TO_FULL_LENGTH') DEFAULT '' NOT NULL, comment char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL default '', originator INTEGER UNSIGNED NOT NULL, time_zone char(64) CHARACTER SET latin1 NOT NULL DEFAULT 'SYSTEM', character_set_client char(32) collate utf8_bin, collation_connection char(32) collate utf8_bin, db_collation char(32) collate utf8_bin, body_utf8 longblob, PRIMARY KEY (db, name) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT 'Events';
SET @sql_mode_orig=@@SESSION.sql_mode;
SET SESSION sql_mode='NO_ENGINE_SUBSTITUTION';
......@@ -113,18 +105,18 @@ SET SESSION sql_mode='NO_ENGINE_SUBSTITUTION';
CREATE TABLE IF NOT EXISTS innodb_table_stats (
database_name VARCHAR(64) NOT NULL,
table_name VARCHAR(64) NOT NULL,
last_update TIMESTAMP NOT NULL,
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
n_rows BIGINT UNSIGNED NOT NULL,
clustered_index_size BIGINT UNSIGNED NOT NULL,
sum_of_other_index_sizes BIGINT UNSIGNED NOT NULL,
PRIMARY KEY (database_name, table_name)
) ENGINE=INNODB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
) ENGINE=INNODB DEFAULT CHARSET=utf8 COLLATE=utf8_bin STATS_PERSISTENT=0;
CREATE TABLE IF NOT EXISTS innodb_index_stats (
database_name VARCHAR(64) NOT NULL,
table_name VARCHAR(64) NOT NULL,
index_name VARCHAR(64) NOT NULL,
last_update TIMESTAMP NOT NULL,
last_update TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
/* there are at least:
stat_name='size'
stat_name='n_leaf_pages'
......@@ -133,18 +125,92 @@ CREATE TABLE IF NOT EXISTS innodb_index_stats (
stat_value BIGINT UNSIGNED NOT NULL,
sample_size BIGINT UNSIGNED,
stat_description VARCHAR(1024) NOT NULL,
PRIMARY KEY (database_name, table_name, index_name, stat_name),
FOREIGN KEY (database_name, table_name)
REFERENCES innodb_table_stats (database_name, table_name)
) ENGINE=INNODB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
PRIMARY KEY (database_name, table_name, index_name, stat_name)
) ENGINE=INNODB DEFAULT CHARSET=utf8 COLLATE=utf8_bin STATS_PERSISTENT=0;
SET SESSION sql_mode=@sql_mode_orig;
CREATE TABLE IF NOT EXISTS proxies_priv (Host char(60) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Proxied_host char(60) binary DEFAULT '' NOT NULL, Proxied_user char(16) binary DEFAULT '' NOT NULL, With_grant BOOL DEFAULT 0 NOT NULL, Grantor char(77) DEFAULT '' NOT NULL, Timestamp timestamp, PRIMARY KEY Host (Host,User,Proxied_host,Proxied_user), KEY Grantor (Grantor) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='User proxy privileges';
set @have_innodb= (select count(engine) from information_schema.engines where engine='INNODB' and support != 'NO');
SET @cmd="CREATE TABLE IF NOT EXISTS slave_relay_log_info (
Number_of_lines INTEGER UNSIGNED NOT NULL COMMENT 'Number of lines in the file or rows in the table. Used to version table definitions.',
Relay_log_name TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'The name of the current relay log file.',
Relay_log_pos BIGINT UNSIGNED NOT NULL COMMENT 'The relay log position of the last executed event.',
Master_log_name TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'The name of the master binary log file from which the events in the relay log file were read.',
Master_log_pos BIGINT UNSIGNED NOT NULL COMMENT 'The master log position of the last executed event.',
Sql_delay INTEGER NOT NULL COMMENT 'The number of seconds that the slave must lag behind the master.',
Number_of_workers INTEGER UNSIGNED NOT NULL,
Id INTEGER UNSIGNED NOT NULL COMMENT 'Internal Id that uniquely identifies this record.',
PRIMARY KEY(Id)) DEFAULT CHARSET=utf8 STATS_PERSISTENT=0 COMMENT 'Relay Log Information'";
SET @str=IF(@have_innodb <> 0, CONCAT(@cmd, ' ENGINE= INNODB;'), CONCAT(@cmd, ' ENGINE= MYISAM;'));
-- Don't create the table; MariaDB will have another implementation
#PREPARE stmt FROM @str;
#EXECUTE stmt;
#DROP PREPARE stmt;
SET @cmd= "CREATE TABLE IF NOT EXISTS slave_master_info (
Number_of_lines INTEGER UNSIGNED NOT NULL COMMENT 'Number of lines in the file.',
Master_log_name TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT 'The name of the master binary log currently being read from the master.',
Master_log_pos BIGINT UNSIGNED NOT NULL COMMENT 'The master log position of the last read event.',
Host CHAR(64) CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The host name of the master.',
User_name TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The user name used to connect to the master.',
User_password TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The password used to connect to the master.',
Port INTEGER UNSIGNED NOT NULL COMMENT 'The network port used to connect to the master.',
Connect_retry INTEGER UNSIGNED NOT NULL COMMENT 'The period (in seconds) that the slave will wait before trying to reconnect to the master.',
Enabled_ssl BOOLEAN NOT NULL COMMENT 'Indicates whether the server supports SSL connections.',
Ssl_ca TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The file used for the Certificate Authority (CA) certificate.',
Ssl_capath TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The path to the Certificate Authority (CA) certificates.',
Ssl_cert TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The name of the SSL certificate file.',
Ssl_cipher TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The name of the cipher in use for the SSL connection.',
Ssl_key TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The name of the SSL key file.',
Ssl_verify_server_cert BOOLEAN NOT NULL COMMENT 'Whether to verify the server certificate.',
Heartbeat FLOAT NOT NULL COMMENT '',
Bind TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'Displays which interface is employed when connecting to the MySQL server',
Ignored_server_ids TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The number of server IDs to be ignored, followed by the actual server IDs',
Uuid TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The master server uuid.',
Retry_count BIGINT UNSIGNED NOT NULL COMMENT 'Number of reconnect attempts, to the master, before giving up.',
Ssl_crl TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The file used for the Certificate Revocation List (CRL)',
Ssl_crlpath TEXT CHARACTER SET utf8 COLLATE utf8_bin COMMENT 'The path used for Certificate Revocation List (CRL) files',
Enabled_auto_position BOOLEAN NOT NULL COMMENT 'Indicates whether GTIDs will be used to retrieve events from the master.',
PRIMARY KEY(Host, Port)) DEFAULT CHARSET=utf8 STATS_PERSISTENT=0 COMMENT 'Master Information'";
SET @str=IF(@have_innodb <> 0, CONCAT(@cmd, ' ENGINE= INNODB;'), CONCAT(@cmd, ' ENGINE= MYISAM;'));
-- Don't create the table; MariaDB will have another implementation
#PREPARE stmt FROM @str;
#EXECUTE stmt;
#DROP PREPARE stmt;
SET @cmd= "CREATE TABLE IF NOT EXISTS slave_worker_info (
Id INTEGER UNSIGNED NOT NULL,
Relay_log_name TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
Relay_log_pos BIGINT UNSIGNED NOT NULL,
Master_log_name TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
Master_log_pos BIGINT UNSIGNED NOT NULL,
Checkpoint_relay_log_name TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
Checkpoint_relay_log_pos BIGINT UNSIGNED NOT NULL,
Checkpoint_master_log_name TEXT CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
Checkpoint_master_log_pos BIGINT UNSIGNED NOT NULL,
Checkpoint_seqno INT UNSIGNED NOT NULL,
Checkpoint_group_size INTEGER UNSIGNED NOT NULL,
Checkpoint_group_bitmap BLOB NOT NULL,
PRIMARY KEY(Id)) DEFAULT CHARSET=utf8 STATS_PERSISTENT=0 COMMENT 'Worker Information'";
SET @str=IF(@have_innodb <> 0, CONCAT(@cmd, ' ENGINE= INNODB;'), CONCAT(@cmd, ' ENGINE= MYISAM;'));
-- Don't create the table; MariaDB will have another implementation
#PREPARE stmt FROM @str;
#EXECUTE stmt;
#DROP PREPARE stmt;
CREATE TABLE IF NOT EXISTS proxies_priv (Host char(60) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Proxied_host char(60) binary DEFAULT '' NOT NULL, Proxied_user char(16) binary DEFAULT '' NOT NULL, With_grant BOOL DEFAULT 0 NOT NULL, Grantor char(77) DEFAULT '' NOT NULL, Timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY Host (Host,User,Proxied_host,Proxied_user), KEY Grantor (Grantor) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='User proxy privileges';
-- Remember for later if proxies_priv table already existed
set @had_proxies_priv_table= @@warning_count != 0;
--
-- Tables unique for MariaDB
--
CREATE TABLE IF NOT EXISTS table_stats (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, cardinality bigint(21) unsigned DEFAULT NULL, PRIMARY KEY (db_name,table_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Tables';
CREATE TABLE IF NOT EXISTS column_stats (db_name varchar(64) NOT NULL, table_name varchar(64) NOT NULL, column_name varchar(64) NOT NULL, min_value varchar(255) DEFAULT NULL, max_value varchar(255) DEFAULT NULL, nulls_ratio decimal(12,4) DEFAULT NULL, avg_length decimal(12,4) DEFAULT NULL, avg_frequency decimal(12,4) DEFAULT NULL, PRIMARY KEY (db_name,table_name,column_name) ) ENGINE=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Statistics on Columns';
......
-- Copyright (C) 2003, 2011 Oracle and/or its affiliates.
-- Copyright (C) 2010, 2011 Monty Program Ab
-- Copyright (C) 2010-2013 Monty Program Ab & SkySQL Ab
--
-- 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
......@@ -21,6 +21,9 @@
# because these just mean that your tables are already up to date.
# This script is safe to run even if your tables are already up to date!
# Warning message(s) produced for a statement can be printed by explicitly
# adding a 'SHOW WARNINGS' after the statement.
set sql_mode='';
set storage_engine=MyISAM;
......@@ -234,18 +237,21 @@ ALTER TABLE func
SET @old_log_state = @@global.general_log;
SET GLOBAL general_log = 'OFF';
ALTER TABLE general_log
MODIFY event_time TIMESTAMP(6) NOT NULL,
MODIFY event_time TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
MODIFY user_host MEDIUMTEXT NOT NULL,
MODIFY thread_id INTEGER NOT NULL,
MODIFY server_id INTEGER UNSIGNED NOT NULL,
MODIFY command_type VARCHAR(64) NOT NULL,
MODIFY argument MEDIUMTEXT NOT NULL;
MODIFY argument MEDIUMTEXT NOT NULL,
MODIFY thread_id BIGINT(21) UNSIGNED NOT NULL;
SET GLOBAL general_log = @old_log_state;
SET @old_log_state = @@global.slow_query_log;
SET GLOBAL slow_query_log = 'OFF';
ALTER TABLE slow_log
MODIFY start_time TIMESTAMP(6) NOT NULL,
ADD COLUMN thread_id BIGINT(21) UNSIGNED NOT NULL AFTER sql_text;
ALTER TABLE slow_log
MODIFY start_time TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
MODIFY user_host MEDIUMTEXT NOT NULL,
MODIFY query_time TIME(6) NOT NULL,
MODIFY lock_time TIME(6) NOT NULL,
......@@ -255,7 +261,8 @@ ALTER TABLE slow_log
MODIFY last_insert_id INTEGER NOT NULL,
MODIFY insert_id INTEGER NOT NULL,
MODIFY server_id INTEGER UNSIGNED NOT NULL,
MODIFY sql_text MEDIUMTEXT NOT NULL;
MODIFY sql_text MEDIUMTEXT NOT NULL,
MODIFY thread_id BIGINT(21) UNSIGNED NOT NULL;
SET GLOBAL slow_query_log = @old_log_state;
ALTER TABLE plugin
......@@ -383,7 +390,7 @@ ALTER TABLE procs_priv
COLLATE utf8_general_ci NOT NULL AFTER Routine_name;
ALTER TABLE procs_priv
MODIFY Timestamp timestamp AFTER Proc_priv;
MODIFY Timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP AFTER Proc_priv;
#
# proc
......@@ -622,8 +629,8 @@ ALTER TABLE user MODIFY Create_tablespace_priv enum('N','Y') COLLATE utf8_genera
UPDATE user SET Create_tablespace_priv = Super_priv WHERE @hadCreateTablespacePriv = 0;
ALTER TABLE user ADD plugin char(64) DEFAULT '', ADD authentication_string TEXT;
ALTER TABLE user MODIFY plugin char(64) CHARACTER SET latin1 DEFAULT '' NOT NULL;
ALTER TABLE user MODIFY authentication_string TEXT NOT NULL;
ALTER TABLE user ADD password_expired ENUM('N', 'Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL;
ALTER TABLE user MODIFY plugin char(64) CHARACTER SET latin1 DEFAULT '' NOT NULL, user MODIFY authentication_string TEXT NOT NULL;
-- Need to pre-fill mysql.proxies_priv with access for root even when upgrading from
-- older versions
......
/* Copyright (c) 2007, 2011, Oracle and/or its affiliates.
/* Copyright (c) 2007, 2012, Oracle and/or its affiliates.
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
......@@ -14,9 +14,9 @@
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
#include "mdl.h"
#include "sql_class.h"
#include "debug_sync.h"
#include "sql_array.h"
#include <hash.h>
#include <mysqld_error.h>
#include <mysql/plugin.h>
......@@ -29,7 +29,7 @@ static PSI_mutex_key key_MDL_wait_LOCK_wait_status;
static PSI_mutex_info all_mdl_mutexes[]=
{
{ &key_MDL_map_mutex, "MDL_map::mutex", PSI_FLAG_GLOBAL},
{ &key_MDL_map_mutex, "MDL_map::mutex", 0},
{ &key_MDL_wait_LOCK_wait_status, "MDL_wait::LOCK_wait_status", 0}
};
......@@ -113,22 +113,26 @@ class MDL_object_lock_cache_adapter;
/**
A collection of all MDL locks. A singleton,
there is only one instance of the map in the server.
A partition in a collection of all MDL locks.
MDL_map is partitioned for scalability reasons.
Maps MDL_key to MDL_lock instances.
*/
class MDL_map
class MDL_map_partition
{
public:
void init();
void destroy();
MDL_lock *find_or_insert(const MDL_key *key);
void remove(MDL_lock *lock);
MDL_map_partition();
~MDL_map_partition();
inline MDL_lock *find_or_insert(const MDL_key *mdl_key,
my_hash_value_type hash_value);
inline void remove(MDL_lock *lock);
my_hash_value_type get_key_hash(const MDL_key *mdl_key) const
{
return my_calc_hash(&m_locks, mdl_key->ptr(), mdl_key->length());
}
private:
bool move_from_hash_to_lock_mutex(MDL_lock *lock);
private:
/** All acquired locks in the server. */
/** A partition of all acquired locks in the server. */
HASH m_locks;
/* Protects access to m_locks hash. */
mysql_mutex_t m_mutex;
......@@ -151,6 +155,30 @@ private:
I_P_List_counter>
Lock_cache;
Lock_cache m_unused_locks_cache;
};
/**
Start-up parameter for the number of partitions of the MDL_lock hash.
*/
ulong mdl_locks_hash_partitions;
/**
A collection of all MDL locks. A singleton,
there is only one instance of the map in the server.
Contains instances of MDL_map_partition
*/
class MDL_map
{
public:
void init();
void destroy();
MDL_lock *find_or_insert(const MDL_key *key);
void remove(MDL_lock *lock);
private:
/** Array of partitions where the locks are actually stored. */
Dynamic_array<MDL_map_partition *> m_partitions;
/** Pre-allocated MDL_lock object for GLOBAL namespace. */
MDL_lock *m_global_lock;
/** Pre-allocated MDL_lock object for COMMIT namespace. */
......@@ -398,7 +426,8 @@ public:
bool can_grant_lock(enum_mdl_type type, MDL_context *requstor_ctx,
bool ignore_lock_priority) const;
inline static MDL_lock *create(const MDL_key *key);
inline static MDL_lock *create(const MDL_key *key,
MDL_map_partition *map_part);
void reschedule_waiters();
......@@ -425,13 +454,14 @@ public:
public:
MDL_lock(const MDL_key *key_arg)
MDL_lock(const MDL_key *key_arg, MDL_map_partition *map_part)
: key(key_arg),
m_hog_lock_count(0),
m_ref_usage(0),
m_ref_release(0),
m_is_destroyed(FALSE),
m_version(0)
m_version(0),
m_map_part(map_part)
{
mysql_prlock_init(key_MDL_lock_rwlock, &m_rwlock);
}
......@@ -444,18 +474,18 @@ public:
public:
/**
These three members are used to make it possible to separate
the mdl_locks.m_mutex mutex and MDL_lock::m_rwlock in
the MDL_map_partition::m_mutex mutex and MDL_lock::m_rwlock in
MDL_map::find_or_insert() for increased scalability.
The 'm_is_destroyed' member is only set by destroyers that
have both the mdl_locks.m_mutex and MDL_lock::m_rwlock, thus
have both the MDL_map_partition::m_mutex and MDL_lock::m_rwlock, thus
holding any of the mutexes is sufficient to read it.
The 'm_ref_usage; is incremented under protection by
mdl_locks.m_mutex, but when 'm_is_destroyed' is set to TRUE, this
MDL_map_partition::m_mutex, but when 'm_is_destroyed' is set to TRUE, this
member is moved to be protected by the MDL_lock::m_rwlock.
This means that the MDL_map::find_or_insert() which only
holds the MDL_lock::m_rwlock can compare it to 'm_ref_release'
without acquiring mdl_locks.m_mutex again and if equal it can also
destroy the lock object safely.
without acquiring MDL_map_partition::m_mutex again and if equal
it can also destroy the lock object safely.
The 'm_ref_release' is incremented under protection by
MDL_lock::m_rwlock.
Note since we are only interested in equality of these two
......@@ -469,19 +499,23 @@ public:
/**
We use the same idea and an additional version counter to support
caching of unused MDL_lock object for further re-use.
This counter is incremented while holding both MDL_map::m_mutex and
MDL_lock::m_rwlock locks each time when a MDL_lock is moved from
the hash to the unused objects list (or destroyed).
This counter is incremented while holding both MDL_map_partition::m_mutex
and MDL_lock::m_rwlock locks each time when a MDL_lock is moved from
the partitioned hash to the paritioned unused objects list (or destroyed).
A thread, which has found a MDL_lock object for the key in the hash
and then released the MDL_map::m_mutex before acquiring the
and then released the MDL_map_partition::m_mutex before acquiring the
MDL_lock::m_rwlock, can determine that this object was moved to the
unused objects list (or destroyed) while it held no locks by comparing
the version value which it read while holding the MDL_map::m_mutex
the version value which it read while holding the MDL_map_partition::m_mutex
with the value read after acquiring the MDL_lock::m_rwlock.
Note that since it takes several years to overflow this counter such
theoretically possible overflows should not have any practical effects.
*/
ulonglong m_version;
/**
Partition of MDL_map where the lock is stored.
*/
MDL_map_partition *m_map_part;
};
......@@ -494,8 +528,8 @@ public:
class MDL_scoped_lock : public MDL_lock
{
public:
MDL_scoped_lock(const MDL_key *key_arg)
: MDL_lock(key_arg)
MDL_scoped_lock(const MDL_key *key_arg, MDL_map_partition *map_part)
: MDL_lock(key_arg, map_part)
{ }
virtual const bitmap_t *incompatible_granted_types_bitmap() const
......@@ -535,8 +569,8 @@ private:
class MDL_object_lock : public MDL_lock
{
public:
MDL_object_lock(const MDL_key *key_arg)
: MDL_lock(key_arg)
MDL_object_lock(const MDL_key *key_arg, MDL_map_partition *map_part)
: MDL_lock(key_arg, map_part)
{ }
/**
......@@ -569,7 +603,7 @@ public:
}
virtual bool needs_notification(const MDL_ticket *ticket) const
{
return ticket->is_upgradable_or_exclusive();
return (ticket->get_type() >= MDL_SHARED_NO_WRITE);
}
virtual void notify_conflicting_locks(MDL_context *ctx);
......@@ -666,33 +700,62 @@ void mdl_destroy()
}
/** Initialize the global hash containing all MDL locks. */
/** Initialize the container for all MDL locks. */
void MDL_map::init()
{
MDL_key global_lock_key(MDL_key::GLOBAL, "", "");
MDL_key commit_lock_key(MDL_key::COMMIT, "", "");
m_global_lock= MDL_lock::create(&global_lock_key, NULL);
m_commit_lock= MDL_lock::create(&commit_lock_key, NULL);
for (uint i= 0; i < mdl_locks_hash_partitions; i++)
{
MDL_map_partition *part= new (std::nothrow) MDL_map_partition();
m_partitions.append(part);
}
}
/** Initialize the partition in the container with all MDL locks. */
MDL_map_partition::MDL_map_partition()
{
mysql_mutex_init(key_MDL_map_mutex, &m_mutex, NULL);
my_hash_init(&m_locks, &my_charset_bin, 16 /* FIXME */, 0, 0,
mdl_locks_key, 0, 0);
m_global_lock= MDL_lock::create(&global_lock_key);
m_commit_lock= MDL_lock::create(&commit_lock_key);
}
};
/**
Destroy the global hash containing all MDL locks.
Destroy the container for all MDL locks.
@pre It must be empty.
*/
void MDL_map::destroy()
{
MDL_lock::destroy(m_global_lock);
MDL_lock::destroy(m_commit_lock);
while (m_partitions.elements() > 0)
{
MDL_map_partition *part= m_partitions.pop();
delete part;
}
}
/**
Destroy the partition in container for all MDL locks.
@pre It must be empty.
*/
MDL_map_partition::~MDL_map_partition()
{
DBUG_ASSERT(!m_locks.records);
mysql_mutex_destroy(&m_mutex);
my_hash_free(&m_locks);
MDL_lock::destroy(m_global_lock);
MDL_lock::destroy(m_commit_lock);
MDL_object_lock *lock;
while ((lock= m_unused_locks_cache.pop_front()))
......@@ -712,13 +775,12 @@ void MDL_map::destroy()
MDL_lock* MDL_map::find_or_insert(const MDL_key *mdl_key)
{
MDL_lock *lock;
my_hash_value_type hash_value;
if (mdl_key->mdl_namespace() == MDL_key::GLOBAL ||
mdl_key->mdl_namespace() == MDL_key::COMMIT)
{
/*
Avoid locking m_mutex when lock for GLOBAL or COMMIT namespace is
Avoid locking any m_mutex when lock for GLOBAL or COMMIT namespace is
requested. Return pointer to pre-allocated MDL_lock instance instead.
Such an optimization allows to save one mutex lock/unlock for any
statement changing data.
......@@ -736,8 +798,27 @@ MDL_lock* MDL_map::find_or_insert(const MDL_key *mdl_key)
return lock;
}
my_hash_value_type hash_value= m_partitions.at(0)->get_key_hash(mdl_key);
uint part_id= hash_value % mdl_locks_hash_partitions;
MDL_map_partition *part= m_partitions.at(part_id);
return part->find_or_insert(mdl_key, hash_value);
}
hash_value= my_calc_hash(&m_locks, mdl_key->ptr(), mdl_key->length());
/**
Find MDL_lock object corresponding to the key and hash value in
MDL_map partition, create it if it does not exist.
@retval non-NULL - Success. MDL_lock instance for the key with
locked MDL_lock::m_rwlock.
@retval NULL - Failure (OOM).
*/
MDL_lock* MDL_map_partition::find_or_insert(const MDL_key *mdl_key,
my_hash_value_type hash_value)
{
MDL_lock *lock;
retry:
mysql_mutex_lock(&m_mutex);
......@@ -770,7 +851,7 @@ retry:
}
else
{
lock= MDL_lock::create(mdl_key);
lock= MDL_lock::create(mdl_key, this);
}
if (!lock || my_hash_insert(&m_locks, (uchar*)lock))
......@@ -801,7 +882,7 @@ retry:
/**
Release mdl_locks.m_mutex mutex and lock MDL_lock::m_rwlock for lock
Release MDL_map_partition::m_mutex mutex and lock MDL_lock::m_rwlock for lock
object from the hash. Handle situation when object was released
while we held no locks.
......@@ -810,7 +891,7 @@ retry:
should re-try looking up MDL_lock object in the hash.
*/
bool MDL_map::move_from_hash_to_lock_mutex(MDL_lock *lock)
bool MDL_map_partition::move_from_hash_to_lock_mutex(MDL_lock *lock)
{
ulonglong version;
......@@ -819,8 +900,8 @@ bool MDL_map::move_from_hash_to_lock_mutex(MDL_lock *lock)
/*
We increment m_ref_usage which is a reference counter protected by
mdl_locks.m_mutex under the condition it is present in the hash and
m_is_destroyed is FALSE.
MDL_map_partition::m_mutex under the condition it is present in the hash
and m_is_destroyed is FALSE.
*/
lock->m_ref_usage++;
/* Read value of the version counter under protection of m_mutex lock. */
......@@ -892,28 +973,41 @@ void MDL_map::remove(MDL_lock *lock)
return;
}
lock->m_map_part->remove(lock);
}
/**
Destroy MDL_lock object belonging to specific MDL_map
partition or delegate this responsibility to whatever
thread that holds the last outstanding reference to it.
*/
void MDL_map_partition::remove(MDL_lock *lock)
{
mysql_mutex_lock(&m_mutex);
my_hash_delete(&m_locks, (uchar*) lock);
/*
To let threads holding references to the MDL_lock object know that it was
moved to the list of unused objects or destroyed, we increment the version
counter under protection of both MDL_map::m_mutex and MDL_lock::m_rwlock
locks. This allows us to read the version value while having either one
of those locks.
counter under protection of both MDL_map_partition::m_mutex and
MDL_lock::m_rwlock locks. This allows us to read the version value while
having either one of those locks.
*/
lock->m_version++;
if ((lock->key.mdl_namespace() != MDL_key::SCHEMA) &&
(m_unused_locks_cache.elements() < mdl_locks_cache_size))
(m_unused_locks_cache.elements() <
mdl_locks_cache_size/mdl_locks_hash_partitions))
{
/*
This is an object of MDL_object_lock type and the cache of unused
objects has not reached its maximum size yet. So instead of destroying
object we move it to the list of unused objects to allow its later
re-use with possibly different key. Any threads holding references to
this object (owning MDL_map::m_mutex or MDL_lock::m_rwlock) will notice
this thanks to the fact that we have changed the MDL_lock::m_version
counter.
this object (owning MDL_map_partition::m_mutex or MDL_lock::m_rwlock)
will notice this thanks to the fact that we have changed the
MDL_lock::m_version counter.
*/
DBUG_ASSERT(lock->key.mdl_namespace() != MDL_key::GLOBAL &&
lock->key.mdl_namespace() != MDL_key::COMMIT);
......@@ -930,8 +1024,8 @@ void MDL_map::remove(MDL_lock *lock)
has the responsibility to release it.
Setting of m_is_destroyed to TRUE while holding _both_
mdl_locks.m_mutex and MDL_lock::m_rwlock mutexes transfers the
protection of m_ref_usage from mdl_locks.m_mutex to
MDL_map_partition::m_mutex and MDL_lock::m_rwlock mutexes transfers
the protection of m_ref_usage from MDL_map_partition::m_mutex to
MDL_lock::m_rwlock while removal of the object from the hash
(and cache of unused objects) makes it read-only. Therefore
whoever acquires MDL_lock::m_rwlock next will see the most up
......@@ -961,7 +1055,8 @@ void MDL_map::remove(MDL_lock *lock)
*/
MDL_context::MDL_context()
: m_thd(NULL),
:
m_owner(NULL),
m_needs_thr_lock_abort(FALSE),
m_waiting_for(NULL)
{
......@@ -983,9 +1078,9 @@ MDL_context::MDL_context()
void MDL_context::destroy()
{
DBUG_ASSERT(m_tickets[MDL_STATEMENT].is_empty() &&
m_tickets[MDL_TRANSACTION].is_empty() &&
m_tickets[MDL_EXPLICIT].is_empty());
DBUG_ASSERT(m_tickets[MDL_STATEMENT].is_empty());
DBUG_ASSERT(m_tickets[MDL_TRANSACTION].is_empty());
DBUG_ASSERT(m_tickets[MDL_EXPLICIT].is_empty());
mysql_prlock_destroy(&m_LOCK_waiting_for);
}
......@@ -1050,16 +1145,17 @@ void MDL_request::init(const MDL_key *key_arg,
@note Also chooses an MDL_lock descendant appropriate for object namespace.
*/
inline MDL_lock *MDL_lock::create(const MDL_key *mdl_key)
inline MDL_lock *MDL_lock::create(const MDL_key *mdl_key,
MDL_map_partition *map_part)
{
switch (mdl_key->mdl_namespace())
{
case MDL_key::GLOBAL:
case MDL_key::SCHEMA:
case MDL_key::COMMIT:
return new MDL_scoped_lock(mdl_key);
return new (std::nothrow) MDL_scoped_lock(mdl_key, map_part);
default:
return new MDL_object_lock(mdl_key);
return new (std::nothrow) MDL_object_lock(mdl_key, map_part);
}
}
......@@ -1084,7 +1180,8 @@ MDL_ticket *MDL_ticket::create(MDL_context *ctx_arg, enum_mdl_type type_arg
#endif
)
{
return new MDL_ticket(ctx_arg, type_arg
return new (std::nothrow)
MDL_ticket(ctx_arg, type_arg
#ifndef DBUG_OFF
, duration_arg
#endif
......@@ -1177,6 +1274,7 @@ void MDL_wait::reset_status()
/**
Wait for the status to be assigned to this wait slot.
@param owner MDL context owner.
@param abs_timeout Absolute time after which waiting should stop.
@param set_status_on_timeout TRUE - If in case of timeout waiting
context should close the wait slot by
......@@ -1188,7 +1286,7 @@ void MDL_wait::reset_status()
*/
MDL_wait::enum_wait_status
MDL_wait::timed_wait(THD *thd, struct timespec *abs_timeout,
MDL_wait::timed_wait(MDL_context_owner *owner, struct timespec *abs_timeout,
bool set_status_on_timeout,
const PSI_stage_info *wait_state_name)
{
......@@ -1199,16 +1297,16 @@ MDL_wait::timed_wait(THD *thd, struct timespec *abs_timeout,
mysql_mutex_lock(&m_LOCK_wait_status);
THD_ENTER_COND(thd, &m_COND_wait_status, &m_LOCK_wait_status,
owner->ENTER_COND(&m_COND_wait_status, &m_LOCK_wait_status,
wait_state_name, & old_stage);
thd_wait_begin(thd, THD_WAIT_META_DATA_LOCK);
while (!m_wait_status && !thd->killed &&
thd_wait_begin(NULL, THD_WAIT_META_DATA_LOCK);
while (!m_wait_status && !owner->is_killed() &&
wait_result != ETIMEDOUT && wait_result != ETIME)
{
wait_result= mysql_cond_timedwait(&m_COND_wait_status, &m_LOCK_wait_status,
abs_timeout);
}
thd_wait_end(thd);
thd_wait_end(NULL);
if (m_wait_status == EMPTY)
{
......@@ -1224,14 +1322,14 @@ MDL_wait::timed_wait(THD *thd, struct timespec *abs_timeout,
false, which means that the caller intends to restart the
wait.
*/
if (thd->killed)
if (owner->is_killed())
m_wait_status= KILLED;
else if (set_status_on_timeout)
m_wait_status= TIMEOUT;
}
result= m_wait_status;
thd->EXIT_COND(& old_stage);
owner->EXIT_COND(& old_stage);
DBUG_RETURN(result);
}
......@@ -1445,7 +1543,7 @@ void MDL_lock::reschedule_waiters()
| Type of active |
Request | scoped lock |
type | IS(**) IX S X |
type | IS(*) IX S X |
---------+------------------+
IS | + + + + |
IX | + + - - |
......@@ -1458,7 +1556,7 @@ void MDL_lock::reschedule_waiters()
| Pending |
Request | scoped lock |
type | IS(**) IX S X |
type | IS(*) IX S X |
---------+-----------------+
IS | + + + + |
IX | + + - - |
......@@ -2010,8 +2108,8 @@ void MDL_object_lock::notify_conflicting_locks(MDL_context *ctx)
lock or some other non-MDL resource we might need to wake it up
by calling code outside of MDL.
*/
mysql_notify_thread_having_shared_lock(ctx->get_thd(),
conflicting_ctx->get_thd(),
ctx->get_owner()->
notify_shared_lock(conflicting_ctx->get_owner(),
conflicting_ctx->get_needs_thr_lock_abort());
}
}
......@@ -2042,8 +2140,8 @@ void MDL_scoped_lock::notify_conflicting_locks(MDL_context *ctx)
insert delayed. We need to kill such threads in order to get
global shared lock. We do this my calling code outside of MDL.
*/
mysql_notify_thread_having_shared_lock(ctx->get_thd(),
conflicting_ctx->get_thd(),
ctx->get_owner()->
notify_shared_lock(conflicting_ctx->get_owner(),
conflicting_ctx->get_needs_thr_lock_abort());
}
}
......@@ -2117,7 +2215,7 @@ MDL_context::acquire_lock(MDL_request *mdl_request, ulong lock_wait_timeout)
will_wait_for(ticket);
/* There is a shared or exclusive lock on the object. */
DEBUG_SYNC(m_thd, "mdl_acquire_lock_wait");
DEBUG_SYNC(get_thd(), "mdl_acquire_lock_wait");
find_deadlock();
......@@ -2130,7 +2228,7 @@ MDL_context::acquire_lock(MDL_request *mdl_request, ulong lock_wait_timeout)
while (cmp_timespec(abs_shortwait, abs_timeout) <= 0)
{
/* abs_timeout is far away. Wait a short while and notify locks. */
wait_status= m_wait.timed_wait(m_thd, &abs_shortwait, FALSE,
wait_status= m_wait.timed_wait(m_owner, &abs_shortwait, FALSE,
mdl_request->key.get_wait_state_name());
if (wait_status != MDL_wait::EMPTY)
......@@ -2142,11 +2240,11 @@ MDL_context::acquire_lock(MDL_request *mdl_request, ulong lock_wait_timeout)
set_timespec(abs_shortwait, 1);
}
if (wait_status == MDL_wait::EMPTY)
wait_status= m_wait.timed_wait(m_thd, &abs_timeout, TRUE,
wait_status= m_wait.timed_wait(m_owner, &abs_timeout, TRUE,
mdl_request->key.get_wait_state_name());
}
else
wait_status= m_wait.timed_wait(m_thd, &abs_timeout, TRUE,
wait_status= m_wait.timed_wait(m_owner, &abs_timeout, TRUE,
mdl_request->key.get_wait_state_name());
done_waiting_for();
......@@ -2231,8 +2329,7 @@ bool MDL_context::acquire_locks(MDL_request_list *mdl_requests,
/* Sort requests according to MDL_key. */
if (! (sort_buf= (MDL_request **)my_malloc(req_count *
sizeof(MDL_request*),
MYF(MY_WME |
MY_THREAD_SPECIFIC))))
MYF(MY_WME))))
DBUG_RETURN(TRUE);
for (p_req= sort_buf; p_req < sort_buf + req_count; p_req++)
......
#ifndef MDL_H
#define MDL_H
/* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
/* Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
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
......@@ -12,8 +12,8 @@
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 St, Fifth Floor, Boston, MA 02110-1301 USA */
along with this program; if not, write to the Free Software Foundation,
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
#if defined(__IBMC__) || defined(__IBMCPP__)
/* Further down, "next_in_lock" and "next_in_context" have the same type,
......@@ -26,10 +26,11 @@
#include "sql_plist.h"
#include <my_sys.h>
#include <my_pthread.h>
#include <m_string.h>
#include <mysql_com.h>
#include <algorithm>
class THD;
class MDL_context;
......@@ -54,6 +55,67 @@ class MDL_ticket;
*/
#define EXIT_COND(S) exit_cond(S, __func__, __FILE__, __LINE__)
/**
An interface to separate the MDL module from the THD, and the rest of the
server code.
*/
class MDL_context_owner
{
public:
virtual ~MDL_context_owner() {}
/**
Enter a condition wait.
For @c enter_cond() / @c exit_cond() to work the mutex must be held before
@c enter_cond(); this mutex is then released by @c exit_cond().
Usage must be: lock mutex; enter_cond(); your code; exit_cond().
@param cond the condition to wait on
@param mutex the associated mutex
@param [in] stage the stage to enter, or NULL
@param [out] old_stage the previous stage, or NULL
@param src_function function name of the caller
@param src_file file name of the caller
@param src_line line number of the caller
@sa ENTER_COND(), THD::enter_cond()
@sa EXIT_COND(), THD::exit_cond()
*/
virtual void enter_cond(mysql_cond_t *cond, mysql_mutex_t *mutex,
const PSI_stage_info *stage, PSI_stage_info *old_stage,
const char *src_function, const char *src_file,
int src_line) = 0;
/**
@def EXIT_COND(S)
End a wait on a condition
@param [in] stage the new stage to enter
@param src_function function name of the caller
@param src_file file name of the caller
@param src_line line number of the caller
@sa ENTER_COND(), THD::enter_cond()
@sa EXIT_COND(), THD::exit_cond()
*/
virtual void exit_cond(const PSI_stage_info *stage,
const char *src_function, const char *src_file,
int src_line) = 0;
/**
Has the owner thread been killed?
*/
virtual int is_killed() = 0;
/**
This one is only used for DEBUG_SYNC.
(Do not use it to peek/poke into other parts of THD.)
*/
virtual THD* get_thd() = 0;
/**
@see THD::notify_shared_lock()
*/
virtual bool notify_shared_lock(MDL_context_owner *in_use,
bool needs_thr_lock_abort) = 0;
};
/**
Type of metadata lock request.
......@@ -273,8 +335,16 @@ public:
const char *db, const char *name)
{
m_ptr[0]= (char) mdl_namespace;
m_db_name_length= (uint16) (strmov(m_ptr + 1, db) - m_ptr - 1);
m_length= (uint16) (strmov(m_ptr + m_db_name_length + 2, name) - m_ptr + 1);
/*
It is responsibility of caller to ensure that db and object names
are not longer than NAME_LEN. Still we play safe and try to avoid
buffer overruns.
*/
DBUG_ASSERT(strlen(db) <= NAME_LEN && strlen(name) <= NAME_LEN);
m_db_name_length= static_cast<uint16>(strmake(m_ptr + 1, db, NAME_LEN) -
m_ptr - 1);
m_length= static_cast<uint16>(strmake(m_ptr + m_db_name_length + 2, name,
NAME_LEN) - m_ptr + 1);
}
void mdl_key_init(const MDL_key *rhs)
{
......@@ -297,7 +367,8 @@ public:
character set is utf-8, we can safely assume that no
character starts with a zero byte.
*/
return memcmp(m_ptr, rhs->m_ptr, MY_MIN(m_length, rhs->m_length));
using std::min;
return memcmp(m_ptr, rhs->m_ptr, min(m_length, rhs->m_length));
}
MDL_key(const MDL_key *rhs)
......@@ -624,7 +695,7 @@ public:
bool set_status(enum_wait_status result_arg);
enum_wait_status get_status();
void reset_status();
enum_wait_status timed_wait(THD *thd,
enum_wait_status timed_wait(MDL_context_owner *owner,
struct timespec *abs_timeout,
bool signal_timeout,
const PSI_stage_info *wait_state_name);
......@@ -706,7 +777,7 @@ public:
void release_transactional_locks();
void rollback_to_savepoint(const MDL_savepoint &mdl_savepoint);
inline THD *get_thd() const { return m_thd; }
MDL_context_owner *get_owner() { return m_owner; }
/** @pre Only valid if we started waiting for lock. */
inline uint get_deadlock_weight() const
......@@ -719,7 +790,7 @@ public:
already has received some signal or closed
signal slot.
*/
void init(THD *thd_arg) { m_thd= thd_arg; }
void init(MDL_context_owner *arg) { m_owner= arg; }
void set_needs_thr_lock_abort(bool needs_thr_lock_abort)
{
......@@ -799,7 +870,7 @@ private:
involved schemas and global intention exclusive lock.
*/
Ticket_list m_tickets[MDL_DURATION_END];
THD *m_thd;
MDL_context_owner *m_owner;
/**
TRUE - if for this context we will break protocol and try to
acquire table-level locks while having only S lock on
......@@ -828,6 +899,7 @@ private:
*/
MDL_wait_for_subgraph *m_waiting_for;
private:
THD *get_thd() const { return m_owner->get_thd(); }
MDL_ticket *find_ticket(MDL_request *mdl_req,
enum_mdl_duration *duration);
void release_locks_stored_before(enum_mdl_duration duration, MDL_ticket *sentinel);
......@@ -872,8 +944,6 @@ private:
void mdl_init();
void mdl_destroy();
extern bool mysql_notify_thread_having_shared_lock(THD *thd, THD *in_use,
bool needs_thr_lock_abort);
#ifndef DBUG_OFF
extern mysql_mutex_t LOCK_open;
......@@ -887,6 +957,14 @@ extern mysql_mutex_t LOCK_open;
extern ulong mdl_locks_cache_size;
static const ulong MDL_LOCKS_CACHE_SIZE_DEFAULT = 1024;
/*
Start-up parameter for the number of partitions of the hash
containing all the MDL_lock objects and a constant for
its default value.
*/
extern ulong mdl_locks_hash_partitions;
static const ulong MDL_LOCKS_HASH_PARTITIONS_DEFAULT = 8;
/*
Metadata locking subsystem tries not to grant more than
max_write_lock_count high-prio, strong locks successively,
......
......@@ -124,6 +124,17 @@ public:
return (insert_dynamic(&array, (uchar*)&el));
}
/// Pops the last element. Does nothing if array is empty.
Elem& pop()
{
return *((Elem*)pop_dynamic(&array));
}
void del(uint idx)
{
delete_dynamic_element(&array, idx);
}
int elements()
{
return array.elements;
......
......@@ -4860,55 +4860,20 @@ lock_table_names(THD *thd,
continue;
}
/*
Write lock on normal tables is not allowed in a read only transaction.
*/
/* Write lock on normal tables is not allowed in a read only transaction. */
if (thd->tx_read_only)
{
my_error(ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION, MYF(0));
DBUG_RETURN(true);
}
if (! (flags & MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK) && schema_set.insert(table))
if (! (flags & MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK) &&
schema_set.insert(table))
DBUG_RETURN(TRUE);
mdl_requests.push_front(&table->mdl_request);
}
if (! (flags & MYSQL_OPEN_SKIP_SCOPED_MDL_LOCK) &&
! mdl_requests.is_empty())
{
/*
Scoped locks: Take intention exclusive locks on all involved
schemas.
*/
Hash_set<TABLE_LIST, schema_set_get_key>::Iterator it(schema_set);
while ((table= it++))
{
MDL_request *schema_request= new (thd->mem_root) MDL_request;
if (schema_request == NULL)
return TRUE;
schema_request->init(MDL_key::SCHEMA, table->db, "",
MDL_INTENTION_EXCLUSIVE,
MDL_TRANSACTION);
mdl_requests.push_front(schema_request);
}
/*
Protect this statement against concurrent global read lock
by acquiring global intention exclusive lock with statement
duration.
*/
if (thd->global_read_lock.can_acquire_protection())
return TRUE;
global_request.init(MDL_key::GLOBAL, "", "", MDL_INTENTION_EXCLUSIVE,
MDL_STATEMENT);
mdl_requests.push_front(&global_request);
}
if (thd->mdl_context.acquire_locks(&mdl_requests, lock_wait_timeout))
return TRUE;
if (mdl_requests.is_empty())
DBUG_RETURN(FALSE);
......
......@@ -62,6 +62,7 @@
#include "debug_sync.h"
#include "sql_parse.h" // is_update_query
#include "sql_callback.h"
#include "lock.h"
#include "sql_connect.h"
/*
......@@ -1788,6 +1789,46 @@ void THD::disconnect()
}
bool THD::notify_shared_lock(MDL_context_owner *ctx_in_use,
bool needs_thr_lock_abort)
{
THD *in_use= ctx_in_use->get_thd();
bool signalled= FALSE;
if ((in_use->system_thread & SYSTEM_THREAD_DELAYED_INSERT) &&
!in_use->killed)
{
in_use->killed= KILL_CONNECTION;
mysql_mutex_lock(&in_use->mysys_var->mutex);
if (in_use->mysys_var->current_cond)
mysql_cond_broadcast(in_use->mysys_var->current_cond);
mysql_mutex_unlock(&in_use->mysys_var->mutex);
signalled= TRUE;
}
if (needs_thr_lock_abort)
{
mysql_mutex_lock(&in_use->LOCK_thd_data);
for (TABLE *thd_table= in_use->open_tables;
thd_table ;
thd_table= thd_table->next)
{
/*
Check for TABLE::needs_reopen() is needed since in some places we call
handler::close() for table instance (and set TABLE::db_stat to 0)
and do not remove such instances from the THD::open_tables
for some time, during which other thread can see those instances
(e.g. see partitioning code).
*/
if (!thd_table->needs_reopen())
signalled|= mysql_lock_abort_for_thread(this, thd_table);
}
mysql_mutex_unlock(&in_use->LOCK_thd_data);
}
return signalled;
}
/*
Get error number for killed state
Note that the error message can't have any parameters.
......
......@@ -1571,6 +1571,7 @@ void dbug_serve_apcs(THD *thd, int n_calls);
*/
class THD :public Statement,
public MDL_context_owner,
public Open_tables_state
{
private:
......@@ -2583,6 +2584,37 @@ public:
mysql_mutex_unlock(&mysys_var->mutex);
return;
}
virtual int is_killed() { return killed; }
virtual THD* get_thd() { return this; }
/**
A callback to the server internals that is used to address
special cases of the locking protocol.
Invoked when acquiring an exclusive lock, for each thread that
has a conflicting shared metadata lock.
This function:
- aborts waiting of the thread on a data lock, to make it notice
the pending exclusive lock and back off.
- if the thread is an INSERT DELAYED thread, sends it a KILL
signal to terminate it.
@note This function does not wait for the thread to give away its
locks. Waiting is done outside for all threads at once.
@param ctx_in_use The MDL context owner (thread) to wake up.
@param needs_thr_lock_abort Indicates that to wake up thread
this call needs to abort its waiting
on table-level lock.
@retval TRUE if the thread was woken up
@retval FALSE otherwise.
*/
virtual bool notify_shared_lock(MDL_context_owner *ctx_in_use,
bool needs_thr_lock_abort);
// End implementation of MDL_context_owner interface.
inline bool is_strict_mode() const
{
return variables.sql_mode & (MODE_STRICT_TRANS_TABLES |
......
......@@ -3520,7 +3520,6 @@ Prepared_statement::execute_loop(String *expanded_query,
Reprepare_observer reprepare_observer;
bool error;
int reprepare_attempt= 0;
bool need_set_parameters= true;
/* Check if we got an error when sending long data */
if (state == Query_arena::STMT_ERROR)
......@@ -3529,20 +3528,19 @@ Prepared_statement::execute_loop(String *expanded_query,
return TRUE;
}
reexecute:
if (need_set_parameters &&
set_parameters(expanded_query, packet, packet_end))
if (set_parameters(expanded_query, packet, packet_end))
return TRUE;
/*
if set_parameters() has generated warnings,
we need to repeat it when reexecuting, to recreate these
warnings.
*/
need_set_parameters= thd->get_stmt_da()->statement_warn_count();
reprepare_observer.reset_reprepare_observer();
#ifdef NOT_YET_FROM_MYSQL_5_6
if (unlikely(thd->security_ctx->password_expired &&
!lex->is_change_password))
{
my_error(ER_MUST_CHANGE_PASSWORD, MYF(0));
return true;
}
#endif
reexecute:
/*
If the free_list is not empty, we'll wrongly free some externally
allocated items when cleaning up after validation of the prepared
......@@ -3556,18 +3554,20 @@ reexecute:
the observer method will be invoked to push an error into
the error stack.
*/
if (sql_command_flags[lex->sql_command] &
CF_REEXECUTION_FRAGILE)
if (sql_command_flags[lex->sql_command] & CF_REEXECUTION_FRAGILE)
{
reprepare_observer.reset_reprepare_observer();
DBUG_ASSERT(thd->m_reprepare_observer == NULL);
thd->m_reprepare_observer = &reprepare_observer;
thd->m_reprepare_observer= &reprepare_observer;
}
error= execute(expanded_query, open_cursor) || thd->is_error();
thd->m_reprepare_observer= NULL;
if (error && !thd->is_fatal_error && !thd->killed &&
if ((sql_command_flags[lex->sql_command] & CF_REEXECUTION_FRAGILE) &&
error && !thd->is_fatal_error && !thd->killed &&
reprepare_observer.is_invalidated() &&
reprepare_attempt++ < MAX_REPREPARE_ATTEMPTS)
{
......
......@@ -1331,6 +1331,12 @@ static Sys_var_ulong Sys_metadata_locks_cache_size(
VALID_RANGE(1, 1024*1024), DEFAULT(MDL_LOCKS_CACHE_SIZE_DEFAULT),
BLOCK_SIZE(1));
static Sys_var_ulong Sys_metadata_locks_hash_instances(
"metadata_locks_hash_instances", "Number of metadata locks hash instances",
READ_ONLY GLOBAL_VAR(mdl_locks_hash_partitions), CMD_LINE(REQUIRED_ARG),
VALID_RANGE(1, 1024), DEFAULT(MDL_LOCKS_HASH_PARTITIONS_DEFAULT),
BLOCK_SIZE(1));
/*
"pseudo_thread_id" variable used in the test suite to detect 32/64bit
systems. If you change it to something else then ulong then fix the tests
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment