From d8faf3f1798eeea3147fb6cc95d8bd96c3a3878c Mon Sep 17 00:00:00 2001 From: Joerg Bruehe Date: Mon, 14 May 2012 15:15:13 +0200 Subject: [PATCH 01/90] Raise version after cloning 5.5.25 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 6111f6d453f..a6ecc1acc76 100644 --- a/VERSION +++ b/VERSION @@ -1,4 +1,4 @@ MYSQL_VERSION_MAJOR=5 MYSQL_VERSION_MINOR=5 -MYSQL_VERSION_PATCH=25 +MYSQL_VERSION_PATCH=26 MYSQL_VERSION_EXTRA= From e72278fd423d98181d1c4da34e8369e7219b05f8 Mon Sep 17 00:00:00 2001 From: Bjorn Munch Date: Tue, 15 May 2012 09:14:44 +0200 Subject: [PATCH 02/90] Added some extra optional path to test suites --- mysql-test/lib/My/Find.pm | 7 ++++--- mysql-test/lib/mtr_cases.pm | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/mysql-test/lib/My/Find.pm b/mysql-test/lib/My/Find.pm index 0fffc0d7fd7..2730f83a496 100644 --- a/mysql-test/lib/My/Find.pm +++ b/mysql-test/lib/My/Find.pm @@ -126,9 +126,9 @@ sub my_find_file { # # sub my_find_dir { - my ($base, $paths, $dirs, $required)= @_; - croak "usage: my_find_dir(, [, ])" - unless (@_ == 3 or @_ == 2); + my ($base, $paths, $dirs, $optional)= @_; + croak "usage: my_find_dir(, [, [, ]])" + unless (@_ == 3 or @_ == 2 or @_ == 4); # ------------------------------------------------------- # Find and return the first directory @@ -136,6 +136,7 @@ sub my_find_dir { foreach my $path (my_find_paths($base, $paths, $dirs)) { return $path if ( -d $path ); } + return "" if $optional; find_error($base, $paths, $dirs); } diff --git a/mysql-test/lib/mtr_cases.pm b/mysql-test/lib/mtr_cases.pm index 90045d855ab..19eaac6747c 100644 --- a/mysql-test/lib/mtr_cases.pm +++ b/mysql-test/lib/mtr_cases.pm @@ -127,6 +127,7 @@ sub collect_test_cases ($$$) { { push(@$cases, collect_one_suite($suite, $opt_cases)); last if $some_test_found; + push(@$cases, collect_one_suite("i_".$suite, $opt_cases)); } } @@ -277,10 +278,10 @@ sub collect_one_suite($) $suitedir= my_find_dir($suitedir, ["suite", ".", - # Look in storage engine specific suite dirs - "../storage/*/mysql-test-suites" + "../internal/mysql-test/suite" ], - [$suite]); + [$suite], ($suite =~ /^i_/)); + return unless $suitedir; } mtr_verbose("suitedir: $suitedir"); } From fcb033053d72502366f890c4652603c6cbc4fadb Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Tue, 15 May 2012 13:12:22 +0300 Subject: [PATCH 03/90] Bug #11761822: yassl rejects valid certificate which openssl accepts Applied the fix that updates yaSSL to 2.2.1 and fixes parsing this particular certificate. Added a test case with the certificate itself. --- extra/yassl/taocrypt/src/asn.cpp | 4 ++++ vio/viosslfactories.c | 10 ++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/extra/yassl/taocrypt/src/asn.cpp b/extra/yassl/taocrypt/src/asn.cpp index a502666d15b..5ec4cac1c44 100644 --- a/extra/yassl/taocrypt/src/asn.cpp +++ b/extra/yassl/taocrypt/src/asn.cpp @@ -758,6 +758,10 @@ void CertDecoder::GetName(NameType nt) while (source_.get_index() < length) { GetSet(); + if (source_.GetError().What() == SET_E) { + source_.SetError(NO_ERROR_E); // extensions may only have sequence + source_.prev(); + } GetSequence(); byte b = source_.next(); diff --git a/vio/viosslfactories.c b/vio/viosslfactories.c index 3c0c2f3a7ec..945e288a799 100644 --- a/vio/viosslfactories.c +++ b/vio/viosslfactories.c @@ -201,7 +201,7 @@ static void check_ssl_init() static struct st_VioSSLFd * new_VioSSLFd(const char *key_file, const char *cert_file, const char *ca_file, const char *ca_path, - const char *cipher, SSL_METHOD *method, + const char *cipher, my_bool is_client_method, enum enum_ssl_init_error* error) { DH *dh; @@ -222,7 +222,9 @@ new_VioSSLFd(const char *key_file, const char *cert_file, my_malloc(sizeof(struct st_VioSSLFd),MYF(0))))) DBUG_RETURN(0); - if (!(ssl_fd->ssl_context= SSL_CTX_new(method))) + if (!(ssl_fd->ssl_context= SSL_CTX_new(is_client_method ? + TLSv1_client_method() : + TLSv1_server_method()))) { *error= SSL_INITERR_MEMFAIL; DBUG_PRINT("error", ("%s", sslGetErrString(*error))); @@ -300,7 +302,7 @@ new_VioSSLConnectorFd(const char *key_file, const char *cert_file, verify= SSL_VERIFY_NONE; if (!(ssl_fd= new_VioSSLFd(key_file, cert_file, ca_file, - ca_path, cipher, TLSv1_client_method(), &dummy))) + ca_path, cipher, TRUE, &dummy))) { return 0; } @@ -322,7 +324,7 @@ new_VioSSLAcceptorFd(const char *key_file, const char *cert_file, struct st_VioSSLFd *ssl_fd; int verify= SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE; if (!(ssl_fd= new_VioSSLFd(key_file, cert_file, ca_file, - ca_path, cipher, TLSv1_server_method(), error))) + ca_path, cipher, FALSE, error))) { return 0; } From c5dc1ea52654627ac2f6f406a16bc04bead9ed0d Mon Sep 17 00:00:00 2001 From: Olav Sandstaa Date: Wed, 16 May 2012 09:49:23 +0200 Subject: [PATCH 05/90] Fix for Bug#12667154 SAME QUERY EXEC AS WHERE SUBQ GIVES DIFFERENT RESULTS ON IN() & NOT IN() COMP #3 This bug causes a wrong result in mysql-trunk when ICP is used and bad performance in mysql-5.5 and mysql-trunk. Using the query from bug report to explain what happens and causes the wrong result from the query when ICP is enabled: 1. The t3 table contains four records. The outer query will read these and for each of these it will execute the subquery. 2. Before the first execution of the subquery it will be optimized. In this case the important is what happens to the first table t1: -make_join_select() will call the range optimizer which decides that t1 should be accessed using a range scan on the k1 index It creates a QUICK_RANGE_SELECT object for this. -As the last part of optimization the ICP code pushes the condition down to the storage engine for table t1 on the k1 index. This produces the following information in the explain for this table: 2 DEPENDENT SUBQUERY t1 range k1 k1 5 NULL 3 Using index condition; Using filesort Note the use of filesort. 3. The first execution of the subquery does (among other things) due to the need for sorting: a. Call create_sort_index() which again will call find_all_keys(): b. find_all_keys() will read the required keys for all qualifying rows from the storage engine. To do this it checks if it has a quick-select for the table. It will use the quick-select for reading records. In this case it will read four records from the storage engine (based on the range criteria). The storage engine will evaluate the pushed index condition for each record. c. At the end of create_sort_index() there is code that cleans up a lot of stuff on the join tab. One of the things that is cleaned is the select object. The result of this is that the quick-select object created in make_join_select is deleted. 4. The second execution of the subquery does the same as the first but the result is different: a. Call create_sort_index() which again will call find_all_keys() (same as for the first execution) b. find_all_keys() will read the keys from the storage engine. To do this it checks if it has a quick-select for the table. Now there is NO quick-select object(!) (since it was deleted in step 3c). So find_all_keys defaults to read the table using a table scan instead. So instead of reading the four relevant records in the range it reads the entire table (6 records). It then evaluates the table's condition (and here it goes wrong). Since the entire condition has been pushed down to the storage engine using ICP all 6 records qualify. (Note that the storage engine will not evaluate the pushed index condition in this case since it was pushed for the k1 index and now we do a table scan without any index being used). The result is that here we return six qualifying key values instead of four due to not evaluating the table's condition. c. As above. 5. The two last execution of the subquery will also produce wrong results for the same reason. Summary: The problem occurs due to all but the first executions of the subquery is done as a table scan without evaluating the table's condition (which is pushed to the storage engine on a different index). This is caused by the create_sort_index() function deleting the quick-select object that should have been used for executing the subquery as a range scan. Note that this bug in addition to causing wrong results also can result in bad performance due to executing the subquery using a table scan instead of a range scan. This is an issue in MySQL 5.5. The fix for this problem is to avoid that the Quick-select-object that the optimizer created is deleted when create_sort_index() is doing clean-up of the join-tab. This will ensure that the quick-select object and the corresponding pushed index condition will be available and used by all following executions of the subquery. sql/sql_select.cc: Fix for Bug#12667154: Change how create_sort_index() cleans up the join_tab's select and quick-select objects in order to avoid that a quick-select object created outside of create_sort_index() is deleted. --- sql/sql_select.cc | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 3c709e3c0ea..193121c9a95 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -14066,6 +14066,14 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order, table= tab->table; select= tab->select; + /* + If we have a select->quick object that is created outside of + create_sort_index() and this is part of a subquery that + potentially can be executed multiple times then we should not + delete the quick object on exit from this function. + */ + bool keep_quick= select && select->quick && join->join_tab_save; + /* When there is SQL_BIG_RESULT do not sort using index for GROUP BY, and thus force sorting on disk unless a group min-max optimization @@ -14117,6 +14125,7 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order, get_quick_select_for_ref(thd, table, &tab->ref, tab->found_records)))) goto err; + DBUG_ASSERT(!keep_quick); } } @@ -14147,9 +14156,25 @@ create_sort_index(THD *thd, JOIN *join, ORDER *order, tablesort_result_cache= table->sort.io_cache; table->sort.io_cache= NULL; - select->cleanup(); // filesort did select - tab->select= 0; - table->quick_keys.clear_all(); // as far as we cleanup select->quick + /* + If a quick object was created outside of create_sort_index() + that might be reused, then do not call select->cleanup() since + it will delete the quick object. + */ + if (!keep_quick) + { + select->cleanup(); + /* + The select object should now be ready for the next use. If it + is re-used then there exists a backup copy of this join tab + which has the pointer to it. The join tab will be restored in + JOIN::reset(). So here we just delete the pointer to it. + */ + tab->select= NULL; + // If we deleted the quick select object we need to clear quick_keys + table->quick_keys.clear_all(); + } + // Restore the output resultset table->sort.io_cache= tablesort_result_cache; } tab->select_cond=0; From 0e9c1e9fc395f3afe1e6b5a2d758eb42d765ec15 Mon Sep 17 00:00:00 2001 From: Venkata Sidagam Date: Wed, 16 May 2012 13:55:22 +0530 Subject: [PATCH 06/90] Bug #13955256: KEYCACHE CRASHES, CORRUPTIONS/HANGS WITH, FULLTEXT INDEX AND CONCURRENT DML. Problem Statement: ------------------ 1) Create a table with FT index. 2) Enable concurrent inserts. 3) In multiple threads do below operations repeatedly a) truncate table b) insert into table .... c) select ... match .. against .. non-boolean/boolean mode After some time we could observe two different assert core dumps Analysis: -------- 1)assert core dump at key_read_cache(): Two select threads operating in-parallel on same key root block. 1st select thread block->status is set to BLOCK_ERROR because the my_pread() in read_block() is returning '0'. Truncate table made the index file size as 1024 and pread was asked to get the block of count bytes(1024 bytes) from offset of 1024 which it cannot read since its "end of file" and retuning '0' setting "my_errno= HA_ERR_FILE_TOO_SHORT" and the key_file_length, key_root[0] is same i.e. 1024. Since block status has BLOCK_ERROR the 1st select thread enter into the free_block() and will be under wait on conditional mutex by making status as BLOCK_REASSIGNED and goes for wait_on_readers(). Other select thread will also work on the same block and sees the status as BLOCK_ERROR and enters into free_block(), checks for BLOCK_REASSIGNED and asserting the server. 2)assert core dump at key_write_cache(): One select thread and One insert thread. Select thread gets the unlocks the 'keycache->cache_lock', which allows other threads to continue and gets the pread() return value as'0'(please see the explanation above) and tries to get the lock on 'keycache->cache_lock' and waits there for the lock. Insert thread requests for the block, block will be assigned from the hash list and makes the page_status as 'PAGE_WAIT_TO_BE_READ' and goes for the read_block(), waits in the queue since there are some other threads performing reads on the same block. Select thread which was waiting for the 'keycache->cache_lock' mutex in the read_block() will continue after getting the my_pread() value as '0' and sets the block status as BLOCK_ERROR and goes to the free_block() and go to the wait_for_readers(). Now the insert thread will awake and continues. and checks block->status as not BLOCK_READ and it asserts. Fix: --- In the full text code, multiple readers of index file is not guarded. Hence added below below code in _ft2_search() and walk_and_match(). to lock the key_root I have used below code in _ft2_search() if (info->s->concurrent_insert) mysql_rwlock_rdlock(&share->key_root_lock[0]); and to unlock if (info->s->concurrent_insert) mysql_rwlock_unlock(&share->key_root_lock[0]); storage/myisam/ft_boolean_search.c: Since its a recursion function, to avoid confusion in taking and releasing the locks, renamed _ft2_search() to _ft2_search_internal() function. And _ft2_search() will take the lock, call _ft2_search_internal() and release the lock in case of concurrent inserts. storage/myisam/ft_nlq_search.c: Added read locks code in walk_and_match() --- storage/myisam/ft_boolean_search.c | 16 ++++++++++++++-- storage/myisam/ft_nlq_search.c | 18 +++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/storage/myisam/ft_boolean_search.c b/storage/myisam/ft_boolean_search.c index 62d912a0fd0..16cf2669c6d 100644 --- a/storage/myisam/ft_boolean_search.c +++ b/storage/myisam/ft_boolean_search.c @@ -354,7 +354,7 @@ static int _ftb_no_dupes_cmp(void* not_used __attribute__((unused)), returns 1 if the search was finished (must-word wasn't found) */ -static int _ft2_search(FTB *ftb, FTB_WORD *ftbw, my_bool init_search) +static int _ft2_search_no_lock(FTB *ftb, FTB_WORD *ftbw, my_bool init_search) { int r; int subkeys=1; @@ -454,7 +454,7 @@ static int _ft2_search(FTB *ftb, FTB_WORD *ftbw, my_bool init_search) ftbw->key_root=info->s->state.key_root[ftb->keynr]; ftbw->keyinfo=info->s->keyinfo+ftb->keynr; ftbw->off=0; - return _ft2_search(ftb, ftbw, 0); + return _ft2_search_no_lock(ftb, ftbw, 0); } /* matching key found */ @@ -482,6 +482,18 @@ static int _ft2_search(FTB *ftb, FTB_WORD *ftbw, my_bool init_search) return 0; } +static int _ft2_search(FTB *ftb, FTB_WORD *ftbw, my_bool init_search) +{ + int r; + MYISAM_SHARE *share= ftb->info->s; + if (share->concurrent_insert) + rw_rdlock(&share->key_root_lock[ftb->keynr]); + r= _ft2_search_no_lock(ftb, ftbw, init_search); + if (share->concurrent_insert) + rw_unlock(&share->key_root_lock[ftb->keynr]); + return r; +} + static void _ftb_init_index_search(FT_INFO *ftb) { int i; diff --git a/storage/myisam/ft_nlq_search.c b/storage/myisam/ft_nlq_search.c index 333ec5d0b4f..c74451828a4 100644 --- a/storage/myisam/ft_nlq_search.c +++ b/storage/myisam/ft_nlq_search.c @@ -71,9 +71,10 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio) TREE_ELEMENT *selem; double gweight=1; MI_INFO *info=aio->info; + MYISAM_SHARE *share= info->s; uchar *keybuff=aio->keybuff; MI_KEYDEF *keyinfo=info->s->keyinfo+aio->keynr; - my_off_t key_root=info->s->state.key_root[aio->keynr]; + my_off_t key_root; uint extra= HA_FT_WLEN + info->s->rec_reflength; #if HA_FT_WTYPE == HA_KEYTYPE_FLOAT float tmp_weight; @@ -89,6 +90,11 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio) keylen-=HA_FT_WLEN; doc_cnt=0; + if (share->concurrent_insert) + rw_rdlock(&share->key_root_lock[aio->keynr]); + + key_root= share->state.key_root[aio->keynr]; + /* Skip rows inserted by current inserted */ for (r=_mi_search(info, keyinfo, keybuff, keylen, SEARCH_FIND, key_root) ; !r && @@ -98,6 +104,9 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio) info->lastkey_length, SEARCH_BIGGER, key_root)) ; + if (share->concurrent_insert) + rw_unlock(&share->key_root_lock[aio->keynr]); + info->update|= HA_STATE_AKTIV; /* for _mi_test_if_changed() */ /* The following should be safe, even if we compare doubles */ @@ -121,6 +130,8 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio) keyinfo=& info->s->ft2_keyinfo; key_root=info->lastpos; keylen=0; + if (share->concurrent_insert) + rw_rdlock(&share->key_root_lock[aio->keynr]); r=_mi_search_first(info, keyinfo, key_root); goto do_skip; } @@ -155,6 +166,9 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio) if (gweight < 0 || doc_cnt > 2000000) gweight=0; + if (share->concurrent_insert) + rw_rdlock(&share->key_root_lock[aio->keynr]); + if (_mi_test_if_changed(info) == 0) r=_mi_search_next(info, keyinfo, info->lastkey, info->lastkey_length, SEARCH_BIGGER, key_root); @@ -167,6 +181,8 @@ do_skip: r= _mi_search_next(info, keyinfo, info->lastkey, info->lastkey_length, SEARCH_BIGGER, key_root); + if (share->concurrent_insert) + rw_unlock(&share->key_root_lock[aio->keynr]); } word->weight=gweight; From 7a6c449c62ae86872aeef489895e1f016b921da6 Mon Sep 17 00:00:00 2001 From: Annamalai Gurusami Date: Wed, 16 May 2012 15:23:56 +0530 Subject: [PATCH 07/90] Bug #13943231: ALTER TABLE AFTER DISCARD MAY CRASH THE SERVER The following scenario crashes our mysql server: 1. set global innodb_file_per_table=1; 2. create table t1(c1 int) engine=innodb; 3. alter table t1 discard tablespace; 4. alter table t1 add unique index(c1); Step 4 crashes the server. This patch introduces a check on discarded tablespace to avoid the crash. rb://1041 approved by Marko Makela --- storage/innodb_plugin/handler/handler0alter.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/storage/innodb_plugin/handler/handler0alter.cc b/storage/innodb_plugin/handler/handler0alter.cc index e2702b157af..6f02b500d96 100644 --- a/storage/innodb_plugin/handler/handler0alter.cc +++ b/storage/innodb_plugin/handler/handler0alter.cc @@ -665,6 +665,10 @@ ha_innobase::add_index( DBUG_RETURN(HA_ERR_NO_SUCH_TABLE); } + if (innodb_table->tablespace_discarded) { + DBUG_RETURN(-1); + } + /* Check that index keys are sensible */ error = innobase_check_index_keys(key_info, num_of_keys, innodb_table); From 0581d1c46c1bbe3f87ac4cef697af3b75392b815 Mon Sep 17 00:00:00 2001 From: Mayank Prasad Date: Thu, 17 May 2012 22:24:23 +0530 Subject: [PATCH 08/90] Bug#11766101 : 59140: LIKE CONCAT('%',@A,'%') DOESN'T MATCH WHEN @A CONTAINS LATIN1 STRING Issue/Cause: Issue is of memory corruption.During optimization phase, pattern to be matched in where clause, is prepared. This is done in Item_func_concat::val_str() function which forms the resultant string (tmp_value) and return its pointer. In caller, Item_func_like::fix_fields, pattern is made to point to this string (tmp_value). In further processing, tmp_value is getting modified which causes pattern to have changed/wrong values. Fix: Allocate its own memroy location in caller, copy value of resultant string (tmp_value) into that and make pattern to point to that. This makes sure no further changes to tmp_value will affect pattern. --- sql/item_cmpfunc.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index fb9878ccb0a..657bc3ed234 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -4877,8 +4877,8 @@ bool Item_func_like::fix_fields(THD *thd, Item **ref) } if (canDoTurboBM) { - pattern = first + 1; pattern_len = (int) len - 2; + pattern = thd->strmake(first + 1, pattern_len); DBUG_PRINT("info", ("Initializing pattern: '%s'", first)); int *suff = (int*) thd->alloc((int) (sizeof(int)* ((pattern_len + 1)*2+ From 02f90402c8218227c81f86f0b56cd283f7a2eb64 Mon Sep 17 00:00:00 2001 From: Tor Didriksen Date: Fri, 18 May 2012 12:57:38 +0200 Subject: [PATCH 09/90] Bug#14039955 RPAD FUNCTION LEADS TO UNINITIALIZED VALUES WARNING IN MY_STRTOD Rewrite the "parser" in my_strtod_int() to avoid reading past the end of the input string. --- strings/dtoa.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/strings/dtoa.c b/strings/dtoa.c index ef1c141ec44..4086bf412fe 100644 --- a/strings/dtoa.c +++ b/strings/dtoa.c @@ -1416,20 +1416,27 @@ static double my_strtod_int(const char *s00, char **se, int *error, char *buf, s c= *++s; if (!nd) { - for (; s < end && c == '0'; c= *++s) + for (; s < end; ++s) + { + c= *s; + if (c != '0') + break; nz++; + } if (s < end && c > '0' && c <= '9') { s0= s; nf+= nz; nz= 0; - goto have_dig; } - goto dig_done; + else + goto dig_done; } - for (; s < end && c >= '0' && c <= '9'; c = *++s) + for (; s < end; ++s) { - have_dig: + c= *s; + if (c < '0' || c > '9') + break; /* Here we are parsing the fractional part. We can stop counting digits after a while: the extra digits From f436b188e24e35e155497bbcdae7c8b2c97cb2e5 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Tue, 15 May 2012 12:45:52 +0200 Subject: [PATCH 10/90] bug#13949735: crash regression from bug#13694811. There can be cases when the optimizer calls ha_partition::records_in_range when there are no matching partitions. So the DBUG_ASSERT of !tot_used_partitions does assert. Fixed by returning 0 instead when no matching partitions are found. This will avoid the crash. records_in_range will then try to find the biggest used partition, which will not find any partition and records_in_range will then return 0, meaning non rows can be found. Patch contributed by Davi Arnaut at twitter. --- sql/ha_partition.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 5b25bd26298..1debc02d7f2 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -6322,7 +6322,17 @@ ha_rows ha_partition::min_rows_for_estimate() DBUG_ENTER("ha_partition::min_rows_for_estimate"); tot_used_partitions= bitmap_bits_set(&m_part_info->used_partitions); - DBUG_ASSERT(tot_used_partitions); + + /* + All partitions might have been left as unused during partition pruning + due to, for example, an impossible WHERE condition. Nonetheless, the + optimizer might still attempt to perform (e.g. range) analysis where an + estimate of the the number of rows is calculated using records_in_range. + Hence, to handle this and other possible cases, use zero as the minimum + number of rows to base the estimate on if no partition is being used. + */ + if (!tot_used_partitions) + DBUG_RETURN(0); /* Allow O(log2(tot_partitions)) increase in number of used partitions. From 5917c58a5d23e30ed33ca9559ac3a8010d182d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Tue, 15 May 2012 15:04:39 +0300 Subject: [PATCH 11/90] Bug#14025221 FOREIGN KEY REFERENCES FREED MEMORY AFTER DROP INDEX dict_table_replace_index_in_foreign_list(): Replace the dropped index also in the foreign key constraints of child tables that are referencing this table. row_ins_check_foreign_constraint(): If the underlying index is missing, refuse the operation. rb:1051 approved by Jimmy Yang --- storage/innodb_plugin/dict/dict0dict.c | 22 ++++++++++++++++++++++ storage/innodb_plugin/row/row0ins.c | 6 ++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/storage/innodb_plugin/dict/dict0dict.c b/storage/innodb_plugin/dict/dict0dict.c index df7ac85681c..cfeba015723 100644 --- a/storage/innodb_plugin/dict/dict0dict.c +++ b/storage/innodb_plugin/dict/dict0dict.c @@ -4872,6 +4872,28 @@ dict_table_replace_index_in_foreign_list( foreign->foreign_index = new_index; } } + + + for (foreign = UT_LIST_GET_FIRST(table->referenced_list); + foreign; + foreign = UT_LIST_GET_NEXT(referenced_list, foreign)) { + + dict_index_t* new_index; + + if (foreign->referenced_index == index) { + ut_ad(foreign->referenced_table == index->table); + + new_index = dict_foreign_find_index( + foreign->referenced_table, + foreign->referenced_col_names, + foreign->n_fields, index, + /*check_charsets=*/TRUE, /*check_null=*/FALSE); + ut_ad(new_index || !trx->check_foreigns); + ut_ad(!new_index || new_index->table == index->table); + + foreign->referenced_index = new_index; + } + } } /**********************************************************************//** diff --git a/storage/innodb_plugin/row/row0ins.c b/storage/innodb_plugin/row/row0ins.c index 2d4afa6c5ed..4994a91dd23 100644 --- a/storage/innodb_plugin/row/row0ins.c +++ b/storage/innodb_plugin/row/row0ins.c @@ -1296,7 +1296,8 @@ run_again: check_index = foreign->foreign_index; } - if (check_table == NULL || check_table->ibd_file_missing) { + if (check_table == NULL || check_table->ibd_file_missing + || check_index == NULL) { if (check_ref) { FILE* ef = dict_foreign_err_file; @@ -1331,9 +1332,6 @@ run_again: goto exit_func; } - ut_a(check_table); - ut_a(check_index); - if (check_table != table) { /* We already have a LOCK_IX on table, but not necessarily on check_table */ From 5d8b38df4c6166bb7f52d6602c2b7eb48628c233 Mon Sep 17 00:00:00 2001 From: Nuno Carvalho Date: Tue, 15 May 2012 22:06:48 +0100 Subject: [PATCH 12/90] BUG#11754117 - 45670: INTVAR_EVENTS FOR FILTERED-OUT QUERY_LOG_EVENTS ARE EXECUTED Improved random number filtering verification on rpl_filter_tables_not_exist test. --- .../rpl/r/rpl_filter_tables_not_exist.result | 9 +++++---- .../rpl/t/rpl_filter_tables_not_exist.test | 17 +++++++++-------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_filter_tables_not_exist.result b/mysql-test/suite/rpl/r/rpl_filter_tables_not_exist.result index f0dc97b71f2..e11c54499fe 100644 --- a/mysql-test/suite/rpl/r/rpl_filter_tables_not_exist.result +++ b/mysql-test/suite/rpl/r/rpl_filter_tables_not_exist.result @@ -114,17 +114,17 @@ id c 3 3 [on master] drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; -CREATE TABLE test.t5 (a INT AUTO_INCREMENT PRIMARY KEY, b INT, c INT); +CREATE TABLE test.t5 (a INT AUTO_INCREMENT PRIMARY KEY, b DECIMAL(20,20), c INT); CREATE TABLE test.t1 (a INT); INSERT INTO test.t1 VALUES(1); call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); -CREATE TABLE test.t_slave (a INT AUTO_INCREMENT PRIMARY KEY, b INT, c INT); +CREATE TABLE test.t_slave (a INT AUTO_INCREMENT PRIMARY KEY, b DECIMAL(20,20), c INT); CREATE TRIGGER t1_update AFTER UPDATE ON test.t1 FOR EACH ROW -INSERT INTO test.t_slave VALUES(NULL, ROUND(RAND() * 1000), @c); +INSERT INTO test.t_slave VALUES(NULL, RAND(), @c); SET INSERT_ID=2; SET @c=2; SET @@rand_seed1=10000000, @@rand_seed2=1000000; -INSERT INTO t5 VALUES (NULL, ROUND(RAND() * 1000), @c); +INSERT INTO t5 VALUES (NULL, RAND(), @c); Warnings: Note 1592 Statement may not be safe to log in statement format. SELECT b into @b FROM test.t5; @@ -132,6 +132,7 @@ UPDATE test.t1 SET a=2; SELECT a AS 'ONE' into @a FROM test.t_slave; SELECT c AS 'NULL' into @c FROM test.t_slave; SELECT b into @b FROM test.t_slave; +include/assert.inc [Random values from master and slave must be different] drop table test.t5; drop table test.t1; drop table test.t_slave; diff --git a/mysql-test/suite/rpl/t/rpl_filter_tables_not_exist.test b/mysql-test/suite/rpl/t/rpl_filter_tables_not_exist.test index b62a6e96437..3572dd53ea7 100644 --- a/mysql-test/suite/rpl/t/rpl_filter_tables_not_exist.test +++ b/mysql-test/suite/rpl/t/rpl_filter_tables_not_exist.test @@ -215,21 +215,23 @@ drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; # be filtered as well. # connection master; -CREATE TABLE test.t5 (a INT AUTO_INCREMENT PRIMARY KEY, b INT, c INT); # ignored on slave +# Although RAND() is from 0 to 1.0, DECIMAL(M,D), requires that M must be >= D. +CREATE TABLE test.t5 (a INT AUTO_INCREMENT PRIMARY KEY, b DECIMAL(20,20), c INT); # ignored on slave CREATE TABLE test.t1 (a INT); # accepted on slave INSERT INTO test.t1 VALUES(1); --sync_slave_with_master call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); -CREATE TABLE test.t_slave (a INT AUTO_INCREMENT PRIMARY KEY, b INT, c INT); +# Although RAND() is from 0 to 1.0, DECIMAL(M,D), requires that M must be >= D. +CREATE TABLE test.t_slave (a INT AUTO_INCREMENT PRIMARY KEY, b DECIMAL(20,20), c INT); CREATE TRIGGER t1_update AFTER UPDATE ON test.t1 FOR EACH ROW - INSERT INTO test.t_slave VALUES(NULL, ROUND(RAND() * 1000), @c); + INSERT INTO test.t_slave VALUES(NULL, RAND(), @c); connection master; SET INSERT_ID=2; SET @c=2; SET @@rand_seed1=10000000, @@rand_seed2=1000000; -INSERT INTO t5 VALUES (NULL, ROUND(RAND() * 1000), @c); # to be ignored +INSERT INTO t5 VALUES (NULL, RAND(), @c); # to be ignored SELECT b into @b FROM test.t5; --let $b_master=`select @b` UPDATE test.t1 SET a=2; # to run trigger on slave @@ -253,10 +255,9 @@ if (`SELECT @a != 2 and @c != NULL`) SELECT b into @b FROM test.t_slave; --let $b_slave=`select @b` -if (`SELECT $b_slave = $b_master`) -{ - --echo Might be pure coincidence of two randoms from master and slave table. Don not panic yet. -} +--let $assert_text= Random values from master and slave must be different +--let $assert_cond= $b_master != $b_slave +--source include/assert.inc # cleanup BUG#11754117 connection master; From bcb5d73767fbc04c88d3c8b05eafbdc9a905ea1f Mon Sep 17 00:00:00 2001 From: Annamalai Gurusami Date: Wed, 16 May 2012 11:17:48 +0530 Subject: [PATCH 13/90] Bug #12752572 61579: REPLICATION FAILURE WHILE INNODB_AUTOINC_LOCK_MODE=1 AND USING TRIGGER When an insert stmt like "insert into t values (1),(2),(3)" is executed, the autoincrement values assigned to these three rows are expected to be contiguous. In the given lock mode (innodb_autoinc_lock_mode=1), the auto inc lock will be released before the end of the statement. So to make the autoincrement contiguous for a given statement, we need to reserve the auto inc values at the beginning of the statement. rb://1074 approved by Alexander Nozdrin --- sql/handler.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/sql/handler.cc b/sql/handler.cc index d2eaab19ad8..20bf2355c25 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -2397,6 +2397,17 @@ int handler::update_auto_increment() reservation means potentially losing unused values). Note that in prelocked mode no estimation is given. */ + + /* + For multi-row inserts, if the bulk inserts cannot be started, the + handler::estimation_rows_to_insert will not be set. Set it here. + */ + if ((estimation_rows_to_insert == 0) && + (thd->lex->many_values.elements > 0)) + { + estimation_rows_to_insert= thd->lex->many_values.elements; + } + if ((auto_inc_intervals_count == 0) && (estimation_rows_to_insert > 0)) nb_desired_values= estimation_rows_to_insert; else /* go with the increasing defaults */ @@ -4690,6 +4701,8 @@ int handler::ha_write_row(uchar *buf) DBUG_RETURN(error); if (unlikely(error= binlog_log_row(table, 0, buf, log_func))) DBUG_RETURN(error); /* purecov: inspected */ + + DEBUG_SYNC_C("ha_write_row_end"); DBUG_RETURN(0); } From 6b05e434bff43365add2a9636edbace157c84e89 Mon Sep 17 00:00:00 2001 From: Venkata Sidagam Date: Wed, 16 May 2012 16:14:27 +0530 Subject: [PATCH 14/90] Bug #13955256: KEYCACHE CRASHES, CORRUPTIONS/HANGS WITH, FULLTEXT INDEX AND CONCURRENT DML. Problem Statement: ------------------ 1) Create a table with FT index. 2) Enable concurrent inserts. 3) In multiple threads do below operations repeatedly a) truncate table b) insert into table .... c) select ... match .. against .. non-boolean/boolean mode After some time we could observe two different assert core dumps Analysis: -------- 1)assert core dump at key_read_cache(): Two select threads operating in-parallel on same key root block. 1st select thread block->status is set to BLOCK_ERROR because the my_pread() in read_block() is returning '0'. Truncate table made the index file size as 1024 and pread was asked to get the block of count bytes(1024 bytes) from offset of 1024 which it cannot read since its "end of file" and retuning '0' setting "my_errno= HA_ERR_FILE_TOO_SHORT" and the key_file_length, key_root[0] is same i.e. 1024. Since block status has BLOCK_ERROR the 1st select thread enter into the free_block() and will be under wait on conditional mutex by making status as BLOCK_REASSIGNED and goes for wait_on_readers(). Other select thread will also work on the same block and sees the status as BLOCK_ERROR and enters into free_block(), checks for BLOCK_REASSIGNED and asserting the server. 2)assert core dump at key_write_cache(): One select thread and One insert thread. Select thread gets the unlocks the 'keycache->cache_lock', which allows other threads to continue and gets the pread() return value as'0'(please see the explanation above) and tries to get the lock on 'keycache->cache_lock' and waits there for the lock. Insert thread requests for the block, block will be assigned from the hash list and makes the page_status as 'PAGE_WAIT_TO_BE_READ' and goes for the read_block(), waits in the queue since there are some other threads performing reads on the same block. Select thread which was waiting for the 'keycache->cache_lock' mutex in the read_block() will continue after getting the my_pread() value as '0' and sets the block status as BLOCK_ERROR and goes to the free_block() and go to the wait_for_readers(). Now the insert thread will awake and continues. and checks block->status as not BLOCK_READ and it asserts. Fix: --- In the full text code, multiple readers of index file is not guarded. Hence added below below code in _ft2_search() and walk_and_match(). to lock the key_root I have used below code in _ft2_search() if (info->s->concurrent_insert) mysql_rwlock_rdlock(&share->key_root_lock[0]); and to unlock if (info->s->concurrent_insert) mysql_rwlock_unlock(&share->key_root_lock[0]); storage/myisam/ft_boolean_search.c: Since its a recursion function, to avoid confusion in taking and releasing the locks, renamed _ft2_search() to _ft2_search_internal() function. And _ft2_search() will take the lock, call _ft2_search_internal() and release the lock in case of concurrent inserts. storage/myisam/ft_nlq_search.c: Added read locks code in walk_and_match() --- storage/myisam/ft_boolean_search.c | 16 ++++++++++++++-- storage/myisam/ft_nlq_search.c | 18 +++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/storage/myisam/ft_boolean_search.c b/storage/myisam/ft_boolean_search.c index 62d912a0fd0..16cf2669c6d 100644 --- a/storage/myisam/ft_boolean_search.c +++ b/storage/myisam/ft_boolean_search.c @@ -354,7 +354,7 @@ static int _ftb_no_dupes_cmp(void* not_used __attribute__((unused)), returns 1 if the search was finished (must-word wasn't found) */ -static int _ft2_search(FTB *ftb, FTB_WORD *ftbw, my_bool init_search) +static int _ft2_search_no_lock(FTB *ftb, FTB_WORD *ftbw, my_bool init_search) { int r; int subkeys=1; @@ -454,7 +454,7 @@ static int _ft2_search(FTB *ftb, FTB_WORD *ftbw, my_bool init_search) ftbw->key_root=info->s->state.key_root[ftb->keynr]; ftbw->keyinfo=info->s->keyinfo+ftb->keynr; ftbw->off=0; - return _ft2_search(ftb, ftbw, 0); + return _ft2_search_no_lock(ftb, ftbw, 0); } /* matching key found */ @@ -482,6 +482,18 @@ static int _ft2_search(FTB *ftb, FTB_WORD *ftbw, my_bool init_search) return 0; } +static int _ft2_search(FTB *ftb, FTB_WORD *ftbw, my_bool init_search) +{ + int r; + MYISAM_SHARE *share= ftb->info->s; + if (share->concurrent_insert) + rw_rdlock(&share->key_root_lock[ftb->keynr]); + r= _ft2_search_no_lock(ftb, ftbw, init_search); + if (share->concurrent_insert) + rw_unlock(&share->key_root_lock[ftb->keynr]); + return r; +} + static void _ftb_init_index_search(FT_INFO *ftb) { int i; diff --git a/storage/myisam/ft_nlq_search.c b/storage/myisam/ft_nlq_search.c index 333ec5d0b4f..c74451828a4 100644 --- a/storage/myisam/ft_nlq_search.c +++ b/storage/myisam/ft_nlq_search.c @@ -71,9 +71,10 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio) TREE_ELEMENT *selem; double gweight=1; MI_INFO *info=aio->info; + MYISAM_SHARE *share= info->s; uchar *keybuff=aio->keybuff; MI_KEYDEF *keyinfo=info->s->keyinfo+aio->keynr; - my_off_t key_root=info->s->state.key_root[aio->keynr]; + my_off_t key_root; uint extra= HA_FT_WLEN + info->s->rec_reflength; #if HA_FT_WTYPE == HA_KEYTYPE_FLOAT float tmp_weight; @@ -89,6 +90,11 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio) keylen-=HA_FT_WLEN; doc_cnt=0; + if (share->concurrent_insert) + rw_rdlock(&share->key_root_lock[aio->keynr]); + + key_root= share->state.key_root[aio->keynr]; + /* Skip rows inserted by current inserted */ for (r=_mi_search(info, keyinfo, keybuff, keylen, SEARCH_FIND, key_root) ; !r && @@ -98,6 +104,9 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio) info->lastkey_length, SEARCH_BIGGER, key_root)) ; + if (share->concurrent_insert) + rw_unlock(&share->key_root_lock[aio->keynr]); + info->update|= HA_STATE_AKTIV; /* for _mi_test_if_changed() */ /* The following should be safe, even if we compare doubles */ @@ -121,6 +130,8 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio) keyinfo=& info->s->ft2_keyinfo; key_root=info->lastpos; keylen=0; + if (share->concurrent_insert) + rw_rdlock(&share->key_root_lock[aio->keynr]); r=_mi_search_first(info, keyinfo, key_root); goto do_skip; } @@ -155,6 +166,9 @@ static int walk_and_match(FT_WORD *word, uint32 count, ALL_IN_ONE *aio) if (gweight < 0 || doc_cnt > 2000000) gweight=0; + if (share->concurrent_insert) + rw_rdlock(&share->key_root_lock[aio->keynr]); + if (_mi_test_if_changed(info) == 0) r=_mi_search_next(info, keyinfo, info->lastkey, info->lastkey_length, SEARCH_BIGGER, key_root); @@ -167,6 +181,8 @@ do_skip: r= _mi_search_next(info, keyinfo, info->lastkey, info->lastkey_length, SEARCH_BIGGER, key_root); + if (share->concurrent_insert) + rw_unlock(&share->key_root_lock[aio->keynr]); } word->weight=gweight; From ce9e6b5a9a8b10ec9b09ea4349c811cdff2ab95f Mon Sep 17 00:00:00 2001 From: Annamalai Gurusami Date: Wed, 16 May 2012 16:36:49 +0530 Subject: [PATCH 15/90] Bug #13943231: ALTER TABLE AFTER DISCARD MAY CRASH THE SERVER The following scenario crashes our mysql server: 1. set global innodb_file_per_table=1; 2. create table t1(c1 int) engine=innodb; 3. alter table t1 discard tablespace; 4. alter table t1 add unique index(c1); Step 4 crashes the server. This patch introduces a check on discarded tablespace to avoid the crash. rb://1041 approved by Marko Makela --- storage/innodb_plugin/handler/handler0alter.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/storage/innodb_plugin/handler/handler0alter.cc b/storage/innodb_plugin/handler/handler0alter.cc index e2702b157af..6f02b500d96 100644 --- a/storage/innodb_plugin/handler/handler0alter.cc +++ b/storage/innodb_plugin/handler/handler0alter.cc @@ -665,6 +665,10 @@ ha_innobase::add_index( DBUG_RETURN(HA_ERR_NO_SUCH_TABLE); } + if (innodb_table->tablespace_discarded) { + DBUG_RETURN(-1); + } + /* Check that index keys are sensible */ error = innobase_check_index_keys(key_info, num_of_keys, innodb_table); From 21faded51e8389d72cc1a729a5e40a5e41aa4540 Mon Sep 17 00:00:00 2001 From: Gopal Shankar Date: Thu, 17 May 2012 18:07:59 +0530 Subject: [PATCH 18/90] Bug#12636001 : deadlock from thd_security_context PROBLEM: Threads end-up in deadlock due to locks acquired as described below, con1: Run Query on a table. It is important that this SELECT must back-off while trying to open the t1 and enter into wait_for_condition(). The SELECT then is blocked trying to lock mysys_var->mutex which is held by con3. The very significant fact here is that mysys_var->current_mutex will still point to LOCK_open, even if LOCK_open is no longer held by con1 at this point. con2: Try dropping table used in con1 or query some table. It will hold LOCK_open and be blocked trying to lock kernel_mutex held by con4. con3: Try killing the query run by con1. It will hold THD::LOCK_thd_data belonging to con1 while trying to lock mysys_var->current_mutex belonging to con1. But current_mutex will point to LOCK_open which is held by con2. con4: Get innodb engine status It will hold kernel_mutex, trying to lock THD::LOCK_thd_data belonging to con1 which is held by con3. So while technically only con2, con3 and con4 participate in the deadlock, con1's mysys_var->current_mutex pointing to LOCK_open is a vital component of the deadlock. CYCLE = (THD::LOCK_thd_data -> LOCK_open -> kernel_mutex -> THD::LOCK_thd_data) FIX: LOCK_thd_data has responsibility of protecting, 1) thd->query, thd->query_length 2) VIO 3) thd->mysys_var (used by KILL statement and shutdown) 4) THD during thread delete. Among above responsibilities, 1), 2)and (3,4) seems to be three independent group of responsibility. If there is different LOCK owning responsibility of (3,4), the above mentioned deadlock cycle can be avoid. This fix introduces LOCK_thd_kill to handle responsibility (3,4), which eliminates the deadlock issue. Note: The problem is not found in 5.5. Introduction MDL subsystem caused metadata locking responsibility to be moved from TDC/TC to MDL subsystem. Due to this, responsibility of LOCK_open is reduced. As the use of LOCK_open is removed in open_table() and mysql_rm_table() the above mentioned CYCLE does not form. Revision ID for changes, open_table() = dlenev@mysql.com-20100727133458-m3ua9oslnx8fbbvz mysql_rm_table() = jon.hauglid@oracle.com-20101116100012-kxep9txz2fxy3nmw --- sql/event_scheduler.cc | 4 ++-- sql/slave.cc | 4 ++-- sql/sql_base.cc | 2 ++ sql/sql_class.cc | 13 +++++++++++-- sql/sql_class.h | 16 ++++++++++++++-- sql/sql_parse.cc | 5 +++-- sql/sql_repl.cc | 4 ++-- 7 files changed, 36 insertions(+), 12 deletions(-) diff --git a/sql/event_scheduler.cc b/sql/event_scheduler.cc index a24c70a8494..d217d8d76cd 100755 --- a/sql/event_scheduler.cc +++ b/sql/event_scheduler.cc @@ -632,13 +632,13 @@ Event_scheduler::stop() DBUG_PRINT("info", ("Scheduler thread has id %lu", scheduler_thd->thread_id)); /* Lock from delete */ - pthread_mutex_lock(&scheduler_thd->LOCK_thd_data); + pthread_mutex_lock(&scheduler_thd->LOCK_thd_kill); /* This will wake up the thread if it waits on Queue's conditional */ sql_print_information("Event Scheduler: Killing the scheduler thread, " "thread id %lu", scheduler_thd->thread_id); scheduler_thd->awake(THD::KILL_CONNECTION); - pthread_mutex_unlock(&scheduler_thd->LOCK_thd_data); + pthread_mutex_unlock(&scheduler_thd->LOCK_thd_kill); /* thd could be 0x0, when shutting down */ sql_print_information("Event Scheduler: " diff --git a/sql/slave.cc b/sql/slave.cc index 0910d196583..437762cc318 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -515,7 +515,7 @@ terminate_slave_thread(THD *thd, int error; DBUG_PRINT("loop", ("killing slave thread")); - pthread_mutex_lock(&thd->LOCK_thd_data); + pthread_mutex_lock(&thd->LOCK_thd_kill); #ifndef DONT_USE_THR_ALARM /* Error codes from pthread_kill are: @@ -526,7 +526,7 @@ terminate_slave_thread(THD *thd, DBUG_ASSERT(err != EINVAL); #endif thd->awake(THD::NOT_KILLED); - pthread_mutex_unlock(&thd->LOCK_thd_data); + pthread_mutex_unlock(&thd->LOCK_thd_kill); /* There is a small chance that slave thread might miss the first diff --git a/sql/sql_base.cc b/sql/sql_base.cc index ca24830db63..2ce5ec81917 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2203,6 +2203,8 @@ void wait_for_condition(THD *thd, pthread_mutex_t *mutex, pthread_cond_t *cond) */ pthread_mutex_unlock(mutex); + DEBUG_SYNC(thd, "waiting_for_table_unlock"); + DBUG_EXECUTE_IF("sleep_after_waiting_for_table", my_sleep(1000000);); pthread_mutex_lock(&thd->mysys_var->mutex); thd->mysys_var->current_mutex= 0; thd->mysys_var->current_cond= 0; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 2f3e8153cbd..0f6bd4c1954 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -365,6 +365,7 @@ extern "C" char *thd_security_context(THD *thd, char *buffer, unsigned int length, unsigned int max_query_len) { + DEBUG_SYNC(thd, "thd_security_context"); String str(buffer, length, &my_charset_latin1); const Security_context *sctx= &thd->main_security_ctx; char header[64]; @@ -695,6 +696,7 @@ THD::THD() active_vio = 0; #endif pthread_mutex_init(&LOCK_thd_data, MY_MUTEX_INIT_FAST); + pthread_mutex_init(&LOCK_thd_kill, MY_MUTEX_INIT_FAST); /* Variables with default values */ proc_info="login"; @@ -999,6 +1001,8 @@ THD::~THD() /* Ensure that no one is using THD */ pthread_mutex_lock(&LOCK_thd_data); pthread_mutex_unlock(&LOCK_thd_data); + pthread_mutex_lock(&LOCK_thd_kill); + pthread_mutex_unlock(&LOCK_thd_kill); add_to_status(&global_status_var, &status_var); /* Close connection */ @@ -1026,6 +1030,7 @@ THD::~THD() #endif mysys_var=0; // Safety (shouldn't be needed) pthread_mutex_destroy(&LOCK_thd_data); + pthread_mutex_destroy(&LOCK_thd_kill); #ifndef DBUG_OFF dbug_sentry= THD_SENTRY_GONE; #endif @@ -1104,9 +1109,11 @@ void add_diff_to_status(STATUS_VAR *to_var, STATUS_VAR *from_var, void THD::awake(THD::killed_state state_to_set) { DBUG_ENTER("THD::awake"); - DBUG_PRINT("enter", ("this: 0x%lx", (long) this)); + DBUG_PRINT("enter", ("this: 0x%lx thread_id=%lu killed_state=%d", + (long) this, thread_id, state_to_set)); THD_CHECK_SENTRY(this); - safe_mutex_assert_owner(&LOCK_thd_data); + safe_mutex_assert_not_owner(&LOCK_thd_data); + safe_mutex_assert_owner(&LOCK_thd_kill); killed= state_to_set; if (state_to_set != THD::KILL_QUERY) @@ -1127,7 +1134,9 @@ void THD::awake(THD::killed_state state_to_set) hack is not used. */ + pthread_mutex_lock(&LOCK_thd_data); close_active_vio(); + pthread_mutex_unlock(&LOCK_thd_data); } #endif } diff --git a/sql/sql_class.h b/sql/sql_class.h index 31d2c664aae..3ecf032db71 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1342,11 +1342,23 @@ public: Protects THD data accessed from other threads: - thd->query and thd->query_length (used by SHOW ENGINE INNODB STATUS and SHOW PROCESSLIST - - thd->mysys_var (used by KILL statement and shutdown). - Is locked when THD is deleted. */ pthread_mutex_t LOCK_thd_data; + /** + - Protects thd->mysys_var (used during KILL statement and shutdown). + - Is Locked when THD is deleted. + + Note: This responsibility was earlier handled by LOCK_thd_data. + This lock is introduced to solve a deadlock issue waiting for + LOCK_thd_data. As this lock reduces responsibility of LOCK_thd_data + the deadlock issues is solved. + Caution: LOCK_thd_kill should not be taken while holding LOCK_thd_data. + THD::awake() currently takes LOCK_thd_data after holding + LOCK_thd_kill. + */ + pthread_mutex_t LOCK_thd_kill; + /* all prepared statements and cursors of this connection */ Statement_map stmt_map; /* diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 729a963eef1..6c376d2c0da 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -7187,7 +7187,7 @@ uint kill_one_thread(THD *thd, ulong id, bool only_kill_query) continue; if (tmp->thread_id == id) { - pthread_mutex_lock(&tmp->LOCK_thd_data); // Lock from delete + pthread_mutex_lock(&tmp->LOCK_thd_kill); // Lock from delete break; } } @@ -7215,12 +7215,13 @@ uint kill_one_thread(THD *thd, ulong id, bool only_kill_query) if ((thd->security_ctx->master_access & SUPER_ACL) || thd->security_ctx->user_matches(tmp->security_ctx)) { + DEBUG_SYNC(thd, "kill_one_thread_before_kill"); tmp->awake(only_kill_query ? THD::KILL_QUERY : THD::KILL_CONNECTION); error=0; } else error=ER_KILL_DENIED_ERROR; - pthread_mutex_unlock(&tmp->LOCK_thd_data); + pthread_mutex_unlock(&tmp->LOCK_thd_kill); } DBUG_PRINT("exit", ("%d", error)); DBUG_RETURN(error); diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index b985805a827..c92d2db2c1e 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -1133,7 +1133,7 @@ void kill_zombie_dump_threads(uint32 slave_server_id) if (tmp->command == COM_BINLOG_DUMP && tmp->server_id == slave_server_id) { - pthread_mutex_lock(&tmp->LOCK_thd_data); // Lock from delete + pthread_mutex_lock(&tmp->LOCK_thd_kill); // Lock from delete break; } } @@ -1146,7 +1146,7 @@ void kill_zombie_dump_threads(uint32 slave_server_id) again. We just to do kill the thread ourselves. */ tmp->awake(THD::KILL_QUERY); - pthread_mutex_unlock(&tmp->LOCK_thd_data); + pthread_mutex_unlock(&tmp->LOCK_thd_kill); } } From 781137c0dddc3c9315a8d40e579fe82f6a900d61 Mon Sep 17 00:00:00 2001 From: Rohit Kalhans Date: Fri, 18 May 2012 14:44:40 +0530 Subject: [PATCH 19/90] BUG#14005409 - 64624 Problem: After the fix for Bug#12589870, a new field that stores the length of db name was added in the buffer that stores the query to be executed. Unlike for the plain user session, the replication execution did not allocate the necessary chunk in Query-event constructor. This caused an invalid read while accessing this field. Solution: We fix this problem by allocating a necessary chunk in the buffer created in the Query_log_event::Query_log_event() and store the length of database name. sql/log_event.cc: Added a new field in the buffer created in the Query_log_event's constructor and store the length of database name. --- sql/log_event.cc | 50 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/sql/log_event.cc b/sql/log_event.cc index 8606964113c..afcc283a6d1 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -2835,24 +2835,34 @@ Query_log_event::Query_log_event(const char* buf, uint event_len, pos= (const uchar*) end; // Break loop } } - + + /** + Layout for the data buffer is as follows + +--------+-----------+------+------+---------+----+-------+ + | catlog | time_zone | user | host | db name | \0 | Query | + +--------+-----------+------+------+---------+----+-------+ + + To support the query cache we append the following buffer to the above + +-------+----------------------------------------+-------+ + |db len | uninitiatlized space of size of db len | FLAGS | + +-------+----------------------------------------+-------+ + + The area of buffer starting from Query field all the way to the end belongs + to the Query buffer and its structure is described in alloc_query() in + sql_parse.cc + */ + + if (!(start= data_buf = (Log_event::Byte*) my_malloc(catalog_len + 1 + + time_zone_len + 1 + + user.length + 1 + + host.length + 1 + + data_len + 1 #if !defined(MYSQL_CLIENT) && defined(HAVE_QUERY_CACHE) - if (!(start= data_buf = (Log_event::Byte*) my_malloc(catalog_len + 1 + - time_zone_len + 1 + - data_len + 1 + - QUERY_CACHE_FLAGS_SIZE + - user.length + 1 + - host.length + 1 + - db_len + 1, - MYF(MY_WME)))) -#else - if (!(start= data_buf = (Log_event::Byte*) my_malloc(catalog_len + 1 + - time_zone_len + 1 + - data_len + 1 + - user.length + 1 + - host.length + 1, - MYF(MY_WME)))) + + sizeof(size_t)//for db_len + + db_len + 1 + + QUERY_CACHE_FLAGS_SIZE #endif + , MYF(MY_WME)))) DBUG_VOID_RETURN; if (catalog_len) // If catalog is given { @@ -2891,6 +2901,14 @@ Query_log_event::Query_log_event(const char* buf, uint event_len, db= (char *)start; query= (char *)(start + db_len + 1); q_len= data_len - db_len -1; + /** + Append the db length at the end of the buffer. This will be used by + Query_cache::send_result_to_client() in case the query cache is On. + */ +#if !defined(MYSQL_CLIENT) && defined(HAVE_QUERY_CACHE) + size_t db_length= (size_t)db_len; + memcpy(start + data_len + 1, &db_length, sizeof(size_t)); +#endif DBUG_VOID_RETURN; } From 1605b7f68f30038ea0a9ce16e688f5827057f64f Mon Sep 17 00:00:00 2001 From: Manish Kumar Date: Mon, 21 May 2012 12:57:39 +0530 Subject: [PATCH 20/90] BUG#12400221 - 60926: BINARY LOG EVENTS LARGER THAN MAX_ALLOWED_PACKET Problem ======== SQL statements close to the size of max_allowed_packet produce binary log events larger than max_allowed_packet. The reason why this failure is occuring is because the event length is more than the total size of the max_allowed_packet + max_event_header length. Now since the event length exceeds this size master Dump thread is unable to send the packet on to the slave. That can happen e.g with row-based replication in Update_rows event. Fix ==== The problem was fixed by increasing the max_allowed_packet for the slave's threads (IO/SQL) by increasing it to 1GB. This is done using the new server option included which is used to regulate the max_allowed_packet of the slave thread (IO/SQL). This causes the large packets to be received by the slave and apply it successfully. sql/log_event.h: Added the new option in the log_event.h file. sql/mysqld.cc: Added a new option to the server. sql/slave.cc: Increasing the session max_allowed_packet to a large value , i.e. not taking global(max_allowed) into consideration, for the slave's threads. --- mysql-test/suite/rpl/r/rpl_log_pos.result | 2 +- mysql-test/suite/rpl/r/rpl_packet.result | 11 +- mysql-test/suite/rpl/t/rpl_packet-slave.opt | 2 +- mysql-test/suite/rpl/t/rpl_packet.test | 11 +- .../inc/slave_max_allowed_packet_basic.inc | 177 ++++++++++++++++++ .../r/max_allowed_packet_basic.result | 12 ++ .../sys_vars/r/max_allowed_packet_func.result | 2 + .../sys_vars/r/net_buffer_length_basic.result | 2 + .../t/slave_max_allowed_packet_basic.test | 3 + sql/log_event.cc | 2 +- sql/log_event.h | 7 + sql/mysql_priv.h | 1 + sql/mysqld.cc | 7 + sql/set_var.cc | 2 + sql/share/errmsg.txt | 34 ++-- sql/slave.cc | 11 +- sql/sql_repl.cc | 2 +- 17 files changed, 252 insertions(+), 36 deletions(-) create mode 100644 mysql-test/suite/sys_vars/inc/slave_max_allowed_packet_basic.inc create mode 100644 mysql-test/suite/sys_vars/t/slave_max_allowed_packet_basic.test diff --git a/mysql-test/suite/rpl/r/rpl_log_pos.result b/mysql-test/suite/rpl/r/rpl_log_pos.result index 91d307008f0..b2224dcd725 100644 --- a/mysql-test/suite/rpl/r/rpl_log_pos.result +++ b/mysql-test/suite/rpl/r/rpl_log_pos.result @@ -9,7 +9,7 @@ change master to master_log_pos=MASTER_LOG_POS; Read_Master_Log_Pos = '75' start slave; include/wait_for_slave_io_error.inc [errno=1236] -Last_IO_Error = 'Got fatal error 1236 from master when reading data from binary log: 'log event entry exceeded max_allowed_packet; Increase max_allowed_packet on master'' +Last_IO_Error = 'Got fatal error 1236 from master when reading data from binary log: 'binlog truncated in the middle of event'' include/stop_slave_sql.inc show master status; File Position Binlog_Do_DB Binlog_Ignore_DB diff --git a/mysql-test/suite/rpl/r/rpl_packet.result b/mysql-test/suite/rpl/r/rpl_packet.result index 7a7f8141ac8..6d68a094594 100644 --- a/mysql-test/suite/rpl/r/rpl_packet.result +++ b/mysql-test/suite/rpl/r/rpl_packet.result @@ -1,7 +1,7 @@ include/master-slave.inc [connection master] -call mtr.add_suppression("Slave I/O: Got a packet bigger than 'max_allowed_packet' bytes, Error_code: 1153"); -call mtr.add_suppression("Slave I/O: Got fatal error 1236 from master when reading data from binary log:"); +call mtr.add_suppression("Slave I/O: Got a packet bigger than 'slave_max_allowed_packet' bytes, Error_code: 1153"); +call mtr.add_suppression("Log entry on master is longer than slave_max_allowed_packet"); drop database if exists DB_NAME_OF_MAX_LENGTH_AKA_NAME_LEN_64_BYTES_____________________; create database DB_NAME_OF_MAX_LENGTH_AKA_NAME_LEN_64_BYTES_____________________; SET @@global.max_allowed_packet=1024; @@ -30,14 +30,14 @@ include/start_slave.inc CREATE TABLE `t1` (`f1` LONGTEXT) ENGINE=MyISAM; INSERT INTO `t1`(`f1`) VALUES ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa2048'); include/wait_for_slave_io_error.inc [errno=1153] -Last_IO_Error = 'Got a packet bigger than 'max_allowed_packet' bytes' +Last_IO_Error = 'Got a packet bigger than 'slave_max_allowed_packet' bytes' include/stop_slave_sql.inc include/rpl_reset.inc DROP TABLE t1; CREATE TABLE t1 (f1 int PRIMARY KEY, f2 LONGTEXT, f3 LONGTEXT) ENGINE=MyISAM; INSERT INTO t1(f1, f2, f3) VALUES(1, REPEAT('a', @@global.max_allowed_packet), REPEAT('b', @@global.max_allowed_packet)); -include/wait_for_slave_io_error.inc [errno=1236] -Last_IO_Error = 'Got fatal error 1236 from master when reading data from binary log: 'log event entry exceeded max_allowed_packet; Increase max_allowed_packet on master'' +include/wait_for_slave_io_error.inc [errno=1153] +Last_IO_Error = 'Got a packet bigger than 'slave_max_allowed_packet' bytes' STOP SLAVE; RESET SLAVE; RESET MASTER; @@ -52,6 +52,7 @@ SET @@global.max_allowed_packet= 1024; Warnings: Warning 1105 The value of 'max_allowed_packet' should be no less than the value of 'net_buffer_length' SET @@global.net_buffer_length= 1024; +SET @@global.slave_max_allowed_packet= 1073741824; DROP TABLE t1; RESET SLAVE; include/rpl_end.inc diff --git a/mysql-test/suite/rpl/t/rpl_packet-slave.opt b/mysql-test/suite/rpl/t/rpl_packet-slave.opt index 42d4f94c999..e0a7a203f99 100644 --- a/mysql-test/suite/rpl/t/rpl_packet-slave.opt +++ b/mysql-test/suite/rpl/t/rpl_packet-slave.opt @@ -1 +1 @@ --O max_allowed_packet=1024 -O net_buffer_length=1024 +-O max_allowed_packet=1024 -O net_buffer_length=1024 -O slave_max_allowed_packet=1024 diff --git a/mysql-test/suite/rpl/t/rpl_packet.test b/mysql-test/suite/rpl/t/rpl_packet.test index 3197b6160cd..7fbea87f71e 100644 --- a/mysql-test/suite/rpl/t/rpl_packet.test +++ b/mysql-test/suite/rpl/t/rpl_packet.test @@ -11,9 +11,8 @@ # max-out size db name source include/master-slave.inc; source include/have_binlog_format_row.inc; -call mtr.add_suppression("Slave I/O: Got a packet bigger than 'max_allowed_packet' bytes, Error_code: 1153"); -call mtr.add_suppression("Slave I/O: Got fatal error 1236 from master when reading data from binary log:"); - +call mtr.add_suppression("Slave I/O: Got a packet bigger than 'slave_max_allowed_packet' bytes, Error_code: 1153"); +call mtr.add_suppression("Log entry on master is longer than slave_max_allowed_packet"); let $db= DB_NAME_OF_MAX_LENGTH_AKA_NAME_LEN_64_BYTES_____________________; disable_warnings; eval drop database if exists $db; @@ -23,6 +22,7 @@ eval create database $db; connection master; let $old_max_allowed_packet= `SELECT @@global.max_allowed_packet`; let $old_net_buffer_length= `SELECT @@global.net_buffer_length`; +let $old_slave_max_allowed_packet= `SELECT @@global.slave_max_allowed_packet`; SET @@global.max_allowed_packet=1024; SET @@global.net_buffer_length=1024; @@ -124,8 +124,8 @@ INSERT INTO t1(f1, f2, f3) VALUES(1, REPEAT('a', @@global.max_allowed_packet), R connection slave; # The slave I/O thread must stop after receiving -# 1236=ER_MASTER_FATAL_ERROR_READING_BINLOG error message from master. ---let $slave_io_errno= 1236 +# 1153 = ER_NET_PACKET_TOO_LARGE +--let $slave_io_errno= 1153 --let $show_slave_io_error= 1 --source include/wait_for_slave_io_error.inc @@ -166,6 +166,7 @@ connection master; DROP TABLE t1; eval SET @@global.max_allowed_packet= $old_max_allowed_packet; eval SET @@global.net_buffer_length= $old_net_buffer_length; +eval SET @@global.slave_max_allowed_packet= $old_slave_max_allowed_packet; # slave is stopped connection slave; DROP TABLE t1; diff --git a/mysql-test/suite/sys_vars/inc/slave_max_allowed_packet_basic.inc b/mysql-test/suite/sys_vars/inc/slave_max_allowed_packet_basic.inc new file mode 100644 index 00000000000..4caaae84906 --- /dev/null +++ b/mysql-test/suite/sys_vars/inc/slave_max_allowed_packet_basic.inc @@ -0,0 +1,177 @@ +############## mysql-test\t\slave_max_allowed_packet_basic.test ################## +# # +# Variable Name: slave_max_allowed_packet # +# Scope: GLOBAL # +# Access Type: Dynamic # +# Data Type: numeric # +# Default Value:1073741824 # +# Range: 1024 - 1073741824 # +# # +# # +# # +# Description: Test Cases of Dynamic System Variable slave_max_allowed_packet # +# that checks the behavior of this variable in the following ways# +# * Default Value # +# * Valid & Invalid values # +# * Scope & Access method # +# * Data Integrity # +# # +############################################################################### + +--source include/load_sysvars.inc + +######################################################################## +# START OF slave_max_allowed_packet TESTS # +######################################################################## + + +########################################################################### +# Saving initial value of slave_max_allowed_packet in a temporary variable# +########################################################################### + +SET @start_value = @@global.slave_max_allowed_packet; +SELECT @start_value; + + +--echo '#--------------------FN_DYNVARS_072_01------------------------#' +######################################################################## +# Display the DEFAULT value of slave_max_allowed_packet # +######################################################################## + +SET @@global.slave_max_allowed_packet = 5000; +SET @@global.slave_max_allowed_packet = DEFAULT; +SELECT @@global.slave_max_allowed_packet; + + +--echo '#---------------------FN_DYNVARS_072_02-------------------------#' +############################################### +# Verify default value of variable # +############################################### + +SET @@global.slave_max_allowed_packet = @start_value; +SELECT @@global.slave_max_allowed_packet = 1073741824; +--echo 'Bug# 34876: Incorrect Default Value is assigned to variable'; + +--echo '#--------------------FN_DYNVARS_072_03------------------------#' +######################################################################## +# Change the value of slave_max_allowed_packet to a valid value # +######################################################################## + +SET @@global.slave_max_allowed_packet = 1024; +SELECT @@global.slave_max_allowed_packet; +SET @@global.slave_max_allowed_packet = 1073741824; +SELECT @@global.slave_max_allowed_packet; +SET @@global.slave_max_allowed_packet = 1073741824; +SELECT @@global.slave_max_allowed_packet; +SET @@global.slave_max_allowed_packet = 1025; +SELECT @@global.slave_max_allowed_packet; +SET @@global.slave_max_allowed_packet = 65535; +SELECT @@global.slave_max_allowed_packet; +--echo 'Bug# 34877: Invalid Values are coming in variable on assigning valid values'; + + +--echo '#--------------------FN_DYNVARS_072_04-------------------------#' +########################################################################### +# Change the value of slave_max_allowed_packet to invalid value # +########################################################################### + +SET @@global.slave_max_allowed_packet = -1; +SELECT @@global.slave_max_allowed_packet; +SET @@global.slave_max_allowed_packet = 100000000000; +SELECT @@global.slave_max_allowed_packet; +--Error ER_WRONG_TYPE_FOR_VAR +SET @@global.slave_max_allowed_packet = 10000.01; +SELECT @@global.slave_max_allowed_packet; +SET @@global.slave_max_allowed_packet = -1024; +SELECT @@global.slave_max_allowed_packet; +SET @@global.slave_max_allowed_packet = 4294967296; +SELECT @@global.slave_max_allowed_packet; +SET @@global.slave_max_allowed_packet = 1023; +SELECT @@global.slave_max_allowed_packet; + +--echo 'Bug # 34837: Errors are not coming on assigning invalid values to variable'; + +--Error ER_WRONG_TYPE_FOR_VAR +SET @@global.slave_max_allowed_packet = ON; +SELECT @@global.slave_max_allowed_packet; +--Error ER_WRONG_TYPE_FOR_VAR +SET @@global.slave_max_allowed_packet = 'test'; +SELECT @@global.slave_max_allowed_packet; + + +--echo '#-------------------FN_DYNVARS_072_05----------------------------#' +########################################################################### +# Test if accessing session slave_max_allowed_packet gives error # +########################################################################### + +--Error ER_GLOBAL_VARIABLE +SET @@session.slave_max_allowed_packet = 4096; +--Error ER_INCORRECT_GLOBAL_LOCAL_VAR +SELECT @@session.slave_max_allowed_packet; + + +--echo '#----------------------FN_DYNVARS_072_06------------------------#' +############################################################################## +# Check if the value in GLOBAL & SESSION Tables matches values in variable # +############################################################################## + +SELECT @@global.slave_max_allowed_packet = VARIABLE_VALUE +FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES +WHERE VARIABLE_NAME='slave_max_allowed_packet'; + +SELECT @@slave_max_allowed_packet = VARIABLE_VALUE +FROM INFORMATION_SCHEMA.SESSION_VARIABLES +WHERE VARIABLE_NAME='slave_max_allowed_packet'; + + +--echo '#---------------------FN_DYNVARS_072_07----------------------#' +################################################################### +# Check if TRUE and FALSE values can be used on variable # +################################################################### + +SET @@global.slave_max_allowed_packet = TRUE; +SELECT @@global.slave_max_allowed_packet; +SET @@global.slave_max_allowed_packet = FALSE; +SELECT @@global.slave_max_allowed_packet; + + +--echo '#---------------------FN_DYNVARS_072_08----------------------#' +######################################################################################################## +# Check if accessing variable with SESSION,LOCAL and without SCOPE points to same session variable # +######################################################################################################## + +SET @@global.slave_max_allowed_packet = 5000; +SELECT @@slave_max_allowed_packet = @@global.slave_max_allowed_packet; + + +--echo '#---------------------FN_DYNVARS_072_09----------------------#' +################################################################################ +# Check if slave_max_allowed_packet can be accessed with and without @@ sign # +################################################################################ + +--Error ER_GLOBAL_VARIABLE +SET slave_max_allowed_packet = 6000; +SELECT @@slave_max_allowed_packet; +--Error ER_PARSE_ERROR +SET local.slave_max_allowed_packet = 7000; +--Error ER_UNKNOWN_TABLE +SELECT local.slave_max_allowed_packet; +--Error ER_PARSE_ERROR +SET global.slave_max_allowed_packet = 8000; +--Error ER_UNKNOWN_TABLE +SELECT global.slave_max_allowed_packet; +--Error ER_BAD_FIELD_ERROR +SELECT slave_max_allowed_packet = @@session.slave_max_allowed_packet; + + +############################## +# Restore initial value # +############################## + +SET @@global.slave_max_allowed_packet = @start_value; +SELECT @@global.slave_max_allowed_packet; + + +######################################################################## +# END OF slave_max_allowed_packet TESTS # +######################################################################## diff --git a/mysql-test/suite/sys_vars/r/max_allowed_packet_basic.result b/mysql-test/suite/sys_vars/r/max_allowed_packet_basic.result index ca5b87f19cb..810ddb00b79 100644 --- a/mysql-test/suite/sys_vars/r/max_allowed_packet_basic.result +++ b/mysql-test/suite/sys_vars/r/max_allowed_packet_basic.result @@ -7,6 +7,7 @@ SET @@global.max_allowed_packet = DEFAULT; SET @@global.max_allowed_packet = 1000; Warnings: Warning 1292 Truncated incorrect max_allowed_packet value: '1000' +Warning 1105 The value of 'max_allowed_packet' should be no less than the value of 'net_buffer_length' SET @@global.max_allowed_packet = DEFAULT; SELECT @@global.max_allowed_packet; @@global.max_allowed_packet @@ -25,10 +26,14 @@ SELECT @@global.max_allowed_packet = 1048576; 1 '#--------------------FN_DYNVARS_070_03-------------------------#' SET @@global.max_allowed_packet = 1024; +Warnings: +Warning 1105 The value of 'max_allowed_packet' should be no less than the value of 'net_buffer_length' SELECT @@global.max_allowed_packet; @@global.max_allowed_packet 1024 SET @@global.max_allowed_packet = 1025; +Warnings: +Warning 1105 The value of 'max_allowed_packet' should be no less than the value of 'net_buffer_length' SELECT @@global.max_allowed_packet; @@global.max_allowed_packet 1024 @@ -71,18 +76,21 @@ SELECT @@session.max_allowed_packet; SET @@global.max_allowed_packet = 0; Warnings: Warning 1292 Truncated incorrect max_allowed_packet value: '0' +Warning 1105 The value of 'max_allowed_packet' should be no less than the value of 'net_buffer_length' SELECT @@global.max_allowed_packet; @@global.max_allowed_packet 1024 SET @@global.max_allowed_packet = -1024; Warnings: Warning 1292 Truncated incorrect max_allowed_packet value: '-1024' +Warning 1105 The value of 'max_allowed_packet' should be no less than the value of 'net_buffer_length' SELECT @@global.max_allowed_packet; @@global.max_allowed_packet 1024 SET @@global.max_allowed_packet = 1023; Warnings: Warning 1292 Truncated incorrect max_allowed_packet value: '1023' +Warning 1105 The value of 'max_allowed_packet' should be no less than the value of 'net_buffer_length' SELECT @@global.max_allowed_packet; @@global.max_allowed_packet 1024 @@ -146,17 +154,21 @@ WHERE VARIABLE_NAME='max_allowed_packet'; SET @@global.max_allowed_packet = TRUE; Warnings: Warning 1292 Truncated incorrect max_allowed_packet value: '1' +Warning 1105 The value of 'max_allowed_packet' should be no less than the value of 'net_buffer_length' SELECT @@global.max_allowed_packet; @@global.max_allowed_packet 1024 SET @@global.max_allowed_packet = FALSE; Warnings: Warning 1292 Truncated incorrect max_allowed_packet value: '0' +Warning 1105 The value of 'max_allowed_packet' should be no less than the value of 'net_buffer_length' SELECT @@global.max_allowed_packet; @@global.max_allowed_packet 1024 '#---------------------FN_DYNVARS_070_09----------------------#' SET @@global.max_allowed_packet = 2048; +Warnings: +Warning 1105 The value of 'max_allowed_packet' should be no less than the value of 'net_buffer_length' SELECT @@max_allowed_packet = @@global.max_allowed_packet; @@max_allowed_packet = @@global.max_allowed_packet 0 diff --git a/mysql-test/suite/sys_vars/r/max_allowed_packet_func.result b/mysql-test/suite/sys_vars/r/max_allowed_packet_func.result index 0d682b65aea..a202701b60f 100644 --- a/mysql-test/suite/sys_vars/r/max_allowed_packet_func.result +++ b/mysql-test/suite/sys_vars/r/max_allowed_packet_func.result @@ -23,6 +23,8 @@ SELECT @@session.net_buffer_length; '#--------------------FN_DYNVARS_070_02-------------------------#' ## Setting value of max_allowed packet and net_buffer_length to 1024 ## SET @@global.max_allowed_packet = 1024; +Warnings: +Warning 1105 The value of 'max_allowed_packet' should be no less than the value of 'net_buffer_length' SET @@global.net_buffer_length = 1024; SELECT @@global.max_allowed_packet; @@global.max_allowed_packet diff --git a/mysql-test/suite/sys_vars/r/net_buffer_length_basic.result b/mysql-test/suite/sys_vars/r/net_buffer_length_basic.result index 07f933b5a4b..026c883e501 100644 --- a/mysql-test/suite/sys_vars/r/net_buffer_length_basic.result +++ b/mysql-test/suite/sys_vars/r/net_buffer_length_basic.result @@ -63,12 +63,14 @@ SELECT @@global.net_buffer_length; SET @@global.net_buffer_length = 1048577; Warnings: Warning 1292 Truncated incorrect net_buffer_length value: '1048577' +Warning 1105 The value of 'max_allowed_packet' should be no less than the value of 'net_buffer_length' SELECT @@global.net_buffer_length; @@global.net_buffer_length 1048576 SET @@global.net_buffer_length = 104857633; Warnings: Warning 1292 Truncated incorrect net_buffer_length value: '104857633' +Warning 1105 The value of 'max_allowed_packet' should be no less than the value of 'net_buffer_length' SELECT @@global.net_buffer_length; @@global.net_buffer_length 1048576 diff --git a/mysql-test/suite/sys_vars/t/slave_max_allowed_packet_basic.test b/mysql-test/suite/sys_vars/t/slave_max_allowed_packet_basic.test new file mode 100644 index 00000000000..5b6a557738b --- /dev/null +++ b/mysql-test/suite/sys_vars/t/slave_max_allowed_packet_basic.test @@ -0,0 +1,3 @@ +--source suite/sys_vars/inc/slave_max_allowed_packet_basic.inc + + diff --git a/sql/log_event.cc b/sql/log_event.cc index afcc283a6d1..958b7e4ef36 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -1122,7 +1122,7 @@ failed my_b_read")); Log_event *res= 0; #ifndef max_allowed_packet THD *thd=current_thd; - uint max_allowed_packet= thd ? thd->variables.max_allowed_packet : ~(ulong)0; + uint max_allowed_packet= thd ? slave_max_allowed_packet:~(ulong)0; #endif if (data_len > max_allowed_packet) diff --git a/sql/log_event.h b/sql/log_event.h index 4c80148458c..39cd55f313e 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -275,6 +275,13 @@ struct sql_ex_info MAX_SIZE_LOG_EVENT_STATUS + /* status */ \ NAME_LEN + 1) +/* + The new option is added to handle large packets that are sent from the master + to the slave. It is used to increase the thd(max_allowed) for both the + DUMP thread on the master and the SQL/IO thread on the slave. +*/ +#define MAX_MAX_ALLOWED_PACKET 1024*1024*1024 + /* Event header offsets; these point to places inside the fixed header. diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 359e84a3370..937617032dd 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -1944,6 +1944,7 @@ extern ulong slave_net_timeout, slave_trans_retries; extern uint max_user_connections; extern ulong what_to_log,flush_time; extern ulong query_buff_size; +extern ulong slave_max_allowed_packet; extern ulong max_prepared_stmt_count, prepared_stmt_count; extern ulong binlog_cache_size, open_files_limit; extern ulonglong max_binlog_cache_size; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 4a80fd043c8..db73504cb17 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -28,6 +28,7 @@ #include "mysys_err.h" #include "events.h" #include "debug_sync.h" +#include "log_event.h" #include "../storage/myisam/ha_myisam.h" @@ -574,6 +575,7 @@ static const char *slave_exec_mode_str= "STRICT"; ulong thread_cache_size=0, thread_pool_size= 0; ulong binlog_cache_size=0; ulonglong max_binlog_cache_size=0; +ulong slave_max_allowed_packet= 0; ulong query_cache_size=0; ulong refresh_version; /* Increments on each reload */ query_id_t global_query_id; @@ -5572,6 +5574,7 @@ enum options_mysqld OPT_KEY_CACHE_DIVISION_LIMIT, OPT_KEY_CACHE_AGE_THRESHOLD, OPT_LONG_QUERY_TIME, OPT_LOWER_CASE_TABLE_NAMES, OPT_MAX_ALLOWED_PACKET, + OPT_SLAVE_MAX_ALLOWED_PACKET, OPT_MAX_BINLOG_CACHE_SIZE, OPT_MAX_BINLOG_SIZE, OPT_MAX_CONNECTIONS, OPT_MAX_CONNECT_ERRORS, OPT_MAX_DELAYED_THREADS, OPT_MAX_HEP_TABLE_SIZE, @@ -6700,6 +6703,10 @@ thread is in the relay logs.", &global_system_variables.max_allowed_packet, &max_system_variables.max_allowed_packet, 0, GET_ULONG, REQUIRED_ARG, 1024*1024L, 1024, 1024L*1024L*1024L, MALLOC_OVERHEAD, 1024, 0}, + {"slave_max_allowed_packet", OPT_SLAVE_MAX_ALLOWED_PACKET, + "The maximum packet length to sent successfully from the master to slave.", + &slave_max_allowed_packet, &slave_max_allowed_packet, 0, GET_ULONG, + REQUIRED_ARG, MAX_MAX_ALLOWED_PACKET, 1024, MAX_MAX_ALLOWED_PACKET, MALLOC_OVERHEAD, 1024, 0}, {"max_binlog_cache_size", OPT_MAX_BINLOG_CACHE_SIZE, "Can be used to restrict the total size used to cache a multi-transaction query.", &max_binlog_cache_size, &max_binlog_cache_size, 0, diff --git a/sql/set_var.cc b/sql/set_var.cc index d9133a25d98..bbc47c2d7e8 100644 --- a/sql/set_var.cc +++ b/sql/set_var.cc @@ -366,6 +366,8 @@ static sys_var_const sys_lower_case_table_names(&vars, static sys_var_thd_ulong_session_readonly sys_max_allowed_packet(&vars, "max_allowed_packet", &SV::max_allowed_packet, check_max_allowed_packet); +static sys_var_long_ptr sys_slave_max_allowed_packet(&vars, "slave_max_allowed_packet", + &slave_max_allowed_packet); static sys_var_ulonglong_ptr sys_max_binlog_cache_size(&vars, "max_binlog_cache_size", &max_binlog_cache_size); static sys_var_long_ptr sys_max_binlog_size(&vars, "max_binlog_size", diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index 7cb9d9ebcc1..99bae298e49 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -3512,23 +3512,23 @@ ER_ABORTING_CONNECTION 08S01 swe "Avbröt länken för tråd %ld till db '%-.192s', användare '%-.48s' (%-.64s)" ukr "ðÅÒÅÒ×ÁÎÏ Ú'¤ÄÎÁÎÎÑ %ld ÄÏ ÂÁÚÉ ÄÁÎÎÉÈ: '%-.192s' ËÏÒÉÓÔÕ×ÁÞÁ: '%-.48s' (%-.64s)" ER_NET_PACKET_TOO_LARGE 08S01 - cze "Zji-B¹tìn pøíchozí packet del¹í ne¾ 'max_allowed_packet'" - dan "Modtog en datapakke som var større end 'max_allowed_packet'" - nla "Groter pakket ontvangen dan 'max_allowed_packet'" - eng "Got a packet bigger than 'max_allowed_packet' bytes" - est "Saabus suurem pakett kui lubatud 'max_allowed_packet' muutujaga" - fre "Paquet plus grand que 'max_allowed_packet' reçu" - ger "Empfangenes Paket ist größer als 'max_allowed_packet' Bytes" - hun "A kapott csomag nagyobb, mint a maximalisan engedelyezett: 'max_allowed_packet'" - ita "Ricevuto un pacchetto piu` grande di 'max_allowed_packet'" - kor "'max_allowed_packet'º¸´Ù ´õÅ« ÆÐŶÀ» ¹Þ¾Ò½À´Ï´Ù." - por "Obteve um pacote maior do que a taxa máxima de pacotes definida (max_allowed_packet)" - rum "Un packet mai mare decit 'max_allowed_packet' a fost primit" - rus "ðÏÌÕÞÅÎÎÙÊ ÐÁËÅÔ ÂÏÌØÛÅ, ÞÅÍ 'max_allowed_packet'" - serbian "Primio sam mrežni paket veæi od definisane vrednosti 'max_allowed_packet'" - spa "Obtenido un paquete mayor que 'max_allowed_packet'" - swe "Kommunkationspaketet är större än 'max_allowed_packet'" - ukr "ïÔÒÉÍÁÎÏ ÐÁËÅÔ Â¦ÌØÛÉÊ Î¦Ö max_allowed_packet" + cze "Zji-B¹tìn pøíchozí packet del¹í ne¾ 'slave_max_allowed_packet'" + dan "Modtog en datapakke som var større end 'slave_max_allowed_packet'" + nla "Groter pakket ontvangen dan 'slave_max_allowed_packet'" + eng "Got a packet bigger than 'slave_max_allowed_packet' bytes" + est "Saabus suurem pakett kui lubatud 'slave_max_allowed_packet' muutujaga" + fre "Paquet plus grand que 'slave_max_allowed_packet' reçu" + ger "Empfangenes Paket ist größer als 'slave_max_allowed_packet' Bytes" + hun "A kapott csomag nagyobb, mint a maximalisan engedelyezett: 'slave_max_allowed_packet'" + ita "Ricevuto un pacchetto piu` grande di 'slave_max_allowed_packet'" + kor "'slave_max_allowed_packet'º¸´Ù ´õÅ« ÆÐŶÀ» ¹Þ¾Ò½À´Ï´Ù." + por "Obteve um pacote maior do que a taxa máxima de pacotes definida (slave_max_allowed_packet)" + rum "Un packet mai mare decit 'slave_max_allowed_packet' a fost primit" + rus "ðÏÌÕÞÅÎÎÙÊ ÐÁËÅÔ ÂÏÌØÛÅ, ÞÅÍ 'slave_max_allowed_packet'" + serbian "Primio sam mrežni paket veæi od definisane vrednosti 'slave_max_allowed_packet'" + spa "Obtenido un paquete mayor que 'slave_max_allowed_packet'" + swe "Kommunkationspaketet är större än 'slave_max_allowed_packet'" + ukr "ïÔÒÉÍÁÎÏ ÐÁËÅÔ Â¦ÌØÛÉÊ Î¦Ö slave_max_allowed_packet" ER_NET_READ_ERROR_FROM_PIPE 08S01 cze "Zji-B¹tìna chyba pøi ètení z roury spojení" dan "Fik læsefejl fra forbindelse (connection pipe)" diff --git a/sql/slave.cc b/sql/slave.cc index 437762cc318..b555d4351c9 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -1884,8 +1884,8 @@ static int init_slave_thread(THD* thd, SLAVE_THD_TYPE thd_type) slave threads, since a replication event can become this much larger than the corresponding packet (query) sent from client to master. */ - thd->variables.max_allowed_packet= global_system_variables.max_allowed_packet - + MAX_LOG_EVENT_HEADER; /* note, incr over the global not session var */ + thd->variables.max_allowed_packet= slave_max_allowed_packet; + thd->net.max_packet_size= slave_max_allowed_packet; thd->slave_thread = 1; thd->enable_slow_log= opt_log_slow_slave_statements; set_slave_thread_options(thd); @@ -2630,6 +2630,7 @@ pthread_handler_t handle_slave_io(void *arg) thread, since a replication event can become this much larger than the corresponding packet (query) sent from client to master. */ + thd->net.max_packet_size= slave_max_allowed_packet; mysql->net.max_packet_size= thd->net.max_packet_size+= MAX_LOG_EVENT_HEADER; } else @@ -2761,10 +2762,10 @@ reading event")) switch (mysql_error_number) { case CR_NET_PACKET_TOO_LARGE: sql_print_error("\ -Log entry on master is longer than max_allowed_packet (%ld) on \ +Log entry on master is longer than slave_max_allowed_packet (%lu) on \ slave. If the entry is correct, restart the server with a higher value of \ -max_allowed_packet", - thd->variables.max_allowed_packet); +slave_max_allowed_packet", + slave_max_allowed_packet); mi->report(ERROR_LEVEL, ER_NET_PACKET_TOO_LARGE, "%s", ER(ER_NET_PACKET_TOO_LARGE)); goto err; diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index c92d2db2c1e..e3188def206 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -469,7 +469,7 @@ impossible position"; this larger than the corresponding packet (query) sent from client to master. */ - thd->variables.max_allowed_packet+= MAX_LOG_EVENT_HEADER; + thd->variables.max_allowed_packet= ULONG_MAX; /* We can set log_lock now, it does not move (it's a member of From a73d2ae02c594e74c6deb91a09a789a91e0dcc05 Mon Sep 17 00:00:00 2001 From: Tor Didriksen Date: Mon, 21 May 2012 10:47:12 +0200 Subject: [PATCH 21/90] Bug#13986705 CRASH IN GET_INTERVAL_VALUE() WITH DATE CALCULATION WITH UTF32 INTERVALS This is a followup to the fix for Bug#12340997 get_interval_value() was trying to parse the input string, looking for leading '-' while skipping whitespace. The macro my_isspace() does not work for utf32 character set, since my_charset_utf32_general_ci.ctype == NULL. Solution: convert input to ASCII before parsing, and use the character set of the returned ASCII string. --- sql/item_timefunc.cc | 162 +++++++++++++++++++++---------------------- 1 file changed, 78 insertions(+), 84 deletions(-) diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 6fc85a01668..840c8e55efe 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -865,28 +865,43 @@ bool make_date_time(DATE_TIME_FORMAT *format, MYSQL_TIME *l_time, from the high end. This allows one to give: DAY_TO_SECOND as "D MM:HH:SS", "MM:HH:SS" "HH:SS" or as seconds. - @param length: length of str - @param cs: charset of str - @param values: array of results + @param args item expression which we convert to an ASCII string + @param str_value string buffer + @param is_negative set to true if interval is prefixed by '-' @param count: count of elements in result array + @param values: array of results @param transform_msec: if value is true we suppose that the last part of string value is microseconds and we should transform value to six digit value. For example, '1.1' -> '1.100000' */ -static bool get_interval_info(const char *str,uint length,CHARSET_INFO *cs, +static bool get_interval_info(Item *args, + String *str_value, + bool *is_negative, uint count, ulonglong *values, bool transform_msec) { - const char *end=str+length; - uint i; - long msec_length= 0; + String *res; + if (!(res= args->val_str_ascii(str_value))) + return true; - while (str != end && !my_isdigit(cs,*str)) + CHARSET_INFO *cs= res->charset(); + const char *str= res->ptr(); + const char *end= str + res->length(); + + str+= cs->cset->scan(cs, str, end, MY_SEQ_SPACES); + if (str < end && *str == '-') + { + *is_negative= true; + str++; + } + + while (str < end && !my_isdigit(cs,*str)) str++; - for (i=0 ; i < count ; i++) + long msec_length= 0; + for (uint i=0 ; i < count ; i++) { longlong value; const char *start= str; @@ -1427,45 +1442,24 @@ longlong Item_func_time_to_sec::val_int() To make code easy, allow interval objects without separators. */ -bool get_interval_value(Item *args,interval_type int_type, - String *str_value, INTERVAL *interval) +bool get_interval_value(Item *args, interval_type int_type, + String *str_value, INTERVAL *interval) { ulonglong array[5]; longlong UNINIT_VAR(value); - const char *UNINIT_VAR(str); - size_t UNINIT_VAR(length); - CHARSET_INFO *cs=str_value->charset(); bzero((char*) interval,sizeof(*interval)); if ((int) int_type <= INTERVAL_MICROSECOND) { value= args->val_int(); if (args->null_value) - return 1; + return true; if (value < 0) { - interval->neg=1; + interval->neg= true; value= -value; } } - else - { - String *res; - if (!(res= args->val_str_ascii(str_value))) - return (1); - - /* record negative intervalls in interval->neg */ - str=res->ptr(); - const char *end=str+res->length(); - while (str != end && my_isspace(cs,*str)) - str++; - if (str != end && *str == '-') - { - interval->neg=1; - str++; - } - length= (size_t) (end-str); // Set up pointers to new str - } switch (int_type) { case INTERVAL_YEAR: @@ -1486,88 +1480,88 @@ bool get_interval_value(Item *args,interval_type int_type, case INTERVAL_HOUR: interval->hour= (ulong) value; break; - case INTERVAL_MICROSECOND: - interval->second_part=value; - break; case INTERVAL_MINUTE: interval->minute=value; break; case INTERVAL_SECOND: interval->second=value; break; + case INTERVAL_MICROSECOND: + interval->second_part=value; + break; case INTERVAL_YEAR_MONTH: // Allow YEAR-MONTH YYYYYMM - if (get_interval_info(str,length,cs,2,array,0)) - return (1); + if (get_interval_info(args, str_value, &interval->neg, 2, array, false)) + return true; interval->year= (ulong) array[0]; interval->month= (ulong) array[1]; break; case INTERVAL_DAY_HOUR: - if (get_interval_info(str,length,cs,2,array,0)) - return (1); + if (get_interval_info(args, str_value, &interval->neg, 2, array, false)) + return true; interval->day= (ulong) array[0]; interval->hour= (ulong) array[1]; break; + case INTERVAL_DAY_MINUTE: + if (get_interval_info(args, str_value, &interval->neg, 3, array, false)) + return true; + interval->day= (ulong) array[0]; + interval->hour= (ulong) array[1]; + interval->minute= array[2]; + break; + case INTERVAL_DAY_SECOND: + if (get_interval_info(args, str_value, &interval->neg, 4, array, false)) + return true; + interval->day= (ulong) array[0]; + interval->hour= (ulong) array[1]; + interval->minute= array[2]; + interval->second= array[3]; + break; + case INTERVAL_HOUR_MINUTE: + if (get_interval_info(args, str_value, &interval->neg, 2, array, false)) + return true; + interval->hour= (ulong) array[0]; + interval->minute= array[1]; + break; + case INTERVAL_HOUR_SECOND: + if (get_interval_info(args, str_value, &interval->neg, 3, array, false)) + return true; + interval->hour= (ulong) array[0]; + interval->minute= array[1]; + interval->second= array[2]; + break; + case INTERVAL_MINUTE_SECOND: + if (get_interval_info(args, str_value, &interval->neg, 2, array, false)) + return true; + interval->minute= array[0]; + interval->second= array[1]; + break; case INTERVAL_DAY_MICROSECOND: - if (get_interval_info(str,length,cs,5,array,1)) - return (1); + if (get_interval_info(args, str_value, &interval->neg, 5, array, true)) + return true; interval->day= (ulong) array[0]; interval->hour= (ulong) array[1]; interval->minute= array[2]; interval->second= array[3]; interval->second_part= array[4]; break; - case INTERVAL_DAY_MINUTE: - if (get_interval_info(str,length,cs,3,array,0)) - return (1); - interval->day= (ulong) array[0]; - interval->hour= (ulong) array[1]; - interval->minute= array[2]; - break; - case INTERVAL_DAY_SECOND: - if (get_interval_info(str,length,cs,4,array,0)) - return (1); - interval->day= (ulong) array[0]; - interval->hour= (ulong) array[1]; - interval->minute= array[2]; - interval->second= array[3]; - break; case INTERVAL_HOUR_MICROSECOND: - if (get_interval_info(str,length,cs,4,array,1)) - return (1); + if (get_interval_info(args, str_value, &interval->neg, 4, array, true)) + return true; interval->hour= (ulong) array[0]; interval->minute= array[1]; interval->second= array[2]; interval->second_part= array[3]; break; - case INTERVAL_HOUR_MINUTE: - if (get_interval_info(str,length,cs,2,array,0)) - return (1); - interval->hour= (ulong) array[0]; - interval->minute= array[1]; - break; - case INTERVAL_HOUR_SECOND: - if (get_interval_info(str,length,cs,3,array,0)) - return (1); - interval->hour= (ulong) array[0]; - interval->minute= array[1]; - interval->second= array[2]; - break; case INTERVAL_MINUTE_MICROSECOND: - if (get_interval_info(str,length,cs,3,array,1)) - return (1); + if (get_interval_info(args, str_value, &interval->neg, 3, array, true)) + return true; interval->minute= array[0]; interval->second= array[1]; interval->second_part= array[2]; break; - case INTERVAL_MINUTE_SECOND: - if (get_interval_info(str,length,cs,2,array,0)) - return (1); - interval->minute= array[0]; - interval->second= array[1]; - break; case INTERVAL_SECOND_MICROSECOND: - if (get_interval_info(str,length,cs,2,array,1)) - return (1); + if (get_interval_info(args, str_value, &interval->neg, 2, array, true)) + return true; interval->second= array[0]; interval->second_part= array[1]; break; @@ -1575,7 +1569,7 @@ bool get_interval_value(Item *args,interval_type int_type, DBUG_ASSERT(0); break; /* purecov: end */ } - return 0; + return false; } From e979417c06f98f8ca81a7442d93f53d9aec79446 Mon Sep 17 00:00:00 2001 From: Annamalai Gurusami Date: Mon, 21 May 2012 17:25:40 +0530 Subject: [PATCH 22/90] Bug #12752572 61579: REPLICATION FAILURE WHILE INNODB_AUTOINC_LOCK_MODE=1 AND USING TRIGGER When an insert stmt like "insert into t values (1),(2),(3)" is executed, the autoincrement values assigned to these three rows are expected to be contiguous. In the given lock mode (innodb_autoinc_lock_mode=1), the auto inc lock will be released before the end of the statement. So to make the autoincrement contiguous for a given statement, we need to reserve the auto inc values at the beginning of the statement. Modified the fix based on review comment by Svoj. --- sql/handler.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index 20bf2355c25..9e43d5aba93 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -2398,18 +2398,18 @@ int handler::update_auto_increment() Note that in prelocked mode no estimation is given. */ - /* - For multi-row inserts, if the bulk inserts cannot be started, the - handler::estimation_rows_to_insert will not be set. Set it here. - */ - if ((estimation_rows_to_insert == 0) && - (thd->lex->many_values.elements > 0)) - { - estimation_rows_to_insert= thd->lex->many_values.elements; - } - if ((auto_inc_intervals_count == 0) && (estimation_rows_to_insert > 0)) nb_desired_values= estimation_rows_to_insert; + else if ((auto_inc_intervals_count == 0) && + (thd->lex->many_values.elements > 0)) + { + /* + For multi-row inserts, if the bulk inserts cannot be started, the + handler::estimation_rows_to_insert will not be set. But we still + want to reserve the autoinc values. + */ + nb_desired_values= thd->lex->many_values.elements; + } else /* go with the increasing defaults */ { /* avoid overflow in formula, with this if() */ From 8aedf7d30f4f2c19085407f6793bce84facdf1f5 Mon Sep 17 00:00:00 2001 From: Annamalai Gurusami Date: Wed, 23 May 2012 10:12:52 +0530 Subject: [PATCH 23/90] After the fix for Bug #12752572, there is a pb2 failure. Fixing it by updating the result file. Because a multi-row insert now reserves the auto increment values before hand, if any explicitly specified auto increment values are there, then some of the reserved values are lost. --- mysql-test/suite/rpl/r/rpl_trigger.result | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_trigger.result b/mysql-test/suite/rpl/r/rpl_trigger.result index 784cd1bcdff..e6e6763d76e 100644 --- a/mysql-test/suite/rpl/r/rpl_trigger.result +++ b/mysql-test/suite/rpl/r/rpl_trigger.result @@ -29,7 +29,7 @@ a b 1 2 3 0 4 0 -5 0 +6 0 500 0 select a,name, old_a, old_b, truncate(rand_value,4) from t3; a name old_a old_b truncate(rand_value,4) @@ -39,7 +39,7 @@ a name old_a old_b truncate(rand_value,4) 103 t2 1 2 0.9164 104 t2 3 0 0.8826 105 t2 4 0 0.6635 -106 t2 5 0 0.6699 +106 t2 6 0 0.6699 107 t2 500 0 0.3593 --- On slave -- @@ -52,7 +52,7 @@ a b 1 2 3 0 4 0 -5 0 +6 0 500 0 select a,name, old_a, old_b, truncate(rand_value,4) from t3; a name old_a old_b truncate(rand_value,4) @@ -62,7 +62,7 @@ a name old_a old_b truncate(rand_value,4) 103 t2 1 2 0.9164 104 t2 3 0 0.8826 105 t2 4 0 0.6635 -106 t2 5 0 0.6699 +106 t2 6 0 0.6699 107 t2 500 0 0.3593 drop table t1,t2,t3; select get_lock("bug12480",2); From be7a6d93ccc3a8304246183a44637b43bf2461d7 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Wed, 23 May 2012 10:21:35 +0200 Subject: [PATCH 24/90] Improved the test performance_schema.func_file_io, so that investigating test failures is easier. Detect cases when @before_count / @after_count is NULL. --- mysql-test/suite/perfschema/r/func_file_io.result | 12 ++++++++++++ mysql-test/suite/perfschema/t/func_file_io.test | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/mysql-test/suite/perfschema/r/func_file_io.result b/mysql-test/suite/perfschema/r/func_file_io.result index d99e77dcd8c..c95fae94803 100644 --- a/mysql-test/suite/perfschema/r/func_file_io.result +++ b/mysql-test/suite/perfschema/r/func_file_io.result @@ -15,6 +15,9 @@ SET @before_count = (SELECT SUM(TIMER_WAIT) FROM performance_schema.events_waits_history_long WHERE (EVENT_NAME = 'wait/io/file/myisam/dfile') AND (OBJECT_NAME LIKE '%t1.MYD')); +SELECT (@before_count >= 0) as have_before_count; +have_before_count +1 SELECT IF(@before_count > 0, 'Success', 'Failure') has_instrumentation; has_instrumentation Success @@ -27,6 +30,9 @@ SET @after_count = (SELECT SUM(TIMER_WAIT) FROM performance_schema.events_waits_history_long WHERE (EVENT_NAME = 'wait/io/file/myisam/dfile') AND (OBJECT_NAME LIKE '%t1.MYD') AND (1 = 1)); +SELECT (@after_count >= 0) as have_after_count; +have_after_count +1 SELECT IF((@after_count - @before_count) > 0, 'Success', 'Failure') test_ff1_timed; test_ff1_timed Success @@ -35,6 +41,9 @@ SET @before_count = (SELECT SUM(TIMER_WAIT) FROM performance_schema.events_waits_history_long WHERE (EVENT_NAME = 'wait/io/file/myisam/dfile') AND (OBJECT_NAME LIKE '%t1.MYD') AND (2 = 2)); +SELECT (@before_count >= 0) as have_before_count; +have_before_count +1 SELECT * FROM t1 WHERE id < 6; id b 1 initial value @@ -46,6 +55,9 @@ SET @after_count = (SELECT SUM(TIMER_WAIT) FROM performance_schema.events_waits_history_long WHERE (EVENT_NAME = 'wait/io/file/myisam/dfile') AND (OBJECT_NAME LIKE '%t1.MYD') AND (3 = 3)); +SELECT (@after_count >= 0) as have_after_count; +have_after_count +1 SELECT IF((COALESCE(@after_count, 0) - COALESCE(@before_count, 0)) = 0, 'Success', 'Failure') test_ff2_timed; test_ff2_timed Success diff --git a/mysql-test/suite/perfschema/t/func_file_io.test b/mysql-test/suite/perfschema/t/func_file_io.test index bcf29a7daa2..e8b01a10bd1 100644 --- a/mysql-test/suite/perfschema/t/func_file_io.test +++ b/mysql-test/suite/perfschema/t/func_file_io.test @@ -41,6 +41,7 @@ SET @before_count = (SELECT SUM(TIMER_WAIT) WHERE (EVENT_NAME = 'wait/io/file/myisam/dfile') AND (OBJECT_NAME LIKE '%t1.MYD')); +SELECT (@before_count >= 0) as have_before_count; SELECT IF(@before_count > 0, 'Success', 'Failure') has_instrumentation; SELECT * FROM t1 WHERE id < 4; @@ -50,6 +51,7 @@ SET @after_count = (SELECT SUM(TIMER_WAIT) WHERE (EVENT_NAME = 'wait/io/file/myisam/dfile') AND (OBJECT_NAME LIKE '%t1.MYD') AND (1 = 1)); +SELECT (@after_count >= 0) as have_after_count; SELECT IF((@after_count - @before_count) > 0, 'Success', 'Failure') test_ff1_timed; UPDATE performance_schema.setup_instruments SET enabled='NO'; @@ -59,6 +61,7 @@ SET @before_count = (SELECT SUM(TIMER_WAIT) WHERE (EVENT_NAME = 'wait/io/file/myisam/dfile') AND (OBJECT_NAME LIKE '%t1.MYD') AND (2 = 2)); +SELECT (@before_count >= 0) as have_before_count; SELECT * FROM t1 WHERE id < 6; SET @after_count = (SELECT SUM(TIMER_WAIT) @@ -66,6 +69,7 @@ SET @after_count = (SELECT SUM(TIMER_WAIT) WHERE (EVENT_NAME = 'wait/io/file/myisam/dfile') AND (OBJECT_NAME LIKE '%t1.MYD') AND (3 = 3)); +SELECT (@after_count >= 0) as have_after_count; SELECT IF((COALESCE(@after_count, 0) - COALESCE(@before_count, 0)) = 0, 'Success', 'Failure') test_ff2_timed; # From 889ce031087dbe44cdbdbd2c93a7983667aec536 Mon Sep 17 00:00:00 2001 From: "Norvald H. Ryeng" Date: Wed, 23 May 2012 12:27:32 +0200 Subject: [PATCH 25/90] WL#6311 Remove --safe-mode Print deprecation warning if the --safe-mode command line option is used. --- mysql-test/r/mysqld--help-notwin.result | 2 +- mysql-test/r/mysqld--help-win.result | 2 +- sql/mysqld.cc | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/mysqld--help-notwin.result b/mysql-test/r/mysqld--help-notwin.result index 36649cf761d..72f89ae3bc1 100644 --- a/mysql-test/r/mysqld--help-notwin.result +++ b/mysql-test/r/mysqld--help-notwin.result @@ -595,7 +595,7 @@ The following options may be given as the first argument: master during slave registration --rpl-recovery-rank=# Unused, will be removed - --safe-mode Skip some optimize stages (for testing). + --safe-mode Skip some optimize stages (for testing). Deprecated. --safe-user-create Don't allow new user creation by the user who has no write privileges to the mysql.user table. --secure-auth Disallow authentication for accounts that have old diff --git a/mysql-test/r/mysqld--help-win.result b/mysql-test/r/mysqld--help-win.result index db7dd264b76..2ab41913427 100644 --- a/mysql-test/r/mysqld--help-win.result +++ b/mysql-test/r/mysqld--help-win.result @@ -595,7 +595,7 @@ The following options may be given as the first argument: master during slave registration --rpl-recovery-rank=# Unused, will be removed - --safe-mode Skip some optimize stages (for testing). + --safe-mode Skip some optimize stages (for testing). Deprecated. --safe-user-create Don't allow new user creation by the user who has no write privileges to the mysql.user table. --secure-auth Disallow authentication for accounts that have old diff --git a/sql/mysqld.cc b/sql/mysqld.cc index a37a9701fe7..df9fbaa8652 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -5948,7 +5948,7 @@ struct my_option my_long_options[]= "will not do updates to tables in databases that start with foo and whose " "table names start with bar.", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"safe-mode", OPT_SAFE, "Skip some optimize stages (for testing).", + {"safe-mode", OPT_SAFE, "Skip some optimize stages (for testing). Deprecated.", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, {"safe-user-create", 0, "Don't allow new user creation by the user who has no write privileges to the mysql.user table.", @@ -7081,6 +7081,8 @@ mysqld_get_one_option(int optid, delay_key_write_options= DELAY_KEY_WRITE_NONE; myisam_recover_options= HA_RECOVER_DEFAULT; ha_open_options&= ~(HA_OPEN_DELAY_KEY_WRITE); + sql_print_warning("The syntax '--safe-mode' is deprecated and will be " + "removed in a future release."); break; case (int) OPT_SKIP_PRIOR: opt_specialflag|= SPECIAL_NO_PRIOR; From dcd4fa3fd5330945cb996081e521b2d9d635edab Mon Sep 17 00:00:00 2001 From: Sujatha Sivakumar Date: Thu, 24 May 2012 16:25:07 +0530 Subject: [PATCH 26/90] Bug#13833962:DISABLE [NOTE] START BINLOG_DUMP TO SLAVE_SERVER(0) MESSAGES IN THE ERROR LOG Problem: Using mysqlbinlog with the --read-from-remote-server option as shown below prints a message in error log for each call. This happens for 5.5 and above versions mysqlbinlog -uroot -p --read-from-remote-server --host=localhost test Message in error log file is given below: 120312 10:27:57 [Note] Start binlog_dump to slave_server(0), pos(test, 4) The problem is that it can fill up the error log if the command is called very often. Analysis: The below mentioned print function is called from "mysql_binlog_send" function which causes the "Start binlog_dump..." string to be printed in error log file. sql_print_information("Start binlog_dump to master_thread_id(%lu) slave_server(%d)..." Fix: A condition has been added in such a way that the 'sql_print_information' will be invoked only when the "log_warnings" variable is set to >1 otherwise don't call the 'sql_print_information' function. --- sql/sql_repl.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sql/sql_repl.cc b/sql/sql_repl.cc index ffc7aa4bf8a..5968c17f871 100644 --- a/sql/sql_repl.cc +++ b/sql/sql_repl.cc @@ -476,7 +476,8 @@ void mysql_binlog_send(THD* thd, char* log_ident, my_off_t pos, heartbeat_ts= &heartbeat_buf; set_timespec_nsec(*heartbeat_ts, 0); } - sql_print_information("Start binlog_dump to slave_server(%d), pos(%s, %lu)", + if (global_system_variables.log_warnings > 1) + sql_print_information("Start binlog_dump to slave_server(%d), pos(%s, %lu)", thd->server_id, log_ident, (ulong)pos); if (RUN_HOOK(binlog_transmit, transmit_start, (thd, flags, log_ident, pos))) { From 01748ce128ae4c29cfb63e88cd68918e7d48e946 Mon Sep 17 00:00:00 2001 From: Inaam Rana Date: Thu, 24 May 2012 12:37:03 -0400 Subject: [PATCH 27/90] Bug #14100254 65389: MVCC IS BROKEN WITH IMPLICIT LOCK rb://1088 approved by: Marko Makela This bug was introduced in early stages of plugin. We were not checking for an implicit lock on sec index rec for trx_id that is stamped on current version of the clust_index in case where the clust_index has a previous delete marked version. --- storage/innodb_plugin/row/row0vers.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/storage/innodb_plugin/row/row0vers.c b/storage/innodb_plugin/row/row0vers.c index 8a7bb842293..9aeaa2db6c0 100644 --- a/storage/innodb_plugin/row/row0vers.c +++ b/storage/innodb_plugin/row/row0vers.c @@ -208,18 +208,6 @@ row_vers_impl_x_locked_off_kernel( vers_del = rec_get_deleted_flag(prev_version, comp); prev_trx_id = row_get_rec_trx_id(prev_version, clust_index, clust_offsets); - - /* If the trx_id and prev_trx_id are different and if - the prev_version is marked deleted then the - prev_trx_id must have already committed for the trx_id - to be able to modify the row. Therefore, prev_trx_id - cannot hold any implicit lock. */ - if (vers_del && 0 != ut_dulint_cmp(trx_id, prev_trx_id)) { - - mutex_enter(&kernel_mutex); - break; - } - /* The stack of versions is locked by mtr. Thus, it is safe to fetch the prefixes for externally stored columns. */ From efe42792b363e97dd5ccb74be1abac2d4e79ca9e Mon Sep 17 00:00:00 2001 From: Mayank Prasad Date: Thu, 24 May 2012 23:00:32 +0530 Subject: [PATCH 28/90] Bug#13417440 : 63340: ARCHIVE FILE IO NOT INSTRUMENTED Details: - Archive storage engine file access were not instrumented and thus were not shown in PS tables. Fix: - Added instrumentation code by using PS Apis for I/O. --- .../suite/perfschema/r/query_cache.result | 4 +-- mysql-test/suite/perfschema/t/disabled.def | 2 +- storage/archive/azio.c | 25 +++++++++++-------- storage/archive/ha_archive.cc | 25 ++++++++++++++----- 4 files changed, 37 insertions(+), 19 deletions(-) diff --git a/mysql-test/suite/perfschema/r/query_cache.result b/mysql-test/suite/perfschema/r/query_cache.result index c7ac3d499b4..56511999ab2 100644 --- a/mysql-test/suite/perfschema/r/query_cache.result +++ b/mysql-test/suite/perfschema/r/query_cache.result @@ -38,7 +38,7 @@ spins NULL select name from performance_schema.setup_instruments order by name limit 1; name -wait/io/file/csv/data +wait/io/file/archive/data show status like "Qcache_queries_in_cache"; Variable_name Value Qcache_queries_in_cache 1 @@ -53,7 +53,7 @@ spins NULL select name from performance_schema.setup_instruments order by name limit 1; name -wait/io/file/csv/data +wait/io/file/archive/data show status like "Qcache_queries_in_cache"; Variable_name Value Qcache_queries_in_cache 1 diff --git a/mysql-test/suite/perfschema/t/disabled.def b/mysql-test/suite/perfschema/t/disabled.def index 8cae44a3607..6c496ec6d95 100644 --- a/mysql-test/suite/perfschema/t/disabled.def +++ b/mysql-test/suite/perfschema/t/disabled.def @@ -9,4 +9,4 @@ # Do not use any TAB characters for whitespace. # ############################################################################## - +misc.test : bug#14113704 24/04/2012 Mayank issure reported causing failure. diff --git a/storage/archive/azio.c b/storage/archive/azio.c index 5fc9bc875f8..ec4b5bcb7cd 100644 --- a/storage/archive/azio.c +++ b/storage/archive/azio.c @@ -37,6 +37,8 @@ void putLong(File file, uLong x); uLong getLong(azio_stream *s); void read_header(azio_stream *s, unsigned char *buffer); +extern PSI_file_key arch_key_file_data; + /* =========================================================================== Opens a gzip (.gz) file for reading or writing. The mode parameter is as in fopen ("rb" or "wb"). The file is given either by file descriptor @@ -113,7 +115,7 @@ int az_open (azio_stream *s, const char *path, int Flags, File fd) s->stream.avail_out = AZ_BUFSIZE_WRITE; errno = 0; - s->file = fd < 0 ? my_open(path, Flags, MYF(0)) : fd; + s->file = fd < 0 ? mysql_file_open(arch_key_file_data, path, Flags, MYF(0)) : fd; DBUG_EXECUTE_IF("simulate_archive_open_failure", { if (s->file >= 0) @@ -235,8 +237,8 @@ int get_byte(s) if (s->stream.avail_in == 0) { errno = 0; - s->stream.avail_in= (uInt) my_read(s->file, (uchar *)s->inbuf, - AZ_BUFSIZE_READ, MYF(0)); + s->stream.avail_in= (uInt) mysql_file_read(s->file, (uchar *)s->inbuf, + AZ_BUFSIZE_READ, MYF(0)); if (s->stream.avail_in == 0) { s->z_eof = 1; @@ -277,7 +279,8 @@ void check_header(azio_stream *s) if (len < 2) { if (len) s->inbuf[0] = s->stream.next_in[0]; errno = 0; - len = (uInt)my_read(s->file, (uchar *)s->inbuf + len, AZ_BUFSIZE_READ >> len, MYF(0)); + len = (uInt)mysql_file_read(s->file, (uchar *)s->inbuf + len, + AZ_BUFSIZE_READ >> len, MYF(0)); if (len == (uInt)-1) s->z_err = Z_ERRNO; s->stream.avail_in += len; s->stream.next_in = s->inbuf; @@ -468,7 +471,8 @@ unsigned int ZEXPORT azread ( azio_stream *s, voidp buf, size_t len, int *error) if (s->stream.avail_out > 0) { s->stream.avail_out -= - (uInt)my_read(s->file, (uchar *)next_out, s->stream.avail_out, MYF(0)); + (uInt)mysql_file_read(s->file, (uchar *)next_out, + s->stream.avail_out, MYF(0)); } len -= s->stream.avail_out; s->in += len; @@ -481,7 +485,8 @@ unsigned int ZEXPORT azread ( azio_stream *s, voidp buf, size_t len, int *error) if (s->stream.avail_in == 0 && !s->z_eof) { errno = 0; - s->stream.avail_in = (uInt)my_read(s->file, (uchar *)s->inbuf, AZ_BUFSIZE_READ, MYF(0)); + s->stream.avail_in = (uInt)mysql_file_read(s->file, (uchar *)s->inbuf, + AZ_BUFSIZE_READ, MYF(0)); if (s->stream.avail_in == 0) { s->z_eof = 1; @@ -548,8 +553,8 @@ unsigned int azwrite (azio_stream *s, const voidp buf, unsigned int len) { s->stream.next_out = s->outbuf; - if (my_write(s->file, (uchar *)s->outbuf, AZ_BUFSIZE_WRITE, - MYF(0)) != AZ_BUFSIZE_WRITE) + if (mysql_file_write(s->file, (uchar *)s->outbuf, AZ_BUFSIZE_WRITE, + MYF(0)) != AZ_BUFSIZE_WRITE) { s->z_err = Z_ERRNO; break; @@ -596,7 +601,7 @@ int do_flush (azio_stream *s, int flush) if (len != 0) { s->check_point= my_tell(s->file, MYF(0)); - if ((uInt)my_write(s->file, (uchar *)s->outbuf, len, MYF(0)) != len) + if ((uInt)mysql_file_write(s->file, (uchar *)s->outbuf, len, MYF(0)) != len) { s->z_err = Z_ERRNO; return Z_ERRNO; @@ -783,7 +788,7 @@ void putLong (File file, uLong x) for (n = 0; n < 4; n++) { buffer[0]= (int)(x & 0xff); - my_write(file, buffer, 1, MYF(0)); + mysql_file_write(file, buffer, 1, MYF(0)); x >>= 8; } } diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc index d040d694e1f..dba647b8d1a 100644 --- a/storage/archive/ha_archive.cc +++ b/storage/archive/ha_archive.cc @@ -114,6 +114,8 @@ static HASH archive_open_tables; #define DATA_BUFFER_SIZE 2 // Size of the data used in the data file #define ARCHIVE_CHECK_HEADER 254 // The number we use to determine corruption +extern "C" PSI_file_key arch_key_file_data; + /* Static declarations for handerton */ static handler *archive_create_handler(handlerton *hton, TABLE_SHARE *table, @@ -159,6 +161,14 @@ static PSI_mutex_info all_archive_mutexes[]= { &az_key_mutex_ARCHIVE_SHARE_mutex, "ARCHIVE_SHARE::mutex", 0} }; +PSI_file_key arch_key_file_metadata, arch_key_file_data, arch_key_file_frm; +static PSI_file_info all_archive_files[]= +{ + { &arch_key_file_metadata, "metadata", 0}, + { &arch_key_file_data, "data", 0}, + { &arch_key_file_frm, "FRM", 0} +}; + static void init_archive_psi_keys(void) { const char* category= "archive"; @@ -169,6 +179,9 @@ static void init_archive_psi_keys(void) count= array_elements(all_archive_mutexes); PSI_server->register_mutex(category, all_archive_mutexes, count); + + count= array_elements(all_archive_files); + PSI_server->register_file(category, all_archive_files, count); } #endif /* HAVE_PSI_INTERFACE */ @@ -262,7 +275,7 @@ int archive_discover(handlerton *hton, THD* thd, const char *db, build_table_filename(az_file, sizeof(az_file) - 1, db, name, ARZ, 0); - if (!(my_stat(az_file, &file_stat, MYF(0)))) + if (!(mysql_file_stat(arch_key_file_data, az_file, &file_stat, MYF(0)))) goto err; if (!(azopen(&frm_stream, az_file, O_RDONLY|O_BINARY))) @@ -712,7 +725,7 @@ int ha_archive::create(const char *name, TABLE *table_arg, There is a chance that the file was "discovered". In this case just use whatever file is there. */ - if (!(my_stat(name_buff, &file_stat, MYF(0)))) + if (!(mysql_file_stat(arch_key_file_data, name_buff, &file_stat, MYF(0)))) { my_errno= 0; if (!(azopen(&create_stream, name_buff, O_CREAT|O_RDWR|O_BINARY))) @@ -729,19 +742,19 @@ int ha_archive::create(const char *name, TABLE *table_arg, /* Here is where we open up the frm and pass it to archive to store */ - if ((frm_file= my_open(name_buff, O_RDONLY, MYF(0))) > 0) + if ((frm_file= mysql_file_open(arch_key_file_frm, name_buff, O_RDONLY, MYF(0))) >= 0) { if (!mysql_file_fstat(frm_file, &file_stat, MYF(MY_WME))) { frm_ptr= (uchar *)my_malloc(sizeof(uchar) * file_stat.st_size, MYF(0)); if (frm_ptr) { - my_read(frm_file, frm_ptr, file_stat.st_size, MYF(0)); + mysql_file_read(frm_file, frm_ptr, file_stat.st_size, MYF(0)); azwrite_frm(&create_stream, (char *)frm_ptr, file_stat.st_size); my_free(frm_ptr); } } - my_close(frm_file, MYF(0)); + mysql_file_close(frm_file, MYF(0)); } if (create_info->comment.str) @@ -1607,7 +1620,7 @@ int ha_archive::info(uint flag) { MY_STAT file_stat; // Stat information for the data file - (void) my_stat(share->data_file_name, &file_stat, MYF(MY_WME)); + (void) mysql_file_stat(arch_key_file_data, share->data_file_name, &file_stat, MYF(MY_WME)); if (flag & HA_STATUS_TIME) stats.update_time= (ulong) file_stat.st_mtime; From b2888adb701c1cfd1db137937d50f571fe8366d4 Mon Sep 17 00:00:00 2001 From: Mayank Prasad Date: Fri, 25 May 2012 15:44:27 +0530 Subject: [PATCH 30/90] PB2 Failure Fix : Disabled the test case in correct manner. --- mysql-test/suite/perfschema/t/disabled.def | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/suite/perfschema/t/disabled.def b/mysql-test/suite/perfschema/t/disabled.def index 6c496ec6d95..8a843692d2a 100644 --- a/mysql-test/suite/perfschema/t/disabled.def +++ b/mysql-test/suite/perfschema/t/disabled.def @@ -9,4 +9,4 @@ # Do not use any TAB characters for whitespace. # ############################################################################## -misc.test : bug#14113704 24/04/2012 Mayank issure reported causing failure. +misc : bug#14113704 24/04/2012 Mayank issue reported causing failure. From b2c3acc987193775d392e763c8b9eef3da7c65a8 Mon Sep 17 00:00:00 2001 From: Praveenkumar Hulakund Date: Mon, 28 May 2012 11:14:43 +0530 Subject: [PATCH 31/90] Bug#14003080:65104: MAX_USER_CONNECTIONS WITH PROCESSLIST EMPTY Analysis: ------------- If server is started with limit of MAX_CONNECTIONS and MAX_USER_CONNECTIONS then only MAX_USER_CONNECTIONS of any particular users can be connected to server and total MAX_CONNECTIONS of client can be connected to server. Server maintains a counter for total CONNECTIONS and total CONNECTIONS from particular user. Here, MAX_CONNECTIONS of connections are created to server. Out of this MAX_CONNECTIONS, connections from particular user (say USER1) are also created. The connections from USER1 is lesser than MAX_USER_CONNECTIONS. After that there was one more connection request from USER1. Since USER1 can still create connections as he havent reached MAX_USER_CONNECTIONS, server increments counter of CONNECTIONS per user. As server already has MAX_CONNECTIONS of connections, next check to total CONNECTION count fails. In this case control is returned WITHOUT decrementing the CONNECTIONS per user. So the counter per user CONNECTIONS goes on incrementing for each attempt until current connections are closed. And because of this counter per CONNECTIONS reached MAX_USER_CONNECTIONS. So, next connections form USER1 user always returns with MAX_USER_CONNECTION limit error, even when total connection to sever are less than MAX_CONNECTIONS. Fix: ------------- This issue is occurred because of not handling counters properly in the server. Changed the code to handle per user connection counters properly. --- sql/sql_acl.cc | 19 +++---- sql/sql_class.cc | 86 ++++++++++++++++++++++++++++- sql/sql_class.h | 21 +++++++- sql/sql_connect.cc | 132 +++++++++++++++++++++++++++------------------ sql/sql_connect.h | 3 +- sql/sql_parse.cc | 7 +-- sql/sys_vars.h | 5 +- 7 files changed, 200 insertions(+), 73 deletions(-) diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 3438e60683f..d3715fd2312 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -7810,8 +7810,6 @@ get_cached_table_access(GRANT_INTERNAL_INFO *grant_internal_info, #undef HAVE_OPENSSL #ifdef NO_EMBEDDED_ACCESS_CHECKS #define initialized 0 -#define decrease_user_connections(X) /* nothing */ -#define check_for_max_user_connections(X, Y) 0 #endif #endif #ifndef HAVE_OPENSSL @@ -9297,7 +9295,7 @@ acl_authenticate(THD *thd, uint connect_errors, uint com_change_user_pkt_len) mpvio.packets_read++; // take COM_CHANGE_USER packet into account /* Clear variables that are allocated */ - thd->user_connect= 0; + thd->set_user_connect(NULL); if (parse_com_change_user_packet(&mpvio, com_change_user_pkt_len)) { @@ -9460,11 +9458,11 @@ acl_authenticate(THD *thd, uint connect_errors, uint com_change_user_pkt_len) else sctx->skip_grants(); - if (thd->user_connect && - (thd->user_connect->user_resources.conn_per_hour || - thd->user_connect->user_resources.user_conn || + const USER_CONN *uc; + if ((uc= thd->get_user_connect()) && + (uc->user_resources.conn_per_hour || uc->user_resources.user_conn || global_system_variables.max_user_connections) && - check_for_max_user_connections(thd, thd->user_connect)) + check_for_max_user_connections(thd, uc)) { DBUG_RETURN(1); // The error is set in check_for_max_user_connections() } @@ -9486,6 +9484,7 @@ acl_authenticate(THD *thd, uint connect_errors, uint com_change_user_pkt_len) mysql_mutex_unlock(&LOCK_connection_count); if (!count_ok) { // too many connections + release_user_connection(thd); my_error(ER_CON_COUNT_ERROR, MYF(0)); DBUG_RETURN(1); } @@ -9504,11 +9503,7 @@ acl_authenticate(THD *thd, uint connect_errors, uint com_change_user_pkt_len) if (mysql_change_db(thd, &mpvio.db, FALSE)) { /* mysql_change_db() has pushed the error message. */ - if (thd->user_connect) - { - decrease_user_connections(thd->user_connect); - thd->user_connect= 0; - } + release_user_connection(thd); DBUG_RETURN(1); } } diff --git a/sql/sql_class.cc b/sql/sql_class.cc index bdcb85218c3..7e93157c69e 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -852,7 +852,7 @@ THD::THD() #if defined(ENABLED_PROFILING) profiling.set_thd(this); #endif - user_connect=(USER_CONN *)0; + m_user_connect= NULL; my_hash_init(&user_vars, system_charset_info, USER_VARS_HASH_SIZE, 0, 0, (my_hash_get_key) get_var_key, (my_hash_free_key) free_user_var, 0); @@ -5009,3 +5009,87 @@ bool Discrete_intervals_list::append(Discrete_interval *new_interval) } #endif /* !defined(MYSQL_CLIENT) */ + +void THD::set_user_connect(USER_CONN *uc) +{ + DBUG_ENTER("THD::set_user_connect"); + + m_user_connect= uc; + + DBUG_VOID_RETURN; +} + +void THD::increment_user_connections_counter() +{ + DBUG_ENTER("THD::increment_user_connections_counter"); + + m_user_connect->connections++; + + DBUG_VOID_RETURN; +} + +void THD::decrement_user_connections_counter() +{ + DBUG_ENTER("THD::decrement_user_connections_counter"); + + DBUG_ASSERT(m_user_connect->connections > 0); + m_user_connect->connections--; + + DBUG_VOID_RETURN; +} + +void THD::increment_con_per_hour_counter() +{ + DBUG_ENTER("THD::decrement_conn_per_hour_counter"); + + m_user_connect->conn_per_hour++; + + DBUG_VOID_RETURN; +} + +void THD::increment_updates_counter() +{ + DBUG_ENTER("THD::increment_updates_counter"); + + m_user_connect->updates++; + + DBUG_VOID_RETURN; +} + +void THD::increment_questions_counter() +{ + DBUG_ENTER("THD::increment_updates_counter"); + + m_user_connect->questions++; + + DBUG_VOID_RETURN; +} + +/* + Reset per-hour user resource limits when it has been more than + an hour since they were last checked + + SYNOPSIS: + time_out_user_resource_limits() + + NOTE: + This assumes that the LOCK_user_conn mutex has been acquired, so it is + safe to test and modify members of the USER_CONN structure. +*/ +void THD::time_out_user_resource_limits() +{ + mysql_mutex_assert_owner(&LOCK_user_conn); + ulonglong check_time= start_utime; + DBUG_ENTER("time_out_user_resource_limits"); + + /* If more than a hour since last check, reset resource checking */ + if (check_time - m_user_connect->reset_utime >= LL(3600000000)) + { + m_user_connect->questions=1; + m_user_connect->updates=0; + m_user_connect->conn_per_hour=0; + m_user_connect->reset_utime= check_time; + } + + DBUG_VOID_RETURN; +} diff --git a/sql/sql_class.h b/sql/sql_class.h index bffa490ebe3..d799980f8e1 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1960,7 +1960,26 @@ public: */ ha_rows examined_row_count; - USER_CONN *user_connect; +private: + USER_CONN *m_user_connect; + +public: + void set_user_connect(USER_CONN *uc); + const USER_CONN* get_user_connect() + { return m_user_connect; } + + void increment_user_connections_counter(); + void decrement_user_connections_counter(); + + void increment_con_per_hour_counter(); + + void increment_updates_counter(); + + void increment_questions_counter(); + + void time_out_user_resource_limits(); + +public: CHARSET_INFO *db_charset; Warning_info *warning_info; Diagnostics_area *stmt_da; diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 366dec733c4..cdb0f5de049 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -105,8 +105,8 @@ int get_or_create_user_conn(THD *thd, const char *user, goto end; } } - thd->user_connect=uc; - uc->connections++; + thd->set_user_connect(uc); + thd->increment_user_connections_counter(); end: mysql_mutex_unlock(&LOCK_user_conn); return return_val; @@ -131,7 +131,7 @@ end: 1 error */ -int check_for_max_user_connections(THD *thd, USER_CONN *uc) +int check_for_max_user_connections(THD *thd, const USER_CONN *uc) { int error=0; DBUG_ENTER("check_for_max_user_connections"); @@ -145,7 +145,7 @@ int check_for_max_user_connections(THD *thd, USER_CONN *uc) error=1; goto end; } - time_out_user_resource_limits(thd, uc); + thd->time_out_user_resource_limits(); if (uc->user_resources.user_conn && uc->user_resources.user_conn < uc->connections) { @@ -164,18 +164,18 @@ int check_for_max_user_connections(THD *thd, USER_CONN *uc) error=1; goto end; } - uc->conn_per_hour++; + thd->increment_con_per_hour_counter(); end: if (error) { - uc->connections--; // no need for decrease_user_connections() here + thd->decrement_user_connections_counter(); /* The thread may returned back to the pool and assigned to a user that doesn't have a limit. Ensure the user is not using resources of someone else. */ - thd->user_connect= NULL; + thd->set_user_connect(NULL); } mysql_mutex_unlock(&LOCK_user_conn); DBUG_RETURN(error); @@ -214,38 +214,37 @@ void decrease_user_connections(USER_CONN *uc) DBUG_VOID_RETURN; } - /* - Reset per-hour user resource limits when it has been more than - an hour since they were last checked + Decrements user connections count from the USER_CONN held by THD + And removes USER_CONN from the hash if no body else is using it. - SYNOPSIS: - time_out_user_resource_limits() - thd Thread handler - uc User connection details - - NOTE: - This assumes that the LOCK_user_conn mutex has been acquired, so it is - safe to test and modify members of the USER_CONN structure. -*/ - -void time_out_user_resource_limits(THD *thd, USER_CONN *uc) + SYNOPSIS + release_user_connection() + THD Thread context object. + */ +void release_user_connection(THD *thd) { - ulonglong check_time= thd->start_utime; - DBUG_ENTER("time_out_user_resource_limits"); + const USER_CONN *uc= thd->get_user_connect(); + DBUG_ENTER("release_user_connection"); - /* If more than a hour since last check, reset resource checking */ - if (check_time - uc->reset_utime >= LL(3600000000)) + if (uc) { - uc->questions=1; - uc->updates=0; - uc->conn_per_hour=0; - uc->reset_utime= check_time; + mysql_mutex_lock(&LOCK_user_conn); + DBUG_ASSERT(uc->connections > 0); + thd->decrement_user_connections_counter(); + if (!uc->connections && !mqh_used) + { + /* Last connection for user; Delete it */ + (void) my_hash_delete(&hash_user_connections,(uchar*) uc); + } + mysql_mutex_unlock(&LOCK_user_conn); + thd->set_user_connect(NULL); } DBUG_VOID_RETURN; } + /* Check if maximum queries per hour limit has been reached returns 0 if OK. @@ -254,40 +253,70 @@ void time_out_user_resource_limits(THD *thd, USER_CONN *uc) bool check_mqh(THD *thd, uint check_command) { bool error= 0; - USER_CONN *uc=thd->user_connect; + const USER_CONN *uc=thd->get_user_connect(); DBUG_ENTER("check_mqh"); DBUG_ASSERT(uc != 0); mysql_mutex_lock(&LOCK_user_conn); - time_out_user_resource_limits(thd, uc); + thd->time_out_user_resource_limits(); /* Check that we have not done too many questions / hour */ - if (uc->user_resources.questions && - uc->questions++ >= uc->user_resources.questions) + if (uc->user_resources.questions) { - my_error(ER_USER_LIMIT_REACHED, MYF(0), uc->user, "max_questions", - (long) uc->user_resources.questions); - error=1; - goto end; + thd->increment_questions_counter(); + if ((uc->questions - 1) >= uc->user_resources.questions) + { + my_error(ER_USER_LIMIT_REACHED, MYF(0), uc->user, "max_questions", + (long) uc->user_resources.questions); + error=1; + goto end; + } } if (check_command < (uint) SQLCOM_END) { /* Check that we have not done too many updates / hour */ if (uc->user_resources.updates && - (sql_command_flags[check_command] & CF_CHANGES_DATA) && - uc->updates++ >= uc->user_resources.updates) + (sql_command_flags[check_command] & CF_CHANGES_DATA)) { - my_error(ER_USER_LIMIT_REACHED, MYF(0), uc->user, "max_updates", - (long) uc->user_resources.updates); - error=1; - goto end; + thd->increment_updates_counter(); + if ((uc->updates - 1) >= uc->user_resources.updates) + { + my_error(ER_USER_LIMIT_REACHED, MYF(0), uc->user, "max_updates", + (long) uc->user_resources.updates); + error=1; + goto end; + } } } end: mysql_mutex_unlock(&LOCK_user_conn); DBUG_RETURN(error); } +#else + +int check_for_max_user_connections(THD *thd, const USER_CONN *uc) +{ + return 0; +} + +void decrease_user_connections(USER_CONN *uc) +{ + return; +} + +void release_user_connection(THD *thd) +{ + const USER_CONN *uc= thd->get_user_connect(); + DBUG_ENTER("release_user_connection"); + + if (uc) + { + thd->set_user_connect(NULL); + } + + DBUG_VOID_RETURN; +} #endif /* NO_EMBEDDED_ACCESS_CHECKS */ @@ -609,16 +638,13 @@ void end_connection(THD *thd) { NET *net= &thd->net; plugin_thdvar_cleanup(thd); - if (thd->user_connect) - { - decrease_user_connections(thd->user_connect); - /* - The thread may returned back to the pool and assigned to a user - that doesn't have a limit. Ensure the user is not using resources - of someone else. - */ - thd->user_connect= NULL; - } + + /* + The thread may returned back to the pool and assigned to a user + that doesn't have a limit. Ensure the user is not using resources + of someone else. + */ + release_user_connection(thd); if (thd->killed || (net->error && net->vio != 0)) { diff --git a/sql/sql_connect.h b/sql/sql_connect.h index df6ac789709..2257a970ffa 100644 --- a/sql/sql_connect.h +++ b/sql/sql_connect.h @@ -33,6 +33,7 @@ void reset_mqh(LEX_USER *lu, bool get_them); bool check_mqh(THD *thd, uint check_command); void time_out_user_resource_limits(THD *thd, USER_CONN *uc); void decrease_user_connections(USER_CONN *uc); +void release_user_connection(THD *thd); bool thd_init_client_charset(THD *thd, uint cs_number); bool setup_connection_thread_globals(THD *thd); bool thd_prepare_connection(THD *thd); @@ -47,6 +48,6 @@ void prepare_new_connection_state(THD* thd); void end_connection(THD *thd); int get_or_create_user_conn(THD *thd, const char *user, const char *host, const USER_RESOURCES *mqh); -int check_for_max_user_connections(THD *thd, USER_CONN *uc); +int check_for_max_user_connections(THD *thd, const USER_CONN *uc); #endif /* SQL_CONNECT_INCLUDED */ diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 3e5dfa43d41..ea07bfce0cb 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -949,7 +949,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, uint save_db_length= thd->db_length; char *save_db= thd->db; - USER_CONN *save_user_connect= thd->user_connect; + USER_CONN *save_user_connect= + const_cast(thd->get_user_connect()); Security_context save_security_ctx= *thd->security_ctx; CHARSET_INFO *save_character_set_client= thd->variables.character_set_client; @@ -964,7 +965,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd, { my_free(thd->security_ctx->user); *thd->security_ctx= save_security_ctx; - thd->user_connect= save_user_connect; + thd->set_user_connect(save_user_connect); thd->reset_db (save_db, save_db_length); thd->variables.character_set_client= save_character_set_client; thd->variables.collation_connection= save_collation_connection; @@ -5583,7 +5584,7 @@ void mysql_parse(THD *thd, char *rawbuf, uint length, if (!err) { #ifndef NO_EMBEDDED_ACCESS_CHECKS - if (mqh_used && thd->user_connect && + if (mqh_used && thd->get_user_connect() && check_mqh(thd, lex->sql_command)) { thd->net.error = 0; diff --git a/sql/sys_vars.h b/sql/sys_vars.h index d9d83ed5615..a69a91f7eb7 100644 --- a/sql/sys_vars.h +++ b/sql/sys_vars.h @@ -799,8 +799,9 @@ public: { } uchar *session_value_ptr(THD *thd, LEX_STRING *base) { - if (thd->user_connect && thd->user_connect->user_resources.user_conn) - return (uchar*) &(thd->user_connect->user_resources.user_conn); + const USER_CONN *uc= thd->get_user_connect(); + if (uc && uc->user_resources.user_conn) + return (uchar*) &(uc->user_resources.user_conn); return global_value_ptr(thd, base); } }; From d8b2d4a0694156848db0862a230d248653f8ebe5 Mon Sep 17 00:00:00 2001 From: Rohit Kalhans Date: Tue, 29 May 2012 12:11:30 +0530 Subject: [PATCH 32/90] Bug#11762667: MYSQLBINLOG IGNORES ERRORS WHILE WRITING OUTPUT Problem: mysqlbinlog exits without any error code in case of file write error. It is because of the fact that the calls to Log_event::print() method does not return a value and the thus any error were being ignored. Resolution: We resolve this problem by checking for the IO_CACHE::error == -1 after every call to Log_event:: print() and terminating the further execution. client/mysqlbinlog.cc: - handled error conditions during event->print() calls - added check for error in end_io_cache() mysys/my_write.c: Added debug code to simulate file write error. error returned will be ENOSPC=> error no space on the disk sql/log_event.cc: Added debug code to simulate file write error, by reducing the size of io cache. --- client/mysqlbinlog.cc | 21 ++++++++++++++++++++- mysys/my_write.c | 12 +++++++++++- sql/log_event.cc | 6 ++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index db48675ade2..dd09e7a0938 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -690,6 +690,7 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, DBUG_ENTER("process_event"); print_event_info->short_form= short_form; Exit_status retval= OK_CONTINUE; + IO_CACHE *const head= &print_event_info->head_cache; /* Format events are not concerned by --offset and such, we always need to @@ -753,6 +754,8 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, } else ev->print(result_file, print_event_info); + if (head->error == -1) + goto err; break; case CREATE_FILE_EVENT: @@ -804,6 +807,8 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, output of Append_block_log_event::print is only a comment. */ ev->print(result_file, print_event_info); + if (head->error == -1) + goto err; if ((retval= load_processor.process((Append_block_log_event*) ev)) != OK_CONTINUE) goto end; @@ -812,6 +817,8 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, case EXEC_LOAD_EVENT: { ev->print(result_file, print_event_info); + if (head->error == -1) + goto err; Execute_load_log_event *exv= (Execute_load_log_event*)ev; Create_file_log_event *ce= load_processor.grab_event(exv->file_id); /* @@ -841,6 +848,8 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, print_event_info->common_header_len= glob_description_event->common_header_len; ev->print(result_file, print_event_info); + if (head->error == -1) + goto err; if (!remote_opt) ev->free_temp_buf(); // free memory allocated in dump_local_log_entries else @@ -864,6 +873,8 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, break; case BEGIN_LOAD_QUERY_EVENT: ev->print(result_file, print_event_info); + if (head->error == -1) + goto err; if ((retval= load_processor.process((Begin_load_query_log_event*) ev)) != OK_CONTINUE) goto end; @@ -974,6 +985,8 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, } default: ev->print(result_file, print_event_info); + if (head->error == -1) + goto err; } } @@ -2012,7 +2025,13 @@ err: end: if (fd >= 0) my_close(fd, MYF(MY_WME)); - end_io_cache(file); + /* + Since the end_io_cache() writes to the + file errors may happen. + */ + if (end_io_cache(file)) + retval= ERROR_STOP; + return retval; } diff --git a/mysys/my_write.c b/mysys/my_write.c index f261c768dcb..b545ab776b0 100644 --- a/mysys/my_write.c +++ b/mysys/my_write.c @@ -38,7 +38,17 @@ size_t my_write(int Filedes, const uchar *Buffer, size_t Count, myf MyFlags) for (;;) { - if ((writenbytes= write(Filedes, Buffer, Count)) == Count) + writenbytes= write(Filedes, Buffer, Count); + /** + To simulate the write error set the errno = error code + and the number pf written bytes to -1. + */ + DBUG_EXECUTE_IF ("simulate_file_write_error", + { + errno= ENOSPC; + writenbytes= (size_t) -1; + }); + if (writenbytes == Count) break; if (writenbytes != (size_t) -1) { /* Safeguard */ diff --git a/sql/log_event.cc b/sql/log_event.cc index afcc283a6d1..e7c3419c34f 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -3090,6 +3090,12 @@ void Query_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info) { Write_on_release_cache cache(&print_event_info->head_cache, file); + /** + reduce the size of io cache so that the write function is called + for every call to my_b_write(). + */ + DBUG_EXECUTE_IF ("simulate_file_write_error", + {(&cache)->write_pos= (&cache)->write_end- 500;}); print_query_header(&cache, print_event_info); my_b_write(&cache, (uchar*) query, q_len); my_b_printf(&cache, "\n%s\n", print_event_info->delimiter); From 31a93ea75d00b54326e7f1975dccafdad4e35c5e Mon Sep 17 00:00:00 2001 From: Tor Didriksen Date: Tue, 29 May 2012 10:54:57 +0200 Subject: [PATCH 33/90] Bug#12845091 .EMPTY FILE IN /DATA/TEST PREVENTS USERS FROM DROPPING TEST DB ON 5.5 AND 5.6 --- sql/CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 09672561c11..a3df9e7948b 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -264,7 +264,10 @@ IF(INSTALL_LAYOUT STREQUAL "STANDALONE") # We need to create empty directories (data/test) the installation. # This does not work with current CPack due to http://www.cmake.org/Bug/view.php?id=8767 # Avoid completely empty directories and install dummy file instead. -SET(DUMMY_FILE ${CMAKE_CURRENT_BINARY_DIR}/.empty ) +# Use a file extension so that it will be deleted in case someone does +# 'drop database test' +# See deletable_extentions. +SET(DUMMY_FILE ${CMAKE_CURRENT_BINARY_DIR}/dummy.bak ) FILE(WRITE ${DUMMY_FILE} "") INSTALL(FILES ${DUMMY_FILE} DESTINATION data/test COMPONENT DataFiles) From a2bc9b36696efb97879bc1bd4500156ea52a1b1a Mon Sep 17 00:00:00 2001 From: Annamalai Gurusami Date: Wed, 30 May 2012 10:05:04 +0530 Subject: [PATCH 34/90] Bug #13933132: [ERROR] GOT ERROR -1 WHEN READING TABLE APPEARED WHEN KILLING Suppose there is a query waiting for a lock. If the user kills this query, then "Got error -1 when reading table" error message must not be logged in the server log file. Since this is a user requested interruption, no spurious error message must be logged in the server log. This patch will remove the error message from the log. approved by joh and tatjana --- sql/sql_select.cc | 3 ++- storage/innobase/handler/ha_innodb.cc | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 1cf52e88c12..7c3d2de22bc 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -11791,7 +11791,8 @@ int report_error(TABLE *table, int error) Locking reads can legally return also these errors, do not print them to the .err log */ - if (error != HA_ERR_LOCK_DEADLOCK && error != HA_ERR_LOCK_WAIT_TIMEOUT) + if (error != HA_ERR_LOCK_DEADLOCK && error != HA_ERR_LOCK_WAIT_TIMEOUT + && !table->in_use->killed) sql_print_error("Got error %d when reading table '%s'", error, table->s->path.str); table->file->print_error(error,MYF(0)); diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 8ed082037f0..51b7007145c 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -4893,6 +4893,7 @@ ha_innobase::index_read( ulint ret; DBUG_ENTER("index_read"); + DEBUG_SYNC_C("ha_innobase_index_read_begin"); ut_a(prebuilt->trx == thd_to_trx(user_thd)); ut_ad(key_len != 0 || find_flag != HA_READ_KEY_EXACT); From 96eb519eb77b078f9f96935aacaded44e20ed95c Mon Sep 17 00:00:00 2001 From: Rohit Kalhans Date: Wed, 30 May 2012 13:54:15 +0530 Subject: [PATCH 35/90] Fixing the build failure on Windows debug build. --- sql/log_event.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/sql/log_event.cc b/sql/log_event.cc index e7c3419c34f..a79797e4bc9 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -2852,17 +2852,24 @@ Query_log_event::Query_log_event(const char* buf, uint event_len, sql_parse.cc */ +#if !defined(MYSQL_CLIENT) && defined(HAVE_QUERY_CACHE) if (!(start= data_buf = (Log_event::Byte*) my_malloc(catalog_len + 1 + time_zone_len + 1 + user.length + 1 + host.length + 1 + data_len + 1 -#if !defined(MYSQL_CLIENT) && defined(HAVE_QUERY_CACHE) - + sizeof(size_t)//for db_len - + db_len + 1 - + QUERY_CACHE_FLAGS_SIZE + + sizeof(size_t)//for db_len + + db_len + 1 + + QUERY_CACHE_FLAGS_SIZE, + MYF(MY_WME)))) +#else + if (!(start= data_buf = (Log_event::Byte*) my_malloc(catalog_len + 1 + + time_zone_len + 1 + + user.length + 1 + + host.length + 1 + + data_len + 1, + MYF(MY_WME)))) #endif - , MYF(MY_WME)))) DBUG_VOID_RETURN; if (catalog_len) // If catalog is given { From f20a4c912dd1034d17f094804a15e0f4807922dd Mon Sep 17 00:00:00 2001 From: Tor Didriksen Date: Wed, 30 May 2012 12:47:29 +0200 Subject: [PATCH 37/90] Bug#12845091 .EMPTY FILE IN /DATA/TEST PREVENTS USERS FROM DROPPING TEST DB ON 5.5 AND 5.6 For those who build in-source, we need to change .bzrignore: s/.empty/dummy.bak/ --- .bzrignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bzrignore b/.bzrignore index c54083a4209..655cea20bc5 100644 --- a/.bzrignore +++ b/.bzrignore @@ -3059,7 +3059,7 @@ libmysql/merge_archives_mysqlclient.cmake libmysqld/merge_archives_mysqlserver.cmake libmysqld/mysqlserver_depends.c libmysqld/examples/mysql_embedded -sql/.empty +sql/dummy.bak mysys/thr_lock VERSION.dep info_macros.cmake From 367de4de2d62310fd0546a3fa1fab1e2b69b35b3 Mon Sep 17 00:00:00 2001 From: Nuno Carvalho Date: Wed, 30 May 2012 14:55:13 +0100 Subject: [PATCH 38/90] BUG#14135691: MISSING INITIALIZATION OF MYSQL_BIN_LOG::SYNC_COUNTER MYSQL_BIN_LOG::sync_counter is not initialized on MYSQL_BIN_LOG object creation. Added missing sync_counter initialization. --- sql/log.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/log.cc b/sql/log.cc index 7f629658311..24cee143c71 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -2814,7 +2814,7 @@ const char *MYSQL_LOG::generate_name(const char *log_name, MYSQL_BIN_LOG::MYSQL_BIN_LOG(uint *sync_period) :bytes_written(0), prepared_xids(0), file_id(1), open_count(1), need_start_event(TRUE), - sync_period_ptr(sync_period), + sync_period_ptr(sync_period), sync_counter(0), is_relay_log(0), signal_cnt(0), description_event_for_exec(0), description_event_for_queue(0) { From cf48fcfba33c3c48aa52290a33a7b825e89827c2 Mon Sep 17 00:00:00 2001 From: Marc Alff Date: Thu, 31 May 2012 11:47:13 +0200 Subject: [PATCH 40/90] Bug 14116252 - CANNOT BUILD ARCHIVE ENGINE WHEN WITH_PERFSCHEMA_STORAGE_ENGINE=0 Fixed a build break with compiling without the performance schema, instrumentation should be protected by HAVE_PSI_INTERFACE --- storage/archive/azio.c | 2 ++ storage/archive/ha_archive.cc | 2 ++ 2 files changed, 4 insertions(+) diff --git a/storage/archive/azio.c b/storage/archive/azio.c index ec4b5bcb7cd..15b3434ab32 100644 --- a/storage/archive/azio.c +++ b/storage/archive/azio.c @@ -37,7 +37,9 @@ void putLong(File file, uLong x); uLong getLong(azio_stream *s); void read_header(azio_stream *s, unsigned char *buffer); +#ifdef HAVE_PSI_INTERFACE extern PSI_file_key arch_key_file_data; +#endif /* =========================================================================== Opens a gzip (.gz) file for reading or writing. The mode parameter diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc index dba647b8d1a..24dbaefce27 100644 --- a/storage/archive/ha_archive.cc +++ b/storage/archive/ha_archive.cc @@ -114,7 +114,9 @@ static HASH archive_open_tables; #define DATA_BUFFER_SIZE 2 // Size of the data used in the data file #define ARCHIVE_CHECK_HEADER 254 // The number we use to determine corruption +#ifdef HAVE_PSI_INTERFACE extern "C" PSI_file_key arch_key_file_data; +#endif /* Static declarations for handerton */ static handler *archive_create_handler(handlerton *hton, From 1c0388a5be8346a0a2c0e00caaf2a9c11f26830c Mon Sep 17 00:00:00 2001 From: Jon Olav Hauglid Date: Fri, 1 Jun 2012 09:31:24 +0200 Subject: [PATCH 42/90] Bug#13982017: ALTER TABLE RENAME ENDS UP WITH ERROR 1050 (42S01) Fixed by backport of: ------------------------------------------------------------ revno: 3402.50.156 committer: Jon Olav Hauglid branch nick: mysql-trunk-test timestamp: Wed 2012-02-08 14:10:23 +0100 message: Bug#13417754 ASSERT IN ROW_DROP_DATABASE_FOR_MYSQL DURING DROP SCHEMA This assert could be triggered if an InnoDB table was being moved to a different database using ALTER TABLE ... RENAME, while this database concurrently was being dropped by DROP DATABASE. The reason for the problem was that no metadata lock was taken on the target database by ALTER TABLE ... RENAME. DROP DATABASE was therefore not blocked and could remove the database while ALTER TABLE ... RENAME was executing. This could cause the assert in InnoDB to be triggered. This patch fixes the problem by taking a IX metadata lock on the target database before ALTER TABLE ... RENAME starts moving a table to a different database. Note that this problem did not occur with RENAME TABLE which already takes the correct metadata locks. Also note that this patch slightly changes the behavior of ALTER TABLE ... RENAME. Before, the statement would abort and return an error if a lock on the target table name could not be taken immediately. With this patch, ALTER TABLE ... RENAME will instead block and wait until the lock can be taken (or until we get a lock timeout). This also means that it is possible to get ER_LOCK_DEADLOCK errors in this situation since we allow ALTER TABLE ... RENAME to wait and not just abort immediately. --- mysql-test/r/create-big.result | 4 ++-- mysql-test/t/create-big.test | 27 ++++++++++++++++++++++---- sql/sql_table.cc | 28 ++++++++++++++++++++------- storage/innobase/handler/ha_innodb.cc | 3 +++ 4 files changed, 49 insertions(+), 13 deletions(-) diff --git a/mysql-test/r/create-big.result b/mysql-test/r/create-big.result index 34293d7e5cd..4cce5d8618c 100644 --- a/mysql-test/r/create-big.result +++ b/mysql-test/r/create-big.result @@ -53,8 +53,8 @@ set debug_sync='create_table_select_before_create SIGNAL parked WAIT_FOR go'; create table t1 select 1 as i;; set debug_sync='now WAIT_FOR parked'; alter table t3 rename to t1; -ERROR 42S01: Table 't1' already exists set debug_sync='now SIGNAL go'; +ERROR 42S01: Table 't1' already exists show create table t1; Table Create Table t1 CREATE TABLE `t1` ( @@ -65,8 +65,8 @@ set debug_sync='create_table_select_before_create SIGNAL parked WAIT_FOR go'; create table t1 select 1 as i;; set debug_sync='now WAIT_FOR parked'; alter table t3 rename to t1, add k int; -ERROR 42S01: Table 't1' already exists set debug_sync='now SIGNAL go'; +ERROR 42S01: Table 't1' already exists show create table t1; Table Create Table t1 CREATE TABLE `t1` ( diff --git a/mysql-test/t/create-big.test b/mysql-test/t/create-big.test index d487608f7e1..8d916f8da82 100644 --- a/mysql-test/t/create-big.test +++ b/mysql-test/t/create-big.test @@ -132,11 +132,20 @@ set debug_sync='create_table_select_before_create SIGNAL parked WAIT_FOR go'; --send create table t1 select 1 as i; connection addconroot1; set debug_sync='now WAIT_FOR parked'; ---error ER_TABLE_EXISTS_ERROR -alter table t3 rename to t1; +--send alter table t3 rename to t1 +connection addconroot2; +# Wait until the above ALTER TABLE RENAME is blocked due to CREATE +let $wait_condition= + select count(*) = 1 from information_schema.processlist + where state = "Waiting for table metadata lock" and + info = "alter table t3 rename to t1"; +--source include/wait_condition.inc set debug_sync='now SIGNAL go'; connection default; --reap +connection addconroot1; +--error ER_TABLE_EXISTS_ERROR +--reap connection default; show create table t1; drop table t1; @@ -146,11 +155,21 @@ set debug_sync='create_table_select_before_create SIGNAL parked WAIT_FOR go'; --send create table t1 select 1 as i; connection addconroot1; set debug_sync='now WAIT_FOR parked'; ---error ER_TABLE_EXISTS_ERROR -alter table t3 rename to t1, add k int; +--send alter table t3 rename to t1, add k int +connection addconroot2; +# Wait until the above ALTER TABLE RENAME is blocked due to CREATE +let $wait_condition= + select count(*) = 1 from information_schema.processlist + where state = "Waiting for table metadata lock" and + info = "alter table t3 rename to t1, add k int"; +--source include/wait_condition.inc set debug_sync='now SIGNAL go'; connection default; --reap +connection addconroot1; +--error ER_TABLE_EXISTS_ERROR +--reap +connection default; show create table t1; drop table t1,t3; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index c146079fdb3..60ae2ed800b 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -5872,8 +5872,26 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, } else { + MDL_request_list mdl_requests; + MDL_request target_db_mdl_request; + target_mdl_request.init(MDL_key::TABLE, new_db, new_name, MDL_EXCLUSIVE, MDL_TRANSACTION); + mdl_requests.push_front(&target_mdl_request); + + /* + If we are moving the table to a different database, we also + need IX lock on the database name so that the target database + is protected by MDL while the table is moved. + */ + if (new_db != db) + { + target_db_mdl_request.init(MDL_key::SCHEMA, new_db, "", + MDL_INTENTION_EXCLUSIVE, + MDL_TRANSACTION); + mdl_requests.push_front(&target_db_mdl_request); + } + /* Global intention exclusive lock must have been already acquired when table to be altered was open, so there is no need to do it here. @@ -5882,14 +5900,10 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, "", "", MDL_INTENTION_EXCLUSIVE)); - if (thd->mdl_context.try_acquire_lock(&target_mdl_request)) + if (thd->mdl_context.acquire_locks(&mdl_requests, + thd->variables.lock_wait_timeout)) DBUG_RETURN(TRUE); - if (target_mdl_request.ticket == NULL) - { - /* Table exists and is locked by some thread. */ - my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias); - DBUG_RETURN(TRUE); - } + DEBUG_SYNC(thd, "locked_table_name"); /* Table maybe does not exist, but we got an exclusive lock diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 19644ddc966..9f7290f5b2d 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -47,6 +47,7 @@ this program; if not, write to the Free Software Foundation, Inc., #include // PROCESS_ACL #include +#include // DEBUG_SYNC #include #include #include @@ -7691,6 +7692,8 @@ ha_innobase::rename_table( error = innobase_rename_table(trx, from, to, TRUE); + DEBUG_SYNC(thd, "after_innobase_rename_table"); + /* Tell the InnoDB server that there might be work for utility threads: */ From a28a2ca798e8a4912cf1b91b6e71eaa0a9fb8bb7 Mon Sep 17 00:00:00 2001 From: Annamalai Gurusami Date: Fri, 1 Jun 2012 14:12:57 +0530 Subject: [PATCH 43/90] Bug #13933132: [ERROR] GOT ERROR -1 WHEN READING TABLE APPEARED WHEN KILLING Suppose there is a query waiting for a lock. If the user kills this query, then "Got error -1 when reading table" error message must not be logged in the server log file. Since this is a user requested interruption, no spurious error message must be logged in the server log. This patch will remove the error message from the log. approved by joh and tatjana --- sql/sql_select.cc | 3 ++- storage/innobase/handler/ha_innodb.cc | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 1cf52e88c12..7c3d2de22bc 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -11791,7 +11791,8 @@ int report_error(TABLE *table, int error) Locking reads can legally return also these errors, do not print them to the .err log */ - if (error != HA_ERR_LOCK_DEADLOCK && error != HA_ERR_LOCK_WAIT_TIMEOUT) + if (error != HA_ERR_LOCK_DEADLOCK && error != HA_ERR_LOCK_WAIT_TIMEOUT + && !table->in_use->killed) sql_print_error("Got error %d when reading table '%s'", error, table->s->path.str); table->file->print_error(error,MYF(0)); diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 8ed082037f0..51b7007145c 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -4893,6 +4893,7 @@ ha_innobase::index_read( ulint ret; DBUG_ENTER("index_read"); + DEBUG_SYNC_C("ha_innobase_index_read_begin"); ut_a(prebuilt->trx == thd_to_trx(user_thd)); ut_ad(key_len != 0 || find_flag != HA_READ_KEY_EXACT); From 6e2ce8739c76fff5d5cf6ef9b7c9ae9dc157fc21 Mon Sep 17 00:00:00 2001 From: Tor Didriksen Date: Tue, 5 Jun 2012 12:27:20 +0200 Subject: [PATCH 44/90] Bug#13417440 : 63340: ARCHIVE FILE IO NOT INSTRUMENTED Followup patch: wrong result unless archive storage engine is available. --- mysql-test/suite/perfschema/t/query_cache.test | 1 + 1 file changed, 1 insertion(+) diff --git a/mysql-test/suite/perfschema/t/query_cache.test b/mysql-test/suite/perfschema/t/query_cache.test index 8c9e5fcd0ed..08292306a25 100644 --- a/mysql-test/suite/perfschema/t/query_cache.test +++ b/mysql-test/suite/perfschema/t/query_cache.test @@ -6,6 +6,7 @@ --source include/have_query_cache.inc --source include/not_embedded.inc --source include/have_perfschema.inc +--source include/have_archive.inc --disable_warnings drop table if exists t1; From 2b085e1fba410ceaea2585c9cff511a9cfd2f7ae Mon Sep 17 00:00:00 2001 From: Tor Didriksen Date: Tue, 5 Jun 2012 15:53:39 +0200 Subject: [PATCH 45/90] Bug#14051002 VALGRIND: CONDITIONAL JUMP OR MOVE IN RR_CMP / MY_QSORT Patch for 5.1 and 5.5: fix typo in byte comparison in rr_cmp() --- sql/records.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/records.cc b/sql/records.cc index e275db83c93..da876f7554c 100644 --- a/sql/records.cc +++ b/sql/records.cc @@ -631,7 +631,7 @@ static int rr_cmp(uchar *a,uchar *b) if (a[4] != b[4]) return (int) a[4] - (int) b[4]; if (a[5] != b[5]) - return (int) a[1] - (int) b[5]; + return (int) a[5] - (int) b[5]; if (a[6] != b[6]) return (int) a[6] - (int) b[6]; return (int) a[7] - (int) b[7]; From 164080e4a8ec5ebb6b466eafe82bfa90e4a59fc0 Mon Sep 17 00:00:00 2001 From: Narayanan Venkateswaran Date: Thu, 7 Jun 2012 19:14:26 +0530 Subject: [PATCH 46/90] WL#6161 Integrating with InnoDB codebase in MySQL 5.5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes in the InnoDB codebase required to compile and integrate the MEB codebase with MySQL 5.5. @ storage/innobase/btr/btr0btr.c Excluded buffer pool usage from MEB build. buf_pool_from_bpage calls are in buf0buf.ic, and the buffer pool functions from that file are disabled in MEB. @ storage/innobase/buf/buf0buf.c Disabling more buffer pool functions unused in MEB. @ storage/innobase/dict/dict0dict.c Disabling dict_ind_free that is unused in MEB. @ storage/innobase/dict/dict0mem.c The include #include "ha_prototypes.h" Was causing conflicts with definitions in my_global.h Linking C executable mysqlbackup libinnodb.a(dict0mem.c.o): In function `dict_mem_foreign_table_name_lookup_set': dict0mem.c:(.text+0x91c): undefined reference to `innobase_get_lower_case_table_names' libinnodb.a(dict0mem.c.o): In function `dict_mem_referenced_table_name_lookup_set': dict0mem.c:(.text+0x9fc): undefined reference to `innobase_get_lower_case_table_names' libinnodb.a(dict0mem.c.o): In function `dict_mem_foreign_table_name_lookup_set': dict0mem.c:(.text+0x96e): undefined reference to `innobase_casedn_str' libinnodb.a(dict0mem.c.o): In function `dict_mem_referenced_table_name_lookup_set': dict0mem.c:(.text+0xa4e): undefined reference to `innobase_casedn_str' collect2: ld returned 1 exit status make[2]: *** [mysqlbackup] Error 1 innobase_get_lower_case_table_names innobase_casedn_str are functions that are part of ha_innodb.cc that is not part of the build dict_mem_foreign_table_name_lookup_set function is not there in the current codebase, meaning we do not use it in MEB. @ storage/innobase/fil/fil0fil.c The srv_fast_shutdown variable is declared in srv0srv.c that is not compiled in the mysqlbackup codebase. This throws an undeclared error. From the Manual --------------- innodb_fast_shutdown -------------------- The InnoDB shutdown mode. The default value is 1 as of MySQL 3.23.50, which causes a “fast� shutdown (the normal type of shutdown). If the value is 0, InnoDB does a full purge and an insert buffer merge before a shutdown. These operations can take minutes, or even hours in extreme cases. If the value is 1, InnoDB skips these operations at shutdown. This ideally does not matter from mysqlbackup @ storage/innobase/ha/ha0ha.c In file included from /home/narayanan/mysql-server/mysql-5.5-meb-rel3.8-innodb-integration-1/storage/innobase/ha/ha0ha.c:34:0: /home/narayanan/mysql-server/mysql-5.5-meb-rel3.8-innodb-integration-1/storage/innobase/include/btr0sea.h:286:17: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token make[2]: *** [CMakeFiles/innodb.dir/home/narayanan/mysql-server/mysql-5.5-meb-rel3.8-innodb-integration-1/storage/innobase/ha/ha0ha.c.o] Error 1 make[1]: *** [CMakeFiles/innodb.dir/all] Error 2 make: *** [all] Error 2 # include "sync0rw.h" is excluded from hotbackup compilation in dict0dict.h This causes extern rw_lock_t* btr_search_latch_temp; to throw a failure because the definition of rw_lock_t is not found. @ storage/innobase/include/buf0buf.h Excluding buffer pool functions that are unused from the MEB codebase. @ storage/innobase/include/buf0buf.ic replicated the exclusion of #include "buf0flu.h" #include "buf0lru.h" #include "buf0rea.h" by looking at the current codebase in /src/innodb @ storage/innobase/include/dict0dict.h dict_table_x_lock_indexes, dict_table_x_unlock_indexes, dict_table_is_corrupted, dict_index_is_corrupted, buf_block_buf_fix_inc_func are unused in MEB and was leading to compilation errors and hence excluded. @ storage/innobase/include/dict0dict.ic dict_table_x_lock_indexes, dict_table_x_unlock_indexes, dict_table_is_corrupted, dict_index_is_corrupted, buf_block_buf_fix_inc_func are unused in MEB and was leading to compilation errors and hence excluded. @ storage/innobase/include/log0log.h /home/narayanan/mysql-server/mysql-5.5-meb-rel3.8-innodb-integration-1/storage/innobase/include/log0log.h: At top level: /home/narayanan/mysql-server/mysql-5.5-meb-rel3.8-innodb-integration-1/storage/innobase/include/log0log.h:767:2: error: expected specifier-qualifier-list before ââ ‚¬Ëœmutex_t’ mutex_t definitions were excluded as seen from ambient code hence excluding definition for log_flush_order_mutex also. @ storage/innobase/include/os0file.h Bug in InnoDB code, create_mode should have been create. @ storage/innobase/include/srv0srv.h In file included from /home/narayanan/mysql-server/mysql-5.5-meb-rel3.8-innodb-integration-1/storage/innobase/buf/buf0buf.c:50:0: /home/narayanan/mysql-server/mysql-5.5-meb-rel3.8-innodb-integration-1/storage/innobase/include/srv0srv.h: At top level: /home/narayanan/mysql-server/mysql-5.5-meb-rel3.8-innodb-integration-1/storage/innobase/include/srv0srv.h:120:16: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘srv_use_native_aio’ srv_use_native_aio - we do not use native aio of the OS anyway from MEB. MEB does not compile InnoDB with this option. Hence disabling it. @ storage/innobase/include/trx0sys.h [ 56%] Building C object CMakeFiles/innodb.dir/home/narayanan/mysql-server/mysql-5.5-meb-rel3.8-innodb-integration-1/storage/innobase/trx/trx0sys.c.o /home/narayanan/mysql-server/mysql-5.5-meb-rel3.8-innodb-integration-1/storage/innobase/trx/trx0sys.c: In function ‘trx_sys_read_file_format_id’: /home/narayanan/mysql-server/mysql-5.5-meb-rel3.8-innodb-integration-1/storage/innobase/trx/trx0sys.c:1499:20: error: ‘TRX_SYS_FILE_FORMAT_TAG_MAGIC_N’ undeclared (first use in this function) /home/narayanan/mysql-server/mysql-5.5-meb-rel3.8-innodb-integration-1/storage/innobase/trx/trx0sys.c:1499:20: note: each undeclared identifier is reported only once for each function it appears in /home/narayanan/mysql-server/mysql-5.5-meb-rel3.8-innodb-integration-1/storage/innobase/trx/trx0sys.c: At top level: /home/narayanan/mysql-server/mysql-5.5-meb-rel3.8-innodb-integration-1/storage/innobase/include/buf0buf.h:607:1: warning: ‘buf_block_buf_fix_inc_func’ declared ‘static’ but never defined make[2]: *** [CMakeFiles/innodb.dir/home/narayanan/mysql-server/mysql-5.5-meb-rel3.8-innodb-integration-1/storage/innobase/trx/trx0sys.c.o] Error 1 unused calls excluded to enable compilation @ storage/innobase/mem/mem0dbg.c excluding #include "ha_prototypes.h" that lead to definitions in ha_innodb.cc @ storage/innobase/os/os0file.c InnoDB not compiled with aio support from MEB anyway. Hence excluding this from the compilation. @ storage/innobase/page/page0zip.c page0zip.c:(.text+0x4e9e): undefined reference to `buf_pool_from_block' collect2: ld returned 1 exit status buf_pool_from_block defined in buf0buf.ic, most of the file is excluded for compilation of MEB @ storage/innobase/ut/ut0dbg.c excluding #include "ha_prototypes.h" since it leads to definitions in ha_innodb.cc innobase_basename(file) is defined in ha_innodb.cc. Hence excluding that also. @ storage/innobase/ut/ut0ut.c cal_tm unused from MEB, was leading to earnings, hence disabling for MEB. --- storage/innobase/btr/btr0btr.c | 4 ++++ storage/innobase/buf/buf0buf.c | 2 +- storage/innobase/dict/dict0dict.c | 14 ++++++++++++-- storage/innobase/dict/dict0mem.c | 4 +++- storage/innobase/fil/fil0fil.c | 2 ++ storage/innobase/ha/ha0ha.c | 16 +--------------- storage/innobase/include/btr0btr.h | 3 +++ storage/innobase/include/btr0types.h | 4 ++++ storage/innobase/include/buf0buf.h | 16 ++++++++-------- storage/innobase/include/buf0buf.ic | 2 ++ storage/innobase/include/dict0dict.h | 5 ++++- storage/innobase/include/dict0dict.ic | 2 ++ storage/innobase/include/log0log.h | 2 +- storage/innobase/include/os0file.h | 2 +- storage/innobase/include/srv0srv.h | 2 +- storage/innobase/include/trx0sys.h | 4 +--- storage/innobase/mem/mem0dbg.c | 4 +++- storage/innobase/os/os0file.c | 2 ++ storage/innobase/page/page0zip.c | 2 ++ storage/innobase/trx/trx0sys.c | 2 +- storage/innobase/ut/ut0dbg.c | 6 ++++-- storage/innobase/ut/ut0ut.c | 8 ++++++++ 22 files changed, 70 insertions(+), 38 deletions(-) diff --git a/storage/innobase/btr/btr0btr.c b/storage/innobase/btr/btr0btr.c index fc3cdaf3cf1..b714219e304 100644 --- a/storage/innobase/btr/btr0btr.c +++ b/storage/innobase/btr/btr0btr.c @@ -42,6 +42,7 @@ Created 6/2/1994 Heikki Tuuri #include "ibuf0ibuf.h" #include "trx0trx.h" +#endif /* UNIV_HOTBACKUP */ /**************************************************************//** Report that an index page is corrupted. */ UNIV_INTERN @@ -64,6 +65,7 @@ btr_corruption_report( buf_page_print(buf_block_get_frame(block), 0, 0); } +#ifndef UNIV_HOTBACKUP #ifdef UNIV_BLOB_DEBUG # include "srv0srv.h" # include "ut0rbt.h" @@ -1575,7 +1577,9 @@ btr_page_reorganize_low( dict_index_t* index, /*!< in: record descriptor */ mtr_t* mtr) /*!< in: mtr */ { +#ifndef UNIV_HOTBACKUP buf_pool_t* buf_pool = buf_pool_from_bpage(&block->page); +#endif /* !UNIV_HOTBACKUP */ page_t* page = buf_block_get_frame(block); page_zip_des_t* page_zip = buf_block_get_page_zip(block); buf_block_t* temp_block; diff --git a/storage/innobase/buf/buf0buf.c b/storage/innobase/buf/buf0buf.c index 1672057d552..fed07129b65 100644 --- a/storage/innobase/buf/buf0buf.c +++ b/storage/innobase/buf/buf0buf.c @@ -302,7 +302,6 @@ struct buf_chunk_struct{ was allocated for the frames */ buf_block_t* blocks; /*!< array of buffer control blocks */ }; -#endif /* !UNIV_HOTBACKUP */ /********************************************************************//** Gets the smallest oldest_modification lsn for any page in the pool. Returns @@ -438,6 +437,7 @@ buf_block_alloc( return(block); } +#endif /* !UNIV_HOTBACKUP */ /********************************************************************//** Calculates a page checksum which is stored to the page when it is written diff --git a/storage/innobase/dict/dict0dict.c b/storage/innobase/dict/dict0dict.c index a59401e8edf..6f2c2caffaf 100644 --- a/storage/innobase/dict/dict0dict.c +++ b/storage/innobase/dict/dict0dict.c @@ -169,6 +169,7 @@ void dict_field_print_low( /*=================*/ const dict_field_t* field); /*!< in: field */ +#ifndef UNIV_HOTBACKUP /*********************************************************************//** Frees a foreign key struct. */ static @@ -182,7 +183,7 @@ and unique key errors */ UNIV_INTERN FILE* dict_foreign_err_file = NULL; /* mutex protecting the foreign and unique error buffers */ UNIV_INTERN mutex_t dict_foreign_err_mutex; - +#endif /* !UNIV_HOTBACKUP */ /******************************************************************//** Makes all characters in a NUL-terminated UTF-8 string lower case. */ UNIV_INTERN @@ -2247,6 +2248,7 @@ dict_index_build_internal_non_clust( return(new_index); } +#ifndef UNIV_HOTBACKUP /*====================== FOREIGN KEY PROCESSING ========================*/ /*********************************************************************//** @@ -2511,6 +2513,7 @@ dict_foreign_find_equiv_index( FALSE/* allow columns to be NULL */)); } +#endif /* !UNIV_HOTBACKUP */ /**********************************************************************//** Returns an index object by matching on the name and column names and if more than one index matches return the index with the max id @@ -2570,6 +2573,7 @@ dict_table_get_index_by_max_id( return(found); } +#ifndef UNIV_HOTBACKUP /**********************************************************************//** Report an error in a foreign key definition. */ static @@ -2735,6 +2739,7 @@ dict_foreign_add_to_cache( return(DB_SUCCESS); } +#endif /* !UNIV_HOTBACKUP */ /*********************************************************************//** Scans from pointer onwards. Stops if is at the start of a copy of 'string' where characters are compared without case sensitivity, and @@ -3214,6 +3219,7 @@ end_of_string: } } +#ifndef UNIV_HOTBACKUP /*********************************************************************//** Finds the highest [number] for foreign key constraints of the table. Looks only at the >= 4.0.18-format id's, which are of the form @@ -4050,7 +4056,7 @@ syntax_error: } /*==================== END OF FOREIGN KEY PROCESSING ====================*/ - +#endif /* !UNIV_HOTBACKUP */ /**********************************************************************//** Returns an index object if it is found in the dictionary cache. Assumes that dict_sys->mutex is already being held. @@ -4411,6 +4417,7 @@ fake_statistics: dict_table_stats_unlock(table, RW_X_LATCH); } +#ifndef UNIV_HOTBACKUP /**********************************************************************//** Prints info of a foreign key constraint. */ static @@ -4441,6 +4448,7 @@ dict_foreign_print_low( fputs(" )\n", stderr); } +#endif /* !UNIV_HOTBACKUP */ /**********************************************************************//** Prints a table data. */ UNIV_INTERN @@ -4622,6 +4630,7 @@ dict_field_print_low( } } +#ifndef UNIV_HOTBACKUP /**********************************************************************//** Outputs info on a foreign key of a table in a format suitable for CREATE TABLE. */ @@ -4810,6 +4819,7 @@ dict_print_info_on_foreign_keys( mutex_exit(&(dict_sys->mutex)); } +#endif /* !UNIV_HOTBACKUP */ /********************************************************************//** Displays the names of the index and the table. */ UNIV_INTERN diff --git a/storage/innobase/dict/dict0mem.c b/storage/innobase/dict/dict0mem.c index 982cca5a796..a8ff501a700 100644 --- a/storage/innobase/dict/dict0mem.c +++ b/storage/innobase/dict/dict0mem.c @@ -33,8 +33,8 @@ Created 1/8/1996 Heikki Tuuri #include "data0type.h" #include "mach0data.h" #include "dict0dict.h" -#include "ha_prototypes.h" /* innobase_casedn_str()*/ #ifndef UNIV_HOTBACKUP +# include "ha_prototypes.h" /* innobase_casedn_str()*/ # include "lock0lock.h" #endif /* !UNIV_HOTBACKUP */ #ifdef UNIV_BLOB_DEBUG @@ -272,6 +272,7 @@ dict_mem_index_create( return(index); } +#ifndef UNIV_HOTBACKUP /**********************************************************************//** Creates and initializes a foreign constraint memory object. @return own: foreign constraint struct */ @@ -346,6 +347,7 @@ dict_mem_referenced_table_name_lookup_set( } } +#endif /* !UNIV_HOTBACKUP */ /**********************************************************************//** Adds a field definition to an index. NOTE: does not take a copy of the column name if the field is a column. The memory occupied diff --git a/storage/innobase/fil/fil0fil.c b/storage/innobase/fil/fil0fil.c index 0a467d40345..23fe76f2281 100644 --- a/storage/innobase/fil/fil0fil.c +++ b/storage/innobase/fil/fil0fil.c @@ -857,8 +857,10 @@ fil_node_close_file( ut_a(node->open); ut_a(node->n_pending == 0); ut_a(node->n_pending_flushes == 0); +#ifndef UNIV_HOTBACKUP ut_a(node->modification_counter == node->flush_counter || srv_fast_shutdown == 2); +#endif /* !UNIV_HOTBACKUP */ ret = os_file_close(node->handle); ut_a(ret); diff --git a/storage/innobase/ha/ha0ha.c b/storage/innobase/ha/ha0ha.c index 65046138275..4be0d296c7c 100644 --- a/storage/innobase/ha/ha0ha.c +++ b/storage/innobase/ha/ha0ha.c @@ -28,6 +28,7 @@ Created 8/22/1994 Heikki Tuuri #include "ha0ha.ic" #endif +#ifndef UNIV_HOTBACKUP #ifdef UNIV_DEBUG # include "buf0buf.h" #endif /* UNIV_DEBUG */ @@ -51,17 +52,13 @@ ha_create_func( hash table: must be a power of 2, or 0 */ { hash_table_t* table; -#ifndef UNIV_HOTBACKUP ulint i; -#endif /* !UNIV_HOTBACKUP */ ut_ad(ut_is_2pow(n_mutexes)); table = hash_create(n); #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG -# ifndef UNIV_HOTBACKUP table->adaptive = TRUE; -# endif /* !UNIV_HOTBACKUP */ #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ /* Creating MEM_HEAP_BTR_SEARCH type heaps can potentially fail, but in practise it never should in this case, hence the asserts. */ @@ -74,7 +71,6 @@ ha_create_func( return(table); } -#ifndef UNIV_HOTBACKUP hash_create_mutexes(table, n_mutexes, mutex_level); table->heaps = mem_alloc(n_mutexes * sizeof(void*)); @@ -83,7 +79,6 @@ ha_create_func( table->heaps[i] = mem_heap_create_in_btr_search(4096); ut_a(table->heaps[i]); } -#endif /* !UNIV_HOTBACKUP */ return(table); } @@ -134,7 +129,6 @@ ha_insert_for_fold_func( while (prev_node != NULL) { if (prev_node->fold == fold) { #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG -# ifndef UNIV_HOTBACKUP if (table->adaptive) { buf_block_t* prev_block = prev_node->block; ut_a(prev_block->frame @@ -143,7 +137,6 @@ ha_insert_for_fold_func( prev_block->n_pointers--; block->n_pointers++; } -# endif /* !UNIV_HOTBACKUP */ prev_node->block = block; #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ @@ -171,11 +164,9 @@ ha_insert_for_fold_func( ha_node_set_data(node, block, data); #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG -# ifndef UNIV_HOTBACKUP if (table->adaptive) { block->n_pointers++; } -# endif /* !UNIV_HOTBACKUP */ #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ node->fold = fold; @@ -217,13 +208,11 @@ ha_delete_hash_node( #endif /* UNIV_SYNC_DEBUG */ ut_ad(btr_search_enabled); #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG -# ifndef UNIV_HOTBACKUP if (table->adaptive) { ut_a(del_node->block->frame = page_align(del_node->data)); ut_a(del_node->block->n_pointers > 0); del_node->block->n_pointers--; } -# endif /* !UNIV_HOTBACKUP */ #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ HASH_DELETE_AND_COMPACT(ha_node_t, next, table, del_node); @@ -264,13 +253,11 @@ ha_search_and_update_if_found_func( if (node) { #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG -# ifndef UNIV_HOTBACKUP if (table->adaptive) { ut_a(node->block->n_pointers > 0); node->block->n_pointers--; new_block->n_pointers++; } -# endif /* !UNIV_HOTBACKUP */ node->block = new_block; #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ @@ -278,7 +265,6 @@ ha_search_and_update_if_found_func( } } -#ifndef UNIV_HOTBACKUP /*****************************************************************//** Removes from the chain determined by fold all nodes whose data pointer points to the page given. */ diff --git a/storage/innobase/include/btr0btr.h b/storage/innobase/include/btr0btr.h index f531b785786..5592995d4b2 100644 --- a/storage/innobase/include/btr0btr.h +++ b/storage/innobase/include/btr0btr.h @@ -92,6 +92,8 @@ insert/delete buffer when the record is not in the buffer pool. */ buffer when the record is not in the buffer pool. */ #define BTR_DELETE 8192 +#endif /* UNIV_HOTBACKUP */ + /**************************************************************//** Report that an index page is corrupted. */ UNIV_INTERN @@ -112,6 +114,7 @@ btr_corruption_report( ut_error; \ } +#ifndef UNIV_HOTBACKUP #ifdef UNIV_BLOB_DEBUG # include "ut0rbt.h" /** An index->blobs entry for keeping track of off-page column references */ diff --git a/storage/innobase/include/btr0types.h b/storage/innobase/include/btr0types.h index 5adc858b931..ef329af1aac 100644 --- a/storage/innobase/include/btr0types.h +++ b/storage/innobase/include/btr0types.h @@ -39,6 +39,8 @@ typedef struct btr_cur_struct btr_cur_t; /** B-tree search information for the adaptive hash index */ typedef struct btr_search_struct btr_search_t; +#ifndef UNIV_HOTBACKUP + /** @brief The latch protecting the adaptive search system This latch protects the @@ -54,6 +56,8 @@ Bear in mind (3) and (4) when using the hash index. */ extern rw_lock_t* btr_search_latch_temp; +#endif /* UNIV_HOTBACKUP */ + /** The latch protecting the adaptive search system */ #define btr_search_latch (*btr_search_latch_temp) diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h index d9e6801eb86..7c81fe0c539 100644 --- a/storage/innobase/include/buf0buf.h +++ b/storage/innobase/include/buf0buf.h @@ -593,34 +593,34 @@ ib_uint64_t buf_block_get_modify_clock( /*=======================*/ buf_block_t* block); /*!< in: block */ -#else /* !UNIV_HOTBACKUP */ -# define buf_block_modify_clock_inc(block) ((void) 0) -#endif /* !UNIV_HOTBACKUP */ /*******************************************************************//** Increments the bufferfix count. */ UNIV_INLINE void buf_block_buf_fix_inc_func( /*=======================*/ -#ifdef UNIV_SYNC_DEBUG +# ifdef UNIV_SYNC_DEBUG const char* file, /*!< in: file name */ ulint line, /*!< in: line */ -#endif /* UNIV_SYNC_DEBUG */ +# endif /* UNIV_SYNC_DEBUG */ buf_block_t* block) /*!< in/out: block to bufferfix */ __attribute__((nonnull)); -#ifdef UNIV_SYNC_DEBUG +# ifdef UNIV_SYNC_DEBUG /** Increments the bufferfix count. @param b in/out: block to bufferfix @param f in: file name where requested @param l in: line number where requested */ # define buf_block_buf_fix_inc(b,f,l) buf_block_buf_fix_inc_func(f,l,b) -#else /* UNIV_SYNC_DEBUG */ +# else /* UNIV_SYNC_DEBUG */ /** Increments the bufferfix count. @param b in/out: block to bufferfix @param f in: file name where requested @param l in: line number where requested */ # define buf_block_buf_fix_inc(b,f,l) buf_block_buf_fix_inc_func(b) -#endif /* UNIV_SYNC_DEBUG */ +# endif /* UNIV_SYNC_DEBUG */ +#else /* !UNIV_HOTBACKUP */ +# define buf_block_modify_clock_inc(block) ((void) 0) +#endif /* !UNIV_HOTBACKUP */ /********************************************************************//** Calculates a page checksum which is stored to the page when it is written to a file. Note that we must be careful to calculate the same value diff --git a/storage/innobase/include/buf0buf.ic b/storage/innobase/include/buf0buf.ic index 917ee5dda84..0d9687e6b2a 100644 --- a/storage/innobase/include/buf0buf.ic +++ b/storage/innobase/include/buf0buf.ic @@ -31,6 +31,7 @@ Created 11/5/1995 Heikki Tuuri *******************************************************/ #include "mtr0mtr.h" +#ifndef UNIV_HOTBACKUP #include "buf0flu.h" #include "buf0lru.h" #include "buf0rea.h" @@ -180,6 +181,7 @@ buf_page_peek_if_too_old( return(!buf_page_peek_if_young(bpage)); } } +#endif /* !UNIV_HOTBACKUP */ /*********************************************************************//** Gets the state of a block. diff --git a/storage/innobase/include/dict0dict.h b/storage/innobase/include/dict0dict.h index 89d6fc66635..b609bce9d41 100644 --- a/storage/innobase/include/dict0dict.h +++ b/storage/innobase/include/dict0dict.h @@ -750,6 +750,7 @@ ulint dict_table_zip_size( /*================*/ const dict_table_t* table); /*!< in: table */ +#ifndef UNIV_HOTBACKUP /*********************************************************************//** Obtain exclusive locks on all index trees of the table. This is to prevent accessing index trees while InnoDB is updating internal metadata for @@ -766,6 +767,7 @@ void dict_table_x_unlock_indexes( /*========================*/ dict_table_t* table); /*!< in: table */ +#endif /* !UNIV_HOTBACKUP */ /********************************************************************//** Checks if a column is in the ordering columns of the clustered index of a table. Column prefixes are treated like whole columns. @@ -1251,7 +1253,7 @@ UNIV_INTERN void dict_close(void); /*============*/ - +#ifndef UNIV_HOTBACKUP /**********************************************************************//** Check whether the table is corrupted. @return nonzero for corrupted table, zero for valid tables */ @@ -1272,6 +1274,7 @@ dict_index_is_corrupted( const dict_index_t* index) /*!< in: index */ __attribute__((nonnull, pure, warn_unused_result)); +#endif /* !UNIV_HOTBACKUP */ /**********************************************************************//** Flags an index and table corrupted both in the data dictionary cache and in the system table SYS_INDEXES. */ diff --git a/storage/innobase/include/dict0dict.ic b/storage/innobase/include/dict0dict.ic index 7533ce01401..faa28959c59 100644 --- a/storage/innobase/include/dict0dict.ic +++ b/storage/innobase/include/dict0dict.ic @@ -491,6 +491,7 @@ dict_table_zip_size( return(dict_table_flags_to_zip_size(table->flags)); } +#ifndef UNIV_HOTBACKUP /*********************************************************************//** Obtain exclusive locks on all index trees of the table. This is to prevent accessing index trees while InnoDB is updating internal metadata for @@ -533,6 +534,7 @@ dict_table_x_unlock_indexes( rw_lock_x_unlock(dict_index_get_lock(index)); } } +#endif /* !UNIV_HOTBACKUP */ /********************************************************************//** Gets the number of fields in the internal representation of an index, including fields added by the dictionary system. diff --git a/storage/innobase/include/log0log.h b/storage/innobase/include/log0log.h index f2ab6a9898d..30250d4fd27 100644 --- a/storage/innobase/include/log0log.h +++ b/storage/innobase/include/log0log.h @@ -762,7 +762,6 @@ struct log_struct{ buffer */ #ifndef UNIV_HOTBACKUP mutex_t mutex; /*!< mutex protecting the log */ -#endif /* !UNIV_HOTBACKUP */ mutex_t log_flush_order_mutex;/*!< mutex to serialize access to the flush list when we are putting @@ -772,6 +771,7 @@ struct log_struct{ mtr_commit and still ensure that insertions in the flush_list happen in the LSN order. */ +#endif /* !UNIV_HOTBACKUP */ byte* buf_ptr; /* unaligned log buffer */ byte* buf; /*!< log buffer */ ulint buf_size; /*!< log buffer size in bytes */ diff --git a/storage/innobase/include/os0file.h b/storage/innobase/include/os0file.h index fb13120a481..8ef0906ff5f 100644 --- a/storage/innobase/include/os0file.h +++ b/storage/innobase/include/os0file.h @@ -309,7 +309,7 @@ to original un-instrumented file I/O APIs */ os_file_create_func(name, create, purpose, type, success) # define os_file_create_simple(key, name, create, access, success) \ - os_file_create_simple_func(name, create_mode, access, success) + os_file_create_simple_func(name, create, access, success) # define os_file_create_simple_no_error_handling( \ key, name, create_mode, access, success) \ diff --git a/storage/innobase/include/srv0srv.h b/storage/innobase/include/srv0srv.h index ed2f4672a99..5290ef5fe11 100644 --- a/storage/innobase/include/srv0srv.h +++ b/storage/innobase/include/srv0srv.h @@ -111,13 +111,13 @@ extern ulint srv_max_file_format_at_startup; /** Place locks to records only i.e. do not use next-key locking except on duplicate key checking and foreign key checking */ extern ibool srv_locks_unsafe_for_binlog; -#endif /* !UNIV_HOTBACKUP */ /* If this flag is TRUE, then we will use the native aio of the OS (provided we compiled Innobase with it in), otherwise we will use simulated aio we build below with threads. Currently we support native aio on windows and linux */ extern my_bool srv_use_native_aio; +#endif /* !UNIV_HOTBACKUP */ #ifdef __WIN__ extern ibool srv_use_native_conditions; #endif diff --git a/storage/innobase/include/trx0sys.h b/storage/innobase/include/trx0sys.h index 3913792d594..635e7ec30b6 100644 --- a/storage/innobase/include/trx0sys.h +++ b/storage/innobase/include/trx0sys.h @@ -222,7 +222,6 @@ UNIV_INLINE trx_id_t trx_sys_get_new_trx_id(void); /*========================*/ -#endif /* !UNIV_HOTBACKUP */ #ifdef UNIV_DEBUG /* Flag to control TRX_RSEG_N_SLOTS behavior debugging. */ @@ -239,7 +238,6 @@ trx_write_trx_id( /*=============*/ byte* ptr, /*!< in: pointer to memory where written */ trx_id_t id); /*!< in: id */ -#ifndef UNIV_HOTBACKUP /*****************************************************************//** Reads a trx id from an index page. In case that the id size changes in some future version, this function should be used instead of @@ -572,7 +570,6 @@ FIL_PAGE_ARCH_LOG_NO_OR_SPACE_NO. */ #define TRX_SYS_DOUBLEWRITE_BLOCK_SIZE FSP_EXTENT_SIZE /* @} */ -#ifndef UNIV_HOTBACKUP /** File format tag */ /* @{ */ /** The offset of the file format tag on the trx system header page @@ -591,6 +588,7 @@ identifier is added to this 64-bit constant. */ | TRX_SYS_FILE_FORMAT_TAG_MAGIC_N_LOW) /* @} */ +#ifndef UNIV_HOTBACKUP /** Doublewrite control struct */ struct trx_doublewrite_struct{ mutex_t mutex; /*!< mutex protecting the first_free field and diff --git a/storage/innobase/mem/mem0dbg.c b/storage/innobase/mem/mem0dbg.c index ae43d6097a6..0909b7c9a64 100644 --- a/storage/innobase/mem/mem0dbg.c +++ b/storage/innobase/mem/mem0dbg.c @@ -24,7 +24,9 @@ but is included in mem0mem.* ! Created 6/9/1994 Heikki Tuuri *************************************************************************/ -#include "ha_prototypes.h" +#ifndef UNIV_HOTBACKUP +# include "ha_prototypes.h" +#endif /* !UNIV_HOTBACKUP */ #ifdef UNIV_MEM_DEBUG # ifndef UNIV_HOTBACKUP diff --git a/storage/innobase/os/os0file.c b/storage/innobase/os/os0file.c index 502cb44a0fa..1c50e903965 100644 --- a/storage/innobase/os/os0file.c +++ b/storage/innobase/os/os0file.c @@ -303,6 +303,7 @@ UNIV_INTERN ulint os_n_pending_writes = 0; UNIV_INTERN ulint os_n_pending_reads = 0; #ifdef UNIV_DEBUG +# ifndef UNIV_HOTBACKUP /**********************************************************************//** Validates the consistency the aio system some of the time. @return TRUE if ok or the check was skipped */ @@ -329,6 +330,7 @@ os_aio_validate_skip(void) os_aio_validate_count = OS_AIO_VALIDATE_SKIP; return(os_aio_validate()); } +# endif /* !UNIV_HOTBACKUP */ #endif /* UNIV_DEBUG */ #ifdef __WIN__ diff --git a/storage/innobase/page/page0zip.c b/storage/innobase/page/page0zip.c index fb618beac7e..ca3836689d3 100644 --- a/storage/innobase/page/page0zip.c +++ b/storage/innobase/page/page0zip.c @@ -4433,7 +4433,9 @@ page_zip_reorganize( dict_index_t* index, /*!< in: index of the B-tree node */ mtr_t* mtr) /*!< in: mini-transaction */ { +#ifndef UNIV_HOTBACKUP buf_pool_t* buf_pool = buf_pool_from_block(block); +#endif /* !UNIV_HOTBACKUP */ page_zip_des_t* page_zip = buf_block_get_page_zip(block); page_t* page = buf_block_get_frame(block); buf_block_t* temp_block; diff --git a/storage/innobase/trx/trx0sys.c b/storage/innobase/trx/trx0sys.c index 78d11f2d248..3d1a6bbed33 100644 --- a/storage/innobase/trx/trx0sys.c +++ b/storage/innobase/trx/trx0sys.c @@ -134,12 +134,12 @@ UNIV_INTERN mysql_pfs_key_t trx_doublewrite_mutex_key; UNIV_INTERN mysql_pfs_key_t file_format_max_mutex_key; #endif /* UNIV_PFS_MUTEX */ +#ifndef UNIV_HOTBACKUP #ifdef UNIV_DEBUG /* Flag to control TRX_RSEG_N_SLOTS behavior debugging. */ uint trx_rseg_n_slots_debug = 0; #endif -#ifndef UNIV_HOTBACKUP /** This is used to track the maximum file format id known to InnoDB. It's updated via SET GLOBAL innodb_file_format_max = 'x' or when we open or create a table. */ diff --git a/storage/innobase/ut/ut0dbg.c b/storage/innobase/ut/ut0dbg.c index 64fadd76d1c..53ed4a53044 100644 --- a/storage/innobase/ut/ut0dbg.c +++ b/storage/innobase/ut/ut0dbg.c @@ -25,7 +25,9 @@ Created 1/30/1994 Heikki Tuuri #include "univ.i" #include "ut0dbg.h" -#include "ha_prototypes.h" +#ifndef UNIV_HOTBACKUP +# include "ha_prototypes.h" +#endif /* !UNIV_HOTBACKUP */ #if defined(__GNUC__) && (__GNUC__ > 2) #else @@ -56,7 +58,7 @@ ut_dbg_assertion_failed( ut_print_timestamp(stderr); #ifdef UNIV_HOTBACKUP fprintf(stderr, " InnoDB: Assertion failure in file %s line %lu\n", - innobase_basename(file), line); + file, line); #else /* UNIV_HOTBACKUP */ fprintf(stderr, " InnoDB: Assertion failure in thread %lu" diff --git a/storage/innobase/ut/ut0ut.c b/storage/innobase/ut/ut0ut.c index 117a777cb98..2fe45aad2a7 100644 --- a/storage/innobase/ut/ut0ut.c +++ b/storage/innobase/ut/ut0ut.c @@ -245,7 +245,9 @@ ut_print_timestamp( (int)cal_tm.wMinute, (int)cal_tm.wSecond); #else +#ifdef HAVE_LOCALTIME_R struct tm cal_tm; +#endif struct tm* cal_tm_ptr; time_t tm; @@ -288,7 +290,9 @@ ut_sprintf_timestamp( (int)cal_tm.wMinute, (int)cal_tm.wSecond); #else +#ifdef HAVE_LOCALTIME_R struct tm cal_tm; +#endif struct tm* cal_tm_ptr; time_t tm; @@ -333,7 +337,9 @@ ut_sprintf_timestamp_without_extra_chars( (int)cal_tm.wMinute, (int)cal_tm.wSecond); #else +#ifdef HAVE_LOCALTIME_R struct tm cal_tm; +#endif struct tm* cal_tm_ptr; time_t tm; @@ -374,7 +380,9 @@ ut_get_year_month_day( *month = (ulint)cal_tm.wMonth; *day = (ulint)cal_tm.wDay; #else +#ifdef HAVE_LOCALTIME_R struct tm cal_tm; +#endif struct tm* cal_tm_ptr; time_t tm; From d74c3df6ce335a5febbc49530b5e43625b68352d Mon Sep 17 00:00:00 2001 From: Bjorn Munch Date: Fri, 8 Jun 2012 16:31:03 +0200 Subject: [PATCH 47/90] Backport SuSE 11 fix to RPM spec file --- support-files/mysql.spec.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/support-files/mysql.spec.sh b/support-files/mysql.spec.sh index a3d8554188e..5b9a296d90a 100644 --- a/support-files/mysql.spec.sh +++ b/support-files/mysql.spec.sh @@ -176,7 +176,7 @@ %endif %else %if %(test -f /etc/SuSE-release && echo 1 || echo 0) - %define susever %(rpm -qf --qf '%%{version}\\n' /etc/SuSE-release) + %define susever %(rpm -qf --qf '%%{version}\\n' /etc/SuSE-release | cut -d. -f1) %if "%susever" == "10" %define distro_description SUSE Linux Enterprise Server 10 %define distro_releasetag sles10 From 6094d190954285f43000dc44e03934ffb8582eb9 Mon Sep 17 00:00:00 2001 From: Jon Olav Hauglid Date: Tue, 12 Jun 2012 15:04:57 +0200 Subject: [PATCH 48/90] Bug#13586591 RQG GRAMMAR CONF/ENGINES/ENGINE_STRESS.YY CRASHES INNODB | TRX_STATE_NOT_STARTED The problem was that if DELETE with subselect caused a deadlock inside InnoDB, this deadlock was not properly handled by the SQL layer. This meant that the SQL layer would try to unlock the row after InnoDB had rolled back the transaction. This caused an assertion inside InnoDB. This patch fixes the problem by checking for errors reported by SQL_SELECT::skip_record() and not calling unlock_row() if any errors have been reported. --- sql/sql_delete.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 4fd1815ad7f..1bbc9af0835 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -341,8 +341,14 @@ bool mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, break; } } - else + /* + Don't try unlocking the row if skip_record reported an error since in + this case the transaction might have been rolled back already. + */ + else if (!thd->is_error()) table->file->unlock_row(); // Row failed selection, release lock on it + else + break; } killed_status= thd->killed; if (killed_status != THD::NOT_KILLED || thd->is_error()) From cf37a481f0114d4cdb40c4d8fb483939f6b1bc5a Mon Sep 17 00:00:00 2001 From: Harin Vadodaria Date: Wed, 13 Jun 2012 16:03:58 +0530 Subject: [PATCH 49/90] Bug#11753779: MAX_CONNECT_ERRORS WORKS ONLY WHEN 1ST INC_HOST_ERRORS() IS CALLED. Issue : Sequence of calling inc_host_errors() and reset_host_errors() required some changes in order to maintain correct connection error count. Solution : Call to reset_host_errors() is shifted to a location after which no calls to inc_host_errors() are made. --- sql/hostname.cc | 9 ++++++++ sql/sql_connect.cc | 54 ++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 59 insertions(+), 4 deletions(-) diff --git a/sql/hostname.cc b/sql/hostname.cc index 9796755e9fb..38316a8ee19 100644 --- a/sql/hostname.cc +++ b/sql/hostname.cc @@ -214,6 +214,15 @@ char * ip_to_hostname(struct in_addr *in, uint *errors) } my_gethostbyname_r_free(); #else + + DBUG_EXECUTE_IF("addr_fake_ipv4", + { + const char* fake_host= "santa.claus.ipv4.example.com"; + name=my_strdup(fake_host, MYF(0)); + add_hostname(in,name); + DBUG_RETURN(name); + };); + VOID(pthread_mutex_lock(&LOCK_hostname)); if (!(hp=gethostbyaddr((char*) in,sizeof(*in), AF_INET))) { diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 21e2701d06c..7a934541d53 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -360,7 +360,6 @@ check_user(THD *thd, enum enum_server_command command, if (send_old_password_request(thd) || my_net_read(net) != SCRAMBLE_LENGTH_323 + 1) { - inc_host_errors(&thd->remote.sin_addr); my_error(ER_HANDSHAKE_ERROR, MYF(0)); DBUG_RETURN(1); } @@ -832,6 +831,19 @@ static int check_connection(THD *thd) my_error(ER_BAD_HOST_ERROR, MYF(0)); return 1; } + /* BEGIN : DEBUG */ + DBUG_EXECUTE_IF("addr_fake_ipv4", + { + struct sockaddr *sa= (sockaddr *) &net->vio->remote; + sa->sa_family= AF_INET; + struct in_addr *ip4= &((struct sockaddr_in *)sa)->sin_addr; + /* See RFC 5737, 192.0.2.0/23 is reserved */ + const char* fake= "192.0.2.4"; + ip4->s_addr= inet_addr(fake); + strcpy(ip, fake); + };); + /* END : DEBUG */ + if (!(thd->main_security_ctx.ip= my_strdup(ip,MYF(MY_WME)))) return 1; /* The error is set by my_strdup(). */ thd->main_security_ctx.host_or_ip= thd->main_security_ctx.ip; @@ -935,8 +947,6 @@ static int check_connection(THD *thd) #ifdef _CUSTOMCONFIG_ #include "_cust_sql_parse.h" #endif - if (connect_errors) - reset_host_errors(&thd->remote.sin_addr); if (thd->packet.alloc(thd->variables.net_buffer_length)) return 1; /* The error is set by alloc(). */ @@ -953,6 +963,10 @@ static int check_connection(THD *thd) Peek ahead on the client capability packet and determine which version of the protocol should be used. */ + DBUG_EXECUTE_IF("host_error_packet_length", + { + bytes_remaining_in_packet= 0; + };); if (bytes_remaining_in_packet < 2) goto error; @@ -1011,6 +1025,10 @@ static int check_connection(THD *thd) skip_to_ssl: + DBUG_EXECUTE_IF("host_error_charset", + { + goto error; + };); DBUG_PRINT("info", ("client_character_set: %u", charset_code)); if (thd_init_client_charset(thd, charset_code)) goto error; @@ -1079,6 +1097,10 @@ skip_to_ssl: bytes_remaining_in_packet -= AUTH_PACKET_HEADER_SIZE_PROTO_40; } + DBUG_EXECUTE_IF("host_error_SSL_layering", + { + packet_has_required_size= 0; + };); if (!packet_has_required_size) goto error; } @@ -1104,6 +1126,11 @@ skip_to_ssl: get_string= get_40_protocol_string; user= get_string(&end, &bytes_remaining_in_packet, &user_len); + DBUG_EXECUTE_IF("host_error_user", + { + user= NULL; + };); + if (user == NULL) goto error; @@ -1131,6 +1158,11 @@ skip_to_ssl: passwd= get_string(&end, &bytes_remaining_in_packet, &passwd_len); } + DBUG_EXECUTE_IF("host_error_password", + { + passwd= NULL; + };); + if (passwd == NULL) goto error; @@ -1191,7 +1223,21 @@ skip_to_ssl: if (!(thd->main_security_ctx.user= my_strdup(user, MYF(MY_WME)))) return 1; /* The error is set by my_strdup(). */ - return check_user(thd, COM_CONNECT, passwd, passwd_len, db, TRUE); + + if (!check_user(thd, COM_CONNECT, passwd, passwd_len, db, TRUE)) + { + /* + Call to reset_host_errors() should be made only when all sanity checks + are done and connection is going to be a successful. + */ + reset_host_errors(&thd->remote.sin_addr); + return 0; + } + else + { + inc_host_errors(&thd->remote.sin_addr); + return 1; + } error: inc_host_errors(&thd->remote.sin_addr); From 775293b898aa6c5239b17de5d489768de5287803 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 14 Jun 2012 17:07:49 +0530 Subject: [PATCH 50/90] BUG #13946716: FEDERATED_PLUGIN TEST CASE FAIL ON 64BIT ARCHITECTURES --- mysql-test/mysql-test-run.pl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 294dcf13615..674abe7e102 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -1969,6 +1969,7 @@ sub environment_setup { my $lib_example_plugin= mtr_file_exists(vs_config_dirs('storage/example',$plugin_filename), "$basedir/storage/example/.libs/".$plugin_filename, + "$basedir/lib64/mysql/plugin/".$plugin_filename, "$basedir/lib/mysql/plugin/".$plugin_filename); $ENV{'EXAMPLE_PLUGIN'}= ($lib_example_plugin ? basename($lib_example_plugin) : ""); @@ -1991,6 +1992,7 @@ sub environment_setup { my $lib_fed_plugin= mtr_file_exists(vs_config_dirs('storage/federated',$fedplug_filename), "$basedir/storage/federated/.libs/".$fedplug_filename, + "$basedir/lib64/mysql/plugin/".$fedplug_filename, "$basedir/lib/mysql/plugin/".$fedplug_filename); $ENV{'FEDERATED_PLUGIN'}= $fedplug_filename; From bd223999dcd20f67a087ba1dadeecd41a0c5622f Mon Sep 17 00:00:00 2001 From: Sunanda Menon Date: Fri, 15 Jun 2012 10:34:18 +0200 Subject: [PATCH 51/90] Raising the VERSION number after 5.5.26 clone-off --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index a6ecc1acc76..2ac736f0617 100644 --- a/VERSION +++ b/VERSION @@ -1,4 +1,4 @@ MYSQL_VERSION_MAJOR=5 MYSQL_VERSION_MINOR=5 -MYSQL_VERSION_PATCH=26 +MYSQL_VERSION_PATCH=27 MYSQL_VERSION_EXTRA= From bc42eaf95283f66788a70acbed1d7368c784a9a1 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 15 Jun 2012 13:31:27 +0200 Subject: [PATCH 52/90] Raise version number after cloning 5.1.64 --- configure.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.in b/configure.in index 84295a15f4a..4e7a3303353 100644 --- a/configure.in +++ b/configure.in @@ -12,7 +12,7 @@ dnl dnl When changing the major version number please also check the switch dnl statement in mysqlbinlog::check_master_version(). You may also need dnl to update version.c in ndb. -AC_INIT([MySQL Server], [5.1.64], [], [mysql]) +AC_INIT([MySQL Server], [5.1.65], [], [mysql]) AC_CONFIG_SRCDIR([sql/mysqld.cc]) AC_CANONICAL_SYSTEM From cac1cd88abc2a610b42b89e5d39029f75a760ec4 Mon Sep 17 00:00:00 2001 From: "Norvald H. Ryeng" Date: Mon, 18 Jun 2012 09:20:12 +0200 Subject: [PATCH 53/90] Bug#13003736 CRASH IN ITEM_REF::WALK WITH SUBQUERIES Problem: Some queries with subqueries and a HAVING clause that consists only of a column not in the select or grouping lists causes the server to crash. During parsing, an Item_ref is constructed for the HAVING column. The name of the column is resolved when JOIN::prepare calls fix_fields() on its having clause. Since the column is not mentioned in the select or grouping lists, a ref pointer is not found and a new Item_field is created instead. The Item_ref is replaced by the Item_field in the tree of HAVING clauses. Since the tree consists only of this item, the pointer that is updated is JOIN::having. However, st_select_lex::having still points to the Item_ref as the root of the tree of HAVING clauses. The bug is triggered when doing filesort for create_sort_index(). When find_all_keys() calls select->cond->walk() it eventually reaches Item_subselect::walk() where it continues to walk the having clauses from lex->having. This means that it finds the Item_ref instead of the new Item_field, and Item_ref::walk() tries to dereference the ref pointer, which is still null. The crash is reproducible only in 5.5, but the problem lies latent in 5.1 and trunk as well. Fix: After calling fix_fields on the having clause in JOIN::prepare(), set select_lex::having to point to the same item as JOIN::having. This patch also fixes a bug in 5.1 and 5.5 that is triggered if the query is executed as a prepared statement. The Item_field is created in the runtime arena when the query is prepared, and the pointer to the item is saved by st_select_lex::fix_prepare_information() and brought back as a dangling pointer when the query is executed, after the runtime arena has been reclaimed. Fix: Backport fix from trunk that switches to the permanent arena before calling Item_ref::fix_fields() in JOIN::prepare(). sql/item.cc: Set context when creating Item_field. sql/sql_select.cc: Switch to permanent arena and update select_lex->having. --- sql/item.cc | 2 +- sql/sql_select.cc | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sql/item.cc b/sql/item.cc index 90bfb0d2852..356fe4827c8 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -6010,7 +6010,7 @@ bool Item_ref::fix_fields(THD *thd, Item **reference) if (from_field != not_found_field) { Item_field* fld; - if (!(fld= new Item_field(from_field))) + if (!(fld= new Item_field(thd, last_checked_context, from_field))) goto error; thd->change_item_tree(reference, fld); mark_as_dependent(thd, last_checked_context->select_lex, diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 7c3d2de22bc..f2007f609e0 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -528,6 +528,8 @@ JOIN::prepare(Item ***rref_pointer_array, if (having) { + Query_arena backup, *arena; + arena= thd->activate_stmt_arena_if_needed(&backup); nesting_map save_allow_sum_func= thd->lex->allow_sum_func; thd->where="having clause"; thd->lex->allow_sum_func|= 1 << select_lex_arg->nest_level; @@ -536,6 +538,10 @@ JOIN::prepare(Item ***rref_pointer_array, (having->fix_fields(thd, &having) || having->check_cols(1))); select_lex->having_fix_field= 0; + select_lex->having= having; + if (arena) + thd->restore_active_arena(arena, &backup); + if (having_fix_rc || thd->is_error()) DBUG_RETURN(-1); /* purecov: inspected */ thd->lex->allow_sum_func= save_allow_sum_func; From 61e428eb846e820ba0764932d1604859e53abe52 Mon Sep 17 00:00:00 2001 From: Harin Vadodaria Date: Tue, 19 Jun 2012 12:56:40 +0530 Subject: [PATCH 54/90] Bug#11753779: MAX_CONNECT_ERRORS WORKS ONLY WHEN 1ST INC_HOST_ERRORS() IS CALLED. Description: Reverting patch 3755 for bug#11753779 --- sql/hostname.cc | 9 -------- sql/sql_connect.cc | 54 ++++------------------------------------------ 2 files changed, 4 insertions(+), 59 deletions(-) diff --git a/sql/hostname.cc b/sql/hostname.cc index 38316a8ee19..9796755e9fb 100644 --- a/sql/hostname.cc +++ b/sql/hostname.cc @@ -214,15 +214,6 @@ char * ip_to_hostname(struct in_addr *in, uint *errors) } my_gethostbyname_r_free(); #else - - DBUG_EXECUTE_IF("addr_fake_ipv4", - { - const char* fake_host= "santa.claus.ipv4.example.com"; - name=my_strdup(fake_host, MYF(0)); - add_hostname(in,name); - DBUG_RETURN(name); - };); - VOID(pthread_mutex_lock(&LOCK_hostname)); if (!(hp=gethostbyaddr((char*) in,sizeof(*in), AF_INET))) { diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index 7a934541d53..21e2701d06c 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -360,6 +360,7 @@ check_user(THD *thd, enum enum_server_command command, if (send_old_password_request(thd) || my_net_read(net) != SCRAMBLE_LENGTH_323 + 1) { + inc_host_errors(&thd->remote.sin_addr); my_error(ER_HANDSHAKE_ERROR, MYF(0)); DBUG_RETURN(1); } @@ -831,19 +832,6 @@ static int check_connection(THD *thd) my_error(ER_BAD_HOST_ERROR, MYF(0)); return 1; } - /* BEGIN : DEBUG */ - DBUG_EXECUTE_IF("addr_fake_ipv4", - { - struct sockaddr *sa= (sockaddr *) &net->vio->remote; - sa->sa_family= AF_INET; - struct in_addr *ip4= &((struct sockaddr_in *)sa)->sin_addr; - /* See RFC 5737, 192.0.2.0/23 is reserved */ - const char* fake= "192.0.2.4"; - ip4->s_addr= inet_addr(fake); - strcpy(ip, fake); - };); - /* END : DEBUG */ - if (!(thd->main_security_ctx.ip= my_strdup(ip,MYF(MY_WME)))) return 1; /* The error is set by my_strdup(). */ thd->main_security_ctx.host_or_ip= thd->main_security_ctx.ip; @@ -947,6 +935,8 @@ static int check_connection(THD *thd) #ifdef _CUSTOMCONFIG_ #include "_cust_sql_parse.h" #endif + if (connect_errors) + reset_host_errors(&thd->remote.sin_addr); if (thd->packet.alloc(thd->variables.net_buffer_length)) return 1; /* The error is set by alloc(). */ @@ -963,10 +953,6 @@ static int check_connection(THD *thd) Peek ahead on the client capability packet and determine which version of the protocol should be used. */ - DBUG_EXECUTE_IF("host_error_packet_length", - { - bytes_remaining_in_packet= 0; - };); if (bytes_remaining_in_packet < 2) goto error; @@ -1025,10 +1011,6 @@ static int check_connection(THD *thd) skip_to_ssl: - DBUG_EXECUTE_IF("host_error_charset", - { - goto error; - };); DBUG_PRINT("info", ("client_character_set: %u", charset_code)); if (thd_init_client_charset(thd, charset_code)) goto error; @@ -1097,10 +1079,6 @@ skip_to_ssl: bytes_remaining_in_packet -= AUTH_PACKET_HEADER_SIZE_PROTO_40; } - DBUG_EXECUTE_IF("host_error_SSL_layering", - { - packet_has_required_size= 0; - };); if (!packet_has_required_size) goto error; } @@ -1126,11 +1104,6 @@ skip_to_ssl: get_string= get_40_protocol_string; user= get_string(&end, &bytes_remaining_in_packet, &user_len); - DBUG_EXECUTE_IF("host_error_user", - { - user= NULL; - };); - if (user == NULL) goto error; @@ -1158,11 +1131,6 @@ skip_to_ssl: passwd= get_string(&end, &bytes_remaining_in_packet, &passwd_len); } - DBUG_EXECUTE_IF("host_error_password", - { - passwd= NULL; - };); - if (passwd == NULL) goto error; @@ -1223,21 +1191,7 @@ skip_to_ssl: if (!(thd->main_security_ctx.user= my_strdup(user, MYF(MY_WME)))) return 1; /* The error is set by my_strdup(). */ - - if (!check_user(thd, COM_CONNECT, passwd, passwd_len, db, TRUE)) - { - /* - Call to reset_host_errors() should be made only when all sanity checks - are done and connection is going to be a successful. - */ - reset_host_errors(&thd->remote.sin_addr); - return 0; - } - else - { - inc_host_errors(&thd->remote.sin_addr); - return 1; - } + return check_user(thd, COM_CONNECT, passwd, passwd_len, db, TRUE); error: inc_host_errors(&thd->remote.sin_addr); From 247262347e00b1fa3e827b174b765564d6be3b1a Mon Sep 17 00:00:00 2001 From: Evgeny Potemkin Date: Thu, 28 Jun 2012 16:53:45 +0400 Subject: [PATCH 55/90] Bug#14248833: UPDATE ON INNODB TABLE ENTERS RECURSION Introduction of cost based decision on filesort vs index for UPDATE statements changed detection of the fact that the index used to scan the table is being updated. The new design missed the case of index merge when there is no single index to check. That was worked until a recent change in InnoDB after which it went into infinite recursion if update of the used index wasn't properly detected. The fix consists of 'used key being updated' detection code from 5.1. sql/sql_update.cc: Bug#14248833: UPDATE ON INNODB TABLE ENTERS RECURSION The check for used key being updated is extended to cover the case when index merge is used. --- sql/sql_update.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 754170e4c55..c4a95edcfc2 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -450,6 +450,15 @@ int mysql_update(THD *thd, { // Check if we are modifying a key that we are used to search with: used_key_is_modified= is_key_used(table, used_index, table->write_set); } + else if (select && select->quick) + { + /* + select->quick != NULL and used_index == MAX_KEY happens for index + merge and should be handled in a different way. + */ + used_key_is_modified= (!select->quick->unique_key_range() && + select->quick->is_keys_used(table->write_set)); + } #ifdef WITH_PARTITION_STORAGE_ENGINE if (used_key_is_modified || order || From 107c894a540d147338ab4e737eb9ef76e49c3493 Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Thu, 28 Jun 2012 18:38:55 +0300 Subject: [PATCH 56/90] Bug #13708485: malformed resultset packet crashes client Several fixes : * sql-common/client.c Added a validity check of the fields metadata packet sent by the server. Now libmysql will check if the length of the data sent by the server matches what's expected by the protocol before using the data. * client/mysqltest.cc Fixed the error handling code in mysqltest to avoid sending new commands when the reading the result set failed (and there are unread data in the pipe). * sql_common.h + libmysql/libmysql.c + sql-common/client.c unpack_fields() now generates a proper error when it fails. Added a new argument to this function to support the error generation. * sql/protocol.cc Added a debug trigger to cause the server to send a NULL insted of the packet expected by the client for testing purposes. --- client/mysqltest.cc | 4 +++- include/sql_common.h | 8 +++++--- libmysql/libmysql.c | 8 ++++---- sql-common/client.c | 15 ++++++++++++--- sql/protocol.cc | 4 +++- 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 593bb8ea290..e595493ccf0 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 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 @@ -6848,6 +6848,8 @@ void run_query_normal(struct st_connection *cn, struct st_command *command, */ if ((counter==0) && mysql_read_query_result(mysql)) { + /* we've failed to collect the result set */ + cn->pending= TRUE; handle_error(command, mysql_errno(mysql), mysql_error(mysql), mysql_sqlstate(mysql), ds); goto end; diff --git a/include/sql_common.h b/include/sql_common.h index 9e43d076ba9..b64277ce7e1 100644 --- a/include/sql_common.h +++ b/include/sql_common.h @@ -1,4 +1,5 @@ -/* Copyright (C) 2003-2004, 2006 MySQL AB +/* + Copyright (c) 2003, 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 @@ -23,8 +24,9 @@ extern "C" { #endif extern CHARSET_INFO *default_client_charset_info; -MYSQL_FIELD *unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, - my_bool default_value, uint server_capabilities); +MYSQL_FIELD *unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc, + uint fields, my_bool default_value, + uint server_capabilities); void free_rows(MYSQL_DATA *cur); void free_old_query(MYSQL *mysql); void end_server(MYSQL *mysql); diff --git a/libmysql/libmysql.c b/libmysql/libmysql.c index 562da594fea..5d153317150 100644 --- a/libmysql/libmysql.c +++ b/libmysql/libmysql.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 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 @@ -1254,7 +1254,7 @@ MYSQL_FIELD *cli_list_fields(MYSQL *mysql) return NULL; mysql->field_count= (uint) query->rows; - return unpack_fields(query,&mysql->field_alloc, + return unpack_fields(mysql, query,&mysql->field_alloc, mysql->field_count, 1, mysql->server_capabilities); } @@ -1314,7 +1314,7 @@ mysql_list_processes(MYSQL *mysql) if (!(fields = (*mysql->methods->read_rows)(mysql,(MYSQL_FIELD*) 0, protocol_41(mysql) ? 7 : 5))) DBUG_RETURN(NULL); - if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc,field_count,0, + if (!(mysql->fields=unpack_fields(mysql, fields,&mysql->field_alloc,field_count,0, mysql->server_capabilities))) DBUG_RETURN(0); mysql->status=MYSQL_STATUS_GET_RESULT; @@ -1891,7 +1891,7 @@ my_bool cli_read_prepare_result(MYSQL *mysql, MYSQL_STMT *stmt) if (!(fields_data= (*mysql->methods->read_rows)(mysql,(MYSQL_FIELD*)0,7))) DBUG_RETURN(1); - if (!(stmt->fields= unpack_fields(fields_data,&stmt->mem_root, + if (!(stmt->fields= unpack_fields(mysql, fields_data,&stmt->mem_root, field_count,0, mysql->server_capabilities))) DBUG_RETURN(1); diff --git a/sql-common/client.c b/sql-common/client.c index 0df7c242969..51911d913c7 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -1,5 +1,5 @@ /* - Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2003, 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 @@ -1268,7 +1268,7 @@ static void cli_fetch_lengths(ulong *to, MYSQL_ROW column, ***************************************************************************/ MYSQL_FIELD * -unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, +unpack_fields(MYSQL *mysql, MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, my_bool default_value, uint server_capabilities) { MYSQL_ROWS *row; @@ -1281,6 +1281,7 @@ unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, if (!result) { free_rows(data); /* Free old data */ + set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate); DBUG_RETURN(0); } bzero((char*) field, (uint) sizeof(MYSQL_FIELD)*fields); @@ -1308,6 +1309,14 @@ unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, field->org_name_length= lengths[5]; /* Unpack fixed length parts */ + if (lengths[6] != 12) + { + /* malformed packet. signal an error. */ + free_rows(data); /* Free old data */ + set_mysql_error(mysql, CR_MALFORMED_PACKET, unknown_sqlstate); + DBUG_RETURN(0); + } + pos= (uchar*) row->data[6]; field->charsetnr= uint2korr(pos); field->length= (uint) uint4korr(pos+2); @@ -2868,7 +2877,7 @@ get_info: if (!(fields=cli_read_rows(mysql,(MYSQL_FIELD*)0, protocol_41(mysql) ? 7:5))) DBUG_RETURN(1); - if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc, + if (!(mysql->fields=unpack_fields(mysql, fields,&mysql->field_alloc, (uint) field_count,0, mysql->server_capabilities))) DBUG_RETURN(1); diff --git a/sql/protocol.cc b/sql/protocol.cc index 5a727d94c46..a74f6084df4 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 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 @@ -620,6 +620,8 @@ bool Protocol::send_fields(List *list, uint flags) /* Store fixed length fields */ pos= (char*) local_packet->ptr()+local_packet->length(); *pos++= 12; // Length of packed fields + /* inject a NULL to test the client */ + DBUG_EXECUTE_IF("poison_rs_fields", pos[-1]= 0xfb;); if (item->collation.collation == &my_charset_bin || thd_charset == NULL) { /* No conversion */ From 59c79cc5d0f1dab2db65f3d55ffe6a5a777b85c1 Mon Sep 17 00:00:00 2001 From: Joerg Bruehe Date: Thu, 28 Jun 2012 20:03:53 +0200 Subject: [PATCH 57/90] Bug#65745: UPDATE ON INNODB TABLE ENTERS RECURSION Introduction of cost based decision on filesort vs index for UPDATE statements changed detection of the fact that the index used to scan the table is being updated. The new design missed the case of index merge when there is no single index to check. That was worked until a recent change in InnoDB after which it went into infinite recursion if update of the used index wasn't properly detected. The fix consists of 'used key being updated' detection code from 5.1. Patch done by Evgeny Potemkin and transferred into the 5.5.25a release build by Joerg Bruehe. This changeset is the difference between MySQL 5.5.25 and 5.5.25a. VERSION: Version number change. sql/sql_update.cc: Bug#65745: UPDATE ON INNODB TABLE ENTERS RECURSION The check for used key being updated is extended to cover the case when index merge is used. --- VERSION | 2 +- sql/sql_update.cc | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 6111f6d453f..48e6c183915 100644 --- a/VERSION +++ b/VERSION @@ -1,4 +1,4 @@ MYSQL_VERSION_MAJOR=5 MYSQL_VERSION_MINOR=5 -MYSQL_VERSION_PATCH=25 +MYSQL_VERSION_PATCH=25a MYSQL_VERSION_EXTRA= diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 754170e4c55..c4a95edcfc2 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -450,6 +450,15 @@ int mysql_update(THD *thd, { // Check if we are modifying a key that we are used to search with: used_key_is_modified= is_key_used(table, used_index, table->write_set); } + else if (select && select->quick) + { + /* + select->quick != NULL and used_index == MAX_KEY happens for index + merge and should be handled in a different way. + */ + used_key_is_modified= (!select->quick->unique_key_range() && + select->quick->is_keys_used(table->write_set)); + } #ifdef WITH_PARTITION_STORAGE_ENGINE if (used_key_is_modified || order || From 6058319dba910576e00b0b566697b95aff6cb52c Mon Sep 17 00:00:00 2001 From: Yasufumi Kinoshita Date: Fri, 29 Jun 2012 12:04:44 +0900 Subject: [PATCH 58/90] Bug#14251529 : FIX FOR BUG 13704145 CREATES POSSIBLE RACE CONDITION make buf_read_page_low() to treat DB_TABLESPACE_DELETED error correctly rb#1129 approved by Inaam --- storage/innobase/buf/buf0buf.c | 9 ++++-- storage/innobase/buf/buf0lru.c | 14 +++++++++ storage/innobase/buf/buf0rea.c | 48 +++++++++++++++++++++++++++++- storage/innobase/include/buf0buf.h | 5 ++-- 4 files changed, 70 insertions(+), 6 deletions(-) diff --git a/storage/innobase/buf/buf0buf.c b/storage/innobase/buf/buf0buf.c index fed07129b65..32d376136e6 100644 --- a/storage/innobase/buf/buf0buf.c +++ b/storage/innobase/buf/buf0buf.c @@ -3470,9 +3470,10 @@ buf_mark_space_corrupt( /********************************************************************//** Completes an asynchronous read or write request of a file page to or from -the buffer pool. */ +the buffer pool. +@return TRUE if successful */ UNIV_INTERN -void +ibool buf_page_io_complete( /*=================*/ buf_page_t* bpage) /*!< in: pointer to the block in question */ @@ -3599,7 +3600,7 @@ corrupt: table as corrupted instead of crashing server */ if (bpage->space > TRX_SYS_SPACE && buf_mark_space_corrupt(bpage)) { - return; + return(FALSE); } else { fputs("InnoDB: Ending processing" " because of" @@ -3689,6 +3690,8 @@ corrupt: mutex_exit(buf_page_get_mutex(bpage)); buf_pool_mutex_exit(buf_pool); + + return(TRUE); } /*********************************************************************//** diff --git a/storage/innobase/buf/buf0lru.c b/storage/innobase/buf/buf0lru.c index 8e787fdba17..7c8100df58e 100644 --- a/storage/innobase/buf/buf0lru.c +++ b/storage/innobase/buf/buf0lru.c @@ -2164,9 +2164,23 @@ buf_LRU_free_one_page( be in a state where it can be freed; there may or may not be a hash index to the page */ { +#ifdef UNIV_DEBUG + buf_pool_t* buf_pool = buf_pool_from_bpage(bpage); +#endif + mutex_t* block_mutex = buf_page_get_mutex(bpage); + + ut_ad(buf_pool_mutex_own(buf_pool)); + ut_ad(mutex_own(block_mutex)); + if (buf_LRU_block_remove_hashed_page(bpage, TRUE) != BUF_BLOCK_ZIP_FREE) { buf_LRU_block_free_hashed_page((buf_block_t*) bpage); + } else { + /* The block_mutex should have been released by + buf_LRU_block_remove_hashed_page() when it returns + BUF_BLOCK_ZIP_FREE. */ + ut_ad(block_mutex == &buf_pool->zip_mutex); + mutex_enter(block_mutex); } } diff --git a/storage/innobase/buf/buf0rea.c b/storage/innobase/buf/buf0rea.c index da804a66b29..40550186191 100644 --- a/storage/innobase/buf/buf0rea.c +++ b/storage/innobase/buf/buf0rea.c @@ -50,6 +50,44 @@ read-ahead is not done: this is to prevent flooding the buffer pool with i/o-fixed buffer blocks */ #define BUF_READ_AHEAD_PEND_LIMIT 2 +/********************************************************************//** +Unfixes the pages, unlatches the page, +removes it from page_hash and removes it from LRU. */ +static +void +buf_read_page_handle_error( +/*=======================*/ + buf_page_t* bpage) /*!< in: pointer to the block */ +{ + buf_pool_t* buf_pool = buf_pool_from_bpage(bpage); + const ibool uncompressed = (buf_page_get_state(bpage) + == BUF_BLOCK_FILE_PAGE); + + /* First unfix and release lock on the bpage */ + buf_pool_mutex_enter(buf_pool); + mutex_enter(buf_page_get_mutex(bpage)); + ut_ad(buf_page_get_io_fix(bpage) == BUF_IO_READ); + ut_ad(bpage->buf_fix_count == 0); + + /* Set BUF_IO_NONE before we remove the block from LRU list */ + buf_page_set_io_fix(bpage, BUF_IO_NONE); + + if (uncompressed) { + rw_lock_x_unlock_gen( + &((buf_block_t*) bpage)->lock, + BUF_IO_READ); + } + + /* remove the block from LRU list */ + buf_LRU_free_one_page(bpage); + + ut_ad(buf_pool->n_pend_reads > 0); + buf_pool->n_pend_reads--; + + mutex_exit(buf_page_get_mutex(bpage)); + buf_pool_mutex_exit(buf_pool); +} + /********************************************************************//** Low-level function which reads a page asynchronously from a file to the buffer buf_pool if it is not already there, in which case does nothing. @@ -152,12 +190,20 @@ buf_read_page_low( ((buf_block_t*) bpage)->frame, bpage); } thd_wait_end(NULL); + + if (*err == DB_TABLESPACE_DELETED) { + buf_read_page_handle_error(bpage); + return(0); + } + ut_a(*err == DB_SUCCESS); if (sync) { /* The i/o is already completed when we arrive from fil_read */ - buf_page_io_complete(bpage); + if (!buf_page_io_complete(bpage)) { + return(0); + } } return(1); diff --git a/storage/innobase/include/buf0buf.h b/storage/innobase/include/buf0buf.h index 7c81fe0c539..a39592943d8 100644 --- a/storage/innobase/include/buf0buf.h +++ b/storage/innobase/include/buf0buf.h @@ -1162,9 +1162,10 @@ buf_page_init_for_read( ulint offset);/*!< in: page number */ /********************************************************************//** Completes an asynchronous read or write request of a file page to or from -the buffer pool. */ +the buffer pool. +@return TRUE if successful */ UNIV_INTERN -void +ibool buf_page_io_complete( /*=================*/ buf_page_t* bpage); /*!< in: pointer to the block in question */ From 767501fb54f19adf3c136e5131daf11e34b3f039 Mon Sep 17 00:00:00 2001 From: Gleb Shchepa Date: Fri, 29 Jun 2012 12:55:45 +0400 Subject: [PATCH 59/90] Backport of the deprecation warning from WL#6219: "Deprecate and remove YEAR(2) type" Print the warning(note): YEAR(x) is deprecated and will be removed in a future release. Please use YEAR(4) instead on "CREATE TABLE ... YEAR(x)" or "ALTER TABLE MODIFY ... YEAR(x)", where x != 4 --- mysql-test/r/func_group.result | 2 ++ mysql-test/r/type_blob.result | 4 ++++ mysql-test/r/type_year.result | 15 +++++++++++++++ .../suite/engines/iuds/r/delete_year.result | 6 ++++++ .../suite/engines/iuds/r/insert_year.result | 12 ++++++++++++ .../suite/engines/iuds/r/update_year.result | 6 ++++++ mysql-test/suite/funcs_1/r/innodb_views.result | 4 ++++ .../suite/funcs_1/r/is_columns_innodb.result | 6 ++++++ .../suite/funcs_1/r/is_columns_memory.result | 6 ++++++ .../suite/funcs_1/r/is_columns_myisam.result | 6 ++++++ .../r/is_columns_myisam_embedded.result | 6 ++++++ mysql-test/suite/funcs_1/r/memory_views.result | 4 ++++ .../suite/funcs_1/r/myisam_views-big.result | 4 ++++ mysql-test/suite/funcs_1/r/ndb_views.result | 4 ++++ mysql-test/suite/funcs_1/r/storedproc.result | 4 ++++ .../innodb_plugin/r/innodb_bug52745.result | 1 + mysql-test/t/type_year.test | 8 ++++++++ sql/field.cc | 11 +++++++++++ sql/sql_yacc.yy | 18 +++++++++++++++++- 19 files changed, 126 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/func_group.result b/mysql-test/r/func_group.result index b90eb2a4c0f..74899a22636 100644 --- a/mysql-test/r/func_group.result +++ b/mysql-test/r/func_group.result @@ -1524,6 +1524,8 @@ DROP TABLE t1; # Bug#43668: Wrong comparison and MIN/MAX for YEAR(2) # create table t1 (f1 year(2), f2 year(4), f3 date, f4 datetime); +Warnings: +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead insert into t1 values (98,1998,19980101,"1998-01-01 00:00:00"), (00,2000,20000101,"2000-01-01 00:00:01"), diff --git a/mysql-test/r/type_blob.result b/mysql-test/r/type_blob.result index e6fd49b4247..8b4b6438842 100644 --- a/mysql-test/r/type_blob.result +++ b/mysql-test/r/type_blob.result @@ -878,6 +878,8 @@ ERROR 42000: Column length too big for column 'a' (max = 255); use BLOB or TEXT CREATE TABLE b15776 (a char(4294967296)); ERROR 42000: Display width out of range for column 'a' (max = 4294967295) CREATE TABLE b15776 (a year(4294967295)); +Warnings: +Note 1287 'YEAR(4294967295)' is deprecated and will be removed in a future release. Please use YEAR(4) instead INSERT INTO b15776 VALUES (42); SELECT * FROM b15776; a @@ -886,6 +888,8 @@ DROP TABLE b15776; CREATE TABLE b15776 (a year(4294967296)); ERROR 42000: Display width out of range for column 'a' (max = 4294967295) CREATE TABLE b15776 (a year(0)); +Warnings: +Note 1287 'YEAR(0)' is deprecated and will be removed in a future release. Please use YEAR(4) instead DROP TABLE b15776; CREATE TABLE b15776 (a year(-2)); ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-2))' at line 1 diff --git a/mysql-test/r/type_year.result b/mysql-test/r/type_year.result index 2dc491c6166..e00569c93c1 100644 --- a/mysql-test/r/type_year.result +++ b/mysql-test/r/type_year.result @@ -1,5 +1,7 @@ drop table if exists t1; create table t1 (y year,y2 year(2)); +Warnings: +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead insert into t1 values (0,0),(1999,1999),(2000,2000),(2001,2001),(70,70),(69,69); select * from t1; y y2 @@ -50,6 +52,8 @@ End of 5.0 tests # Bug #49480: WHERE using YEAR columns returns unexpected results # CREATE TABLE t2(yy YEAR(2), c2 CHAR(4)); +Warnings: +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead CREATE TABLE t4(yyyy YEAR(4), c4 CHAR(4)); INSERT INTO t2 (c2) VALUES (NULL),(1970),(1999),(2000),(2001),(2069); INSERT INTO t4 (c4) SELECT c2 FROM t2; @@ -355,4 +359,15 @@ total_rows min_value MAX(c1) 3 0 2155 DROP TABLE t1; # +# WL#6219: Deprecate and remove YEAR(2) type +# +CREATE TABLE t1 (c1 YEAR(2), c2 YEAR(4)); +Warnings: +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead +ALTER TABLE t1 MODIFY COLUMN c2 YEAR(2); +Warnings: +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead +DROP TABLE t1; +# End of 5.1 tests diff --git a/mysql-test/suite/engines/iuds/r/delete_year.result b/mysql-test/suite/engines/iuds/r/delete_year.result index 02cbe24ecc9..c82f0dae7d9 100644 --- a/mysql-test/suite/engines/iuds/r/delete_year.result +++ b/mysql-test/suite/engines/iuds/r/delete_year.result @@ -2,7 +2,13 @@ DROP TABLE IF EXISTS t1,t2,t3,t4; CREATE TABLE t1(c1 YEAR NOT NULL,c2 YEAR, PRIMARY KEY(c1)); CREATE TABLE t2(c1 YEAR NOT NULL, c2 YEAR, UNIQUE INDEX idx(c1,c2)); CREATE TABLE t3(c1 YEAR(2) NOT NULL,c2 YEAR(2), PRIMARY KEY(c1)); +Warnings: +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead CREATE TABLE t4(c1 YEAR(2), c2 YEAR(2), UNIQUE INDEX idx(c1,c2)); +Warnings: +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead INSERT INTO t1 VALUES (1901,1901),(1970,1970),(1999,1999),(2000,2000),(2155,2155); INSERT INTO t2 VALUES (1901,1901),(1970,1970),(1999,1999),(2000,2000),(2155,2155); INSERT INTO t3 VALUES (1901,1901),(1970,1970),(1999,1999),(2000,2000),(2155,2155); diff --git a/mysql-test/suite/engines/iuds/r/insert_year.result b/mysql-test/suite/engines/iuds/r/insert_year.result index 386c8090434..b9618ba4e2d 100644 --- a/mysql-test/suite/engines/iuds/r/insert_year.result +++ b/mysql-test/suite/engines/iuds/r/insert_year.result @@ -3235,9 +3235,21 @@ c1 c2 c3 c4 1999 1999 1998-12-30 1998-12-30 11:30:45 DROP TABLE t1,t2,t3,t4; CREATE TABLE t1(c1 YEAR(2) NOT NULL, c2 YEAR(2) NULL, c3 DATE, c4 DATETIME, PRIMARY KEY(c1), UNIQUE INDEX(c2)); +Warnings: +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead CREATE TABLE t2(c1 YEAR(2) NOT NULL, c2 YEAR(2) NULL, c3 DATE, c4 DATETIME, PRIMARY KEY(c1,c2)); +Warnings: +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead CREATE TABLE t3(c1 YEAR(2) NOT NULL, c2 YEAR(2) NULL, c3 DATE, c4 DATETIME, UNIQUE INDEX idx(c1,c2)); +Warnings: +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead CREATE TABLE t4(c1 YEAR(2) NOT NULL, c2 YEAR(2) NULL, c3 DATE, c4 DATETIME); +Warnings: +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead INSERT INTO t1 VALUES('1901','1901','98-12-31','98.12.31 11:30:45'),('1999','1999','98-12-30','98.12.30 11:30:45'),('2000','2000','98-12-29','98.12.29 11:30:45'),('2001','2001','98-12-28','98.12.28 11:30:45'),('2099','2099','98-12-27','98.12.27 11:30:45'),('2100','2100','98-12-26','98.12.26 11:30:45'),('2155','2155','98-12-26','98.12.26 11:30:45'); INSERT INTO t2 VALUES('1901','1901','98-12-31','98.12.31 11:30:45'),('1999','1999','98-12-30','98.12.30 11:30:45'),('2000','2000','98-12-29','98.12.29 11:30:45'),('2001','2001','98-12-28','98.12.28 11:30:45'),('2099','2099','98-12-27','98.12.27 11:30:45'),('2100','2100','98-12-26','98.12.26 11:30:45'),('2155','2155','98-12-26','98.12.26 11:30:45'); INSERT INTO t3 VALUES('1901','1901','98-12-31','98.12.31 11:30:45'),('1999','1999','98-12-30','98.12.30 11:30:45'),('2000','2000','98-12-29','98.12.29 11:30:45'),('2001','2001','98-12-28','98.12.28 11:30:45'),('2099','2099','98-12-27','98.12.27 11:30:45'),('2100','2100','98-12-26','98.12.26 11:30:45'),('2155','2155','98-12-26','98.12.26 11:30:45'); diff --git a/mysql-test/suite/engines/iuds/r/update_year.result b/mysql-test/suite/engines/iuds/r/update_year.result index 1b0ead45314..c762d70a276 100644 --- a/mysql-test/suite/engines/iuds/r/update_year.result +++ b/mysql-test/suite/engines/iuds/r/update_year.result @@ -2,7 +2,13 @@ DROP TABLE IF EXISTS t1,t2,t3,t4; CREATE TABLE t1(c1 YEAR NOT NULL,c2 YEAR, PRIMARY KEY(c1)); CREATE TABLE t2(c1 YEAR NOT NULL, c2 YEAR, UNIQUE INDEX idx(c1,c2)); CREATE TABLE t3(c1 YEAR(2) NOT NULL,c2 YEAR(2), PRIMARY KEY(c1)); +Warnings: +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead CREATE TABLE t4(c1 YEAR(2), c2 YEAR(2), UNIQUE INDEX idx(c1,c2)); +Warnings: +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead INSERT INTO t1 VALUES (1901,1901),(1970,1970),(1999,1999),(2000,2000),(2155,2155); INSERT INTO t2 VALUES (1901,1901),(1970,1970),(1999,1999),(2000,2000),(2155,2155); INSERT INTO t3 VALUES (1901,1901),(1970,1970),(1999,1999),(2000,2000),(2155,2155); diff --git a/mysql-test/suite/funcs_1/r/innodb_views.result b/mysql-test/suite/funcs_1/r/innodb_views.result index a335e135a4f..951068e3300 100644 --- a/mysql-test/suite/funcs_1/r/innodb_views.result +++ b/mysql-test/suite/funcs_1/r/innodb_views.result @@ -53,6 +53,8 @@ f107 year(4) not null default 2000, f108 enum("1enum","2enum") not null default "1enum", f109 set("1set","2set") not null default "1set" ) engine = innodb; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/innodb_tb2.txt' into table tb2; DROP DATABASE IF EXISTS test1; @@ -112,6 +114,8 @@ f107 year(4) not null default 2000, f108 enum("1enum","2enum") not null default "1enum", f109 set("1set","2set") not null default "1set" ) engine = innodb; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/innodb_tb2.txt' into table tb2; USE test; diff --git a/mysql-test/suite/funcs_1/r/is_columns_innodb.result b/mysql-test/suite/funcs_1/r/is_columns_innodb.result index 61079b06666..0abe8e11cf3 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_innodb.result +++ b/mysql-test/suite/funcs_1/r/is_columns_innodb.result @@ -132,6 +132,8 @@ f107 year(4) not null default 2000, f108 enum("1enum","2enum") not null default "1enum", f109 set("1set","2set") not null default "1set" ) engine = innodb; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/innodb_tb2.txt' into table tb2; drop table if exists tb3 ; @@ -262,6 +264,8 @@ f239 varchar(20000) binary, f240 varchar(2000), f241 char(100) ) engine = innodb; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/innodb_tb4.txt' into table tb4; USE test1; @@ -319,6 +323,8 @@ f107 year(4) not null default 2000, f108 enum("1enum","2enum") not null default "1enum", f109 set("1set","2set") not null default "1set" ) engine = innodb; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/innodb_tb2.txt' into table tb2; USE test; diff --git a/mysql-test/suite/funcs_1/r/is_columns_memory.result b/mysql-test/suite/funcs_1/r/is_columns_memory.result index 60dea25e0e3..c476b930f60 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_memory.result +++ b/mysql-test/suite/funcs_1/r/is_columns_memory.result @@ -128,6 +128,8 @@ f107 year(4) not null default 2000, f108 enum("1enum","2enum") not null default "1enum", f109 set("1set","2set") not null default "1set" ) engine = memory; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/memory_tb2.txt' into table tb2 ; drop table if exists tb3; @@ -251,6 +253,8 @@ f238 varchar(25000) binary, f239 varbinary(0), f240 varchar(1200) ) engine = memory; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/memory_tb4.txt' into table tb4; USE test1; @@ -308,6 +312,8 @@ f107 year(4) not null default 2000, f108 enum("1enum","2enum") not null default "1enum", f109 set("1set","2set") not null default "1set" ) engine = memory; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/memory_tb2.txt' into table tb2 ; USE test; diff --git a/mysql-test/suite/funcs_1/r/is_columns_myisam.result b/mysql-test/suite/funcs_1/r/is_columns_myisam.result index 6d0a44d2223..0e464d0fbc1 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_myisam.result +++ b/mysql-test/suite/funcs_1/r/is_columns_myisam.result @@ -144,6 +144,8 @@ f115 VARBINARY(27) null , f116 VARBINARY(64) null, f117 VARBINARY(192) null ) engine = myisam; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/myisam_tb2.txt' into table tb2; drop table if exists tb3 ; @@ -283,6 +285,8 @@ f240 varchar(120), f241 char(100), f242 bit(30) ) engine = myisam; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/myisam_tb4.txt' into table tb4; USE test1; @@ -348,6 +352,8 @@ f115 VARBINARY(27) null , f116 VARBINARY(64) null, f117 VARBINARY(192) null ) engine = myisam; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/myisam_tb2.txt' into table tb2; USE test; diff --git a/mysql-test/suite/funcs_1/r/is_columns_myisam_embedded.result b/mysql-test/suite/funcs_1/r/is_columns_myisam_embedded.result index 739f62e371a..7424ba8573d 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_myisam_embedded.result +++ b/mysql-test/suite/funcs_1/r/is_columns_myisam_embedded.result @@ -144,6 +144,8 @@ f115 VARBINARY(27) null , f116 VARBINARY(64) null, f117 VARBINARY(192) null ) engine = myisam; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/myisam_tb2.txt' into table tb2; drop table if exists tb3 ; @@ -283,6 +285,8 @@ f240 varchar(120), f241 char(100), f242 bit(30) ) engine = myisam; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/myisam_tb4.txt' into table tb4; USE test1; @@ -348,6 +352,8 @@ f115 VARBINARY(27) null , f116 VARBINARY(64) null, f117 VARBINARY(192) null ) engine = myisam; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/myisam_tb2.txt' into table tb2; USE test; diff --git a/mysql-test/suite/funcs_1/r/memory_views.result b/mysql-test/suite/funcs_1/r/memory_views.result index ccbd086b71f..0bb03e62192 100644 --- a/mysql-test/suite/funcs_1/r/memory_views.result +++ b/mysql-test/suite/funcs_1/r/memory_views.result @@ -54,6 +54,8 @@ f107 year(4) not null default 2000, f108 enum("1enum","2enum") not null default "1enum", f109 set("1set","2set") not null default "1set" ) engine = memory; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/memory_tb2.txt' into table tb2 ; DROP DATABASE IF EXISTS test1; @@ -113,6 +115,8 @@ f107 year(4) not null default 2000, f108 enum("1enum","2enum") not null default "1enum", f109 set("1set","2set") not null default "1set" ) engine = memory; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/memory_tb2.txt' into table tb2 ; USE test; diff --git a/mysql-test/suite/funcs_1/r/myisam_views-big.result b/mysql-test/suite/funcs_1/r/myisam_views-big.result index 9b07a0ae45b..0afb1d7d6c8 100644 --- a/mysql-test/suite/funcs_1/r/myisam_views-big.result +++ b/mysql-test/suite/funcs_1/r/myisam_views-big.result @@ -62,6 +62,8 @@ f115 VARBINARY(27) null , f116 VARBINARY(64) null, f117 VARBINARY(192) null ) engine = myisam; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/myisam_tb2.txt' into table tb2; DROP DATABASE IF EXISTS test1; @@ -129,6 +131,8 @@ f115 VARBINARY(27) null , f116 VARBINARY(64) null, f117 VARBINARY(192) null ) engine = myisam; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/myisam_tb2.txt' into table tb2; USE test; diff --git a/mysql-test/suite/funcs_1/r/ndb_views.result b/mysql-test/suite/funcs_1/r/ndb_views.result index b75f4955986..17eaedce56b 100644 --- a/mysql-test/suite/funcs_1/r/ndb_views.result +++ b/mysql-test/suite/funcs_1/r/ndb_views.result @@ -53,6 +53,8 @@ f107 year(4) not null default 2000, f108 enum("1enum","2enum") not null default "1enum", f109 set("1set","2set") not null default "1set" ) engine = ndb; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/ndb_tb2.txt' into table tb2 ; DROP DATABASE IF EXISTS test1; @@ -112,6 +114,8 @@ f107 year(4) not null default 2000, f108 enum("1enum","2enum") not null default "1enum", f109 set("1set","2set") not null default "1set" ) engine = ndb; +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead load data infile '/std_data/funcs_1/ndb_tb2.txt' into table tb2 ; USE test; diff --git a/mysql-test/suite/funcs_1/r/storedproc.result b/mysql-test/suite/funcs_1/r/storedproc.result index 8da7213bded..7647579820a 100644 --- a/mysql-test/suite/funcs_1/r/storedproc.result +++ b/mysql-test/suite/funcs_1/r/storedproc.result @@ -7526,9 +7526,13 @@ BEGIN declare x, y, z year(3) default 2005; SELECT x, y, z; END// +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead CALL sp1(); x y z 2005 2005 2005 +Warnings: +Note 1287 'YEAR(3)' is deprecated and will be removed in a future release. Please use YEAR(4) instead DROP PROCEDURE IF EXISTS sp1; CREATE PROCEDURE sp1( ) BEGIN diff --git a/mysql-test/suite/innodb_plugin/r/innodb_bug52745.result b/mysql-test/suite/innodb_plugin/r/innodb_bug52745.result index 74db8b0c20a..927ba0e0e53 100644 --- a/mysql-test/suite/innodb_plugin/r/innodb_bug52745.result +++ b/mysql-test/suite/innodb_plugin/r/innodb_bug52745.result @@ -58,6 +58,7 @@ col89 float unsigned zerofill DEFAULT NULL, col90 tinyblob ) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=1; Warnings: +Note 1287 'YEAR(2)' is deprecated and will be removed in a future release. Please use YEAR(4) instead Note 1291 Column 'col82' has duplicated value '' in ENUM Note 1291 Column 'col82' has duplicated value '' in ENUM INSERT INTO bug52745 SET diff --git a/mysql-test/t/type_year.test b/mysql-test/t/type_year.test index 1a9e66478e1..8ba8260cfc4 100644 --- a/mysql-test/t/type_year.test +++ b/mysql-test/t/type_year.test @@ -159,6 +159,14 @@ SELECT * FROM t1; SELECT COUNT(*) AS total_rows, MIN(c1) AS min_value, MAX(c1) FROM t1; DROP TABLE t1; +--echo # +--echo # WL#6219: Deprecate and remove YEAR(2) type +--echo # + +CREATE TABLE t1 (c1 YEAR(2), c2 YEAR(4)); +ALTER TABLE t1 MODIFY COLUMN c2 YEAR(2); +DROP TABLE t1; + --echo # --echo End of 5.1 tests diff --git a/sql/field.cc b/sql/field.cc index f398642fdb0..1c937755c0c 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -10227,6 +10227,17 @@ Create_field::Create_field(Field *old_field,Field *orig_field) geom_type= ((Field_geom*)old_field)->geom_type; break; #endif + case MYSQL_TYPE_YEAR: + if (length != 4) + { + char buff[sizeof("YEAR()") + MY_INT64_NUM_DECIMAL_DIGITS + 1]; + snprintf(buff, sizeof(buff), "YEAR(%lu)", length); + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_NOTE, + ER_WARN_DEPRECATED_SYNTAX, + ER(ER_WARN_DEPRECATED_SYNTAX), + buff, "YEAR(4)"); + } + break; default: break; } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 7e7ff7e91ca..854ba432362 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -5034,7 +5034,23 @@ type: $$= MYSQL_TYPE_VARCHAR; } | YEAR_SYM opt_field_length field_options - { $$=MYSQL_TYPE_YEAR; } + { + if (Lex->length) + { + errno= 0; + ulong length= strtoul(Lex->length, NULL, 10); + if (errno == 0 && length <= MAX_FIELD_BLOBLENGTH && length != 4) + { + char buff[sizeof("YEAR()") + MY_INT64_NUM_DECIMAL_DIGITS + 1]; + snprintf(buff, sizeof(buff), "YEAR(%lu)", length); + push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_NOTE, + ER_WARN_DEPRECATED_SYNTAX, + ER(ER_WARN_DEPRECATED_SYNTAX), + buff, "YEAR(4)"); + } + } + $$=MYSQL_TYPE_YEAR; + } | DATE_SYM { $$=MYSQL_TYPE_DATE; } | TIME_SYM From d672a10593756b2252ca8d7340988c2ac6438cb8 Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Fri, 29 Jun 2012 14:04:24 +0300 Subject: [PATCH 60/90] Bug #12910665: AUTH-PLUGIN-DATA-LEN NOT TESTED FOR VALIDITY BY THE CLIENT Added a check for a negative second part of the scramble length. --- sql-common/client.c | 6 ++++++ sql/sql_acl.cc | 1 + 2 files changed, 7 insertions(+) diff --git a/sql-common/client.c b/sql-common/client.c index be24c5e89e4..ef1e3c1b7d4 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -3415,6 +3415,12 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, mysql->server_status=uint2korr(end+3); mysql->server_capabilities|= uint2korr(end+5) << 16; pkt_scramble_len= end[7]; + if (pkt_scramble_len < 0) + { + set_mysql_error(mysql, CR_MALFORMED_PACKET, + unknown_sqlstate); /* purecov: inspected */ + goto error; + } } end+= 18; diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index d3715fd2312..242967fff6a 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -8032,6 +8032,7 @@ static bool send_server_handshake_packet(MPVIO_EXT *mpvio, int2store(end + 3, mpvio->server_status[0]); int2store(end + 5, mpvio->client_capabilities >> 16); end[7]= data_len; + DBUG_EXECUTE_IF("poison_srv_handshake_scramble_len", end[7]= -100;); bzero(end + 8, 10); end+= 18; /* write scramble tail */ From 1ede2dd8146254951493081f2297b0832fdd4d13 Mon Sep 17 00:00:00 2001 From: Jon Olav Hauglid Date: Fri, 29 Jun 2012 13:25:57 +0200 Subject: [PATCH 61/90] Bug#14238406 NEW COMPILATION WARNINGS WITH GCC 4.7 (-WERROR=NARROWING) This patch fixes various compilation warnings of the type "error: narrowing conversion of 'x' from 'datatype1' to 'datatype2' --- client/mysqlbinlog.cc | 4 ++-- include/my_getopt.h | 4 ++-- sql/log.h | 6 ++--- sql/mysqld.cc | 27 +++++++++++----------- sql/sql_profile.cc | 6 ++--- storage/innobase/handler/ha_innodb.cc | 8 +++---- storage/innodb_plugin/handler/ha_innodb.cc | 12 +++++----- 7 files changed, 34 insertions(+), 33 deletions(-) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index dd09e7a0938..e7840865a58 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2000, 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 @@ -1149,7 +1149,7 @@ static struct my_option my_long_options[] = "Stop reading the binlog at position N. Applies to the last binlog " "passed on the command line.", &stop_position, &stop_position, 0, GET_ULL, - REQUIRED_ARG, (ulonglong)(~(my_off_t)0), BIN_LOG_HEADER_SIZE, + REQUIRED_ARG, (longlong)(~(my_off_t)0), BIN_LOG_HEADER_SIZE, (ulonglong)(~(my_off_t)0), 0, 0, 0}, {"to-last-log", 't', "Requires -R. Will not stop at the end of the \ requested binlog but rather continue printing until the end of the last \ diff --git a/include/my_getopt.h b/include/my_getopt.h index 8112303a6a5..5824518a085 100644 --- a/include/my_getopt.h +++ b/include/my_getopt.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2002, 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 @@ -54,7 +54,7 @@ struct my_option enum get_opt_arg_type arg_type; longlong def_value; /* Default value */ longlong min_value; /* Min allowed value */ - longlong max_value; /* Max allowed value */ + ulonglong max_value; /* Max allowed value */ longlong sub_size; /* Subtract this from given value */ long block_size; /* Value should be a mult. of this */ void *app_type; /* To be used by an application */ diff --git a/sql/log.h b/sql/log.h index 9ed5db04e87..02721f1ddd0 100644 --- a/sql/log.h +++ b/sql/log.h @@ -1,5 +1,5 @@ /* - Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2005, 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 @@ -294,8 +294,8 @@ class MYSQL_BIN_LOG: public TC_LOG, private MYSQL_LOG int new_file_impl(bool need_lock); public: - MYSQL_LOG::generate_name; - MYSQL_LOG::is_open; + using MYSQL_LOG::generate_name; + using MYSQL_LOG::is_open; /* This is relay log */ bool is_relay_log; diff --git a/sql/mysqld.cc b/sql/mysqld.cc index db73504cb17..d6397280e0d 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -1,4 +1,4 @@ -/* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2000, 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 @@ -6710,7 +6710,7 @@ thread is in the relay logs.", {"max_binlog_cache_size", OPT_MAX_BINLOG_CACHE_SIZE, "Can be used to restrict the total size used to cache a multi-transaction query.", &max_binlog_cache_size, &max_binlog_cache_size, 0, - GET_ULL, REQUIRED_ARG, ULONG_MAX, IO_SIZE, ULONGLONG_MAX, 0, IO_SIZE, 0}, + GET_ULL, REQUIRED_ARG, (longlong) ULONG_MAX, IO_SIZE, ULONGLONG_MAX, 0, IO_SIZE, 0}, {"max_binlog_size", OPT_MAX_BINLOG_SIZE, "Binary log will be rotated automatically when the size exceeds this " "value. Will also apply to relay logs if max_relay_log_size is 0. " @@ -6748,7 +6748,7 @@ thread is in the relay logs.", "Joins that are probably going to read more than max_join_size records return an error.", &global_system_variables.max_join_size, &max_system_variables.max_join_size, 0, GET_HA_ROWS, REQUIRED_ARG, - HA_POS_ERROR, 1, HA_POS_ERROR, 0, 1, 0}, + (longlong) HA_POS_ERROR, 1, HA_POS_ERROR, 0, 1, 0}, {"max_length_for_sort_data", OPT_MAX_LENGTH_FOR_SORT_DATA, "Max number of bytes in sorted records.", &global_system_variables.max_length_for_sort_data, @@ -6775,7 +6775,7 @@ thread is in the relay logs.", "Limit assumed max number of seeks when looking up rows based on a key.", &global_system_variables.max_seeks_for_key, &max_system_variables.max_seeks_for_key, 0, GET_ULONG, - REQUIRED_ARG, ULONG_MAX, 1, ULONG_MAX, 0, 1, 0 }, + REQUIRED_ARG, (longlong) ULONG_MAX, 1, ULONG_MAX, 0, 1, 0 }, {"max_sort_length", OPT_MAX_SORT_LENGTH, "The number of bytes to use when sorting BLOB or TEXT values (only the " "first max_sort_length bytes of each value are used; the rest are ignored).", @@ -6799,7 +6799,7 @@ thread is in the relay logs.", {"max_write_lock_count", OPT_MAX_WRITE_LOCK_COUNT, "After this many write locks, allow some read locks to run in between.", &max_write_lock_count, &max_write_lock_count, 0, GET_ULONG, - REQUIRED_ARG, ULONG_MAX, 1, ULONG_MAX, 0, 1, 0}, + REQUIRED_ARG, (longlong) ULONG_MAX, 1, ULONG_MAX, 0, 1, 0}, {"min_examined_row_limit", OPT_MIN_EXAMINED_ROW_LIMIT, "Don't log queries which examine less than min_examined_row_limit rows to file.", &global_system_variables.min_examined_row_limit, @@ -6826,18 +6826,19 @@ thread is in the relay logs.", &global_system_variables.myisam_max_extra_sort_file_size, &max_system_variables.myisam_max_extra_sort_file_size, 0, GET_ULL, REQUIRED_ARG, (ulonglong) INT_MAX32, - 0, (ulonglong) MAX_FILE_SIZE, 0, 1, 0}, + 0, MAX_FILE_SIZE, 0, 1, 0}, {"myisam_max_sort_file_size", OPT_MYISAM_MAX_SORT_FILE_SIZE, "Don't use the fast sort index method to created index if the temporary " "file would get bigger than this.", &global_system_variables.myisam_max_sort_file_size, &max_system_variables.myisam_max_sort_file_size, 0, - GET_ULL, REQUIRED_ARG, (longlong) LONG_MAX, 0, (ulonglong) MAX_FILE_SIZE, + GET_ULL, REQUIRED_ARG, (longlong) LONG_MAX, 0, MAX_FILE_SIZE, 0, 1024*1024, 0}, {"myisam_mmap_size", OPT_MYISAM_MMAP_SIZE, "Can be used to restrict the total memory used for memory mmaping of myisam files", &myisam_mmap_size, &myisam_mmap_size, 0, - GET_ULL, REQUIRED_ARG, SIZE_T_MAX, MEMMAP_EXTRA_MARGIN, SIZE_T_MAX, 0, 1, 0}, + GET_ULL, REQUIRED_ARG, (longlong) SIZE_T_MAX, MEMMAP_EXTRA_MARGIN, SIZE_T_MAX, + 0, 1, 0}, {"myisam_repair_threads", OPT_MYISAM_REPAIR_THREADS, "Specifies whether several threads should be used when repairing MyISAM " "tables. For values > 1, one thread is used per index. The value of 1 " @@ -6850,7 +6851,7 @@ thread is in the relay logs.", "or when creating indexes with CREATE INDEX or ALTER TABLE.", &global_system_variables.myisam_sort_buff_size, &max_system_variables.myisam_sort_buff_size, 0, - GET_ULONG, REQUIRED_ARG, 8192 * 1024, 4096, ~0L, 0, 1, 0}, + GET_ULONG, REQUIRED_ARG, 8192 * 1024, 4096, ~0ULL, 0, 1, 0}, {"myisam_use_mmap", OPT_MYISAM_USE_MMAP, "Use memory mapping for reading and writing MyISAM tables.", &opt_myisam_use_mmap, &opt_myisam_use_mmap, 0, GET_BOOL, NO_ARG, @@ -6953,7 +6954,7 @@ thread is in the relay logs.", {"query_cache_size", OPT_QUERY_CACHE_SIZE, "The memory allocated to store results from old queries.", &query_cache_size, &query_cache_size, 0, GET_ULONG, - REQUIRED_ARG, 0, 0, (longlong) ULONG_MAX, 0, 1024, 0}, + REQUIRED_ARG, 0, 0, ULONG_MAX, 0, 1024, 0}, #ifdef HAVE_QUERY_CACHE {"query_cache_type", OPT_QUERY_CACHE_TYPE, "0 = OFF = Don't cache or retrieve results. 1 = ON = Cache all results " @@ -7015,7 +7016,7 @@ thread is in the relay logs.", "Maximum space to use for all relay logs.", &relay_log_space_limit, &relay_log_space_limit, 0, GET_ULL, REQUIRED_ARG, 0L, 0L, - (longlong) ULONG_MAX, 0, 1, 0}, + ULONG_MAX, 0, 1, 0}, {"slave_compressed_protocol", OPT_SLAVE_COMPRESSED_PROTOCOL, "Use compression on master/slave protocol.", &opt_slave_compressed_protocol, @@ -7030,7 +7031,7 @@ thread is in the relay logs.", "it failed with a deadlock or elapsed lock wait timeout, " "before giving up and stopping.", &slave_trans_retries, &slave_trans_retries, 0, - GET_ULONG, REQUIRED_ARG, 10L, 0L, (longlong) ULONG_MAX, 0, 1, 0}, + GET_ULONG, REQUIRED_ARG, 10L, 0L, ULONG_MAX, 0, 1, 0}, #endif /* HAVE_REPLICATION */ {"slow_launch_time", OPT_SLOW_LAUNCH_TIME, "If creating the thread takes longer than this value (in seconds), " @@ -7041,7 +7042,7 @@ thread is in the relay logs.", "Each thread that needs to do a sort allocates a buffer of this size.", &global_system_variables.sortbuff_size, &max_system_variables.sortbuff_size, 0, GET_ULONG, REQUIRED_ARG, - MAX_SORT_MEMORY, MIN_SORT_MEMORY+MALLOC_OVERHEAD*2, ~0L, MALLOC_OVERHEAD, + MAX_SORT_MEMORY, MIN_SORT_MEMORY+MALLOC_OVERHEAD*2, ~0ULL, MALLOC_OVERHEAD, 1, 0}, {"sync-binlog", OPT_SYNC_BINLOG, "Synchronously flush binary log to disk after every #th event. " diff --git a/sql/sql_profile.cc b/sql/sql_profile.cc index 1a6477e4c4d..49666dde476 100644 --- a/sql/sql_profile.cc +++ b/sql/sql_profile.cc @@ -1,5 +1,5 @@ /* - Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. + Copyright (c) 2007, 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 @@ -84,8 +84,8 @@ ST_FIELD_INFO query_profile_statistics_info[]= int make_profile_table_for_show(THD *thd, ST_SCHEMA_TABLE *schema_table) { - int profile_options = thd->lex->profile_options; - int fields_include_condition_truth_values[]= { + uint profile_options = thd->lex->profile_options; + uint fields_include_condition_truth_values[]= { FALSE, /* Query_id */ FALSE, /* Seq */ TRUE, /* Status */ diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 51b7007145c..796f51d737b 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -9128,7 +9128,7 @@ static MYSQL_SYSVAR_ULONG(max_dirty_pages_pct, srv_max_buf_pool_modified_pct, static MYSQL_SYSVAR_ULONG(max_purge_lag, srv_max_purge_lag, PLUGIN_VAR_RQCMDARG, "Desired maximum length of the purge queue (0 = no limit)", - NULL, NULL, 0, 0, ~0L, 0); + NULL, NULL, 0, 0, ~0UL, 0); static MYSQL_SYSVAR_BOOL(rollback_on_timeout, innobase_rollback_on_timeout, PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY, @@ -9182,7 +9182,7 @@ static MYSQL_SYSVAR_ULONG(commit_concurrency, innobase_commit_concurrency, static MYSQL_SYSVAR_ULONG(concurrency_tickets, srv_n_free_tickets_to_enter, PLUGIN_VAR_RQCMDARG, "Number of times a thread is allowed to enter InnoDB within the same SQL query after it has once got the ticket", - NULL, NULL, 500L, 1L, ~0L, 0); + NULL, NULL, 500L, 1L, ~0UL, 0); static MYSQL_SYSVAR_LONG(file_io_threads, innobase_file_io_threads, PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, @@ -9227,7 +9227,7 @@ static MYSQL_SYSVAR_LONG(open_files, innobase_open_files, static MYSQL_SYSVAR_ULONG(sync_spin_loops, srv_n_spin_wait_rounds, PLUGIN_VAR_RQCMDARG, "Count of spin-loop rounds in InnoDB mutexes", - NULL, NULL, 20L, 0L, ~0L, 0); + NULL, NULL, 20L, 0L, ~0UL, 0); static MYSQL_SYSVAR_ULONG(thread_concurrency, srv_thread_concurrency, PLUGIN_VAR_RQCMDARG, @@ -9237,7 +9237,7 @@ static MYSQL_SYSVAR_ULONG(thread_concurrency, srv_thread_concurrency, static MYSQL_SYSVAR_ULONG(thread_sleep_delay, srv_thread_sleep_delay, PLUGIN_VAR_RQCMDARG, "Time of innodb thread sleeping before joining InnoDB queue (usec). Value 0 disable a sleep", - NULL, NULL, 10000L, 0L, ~0L, 0); + NULL, NULL, 10000L, 0L, ~0UL, 0); static MYSQL_SYSVAR_STR(data_file_path, innobase_data_file_path, PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, diff --git a/storage/innodb_plugin/handler/ha_innodb.cc b/storage/innodb_plugin/handler/ha_innodb.cc index 2207f9d009d..412346e8349 100644 --- a/storage/innodb_plugin/handler/ha_innodb.cc +++ b/storage/innodb_plugin/handler/ha_innodb.cc @@ -10974,7 +10974,7 @@ static MYSQL_SYSVAR_BOOL(doublewrite, innobase_use_doublewrite, static MYSQL_SYSVAR_ULONG(io_capacity, srv_io_capacity, PLUGIN_VAR_RQCMDARG, "Number of IOPs the server can do. Tunes the background IO rate", - NULL, NULL, 200, 100, ~0L, 0); + NULL, NULL, 200, 100, ~0UL, 0); static MYSQL_SYSVAR_ULONG(fast_shutdown, innobase_fast_shutdown, PLUGIN_VAR_OPCMDARG, @@ -11052,7 +11052,7 @@ static MYSQL_SYSVAR_BOOL(adaptive_flushing, srv_adaptive_flushing, static MYSQL_SYSVAR_ULONG(max_purge_lag, srv_max_purge_lag, PLUGIN_VAR_RQCMDARG, "Desired maximum length of the purge queue (0 = no limit)", - NULL, NULL, 0, 0, ~0L, 0); + NULL, NULL, 0, 0, ~0UL, 0); static MYSQL_SYSVAR_BOOL(rollback_on_timeout, innobase_rollback_on_timeout, PLUGIN_VAR_OPCMDARG | PLUGIN_VAR_READONLY, @@ -11109,7 +11109,7 @@ static MYSQL_SYSVAR_ULONG(commit_concurrency, innobase_commit_concurrency, static MYSQL_SYSVAR_ULONG(concurrency_tickets, srv_n_free_tickets_to_enter, PLUGIN_VAR_RQCMDARG, "Number of times a thread is allowed to enter InnoDB within the same SQL query after it has once got the ticket", - NULL, NULL, 500L, 1L, ~0L, 0); + NULL, NULL, 500L, 1L, ~0UL, 0); static MYSQL_SYSVAR_LONG(file_io_threads, innobase_file_io_threads, PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY | PLUGIN_VAR_NOSYSVAR, @@ -11171,12 +11171,12 @@ static MYSQL_SYSVAR_LONG(open_files, innobase_open_files, static MYSQL_SYSVAR_ULONG(sync_spin_loops, srv_n_spin_wait_rounds, PLUGIN_VAR_RQCMDARG, "Count of spin-loop rounds in InnoDB mutexes (30 by default)", - NULL, NULL, 30L, 0L, ~0L, 0); + NULL, NULL, 30L, 0L, ~0UL, 0); static MYSQL_SYSVAR_ULONG(spin_wait_delay, srv_spin_wait_delay, PLUGIN_VAR_OPCMDARG, "Maximum delay between polling for a spin lock (6 by default)", - NULL, NULL, 6L, 0L, ~0L, 0); + NULL, NULL, 6L, 0L, ~0UL, 0); static MYSQL_SYSVAR_ULONG(thread_concurrency, srv_thread_concurrency, PLUGIN_VAR_RQCMDARG, @@ -11186,7 +11186,7 @@ static MYSQL_SYSVAR_ULONG(thread_concurrency, srv_thread_concurrency, static MYSQL_SYSVAR_ULONG(thread_sleep_delay, srv_thread_sleep_delay, PLUGIN_VAR_RQCMDARG, "Time of innodb thread sleeping before joining InnoDB queue (usec). Value 0 disable a sleep", - NULL, NULL, 10000L, 0L, ~0L, 0); + NULL, NULL, 10000L, 0L, ~0UL, 0); static MYSQL_SYSVAR_STR(data_file_path, innobase_data_file_path, PLUGIN_VAR_RQCMDARG | PLUGIN_VAR_READONLY, From 5f5df5091e6ddaf445b281f16b7dcf950ed4af02 Mon Sep 17 00:00:00 2001 From: Bjorn Munch Date: Fri, 29 Jun 2012 14:19:31 +0200 Subject: [PATCH 62/90] Fix mysql_plugin test to handle version XXa --- mysql-test/t/mysql_plugin.test | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mysql-test/t/mysql_plugin.test b/mysql-test/t/mysql_plugin.test index 71617b86330..a05b5a624d9 100644 --- a/mysql-test/t/mysql_plugin.test +++ b/mysql-test/t/mysql_plugin.test @@ -372,11 +372,11 @@ let $MYSQL_PLUGIN_CMD= $MYSQL_PLUGIN -n --datadir=$MYSQL_DATADIR --basedir=$MYSQ --echo # Show the help. --echo # replace_result $MYSQL_PLUGIN mysql_plugin; ---replace_regex /Ver [0-9.]+ Distrib [0-9.]+/Ver V.V.VV Distrib XX.XX.XX/ /XX-m[0-9]+/XX/ +--replace_regex /Ver [0-9.]+ Distrib [0-9.]+/Ver V.V.VV Distrib XX.XX.XX/ /XX-m[0-9]+/XX/ /XX[a-z]/XX/ --exec $MYSQL_PLUGIN --help replace_result $MYSQL_PLUGIN mysql_plugin; ---replace_regex /Ver [0-9.]+ Distrib [0-9.]+/Ver V.V.VV Distrib XX.XX.XX/ /XX-m[0-9]+/XX/ +--replace_regex /Ver [0-9.]+ Distrib [0-9.]+/Ver V.V.VV Distrib XX.XX.XX/ /XX-m[0-9]+/XX/ /XX[a-z]/XX/ --exec $MYSQL_PLUGIN --version # From 521deaf36f3ae6686ebea64afe5d3195ad3f80d2 Mon Sep 17 00:00:00 2001 From: Gleb Shchepa Date: Fri, 29 Jun 2012 18:24:43 +0400 Subject: [PATCH 63/90] minor update to make MSVS happy --- sql/field.cc | 2 +- sql/sql_yacc.yy | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sql/field.cc b/sql/field.cc index 1c937755c0c..ff631edd8d4 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -10231,7 +10231,7 @@ Create_field::Create_field(Field *old_field,Field *orig_field) if (length != 4) { char buff[sizeof("YEAR()") + MY_INT64_NUM_DECIMAL_DIGITS + 1]; - snprintf(buff, sizeof(buff), "YEAR(%lu)", length); + my_snprintf(buff, sizeof(buff), "YEAR(%lu)", length); push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_WARN_DEPRECATED_SYNTAX, ER(ER_WARN_DEPRECATED_SYNTAX), diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 854ba432362..7a6981f778a 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -5042,7 +5042,7 @@ type: if (errno == 0 && length <= MAX_FIELD_BLOBLENGTH && length != 4) { char buff[sizeof("YEAR()") + MY_INT64_NUM_DECIMAL_DIGITS + 1]; - snprintf(buff, sizeof(buff), "YEAR(%lu)", length); + my_snprintf(buff, sizeof(buff), "YEAR(%lu)", length); push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_NOTE, ER_WARN_DEPRECATED_SYNTAX, ER(ER_WARN_DEPRECATED_SYNTAX), From 2fc2d9a23287d71c665a81eac2ade64d2c22f183 Mon Sep 17 00:00:00 2001 From: Joerg Bruehe Date: Mon, 2 Jul 2012 13:09:33 +0200 Subject: [PATCH 64/90] Added some extra optional path to test suites. --- mysql-test/lib/My/Find.pm | 7 ++++--- mysql-test/lib/mtr_cases.pm | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mysql-test/lib/My/Find.pm b/mysql-test/lib/My/Find.pm index 952a3c4143d..1f99c470e73 100644 --- a/mysql-test/lib/My/Find.pm +++ b/mysql-test/lib/My/Find.pm @@ -126,9 +126,9 @@ sub my_find_file { # # sub my_find_dir { - my ($base, $paths, $dirs, $required)= @_; - croak "usage: my_find_dir(, [, ])" - unless (@_ == 3 or @_ == 2); + my ($base, $paths, $dirs, $optional)= @_; + croak "usage: my_find_dir(, [, [, ]])" + unless (@_ == 3 or @_ == 2 or @_ == 4); # ------------------------------------------------------- # Find and return the first directory @@ -136,6 +136,7 @@ sub my_find_dir { foreach my $path (my_find_paths($base, $paths, $dirs)) { return $path if ( -d $path ); } + return "" if $optional; find_error($base, $paths, $dirs); } diff --git a/mysql-test/lib/mtr_cases.pm b/mysql-test/lib/mtr_cases.pm index c8381e16061..2f68b70e3e2 100644 --- a/mysql-test/lib/mtr_cases.pm +++ b/mysql-test/lib/mtr_cases.pm @@ -137,6 +137,7 @@ sub collect_test_cases ($$$$) { { push(@$cases, collect_one_suite($suite, $opt_cases, $opt_skip_test_list)); last if $some_test_found; + push(@$cases, collect_one_suite("i_".$suite, $opt_cases, $opt_skip_test_list)); } } @@ -288,13 +289,15 @@ sub collect_one_suite($) $suitedir= my_find_dir($::basedir, ["share/mysql-test/suite", "mysql-test/suite", + "internal/mysql-test/suite", "mysql-test", # Look in storage engine specific suite dirs "storage/*/mtr", # Look in plugin specific suite dir "plugin/$suite/tests", ], - [$suite, "mtr"]); + [$suite, "mtr"], ($suite =~ /^i_/)); + return unless $suitedir; } mtr_verbose("suitedir: $suitedir"); } From 608c2c018e27cd27df8cbd57e3538509734e8dc0 Mon Sep 17 00:00:00 2001 From: Mayank Prasad Date: Tue, 3 Jul 2012 09:55:51 +0530 Subject: [PATCH 65/90] Bug#13417440 : 63340: ARCHIVE FILE IO NOT INSTRUMENTED Details: - Modified test case to make sure its run for all and not only for archive Storage Engine. --- mysql-test/suite/perfschema/r/query_cache.result | 12 ++++++------ mysql-test/suite/perfschema/t/query_cache.test | 5 ++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/mysql-test/suite/perfschema/r/query_cache.result b/mysql-test/suite/perfschema/r/query_cache.result index 56511999ab2..8786cd055ca 100644 --- a/mysql-test/suite/perfschema/r/query_cache.result +++ b/mysql-test/suite/perfschema/r/query_cache.result @@ -36,9 +36,9 @@ Qcache_hits 1 select spins from performance_schema.events_waits_current order by event_name limit 1; spins NULL -select name from performance_schema.setup_instruments order by name limit 1; -name -wait/io/file/archive/data +select * from performance_schema.setup_timers where name='wait'; +NAME TIMER_NAME +wait CYCLE show status like "Qcache_queries_in_cache"; Variable_name Value Qcache_queries_in_cache 1 @@ -51,9 +51,9 @@ Qcache_hits 1 select spins from performance_schema.events_waits_current order by event_name limit 1; spins NULL -select name from performance_schema.setup_instruments order by name limit 1; -name -wait/io/file/archive/data +select * from performance_schema.setup_timers where name='wait'; +NAME TIMER_NAME +wait CYCLE show status like "Qcache_queries_in_cache"; Variable_name Value Qcache_queries_in_cache 1 diff --git a/mysql-test/suite/perfschema/t/query_cache.test b/mysql-test/suite/perfschema/t/query_cache.test index 08292306a25..60d4a648222 100644 --- a/mysql-test/suite/perfschema/t/query_cache.test +++ b/mysql-test/suite/perfschema/t/query_cache.test @@ -6,7 +6,6 @@ --source include/have_query_cache.inc --source include/not_embedded.inc --source include/have_perfschema.inc ---source include/have_archive.inc --disable_warnings drop table if exists t1; @@ -35,7 +34,7 @@ show status like "Qcache_hits"; select spins from performance_schema.events_waits_current order by event_name limit 1; -select name from performance_schema.setup_instruments order by name limit 1; +select * from performance_schema.setup_timers where name='wait'; show status like "Qcache_queries_in_cache"; show status like "Qcache_inserts"; @@ -43,7 +42,7 @@ show status like "Qcache_hits"; select spins from performance_schema.events_waits_current order by event_name limit 1; -select name from performance_schema.setup_instruments order by name limit 1; +select * from performance_schema.setup_timers where name='wait'; show status like "Qcache_queries_in_cache"; show status like "Qcache_inserts"; From 91c8e79fcd98bb586f32b22f5d67fcd5ae08ae28 Mon Sep 17 00:00:00 2001 From: Rohit Kalhans Date: Tue, 3 Jul 2012 18:00:21 +0530 Subject: [PATCH 66/90] BUG#11762667:MYSQLBINLOG IGNORES ERRORS WHILE WRITING OUTPUT This is a followup patch for the bug enabling the test i_binlog.binlog_mysqlbinlog_file_write.test this was disabled in mysql trunk and mysql 5.5 as in the release build mysqlbinlog was not debug compiled whereas the mysqld was. Since have_debug.inc script checks only for mysqld to be debug compiled, the test was not being skipped on release builds. We resolve this problem by creating a new inc file mysqlbinlog_have_debug.inc which checks exclusively for mysqlbinlog to be debug compiled. if not it skips the test. mysql-test/include/mysqlbinlog_have_debug.inc: new inc file to check if mysqlbinlog is debug compiled. --- mysql-test/include/mysqlbinlog_have_debug.inc | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 mysql-test/include/mysqlbinlog_have_debug.inc diff --git a/mysql-test/include/mysqlbinlog_have_debug.inc b/mysql-test/include/mysqlbinlog_have_debug.inc new file mode 100644 index 00000000000..14da1379ecd --- /dev/null +++ b/mysql-test/include/mysqlbinlog_have_debug.inc @@ -0,0 +1,34 @@ +############################################# +# checks if mysqlbinlog is debug compiled +# this "cannot" be done simply by using +# have_debug.inc +############################################# + +--disable_query_log +--let $temp_out_help_file=$MYSQL_TMP_DIR/mysqlbinlog_help.tmp +--exec $MYSQL_BINLOG --help>$temp_out_help_file +let log_tmp=$temp_out_help_file; +--let $temp_inc=$MYSQL_TMP_DIR/temp.inc +let inc_tmp=$temp_inc; + +--perl +use strict; +my $tmp_file= $ENV{'log_tmp'} or die "log_tmp not set"; +open(FILE, "$tmp_file") or die("Unable to open $tmp_file: $!\n"); +my $count = () = grep(/Output debug log/g,); +close FILE; + +my $temp_inc= $ENV{'inc_tmp'} or die "temp_inc not set"; +open(FILE_INC,">", "$temp_inc") or die("can't open file \"$temp_inc\": $!"); +print FILE_INC '--let $is_debug= '.$count; +close FILE_INC; +EOF +--source $temp_inc + +if (!$is_debug) +{ + --skip mysqlbinlog needs to be debug compiled +} +--remove_file $temp_out_help_file +--remove_file $temp_inc +--enable_query_log From 9ce35ffc8677ff3c7171576497ed6c7330000b72 Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Wed, 4 Jul 2012 17:48:58 +0300 Subject: [PATCH 67/90] Bug #11753490: 44939: sql dumps containing broad views fail when executing The problem is that mysql lacks information about the objects a view depends on so it can't dump views and tables in the proper order. Thus it needs to create "stand-in" myisam tables for each view while dumping the tables that it later drops and replaces with the actual view view definition. But since views can have much more columns than an actual table creating these stand-in tables may be problematic. There's no way to portably find out how many columns an mysiam table can have. It's a complicated formula depending on internal server constants. Thus we can't have a reliable error check without repeating the logic and the formula inside mysqldump. 1. Changed the type of the columns of the stand-in tables mysqldump makes to satisfy view dependencies from the original type to smallint to save on row space. 2. Added a warning on the mysqldump's standard error for a possible problems replaying the dump file if the columns of a view exceed 1000. 3. Added a test case. --- client/mysqldump.c | 35 ++++++++++++++++++++------ mysql-test/r/mysqldump.result | 46 +++++++++++++++++------------------ 2 files changed, 51 insertions(+), 30 deletions(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index e273ca0e7fd..dcfe25a5f61 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -2558,6 +2558,7 @@ static uint get_table_structure(char *table, char *db, char *table_type, if (strcmp(field->name, "View") == 0) { char *scv_buff= NULL; + my_ulonglong n_cols; verbose_msg("-- It's a view, create dummy table for view\n"); @@ -2572,8 +2573,8 @@ static uint get_table_structure(char *table, char *db, char *table_type, the same name in order to satisfy views that depend on this view. The table will be removed when the actual view is created. - The properties of each column, aside from the data type, are not - preserved in this temporary table, because they are not necessary. + The properties of each column, are not preserved in this temporary + table, because they are not necessary. This will not be necessary once we can determine dependencies between views and can simply dump them in the appropriate order. @@ -2600,8 +2601,23 @@ static uint get_table_structure(char *table, char *db, char *table_type, else my_free(scv_buff); - if (mysql_num_rows(result)) + n_cols= mysql_num_rows(result); + if (0 != n_cols) { + + /* + The actual formula is based on the column names and how the .FRM + files are stored and is too volatile to be repeated here. + Thus we simply warn the user if the columns exceed a limit we + know works most of the time. + */ + if (n_cols >= 1000) + fprintf(stderr, + "-- Warning: Creating a stand-in table for view %s may" + " fail when replaying the dump file produced because " + "of the number of columns exceeding 1000. Exercise " + "caution when replaying the produced dump file.\n", + table); if (opt_drop) { /* @@ -2628,14 +2644,19 @@ static uint get_table_structure(char *table, char *db, char *table_type, row= mysql_fetch_row(result); - fprintf(sql_file, " %s %s", quote_name(row[0], name_buff, 0), - row[1]); + /* + The actual column type doesn't matter anyway, since the table will + be dropped at run time. + We do tinyint to avoid hitting the row size limit. + */ + fprintf(sql_file, " %s tinyint NOT NULL", + quote_name(row[0], name_buff, 0)); while((row= mysql_fetch_row(result))) { /* col name, col type */ - fprintf(sql_file, ",\n %s %s", - quote_name(row[0], name_buff, 0), row[1]); + fprintf(sql_file, ",\n %s tinyint NOT NULL", + quote_name(row[0], name_buff, 0)); } /* diff --git a/mysql-test/r/mysqldump.result b/mysql-test/r/mysqldump.result index 15fdddb18be..5f3b29f5f7c 100644 --- a/mysql-test/r/mysqldump.result +++ b/mysql-test/r/mysqldump.result @@ -1988,7 +1988,7 @@ DROP TABLE IF EXISTS `v2`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE TABLE `v2` ( - `a` varchar(30) + `a` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; /*!50001 DROP TABLE IF EXISTS `v2`*/; @@ -2082,7 +2082,7 @@ DROP TABLE IF EXISTS `v1`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE TABLE `v1` ( - `a` int(11) + `a` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; /*!50001 DROP TABLE IF EXISTS `v1`*/; @@ -2156,7 +2156,7 @@ DROP TABLE IF EXISTS `v2`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE TABLE `v2` ( - `a` varchar(30) + `a` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; /*!50001 DROP TABLE IF EXISTS `v2`*/; @@ -2270,9 +2270,9 @@ DROP TABLE IF EXISTS `v1`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE TABLE `v1` ( - `a` int(11), - `b` int(11), - `c` varchar(30) + `a` tinyint NOT NULL, + `b` tinyint NOT NULL, + `c` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS `v2`; @@ -2280,7 +2280,7 @@ DROP TABLE IF EXISTS `v2`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE TABLE `v2` ( - `a` int(11) + `a` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS `v3`; @@ -2288,9 +2288,9 @@ DROP TABLE IF EXISTS `v3`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE TABLE `v3` ( - `a` int(11), - `b` int(11), - `c` varchar(30) + `a` tinyint NOT NULL, + `b` tinyint NOT NULL, + `c` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; /*!50001 DROP TABLE IF EXISTS `v1`*/; @@ -3027,9 +3027,9 @@ DROP TABLE IF EXISTS `v0`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE TABLE `v0` ( - `a` int(11), - `b` varchar(32), - `c` varchar(32) + `a` tinyint NOT NULL, + `b` tinyint NOT NULL, + `c` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS `v1`; @@ -3037,9 +3037,9 @@ DROP TABLE IF EXISTS `v1`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE TABLE `v1` ( - `a` int(11), - `b` varchar(32), - `c` varchar(32) + `a` tinyint NOT NULL, + `b` tinyint NOT NULL, + `c` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; DROP TABLE IF EXISTS `v2`; @@ -3047,9 +3047,9 @@ DROP TABLE IF EXISTS `v2`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE TABLE `v2` ( - `a` int(11), - `b` varchar(32), - `c` varchar(32) + `a` tinyint NOT NULL, + `b` tinyint NOT NULL, + `c` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; @@ -3429,7 +3429,7 @@ DROP TABLE IF EXISTS `v1`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE TABLE `v1` ( - `id` int(11) + `id` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; @@ -3489,7 +3489,7 @@ USE `mysqldump_views`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE TABLE `nasishnasifu` ( - `id` bigint(20) unsigned + `id` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; @@ -3882,7 +3882,7 @@ DROP TABLE IF EXISTS `v2`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE TABLE `v2` ( - `c` int(11) + `c` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; /*!50001 DROP TABLE IF EXISTS `v2`*/; @@ -4299,7 +4299,7 @@ DROP TABLE IF EXISTS `v1`; SET @saved_cs_client = @@character_set_client; SET character_set_client = utf8; /*!50001 CREATE TABLE `v1` ( - `id` int(11) + `id` tinyint NOT NULL ) ENGINE=MyISAM */; SET character_set_client = @saved_cs_client; From 06f6e4fe957c6edd7b3655d4987d0fbd67cdb9d6 Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Thu, 5 Jul 2012 09:55:20 +0300 Subject: [PATCH 68/90] Bug #12998841: libmysql divulges plaintext password upon request in 5.5 1. Clear text password client plugin disabled by default. 2. Added an environment variable LIBMYSQL_ENABLE_CLEARTEXT_PLUGIN, that when set to something starting with '1', 'Y' or 'y' will enable the clear text plugin for all connections. 3. Added a new mysql_options() option : MYSQL_ENABLE_CLEARTEXT_PLUGIN that takes an my_bool argument. When the value of the argument is non-zero the clear text plugin is enabled for this connection only. 4. Added an enable-cleartext-plugin config file option that takes a numeric argument. If the numeric value of the numeric argument is non-zero the clear text plugin is enabled for the connection 5. Added a boolean command line option "--enable_cleartext_plugin" to mysql, mysqlslap and mysqladmin. When specified it will call mysql_options with the effect of #3 6. Added a new CLEARTEXT option to the connect command in mysqltest. When specified it will enable the cleartext plugin for usage. 7. Added test cases and updated existing ones that need the clear text plugin. --- client/client_priv.h | 1 + client/mysql.cc | 13 +++++++ client/mysqladmin.cc | 13 +++++++ client/mysqlslap.c | 12 ++++++ client/mysqltest.cc | 8 +++- include/mysql.h | 3 +- include/mysql.h.pp | 3 +- include/sql_common.h | 2 + mysql-test/t/plugin_auth.test | 4 +- sql-common/client.c | 69 ++++++++++++++++++++++++++++++----- sql-common/client_plugin.c | 5 +++ 11 files changed, 119 insertions(+), 14 deletions(-) diff --git a/client/client_priv.h b/client/client_priv.h index b776dcf8014..2362811d2b3 100644 --- a/client/client_priv.h +++ b/client/client_priv.h @@ -87,6 +87,7 @@ enum options_client OPT_PLUGIN_DIR, OPT_DEFAULT_AUTH, OPT_DEFAULT_PLUGIN, + OPT_ENABLE_CLEARTEXT_PLUGIN, OPT_MAX_CLIENT_OPTION }; diff --git a/client/mysql.cc b/client/mysql.cc index b6bc2f4b68f..630c6215603 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -148,6 +148,8 @@ static my_bool column_types_flag; static my_bool preserve_comments= 0; static ulong opt_max_allowed_packet, opt_net_buffer_length; static uint verbose=0,opt_silent=0,opt_mysql_port=0, opt_local_infile=0; +static uint opt_enable_cleartext_plugin= 0; +static my_bool using_opt_enable_cleartext_plugin= 0; static uint my_end_arg; static char * opt_mysql_unix_port=0; static int connect_flag=CLIENT_INTERACTIVE; @@ -1409,6 +1411,10 @@ static struct my_option my_long_options[] = &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"delimiter", OPT_DELIMITER, "Delimiter to be used.", &delimiter_str, &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"enable_cleartext_plugin", OPT_ENABLE_CLEARTEXT_PLUGIN, + "Enable/disable the clear text authentication plugin.", + &opt_enable_cleartext_plugin, &opt_enable_cleartext_plugin, + 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0}, {"execute", 'e', "Execute command and quit. (Disables --force and history file.)", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"vertical", 'E', "Print the output of a query (rows) vertically.", @@ -1636,6 +1642,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), case OPT_LOCAL_INFILE: using_opt_local_infile=1; break; + case OPT_ENABLE_CLEARTEXT_PLUGIN: + using_opt_enable_cleartext_plugin= TRUE; + break; case OPT_TEE: if (argument == disabled_my_option) { @@ -4321,6 +4330,10 @@ sql_real_connect(char *host,char *database,char *user,char *password, if (opt_default_auth && *opt_default_auth) mysql_options(&mysql, MYSQL_DEFAULT_AUTH, opt_default_auth); + if (using_opt_enable_cleartext_plugin) + mysql_options(&mysql, MYSQL_ENABLE_CLEARTEXT_PLUGIN, + (char*) &opt_enable_cleartext_plugin); + if (!mysql_real_connect(&mysql, host, user, password, database, opt_mysql_port, opt_mysql_unix_port, connect_flag | CLIENT_MULTI_STATEMENTS)) diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc index 3f33c25e664..321efd36642 100644 --- a/client/mysqladmin.cc +++ b/client/mysqladmin.cc @@ -43,6 +43,8 @@ static uint opt_count_iterations= 0, my_end_arg; static ulong opt_connect_timeout, opt_shutdown_timeout; static char * unix_port=0; static char *opt_plugin_dir= 0, *opt_default_auth= 0; +static uint opt_enable_cleartext_plugin= 0; +static my_bool using_opt_enable_cleartext_plugin= 0; #ifdef HAVE_SMEM static char *shared_memory_base_name=0; @@ -212,6 +214,10 @@ static struct my_option my_long_options[] = "Default authentication client-side plugin to use.", &opt_default_auth, &opt_default_auth, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"enable_cleartext_plugin", OPT_ENABLE_CLEARTEXT_PLUGIN, + "Enable/disable the clear text authentication plugin.", + &opt_enable_cleartext_plugin, &opt_enable_cleartext_plugin, + 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; @@ -282,6 +288,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib, opt->name); break; + case OPT_ENABLE_CLEARTEXT_PLUGIN: + using_opt_enable_cleartext_plugin= TRUE; + break; } if (error) { @@ -354,6 +363,10 @@ int main(int argc,char *argv[]) if (opt_default_auth && *opt_default_auth) mysql_options(&mysql, MYSQL_DEFAULT_AUTH, opt_default_auth); + if (using_opt_enable_cleartext_plugin) + mysql_options(&mysql, MYSQL_ENABLE_CLEARTEXT_PLUGIN, + (char*) &opt_enable_cleartext_plugin); + if (sql_connect(&mysql, option_wait)) { /* diff --git a/client/mysqlslap.c b/client/mysqlslap.c index a2c01b85b5a..ac1cc31733c 100644 --- a/client/mysqlslap.c +++ b/client/mysqlslap.c @@ -125,6 +125,8 @@ static char *host= NULL, *opt_password= NULL, *user= NULL, *post_system= NULL, *opt_mysql_unix_port= NULL; static char *opt_plugin_dir= 0, *opt_default_auth= 0; +static uint opt_enable_cleartext_plugin= 0; +static my_bool using_opt_enable_cleartext_plugin= 0; const char *delimiter= "\n"; @@ -348,6 +350,9 @@ int main(int argc, char **argv) if (opt_default_auth && *opt_default_auth) mysql_options(&mysql, MYSQL_DEFAULT_AUTH, opt_default_auth); + if (using_opt_enable_cleartext_plugin) + mysql_options(&mysql, MYSQL_ENABLE_CLEARTEXT_PLUGIN, + (char*) &opt_enable_cleartext_plugin); if (!opt_only_print) { if (!(mysql_real_connect(&mysql, host, user, opt_password, @@ -603,6 +608,10 @@ static struct my_option my_long_options[] = "Detach (close and reopen) connections after X number of requests.", &detach_rate, &detach_rate, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, + {"enable_cleartext_plugin", OPT_ENABLE_CLEARTEXT_PLUGIN, + "Enable/disable the clear text authentication plugin.", + &opt_enable_cleartext_plugin, &opt_enable_cleartext_plugin, + 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0}, {"engine", 'e', "Storage engine to use for creating the table.", &default_engine, &default_engine, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -761,6 +770,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), case 'I': /* Info */ usage(); exit(0); + case OPT_ENABLE_CLEARTEXT_PLUGIN: + using_opt_enable_cleartext_plugin= TRUE; + break; } DBUG_RETURN(0); } diff --git a/client/mysqltest.cc b/client/mysqltest.cc index b1784fdc7b6..34d8edcbe0b 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -5456,7 +5456,7 @@ void do_connect(struct st_command *command) int con_port= opt_port; char *con_options; my_bool con_ssl= 0, con_compress= 0; - my_bool con_pipe= 0, con_shm= 0; + my_bool con_pipe= 0, con_shm= 0, con_cleartext_enable= 0; struct st_connection* con_slot; static DYNAMIC_STRING ds_connection_name; @@ -5546,6 +5546,8 @@ void do_connect(struct st_command *command) con_pipe= 1; else if (!strncmp(con_options, "SHM", 3)) con_shm= 1; + else if (!strncmp(con_options, "CLEARTEXT", 9)) + con_cleartext_enable= 1; else die("Illegal option to connect: %.*s", (int) (end - con_options), con_options); @@ -5642,6 +5644,10 @@ void do_connect(struct st_command *command) if (ds_default_auth.length) mysql_options(&con_slot->mysql, MYSQL_DEFAULT_AUTH, ds_default_auth.str); + + if (con_cleartext_enable) + mysql_options(&con_slot->mysql, MYSQL_ENABLE_CLEARTEXT_PLUGIN, + (char*) &con_cleartext_enable); /* Special database to allow one to connect without a database name */ if (ds_database.length && !strcmp(ds_database.str,"*NO-ONE*")) dynstr_set(&ds_database, ""); diff --git a/include/mysql.h b/include/mysql.h index cff8c647152..0ed35413a1c 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -166,7 +166,8 @@ enum mysql_option MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, - MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH + MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH, + MYSQL_ENABLE_CLEARTEXT_PLUGIN }; /** diff --git a/include/mysql.h.pp b/include/mysql.h.pp index 15ec563dfc2..c2c5ba35044 100644 --- a/include/mysql.h.pp +++ b/include/mysql.h.pp @@ -262,7 +262,8 @@ enum mysql_option MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, - MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH + MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH, + MYSQL_ENABLE_CLEARTEXT_PLUGIN }; struct st_mysql_options_extention; struct st_mysql_options { diff --git a/include/sql_common.h b/include/sql_common.h index 307b443d6d6..a2ea3ac45e7 100644 --- a/include/sql_common.h +++ b/include/sql_common.h @@ -31,6 +31,7 @@ extern const char *not_error_sqlstate; struct st_mysql_options_extention { char *plugin_dir; char *default_auth; + my_bool enable_cleartext_plugin; }; typedef struct st_mysql_methods @@ -104,6 +105,7 @@ int mysql_client_plugin_init(); void mysql_client_plugin_deinit(); struct st_mysql_client_plugin; extern struct st_mysql_client_plugin *mysql_client_builtins[]; +extern my_bool libmysql_cleartext_plugin_enabled; #ifdef __cplusplus } diff --git a/mysql-test/t/plugin_auth.test b/mysql-test/t/plugin_auth.test index f169360cf2e..75d3ef3e807 100644 --- a/mysql-test/t/plugin_auth.test +++ b/mysql-test/t/plugin_auth.test @@ -422,10 +422,10 @@ CREATE USER uplain@localhost IDENTIFIED WITH 'cleartext_plugin_server' --echo ## test plugin auth --disable_query_log --error ER_ACCESS_DENIED_ERROR : this should fail : no grant -connect(cleartext_fail_con,localhost,uplain,cleartext_test2); +connect(cleartext_fail_con,localhost,uplain,cleartext_test2,,,,CLEARTEXT); --enable_query_log -connect(cleartext_con,localhost,uplain,cleartext_test); +connect(cleartext_con,localhost,uplain,cleartext_test,,,,CLEARTEXT); connection cleartext_con; select USER(),CURRENT_USER(); diff --git a/sql-common/client.c b/sql-common/client.c index 08f4bfb1151..381768834cd 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -1136,7 +1136,8 @@ static const char *default_options[]= "connect-timeout", "local-infile", "disable-local-infile", "ssl-cipher", "max-allowed-packet", "protocol", "shared-memory-base-name", "multi-results", "multi-statements", "multi-queries", "secure-auth", - "report-data-truncation", "plugin-dir", "default-auth", + "report-data-truncation", "plugin-dir", "default-auth", + "enable-cleartext-plugin", NullS }; enum option_id { @@ -1148,6 +1149,7 @@ enum option_id { OPT_ssl_cipher, OPT_max_allowed_packet, OPT_protocol, OPT_shared_memory_base_name, OPT_multi_results, OPT_multi_statements, OPT_multi_queries, OPT_secure_auth, OPT_report_data_truncation, OPT_plugin_dir, OPT_default_auth, + OPT_enable_cleartext_plugin, OPT_keep_this_one_last }; @@ -1180,14 +1182,27 @@ static int add_init_command(struct st_mysql_options *options, const char *cmd) return 0; } -#define EXTENSION_SET_STRING(OPTS, X, STR) \ - if ((OPTS)->extension) \ - my_free((OPTS)->extension->X); \ - else \ +#define ALLOCATE_EXTENSIONS(OPTS) \ (OPTS)->extension= (struct st_mysql_options_extention *) \ my_malloc(sizeof(struct st_mysql_options_extention), \ - MYF(MY_WME | MY_ZEROFILL)); \ - (OPTS)->extension->X= my_strdup((STR), MYF(MY_WME)); + MYF(MY_WME | MY_ZEROFILL)) \ + +#define ENSURE_EXTENSIONS_PRESENT(OPTS) \ + do { \ + if (!(OPTS)->extension) \ + ALLOCATE_EXTENSIONS(OPTS); \ + } while (0) + + +#define EXTENSION_SET_STRING(OPTS, X, STR) \ + do { \ + if ((OPTS)->extension) \ + my_free((OPTS)->extension->X); \ + else \ + ALLOCATE_EXTENSIONS(OPTS); \ + (OPTS)->extension->X= ((STR) != NULL) ? \ + my_strdup((STR), MYF(MY_WME)) : NULL; \ + } while (0) void mysql_read_default_options(struct st_mysql_options *options, const char *filename,const char *group) @@ -1386,6 +1401,12 @@ void mysql_read_default_options(struct st_mysql_options *options, case OPT_default_auth: EXTENSION_SET_STRING(options, default_auth, opt_arg); break; + + case OPT_enable_cleartext_plugin: + ENSURE_EXTENSIONS_PRESENT(options); + options->extension->enable_cleartext_plugin= + (!opt_arg || atoi(opt_arg) != 0) ? TRUE : FALSE; + default: DBUG_PRINT("warning",("unknown option: %s",option[0])); } @@ -2782,6 +2803,27 @@ static void client_mpvio_info(MYSQL_PLUGIN_VIO *vio, mpvio_info(mpvio->mysql->net.vio, info); } + +my_bool libmysql_cleartext_plugin_enabled= 0; + +static my_bool check_plugin_enabled(MYSQL *mysql, auth_plugin_t *plugin) +{ + if (plugin == &clear_password_client_plugin && + (!libmysql_cleartext_plugin_enabled && + (!mysql->options.extension || + !mysql->options.extension->enable_cleartext_plugin))) + { + set_mysql_extended_error(mysql, CR_AUTH_PLUGIN_CANNOT_LOAD, + unknown_sqlstate, + ER(CR_AUTH_PLUGIN_CANNOT_LOAD), + clear_password_client_plugin.name, + "plugin not enabled"); + return TRUE; + } + return FALSE; +} + + /** Client side of the plugin driver authentication. @@ -2824,6 +2866,9 @@ int run_plugin_auth(MYSQL *mysql, char *data, uint data_len, auth_plugin_name= auth_plugin->name; } + if (check_plugin_enabled(mysql, auth_plugin)) + DBUG_RETURN(1); + DBUG_PRINT ("info", ("using plugin %s", auth_plugin_name)); mysql->net.last_errno= 0; /* just in case */ @@ -2915,6 +2960,9 @@ int run_plugin_auth(MYSQL *mysql, char *data, uint data_len, auth_plugin_name, MYSQL_CLIENT_AUTHENTICATION_PLUGIN))) DBUG_RETURN (1); + if (check_plugin_enabled(mysql, auth_plugin)) + DBUG_RETURN(1); + mpvio.plugin= auth_plugin; res= auth_plugin->authenticate_user((struct st_plugin_vio *)&mpvio, mysql); @@ -4117,6 +4165,11 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg) case MYSQL_DEFAULT_AUTH: EXTENSION_SET_STRING(&mysql->options, default_auth, arg); break; + case MYSQL_ENABLE_CLEARTEXT_PLUGIN: + ENSURE_EXTENSIONS_PRESENT(&mysql->options); + mysql->options.extension->enable_cleartext_plugin= + (*(my_bool*) arg) ? TRUE : FALSE; + break; default: DBUG_RETURN(1); } @@ -4336,5 +4389,3 @@ static int clear_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) return res ? CR_ERROR : CR_OK; } - - diff --git a/sql-common/client_plugin.c b/sql-common/client_plugin.c index 4016f0744be..75faeb7ee97 100644 --- a/sql-common/client_plugin.c +++ b/sql-common/client_plugin.c @@ -197,6 +197,10 @@ err1: static void load_env_plugins(MYSQL *mysql) { char *plugs, *free_env, *s= getenv("LIBMYSQL_PLUGINS"); + char *enable_cleartext_plugin= getenv("LIBMYSQL_ENABLE_CLEARTEXT_PLUGIN"); + + if (enable_cleartext_plugin && strchr("1Yy", enable_cleartext_plugin[0])) + libmysql_cleartext_plugin_enabled= 1; /* no plugins to load */ if(!s) @@ -212,6 +216,7 @@ static void load_env_plugins(MYSQL *mysql) } while (s); my_free(free_env); + } /********** extern functions to be used by libmysql *********************/ From fb3e11d0ab9317a73619d1e5c01669a7c6e034f9 Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Thu, 5 Jul 2012 10:18:18 +0300 Subject: [PATCH 69/90] fixed a missing break --- sql-common/client.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sql-common/client.c b/sql-common/client.c index 381768834cd..be24c5e89e4 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -1406,6 +1406,7 @@ void mysql_read_default_options(struct st_mysql_options *options, ENSURE_EXTENSIONS_PRESENT(options); options->extension->enable_cleartext_plugin= (!opt_arg || atoi(opt_arg) != 0) ? TRUE : FALSE; + break; default: DBUG_PRINT("warning",("unknown option: %s",option[0])); From 048577429f3adcb27100ace3dd6fd4579bcd9e53 Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Thu, 5 Jul 2012 13:41:16 +0300 Subject: [PATCH 70/90] Bug #13889741: HANDLE_FATAL_SIGNAL IN _DB_ENTER_ | HANDLE_FATAL_SIGNAL IN STRNLEN Fixed the following bounds checking problems : 1. in check_if_legal_filename() make sure the null terminated string is long enough before accessing the bytes in it. Prevents pottential read-past-buffer-end 2. in my_wc_mb_filename() of the filename charset check for the end of the destination buffer before sending single byte characters into it. Prevents write-past-end-of-buffer (and garbaling stack in the cases reported here) errors. Added test cases. --- mysys/my_access.c | 3 ++- strings/ctype-utf8.c | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/mysys/my_access.c b/mysys/my_access.c index 210946d50a8..43917da7f98 100644 --- a/mysys/my_access.c +++ b/mysys/my_access.c @@ -148,7 +148,8 @@ static char reserved_map[256]= int check_if_legal_tablename(const char *name) { DBUG_ENTER("check_if_legal_tablename"); - DBUG_RETURN((reserved_map[(uchar) name[0]] & 1) && + DBUG_RETURN(name[0] != 0 && name[1] != 0 && + (reserved_map[(uchar) name[0]] & 1) && (reserved_map[(uchar) name[1]] & 2) && (reserved_map[(uchar) name[2]] & 4) && str_list_find(&reserved_names[1], name)); diff --git a/strings/ctype-utf8.c b/strings/ctype-utf8.c index 205f8c61ddd..a0e69feedab 100644 --- a/strings/ctype-utf8.c +++ b/strings/ctype-utf8.c @@ -4326,6 +4326,10 @@ my_wc_mb_filename(CHARSET_INFO *cs __attribute__((unused)), { int code; char hex[]= "0123456789abcdef"; + + if (s >= e) + return MY_CS_TOOSMALL; + if (wc < 128 && filename_safe_char[wc]) { *s= (uchar) wc; From e3c8fb4a1cf2984cf1aa1fe31ba828de550f619c Mon Sep 17 00:00:00 2001 From: Andrei Elkin Date: Thu, 5 Jul 2012 14:37:48 +0300 Subject: [PATCH 71/90] Bug#14275000 Fixes for BUG11761686 left a flaw that managed to slip away from testing. Only effective filtering branch was actually tested with a regression test added to rpl_filter_tables_not_exist. The reason of the failure is destuction of too early mem-root-allocated memory at the end of the deferred User-var's do_apply_event(). Fixed with bypassing free_root() in the deferred execution branch. Deallocation of created in do_apply_event() items is done by the base code through THD::cleanup_after_query() -> free_items() that the parent Query can't miss. sql/log_event.cc: Do not call free_root() in case the deferred User-var event. Necessary methods to the User-var class are added, do_apply_event() refined. sql/log_event.h: Necessary methods to avoid destoying mem-root-based memory at User-var applying are defined. --- sql/log_event.cc | 16 ++++++++++++---- sql/log_event.h | 11 ++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/sql/log_event.cc b/sql/log_event.cc index a47b3680d82..1822951cccf 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -5640,6 +5640,9 @@ User_var_log_event:: User_var_log_event(const char* buf, const Format_description_log_event* description_event) :Log_event(buf, description_event) +#ifndef MYSQL_CLIENT + , deferred(false) +#endif { /* The Post-Header is empty. The Variable Data part begins immediately. */ buf+= description_event->common_header_len + @@ -5848,7 +5851,10 @@ int User_var_log_event::do_apply_event(Relay_log_info const *rli) CHARSET_INFO *charset; if (rli->deferred_events_collecting) + { + set_deferred(); return rli->deferred_events->add(this); + } if (!(charset= get_charset(charset_number, MYF(MY_WME)))) return 1; @@ -5900,7 +5906,8 @@ int User_var_log_event::do_apply_event(Relay_log_info const *rli) return 0; } } - Item_func_set_user_var e(user_var_name, it); + + Item_func_set_user_var *e= new Item_func_set_user_var(user_var_name, it); /* Item_func_set_user_var can't substitute something else on its place => 0 can be passed as last argument (reference on item) @@ -5909,7 +5916,7 @@ int User_var_log_event::do_apply_event(Relay_log_info const *rli) crash the server, so if fix fields fails, we just return with an error. */ - if (e.fix_fields(thd, 0)) + if (e->fix_fields(thd, 0)) return 1; /* @@ -5917,8 +5924,9 @@ int User_var_log_event::do_apply_event(Relay_log_info const *rli) a single record and with a single column. Thus, like a column value, it could always have IMPLICIT derivation. */ - e.update_hash(val, val_len, type, charset, DERIVATION_IMPLICIT, 0); - free_root(thd->mem_root,0); + e->update_hash(val, val_len, type, charset, DERIVATION_IMPLICIT, 0); + if (!is_deferred()) + free_root(thd->mem_root,0); return 0; } diff --git a/sql/log_event.h b/sql/log_event.h index 39cd55f313e..e755b6a5a41 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -2483,11 +2483,13 @@ public: uint charset_number; bool is_null; #ifndef MYSQL_CLIENT + bool deferred; User_var_log_event(THD* thd_arg, char *name_arg, uint name_len_arg, char *val_arg, ulong val_len_arg, Item_result type_arg, uint charset_number_arg) :Log_event(), name(name_arg), name_len(name_len_arg), val(val_arg), - val_len(val_len_arg), type(type_arg), charset_number(charset_number_arg) + val_len(val_len_arg), type(type_arg), charset_number(charset_number_arg), + deferred(false) { is_null= !val; } void pack_info(Protocol* protocol); #else @@ -2500,6 +2502,13 @@ public: Log_event_type get_type_code() { return USER_VAR_EVENT;} #ifndef MYSQL_CLIENT bool write(IO_CACHE* file); + /* + Getter and setter for deferred User-event. + Returns true if the event is not applied directly + and which case the applier adjusts execution path. + */ + bool is_deferred() { return deferred; } + void set_deferred() { deferred= val; } #endif bool is_valid() const { return 1; } From ca2baa0f3b4cf4d52ce6d0791dcd5acf85889d6e Mon Sep 17 00:00:00 2001 From: Andrei Elkin Date: Thu, 5 Jul 2012 23:53:07 +0300 Subject: [PATCH 72/90] merge bug14275000 fixes to 5.5: sql/log_event.h. --- sql/log_event.h | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/sql/log_event.h b/sql/log_event.h index 387f020ee8b..000c7420ca8 100644 --- a/sql/log_event.h +++ b/sql/log_event.h @@ -2562,23 +2562,15 @@ public: Item_result type; uint charset_number; bool is_null; -<<<<<<< TREE uchar flags; #ifdef MYSQL_SERVER -======= -#ifndef MYSQL_CLIENT bool deferred; ->>>>>>> MERGE-SOURCE User_var_log_event(THD* thd_arg, char *name_arg, uint name_len_arg, char *val_arg, ulong val_len_arg, Item_result type_arg, uint charset_number_arg, uchar flags_arg) :Log_event(), name(name_arg), name_len(name_len_arg), val(val_arg), val_len(val_len_arg), type(type_arg), charset_number(charset_number_arg), -<<<<<<< TREE - flags(flags_arg) -======= - deferred(false) ->>>>>>> MERGE-SOURCE + flags(flags_arg), deferred(false) { is_null= !val; } void pack_info(Protocol* protocol); #else From a1425b103248672ecb966cfc0efb0ba17d6b1d19 Mon Sep 17 00:00:00 2001 From: Bjorn Munch Date: Mon, 9 Jul 2012 15:10:07 +0200 Subject: [PATCH 75/90] Refactor mysql_client_test.c into a framework part and a test part --- tests/Makefile.am | 1 + tests/mysql_client_fw.c | 1375 +++++++++++++++++++++++++++++++++++++ tests/mysql_client_test.c | 1358 +----------------------------------- 3 files changed, 1381 insertions(+), 1353 deletions(-) create mode 100644 tests/mysql_client_fw.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 876db7e8475..4929fa7ba9b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -47,6 +47,7 @@ LDADD = @CLIENT_EXTRA_LDFLAGS@ \ mysql_client_test_LDADD= $(LDADD) $(CXXLDFLAGS) mysql_client_test_SOURCES= mysql_client_test.c\ $(top_srcdir)/mysys/my_memmem.c +mysql_client_test.o: mysql_client_fw.c insert_test_SOURCES= insert_test.c select_test_SOURCES= select_test.c diff --git a/tests/mysql_client_fw.c b/tests/mysql_client_fw.c new file mode 100644 index 00000000000..27a06501d7a --- /dev/null +++ b/tests/mysql_client_fw.c @@ -0,0 +1,1375 @@ +/* Copyright (c) 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 + the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + +#include +#include +#include +#include +#include +#include +#include + +#define VER "2.1" +#define MAX_TEST_QUERY_LENGTH 300 /* MAX QUERY BUFFER LENGTH */ +#define MAX_KEY MAX_INDEXES +#define MAX_SERVER_ARGS 64 + +/* set default options */ +static int opt_testcase = 0; +static char *opt_db= 0; +static char *opt_user= 0; +static char *opt_password= 0; +static char *opt_host= 0; +static char *opt_unix_socket= 0; +#ifdef HAVE_SMEM +static char *shared_memory_base_name= 0; +#endif +static unsigned int opt_port; +static my_bool tty_password= 0, opt_silent= 0; + +static MYSQL *mysql= 0; +static char current_db[]= "client_test_db"; +static unsigned int test_count= 0; +static unsigned int opt_count= 0; +static unsigned int iter_count= 0; +static my_bool have_innodb= FALSE; + +static const char *opt_basedir= "./"; +static const char *opt_vardir= "mysql-test/var"; + +static longlong opt_getopt_ll_test= 0; + +static int embedded_server_arg_count= 0; +static char *embedded_server_args[MAX_SERVER_ARGS]; + +static const char *embedded_server_groups[]= { +"server", +"embedded", +"mysql_client_test_SERVER", +NullS +}; + +static time_t start_time, end_time; +static double total_time; + +const char *default_dbug_option= "d:t:o,/tmp/mysql_client_test.trace"; + +struct my_tests_st +{ +const char *name; +void (*function)(); +}; + +#define myheader(str) \ +DBUG_PRINT("test", ("name: %s", str)); \ + if (opt_silent < 2) \ + { \ + fprintf(stdout, "\n\n#####################################\n"); \ + fprintf(stdout, "%u of (%u/%u): %s", test_count++, iter_count, \ + opt_count, str); \ + fprintf(stdout, " \n#####################################\n"); \ + } + +#define myheader_r(str) \ +DBUG_PRINT("test", ("name: %s", str)); \ + if (!opt_silent) \ + { \ + fprintf(stdout, "\n\n#####################################\n"); \ + fprintf(stdout, "%s", str); \ + fprintf(stdout, " \n#####################################\n"); \ + } + +static void print_error(const char *msg); +static void print_st_error(MYSQL_STMT *stmt, const char *msg); +static void client_disconnect(MYSQL* mysql, my_bool drop_db); + + +/* +Abort unless given experssion is non-zero. + +SYNOPSIS +DIE_UNLESS(expr) + +DESCRIPTION +We can't use any kind of system assert as we need to +preserve tested invariants in release builds as well. +*/ + +#define DIE_UNLESS(expr) \ +((void) ((expr) ? 0 : (die(__FILE__, __LINE__, #expr), 0))) +#define DIE_IF(expr) \ +((void) ((expr) ? (die(__FILE__, __LINE__, #expr), 0) : 0)) +#define DIE(expr) \ +die(__FILE__, __LINE__, #expr) + +static void die(const char *file, int line, const char *expr) +{ + fflush(stdout); + fprintf(stderr, "%s:%d: check failed: '%s'\n", file, line, expr); + fflush(stderr); + exit(1); +} + + +#define myerror(msg) print_error(msg) +#define mysterror(stmt, msg) print_st_error(stmt, msg) + +#define myquery(RES) \ +{ \ + int r= (RES); \ + if (r) \ + myerror(NULL); \ + DIE_UNLESS(r == 0); \ +} + +#define myquery_r(r) \ +{ \ + if (r) \ + myerror(NULL); \ + DIE_UNLESS(r != 0); \ +} + +#define check_execute(stmt, r) \ +{ \ + if (r) \ + mysterror(stmt, NULL); \ + DIE_UNLESS(r == 0); \ +} + +#define check_execute_r(stmt, r) \ +{ \ + if (r) \ + mysterror(stmt, NULL); \ + DIE_UNLESS(r != 0); \ +} + +#define check_stmt(stmt) \ +{ \ + if ( stmt == 0) \ + myerror(NULL); \ + DIE_UNLESS(stmt != 0); \ +} + +#define check_stmt_r(stmt) \ +{ \ + if (stmt == 0) \ + myerror(NULL); \ + DIE_UNLESS(stmt == 0); \ +} + +#define mytest(x) if (!(x)) {myerror(NULL);DIE_UNLESS(FALSE);} +#define mytest_r(x) if ((x)) {myerror(NULL);DIE_UNLESS(FALSE);} + + +/* A workaround for Sun Forte 5.6 on Solaris x86 */ + +static int cmp_double(double *a, double *b) +{ + return *a == *b; +} + + +/* Print the error message */ + +static void print_error(const char *msg) +{ + if (!opt_silent) + { + if (mysql && mysql_errno(mysql)) + { + if (mysql->server_version) + fprintf(stdout, "\n [MySQL-%s]", mysql->server_version); + else + fprintf(stdout, "\n [MySQL]"); + fprintf(stdout, "[%d] %s\n", mysql_errno(mysql), mysql_error(mysql)); + } + else if (msg) + fprintf(stderr, " [MySQL] %s\n", msg); + } +} + + +static void print_st_error(MYSQL_STMT *stmt, const char *msg) +{ + if (!opt_silent) + { + if (stmt && mysql_stmt_errno(stmt)) + { + if (stmt->mysql && stmt->mysql->server_version) + fprintf(stdout, "\n [MySQL-%s]", stmt->mysql->server_version); + else + fprintf(stdout, "\n [MySQL]"); + + fprintf(stdout, "[%d] %s\n", mysql_stmt_errno(stmt), + mysql_stmt_error(stmt)); + } + else if (msg) + fprintf(stderr, " [MySQL] %s\n", msg); + } +} + +/* +Enhanced version of mysql_client_init(), which may also set shared memory +base on Windows. +*/ +static MYSQL *mysql_client_init(MYSQL* con) +{ + MYSQL* res = mysql_init(con); + #ifdef HAVE_SMEM + if (res && shared_memory_base_name) + mysql_options(res, MYSQL_SHARED_MEMORY_BASE_NAME, shared_memory_base_name); + #endif + return res; +} + +/* +Disable direct calls of mysql_init, as it disregards shared memory base. +*/ +#define mysql_init(A) Please use mysql_client_init instead of mysql_init + + +/* Check if the connection has InnoDB tables */ + +static my_bool check_have_innodb(MYSQL *conn) +{ + MYSQL_RES *res; + MYSQL_ROW row; + int rc; + my_bool result; + + rc= mysql_query(conn, "show variables like 'have_innodb'"); + myquery(rc); + res= mysql_use_result(conn); + DIE_UNLESS(res); + + row= mysql_fetch_row(res); + DIE_UNLESS(row); + + result= strcmp(row[1], "YES") == 0; + mysql_free_result(res); + return result; +} + + +/* +This is to be what mysql_query() is for mysql_real_query(), for +mysql_simple_prepare(): a variant without the 'length' parameter. +*/ + +static MYSQL_STMT *STDCALL +mysql_simple_prepare(MYSQL *mysql_arg, const char *query) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql_arg); + if (stmt && mysql_stmt_prepare(stmt, query, (uint) strlen(query))) + { + mysql_stmt_close(stmt); + return 0; + } + return stmt; +} + + +/** +Connect to the server with options given by arguments to this application, +stored in global variables opt_host, opt_user, opt_password, opt_db, +opt_port and opt_unix_socket. + +@param flag[in] client_flag passed on to mysql_real_connect +@param protocol[in] MYSQL_PROTOCOL_* to use for this connection +@param auto_reconnect[in] set to 1 for auto reconnect + +@return pointer to initialized and connected MYSQL object +*/ +static MYSQL* client_connect(ulong flag, uint protocol, my_bool auto_reconnect) +{ + MYSQL* mysql; + int rc; + static char query[MAX_TEST_QUERY_LENGTH]; + myheader_r("client_connect"); + + if (!opt_silent) + fprintf(stdout, "\n Establishing a connection to '%s' ...", + opt_host ? opt_host : ""); + + if (!(mysql= mysql_client_init(NULL))) + { + opt_silent= 0; + myerror("mysql_client_init() failed"); + exit(1); + } + /* enable local infile, in non-binary builds often disabled by default */ + mysql_options(mysql, MYSQL_OPT_LOCAL_INFILE, 0); + mysql_options(mysql, MYSQL_OPT_PROTOCOL, &protocol); + + if (!(mysql_real_connect(mysql, opt_host, opt_user, + opt_password, opt_db ? opt_db:"test", opt_port, + opt_unix_socket, flag))) + { + opt_silent= 0; + myerror("connection failed"); + mysql_close(mysql); + fprintf(stdout, "\n Check the connection options using --help or -?\n"); + exit(1); + } + mysql->reconnect= auto_reconnect; + + if (!opt_silent) + fprintf(stdout, "OK"); + + /* set AUTOCOMMIT to ON*/ + mysql_autocommit(mysql, TRUE); + + if (!opt_silent) + { + fprintf(stdout, "\nConnected to MySQL server version: %s (%lu)\n", + mysql_get_server_info(mysql), + (ulong) mysql_get_server_version(mysql)); + fprintf(stdout, "\n Creating a test database '%s' ...", current_db); + } + strxmov(query, "CREATE DATABASE IF NOT EXISTS ", current_db, NullS); + + rc= mysql_query(mysql, query); + myquery(rc); + + strxmov(query, "USE ", current_db, NullS); + rc= mysql_query(mysql, query); + myquery(rc); + have_innodb= check_have_innodb(mysql); + + if (!opt_silent) + fprintf(stdout, "OK"); + + return mysql; +} + + +/* Close the connection */ + +static void client_disconnect(MYSQL* mysql, my_bool drop_db) +{ + static char query[MAX_TEST_QUERY_LENGTH]; + + myheader_r("client_disconnect"); + + if (mysql) + { + if (drop_db) + { + if (!opt_silent) + fprintf(stdout, "\n dropping the test database '%s' ...", current_db); + strxmov(query, "DROP DATABASE IF EXISTS ", current_db, NullS); + + mysql_query(mysql, query); + if (!opt_silent) + fprintf(stdout, "OK"); + } + + if (!opt_silent) + fprintf(stdout, "\n closing the connection ..."); + mysql_close(mysql); + if (!opt_silent) + fprintf(stdout, "OK\n"); + } +} + + +/* Print dashes */ + +static void my_print_dashes(MYSQL_RES *result) +{ + MYSQL_FIELD *field; + unsigned int i, j; + + mysql_field_seek(result, 0); + fputc('\t', stdout); + fputc('+', stdout); + + for(i= 0; i< mysql_num_fields(result); i++) + { + field= mysql_fetch_field(result); + for(j= 0; j < field->max_length+2; j++) + fputc('-', stdout); + fputc('+', stdout); + } + fputc('\n', stdout); +} + + +/* Print resultset metadata information */ + +static void my_print_result_metadata(MYSQL_RES *result) +{ + MYSQL_FIELD *field; + unsigned int i, j; + unsigned int field_count; + + mysql_field_seek(result, 0); + if (!opt_silent) + { + fputc('\n', stdout); + fputc('\n', stdout); + } + + field_count= mysql_num_fields(result); + for(i= 0; i< field_count; i++) + { + field= mysql_fetch_field(result); + j= strlen(field->name); + if (j < field->max_length) + j= field->max_length; + if (j < 4 && !IS_NOT_NULL(field->flags)) + j= 4; + field->max_length= j; + } + if (!opt_silent) + { + my_print_dashes(result); + fputc('\t', stdout); + fputc('|', stdout); + } + + mysql_field_seek(result, 0); + for(i= 0; i< field_count; i++) + { + field= mysql_fetch_field(result); + if (!opt_silent) + fprintf(stdout, " %-*s |", (int) field->max_length, field->name); + } + if (!opt_silent) + { + fputc('\n', stdout); + my_print_dashes(result); + } +} + + +/* Process the result set */ + +static int my_process_result_set(MYSQL_RES *result) +{ + MYSQL_ROW row; + MYSQL_FIELD *field; + unsigned int i; + unsigned int row_count= 0; + + if (!result) + return 0; + + my_print_result_metadata(result); + + while ((row= mysql_fetch_row(result)) != NULL) + { + mysql_field_seek(result, 0); + if (!opt_silent) + { + fputc('\t', stdout); + fputc('|', stdout); + } + + for(i= 0; i< mysql_num_fields(result); i++) + { + field= mysql_fetch_field(result); + if (!opt_silent) + { + if (row[i] == NULL) + fprintf(stdout, " %-*s |", (int) field->max_length, "NULL"); + else if (IS_NUM(field->type)) + fprintf(stdout, " %*s |", (int) field->max_length, row[i]); + else + fprintf(stdout, " %-*s |", (int) field->max_length, row[i]); + } + } + if (!opt_silent) + { + fputc('\t', stdout); + fputc('\n', stdout); + } + row_count++; + } + if (!opt_silent) + { + if (row_count) + my_print_dashes(result); + + if (mysql_errno(mysql) != 0) + fprintf(stderr, "\n\tmysql_fetch_row() failed\n"); + else + fprintf(stdout, "\n\t%d %s returned\n", row_count, + row_count == 1 ? "row" : "rows"); + } + return row_count; +} + + +static int my_process_result(MYSQL *mysql_arg) +{ + MYSQL_RES *result; + int row_count; + + if (!(result= mysql_store_result(mysql_arg))) + return 0; + + row_count= my_process_result_set(result); + + mysql_free_result(result); + return row_count; +} + + +/* Process the statement result set */ + +#define MAX_RES_FIELDS 50 +#define MAX_FIELD_DATA_SIZE 255 + +static int my_process_stmt_result(MYSQL_STMT *stmt) +{ + int field_count; + int row_count= 0; + MYSQL_BIND buffer[MAX_RES_FIELDS]; + MYSQL_FIELD *field; + MYSQL_RES *result; + char data[MAX_RES_FIELDS][MAX_FIELD_DATA_SIZE]; + ulong length[MAX_RES_FIELDS]; + my_bool is_null[MAX_RES_FIELDS]; + int rc, i; + + if (!(result= mysql_stmt_result_metadata(stmt))) /* No meta info */ + { + while (!mysql_stmt_fetch(stmt)) + row_count++; + return row_count; + } + + field_count= min(mysql_num_fields(result), MAX_RES_FIELDS); + + bzero((char*) buffer, sizeof(buffer)); + bzero((char*) length, sizeof(length)); + bzero((char*) is_null, sizeof(is_null)); + + for(i= 0; i < field_count; i++) + { + buffer[i].buffer_type= MYSQL_TYPE_STRING; + buffer[i].buffer_length= MAX_FIELD_DATA_SIZE; + buffer[i].length= &length[i]; + buffer[i].buffer= (void *) data[i]; + buffer[i].is_null= &is_null[i]; + } + + rc= mysql_stmt_bind_result(stmt, buffer); + check_execute(stmt, rc); + + rc= 1; + mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void*)&rc); + rc= mysql_stmt_store_result(stmt); + check_execute(stmt, rc); + my_print_result_metadata(result); + + mysql_field_seek(result, 0); + while ((rc= mysql_stmt_fetch(stmt)) == 0) + { + if (!opt_silent) + { + fputc('\t', stdout); + fputc('|', stdout); + } + mysql_field_seek(result, 0); + for (i= 0; i < field_count; i++) + { + field= mysql_fetch_field(result); + if (!opt_silent) + { + if (is_null[i]) + fprintf(stdout, " %-*s |", (int) field->max_length, "NULL"); + else if (length[i] == 0) + { + data[i][0]= '\0'; /* unmodified buffer */ + fprintf(stdout, " %*s |", (int) field->max_length, data[i]); + } + else if (IS_NUM(field->type)) + fprintf(stdout, " %*s |", (int) field->max_length, data[i]); + else + fprintf(stdout, " %-*s |", (int) field->max_length, data[i]); + } + } + if (!opt_silent) + { + fputc('\t', stdout); + fputc('\n', stdout); + } + row_count++; + } + DIE_UNLESS(rc == MYSQL_NO_DATA); + if (!opt_silent) + { + if (row_count) + my_print_dashes(result); + fprintf(stdout, "\n\t%d %s returned\n", row_count, + row_count == 1 ? "row" : "rows"); + } + mysql_free_result(result); + return row_count; +} + + +/* Prepare statement, execute, and process result set for given query */ + +int my_stmt_result(const char *buff) +{ + MYSQL_STMT *stmt; + int row_count; + int rc; + + if (!opt_silent) + fprintf(stdout, "\n\n %s", buff); + stmt= mysql_simple_prepare(mysql, buff); + check_stmt(stmt); + + rc= mysql_stmt_execute(stmt); + check_execute(stmt, rc); + + row_count= my_process_stmt_result(stmt); + mysql_stmt_close(stmt); + + return row_count; +} + + +/* Utility function to verify a particular column data */ + +static void verify_col_data(const char *table, const char *col, +const char *exp_data) +{ + static char query[MAX_TEST_QUERY_LENGTH]; + MYSQL_RES *result; + MYSQL_ROW row; + int rc, field= 1; + + if (table && col) + { + strxmov(query, "SELECT ", col, " FROM ", table, " LIMIT 1", NullS); + if (!opt_silent) + fprintf(stdout, "\n %s", query); + rc= mysql_query(mysql, query); + myquery(rc); + + field= 0; + } + + result= mysql_use_result(mysql); + mytest(result); + + if (!(row= mysql_fetch_row(result)) || !row[field]) + { + fprintf(stdout, "\n *** ERROR: FAILED TO GET THE RESULT ***"); + exit(1); + } + if (strcmp(row[field], exp_data)) + { + fprintf(stdout, "\n obtained: `%s` (expected: `%s`)", + row[field], exp_data); + DIE_UNLESS(FALSE); + } + mysql_free_result(result); +} + + +/* Utility function to verify the field members */ + +#define verify_prepare_field(result,no,name,org_name,type,table, \ +org_table,db,length,def) \ +do_verify_prepare_field((result),(no),(name),(org_name),(type), \ +(table),(org_table),(db),(length),(def), \ +__FILE__, __LINE__) + +static void do_verify_prepare_field(MYSQL_RES *result, +unsigned int no, const char *name, +const char *org_name, +enum enum_field_types type, +const char *table, +const char *org_table, const char *db, +unsigned long length, const char *def, +const char *file, int line) +{ + MYSQL_FIELD *field; + CHARSET_INFO *cs; + ulonglong expected_field_length; + + if (!(field= mysql_fetch_field_direct(result, no))) + { + fprintf(stdout, "\n *** ERROR: FAILED TO GET THE RESULT ***"); + exit(1); + } + cs= get_charset(field->charsetnr, 0); + DIE_UNLESS(cs); + if ((expected_field_length= length * cs->mbmaxlen) > UINT_MAX32) + expected_field_length= UINT_MAX32; + if (!opt_silent) + { + fprintf(stdout, "\n field[%d]:", no); + fprintf(stdout, "\n name :`%s`\t(expected: `%s`)", field->name, name); + fprintf(stdout, "\n org_name :`%s`\t(expected: `%s`)", + field->org_name, org_name); + fprintf(stdout, "\n type :`%d`\t(expected: `%d`)", field->type, type); + if (table) + fprintf(stdout, "\n table :`%s`\t(expected: `%s`)", + field->table, table); + if (org_table) + fprintf(stdout, "\n org_table:`%s`\t(expected: `%s`)", + field->org_table, org_table); + fprintf(stdout, "\n database :`%s`\t(expected: `%s`)", field->db, db); + fprintf(stdout, "\n length :`%lu`\t(expected: `%llu`)", + field->length, expected_field_length); + fprintf(stdout, "\n maxlength:`%ld`", field->max_length); + fprintf(stdout, "\n charsetnr:`%d`", field->charsetnr); + fprintf(stdout, "\n default :`%s`\t(expected: `%s`)", + field->def ? field->def : "(null)", def ? def: "(null)"); + fprintf(stdout, "\n"); + } + DIE_UNLESS(strcmp(field->name, name) == 0); + DIE_UNLESS(strcmp(field->org_name, org_name) == 0); + /* + XXX: silent column specification change works based on number of + bytes a column occupies. So CHAR -> VARCHAR upgrade is possible even + for CHAR(2) column if its character set is multibyte. + VARCHAR -> CHAR downgrade won't work for VARCHAR(3) as one would + expect. + */ + if (cs->mbmaxlen == 1) + { + if (field->type != type) + { + fprintf(stderr, + "Expected field type: %d, got type: %d in file %s, line %d\n", + (int) type, (int) field->type, file, line); + DIE_UNLESS(field->type == type); + } + } + if (table) + DIE_UNLESS(strcmp(field->table, table) == 0); + if (org_table) + DIE_UNLESS(strcmp(field->org_table, org_table) == 0); + DIE_UNLESS(strcmp(field->db, db) == 0); + /* + Character set should be taken into account for multibyte encodings, such + as utf8. Field length is calculated as number of characters * maximum + number of bytes a character can occupy. + */ + if (length && (field->length != expected_field_length)) + { + fprintf(stderr, "Expected field length: %llu, got length: %lu\n", + expected_field_length, field->length); + DIE_UNLESS(field->length == expected_field_length); + } + if (def) + DIE_UNLESS(strcmp(field->def, def) == 0); +} + + +/* Utility function to verify the parameter count */ + +static void verify_param_count(MYSQL_STMT *stmt, long exp_count) +{ + long param_count= mysql_stmt_param_count(stmt); + if (!opt_silent) + fprintf(stdout, "\n total parameters in stmt: `%ld` (expected: `%ld`)", + param_count, exp_count); + DIE_UNLESS(param_count == exp_count); +} + + +/* Utility function to verify the total affected rows */ + +static void verify_st_affected_rows(MYSQL_STMT *stmt, ulonglong exp_count) +{ + ulonglong affected_rows= mysql_stmt_affected_rows(stmt); + if (!opt_silent) + fprintf(stdout, "\n total affected rows: `%ld` (expected: `%ld`)", + (long) affected_rows, (long) exp_count); + DIE_UNLESS(affected_rows == exp_count); +} + + +/* Utility function to verify the total affected rows */ + +static void verify_affected_rows(ulonglong exp_count) +{ + ulonglong affected_rows= mysql_affected_rows(mysql); + if (!opt_silent) + fprintf(stdout, "\n total affected rows: `%ld` (expected: `%ld`)", + (long) affected_rows, (long) exp_count); + DIE_UNLESS(affected_rows == exp_count); +} + + +/* Utility function to verify the total fields count */ + +static void verify_field_count(MYSQL_RES *result, uint exp_count) +{ + uint field_count= mysql_num_fields(result); + if (!opt_silent) + fprintf(stdout, "\n total fields in the result set: `%d` (expected: `%d`)", + field_count, exp_count); + DIE_UNLESS(field_count == exp_count); +} + + +/* Utility function to execute a query using prepare-execute */ + +#ifndef EMBEDDED_LIBRARY +static void execute_prepare_query(const char *query, ulonglong exp_count) +{ + MYSQL_STMT *stmt; + ulonglong affected_rows; + int rc; + + stmt= mysql_simple_prepare(mysql, query); + check_stmt(stmt); + + rc= mysql_stmt_execute(stmt); + myquery(rc); + + affected_rows= mysql_stmt_affected_rows(stmt); + if (!opt_silent) + fprintf(stdout, "\n total affected rows: `%ld` (expected: `%ld`)", + (long) affected_rows, (long) exp_count); + + DIE_UNLESS(affected_rows == exp_count); + mysql_stmt_close(stmt); +} +#endif + +/* +Accepts arbitrary number of queries and runs them against the database. +Used to fill tables for each test. +*/ + +void fill_tables(const char **query_list, unsigned query_count) +{ + int rc; + const char **query; + DBUG_ENTER("fill_tables"); + for (query= query_list; query < query_list + query_count; + ++query) + { + rc= mysql_query(mysql, *query); + myquery(rc); + } + DBUG_VOID_RETURN; +} + +/* +All state of fetch from one statement: statement handle, out buffers, +fetch position. +See fetch_n for for the only use case. +*/ + +enum { MAX_COLUMN_LENGTH= 255 }; + +typedef struct st_stmt_fetch +{ +const char *query; +unsigned stmt_no; +MYSQL_STMT *handle; +my_bool is_open; +MYSQL_BIND *bind_array; +char **out_data; +unsigned long *out_data_length; +unsigned column_count; +unsigned row_count; +} Stmt_fetch; + + +/* +Create statement handle, prepare it with statement, execute and allocate +fetch buffers. +*/ + +void stmt_fetch_init(Stmt_fetch *fetch, unsigned stmt_no_arg, +const char *query_arg) +{ + unsigned long type= CURSOR_TYPE_READ_ONLY; + int rc; + unsigned i; + MYSQL_RES *metadata; + DBUG_ENTER("stmt_fetch_init"); + + /* Save query and statement number for error messages */ + fetch->stmt_no= stmt_no_arg; + fetch->query= query_arg; + + fetch->handle= mysql_stmt_init(mysql); + + rc= mysql_stmt_prepare(fetch->handle, fetch->query, strlen(fetch->query)); + check_execute(fetch->handle, rc); + + /* + The attribute is sent to server on execute and asks to open read-only + for result set + */ + mysql_stmt_attr_set(fetch->handle, STMT_ATTR_CURSOR_TYPE, + (const void*) &type); + + rc= mysql_stmt_execute(fetch->handle); + check_execute(fetch->handle, rc); + + /* Find out total number of columns in result set */ + metadata= mysql_stmt_result_metadata(fetch->handle); + fetch->column_count= mysql_num_fields(metadata); + mysql_free_result(metadata); + + /* + Now allocate bind handles and buffers for output data: + calloc memory to reduce number of MYSQL_BIND members we need to + set up. + */ + + fetch->bind_array= (MYSQL_BIND *) calloc(1, sizeof(MYSQL_BIND) * + fetch->column_count); + fetch->out_data= (char**) calloc(1, sizeof(char*) * fetch->column_count); + fetch->out_data_length= (ulong*) calloc(1, sizeof(ulong) * + fetch->column_count); + for (i= 0; i < fetch->column_count; ++i) + { + fetch->out_data[i]= (char*) calloc(1, MAX_COLUMN_LENGTH); + fetch->bind_array[i].buffer_type= MYSQL_TYPE_STRING; + fetch->bind_array[i].buffer= fetch->out_data[i]; + fetch->bind_array[i].buffer_length= MAX_COLUMN_LENGTH; + fetch->bind_array[i].length= fetch->out_data_length + i; + } + + mysql_stmt_bind_result(fetch->handle, fetch->bind_array); + + fetch->row_count= 0; + fetch->is_open= TRUE; + + /* Ready for reading rows */ + DBUG_VOID_RETURN; +} + + +/* Fetch and print one row from cursor */ + +int stmt_fetch_fetch_row(Stmt_fetch *fetch) +{ + int rc; + unsigned i; + DBUG_ENTER("stmt_fetch_fetch_row"); + + if ((rc= mysql_stmt_fetch(fetch->handle)) == 0) + { + ++fetch->row_count; + if (!opt_silent) + printf("Stmt %d fetched row %d:\n", fetch->stmt_no, fetch->row_count); + for (i= 0; i < fetch->column_count; ++i) + { + fetch->out_data[i][fetch->out_data_length[i]]= '\0'; + if (!opt_silent) + printf("column %d: %s\n", i+1, fetch->out_data[i]); + } + } + else + fetch->is_open= FALSE; + DBUG_RETURN(rc); +} + + +void stmt_fetch_close(Stmt_fetch *fetch) +{ + unsigned i; + DBUG_ENTER("stmt_fetch_close"); + + for (i= 0; i < fetch->column_count; ++i) + free(fetch->out_data[i]); + free(fetch->out_data); + free(fetch->out_data_length); + free(fetch->bind_array); + mysql_stmt_close(fetch->handle); + DBUG_VOID_RETURN; +} + +/* +For given array of queries, open query_count cursors and fetch +from them in simultaneous manner. +In case there was an error in one of the cursors, continue +reading from the rest. +*/ + +enum fetch_type { USE_ROW_BY_ROW_FETCH= 0, USE_STORE_RESULT= 1 }; + +my_bool fetch_n(const char **query_list, unsigned query_count, +enum fetch_type fetch_type) +{ + unsigned open_statements= query_count; + int rc, error_count= 0; + Stmt_fetch *fetch_array= (Stmt_fetch*) calloc(1, sizeof(Stmt_fetch) * + query_count); + Stmt_fetch *fetch; + DBUG_ENTER("fetch_n"); + + for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch) + { + /* Init will exit(1) in case of error */ + stmt_fetch_init(fetch, fetch - fetch_array, + query_list[fetch - fetch_array]); + } + + if (fetch_type == USE_STORE_RESULT) + { + for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch) + { + rc= mysql_stmt_store_result(fetch->handle); + check_execute(fetch->handle, rc); + } + } + + while (open_statements) + { + for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch) + { + if (fetch->is_open && (rc= stmt_fetch_fetch_row(fetch))) + { + open_statements--; + /* + We try to fetch from the rest of the statements in case of + error + */ + if (rc != MYSQL_NO_DATA) + { + fprintf(stderr, + "Got error reading rows from statement %d,\n" + "query is: %s,\n" + "error message: %s", (int) (fetch - fetch_array), + fetch->query, + mysql_stmt_error(fetch->handle)); + error_count++; + } + } + } + } + if (error_count) + fprintf(stderr, "Fetch FAILED"); + else + { + unsigned total_row_count= 0; + for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch) + total_row_count+= fetch->row_count; + if (!opt_silent) + printf("Success, total rows fetched: %d\n", total_row_count); + } + for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch) + stmt_fetch_close(fetch); + free(fetch_array); + DBUG_RETURN(error_count != 0); +} + +/* Separate thread query to test some cases */ + +static my_bool thread_query(const char *query) +{ + MYSQL *l_mysql; + my_bool error; + + error= 0; + if (!opt_silent) + fprintf(stdout, "\n in thread_query(%s)", query); + if (!(l_mysql= mysql_client_init(NULL))) + { + myerror("mysql_client_init() failed"); + return 1; + } + if (!(mysql_real_connect(l_mysql, opt_host, opt_user, + opt_password, current_db, opt_port, + opt_unix_socket, 0))) + { + myerror("connection failed"); + error= 1; + goto end; + } + l_mysql->reconnect= 1; + if (mysql_query(l_mysql, query)) + { + fprintf(stderr, "Query failed (%s)\n", mysql_error(l_mysql)); + error= 1; + goto end; + } + mysql_commit(l_mysql); + end: + mysql_close(l_mysql); + return error; +} + + +/* +Read and parse arguments and MySQL options from my.cnf +*/ + +static const char *client_test_load_default_groups[]= { "client", 0 }; +static char **defaults_argv; + +static struct my_option client_test_long_options[] = +{ +{"basedir", 'b', "Basedir for tests.", &opt_basedir, + &opt_basedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, +{"count", 't', "Number of times test to be executed", &opt_count, + &opt_count, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0}, +{"database", 'D', "Database to use", &opt_db, &opt_db, + 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, +{"debug", '#', "Output debug log", &default_dbug_option, + &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, +{"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, + 0, 0, 0, 0, 0}, +{"host", 'h', "Connect to host", &opt_host, &opt_host, + 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, +{"password", 'p', + "Password to use when connecting to server. If password is not given it's asked from the tty.", + 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, +{"port", 'P', "Port number to use for connection or 0 for default to, in " + "order of preference, my.cnf, $MYSQL_TCP_PORT, " + #if MYSQL_PORT_DEFAULT == 0 + "/etc/services, " + #endif + "built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").", + &opt_port, &opt_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, +{"server-arg", 'A', "Send embedded server this as a parameter.", + 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, +{"show-tests", 'T', "Show all tests' names", 0, 0, 0, GET_NO_ARG, NO_ARG, + 0, 0, 0, 0, 0, 0}, +{"silent", 's', "Be more silent", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, + 0}, +#ifdef HAVE_SMEM +{"shared-memory-base-name", 'm', "Base name of shared memory.", + &shared_memory_base_name, (uchar**)&shared_memory_base_name, 0, + GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, +#endif +{"socket", 'S', "Socket file to use for connection", + &opt_unix_socket, &opt_unix_socket, 0, GET_STR, + REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, +{"testcase", 'c', + "May disable some code when runs as mysql-test-run testcase.", + 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, +#ifndef DONT_ALLOW_USER_CHANGE +{"user", 'u', "User for login if not current user", &opt_user, + &opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, +#endif +{"vardir", 'v', "Data dir for tests.", &opt_vardir, + &opt_vardir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, +{"getopt-ll-test", 'g', "Option for testing bug in getopt library", + &opt_getopt_ll_test, &opt_getopt_ll_test, 0, + GET_LL, REQUIRED_ARG, 0, 0, LONGLONG_MAX, 0, 0, 0}, +{ 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} +}; + + +static void usage(void) +{ +/* show the usage string when the user asks for this */ + putc('\n', stdout); + printf("%s Ver %s Distrib %s, for %s (%s)\n", + my_progname, VER, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE); + puts("By Monty, Venu, Kent and others\n"); + printf("\ +Copyright (C) 2002-2004 MySQL AB\n\ +This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\ +and you are welcome to modify and redistribute it under the GPL license\n"); + printf("Usage: %s [OPTIONS] [TESTNAME1 TESTNAME2...]\n", my_progname); + my_print_help(client_test_long_options); + print_defaults("my", client_test_load_default_groups); + my_print_variables(client_test_long_options); +} + + +struct my_tests_st *get_my_tests(); /* Will be defined in main .c file */ + +static struct my_tests_st *my_testlist= 0; + +static my_bool +get_one_option(int optid, const struct my_option *opt __attribute__((unused)), +char *argument) +{ + switch (optid) { + case '#': + DBUG_PUSH(argument ? argument : default_dbug_option); + break; + case 'c': + opt_testcase = 1; + break; + case 'p': + if (argument) + { + char *start=argument; + my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR)); + opt_password= my_strdup(argument, MYF(MY_FAE)); + while (*argument) *argument++= 'x'; /* Destroy argument */ + if (*start) + start[1]=0; + } + else + tty_password= 1; + break; + case 's': + if (argument == disabled_my_option) + opt_silent= 0; + else + opt_silent++; + break; + case 'A': + /* + When the embedded server is being tested, the test suite needs to be + able to pass command-line arguments to the embedded server so it can + locate the language files and data directory. The test suite + (mysql-test-run) never uses config files, just command-line options. + */ + if (!embedded_server_arg_count) + { + embedded_server_arg_count= 1; + embedded_server_args[0]= (char*) ""; + } + if (embedded_server_arg_count == MAX_SERVER_ARGS-1 || + !(embedded_server_args[embedded_server_arg_count++]= + my_strdup(argument, MYF(MY_FAE)))) + { + DIE("Can't use server argument"); + } + break; + case 'T': + { + struct my_tests_st *fptr; + + printf("All possible test names:\n\n"); + for (fptr= my_testlist; fptr->name; fptr++) + printf("%s\n", fptr->name); + exit(0); + break; + } + case '?': + case 'I': /* Info */ + usage(); + exit(0); + break; + } + return 0; +} + +static void get_options(int *argc, char ***argv) +{ + int ho_error; + + if ((ho_error= handle_options(argc, argv, client_test_long_options, + get_one_option))) + exit(ho_error); + + if (tty_password) + opt_password= get_tty_password(NullS); + return; +} + +/* +Print the test output on successful execution before exiting +*/ + +static void print_test_output() +{ + if (opt_silent < 3) + { + fprintf(stdout, "\n\n"); + fprintf(stdout, "All '%d' tests were successful (in '%d' iterations)", + test_count-1, opt_count); + fprintf(stdout, "\n Total execution time: %g SECS", total_time); + if (opt_count > 1) + fprintf(stdout, " (Avg: %g SECS)", total_time/opt_count); + + fprintf(stdout, "\n\n!!! SUCCESS !!!\n"); + } +} + +/*************************************************************************** +main routine +***************************************************************************/ + + +int main(int argc, char **argv) +{ + struct my_tests_st *fptr; + my_testlist= get_my_tests(); + + MY_INIT(argv[0]); + + load_defaults("my", client_test_load_default_groups, &argc, &argv); + defaults_argv= argv; + get_options(&argc, &argv); + + if (mysql_server_init(embedded_server_arg_count, + embedded_server_args, + (char**) embedded_server_groups)) + DIE("Can't initialize MySQL server"); + + /* connect to server with no flags, default protocol, auto reconnect true */ + mysql= client_connect(0, MYSQL_PROTOCOL_DEFAULT, 1); + + total_time= 0; + for (iter_count= 1; iter_count <= opt_count; iter_count++) + { + /* Start of tests */ + test_count= 1; + start_time= time((time_t *)0); + if (!argc) + { + for (fptr= my_testlist; fptr->name; fptr++) + (*fptr->function)(); + } + else + { + for ( ; *argv ; argv++) + { + for (fptr= my_testlist; fptr->name; fptr++) + { + if (!strcmp(fptr->name, *argv)) + { + (*fptr->function)(); + break; + } + } + if (!fptr->name) + { + fprintf(stderr, "\n\nGiven test not found: '%s'\n", *argv); + fprintf(stderr, "See legal test names with %s -T\n\nAborting!\n", + my_progname); + client_disconnect(mysql, 1); + free_defaults(defaults_argv); + exit(1); + } + } + } + + end_time= time((time_t *)0); + total_time+= difftime(end_time, start_time); + + /* End of tests */ + } + + client_disconnect(mysql, 1); /* disconnect from server */ + + free_defaults(defaults_argv); + print_test_output(); + + while (embedded_server_arg_count > 1) + my_free(embedded_server_args[--embedded_server_arg_count],MYF(0)); + + mysql_server_end(); + + my_end(0); + + exit(0); +} diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c index f553eb530ae..c38695db1b1 100644 --- a/tests/mysql_client_test.c +++ b/tests/mysql_client_test.c @@ -1,4 +1,4 @@ -/* Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved. +/* Copyright (c) 2002, 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 @@ -25,378 +25,12 @@ DOESN'T CONTAIN WARNINGS/ERRORS BEFORE YOU PUSH. */ - -#include -#include -#include -#include -#include -#include -#include - -#define VER "2.1" -#define MAX_TEST_QUERY_LENGTH 300 /* MAX QUERY BUFFER LENGTH */ -#define MAX_KEY MAX_INDEXES -#define MAX_SERVER_ARGS 64 - -/* set default options */ -static int opt_testcase = 0; -static char *opt_db= 0; -static char *opt_user= 0; -static char *opt_password= 0; -static char *opt_host= 0; -static char *opt_unix_socket= 0; -#ifdef HAVE_SMEM -static char *shared_memory_base_name= 0; -#endif -static unsigned int opt_port; -static my_bool tty_password= 0, opt_silent= 0; - -static MYSQL *mysql= 0; -static char current_db[]= "client_test_db"; -static unsigned int test_count= 0; -static unsigned int opt_count= 0; -static unsigned int iter_count= 0; -static my_bool have_innodb= FALSE; - -static const char *opt_basedir= "./"; -static const char *opt_vardir= "mysql-test/var"; - -static longlong opt_getopt_ll_test= 0; - -static int embedded_server_arg_count= 0; -static char *embedded_server_args[MAX_SERVER_ARGS]; - -static const char *embedded_server_groups[]= { - "server", - "embedded", - "mysql_client_test_SERVER", - NullS -}; - -static time_t start_time, end_time; -static double total_time; - -const char *default_dbug_option= "d:t:o,/tmp/mysql_client_test.trace"; - -struct my_tests_st -{ - const char *name; - void (*function)(); -}; - -#define myheader(str) \ -DBUG_PRINT("test", ("name: %s", str)); \ -if (opt_silent < 2) \ -{ \ - fprintf(stdout, "\n\n#####################################\n"); \ - fprintf(stdout, "%u of (%u/%u): %s", test_count++, iter_count, \ - opt_count, str); \ - fprintf(stdout, " \n#####################################\n"); \ -} - -#define myheader_r(str) \ -DBUG_PRINT("test", ("name: %s", str)); \ -if (!opt_silent) \ -{ \ - fprintf(stdout, "\n\n#####################################\n"); \ - fprintf(stdout, "%s", str); \ - fprintf(stdout, " \n#####################################\n"); \ -} - -static void print_error(const char *msg); -static void print_st_error(MYSQL_STMT *stmt, const char *msg); -static void client_disconnect(MYSQL* mysql, my_bool drop_db); - - /* - Abort unless given experssion is non-zero. - - SYNOPSIS - DIE_UNLESS(expr) - - DESCRIPTION - We can't use any kind of system assert as we need to - preserve tested invariants in release builds as well. + The fw.c file includes all the mysql_client_test framework; this file + contains only the actual tests, plus the list of test functions to call. */ -#define DIE_UNLESS(expr) \ - ((void) ((expr) ? 0 : (die(__FILE__, __LINE__, #expr), 0))) -#define DIE_IF(expr) \ - ((void) ((expr) ? (die(__FILE__, __LINE__, #expr), 0) : 0)) -#define DIE(expr) \ - die(__FILE__, __LINE__, #expr) - -static void die(const char *file, int line, const char *expr) -{ - fflush(stdout); - fprintf(stderr, "%s:%d: check failed: '%s'\n", file, line, expr); - fflush(stderr); - exit(1); -} - - -#define myerror(msg) print_error(msg) -#define mysterror(stmt, msg) print_st_error(stmt, msg) - -#define myquery(RES) \ -{ \ - int r= (RES); \ - if (r) \ - myerror(NULL); \ - DIE_UNLESS(r == 0); \ -} - -#define myquery_r(r) \ -{ \ -if (r) \ - myerror(NULL); \ -DIE_UNLESS(r != 0); \ -} - -#define check_execute(stmt, r) \ -{ \ -if (r) \ - mysterror(stmt, NULL); \ -DIE_UNLESS(r == 0);\ -} - -#define check_execute_r(stmt, r) \ -{ \ -if (r) \ - mysterror(stmt, NULL); \ -DIE_UNLESS(r != 0);\ -} - -#define check_stmt(stmt) \ -{ \ -if ( stmt == 0) \ - myerror(NULL); \ -DIE_UNLESS(stmt != 0); \ -} - -#define check_stmt_r(stmt) \ -{ \ -if (stmt == 0) \ - myerror(NULL);\ -DIE_UNLESS(stmt == 0);\ -} - -#define mytest(x) if (!(x)) {myerror(NULL);DIE_UNLESS(FALSE);} -#define mytest_r(x) if ((x)) {myerror(NULL);DIE_UNLESS(FALSE);} - - -/* A workaround for Sun Forte 5.6 on Solaris x86 */ - -static int cmp_double(double *a, double *b) -{ - return *a == *b; -} - - -/* Print the error message */ - -static void print_error(const char *msg) -{ - if (!opt_silent) - { - if (mysql && mysql_errno(mysql)) - { - if (mysql->server_version) - fprintf(stdout, "\n [MySQL-%s]", mysql->server_version); - else - fprintf(stdout, "\n [MySQL]"); - fprintf(stdout, "[%d] %s\n", mysql_errno(mysql), mysql_error(mysql)); - } - else if (msg) - fprintf(stderr, " [MySQL] %s\n", msg); - } -} - - -static void print_st_error(MYSQL_STMT *stmt, const char *msg) -{ - if (!opt_silent) - { - if (stmt && mysql_stmt_errno(stmt)) - { - if (stmt->mysql && stmt->mysql->server_version) - fprintf(stdout, "\n [MySQL-%s]", stmt->mysql->server_version); - else - fprintf(stdout, "\n [MySQL]"); - - fprintf(stdout, "[%d] %s\n", mysql_stmt_errno(stmt), - mysql_stmt_error(stmt)); - } - else if (msg) - fprintf(stderr, " [MySQL] %s\n", msg); - } -} - -/* - Enhanced version of mysql_client_init(), which may also set shared memory - base on Windows. -*/ -static MYSQL *mysql_client_init(MYSQL* con) -{ - MYSQL* res = mysql_init(con); -#ifdef HAVE_SMEM - if (res && shared_memory_base_name) - mysql_options(res, MYSQL_SHARED_MEMORY_BASE_NAME, shared_memory_base_name); -#endif - return res; -} - -/* - Disable direct calls of mysql_init, as it disregards shared memory base. -*/ -#define mysql_init(A) Please use mysql_client_init instead of mysql_init - - -/* Check if the connection has InnoDB tables */ - -static my_bool check_have_innodb(MYSQL *conn) -{ - MYSQL_RES *res; - MYSQL_ROW row; - int rc; - my_bool result; - - rc= mysql_query(conn, "show variables like 'have_innodb'"); - myquery(rc); - res= mysql_use_result(conn); - DIE_UNLESS(res); - - row= mysql_fetch_row(res); - DIE_UNLESS(row); - - result= strcmp(row[1], "YES") == 0; - mysql_free_result(res); - return result; -} - - -/* - This is to be what mysql_query() is for mysql_real_query(), for - mysql_simple_prepare(): a variant without the 'length' parameter. -*/ - -static MYSQL_STMT *STDCALL -mysql_simple_prepare(MYSQL *mysql_arg, const char *query) -{ - MYSQL_STMT *stmt= mysql_stmt_init(mysql_arg); - if (stmt && mysql_stmt_prepare(stmt, query, (uint) strlen(query))) - { - mysql_stmt_close(stmt); - return 0; - } - return stmt; -} - - -/** - Connect to the server with options given by arguments to this application, - stored in global variables opt_host, opt_user, opt_password, opt_db, - opt_port and opt_unix_socket. - - @param flag[in] client_flag passed on to mysql_real_connect - @param protocol[in] MYSQL_PROTOCOL_* to use for this connection - @param auto_reconnect[in] set to 1 for auto reconnect - - @return pointer to initialized and connected MYSQL object -*/ -static MYSQL* client_connect(ulong flag, uint protocol, my_bool auto_reconnect) -{ - MYSQL* mysql; - int rc; - static char query[MAX_TEST_QUERY_LENGTH]; - myheader_r("client_connect"); - - if (!opt_silent) - fprintf(stdout, "\n Establishing a connection to '%s' ...", - opt_host ? opt_host : ""); - - if (!(mysql= mysql_client_init(NULL))) - { - opt_silent= 0; - myerror("mysql_client_init() failed"); - exit(1); - } - /* enable local infile, in non-binary builds often disabled by default */ - mysql_options(mysql, MYSQL_OPT_LOCAL_INFILE, 0); - mysql_options(mysql, MYSQL_OPT_PROTOCOL, &protocol); - - if (!(mysql_real_connect(mysql, opt_host, opt_user, - opt_password, opt_db ? opt_db:"test", opt_port, - opt_unix_socket, flag))) - { - opt_silent= 0; - myerror("connection failed"); - mysql_close(mysql); - fprintf(stdout, "\n Check the connection options using --help or -?\n"); - exit(1); - } - mysql->reconnect= auto_reconnect; - - if (!opt_silent) - fprintf(stdout, "OK"); - - /* set AUTOCOMMIT to ON*/ - mysql_autocommit(mysql, TRUE); - - if (!opt_silent) - { - fprintf(stdout, "\nConnected to MySQL server version: %s (%lu)\n", - mysql_get_server_info(mysql), - (ulong) mysql_get_server_version(mysql)); - fprintf(stdout, "\n Creating a test database '%s' ...", current_db); - } - strxmov(query, "CREATE DATABASE IF NOT EXISTS ", current_db, NullS); - - rc= mysql_query(mysql, query); - myquery(rc); - - strxmov(query, "USE ", current_db, NullS); - rc= mysql_query(mysql, query); - myquery(rc); - have_innodb= check_have_innodb(mysql); - - if (!opt_silent) - fprintf(stdout, "OK"); - - return mysql; -} - - -/* Close the connection */ - -static void client_disconnect(MYSQL* mysql, my_bool drop_db) -{ - static char query[MAX_TEST_QUERY_LENGTH]; - - myheader_r("client_disconnect"); - - if (mysql) - { - if (drop_db) - { - if (!opt_silent) - fprintf(stdout, "\n dropping the test database '%s' ...", current_db); - strxmov(query, "DROP DATABASE IF EXISTS ", current_db, NullS); - - mysql_query(mysql, query); - if (!opt_silent) - fprintf(stdout, "OK"); - } - - if (!opt_silent) - fprintf(stdout, "\n closing the connection ..."); - mysql_close(mysql); - if (!opt_silent) - fprintf(stdout, "OK\n"); - } -} - +#include "mysql_client_fw.c" /* Query processing */ @@ -443,471 +77,6 @@ static void client_query() } -/* Print dashes */ - -static void my_print_dashes(MYSQL_RES *result) -{ - MYSQL_FIELD *field; - unsigned int i, j; - - mysql_field_seek(result, 0); - fputc('\t', stdout); - fputc('+', stdout); - - for(i= 0; i< mysql_num_fields(result); i++) - { - field= mysql_fetch_field(result); - for(j= 0; j < field->max_length+2; j++) - fputc('-', stdout); - fputc('+', stdout); - } - fputc('\n', stdout); -} - - -/* Print resultset metadata information */ - -static void my_print_result_metadata(MYSQL_RES *result) -{ - MYSQL_FIELD *field; - unsigned int i, j; - unsigned int field_count; - - mysql_field_seek(result, 0); - if (!opt_silent) - { - fputc('\n', stdout); - fputc('\n', stdout); - } - - field_count= mysql_num_fields(result); - for(i= 0; i< field_count; i++) - { - field= mysql_fetch_field(result); - j= strlen(field->name); - if (j < field->max_length) - j= field->max_length; - if (j < 4 && !IS_NOT_NULL(field->flags)) - j= 4; - field->max_length= j; - } - if (!opt_silent) - { - my_print_dashes(result); - fputc('\t', stdout); - fputc('|', stdout); - } - - mysql_field_seek(result, 0); - for(i= 0; i< field_count; i++) - { - field= mysql_fetch_field(result); - if (!opt_silent) - fprintf(stdout, " %-*s |", (int) field->max_length, field->name); - } - if (!opt_silent) - { - fputc('\n', stdout); - my_print_dashes(result); - } -} - - -/* Process the result set */ - -static int my_process_result_set(MYSQL_RES *result) -{ - MYSQL_ROW row; - MYSQL_FIELD *field; - unsigned int i; - unsigned int row_count= 0; - - if (!result) - return 0; - - my_print_result_metadata(result); - - while ((row= mysql_fetch_row(result)) != NULL) - { - mysql_field_seek(result, 0); - if (!opt_silent) - { - fputc('\t', stdout); - fputc('|', stdout); - } - - for(i= 0; i< mysql_num_fields(result); i++) - { - field= mysql_fetch_field(result); - if (!opt_silent) - { - if (row[i] == NULL) - fprintf(stdout, " %-*s |", (int) field->max_length, "NULL"); - else if (IS_NUM(field->type)) - fprintf(stdout, " %*s |", (int) field->max_length, row[i]); - else - fprintf(stdout, " %-*s |", (int) field->max_length, row[i]); - } - } - if (!opt_silent) - { - fputc('\t', stdout); - fputc('\n', stdout); - } - row_count++; - } - if (!opt_silent) - { - if (row_count) - my_print_dashes(result); - - if (mysql_errno(mysql) != 0) - fprintf(stderr, "\n\tmysql_fetch_row() failed\n"); - else - fprintf(stdout, "\n\t%d %s returned\n", row_count, - row_count == 1 ? "row" : "rows"); - } - return row_count; -} - - -static int my_process_result(MYSQL *mysql_arg) -{ - MYSQL_RES *result; - int row_count; - - if (!(result= mysql_store_result(mysql_arg))) - return 0; - - row_count= my_process_result_set(result); - - mysql_free_result(result); - return row_count; -} - - -/* Process the statement result set */ - -#define MAX_RES_FIELDS 50 -#define MAX_FIELD_DATA_SIZE 255 - -static int my_process_stmt_result(MYSQL_STMT *stmt) -{ - int field_count; - int row_count= 0; - MYSQL_BIND buffer[MAX_RES_FIELDS]; - MYSQL_FIELD *field; - MYSQL_RES *result; - char data[MAX_RES_FIELDS][MAX_FIELD_DATA_SIZE]; - ulong length[MAX_RES_FIELDS]; - my_bool is_null[MAX_RES_FIELDS]; - int rc, i; - - if (!(result= mysql_stmt_result_metadata(stmt))) /* No meta info */ - { - while (!mysql_stmt_fetch(stmt)) - row_count++; - return row_count; - } - - field_count= min(mysql_num_fields(result), MAX_RES_FIELDS); - - bzero((char*) buffer, sizeof(buffer)); - bzero((char*) length, sizeof(length)); - bzero((char*) is_null, sizeof(is_null)); - - for(i= 0; i < field_count; i++) - { - buffer[i].buffer_type= MYSQL_TYPE_STRING; - buffer[i].buffer_length= MAX_FIELD_DATA_SIZE; - buffer[i].length= &length[i]; - buffer[i].buffer= (void *) data[i]; - buffer[i].is_null= &is_null[i]; - } - - rc= mysql_stmt_bind_result(stmt, buffer); - check_execute(stmt, rc); - - rc= 1; - mysql_stmt_attr_set(stmt, STMT_ATTR_UPDATE_MAX_LENGTH, (void*)&rc); - rc= mysql_stmt_store_result(stmt); - check_execute(stmt, rc); - my_print_result_metadata(result); - - mysql_field_seek(result, 0); - while ((rc= mysql_stmt_fetch(stmt)) == 0) - { - if (!opt_silent) - { - fputc('\t', stdout); - fputc('|', stdout); - } - mysql_field_seek(result, 0); - for (i= 0; i < field_count; i++) - { - field= mysql_fetch_field(result); - if (!opt_silent) - { - if (is_null[i]) - fprintf(stdout, " %-*s |", (int) field->max_length, "NULL"); - else if (length[i] == 0) - { - data[i][0]= '\0'; /* unmodified buffer */ - fprintf(stdout, " %*s |", (int) field->max_length, data[i]); - } - else if (IS_NUM(field->type)) - fprintf(stdout, " %*s |", (int) field->max_length, data[i]); - else - fprintf(stdout, " %-*s |", (int) field->max_length, data[i]); - } - } - if (!opt_silent) - { - fputc('\t', stdout); - fputc('\n', stdout); - } - row_count++; - } - DIE_UNLESS(rc == MYSQL_NO_DATA); - if (!opt_silent) - { - if (row_count) - my_print_dashes(result); - fprintf(stdout, "\n\t%d %s returned\n", row_count, - row_count == 1 ? "row" : "rows"); - } - mysql_free_result(result); - return row_count; -} - - -/* Prepare statement, execute, and process result set for given query */ - -int my_stmt_result(const char *buff) -{ - MYSQL_STMT *stmt; - int row_count; - int rc; - - if (!opt_silent) - fprintf(stdout, "\n\n %s", buff); - stmt= mysql_simple_prepare(mysql, buff); - check_stmt(stmt); - - rc= mysql_stmt_execute(stmt); - check_execute(stmt, rc); - - row_count= my_process_stmt_result(stmt); - mysql_stmt_close(stmt); - - return row_count; -} - - -/* Utility function to verify a particular column data */ - -static void verify_col_data(const char *table, const char *col, - const char *exp_data) -{ - static char query[MAX_TEST_QUERY_LENGTH]; - MYSQL_RES *result; - MYSQL_ROW row; - int rc, field= 1; - - if (table && col) - { - strxmov(query, "SELECT ", col, " FROM ", table, " LIMIT 1", NullS); - if (!opt_silent) - fprintf(stdout, "\n %s", query); - rc= mysql_query(mysql, query); - myquery(rc); - - field= 0; - } - - result= mysql_use_result(mysql); - mytest(result); - - if (!(row= mysql_fetch_row(result)) || !row[field]) - { - fprintf(stdout, "\n *** ERROR: FAILED TO GET THE RESULT ***"); - exit(1); - } - if (strcmp(row[field], exp_data)) - { - fprintf(stdout, "\n obtained: `%s` (expected: `%s`)", - row[field], exp_data); - DIE_UNLESS(FALSE); - } - mysql_free_result(result); -} - - -/* Utility function to verify the field members */ - -#define verify_prepare_field(result,no,name,org_name,type,table,\ - org_table,db,length,def) \ - do_verify_prepare_field((result),(no),(name),(org_name),(type), \ - (table),(org_table),(db),(length),(def), \ - __FILE__, __LINE__) - -static void do_verify_prepare_field(MYSQL_RES *result, - unsigned int no, const char *name, - const char *org_name, - enum enum_field_types type, - const char *table, - const char *org_table, const char *db, - unsigned long length, const char *def, - const char *file, int line) -{ - MYSQL_FIELD *field; - CHARSET_INFO *cs; - ulonglong expected_field_length; - - if (!(field= mysql_fetch_field_direct(result, no))) - { - fprintf(stdout, "\n *** ERROR: FAILED TO GET THE RESULT ***"); - exit(1); - } - cs= get_charset(field->charsetnr, 0); - DIE_UNLESS(cs); - if ((expected_field_length= length * cs->mbmaxlen) > UINT_MAX32) - expected_field_length= UINT_MAX32; - if (!opt_silent) - { - fprintf(stdout, "\n field[%d]:", no); - fprintf(stdout, "\n name :`%s`\t(expected: `%s`)", field->name, name); - fprintf(stdout, "\n org_name :`%s`\t(expected: `%s`)", - field->org_name, org_name); - fprintf(stdout, "\n type :`%d`\t(expected: `%d`)", field->type, type); - if (table) - fprintf(stdout, "\n table :`%s`\t(expected: `%s`)", - field->table, table); - if (org_table) - fprintf(stdout, "\n org_table:`%s`\t(expected: `%s`)", - field->org_table, org_table); - fprintf(stdout, "\n database :`%s`\t(expected: `%s`)", field->db, db); - fprintf(stdout, "\n length :`%lu`\t(expected: `%llu`)", - field->length, expected_field_length); - fprintf(stdout, "\n maxlength:`%ld`", field->max_length); - fprintf(stdout, "\n charsetnr:`%d`", field->charsetnr); - fprintf(stdout, "\n default :`%s`\t(expected: `%s`)", - field->def ? field->def : "(null)", def ? def: "(null)"); - fprintf(stdout, "\n"); - } - DIE_UNLESS(strcmp(field->name, name) == 0); - DIE_UNLESS(strcmp(field->org_name, org_name) == 0); - /* - XXX: silent column specification change works based on number of - bytes a column occupies. So CHAR -> VARCHAR upgrade is possible even - for CHAR(2) column if its character set is multibyte. - VARCHAR -> CHAR downgrade won't work for VARCHAR(3) as one would - expect. - */ - if (cs->mbmaxlen == 1) - { - if (field->type != type) - { - fprintf(stderr, - "Expected field type: %d, got type: %d in file %s, line %d\n", - (int) type, (int) field->type, file, line); - DIE_UNLESS(field->type == type); - } - } - if (table) - DIE_UNLESS(strcmp(field->table, table) == 0); - if (org_table) - DIE_UNLESS(strcmp(field->org_table, org_table) == 0); - DIE_UNLESS(strcmp(field->db, db) == 0); - /* - Character set should be taken into account for multibyte encodings, such - as utf8. Field length is calculated as number of characters * maximum - number of bytes a character can occupy. - */ - if (length && (field->length != expected_field_length)) - { - fprintf(stderr, "Expected field length: %llu, got length: %lu\n", - expected_field_length, field->length); - DIE_UNLESS(field->length == expected_field_length); - } - if (def) - DIE_UNLESS(strcmp(field->def, def) == 0); -} - - -/* Utility function to verify the parameter count */ - -static void verify_param_count(MYSQL_STMT *stmt, long exp_count) -{ - long param_count= mysql_stmt_param_count(stmt); - if (!opt_silent) - fprintf(stdout, "\n total parameters in stmt: `%ld` (expected: `%ld`)", - param_count, exp_count); - DIE_UNLESS(param_count == exp_count); -} - - -/* Utility function to verify the total affected rows */ - -static void verify_st_affected_rows(MYSQL_STMT *stmt, ulonglong exp_count) -{ - ulonglong affected_rows= mysql_stmt_affected_rows(stmt); - if (!opt_silent) - fprintf(stdout, "\n total affected rows: `%ld` (expected: `%ld`)", - (long) affected_rows, (long) exp_count); - DIE_UNLESS(affected_rows == exp_count); -} - - -/* Utility function to verify the total affected rows */ - -static void verify_affected_rows(ulonglong exp_count) -{ - ulonglong affected_rows= mysql_affected_rows(mysql); - if (!opt_silent) - fprintf(stdout, "\n total affected rows: `%ld` (expected: `%ld`)", - (long) affected_rows, (long) exp_count); - DIE_UNLESS(affected_rows == exp_count); -} - - -/* Utility function to verify the total fields count */ - -static void verify_field_count(MYSQL_RES *result, uint exp_count) -{ - uint field_count= mysql_num_fields(result); - if (!opt_silent) - fprintf(stdout, "\n total fields in the result set: `%d` (expected: `%d`)", - field_count, exp_count); - DIE_UNLESS(field_count == exp_count); -} - - -/* Utility function to execute a query using prepare-execute */ - -#ifndef EMBEDDED_LIBRARY -static void execute_prepare_query(const char *query, ulonglong exp_count) -{ - MYSQL_STMT *stmt; - ulonglong affected_rows; - int rc; - - stmt= mysql_simple_prepare(mysql, query); - check_stmt(stmt); - - rc= mysql_stmt_execute(stmt); - myquery(rc); - - affected_rows= mysql_stmt_affected_rows(stmt); - if (!opt_silent) - fprintf(stdout, "\n total affected rows: `%ld` (expected: `%ld`)", - (long) affected_rows, (long) exp_count); - - DIE_UNLESS(affected_rows == exp_count); - mysql_stmt_close(stmt); -} -#endif - /* Store result processing */ static void client_store_result() @@ -949,267 +118,6 @@ static void client_use_result() } -/* - Accepts arbitrary number of queries and runs them against the database. - Used to fill tables for each test. -*/ - -void fill_tables(const char **query_list, unsigned query_count) -{ - int rc; - const char **query; - DBUG_ENTER("fill_tables"); - for (query= query_list; query < query_list + query_count; - ++query) - { - rc= mysql_query(mysql, *query); - myquery(rc); - } - DBUG_VOID_RETURN; -} - -/* - All state of fetch from one statement: statement handle, out buffers, - fetch position. - See fetch_n for for the only use case. -*/ - -enum { MAX_COLUMN_LENGTH= 255 }; - -typedef struct st_stmt_fetch -{ - const char *query; - unsigned stmt_no; - MYSQL_STMT *handle; - my_bool is_open; - MYSQL_BIND *bind_array; - char **out_data; - unsigned long *out_data_length; - unsigned column_count; - unsigned row_count; -} Stmt_fetch; - - -/* - Create statement handle, prepare it with statement, execute and allocate - fetch buffers. -*/ - -void stmt_fetch_init(Stmt_fetch *fetch, unsigned stmt_no_arg, - const char *query_arg) -{ - unsigned long type= CURSOR_TYPE_READ_ONLY; - int rc; - unsigned i; - MYSQL_RES *metadata; - DBUG_ENTER("stmt_fetch_init"); - - /* Save query and statement number for error messages */ - fetch->stmt_no= stmt_no_arg; - fetch->query= query_arg; - - fetch->handle= mysql_stmt_init(mysql); - - rc= mysql_stmt_prepare(fetch->handle, fetch->query, strlen(fetch->query)); - check_execute(fetch->handle, rc); - - /* - The attribute is sent to server on execute and asks to open read-only - for result set - */ - mysql_stmt_attr_set(fetch->handle, STMT_ATTR_CURSOR_TYPE, - (const void*) &type); - - rc= mysql_stmt_execute(fetch->handle); - check_execute(fetch->handle, rc); - - /* Find out total number of columns in result set */ - metadata= mysql_stmt_result_metadata(fetch->handle); - fetch->column_count= mysql_num_fields(metadata); - mysql_free_result(metadata); - - /* - Now allocate bind handles and buffers for output data: - calloc memory to reduce number of MYSQL_BIND members we need to - set up. - */ - - fetch->bind_array= (MYSQL_BIND *) calloc(1, sizeof(MYSQL_BIND) * - fetch->column_count); - fetch->out_data= (char**) calloc(1, sizeof(char*) * fetch->column_count); - fetch->out_data_length= (ulong*) calloc(1, sizeof(ulong) * - fetch->column_count); - for (i= 0; i < fetch->column_count; ++i) - { - fetch->out_data[i]= (char*) calloc(1, MAX_COLUMN_LENGTH); - fetch->bind_array[i].buffer_type= MYSQL_TYPE_STRING; - fetch->bind_array[i].buffer= fetch->out_data[i]; - fetch->bind_array[i].buffer_length= MAX_COLUMN_LENGTH; - fetch->bind_array[i].length= fetch->out_data_length + i; - } - - mysql_stmt_bind_result(fetch->handle, fetch->bind_array); - - fetch->row_count= 0; - fetch->is_open= TRUE; - - /* Ready for reading rows */ - DBUG_VOID_RETURN; -} - - -/* Fetch and print one row from cursor */ - -int stmt_fetch_fetch_row(Stmt_fetch *fetch) -{ - int rc; - unsigned i; - DBUG_ENTER("stmt_fetch_fetch_row"); - - if ((rc= mysql_stmt_fetch(fetch->handle)) == 0) - { - ++fetch->row_count; - if (!opt_silent) - printf("Stmt %d fetched row %d:\n", fetch->stmt_no, fetch->row_count); - for (i= 0; i < fetch->column_count; ++i) - { - fetch->out_data[i][fetch->out_data_length[i]]= '\0'; - if (!opt_silent) - printf("column %d: %s\n", i+1, fetch->out_data[i]); - } - } - else - fetch->is_open= FALSE; - DBUG_RETURN(rc); -} - - -void stmt_fetch_close(Stmt_fetch *fetch) -{ - unsigned i; - DBUG_ENTER("stmt_fetch_close"); - - for (i= 0; i < fetch->column_count; ++i) - free(fetch->out_data[i]); - free(fetch->out_data); - free(fetch->out_data_length); - free(fetch->bind_array); - mysql_stmt_close(fetch->handle); - DBUG_VOID_RETURN; -} - -/* - For given array of queries, open query_count cursors and fetch - from them in simultaneous manner. - In case there was an error in one of the cursors, continue - reading from the rest. -*/ - -enum fetch_type { USE_ROW_BY_ROW_FETCH= 0, USE_STORE_RESULT= 1 }; - -my_bool fetch_n(const char **query_list, unsigned query_count, - enum fetch_type fetch_type) -{ - unsigned open_statements= query_count; - int rc, error_count= 0; - Stmt_fetch *fetch_array= (Stmt_fetch*) calloc(1, sizeof(Stmt_fetch) * - query_count); - Stmt_fetch *fetch; - DBUG_ENTER("fetch_n"); - - for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch) - { - /* Init will exit(1) in case of error */ - stmt_fetch_init(fetch, fetch - fetch_array, - query_list[fetch - fetch_array]); - } - - if (fetch_type == USE_STORE_RESULT) - { - for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch) - { - rc= mysql_stmt_store_result(fetch->handle); - check_execute(fetch->handle, rc); - } - } - - while (open_statements) - { - for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch) - { - if (fetch->is_open && (rc= stmt_fetch_fetch_row(fetch))) - { - open_statements--; - /* - We try to fetch from the rest of the statements in case of - error - */ - if (rc != MYSQL_NO_DATA) - { - fprintf(stderr, - "Got error reading rows from statement %d,\n" - "query is: %s,\n" - "error message: %s", (int) (fetch - fetch_array), - fetch->query, - mysql_stmt_error(fetch->handle)); - error_count++; - } - } - } - } - if (error_count) - fprintf(stderr, "Fetch FAILED"); - else - { - unsigned total_row_count= 0; - for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch) - total_row_count+= fetch->row_count; - if (!opt_silent) - printf("Success, total rows fetched: %d\n", total_row_count); - } - for (fetch= fetch_array; fetch < fetch_array + query_count; ++fetch) - stmt_fetch_close(fetch); - free(fetch_array); - DBUG_RETURN(error_count != 0); -} - -/* Separate thread query to test some cases */ - -static my_bool thread_query(const char *query) -{ - MYSQL *l_mysql; - my_bool error; - - error= 0; - if (!opt_silent) - fprintf(stdout, "\n in thread_query(%s)", query); - if (!(l_mysql= mysql_client_init(NULL))) - { - myerror("mysql_client_init() failed"); - return 1; - } - if (!(mysql_real_connect(l_mysql, opt_host, opt_user, - opt_password, current_db, opt_port, - opt_unix_socket, 0))) - { - myerror("connection failed"); - error= 1; - goto end; - } - l_mysql->reconnect= 1; - if (mysql_query(l_mysql, query)) - { - fprintf(stderr, "Query failed (%s)\n", mysql_error(l_mysql)); - error= 1; - goto end; - } - mysql_commit(l_mysql); -end: - mysql_close(l_mysql); - return error; -} - - /* Query processing */ static void test_debug_example() @@ -18593,85 +17501,6 @@ static void test_bug13001491() } -/* - Read and parse arguments and MySQL options from my.cnf -*/ - -static const char *client_test_load_default_groups[]= { "client", 0 }; -static char **defaults_argv; - -static struct my_option client_test_long_options[] = -{ - {"basedir", 'b', "Basedir for tests.", &opt_basedir, - &opt_basedir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"count", 't', "Number of times test to be executed", &opt_count, - &opt_count, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0}, - {"database", 'D', "Database to use", &opt_db, &opt_db, - 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"debug", '#', "Output debug log", &default_dbug_option, - &default_dbug_option, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, - {"help", '?', "Display this help and exit", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, - 0, 0, 0, 0, 0}, - {"host", 'h', "Connect to host", &opt_host, &opt_host, - 0, GET_STR_ALLOC, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"password", 'p', - "Password to use when connecting to server. If password is not given it's asked from the tty.", - 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0}, - {"port", 'P', "Port number to use for connection or 0 for default to, in " - "order of preference, my.cnf, $MYSQL_TCP_PORT, " -#if MYSQL_PORT_DEFAULT == 0 - "/etc/services, " -#endif - "built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").", - &opt_port, &opt_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"server-arg", 'A', "Send embedded server this as a parameter.", - 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"show-tests", 'T', "Show all tests' names", 0, 0, 0, GET_NO_ARG, NO_ARG, - 0, 0, 0, 0, 0, 0}, - {"silent", 's', "Be more silent", 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, - 0}, -#ifdef HAVE_SMEM - {"shared-memory-base-name", 'm', "Base name of shared memory.", - &shared_memory_base_name, (uchar**)&shared_memory_base_name, 0, - GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, -#endif - {"socket", 'S', "Socket file to use for connection", - &opt_unix_socket, &opt_unix_socket, 0, GET_STR, - REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"testcase", 'c', - "May disable some code when runs as mysql-test-run testcase.", - 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}, -#ifndef DONT_ALLOW_USER_CHANGE - {"user", 'u', "User for login if not current user", &opt_user, - &opt_user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, -#endif - {"vardir", 'v', "Data dir for tests.", &opt_vardir, - &opt_vardir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"getopt-ll-test", 'g', "Option for testing bug in getopt library", - &opt_getopt_ll_test, &opt_getopt_ll_test, 0, - GET_LL, REQUIRED_ARG, 0, 0, LONGLONG_MAX, 0, 0, 0}, - { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} -}; - - -static void usage(void) -{ - /* show the usage string when the user asks for this */ - putc('\n', stdout); - printf("%s Ver %s Distrib %s, for %s (%s)\n", - my_progname, VER, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE); - puts("By Monty, Venu, Kent and others\n"); - printf("\ -Copyright (C) 2002-2004 MySQL AB\n\ -This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\ -and you are welcome to modify and redistribute it under the GPL license\n"); - printf("Usage: %s [OPTIONS] [TESTNAME1 TESTNAME2...]\n", my_progname); - my_print_help(client_test_long_options); - print_defaults("my", client_test_load_default_groups); - my_print_variables(client_test_long_options); -} - - static struct my_tests_st my_tests[]= { { "disable_query_logs", disable_query_logs }, { "test_view_sp_list_fields", test_view_sp_list_fields }, @@ -18926,181 +17755,4 @@ static struct my_tests_st my_tests[]= { }; -static my_bool -get_one_option(int optid, const struct my_option *opt __attribute__((unused)), - char *argument) -{ - switch (optid) { - case '#': - DBUG_PUSH(argument ? argument : default_dbug_option); - break; - case 'c': - opt_testcase = 1; - break; - case 'p': - if (argument) - { - char *start=argument; - my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR)); - opt_password= my_strdup(argument, MYF(MY_FAE)); - while (*argument) *argument++= 'x'; /* Destroy argument */ - if (*start) - start[1]=0; - } - else - tty_password= 1; - break; - case 's': - if (argument == disabled_my_option) - opt_silent= 0; - else - opt_silent++; - break; - case 'A': - /* - When the embedded server is being tested, the test suite needs to be - able to pass command-line arguments to the embedded server so it can - locate the language files and data directory. The test suite - (mysql-test-run) never uses config files, just command-line options. - */ - if (!embedded_server_arg_count) - { - embedded_server_arg_count= 1; - embedded_server_args[0]= (char*) ""; - } - if (embedded_server_arg_count == MAX_SERVER_ARGS-1 || - !(embedded_server_args[embedded_server_arg_count++]= - my_strdup(argument, MYF(MY_FAE)))) - { - DIE("Can't use server argument"); - } - break; - case 'T': - { - struct my_tests_st *fptr; - - printf("All possible test names:\n\n"); - for (fptr= my_tests; fptr->name; fptr++) - printf("%s\n", fptr->name); - exit(0); - break; - } - case '?': - case 'I': /* Info */ - usage(); - exit(0); - break; - } - return 0; -} - -static void get_options(int *argc, char ***argv) -{ - int ho_error; - - if ((ho_error= handle_options(argc, argv, client_test_long_options, - get_one_option))) - exit(ho_error); - - if (tty_password) - opt_password= get_tty_password(NullS); - return; -} - -/* - Print the test output on successful execution before exiting -*/ - -static void print_test_output() -{ - if (opt_silent < 3) - { - fprintf(stdout, "\n\n"); - fprintf(stdout, "All '%d' tests were successful (in '%d' iterations)", - test_count-1, opt_count); - fprintf(stdout, "\n Total execution time: %g SECS", total_time); - if (opt_count > 1) - fprintf(stdout, " (Avg: %g SECS)", total_time/opt_count); - - fprintf(stdout, "\n\n!!! SUCCESS !!!\n"); - } -} - -/*************************************************************************** - main routine -***************************************************************************/ - - -int main(int argc, char **argv) -{ - struct my_tests_st *fptr; - - MY_INIT(argv[0]); - - load_defaults("my", client_test_load_default_groups, &argc, &argv); - defaults_argv= argv; - get_options(&argc, &argv); - - if (mysql_server_init(embedded_server_arg_count, - embedded_server_args, - (char**) embedded_server_groups)) - DIE("Can't initialize MySQL server"); - - /* connect to server with no flags, default protocol, auto reconnect true */ - mysql= client_connect(0, MYSQL_PROTOCOL_DEFAULT, 1); - - total_time= 0; - for (iter_count= 1; iter_count <= opt_count; iter_count++) - { - /* Start of tests */ - test_count= 1; - start_time= time((time_t *)0); - if (!argc) - { - for (fptr= my_tests; fptr->name; fptr++) - (*fptr->function)(); - } - else - { - for ( ; *argv ; argv++) - { - for (fptr= my_tests; fptr->name; fptr++) - { - if (!strcmp(fptr->name, *argv)) - { - (*fptr->function)(); - break; - } - } - if (!fptr->name) - { - fprintf(stderr, "\n\nGiven test not found: '%s'\n", *argv); - fprintf(stderr, "See legal test names with %s -T\n\nAborting!\n", - my_progname); - client_disconnect(mysql, 1); - free_defaults(defaults_argv); - exit(1); - } - } - } - - end_time= time((time_t *)0); - total_time+= difftime(end_time, start_time); - - /* End of tests */ - } - - client_disconnect(mysql, 1); /* disconnect from server */ - - free_defaults(defaults_argv); - print_test_output(); - - while (embedded_server_arg_count > 1) - my_free(embedded_server_args[--embedded_server_arg_count],MYF(0)); - - mysql_server_end(); - - my_end(0); - - exit(0); -} +static struct my_tests_st *get_my_tests() { return my_tests; } From aacb690bd52942d2152e661f451fb3b4dd8e0ccf Mon Sep 17 00:00:00 2001 From: Bjorn Munch Date: Mon, 9 Jul 2012 16:36:50 +0200 Subject: [PATCH 76/90] Fixed compile error in mysql_client_test using gcc --- tests/mysql_client_fw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/mysql_client_fw.c b/tests/mysql_client_fw.c index 27a06501d7a..34a4c05215b 100644 --- a/tests/mysql_client_fw.c +++ b/tests/mysql_client_fw.c @@ -1190,7 +1190,7 @@ and you are welcome to modify and redistribute it under the GPL license\n"); } -struct my_tests_st *get_my_tests(); /* Will be defined in main .c file */ +static struct my_tests_st *get_my_tests(); /* To be defined in main .c file */ static struct my_tests_st *my_testlist= 0; From b21319483f708a9bdff43d2773b67043054f5a35 Mon Sep 17 00:00:00 2001 From: Bjorn Munch Date: Tue, 10 Jul 2012 10:04:57 +0200 Subject: [PATCH 77/90] mysql_client_test did not build within limbysqld/examples --- libmysqld/examples/CMakeLists.txt | 3 ++- libmysqld/examples/Makefile.am | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libmysqld/examples/CMakeLists.txt b/libmysqld/examples/CMakeLists.txt index 2b900a1fa8f..d7f994d9b9f 100644 --- a/libmysqld/examples/CMakeLists.txt +++ b/libmysqld/examples/CMakeLists.txt @@ -17,7 +17,8 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/libmysqld/include ${CMAKE_SOURCE_DIR}/regex - ${CMAKE_SOURCE_DIR}/zlib + ${CMAKE_SOURCE_DIR}/zlib + ${CMAKE_SOURCE_DIR}/tests ${CMAKE_SOURCE_DIR}/extra/yassl/include) # Currently does not work with DBUG, there are missing symbols reported. diff --git a/libmysqld/examples/Makefile.am b/libmysqld/examples/Makefile.am index a732b209e27..a0f1a64ffdc 100644 --- a/libmysqld/examples/Makefile.am +++ b/libmysqld/examples/Makefile.am @@ -35,7 +35,7 @@ link_sources: DEFS = -DEMBEDDED_LIBRARY INCLUDES = -I$(top_builddir)/include -I$(top_srcdir)/include -I$(srcdir) \ -I$(top_srcdir) -I$(top_srcdir)/client -I$(top_srcdir)/regex \ - $(openssl_includes) + -I$(top_srcdir)/tests $(openssl_includes) LIBS = @LIBS@ @WRAPLIBS@ @CLIENT_LIBS@ $(yassl_libs) LDADD = @CLIENT_EXTRA_LDFLAGS@ ../libmysqld.a @LIBDL@ $(CXXLDFLAGS) \ @NDB_SCI_LIBS@ @@ -51,6 +51,7 @@ mysql_LDADD = @readline_link@ @TERMCAP_LIB@ $(LDADD) mysql_client_test_embedded_LINK = $(CXXLINK) nodist_mysql_client_test_embedded_SOURCES = mysql_client_test.c +mysql_client_test.o: $(top_srcdir)/tests/mysql_client_fw.c # Don't update the files from bitkeeper %::SCCS/s.% From 13f7f002886c18fc911f6cf6d5bd672f8c96d844 Mon Sep 17 00:00:00 2001 From: Sujatha Sivakumar Date: Tue, 10 Jul 2012 14:23:17 +0530 Subject: [PATCH 78/90] BUG#11762670:MY_B_WRITE RETURN VALUE IGNORED Problem: ======= The return value from my_b_write is ignored by: `my_b_write_quoted', `my_b_write_bit',`Query_log_event::print_query_header' Most callers of `my_b_printf' ignore the return value. `log_event.cc' has many calls to it. Analysis: ======== `my_b_write' is used to write data into a file. If the write fails it sets appropriate error number and error message through my_error() function call and sets the IO_CACHE::error == -1. `my_b_printf' function is also used to write data into a file, it internally invokes my_b_write to do the write operation. Upon success it returns number of characters written to file and on error it returns -1 and sets the error through my_error() and also sets IO_CACHE::error == -1. Most of the event specific print functions for example `Create_file_log_event::print', `Execute_load_log_event::print' etc are the ones which make several calls to the above two functions and they do not check for the return value after the 'print' call. All the above mentioned abuse cases deal with the client side. Fix: === As part of bug fix a check for IO_CACHE::error == -1 has been added at a very high level after the call to the 'print' function. There are few more places where the return value of "my_b_write" is ignored those are mentioned below. +++ mysys/mf_iocache2.c 2012-06-04 07:03:15 +0000 @@ -430,7 +430,8 @@ memset(buffz, '0', minimum_width - length2); else memset(buffz, ' ', minimum_width - length2); - my_b_write(info, buffz, minimum_width - length2); +++ sql/log.cc 2012-06-08 09:04:46 +0000 @@ -2388,7 +2388,12 @@ { end= strxmov(buff, "# administrator command: ", NullS); buff_len= (ulong) (end - buff); - my_b_write(&log_file, (uchar*) buff, buff_len); At these places appropriate return value handlers have been added. client/mysqlbinlog.cc: check for IO_CACHE::error == -1 has been added after the call to the event specific print functions mysys/mf_iocache2.c: Added handler to check the written value of `my_b_write' sql/log.cc: Added handler to check the written value of `my_b_write' sql/log_event.cc: Added error simulation statements in `Create_file_log_event::print` and `Execute_load_query_log_event::print' sql/rpl_utility.h: Removed the extra ';' --- client/mysqlbinlog.cc | 13 ++++++++++++- mysys/mf_iocache2.c | 6 +++++- sql/log.cc | 5 ++++- sql/log_event.cc | 24 +++++++++++++++++++----- sql/rpl_utility.h | 2 +- 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index e7840865a58..b5acfc5c169 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -784,8 +784,11 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, goto end; } else + { ce->print(result_file, print_event_info, TRUE); - + if (head->error == -1) + goto err; + } // If this binlog is not 3.23 ; why this test?? if (glob_description_event->binlog_version >= 3) { @@ -836,6 +839,8 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, ce->print(result_file, print_event_info, TRUE); my_free((char*)ce->fname,MYF(MY_WME)); delete ce; + if (head->error == -1) + goto err; } else warning("Ignoring Execute_load_log_event as there is no " @@ -890,6 +895,12 @@ Exit_status process_event(PRINT_EVENT_INFO *print_event_info, Log_event *ev, { convert_path_to_forward_slashes(fname); exlq->print(result_file, print_event_info, fname); + if (head->error == -1) + { + if (fname) + my_free(fname, MYF(MY_WME)); + goto err; + } } else warning("Ignoring Execute_load_query since there is no " diff --git a/mysys/mf_iocache2.c b/mysys/mf_iocache2.c index 828145b7931..dd56e332433 100644 --- a/mysys/mf_iocache2.c +++ b/mysys/mf_iocache2.c @@ -430,7 +430,11 @@ process_flags: memset(buffz, '0', minimum_width - length2); else memset(buffz, ' ', minimum_width - length2); - my_b_write(info, buffz, minimum_width - length2); + if (my_b_write(info, buffz, minimum_width - length2)) + { + my_afree(buffz); + goto err; + } my_afree(buffz); } diff --git a/sql/log.cc b/sql/log.cc index 3714f1190be..57c14b24782 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -2388,7 +2388,10 @@ bool MYSQL_QUERY_LOG::write(THD *thd, time_t current_time, { end= strxmov(buff, "# administrator command: ", NullS); buff_len= (ulong) (end - buff); - my_b_write(&log_file, (uchar*) buff, buff_len); + DBUG_EXECUTE_IF("simulate_slow_log_write_error", + {DBUG_SET("+d,simulate_file_write_error");}); + if(my_b_write(&log_file, (uchar*) buff, buff_len)) + tmp_errno= errno; } if (my_b_write(&log_file, (uchar*) sql_text, sql_text_len) || my_b_write(&log_file, (uchar*) ";\n",2) || diff --git a/sql/log_event.cc b/sql/log_event.cc index a47b3680d82..2ad740698c6 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -6312,11 +6312,18 @@ void Create_file_log_event::print(FILE* file, PRINT_EVENT_INFO* print_event_info { Load_log_event::print(file, print_event_info, !check_fname_outside_temp_buf()); - /* - That one is for "file_id: etc" below: in mysqlbinlog we want the #, in - SHOW BINLOG EVENTS we don't. - */ - my_b_printf(&cache, "#"); + /** + reduce the size of io cache so that the write function is called + for every call to my_b_printf(). + */ + DBUG_EXECUTE_IF ("simulate_create_event_write_error", + {(&cache)->write_pos= (&cache)->write_end; + DBUG_SET("+d,simulate_file_write_error");}); + /* + That one is for "file_id: etc" below: in mysqlbinlog we want the #, in + SHOW BINLOG EVENTS we don't. + */ + my_b_printf(&cache, "#"); } my_b_printf(&cache, " file_id: %d block_len: %d\n", file_id, block_len); @@ -6992,6 +6999,13 @@ void Execute_load_query_log_event::print(FILE* file, Write_on_release_cache cache(&print_event_info->head_cache, file); print_query_header(&cache, print_event_info); + /** + reduce the size of io cache so that the write function is called + for every call to my_b_printf(). + */ + DBUG_EXECUTE_IF ("simulate_execute_event_write_error", + {(&cache)->write_pos= (&cache)->write_end; + DBUG_SET("+d,simulate_file_write_error");}); if (local_fname) { diff --git a/sql/rpl_utility.h b/sql/rpl_utility.h index 81a10cca814..b2577643add 100644 --- a/sql/rpl_utility.h +++ b/sql/rpl_utility.h @@ -300,7 +300,7 @@ private: public: Deferred_log_events(Relay_log_info *rli); ~Deferred_log_events(); - /* queue for exection at Query-log-event time prior the Query */; + /* queue for exection at Query-log-event time prior the Query */ int add(Log_event *ev); bool is_empty(); bool execute(Relay_log_info *rli); From dc050309716ec62531753a0edb0676fa03f138dc Mon Sep 17 00:00:00 2001 From: Bjorn Munch Date: Tue, 10 Jul 2012 11:48:43 +0200 Subject: [PATCH 79/90] mysql_client_fw.c was not included in make dist --- tests/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Makefile.am b/tests/Makefile.am index 4929fa7ba9b..3da18683f85 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -33,6 +33,7 @@ EXTRA_DIST = auto_increment.res auto_increment.tst \ grant.pl grant.res test_delayed_insert.pl \ pmail.pl mail_to_db.pl table_types.pl \ myisam-big-rows.tst \ + mysql_client_fw.c \ CMakeLists.txt bin_PROGRAMS = mysql_client_test From 86476179479eb14343e1d434a2345d9cad47a28a Mon Sep 17 00:00:00 2001 From: Bjorn Munch Date: Tue, 10 Jul 2012 11:57:24 +0200 Subject: [PATCH 80/90] mysql_client_fw.c was not included in make dist --- tests/Makefile.am | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Makefile.am b/tests/Makefile.am index 4929fa7ba9b..3da18683f85 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -33,6 +33,7 @@ EXTRA_DIST = auto_increment.res auto_increment.tst \ grant.pl grant.res test_delayed_insert.pl \ pmail.pl mail_to_db.pl table_types.pl \ myisam-big-rows.tst \ + mysql_client_fw.c \ CMakeLists.txt bin_PROGRAMS = mysql_client_test From 6da51d170519ac6f0492eccdb33026e9031f653a Mon Sep 17 00:00:00 2001 From: Rohit Kalhans Date: Tue, 10 Jul 2012 18:24:11 +0530 Subject: [PATCH 81/90] BUG#11759333: SBR LOGGING WARNING MESSAGES FOR PRIMARY KEY UPDATES WITH A LIMIT OF 1 Problem: The unsafety warning for statements such as update...limit1 where pk=1 are thrown when binlog-format = STATEMENT,despite of the fact that such statements are actually safe. this leads to filling up of the disk space with false warnings. Solution: This is not a complete fix for the problem, but prevents the disks from getting filled up. This should therefore be regarded as a workaround. In the future this should be overriden by server general suppress/filtering framework. It should also be noted that another worklog is supposed to defeat this case's artificial unsafety. We use a warning suppression mechanism to detect warning flood, enable the suppression, and disable this when the average warnings/second has reduced to acceptable limits. Activation: The supression for LIMIT unsafe statements are activated when the last 50 warnings were logged in less than 50 seconds. Supression: Once activated this supression will prevent the individual warnings to be logged in the error log, but print the warning for every 50 warnings with the note: "The last warning was repeated N times in last S seconds" Noteworthy is the fact that this supression works only on the error logs and the warnings seen by the clients will remain as it is (i.e. one warning/ unsafe statement) Deactivation: The supression will be deactivated once the average # of warnings/sec have gone down to the acceptable limits. sql/sql_class.cc: Added code to supress warning while logging them to error-log. --- sql/sql_class.cc | 144 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 139 insertions(+), 5 deletions(-) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index 7e93157c69e..c118030e7b4 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -4806,6 +4806,140 @@ show_query_type(THD::enum_binlog_query_type qtype) } #endif +/* + Constants required for the limit unsafe warnings suppression +*/ +//seconds after which the limit unsafe warnings suppression will be activated +#define LIMIT_UNSAFE_WARNING_ACTIVATION_TIMEOUT 50 +//number of limit unsafe warnings after which the suppression will be activated +#define LIMIT_UNSAFE_WARNING_ACTIVATION_THRESHOLD_COUNT 50 + +static struct timeval limit_unsafe_suppression_start_time; +static struct timezone limit_unsafe_suppression_start_time_zone; +static bool unsafe_warning_suppression_is_activated= false; +static int limit_unsafe_warning_count= 0; + +/** + Auxiliary function to reset the limit unsafety warning suppression. +*/ +static void reset_binlog_unsafe_suppression() +{ + DBUG_ENTER("reset_binlog_unsafe_suppression"); + unsafe_warning_suppression_is_activated= false; + limit_unsafe_warning_count= 0; + gettimeofday(&limit_unsafe_suppression_start_time, + &limit_unsafe_suppression_start_time_zone); + DBUG_VOID_RETURN; +} + +/** + Auxiliary function to print warning in the error log. +*/ +static void print_unsafe_warning_to_log(int unsafe_type, char* buf, + char* query) +{ + DBUG_ENTER("print_unsafe_warning_in_log"); + sprintf(buf, ER(ER_BINLOG_UNSAFE_STATEMENT), + ER(LEX::binlog_stmt_unsafe_errcode[unsafe_type])); + sql_print_warning(ER(ER_MESSAGE_AND_STATEMENT), buf, query); + DBUG_VOID_RETURN; +} + +/** + Auxiliary function to check if the warning for limit unsafety should be + thrown or suppressed. Details of the implementation can be found in the + comments inline. + SYNOPSIS: + @params + buf - buffer to hold the warning message text + unsafe_type - The type of unsafety. + query - The actual query statement. + + TODO: Remove this function and implement a general service for all warnings + that would prevent flooding the error log. +*/ +static void do_unsafe_limit_checkout(char* buf, int unsafe_type, char* query) +{ + struct timeval now; + struct timezone tz_now; + DBUG_ENTER("do_unsafe_limit_checkout"); + DBUG_ASSERT(unsafe_type == LEX::BINLOG_STMT_UNSAFE_LIMIT); + limit_unsafe_warning_count++; + /* + INITIALIZING: + If this is the first time this function is called with log warning + enabled, the monitoring the unsafe warnings should start. + */ + if (limit_unsafe_suppression_start_time.tv_sec == 0) + { + gettimeofday(&limit_unsafe_suppression_start_time, + &limit_unsafe_suppression_start_time_zone); + print_unsafe_warning_to_log(unsafe_type, buf, query); + } + else + { + if (!unsafe_warning_suppression_is_activated) + print_unsafe_warning_to_log(unsafe_type, buf, query); + + if (limit_unsafe_warning_count >= + LIMIT_UNSAFE_WARNING_ACTIVATION_THRESHOLD_COUNT) + { + gettimeofday (&now, &tz_now); + if (!unsafe_warning_suppression_is_activated) + { + /* + ACTIVATION: + We got LIMIT_UNSAFE_WARNING_ACTIVATION_THRESHOLD_COUNT warnings in + less than LIMIT_UNSAFE_WARNING_ACTIVATION_TIMEOUT we activate the + suppression. + */ + if ((now.tv_sec-limit_unsafe_suppression_start_time.tv_sec) <= + LIMIT_UNSAFE_WARNING_ACTIVATION_TIMEOUT) + { + unsafe_warning_suppression_is_activated= true; + DBUG_PRINT("info",("A warning flood has been detected and the limit \ +unsafety warning suppression has been activated.")); + } + else + { + /* + there is no flooding till now, therefore we restart the monitoring + */ + gettimeofday(&limit_unsafe_suppression_start_time, + &limit_unsafe_suppression_start_time_zone); + limit_unsafe_warning_count= 0; + } + } + else + { + /* + Print the suppression note and the unsafe warning. + */ + sql_print_information("The following warning was suppressed %d times \ +during the last %d seconds in the error log", + limit_unsafe_warning_count, + (int) + (now.tv_sec - + limit_unsafe_suppression_start_time.tv_sec)); + print_unsafe_warning_to_log(unsafe_type, buf, query); + /* + DEACTIVATION: We got LIMIT_UNSAFE_WARNING_ACTIVATION_THRESHOLD_COUNT + warnings in more than LIMIT_UNSAFE_WARNING_ACTIVATION_TIMEOUT, the + suppression should be deactivated. + */ + if ((now.tv_sec - limit_unsafe_suppression_start_time.tv_sec) > + LIMIT_UNSAFE_WARNING_ACTIVATION_TIMEOUT) + { + reset_binlog_unsafe_suppression(); + DBUG_PRINT("info",("The limit unsafety warning supression has been \ +deactivated")); + } + } + limit_unsafe_warning_count= 0; + } + } + DBUG_VOID_RETURN; +} /** Auxiliary method used by @c binlog_query() to raise warnings. @@ -4815,6 +4949,7 @@ show_query_type(THD::enum_binlog_query_type qtype) */ void THD::issue_unsafe_warnings() { + char buf[MYSQL_ERRMSG_SIZE * 2]; DBUG_ENTER("issue_unsafe_warnings"); /* Ensure that binlog_unsafe_warning_flags is big enough to hold all @@ -4840,17 +4975,16 @@ void THD::issue_unsafe_warnings() ER(LEX::binlog_stmt_unsafe_errcode[unsafe_type])); if (global_system_variables.log_warnings) { - char buf[MYSQL_ERRMSG_SIZE * 2]; - sprintf(buf, ER(ER_BINLOG_UNSAFE_STATEMENT), - ER(LEX::binlog_stmt_unsafe_errcode[unsafe_type])); - sql_print_warning(ER(ER_MESSAGE_AND_STATEMENT), buf, query()); + if (unsafe_type == LEX::BINLOG_STMT_UNSAFE_LIMIT) + do_unsafe_limit_checkout( buf, unsafe_type, query()); + else //cases other than LIMIT unsafety + print_unsafe_warning_to_log(unsafe_type, buf, query()); } } } DBUG_VOID_RETURN; } - /** Log the current query. From a47e778a61e26a195642dde82f0062da2dfa2aaa Mon Sep 17 00:00:00 2001 From: Jon Olav Hauglid Date: Tue, 10 Jul 2012 16:13:02 +0200 Subject: [PATCH 83/90] Bug#12623923 Server can crash after failure to create primary key with innodb tables The bug was triggered if a single ALTER TABLE statement both added and dropped indexes and ALTER TABLE failed during drop (e.g. because the index was needed in a foreign key constraint). In such cases, the server index information would get out of sync with InnoDB - the added index would be present inside InnoDB, but not in the server. This could then lead to InnoDB error messages and/or server crashes. The root cause is that new indexes are added before old indexes are dropped. This means that if ALTER TABLE fails while dropping indexes, index changes will be reverted in the server but not inside InnoDB. This patch fixes the problem by dropping any added indexes if drop fails (for ALTER TABLE statements that both adds and drops indexes). However, this won't work if we added a primary key as this key might not be possible to drop inside InnoDB. Therefore, we resort to the copy algorithm if a primary key is added by an ALTER TABLE statement that also drops an index. In 5.6 this bug is more properly fixed by the handler interface changes done in the scope of WL#5534 "Online ALTER". --- sql/sql_table.cc | 49 +++++++++++++++++++---- storage/innobase/handler/ha_innodb.cc | 13 ++++-- storage/innobase/handler/handler0alter.cc | 14 +++---- 3 files changed, 57 insertions(+), 19 deletions(-) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 60ae2ed800b..7d70fa8afd2 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -6313,11 +6313,23 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, the primary key is not added and dropped in the same statement. Otherwise we have to recreate the table. need_copy_table is no-zero at this place. + + Also, in-place is not possible if we add a primary key + and drop another key in the same statement. If the drop fails, + we will not be able to revert adding of primary key. */ if ( pk_changed < 2 ) { - if ((alter_flags & needed_inplace_with_read_flags) == - needed_inplace_with_read_flags) + if ((needed_inplace_with_read_flags & HA_INPLACE_ADD_PK_INDEX_NO_WRITE) && + index_drop_count > 0) + { + /* + Do copy, not in-place ALTER. + Avoid setting ALTER_TABLE_METADATA_ONLY. + */ + } + else if ((alter_flags & needed_inplace_with_read_flags) == + needed_inplace_with_read_flags) { /* All required in-place flags to allow concurrent reads are present. */ need_copy_table= ALTER_TABLE_METADATA_ONLY; @@ -6579,17 +6591,38 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, Tell the handler to prepare for drop indexes. This re-numbers the indexes to get rid of gaps. */ - if ((error= table->file->prepare_drop_index(table, key_numbers, - index_drop_count))) + error= table->file->prepare_drop_index(table, key_numbers, + index_drop_count); + if (!error) { - table->file->print_error(error, MYF(0)); - goto err_new_table_cleanup; + /* Tell the handler to finally drop the indexes. */ + error= table->file->final_drop_index(table); } - /* Tell the handler to finally drop the indexes. */ - if ((error= table->file->final_drop_index(table))) + if (error) { table->file->print_error(error, MYF(0)); + if (index_add_count) // Drop any new indexes added. + { + /* + Temporarily set table-key_info to include information about the + indexes added above that we now need to drop. + */ + KEY *save_key_info= table->key_info; + table->key_info= key_info_buffer; + if ((error= table->file->prepare_drop_index(table, index_add_buffer, + index_add_count))) + table->file->print_error(error, MYF(0)); + else if ((error= table->file->final_drop_index(table))) + table->file->print_error(error, MYF(0)); + table->key_info= save_key_info; + } + + /* + Mark this TABLE instance as stale to avoid + out-of-sync index information. + */ + table->m_needs_reopen= true; goto err_new_table_cleanup; } } diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index ea47a8160f9..60a62482f9c 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -8010,10 +8010,15 @@ innobase_get_mysql_key_number_for_index( } } - /* Print an error message if we cannot find the index - ** in the "index translation table". */ - sql_print_error("Cannot find index %s in InnoDB index " - "translation table.", index->name); + /* If index_count in translation table is set to 0, it + is possible we are in the process of rebuilding table, + do not spit error in this case */ + if (share->idx_trans_tbl.index_count) { + /* Print an error message if we cannot find the index + ** in the "index translation table". */ + sql_print_error("Cannot find index %s in InnoDB index " + "translation table.", index->name); + } } /* If we do not have an "index translation table", or not able diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index e8e3cb0e5cd..5e20bea36dd 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -773,7 +773,7 @@ ha_innobase::add_index( row_mysql_lock_data_dictionary(trx); dict_locked = TRUE; - ut_d(dict_table_check_for_dup_indexes(prebuilt->table, FALSE)); + ut_d(dict_table_check_for_dup_indexes(prebuilt->table, TRUE)); /* If a new primary key is defined for the table we need to drop the original table and rebuild all indexes. */ @@ -809,7 +809,7 @@ ha_innobase::add_index( } ut_d(dict_table_check_for_dup_indexes(prebuilt->table, - FALSE)); + TRUE)); mem_heap_free(heap); trx_general_rollback_for_mysql(trx, NULL); row_mysql_unlock_data_dictionary(trx); @@ -1061,7 +1061,7 @@ ha_innobase::final_add_index( trx_commit_for_mysql(prebuilt->trx); } - ut_d(dict_table_check_for_dup_indexes(prebuilt->table, FALSE)); + ut_d(dict_table_check_for_dup_indexes(prebuilt->table, TRUE)); row_mysql_unlock_data_dictionary(trx); trx_free_for_mysql(trx); @@ -1104,7 +1104,7 @@ ha_innobase::prepare_drop_index( /* Test and mark all the indexes to be dropped */ row_mysql_lock_data_dictionary(trx); - ut_d(dict_table_check_for_dup_indexes(prebuilt->table, FALSE)); + ut_d(dict_table_check_for_dup_indexes(prebuilt->table, TRUE)); /* Check that none of the indexes have previously been flagged for deletion. */ @@ -1275,7 +1275,7 @@ func_exit: } while (index); } - ut_d(dict_table_check_for_dup_indexes(prebuilt->table, FALSE)); + ut_d(dict_table_check_for_dup_indexes(prebuilt->table, TRUE)); row_mysql_unlock_data_dictionary(trx); DBUG_RETURN(err); @@ -1322,7 +1322,7 @@ ha_innobase::final_drop_index( prebuilt->table->flags, user_thd); row_mysql_lock_data_dictionary(trx); - ut_d(dict_table_check_for_dup_indexes(prebuilt->table, FALSE)); + ut_d(dict_table_check_for_dup_indexes(prebuilt->table, TRUE)); if (UNIV_UNLIKELY(err)) { @@ -1366,7 +1366,7 @@ ha_innobase::final_drop_index( share->idx_trans_tbl.index_count = 0; func_exit: - ut_d(dict_table_check_for_dup_indexes(prebuilt->table, FALSE)); + ut_d(dict_table_check_for_dup_indexes(prebuilt->table, TRUE)); trx_commit_for_mysql(trx); trx_commit_for_mysql(prebuilt->trx); row_mysql_unlock_data_dictionary(trx); From 3a71ab0805f2e8cb46872d10b98d8355d15ddcb8 Mon Sep 17 00:00:00 2001 From: Mayank Prasad Date: Tue, 10 Jul 2012 19:59:59 +0530 Subject: [PATCH 84/90] Bug#13889741: HANDLE_FATAL_SIGNAL IN _DB_ENTER_ |HANDLE_FATAL_SIGNAL IN STRNLEN Follow up patch to resolve pb2 failure on windows platform --- sql/sql_show.cc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 189532b2479..e9873d2325f 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2784,9 +2784,12 @@ int make_db_list(THD *thd, List *files, /* If we have db lookup vaule we just add it to list and - exit from the function + exit from the function. + We don't do this for database names longer than the maximum + path length. */ - if (lookup_field_vals->db_value.str) + if (lookup_field_vals->db_value.str && + lookup_field_vals->db_value.length < FN_REFLEN) { if (is_infoschema_db(lookup_field_vals->db_value.str, lookup_field_vals->db_value.length)) From 6fe6288d837a1a3d6a78db9a230e009d039464ab Mon Sep 17 00:00:00 2001 From: Rohit Kalhans Date: Tue, 10 Jul 2012 22:02:25 +0530 Subject: [PATCH 85/90] bug#11759333: follow-up patch for the failure on pb2 windows build --- sql/sql_class.cc | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/sql/sql_class.cc b/sql/sql_class.cc index c118030e7b4..8931d67dd25 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -4814,8 +4814,7 @@ show_query_type(THD::enum_binlog_query_type qtype) //number of limit unsafe warnings after which the suppression will be activated #define LIMIT_UNSAFE_WARNING_ACTIVATION_THRESHOLD_COUNT 50 -static struct timeval limit_unsafe_suppression_start_time; -static struct timezone limit_unsafe_suppression_start_time_zone; +static ulonglong limit_unsafe_suppression_start_time= 0; static bool unsafe_warning_suppression_is_activated= false; static int limit_unsafe_warning_count= 0; @@ -4827,8 +4826,7 @@ static void reset_binlog_unsafe_suppression() DBUG_ENTER("reset_binlog_unsafe_suppression"); unsafe_warning_suppression_is_activated= false; limit_unsafe_warning_count= 0; - gettimeofday(&limit_unsafe_suppression_start_time, - &limit_unsafe_suppression_start_time_zone); + limit_unsafe_suppression_start_time= my_getsystime()/10000000; DBUG_VOID_RETURN; } @@ -4860,8 +4858,7 @@ static void print_unsafe_warning_to_log(int unsafe_type, char* buf, */ static void do_unsafe_limit_checkout(char* buf, int unsafe_type, char* query) { - struct timeval now; - struct timezone tz_now; + ulonglong now= 0; DBUG_ENTER("do_unsafe_limit_checkout"); DBUG_ASSERT(unsafe_type == LEX::BINLOG_STMT_UNSAFE_LIMIT); limit_unsafe_warning_count++; @@ -4870,10 +4867,9 @@ static void do_unsafe_limit_checkout(char* buf, int unsafe_type, char* query) If this is the first time this function is called with log warning enabled, the monitoring the unsafe warnings should start. */ - if (limit_unsafe_suppression_start_time.tv_sec == 0) + if (limit_unsafe_suppression_start_time == 0) { - gettimeofday(&limit_unsafe_suppression_start_time, - &limit_unsafe_suppression_start_time_zone); + limit_unsafe_suppression_start_time= my_getsystime()/10000000; print_unsafe_warning_to_log(unsafe_type, buf, query); } else @@ -4884,7 +4880,7 @@ static void do_unsafe_limit_checkout(char* buf, int unsafe_type, char* query) if (limit_unsafe_warning_count >= LIMIT_UNSAFE_WARNING_ACTIVATION_THRESHOLD_COUNT) { - gettimeofday (&now, &tz_now); + now= my_getsystime()/10000000; if (!unsafe_warning_suppression_is_activated) { /* @@ -4893,7 +4889,7 @@ static void do_unsafe_limit_checkout(char* buf, int unsafe_type, char* query) less than LIMIT_UNSAFE_WARNING_ACTIVATION_TIMEOUT we activate the suppression. */ - if ((now.tv_sec-limit_unsafe_suppression_start_time.tv_sec) <= + if ((now-limit_unsafe_suppression_start_time) <= LIMIT_UNSAFE_WARNING_ACTIVATION_TIMEOUT) { unsafe_warning_suppression_is_activated= true; @@ -4905,8 +4901,7 @@ unsafety warning suppression has been activated.")); /* there is no flooding till now, therefore we restart the monitoring */ - gettimeofday(&limit_unsafe_suppression_start_time, - &limit_unsafe_suppression_start_time_zone); + limit_unsafe_suppression_start_time= my_getsystime()/10000000; limit_unsafe_warning_count= 0; } } @@ -4919,15 +4914,14 @@ unsafety warning suppression has been activated.")); during the last %d seconds in the error log", limit_unsafe_warning_count, (int) - (now.tv_sec - - limit_unsafe_suppression_start_time.tv_sec)); + (now-limit_unsafe_suppression_start_time)); print_unsafe_warning_to_log(unsafe_type, buf, query); /* DEACTIVATION: We got LIMIT_UNSAFE_WARNING_ACTIVATION_THRESHOLD_COUNT warnings in more than LIMIT_UNSAFE_WARNING_ACTIVATION_TIMEOUT, the suppression should be deactivated. */ - if ((now.tv_sec - limit_unsafe_suppression_start_time.tv_sec) > + if ((now - limit_unsafe_suppression_start_time) > LIMIT_UNSAFE_WARNING_ACTIVATION_TIMEOUT) { reset_binlog_unsafe_suppression(); From fc74e2e08f0332ff94cb536956f28177c4048c54 Mon Sep 17 00:00:00 2001 From: Chaithra Gopalareddy Date: Wed, 11 Jul 2012 08:19:17 +0530 Subject: [PATCH 86/90] Bug #13444084:PRIMARY KEY OR UNIQUE KEY >453 BYTES FAILS FOR COUNT DISTINCT GROUP BY PROBLEM: To calculate the final result of the count(distinct(select 1)) we call 'end_send' function instead of 'end_send_group'. 'end_send' cannot be called if we have aggregate functions that need to be evaluated. ANALYSIS: While evaluating for a possible loose_index_scan option for the query, the variable 'is_agg_distinct' is set to 'false' as the item in the distinct clause is not a field. But, we choose loose_index_scan by not taking this into consideration. So, while setting the final 'select_function' to evaluate the result, 'precomputed_group_by' is set to TRUE as in this case loose_index_scan is chosen and we do not have agg_distinct in the query (which is clearly wrong as we have one). As a result, 'end_send' function is chosen as the final select_function instead of 'end_send_group'. The difference between the two being, 'end_send_group' evaluates the aggregates while 'end_send' does not. Hence the wrong result. FIX: The variable 'is_agg_distinct' always represents if 'loose_idnex_scan' can be chosen for aggregate_distinct functions present in the select. So, we check for this variable to continue with loose_index_scan option. sql/opt_range.cc: Do not continue if is_agg_distinct is not set in case of agg_distinct functions. --- sql/opt_range.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 8a6607cf343..03f444c22b5 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -9463,9 +9463,10 @@ get_best_group_min_max(PARAM *param, SEL_TREE *tree, double read_time) have_min= TRUE; else if (min_max_item->sum_func() == Item_sum::MAX_FUNC) have_max= TRUE; - else if (min_max_item->sum_func() == Item_sum::COUNT_DISTINCT_FUNC || - min_max_item->sum_func() == Item_sum::SUM_DISTINCT_FUNC || - min_max_item->sum_func() == Item_sum::AVG_DISTINCT_FUNC) + else if (is_agg_distinct && + (min_max_item->sum_func() == Item_sum::COUNT_DISTINCT_FUNC || + min_max_item->sum_func() == Item_sum::SUM_DISTINCT_FUNC || + min_max_item->sum_func() == Item_sum::AVG_DISTINCT_FUNC)) continue; else DBUG_RETURN(NULL); From 4c33e849f17d321b198d9e9fbcaa150358993bc4 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 11 Jul 2012 15:18:34 +0200 Subject: [PATCH 89/90] Raise version number after cloning 5.1.65 --- configure.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.in b/configure.in index 4e7a3303353..068328992e0 100644 --- a/configure.in +++ b/configure.in @@ -12,7 +12,7 @@ dnl dnl When changing the major version number please also check the switch dnl statement in mysqlbinlog::check_master_version(). You may also need dnl to update version.c in ndb. -AC_INIT([MySQL Server], [5.1.65], [], [mysql]) +AC_INIT([MySQL Server], [5.1.66], [], [mysql]) AC_CONFIG_SRCDIR([sql/mysqld.cc]) AC_CANONICAL_SYSTEM From 704898bf3200af4da42c1bf9251a7da5533db73f Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 8 Aug 2012 12:32:34 +0200 Subject: [PATCH 90/90] undo the fix for MySQL Bug#12998841 --- client/client_priv.h | 1 - client/mysql.cc | 13 ------- client/mysqladmin.cc | 13 ------- client/mysqlslap.c | 12 ------ client/mysqltest.cc | 8 +--- include/mysql.h | 3 +- include/mysql.h.pp | 3 +- include/sql_common.h | 2 - mysql-test/t/plugin_auth.test | 4 +- sql-common/client.c | 70 +++++------------------------------ sql-common/client_plugin.c | 5 --- 11 files changed, 14 insertions(+), 120 deletions(-) diff --git a/client/client_priv.h b/client/client_priv.h index 2362811d2b3..b776dcf8014 100644 --- a/client/client_priv.h +++ b/client/client_priv.h @@ -87,7 +87,6 @@ enum options_client OPT_PLUGIN_DIR, OPT_DEFAULT_AUTH, OPT_DEFAULT_PLUGIN, - OPT_ENABLE_CLEARTEXT_PLUGIN, OPT_MAX_CLIENT_OPTION }; diff --git a/client/mysql.cc b/client/mysql.cc index 630c6215603..b6bc2f4b68f 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -148,8 +148,6 @@ static my_bool column_types_flag; static my_bool preserve_comments= 0; static ulong opt_max_allowed_packet, opt_net_buffer_length; static uint verbose=0,opt_silent=0,opt_mysql_port=0, opt_local_infile=0; -static uint opt_enable_cleartext_plugin= 0; -static my_bool using_opt_enable_cleartext_plugin= 0; static uint my_end_arg; static char * opt_mysql_unix_port=0; static int connect_flag=CLIENT_INTERACTIVE; @@ -1411,10 +1409,6 @@ static struct my_option my_long_options[] = &default_charset, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"delimiter", OPT_DELIMITER, "Delimiter to be used.", &delimiter_str, &delimiter_str, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"enable_cleartext_plugin", OPT_ENABLE_CLEARTEXT_PLUGIN, - "Enable/disable the clear text authentication plugin.", - &opt_enable_cleartext_plugin, &opt_enable_cleartext_plugin, - 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0}, {"execute", 'e', "Execute command and quit. (Disables --force and history file.)", 0, 0, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"vertical", 'E', "Print the output of a query (rows) vertically.", @@ -1642,9 +1636,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), case OPT_LOCAL_INFILE: using_opt_local_infile=1; break; - case OPT_ENABLE_CLEARTEXT_PLUGIN: - using_opt_enable_cleartext_plugin= TRUE; - break; case OPT_TEE: if (argument == disabled_my_option) { @@ -4330,10 +4321,6 @@ sql_real_connect(char *host,char *database,char *user,char *password, if (opt_default_auth && *opt_default_auth) mysql_options(&mysql, MYSQL_DEFAULT_AUTH, opt_default_auth); - if (using_opt_enable_cleartext_plugin) - mysql_options(&mysql, MYSQL_ENABLE_CLEARTEXT_PLUGIN, - (char*) &opt_enable_cleartext_plugin); - if (!mysql_real_connect(&mysql, host, user, password, database, opt_mysql_port, opt_mysql_unix_port, connect_flag | CLIENT_MULTI_STATEMENTS)) diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc index 321efd36642..3f33c25e664 100644 --- a/client/mysqladmin.cc +++ b/client/mysqladmin.cc @@ -43,8 +43,6 @@ static uint opt_count_iterations= 0, my_end_arg; static ulong opt_connect_timeout, opt_shutdown_timeout; static char * unix_port=0; static char *opt_plugin_dir= 0, *opt_default_auth= 0; -static uint opt_enable_cleartext_plugin= 0; -static my_bool using_opt_enable_cleartext_plugin= 0; #ifdef HAVE_SMEM static char *shared_memory_base_name=0; @@ -214,10 +212,6 @@ static struct my_option my_long_options[] = "Default authentication client-side plugin to use.", &opt_default_auth, &opt_default_auth, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"enable_cleartext_plugin", OPT_ENABLE_CLEARTEXT_PLUGIN, - "Enable/disable the clear text authentication plugin.", - &opt_enable_cleartext_plugin, &opt_enable_cleartext_plugin, - 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0}, { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; @@ -288,9 +282,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib, opt->name); break; - case OPT_ENABLE_CLEARTEXT_PLUGIN: - using_opt_enable_cleartext_plugin= TRUE; - break; } if (error) { @@ -363,10 +354,6 @@ int main(int argc,char *argv[]) if (opt_default_auth && *opt_default_auth) mysql_options(&mysql, MYSQL_DEFAULT_AUTH, opt_default_auth); - if (using_opt_enable_cleartext_plugin) - mysql_options(&mysql, MYSQL_ENABLE_CLEARTEXT_PLUGIN, - (char*) &opt_enable_cleartext_plugin); - if (sql_connect(&mysql, option_wait)) { /* diff --git a/client/mysqlslap.c b/client/mysqlslap.c index ac1cc31733c..a2c01b85b5a 100644 --- a/client/mysqlslap.c +++ b/client/mysqlslap.c @@ -125,8 +125,6 @@ static char *host= NULL, *opt_password= NULL, *user= NULL, *post_system= NULL, *opt_mysql_unix_port= NULL; static char *opt_plugin_dir= 0, *opt_default_auth= 0; -static uint opt_enable_cleartext_plugin= 0; -static my_bool using_opt_enable_cleartext_plugin= 0; const char *delimiter= "\n"; @@ -350,9 +348,6 @@ int main(int argc, char **argv) if (opt_default_auth && *opt_default_auth) mysql_options(&mysql, MYSQL_DEFAULT_AUTH, opt_default_auth); - if (using_opt_enable_cleartext_plugin) - mysql_options(&mysql, MYSQL_ENABLE_CLEARTEXT_PLUGIN, - (char*) &opt_enable_cleartext_plugin); if (!opt_only_print) { if (!(mysql_real_connect(&mysql, host, user, opt_password, @@ -608,10 +603,6 @@ static struct my_option my_long_options[] = "Detach (close and reopen) connections after X number of requests.", &detach_rate, &detach_rate, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, - {"enable_cleartext_plugin", OPT_ENABLE_CLEARTEXT_PLUGIN, - "Enable/disable the clear text authentication plugin.", - &opt_enable_cleartext_plugin, &opt_enable_cleartext_plugin, - 0, GET_BOOL, OPT_ARG, 0, 0, 0, 0, 0, 0}, {"engine", 'e', "Storage engine to use for creating the table.", &default_engine, &default_engine, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, @@ -770,9 +761,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), case 'I': /* Info */ usage(); exit(0); - case OPT_ENABLE_CLEARTEXT_PLUGIN: - using_opt_enable_cleartext_plugin= TRUE; - break; } DBUG_RETURN(0); } diff --git a/client/mysqltest.cc b/client/mysqltest.cc index 34d8edcbe0b..b1784fdc7b6 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -5456,7 +5456,7 @@ void do_connect(struct st_command *command) int con_port= opt_port; char *con_options; my_bool con_ssl= 0, con_compress= 0; - my_bool con_pipe= 0, con_shm= 0, con_cleartext_enable= 0; + my_bool con_pipe= 0, con_shm= 0; struct st_connection* con_slot; static DYNAMIC_STRING ds_connection_name; @@ -5546,8 +5546,6 @@ void do_connect(struct st_command *command) con_pipe= 1; else if (!strncmp(con_options, "SHM", 3)) con_shm= 1; - else if (!strncmp(con_options, "CLEARTEXT", 9)) - con_cleartext_enable= 1; else die("Illegal option to connect: %.*s", (int) (end - con_options), con_options); @@ -5644,10 +5642,6 @@ void do_connect(struct st_command *command) if (ds_default_auth.length) mysql_options(&con_slot->mysql, MYSQL_DEFAULT_AUTH, ds_default_auth.str); - - if (con_cleartext_enable) - mysql_options(&con_slot->mysql, MYSQL_ENABLE_CLEARTEXT_PLUGIN, - (char*) &con_cleartext_enable); /* Special database to allow one to connect without a database name */ if (ds_database.length && !strcmp(ds_database.str,"*NO-ONE*")) dynstr_set(&ds_database, ""); diff --git a/include/mysql.h b/include/mysql.h index 0ed35413a1c..cff8c647152 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -166,8 +166,7 @@ enum mysql_option MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, - MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH, - MYSQL_ENABLE_CLEARTEXT_PLUGIN + MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH }; /** diff --git a/include/mysql.h.pp b/include/mysql.h.pp index c2c5ba35044..15ec563dfc2 100644 --- a/include/mysql.h.pp +++ b/include/mysql.h.pp @@ -262,8 +262,7 @@ enum mysql_option MYSQL_OPT_USE_REMOTE_CONNECTION, MYSQL_OPT_USE_EMBEDDED_CONNECTION, MYSQL_OPT_GUESS_CONNECTION, MYSQL_SET_CLIENT_IP, MYSQL_SECURE_AUTH, MYSQL_REPORT_DATA_TRUNCATION, MYSQL_OPT_RECONNECT, - MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH, - MYSQL_ENABLE_CLEARTEXT_PLUGIN + MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_PLUGIN_DIR, MYSQL_DEFAULT_AUTH }; struct st_mysql_options_extention; struct st_mysql_options { diff --git a/include/sql_common.h b/include/sql_common.h index a2ea3ac45e7..307b443d6d6 100644 --- a/include/sql_common.h +++ b/include/sql_common.h @@ -31,7 +31,6 @@ extern const char *not_error_sqlstate; struct st_mysql_options_extention { char *plugin_dir; char *default_auth; - my_bool enable_cleartext_plugin; }; typedef struct st_mysql_methods @@ -105,7 +104,6 @@ int mysql_client_plugin_init(); void mysql_client_plugin_deinit(); struct st_mysql_client_plugin; extern struct st_mysql_client_plugin *mysql_client_builtins[]; -extern my_bool libmysql_cleartext_plugin_enabled; #ifdef __cplusplus } diff --git a/mysql-test/t/plugin_auth.test b/mysql-test/t/plugin_auth.test index 75d3ef3e807..f169360cf2e 100644 --- a/mysql-test/t/plugin_auth.test +++ b/mysql-test/t/plugin_auth.test @@ -422,10 +422,10 @@ CREATE USER uplain@localhost IDENTIFIED WITH 'cleartext_plugin_server' --echo ## test plugin auth --disable_query_log --error ER_ACCESS_DENIED_ERROR : this should fail : no grant -connect(cleartext_fail_con,localhost,uplain,cleartext_test2,,,,CLEARTEXT); +connect(cleartext_fail_con,localhost,uplain,cleartext_test2); --enable_query_log -connect(cleartext_con,localhost,uplain,cleartext_test,,,,CLEARTEXT); +connect(cleartext_con,localhost,uplain,cleartext_test); connection cleartext_con; select USER(),CURRENT_USER(); diff --git a/sql-common/client.c b/sql-common/client.c index ef1e3c1b7d4..16beb27978e 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -1136,8 +1136,7 @@ static const char *default_options[]= "connect-timeout", "local-infile", "disable-local-infile", "ssl-cipher", "max-allowed-packet", "protocol", "shared-memory-base-name", "multi-results", "multi-statements", "multi-queries", "secure-auth", - "report-data-truncation", "plugin-dir", "default-auth", - "enable-cleartext-plugin", + "report-data-truncation", "plugin-dir", "default-auth", NullS }; enum option_id { @@ -1149,7 +1148,6 @@ enum option_id { OPT_ssl_cipher, OPT_max_allowed_packet, OPT_protocol, OPT_shared_memory_base_name, OPT_multi_results, OPT_multi_statements, OPT_multi_queries, OPT_secure_auth, OPT_report_data_truncation, OPT_plugin_dir, OPT_default_auth, - OPT_enable_cleartext_plugin, OPT_keep_this_one_last }; @@ -1182,27 +1180,14 @@ static int add_init_command(struct st_mysql_options *options, const char *cmd) return 0; } -#define ALLOCATE_EXTENSIONS(OPTS) \ +#define EXTENSION_SET_STRING(OPTS, X, STR) \ + if ((OPTS)->extension) \ + my_free((OPTS)->extension->X); \ + else \ (OPTS)->extension= (struct st_mysql_options_extention *) \ my_malloc(sizeof(struct st_mysql_options_extention), \ - MYF(MY_WME | MY_ZEROFILL)) \ - -#define ENSURE_EXTENSIONS_PRESENT(OPTS) \ - do { \ - if (!(OPTS)->extension) \ - ALLOCATE_EXTENSIONS(OPTS); \ - } while (0) - - -#define EXTENSION_SET_STRING(OPTS, X, STR) \ - do { \ - if ((OPTS)->extension) \ - my_free((OPTS)->extension->X); \ - else \ - ALLOCATE_EXTENSIONS(OPTS); \ - (OPTS)->extension->X= ((STR) != NULL) ? \ - my_strdup((STR), MYF(MY_WME)) : NULL; \ - } while (0) + MYF(MY_WME | MY_ZEROFILL)); \ + (OPTS)->extension->X= my_strdup((STR), MYF(MY_WME)); void mysql_read_default_options(struct st_mysql_options *options, const char *filename,const char *group) @@ -1401,13 +1386,6 @@ void mysql_read_default_options(struct st_mysql_options *options, case OPT_default_auth: EXTENSION_SET_STRING(options, default_auth, opt_arg); break; - - case OPT_enable_cleartext_plugin: - ENSURE_EXTENSIONS_PRESENT(options); - options->extension->enable_cleartext_plugin= - (!opt_arg || atoi(opt_arg) != 0) ? TRUE : FALSE; - break; - default: DBUG_PRINT("warning",("unknown option: %s",option[0])); } @@ -2804,27 +2782,6 @@ static void client_mpvio_info(MYSQL_PLUGIN_VIO *vio, mpvio_info(mpvio->mysql->net.vio, info); } - -my_bool libmysql_cleartext_plugin_enabled= 0; - -static my_bool check_plugin_enabled(MYSQL *mysql, auth_plugin_t *plugin) -{ - if (plugin == &clear_password_client_plugin && - (!libmysql_cleartext_plugin_enabled && - (!mysql->options.extension || - !mysql->options.extension->enable_cleartext_plugin))) - { - set_mysql_extended_error(mysql, CR_AUTH_PLUGIN_CANNOT_LOAD, - unknown_sqlstate, - ER(CR_AUTH_PLUGIN_CANNOT_LOAD), - clear_password_client_plugin.name, - "plugin not enabled"); - return TRUE; - } - return FALSE; -} - - /** Client side of the plugin driver authentication. @@ -2867,9 +2824,6 @@ int run_plugin_auth(MYSQL *mysql, char *data, uint data_len, auth_plugin_name= auth_plugin->name; } - if (check_plugin_enabled(mysql, auth_plugin)) - DBUG_RETURN(1); - DBUG_PRINT ("info", ("using plugin %s", auth_plugin_name)); mysql->net.last_errno= 0; /* just in case */ @@ -2961,9 +2915,6 @@ int run_plugin_auth(MYSQL *mysql, char *data, uint data_len, auth_plugin_name, MYSQL_CLIENT_AUTHENTICATION_PLUGIN))) DBUG_RETURN (1); - if (check_plugin_enabled(mysql, auth_plugin)) - DBUG_RETURN(1); - mpvio.plugin= auth_plugin; res= auth_plugin->authenticate_user((struct st_plugin_vio *)&mpvio, mysql); @@ -4172,11 +4123,6 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg) case MYSQL_DEFAULT_AUTH: EXTENSION_SET_STRING(&mysql->options, default_auth, arg); break; - case MYSQL_ENABLE_CLEARTEXT_PLUGIN: - ENSURE_EXTENSIONS_PRESENT(&mysql->options); - mysql->options.extension->enable_cleartext_plugin= - (*(my_bool*) arg) ? TRUE : FALSE; - break; default: DBUG_RETURN(1); } @@ -4396,3 +4342,5 @@ static int clear_password_auth_client(MYSQL_PLUGIN_VIO *vio, MYSQL *mysql) return res ? CR_ERROR : CR_OK; } + + diff --git a/sql-common/client_plugin.c b/sql-common/client_plugin.c index 75faeb7ee97..4016f0744be 100644 --- a/sql-common/client_plugin.c +++ b/sql-common/client_plugin.c @@ -197,10 +197,6 @@ err1: static void load_env_plugins(MYSQL *mysql) { char *plugs, *free_env, *s= getenv("LIBMYSQL_PLUGINS"); - char *enable_cleartext_plugin= getenv("LIBMYSQL_ENABLE_CLEARTEXT_PLUGIN"); - - if (enable_cleartext_plugin && strchr("1Yy", enable_cleartext_plugin[0])) - libmysql_cleartext_plugin_enabled= 1; /* no plugins to load */ if(!s) @@ -216,7 +212,6 @@ static void load_env_plugins(MYSQL *mysql) } while (s); my_free(free_env); - } /********** extern functions to be used by libmysql *********************/