From 92bfebb66eaddacd5d2dfa6cf749d721a921ff4c Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Fri, 20 Nov 2009 00:13:54 +0100 Subject: Bug#32115: Bad use of Name_resolution_context from current LEX in partitioning port from mysql-next (5.4) to mysql-next-mr-bugfixing (5.5/5.6?) 2755 Konstantin Osipov 2008-11-27 Bug#32115 will remove the pre-requisite to initialize LEX to open tables. This dependency was added in 5.1 and was supposed to be removed in 6.0. Remove asserts and initialization of LEX in places where we don't deal with partitioned tables. --- sql/table.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'sql/table.cc') diff --git a/sql/table.cc b/sql/table.cc index 22b4b2f9b5e..600bd8bb33d 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1649,9 +1649,6 @@ int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias, DBUG_PRINT("enter",("name: '%s.%s' form: 0x%lx", share->db.str, share->table_name.str, (long) outparam)); - /* Parsing of partitioning information from .frm needs thd->lex set up. */ - DBUG_ASSERT(thd->lex->is_lex_started); - error= 1; bzero((char*) outparam, sizeof(*outparam)); outparam->in_use= thd; @@ -1833,6 +1830,8 @@ int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias, thd->restore_active_arena(&part_func_arena, &backup_arena); goto partititon_err; } + /* fix_partition_func needs thd->lex set up. TODO: fix! */ + DBUG_ASSERT(thd->lex->is_lex_started); outparam->part_info->is_auto_partitioned= share->auto_partitioned; DBUG_PRINT("info", ("autopartitioned: %u", share->auto_partitioned)); /* we should perform the fix_partition_func in either local or -- cgit v1.2.1 From 4205c622e1a741bae1b2d8d213342f8e0bdd936a Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Fri, 20 Nov 2009 01:20:08 +0100 Subject: Bug#32115: Bad use of Name_resolution_context from current LEX in partitioning port from mysql-next (5.4?) to mysql-next-mr-bugfixes (5.5/5.6?) 3477 Mikael Ronstrom 2009-07-29 Bug#32115, made use of local lex object to avoid side effects of opening partitioned tables 3478 Mikael Ronstrom 2009-07-29 Bug#32115, added an extra test in debug builds to ensure no dangling pointers to the old lex object is still around 3479 Mikael Ronstrom 2009-07-29 Bug#32115, Removed an assert that was no longer needed 3480 Mikael Ronstrom 2009-08-05 Bug#32115, fixed review comments 3481 Mikael Ronstrom 2009-08-07 Bug#32115, remove now obsolete lex_start calls --- sql/table.cc | 2 -- 1 file changed, 2 deletions(-) (limited to 'sql/table.cc') diff --git a/sql/table.cc b/sql/table.cc index 600bd8bb33d..39a7e163c37 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1830,8 +1830,6 @@ int open_table_from_share(THD *thd, TABLE_SHARE *share, const char *alias, thd->restore_active_arena(&part_func_arena, &backup_arena); goto partititon_err; } - /* fix_partition_func needs thd->lex set up. TODO: fix! */ - DBUG_ASSERT(thd->lex->is_lex_started); outparam->part_info->is_auto_partitioned= share->auto_partitioned; DBUG_PRINT("info", ("autopartitioned: %u", share->auto_partitioned)); /* we should perform the fix_partition_func in either local or -- cgit v1.2.1 From 4cff617c2541279a53b92acbd4e4d8716dc54873 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Tue, 24 Nov 2009 16:54:59 +0300 Subject: Backport of: ---------------------------------------------------------------------- ChangeSet@1.2571, 2008-04-08 12:30:06+02:00, vvaintroub@wva. +122 -0 Bug#32082 : definition of VOID in my_global.h conflicts with Windows SDK headers VOID macro is now removed. Its usage is replaced with void cast. In some cases, where cast does not make much sense (pthread_*, printf, hash_delete, my_seek), cast is ommited. --- sql/table.cc | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'sql/table.cc') diff --git a/sql/table.cc b/sql/table.cc index 22b4b2f9b5e..7ea04ed3e15 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -753,7 +753,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, /* Read keyinformation */ key_info_length= (uint) uint2korr(head+28); - VOID(my_seek(file,(ulong) uint2korr(head+6),MY_SEEK_SET,MYF(0))); + my_seek(file,(ulong) uint2korr(head+6),MY_SEEK_SET,MYF(0)); if (read_string(file,(uchar**) &disk_buff,key_info_length)) goto err; /* purecov: inspected */ if (disk_buff[0] & 0x80) @@ -1030,7 +1030,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, record_offset, MYF(MY_NABP))) goto err; /* purecov: inspected */ - VOID(my_seek(file,pos,MY_SEEK_SET,MYF(0))); + my_seek(file,pos,MY_SEEK_SET,MYF(0)); if (my_read(file, head,288,MYF(MY_NABP))) goto err; #ifdef HAVE_CRYPTED_FRM @@ -2059,7 +2059,7 @@ ulong get_form_pos(File file, uchar *head, TYPELIB *save_names) if (names) { length=uint2korr(head+4); - VOID(my_seek(file,64L,MY_SEEK_SET,MYF(0))); + my_seek(file,64L,MY_SEEK_SET,MYF(0)); if (!(buf= (uchar*) my_malloc((size_t) length+a_length+names*4, MYF(MY_WME))) || my_read(file, buf+a_length, (size_t) (length+names*4), @@ -2138,17 +2138,17 @@ ulong make_new_entry(File file, uchar *fileinfo, TYPELIB *formnames, while (endpos > maxlength) { - VOID(my_seek(file,(ulong) (endpos-bufflength),MY_SEEK_SET,MYF(0))); + my_seek(file,(ulong) (endpos-bufflength),MY_SEEK_SET,MYF(0)); if (my_read(file, buff, bufflength, MYF(MY_NABP+MY_WME))) DBUG_RETURN(0L); - VOID(my_seek(file,(ulong) (endpos-bufflength+IO_SIZE),MY_SEEK_SET, - MYF(0))); + my_seek(file,(ulong) (endpos-bufflength+IO_SIZE),MY_SEEK_SET, + MYF(0)); if ((my_write(file, buff,bufflength,MYF(MY_NABP+MY_WME)))) DBUG_RETURN(0); endpos-=bufflength; bufflength=IO_SIZE; } bzero(buff,IO_SIZE); /* Null new block */ - VOID(my_seek(file,(ulong) maxlength,MY_SEEK_SET,MYF(0))); + my_seek(file,(ulong) maxlength,MY_SEEK_SET,MYF(0)); if (my_write(file,buff,bufflength,MYF(MY_NABP+MY_WME))) DBUG_RETURN(0L); maxlength+=IO_SIZE; /* Fix old ref */ @@ -2164,11 +2164,11 @@ ulong make_new_entry(File file, uchar *fileinfo, TYPELIB *formnames, if (n_length == 1 ) { /* First name */ length++; - VOID(strxmov((char*) buff,"/",newname,"/",NullS)); + (void) strxmov((char*) buff,"/",newname,"/",NullS); } else - VOID(strxmov((char*) buff,newname,"/",NullS)); /* purecov: inspected */ - VOID(my_seek(file,63L+(ulong) n_length,MY_SEEK_SET,MYF(0))); + (void) strxmov((char*) buff,newname,"/",NullS); /* purecov: inspected */ + my_seek(file,63L+(ulong) n_length,MY_SEEK_SET,MYF(0)); if (my_write(file, buff, (size_t) length+1,MYF(MY_NABP+MY_WME)) || (names && my_write(file,(uchar*) (*formnames->type_names+n_length-1), names*4, MYF(MY_NABP+MY_WME))) || @@ -2177,7 +2177,7 @@ ulong make_new_entry(File file, uchar *fileinfo, TYPELIB *formnames, int2store(fileinfo+8,names+1); int2store(fileinfo+4,n_length+length); - VOID(my_chsize(file, newpos, 0, MYF(MY_WME)));/* Append file with '\0' */ + (void) my_chsize(file, newpos, 0, MYF(MY_WME));/* Append file with '\0' */ DBUG_RETURN(newpos); } /* make_new_entry */ @@ -2531,8 +2531,8 @@ File create_frm(THD *thd, const char *name, const char *db, { if (my_write(file,fill, IO_SIZE, MYF(MY_WME | MY_NABP))) { - VOID(my_close(file,MYF(0))); - VOID(my_delete(name,MYF(0))); + (void) my_close(file,MYF(0)); + (void) my_delete(name,MYF(0)); return(-1); } } @@ -2569,8 +2569,8 @@ int rename_file_ext(const char * from,const char * to,const char * ext) { char from_b[FN_REFLEN],to_b[FN_REFLEN]; - VOID(strxmov(from_b,from,ext,NullS)); - VOID(strxmov(to_b,to,ext,NullS)); + (void) strxmov(from_b,from,ext,NullS); + (void) strxmov(to_b,to,ext,NullS); return (my_rename(from_b,to_b,MYF(MY_WME))); } -- cgit v1.2.1 From 69b9761f2913dfa9fa2989ef7f3e01b8d2d3e334 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Mon, 30 Nov 2009 18:55:03 +0300 Subject: Initial import of WL#3726 "DDL locking for all metadata objects". Backport of: ------------------------------------------------------------ revno: 2630.4.1 committer: Dmitry Lenev branch nick: mysql-6.0-3726-w timestamp: Fri 2008-05-23 17:54:03 +0400 message: WL#3726 "DDL locking for all metadata objects". After review fixes in progress. ------------------------------------------------------------ This is the first patch in series. It transforms the metadata locking subsystem to use a dedicated module (mdl.h,cc). No significant changes in the locking protocol. The import passes the test suite with the exception of deprecated/removed 6.0 features, and MERGE tables. The latter are subject to a fix by WL#4144. Unfortunately, the original changeset comments got lost in a merge, thus this import has its own (largely insufficient) comments. This patch fixes Bug#25144 "replication / binlog with view breaks". Warning: this patch introduces an incompatible change: Under LOCK TABLES, it's no longer possible to FLUSH a table that was not locked for WRITE. Under LOCK TABLES, it's no longer possible to DROP a table or VIEW that was not locked for WRITE. ****** Backport of: ------------------------------------------------------------ revno: 2630.4.2 committer: Dmitry Lenev branch nick: mysql-6.0-3726-w timestamp: Sat 2008-05-24 14:03:45 +0400 message: WL#3726 "DDL locking for all metadata objects". After review fixes in progress. ****** Backport of: ------------------------------------------------------------ revno: 2630.4.3 committer: Dmitry Lenev branch nick: mysql-6.0-3726-w timestamp: Sat 2008-05-24 14:08:51 +0400 message: WL#3726 "DDL locking for all metadata objects" Fixed failing Windows builds by adding mdl.cc to the lists of files needed to build server/libmysqld on Windows. ****** Backport of: ------------------------------------------------------------ revno: 2630.4.4 committer: Dmitry Lenev branch nick: mysql-6.0-3726-w timestamp: Sat 2008-05-24 21:57:58 +0400 message: WL#3726 "DDL locking for all metadata objects". Fix for assert failures in kill.test which occured when one tried to kill ALTER TABLE statement on merge table while it was waiting in wait_while_table_is_used() for other connections to close this table. These assert failures stemmed from the fact that cleanup code in this case assumed that temporary table representing new version of table was open with adding to THD::temporary_tables list while code which were opening this temporary table wasn't always fulfilling this. This patch changes code that opens new version of table to always do this linking in. It also streamlines cleanup process for cases when error occurs while we have new version of table open. ****** WL#3726 "DDL locking for all metadata objects" Add libmysqld/mdl.cc to .bzrignore. ****** Backport of: ------------------------------------------------------------ revno: 2630.4.6 committer: Dmitry Lenev branch nick: mysql-6.0-3726-w timestamp: Sun 2008-05-25 00:33:22 +0400 message: WL#3726 "DDL locking for all metadata objects". Addition to the fix of assert failures in kill.test caused by changes for this worklog. Make sure we close the new table only once. --- sql/table.cc | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'sql/table.cc') diff --git a/sql/table.cc b/sql/table.cc index 7ea04ed3e15..181014df9f4 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -316,6 +316,9 @@ TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key, share->table_map_id= ~0UL; share->cached_row_logging_check= -1; + share->used_tables.empty(); + share->free_tables.empty(); + memcpy((char*) &share->mem_root, (char*) &mem_root, sizeof(mem_root)); pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST); pthread_cond_init(&share->cond, NULL); @@ -382,6 +385,9 @@ void init_tmp_table_share(THD *thd, TABLE_SHARE *share, const char *key, */ share->table_map_id= (ulong) thd->query_id; + share->used_tables.empty(); + share->free_tables.empty(); + DBUG_VOID_RETURN; } @@ -4832,6 +4838,20 @@ size_t max_row_length(TABLE *table, const uchar *data) return length; } + +/** + Helper function which allows to allocate metadata lock request + objects for all elements of table list. +*/ + +void alloc_mdl_locks(TABLE_LIST *table_list, MEM_ROOT *root) +{ + for ( ; table_list ; table_list= table_list->next_global) + table_list->mdl_lock= mdl_alloc_lock(0, table_list->db, + table_list->table_name, root); +} + + /***************************************************************************** ** Instansiate templates *****************************************************************************/ -- cgit v1.2.1 From b6c33a9a63a13d37822c0439bafb0daf9b2f3b5a Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Mon, 30 Nov 2009 22:11:32 +0300 Subject: Backport of: ------------------------------------------------------------ revno: 2630.6.1 committer: Konstantin Osipov branch nick: mysql-6.0-3726 timestamp: Tue 2008-05-27 13:45:34 +0400 message: Remove an unused argument from release_table_share(). Remove unused members from TABLE_SHARE struct. Review comments in scope of WL#3726 "DDL locking for all metadata objects" --- sql/table.cc | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'sql/table.cc') diff --git a/sql/table.cc b/sql/table.cc index 181014df9f4..b232ba23a89 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -321,7 +321,6 @@ TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key, memcpy((char*) &share->mem_root, (char*) &mem_root, sizeof(mem_root)); pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST); - pthread_cond_init(&share->cond, NULL); } DBUG_RETURN(share); } @@ -418,16 +417,9 @@ void free_table_share(TABLE_SHARE *share) */ if (share->tmp_table == NO_TMP_TABLE) { - /* share->mutex is locked in release_table_share() */ - while (share->waiting_on_cond) - { - pthread_cond_broadcast(&share->cond); - pthread_cond_wait(&share->cond, &share->mutex); - } /* No thread refers to this anymore */ pthread_mutex_unlock(&share->mutex); pthread_mutex_destroy(&share->mutex); - pthread_cond_destroy(&share->cond); } my_hash_free(&share->name_hash); @@ -2001,7 +1993,7 @@ int closefrm(register TABLE *table, bool free_share) if (free_share) { if (table->s->tmp_table == NO_TMP_TABLE) - release_table_share(table->s, RELEASE_NORMAL); + release_table_share(table->s); else free_table_share(table->s); } -- cgit v1.2.1 From 511c68fbd461efecd5bd9f7c08b42916fa8416c9 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Mon, 30 Nov 2009 22:38:25 +0300 Subject: Backport of: ------------------------------------------------------------------- revno: 2630.6.6 committer: Konstantin Osipov branch nick: mysql-6.0-3726 timestamp: Tue 2008-05-27 16:15:44 +0400 message: Implement code review fixes for WL#3726 "DDL locking for all metadata objects": cleanup the code from share->mutex acquisitions, which are now obsolete. --- sql/table.cc | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'sql/table.cc') diff --git a/sql/table.cc b/sql/table.cc index b232ba23a89..c8814cff685 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -320,7 +320,7 @@ TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key, share->free_tables.empty(); memcpy((char*) &share->mem_root, (char*) &mem_root, sizeof(mem_root)); - pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST); + pthread_mutex_init(&share->LOCK_ha_data, MY_MUTEX_INIT_FAST); } DBUG_RETURN(share); } @@ -411,18 +411,11 @@ void free_table_share(TABLE_SHARE *share) DBUG_PRINT("enter", ("table: %s.%s", share->db.str, share->table_name.str)); DBUG_ASSERT(share->ref_count == 0); - /* - If someone is waiting for this to be deleted, inform it about this. - Don't do a delete until we know that no one is refering to this anymore. - */ + /* The mutex is initialized only for shares that are part of the TDC */ if (share->tmp_table == NO_TMP_TABLE) - { - /* No thread refers to this anymore */ - pthread_mutex_unlock(&share->mutex); - pthread_mutex_destroy(&share->mutex); - } + pthread_mutex_destroy(&share->LOCK_ha_data); my_hash_free(&share->name_hash); - + plugin_unlock(NULL, share->db_plugin); share->db_plugin= NULL; -- cgit v1.2.1 From a9dbad1afd452ca10116a0bbf83ab3d98b33723e Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Tue, 1 Dec 2009 01:33:22 +0300 Subject: Backport of: ------------------------------------------------------------ revno: 2630.4.17 committer: Dmitry Lenev branch nick: mysql-6.0-3726-w2 timestamp: Thu 2008-05-29 16:52:56 +0400 message: WL#3726 "DDL locking for all metadata objects". After review fixes in progress. "The great correction of names". Renamed MDL_LOCK and MDL_LOCK_DATA classes to make usage of these names in metadata locking subsystem consistent with other parts of server (i.e. thr_lock.cc). Now we MDL_LOCK_DATA corresponds to request for a lock and MDL_LOCK to the lock itself. Adjusted code in MDL subsystem and other places using these classes accordingly. Did similar thing for GLOBAL_MDL_LOCK_DATA class and also changed name of its members to correspond to names of MDL_LOCK_DATA members. Finally got rid of usage of one letter variables in MDL code since it makes code harder to search in (according to reviewer). --- sql/table.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'sql/table.cc') diff --git a/sql/table.cc b/sql/table.cc index c8814cff685..3943dc8e50b 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -4832,8 +4832,9 @@ size_t max_row_length(TABLE *table, const uchar *data) void alloc_mdl_locks(TABLE_LIST *table_list, MEM_ROOT *root) { for ( ; table_list ; table_list= table_list->next_global) - table_list->mdl_lock= mdl_alloc_lock(0, table_list->db, - table_list->table_name, root); + table_list->mdl_lock_data= mdl_alloc_lock(0, table_list->db, + table_list->table_name, + root); } -- cgit v1.2.1 From ef15a335b3c924b779ba986acafffad41ff07ba8 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Thu, 3 Dec 2009 02:09:22 +0300 Subject: Backport of: ---------------------------------------------------------- revno: 2630.4.38 committer: Konstantin Osipov branch nick: mysql-6.0-4144 timestamp: Wed 2008-06-25 22:07:06 +0400 message: WL#4144 - Lock MERGE engine children. Committing a version of the patch merged with WL#3726 on behalf of Ingo. Step #1: Move locking from parent to children. MERGE children are now left in the query list of tables after inserted there in open_tables(). So they are locked by lock_tables() as all other tables are. The MERGE parent does not store locks any more. It appears in a MYSQL_LOCK with zero lock data. This is kind of a "dummy" lock. All other lock handling is also done directly on the children. To protect against parent or child modifications during LOCK TABLES, the children are detached after every statement and attached before every statement, even under LOCK TABLES. The children table list is removed from the query list of tables on every detach and on close of the parent. Step #2: Move MERGE specific functionality from SQL layer into table handler. Functionality moved from SQL layer (mainly sql_base.cc) to the table handler (ha_myisammrg.cc). Unnecessary code is removed from the SQL layer. Step #3: Moved all MERGE specific members from TABLE to ha_myisammrg. Moved members from TABLE to ha_myisammrg. Renamed some mebers. Fixed comments. Step #4: Valgrind and coverage testing Valgrind did not uncover new problems. Added purecov comments. Added a new test for DATA/INDEX DIRECTORY options. Changed handling of ::reset() for non-attached children. Fixed the merge-big test. Step #5: Fixed crashes detected during review Changed detection when to attach/detach. Added new tests. Backport also the fix for Bug#44040 "MySQL allows creating a MERGE table upon VIEWs but crashes when using it" --- sql/table.cc | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'sql/table.cc') diff --git a/sql/table.cc b/sql/table.cc index 3943dc8e50b..dd39d05733e 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -4555,24 +4555,6 @@ void TABLE::mark_columns_needed_for_insert() } -/** - @brief Check if this is part of a MERGE table with attached children. - - @return status - @retval TRUE children are attached - @retval FALSE no MERGE part or children not attached - - @detail - A MERGE table consists of a parent TABLE and zero or more child - TABLEs. Each of these TABLEs is called a part of a MERGE table. -*/ - -bool TABLE::is_children_attached(void) -{ - return((child_l && children_attached) || - (parent && parent->children_attached)); -} - /* Cleanup this table for re-execution. -- cgit v1.2.1 From 911c673edf45616137d71f43f472be410ecb7511 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Fri, 4 Dec 2009 02:29:40 +0300 Subject: Backport of: ------------------------------------------------------------ revno: 2617.23.18 committer: Davi Arnaut branch nick: 4284-6.0 timestamp: Mon 2009-03-02 18:18:26 -0300 message: Bug#989: If DROP TABLE while there's an active transaction, wrong binlog order WL#4284: Transactional DDL locking This is a prerequisite patch: These changes are intended to split lock requests from granted locks and to allow the memory and lifetime of granted locks to be managed within the MDL subsystem. Furthermore, tickets can now be shared and therefore are used to satisfy multiple lock requests, but only shared locks can be recursive. The problem is that the MDL subsystem morphs lock requests into granted locks locks but does not manage the memory and lifetime of lock requests, and hence, does not manage the memory of granted locks either. This can be problematic because it puts the burden of tracking references on the users of the subsystem and it can't be easily done in transactional contexts where the locks have to be kept around for the duration of a transaction. Another issue is that recursive locks (when the context trying to acquire a lock already holds a lock on the same object) requires that each time the lock is granted, a unique lock request/granted lock structure structure must be kept around until the lock is released. This can lead to memory leaks in transactional contexts as locks taken during the transaction should only be released at the end of the transaction. This also leads to unnecessary wake ups (broadcasts) in the MDL subsystem if the context still holds a equivalent of the lock being released. These issues are exacerbated due to the fact that WL#4284 low-level design says that the implementation should "2) Store metadata locks in transaction memory root, rather than statement memory root" but this is not possible because a memory root, as implemented in mysys, requires all objects allocated from it to be freed all at once. This patch combines review input and significant code contributions from Konstantin Osipov (kostja) and Dmitri Lenev (dlenev). --- sql/table.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'sql/table.cc') diff --git a/sql/table.cc b/sql/table.cc index dd39d05733e..b1988faf722 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -4811,12 +4811,11 @@ size_t max_row_length(TABLE *table, const uchar *data) objects for all elements of table list. */ -void alloc_mdl_locks(TABLE_LIST *table_list, MEM_ROOT *root) +void alloc_mdl_requests(TABLE_LIST *table_list, MEM_ROOT *root) { for ( ; table_list ; table_list= table_list->next_global) - table_list->mdl_lock_data= mdl_alloc_lock(0, table_list->db, - table_list->table_name, - root); + table_list->mdl_lock_request= + mdl_request_alloc(0, table_list->db, table_list->table_name, root); } -- cgit v1.2.1 From a3a23ec4d3b9d9c22b8bdbc9adf2cd0f157c6a3f Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Fri, 4 Dec 2009 02:52:05 +0300 Subject: Backport of: ---------------------------------------------------------- revno: 2617.23.20 committer: Konstantin Osipov branch nick: mysql-6.0-runtime timestamp: Wed 2009-03-04 16:31:31 +0300 message: WL#4284 "Transactional DDL locking" Review comments: "Objectify" the MDL API. MDL_request and MDL_context still need manual construction and destruction, since they are used in environment that is averse to constructors/destructors. --- sql/table.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'sql/table.cc') diff --git a/sql/table.cc b/sql/table.cc index b1988faf722..8d28514e912 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -4814,8 +4814,8 @@ size_t max_row_length(TABLE *table, const uchar *data) void alloc_mdl_requests(TABLE_LIST *table_list, MEM_ROOT *root) { for ( ; table_list ; table_list= table_list->next_global) - table_list->mdl_lock_request= - mdl_request_alloc(0, table_list->db, table_list->table_name, root); + table_list->mdl_request= + MDL_request::create(0, table_list->db, table_list->table_name, root); } -- cgit v1.2.1 From a66a2608ae4d70a3f9b3d41e38cfb97eb616bed3 Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Tue, 8 Dec 2009 12:57:07 +0300 Subject: Backport of: ---------------------------------------------------------- revno: 2617.69.20 committer: Konstantin Osipov branch nick: 5.4-4284-1-assert timestamp: Thu 2009-08-13 18:29:55 +0400 message: WL#4284 "Transactional DDL locking" A review fix. Since WL#4284 implementation separated MDL_request and MDL_ticket, MDL_request becamse a utility object necessary only to get a ticket. Store it by-value in TABLE_LIST with the intent to merge MDL_request::key with table_list->table_name and table_list->db in future. Change the MDL subsystem to not require MDL_requests to stay around till close_thread_tables(). Remove the list of requests from the MDL context. Requests for shared metadata locks acquired in open_tables() are only used as a list in recover_from_failed_open_table_attempt(), which calls mdl_context.wait_for_locks() for this list. To keep such list for recover_from_failed_open_table_attempt(), introduce a context class (Open_table_context), that collects all requests. A lot of minor cleanups and simplications that became possible with this change. --- sql/table.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'sql/table.cc') diff --git a/sql/table.cc b/sql/table.cc index 8d28514e912..7fb9bbbd955 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -4583,6 +4583,14 @@ void TABLE_LIST::reinit_before_use(THD *thd) } while (parent_embedding && parent_embedding->nested_join->join_list.head() == embedded); + + mdl_request.ticket= NULL; + /* + Not strictly necessary, but we manipulate with the type in open_table(), + so it's "safe" to reset the lock request type to the parser default, to + restore things back to first-execution state. + */ + mdl_request.set_type(MDL_SHARED); } /* @@ -4811,11 +4819,11 @@ size_t max_row_length(TABLE *table, const uchar *data) objects for all elements of table list. */ -void alloc_mdl_requests(TABLE_LIST *table_list, MEM_ROOT *root) +void init_mdl_requests(TABLE_LIST *table_list) { for ( ; table_list ; table_list= table_list->next_global) - table_list->mdl_request= - MDL_request::create(0, table_list->db, table_list->table_name, root); + table_list->mdl_request.init(0, table_list->db, table_list->table_name, + MDL_SHARED); } -- cgit v1.2.1 From 4592dd2d8147d54422432afcf0e87530df9a3d59 Mon Sep 17 00:00:00 2001 From: Jon Olav Hauglid Date: Wed, 9 Dec 2009 09:51:20 +0100 Subject: Backport of revno: 2617.69.40 A pre-requisite patch for Bug#30977 "Concurrent statement using stored function and DROP FUNCTION breaks SBR". This patch changes the MDL API by introducing a namespace for lock keys: MDL_TABLE for tables and views and MDL_PROCEDURE for stored procedures and functions. The latter is needed for the fix for Bug#30977. --- sql/table.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sql/table.cc') diff --git a/sql/table.cc b/sql/table.cc index 7fb9bbbd955..c66610e5693 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -4822,7 +4822,7 @@ size_t max_row_length(TABLE *table, const uchar *data) void init_mdl_requests(TABLE_LIST *table_list) { for ( ; table_list ; table_list= table_list->next_global) - table_list->mdl_request.init(0, table_list->db, table_list->table_name, + table_list->mdl_request.init(MDL_TABLE, table_list->db, table_list->table_name, MDL_SHARED); } -- cgit v1.2.1 From 2e73ea7ea8a56765982ba5c8642ed5b14ef39fde Mon Sep 17 00:00:00 2001 From: Konstantin Osipov Date: Thu, 10 Dec 2009 11:21:38 +0300 Subject: Backport of: ------------------------------------------------------------ revno: 2617.68.25 committer: Dmitry Lenev branch nick: mysql-next-bg-pre2-2 timestamp: Wed 2009-09-16 18:26:50 +0400 message: Follow-up for one of pre-requisite patches for fixing bug #30977 "Concurrent statement using stored function and DROP FUNCTION breaks SBR". Made enum_mdl_namespace enum part of MDL_key class and removed MDL_ prefix from the names of enum members. In order to do the latter changed name of PROCEDURE symbol to PROCEDURE_SYM (otherwise macro which was automatically generated for this symbol conflicted with MDL_key::PROCEDURE enum member). --- sql/table.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'sql/table.cc') diff --git a/sql/table.cc b/sql/table.cc index c66610e5693..aef836c330e 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -4822,7 +4822,8 @@ size_t max_row_length(TABLE *table, const uchar *data) void init_mdl_requests(TABLE_LIST *table_list) { for ( ; table_list ; table_list= table_list->next_global) - table_list->mdl_request.init(MDL_TABLE, table_list->db, table_list->table_name, + table_list->mdl_request.init(MDL_key::TABLE, + table_list->db, table_list->table_name, MDL_SHARED); } -- cgit v1.2.1 From ae2768ce9c7df45ec88ba49bf149985bf7c9308d Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 22 Dec 2009 10:35:56 +0100 Subject: WL#4738 streamline/simplify @@variable creation process Bug#16565 mysqld --help --verbose does not order variablesBug#20413 sql_slave_skip_counter is not shown in show variables Bug#20415 Output of mysqld --help --verbose is incomplete Bug#25430 variable not found in SELECT @@global.ft_max_word_len; Bug#32902 plugin variables don't know their names Bug#34599 MySQLD Option and Variable Reference need to be consistent in formatting! Bug#34829 No default value for variable and setting default does not raise error Bug#34834 ? Is accepted as a valid sql mode Bug#34878 Few variables have default value according to documentation but error occurs Bug#34883 ft_boolean_syntax cant be assigned from user variable to global var. Bug#37187 `INFORMATION_SCHEMA`.`GLOBAL_VARIABLES`: inconsistent status Bug#40988 log_output_basic.test succeeded though syntactically false. Bug#41010 enum-style command-line options are not honoured (maria.maria-recover fails) Bug#42103 Setting key_buffer_size to a negative value may lead to very large allocations Bug#44691 Some plugins configured as MYSQL_PLUGIN_MANDATORY in can be disabled Bug#44797 plugins w/o command-line options have no disabling option in --help Bug#46314 string system variables don't support expressions Bug#46470 sys_vars.max_binlog_cache_size_basic_32 is broken Bug#46586 When using the plugin interface the type "set" for options caused a crash. Bug#47212 Crash in DBUG_PRINT in mysqltest.cc when trying to print octal number Bug#48758 mysqltest crashes on sys_vars.collation_server_basic in gcov builds Bug#49417 some complaints about mysqld --help --verbose output Bug#49540 DEFAULT value of binlog_format isn't the default value Bug#49640 ambiguous option '--skip-skip-myisam' (double skip prefix) Bug#49644 init_connect and \0 Bug#49645 init_slave and multi-byte characters Bug#49646 mysql --show-warnings crashes when server dies --- sql/table.cc | 6 ------ 1 file changed, 6 deletions(-) (limited to 'sql/table.cc') diff --git a/sql/table.cc b/sql/table.cc index 0f68bb7c29e..eef03955183 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1406,12 +1406,6 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, keyinfo->extra_length+=HA_KEY_BLOB_LENGTH; key_part->store_length+=HA_KEY_BLOB_LENGTH; keyinfo->key_length+= HA_KEY_BLOB_LENGTH; - /* - Mark that there may be many matching values for one key - combination ('a', 'a ', 'a '...) - */ - if (!(field->flags & BINARY_FLAG)) - keyinfo->flags|= HA_END_SPACE_KEY; } if (field->type() == MYSQL_TYPE_BIT) key_part->key_part_flag|= HA_BIT_PART; -- cgit v1.2.1 From a85539a83ae3c1416b6cabe0fabca4aa0153bd86 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 23 Dec 2009 13:06:03 +0100 Subject: fixed "engine not found" error in open_binary_frm corrected rotten test --- sql/table.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'sql/table.cc') diff --git a/sql/table.cc b/sql/table.cc index eef03955183..ea36a856d2c 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -934,6 +934,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, { /* purecov: begin inspected */ error= 8; + name.str[name.length]=0; my_error(ER_UNKNOWN_STORAGE_ENGINE, MYF(0), name.str); my_free(buff, MYF(0)); goto err; -- cgit v1.2.1 From a4c3bc618bb83884a19dc157bc56d4e3d2432c22 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Wed, 6 Jan 2010 22:42:07 -0700 Subject: WL#2360 Performance schema Part IV: sql instrumentation --- sql/table.cc | 132 +++++++++++++++++++++++++++++++---------------------------- 1 file changed, 69 insertions(+), 63 deletions(-) (limited to 'sql/table.cc') diff --git a/sql/table.cc b/sql/table.cc index ea36a856d2c..c0c365f4901 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -1,4 +1,4 @@ -/* Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc. +/* Copyright 2000-2008 MySQL AB, 2008-2009 Sun Microsystems, Inc. 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 @@ -24,6 +24,9 @@ /* INFORMATION_SCHEMA name */ LEX_STRING INFORMATION_SCHEMA_NAME= {C_STRING_WITH_LEN("information_schema")}; +/* PERFORMANCE_SCHEMA name */ +LEX_STRING PERFORMANCE_SCHEMA_DB_NAME= {C_STRING_WITH_LEN("performance_schema")}; + /* MYSQL_SCHEMA name */ LEX_STRING MYSQL_SCHEMA_NAME= {C_STRING_WITH_LEN("mysql")}; @@ -214,37 +217,35 @@ TABLE_CATEGORY get_table_category(const LEX_STRING *db, const LEX_STRING *name) if ((db->length == INFORMATION_SCHEMA_NAME.length) && (my_strcasecmp(system_charset_info, - INFORMATION_SCHEMA_NAME.str, - db->str) == 0)) - { + INFORMATION_SCHEMA_NAME.str, + db->str) == 0)) return TABLE_CATEGORY_INFORMATION; - } + + if ((db->length == PERFORMANCE_SCHEMA_DB_NAME.length) && + (my_strcasecmp(system_charset_info, + PERFORMANCE_SCHEMA_DB_NAME.str, + db->str) == 0)) + return TABLE_CATEGORY_PERFORMANCE; if ((db->length == MYSQL_SCHEMA_NAME.length) && (my_strcasecmp(system_charset_info, - MYSQL_SCHEMA_NAME.str, - db->str) == 0)) + MYSQL_SCHEMA_NAME.str, + db->str) == 0)) { if (is_system_table_name(name->str, name->length)) - { return TABLE_CATEGORY_SYSTEM; - } if ((name->length == GENERAL_LOG_NAME.length) && (my_strcasecmp(system_charset_info, - GENERAL_LOG_NAME.str, - name->str) == 0)) - { - return TABLE_CATEGORY_PERFORMANCE; - } + GENERAL_LOG_NAME.str, + name->str) == 0)) + return TABLE_CATEGORY_LOG; if ((name->length == SLOW_LOG_NAME.length) && (my_strcasecmp(system_charset_info, - SLOW_LOG_NAME.str, - name->str) == 0)) - { - return TABLE_CATEGORY_PERFORMANCE; - } + SLOW_LOG_NAME.str, + name->str) == 0)) + return TABLE_CATEGORY_LOG; } return TABLE_CATEGORY_USER; @@ -317,8 +318,8 @@ TABLE_SHARE *alloc_table_share(TABLE_LIST *table_list, char *key, share->cached_row_logging_check= -1; memcpy((char*) &share->mem_root, (char*) &mem_root, sizeof(mem_root)); - pthread_mutex_init(&share->mutex, MY_MUTEX_INIT_FAST); - pthread_cond_init(&share->cond, NULL); + mysql_mutex_init(key_TABLE_SHARE_mutex, &share->mutex, MY_MUTEX_INIT_FAST); + mysql_cond_init(key_TABLE_SHARE_cond, &share->cond, NULL); } DBUG_RETURN(share); } @@ -415,13 +416,13 @@ void free_table_share(TABLE_SHARE *share) /* share->mutex is locked in release_table_share() */ while (share->waiting_on_cond) { - pthread_cond_broadcast(&share->cond); - pthread_cond_wait(&share->cond, &share->mutex); + mysql_cond_broadcast(&share->cond); + mysql_cond_wait(&share->cond, &share->mutex); } /* No thread refers to this anymore */ - pthread_mutex_unlock(&share->mutex); - pthread_mutex_destroy(&share->mutex); - pthread_cond_destroy(&share->cond); + mysql_mutex_unlock(&share->mutex); + mysql_mutex_destroy(&share->mutex); + mysql_cond_destroy(&share->cond); } my_hash_free(&share->name_hash); @@ -539,7 +540,8 @@ int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags) disk_buff= NULL; strxmov(path, share->normalized_path.str, reg_ext, NullS); - if ((file= my_open(path, O_RDONLY | O_SHARE, MYF(0))) < 0) + if ((file= mysql_file_open(key_file_frm, + path, O_RDONLY | O_SHARE, MYF(0))) < 0) { /* We don't try to open 5.0 unencoded name, if @@ -550,7 +552,7 @@ int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags) - non-encoded db or table name contain "#mysql50#" prefix. This kind of tables must have been opened only by the - my_open() above. + mysql_file_open() above. */ if (strchr(share->table_name.str, '@') || !strncmp(share->db.str, MYSQL50_TABLE_NAME_PREFIX, @@ -576,7 +578,8 @@ int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags) so no need to check the old file name. */ if (length == share->normalized_path.length || - ((file= my_open(path, O_RDONLY | O_SHARE, MYF(0))) < 0)) + ((file= mysql_file_open(key_file_frm, + path, O_RDONLY | O_SHARE, MYF(0))) < 0)) goto err_not_open; /* Unencoded 5.0 table name found */ @@ -586,7 +589,7 @@ int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags) } error= 4; - if (my_read(file, head, 64, MYF(MY_NABP))) + if (mysql_file_read(file, head, 64, MYF(MY_NABP))) goto err; if (head[0] == (uchar) 254 && head[1] == 1) @@ -639,7 +642,7 @@ int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags) thd->status_var.opened_shares++; err: - my_close(file, MYF(MY_WME)); + mysql_file_close(file, MYF(MY_WME)); err_not_open: if (error && !error_given) @@ -753,7 +756,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, /* Read keyinformation */ key_info_length= (uint) uint2korr(head+28); - my_seek(file,(ulong) uint2korr(head+6),MY_SEEK_SET,MYF(0)); + mysql_file_seek(file, (ulong) uint2korr(head+6), MY_SEEK_SET, MYF(0)); if (read_string(file,(uchar**) &disk_buff,key_info_length)) goto err; /* purecov: inspected */ if (disk_buff[0] & 0x80) @@ -857,8 +860,8 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, DBUG_PRINT("info", ("extra segment size is %u bytes", n_length)); if (!(next_chunk= buff= (uchar*) my_malloc(n_length, MYF(MY_WME)))) goto err; - if (my_pread(file, buff, n_length, record_offset + share->reclength, - MYF(MY_NABP))) + if (mysql_file_pread(file, buff, n_length, record_offset + share->reclength, + MYF(MY_NABP))) { my_free(buff, MYF(0)); goto err; @@ -1027,12 +1030,12 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, rec_buff_length))) goto err; /* purecov: inspected */ share->default_values= record; - if (my_pread(file, record, (size_t) share->reclength, - record_offset, MYF(MY_NABP))) + if (mysql_file_pread(file, record, (size_t) share->reclength, + record_offset, MYF(MY_NABP))) goto err; /* purecov: inspected */ - my_seek(file,pos,MY_SEEK_SET,MYF(0)); - if (my_read(file, head,288,MYF(MY_NABP))) + mysql_file_seek(file, pos, MY_SEEK_SET, MYF(0)); + if (mysql_file_read(file, head, 288, MYF(MY_NABP))) goto err; #ifdef HAVE_CRYPTED_FRM if (crypted) @@ -2059,11 +2062,11 @@ ulong get_form_pos(File file, uchar *head, TYPELIB *save_names) if (names) { length=uint2korr(head+4); - my_seek(file,64L,MY_SEEK_SET,MYF(0)); + mysql_file_seek(file, 64L, MY_SEEK_SET, MYF(0)); if (!(buf= (uchar*) my_malloc((size_t) length+a_length+names*4, MYF(MY_WME))) || - my_read(file, buf+a_length, (size_t) (length+names*4), - MYF(MY_NABP))) + mysql_file_read(file, buf+a_length, (size_t) (length+names*4), + MYF(MY_NABP))) { /* purecov: inspected */ x_free((uchar*) buf); /* purecov: inspected */ DBUG_RETURN(0L); /* purecov: inspected */ @@ -2101,7 +2104,7 @@ int read_string(File file, uchar**to, size_t length) x_free(*to); if (!(*to= (uchar*) my_malloc(length+1,MYF(MY_WME))) || - my_read(file, *to, length,MYF(MY_NABP))) + mysql_file_read(file, *to, length, MYF(MY_NABP))) { x_free(*to); /* purecov: inspected */ *to= 0; /* purecov: inspected */ @@ -2133,23 +2136,24 @@ ulong make_new_entry(File file, uchar *fileinfo, TYPELIB *formnames, { /* Expand file */ newpos+=IO_SIZE; int4store(fileinfo+10,newpos); - endpos=(ulong) my_seek(file,0L,MY_SEEK_END,MYF(0));/* Copy from file-end */ + /* Copy from file-end */ + endpos= (ulong) mysql_file_seek(file, 0L, MY_SEEK_END, MYF(0)); bufflength= (uint) (endpos & (IO_SIZE-1)); /* IO_SIZE is a power of 2 */ while (endpos > maxlength) { - my_seek(file,(ulong) (endpos-bufflength),MY_SEEK_SET,MYF(0)); - if (my_read(file, buff, bufflength, MYF(MY_NABP+MY_WME))) + mysql_file_seek(file, (ulong) (endpos-bufflength), MY_SEEK_SET, MYF(0)); + if (mysql_file_read(file, buff, bufflength, MYF(MY_NABP+MY_WME))) DBUG_RETURN(0L); - my_seek(file,(ulong) (endpos-bufflength+IO_SIZE),MY_SEEK_SET, - MYF(0)); - if ((my_write(file, buff,bufflength,MYF(MY_NABP+MY_WME)))) + mysql_file_seek(file, (ulong) (endpos-bufflength+IO_SIZE), MY_SEEK_SET, + MYF(0)); + if ((mysql_file_write(file, buff, bufflength, MYF(MY_NABP+MY_WME)))) DBUG_RETURN(0); endpos-=bufflength; bufflength=IO_SIZE; } bzero(buff,IO_SIZE); /* Null new block */ - my_seek(file,(ulong) maxlength,MY_SEEK_SET,MYF(0)); - if (my_write(file,buff,bufflength,MYF(MY_NABP+MY_WME))) + mysql_file_seek(file, (ulong) maxlength, MY_SEEK_SET, MYF(0)); + if (mysql_file_write(file, buff, bufflength, MYF(MY_NABP+MY_WME))) DBUG_RETURN(0L); maxlength+=IO_SIZE; /* Fix old ref */ int2store(fileinfo+6,maxlength); @@ -2168,16 +2172,17 @@ ulong make_new_entry(File file, uchar *fileinfo, TYPELIB *formnames, } else (void) strxmov((char*) buff,newname,"/",NullS); /* purecov: inspected */ - my_seek(file,63L+(ulong) n_length,MY_SEEK_SET,MYF(0)); - if (my_write(file, buff, (size_t) length+1,MYF(MY_NABP+MY_WME)) || - (names && my_write(file,(uchar*) (*formnames->type_names+n_length-1), - names*4, MYF(MY_NABP+MY_WME))) || - my_write(file, fileinfo+10, 4,MYF(MY_NABP+MY_WME))) + mysql_file_seek(file, 63L+(ulong) n_length, MY_SEEK_SET, MYF(0)); + if (mysql_file_write(file, buff, (size_t) length+1, MYF(MY_NABP+MY_WME)) || + (names && mysql_file_write(file, + (uchar*) (*formnames->type_names+n_length-1), + names*4, MYF(MY_NABP+MY_WME))) || + mysql_file_write(file, fileinfo+10, 4, MYF(MY_NABP+MY_WME))) DBUG_RETURN(0L); /* purecov: inspected */ int2store(fileinfo+8,names+1); int2store(fileinfo+4,n_length+length); - (void) my_chsize(file, newpos, 0, MYF(MY_WME));/* Append file with '\0' */ + (void) mysql_file_chsize(file, newpos, 0, MYF(MY_WME));/* Append file with '\0' */ DBUG_RETURN(newpos); } /* make_new_entry */ @@ -2459,7 +2464,8 @@ File create_frm(THD *thd, const char *name, const char *db, if (create_info->min_rows > UINT_MAX32) create_info->min_rows= UINT_MAX32; - if ((file= my_create(name, CREATE_MODE, create_flags, MYF(0))) >= 0) + if ((file= mysql_file_create(key_file_frm, + name, CREATE_MODE, create_flags, MYF(0))) >= 0) { uint key_length, tmp_key_length, tmp, csid; bzero((char*) fileinfo,64); @@ -2529,10 +2535,10 @@ File create_frm(THD *thd, const char *name, const char *db, bzero(fill,IO_SIZE); for (; length > IO_SIZE ; length-= IO_SIZE) { - if (my_write(file,fill, IO_SIZE, MYF(MY_WME | MY_NABP))) + if (mysql_file_write(file, fill, IO_SIZE, MYF(MY_WME | MY_NABP))) { - (void) my_close(file,MYF(0)); - (void) my_delete(name,MYF(0)); + (void) mysql_file_close(file, MYF(0)); + (void) mysql_file_delete(key_file_frm, name, MYF(0)); return(-1); } } @@ -2571,7 +2577,7 @@ rename_file_ext(const char * from,const char * to,const char * ext) char from_b[FN_REFLEN],to_b[FN_REFLEN]; (void) strxmov(from_b,from,ext,NullS); (void) strxmov(to_b,to,ext,NullS); - return (my_rename(from_b,to_b,MYF(MY_WME))); + return (mysql_file_rename(key_file_frm, from_b, to_b, MYF(MY_WME))); } @@ -3935,7 +3941,7 @@ const char *Natural_join_column::db_name() DBUG_ASSERT(!strcmp(table_ref->db, table_ref->table->s->db.str) || (table_ref->schema_table && - is_schema_db(table_ref->table->s->db.str))); + is_infoschema_db(table_ref->table->s->db.str))); return table_ref->db; } @@ -4153,7 +4159,7 @@ const char *Field_iterator_table_ref::get_db_name() */ DBUG_ASSERT(!strcmp(table_ref->db, table_ref->table->s->db.str) || (table_ref->schema_table && - is_schema_db(table_ref->table->s->db.str))); + is_infoschema_db(table_ref->table->s->db.str))); return table_ref->db; } -- cgit v1.2.1 From afd15c43a9103c47389835105489acd07d64e014 Mon Sep 17 00:00:00 2001 From: Dmitry Lenev Date: Mon, 1 Feb 2010 14:43:06 +0300 Subject: Implement new type-of-operation-aware metadata locks. Add a wait-for graph based deadlock detector to the MDL subsystem. Fixes bug #46272 "MySQL 5.4.4, new MDL: unnecessary deadlock" and bug #37346 "innodb does not detect deadlock between update and alter table". The first bug manifested itself as an unwarranted abort of a transaction with ER_LOCK_DEADLOCK error by a concurrent ALTER statement, when this transaction tried to repeat use of a table, which it has already used in a similar fashion before ALTER started. The second bug showed up as a deadlock between table-level locks and InnoDB row locks, which was "detected" only after innodb_lock_wait_timeout timeout. A transaction would start using the table and modify a few rows. Then ALTER TABLE would come in, and start copying rows into a temporary table. Eventually it would stumble on the modified records and get blocked on a row lock. The first transaction would try to do more updates, and get blocked on thr_lock.c lock. This situation of circular wait would only get resolved by a timeout. Both these bugs stemmed from inadequate solutions to the problem of deadlocks occurring between different locking subsystems. In the first case we tried to avoid deadlocks between metadata locking and table-level locking subsystems, when upgrading shared metadata lock to exclusive one. Transactions holding the shared lock on the table and waiting for some table-level lock used to be aborted too aggressively. We also allowed ALTER TABLE to start in presence of transactions that modify the subject table. ALTER TABLE acquires TL_WRITE_ALLOW_READ lock at start, and that block all writes against the table (naturally, we don't want any writes to be lost when switching the old and the new table). TL_WRITE_ALLOW_READ lock, in turn, would block the started transaction on thr_lock.c lock, should they do more updates. This, again, lead to the need to abort such transactions. The second bug occurred simply because we didn't have any mechanism to detect deadlocks between the table-level locks in thr_lock.c and row-level locks in InnoDB, other than innodb_lock_wait_timeout. This patch solves both these problems by moving lock conflicts which are causing these deadlocks into the metadata locking subsystem, thus making it possible to avoid or detect such deadlocks inside MDL. To do this we introduce new type-of-operation-aware metadata locks, which allow MDL subsystem to know not only the fact that transaction has used or is going to use some object but also what kind of operation it has carried out or going to carry out on the object. This, along with the addition of a special kind of upgradable metadata lock, allows ALTER TABLE to wait until all transactions which has updated the table to go away. This solves the second issue. Another special type of upgradable metadata lock is acquired by LOCK TABLE WRITE. This second lock type allows to solve the first issue, since abortion of table-level locks in event of DDL under LOCK TABLES becomes also unnecessary. Below follows the list of incompatible changes introduced by this patch: - From now on, ALTER TABLE and CREATE/DROP TRIGGER SQL (i.e. those statements that acquire TL_WRITE_ALLOW_READ lock) wait for all transactions which has *updated* the table to complete. - From now on, LOCK TABLES ... WRITE, REPAIR/OPTIMIZE TABLE (i.e. all statements which acquire TL_WRITE table-level lock) wait for all transaction which *updated or read* from the table to complete. As a consequence, innodb_table_locks=0 option no longer applies to LOCK TABLES ... WRITE. - DROP DATABASE, DROP TABLE, RENAME TABLE no longer abort statements or transactions which use tables being dropped or renamed, and instead wait for these transactions to complete. - Since LOCK TABLES WRITE now takes a special metadata lock, not compatible with with reads or writes against the subject table and transaction-wide, thr_lock.c deadlock avoidance algorithm that used to ensure absence of deadlocks between LOCK TABLES WRITE and other statements is no longer sufficient, even for MyISAM. The wait-for graph based deadlock detector of MDL subsystem may sometimes be necessary and is involved. This may lead to ER_LOCK_DEADLOCK error produced for multi-statement transactions even if these only use MyISAM: session 1: session 2: begin; update t1 ... lock table t2 write, t1 write; -- gets a lock on t2, blocks on t1 update t2 ... (ER_LOCK_DEADLOCK) - Finally, support of LOW_PRIORITY option for LOCK TABLES ... WRITE was abandoned. LOCK TABLE ... LOW_PRIORITY WRITE from now on has the same priority as the usual LOCK TABLE ... WRITE. SELECT HIGH PRIORITY no longer trumps LOCK TABLE ... WRITE in the wait queue. - We do not take upgradable metadata locks on implicitly locked tables. So if one has, say, a view v1 that uses table t1, and issues: LOCK TABLE v1 WRITE; FLUSH TABLE t1; -- (or just 'FLUSH TABLES'), an error is produced. In order to be able to perform DDL on a table under LOCK TABLES, the table must be locked explicitly in the LOCK TABLES list. --- sql/table.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'sql/table.cc') diff --git a/sql/table.cc b/sql/table.cc index 74add641544..2bd7a8cc7ec 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -4583,11 +4583,12 @@ void TABLE_LIST::reinit_before_use(THD *thd) mdl_request.ticket= NULL; /* - Not strictly necessary, but we manipulate with the type in open_table(), - so it's "safe" to reset the lock request type to the parser default, to - restore things back to first-execution state. + Since we manipulate with the metadata lock type in open_table(), + we need to reset it to the parser default, to restore things back + to first-execution state. */ - mdl_request.set_type(MDL_SHARED); + mdl_request.set_type((lock_type >= TL_WRITE_ALLOW_WRITE) ? + MDL_SHARED_WRITE : MDL_SHARED_READ); } /* @@ -4821,7 +4822,8 @@ void init_mdl_requests(TABLE_LIST *table_list) for ( ; table_list ; table_list= table_list->next_global) table_list->mdl_request.init(MDL_key::TABLE, table_list->db, table_list->table_name, - MDL_SHARED); + table_list->lock_type >= TL_WRITE_ALLOW_WRITE ? + MDL_SHARED_WRITE : MDL_SHARED_READ); } -- cgit v1.2.1 From 7c10a8981ce3f5eff59e0f3a73e4f0ad176f8c90 Mon Sep 17 00:00:00 2001 From: Alexander Nozdrin Date: Sat, 20 Feb 2010 13:07:32 +0300 Subject: Patch for WL#3736: Extended Table, Column and Index Comments. The task is to (a) add a comment on indexes and (b) increase the maximum length of column, table and the new index comments. The patch committed on behalf of Yoshinori Matsunobu (Yoshinori.Matsunobu@Sun.COM). --- sql/table.cc | 88 +++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 69 insertions(+), 19 deletions(-) (limited to 'sql/table.cc') diff --git a/sql/table.cc b/sql/table.cc index 514ea865e8c..0e66ff9da94 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -517,7 +517,7 @@ int open_table_def(THD *thd, TABLE_SHARE *share, uint db_flags) int error, table_type; bool error_given; File file; - uchar head[288], *disk_buff; + uchar head[64], *disk_buff; char path[FN_REFLEN]; MEM_ROOT **root_ptr, *old_root; DBUG_ENTER("open_table_def"); @@ -660,6 +660,7 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, uint i,j; bool use_hash; char *keynames, *names, *comment_pos; + uchar forminfo[288]; uchar *record; uchar *disk_buff, *strpos, *null_flags, *null_pos; ulong pos, record_offset, *rec_per_key, rec_buff_length; @@ -682,6 +683,9 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, if (!(pos=get_form_pos(file,head,(TYPELIB*) 0))) goto err; /* purecov: inspected */ + mysql_file_seek(file,pos,MY_SEEK_SET,MYF(0)); + if (mysql_file_read(file, forminfo,288,MYF(MY_NABP))) + goto err; share->frm_version= head[2]; /* Check if .frm file created by MySQL 5.0. In this case we want to @@ -827,6 +831,20 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, keynames=(char*) key_part; strpos+= (strmov(keynames, (char *) strpos) - keynames)+1; + //reading index comments + for (keyinfo= share->key_info, i=0; i < keys; i++, keyinfo++) + { + if (keyinfo->flags & HA_USES_COMMENT) + { + keyinfo->comment.length= uint2korr(strpos); + keyinfo->comment.str= strmake_root(&share->mem_root, (char*) strpos+2, + keyinfo->comment.length); + strpos+= 2 + keyinfo->comment.length; + } + DBUG_ASSERT(test(keyinfo->flags & HA_USES_COMMENT) == + (keyinfo->comment.length > 0)); + } + share->reclength = uint2korr((head+16)); if (*(head+26) == 1) share->system= 1; /* one-record-database */ @@ -1007,6 +1025,25 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, } } } + if (forminfo[46] == (uchar)255) + { + //reading long table comment + if (next_chunk + 2 > buff_end) + { + DBUG_PRINT("error", + ("long table comment is not defined in .frm")); + my_free(buff, MYF(0)); + goto err; + } + share->comment.length = uint2korr(next_chunk); + if (! (share->comment.str= strmake_root(&share->mem_root, + (char*)next_chunk + 2, share->comment.length))) + { + my_free(buff, MYF(0)); + goto err; + } + next_chunk+= 2 + share->comment.length; + } my_free(buff, MYF(0)); } share->key_block_size= uint2korr(head+62); @@ -1023,29 +1060,30 @@ static int open_binary_frm(THD *thd, TABLE_SHARE *share, uchar *head, record_offset, MYF(MY_NABP))) goto err; /* purecov: inspected */ - mysql_file_seek(file, pos, MY_SEEK_SET, MYF(0)); - if (mysql_file_read(file, head, 288, MYF(MY_NABP))) - goto err; + mysql_file_seek(file, pos+288, MY_SEEK_SET, MYF(0)); #ifdef HAVE_CRYPTED_FRM if (crypted) { - crypted->decode((char*) head+256,288-256); - if (sint2korr(head+284) != 0) // Should be 0 + crypted->decode((char*) forminfo+256,288-256); + if (sint2korr(forminfo+284) != 0) // Should be 0 goto err; // Wrong password } #endif - share->fields= uint2korr(head+258); - pos= uint2korr(head+260); /* Length of all screens */ - n_length= uint2korr(head+268); - interval_count= uint2korr(head+270); - interval_parts= uint2korr(head+272); - int_length= uint2korr(head+274); - share->null_fields= uint2korr(head+282); - com_length= uint2korr(head+284); - share->comment.length= (int) (head[46]); - share->comment.str= strmake_root(&share->mem_root, (char*) head+47, - share->comment.length); + share->fields= uint2korr(forminfo+258); + pos= uint2korr(forminfo+260); /* Length of all screens */ + n_length= uint2korr(forminfo+268); + interval_count= uint2korr(forminfo+270); + interval_parts= uint2korr(forminfo+272); + int_length= uint2korr(forminfo+274); + share->null_fields= uint2korr(forminfo+282); + com_length= uint2korr(forminfo+284); + if (forminfo[46] != (uchar)255) + { + share->comment.length= (int) (forminfo[46]); + share->comment.str= strmake_root(&share->mem_root, (char*) forminfo+47, + share->comment.length); + } DBUG_PRINT("info",("i_count: %d i_parts: %d index: %d n_length: %d int_length: %d com_length: %d", interval_count,interval_parts, share->keys,n_length,int_length, com_length)); @@ -2437,12 +2475,14 @@ void append_unescaped(String *res, const char *pos, uint length) File create_frm(THD *thd, const char *name, const char *db, const char *table, uint reclength, uchar *fileinfo, - HA_CREATE_INFO *create_info, uint keys) + HA_CREATE_INFO *create_info, uint keys, KEY *key_info) { register File file; ulong length; uchar fill[IO_SIZE]; int create_flags= O_RDWR | O_TRUNC; + ulong key_comment_total_bytes= 0; + uint i; if (create_info->options & HA_LEX_CREATE_TMP_TABLE) create_flags|= O_EXCL | O_NOFOLLOW; @@ -2479,7 +2519,17 @@ File create_frm(THD *thd, const char *name, const char *db, 1 byte for the NAMES_SEP_CHAR (after the last name) 9 extra bytes (padding for safety? alignment?) */ - key_length= keys * (8 + MAX_REF_PARTS * 9 + NAME_LEN + 1) + 16; + for (i= 0; i < keys; i++) + { + DBUG_ASSERT(test(key_info[i].flags & HA_USES_COMMENT) == + (key_info[i].comment.length > 0)); + if (key_info[i].flags & HA_USES_COMMENT) + key_comment_total_bytes += 2 + key_info[i].comment.length; + } + + key_length= keys * (8 + MAX_REF_PARTS * 9 + NAME_LEN + 1) + 16 + + key_comment_total_bytes; + length= next_io_size((ulong) (IO_SIZE+key_length+reclength+ create_info->extra_size)); int4store(fileinfo+10,length); -- cgit v1.2.1