From 209682e051977c5cca6af380f6ff202296c3984b Mon Sep 17 00:00:00 2001 From: "svoj@april.(none)" <> Date: Thu, 6 Apr 2006 15:19:01 +0500 Subject: [PATCH 1/8] Fix for bug#14945 "Truncate table doesn't reset the auto_increment counter". When TRUNCATE TABLE was called within an stored procedure the auto_increment counter was not reset to 0 even if straight TRUNCATE for this table did this. This fix makes TRUNCATE in stored procedures to be handled exactly in the same way as straight TRUNCATE. We achieve this by rolling back the fix for bug 8850, which is no longer needed since stored procedures don't require prelocked mode anymore (and TRUNCATE is not allowed in stored functions or triggers). --- mysql-test/r/sp.result | 11 +++++++++++ mysql-test/t/sp.test | 15 +++++++++++++++ sql/sql_delete.cc | 3 +-- sql/sql_parse.cc | 2 +- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/sp.result b/mysql-test/r/sp.result index 3e139f8cce5..dadcab76947 100644 --- a/mysql-test/r/sp.result +++ b/mysql-test/r/sp.result @@ -4811,6 +4811,17 @@ begin declare x int; select id from t1 order by x; end| +drop procedure if exists bug14945| +create table t3 (id int not null auto_increment primary key)| +create procedure bug14945() deterministic truncate t3| +insert into t3 values (null)| +call bug14945()| +insert into t3 values (null)| +select * from t3| +id +1 +drop table t3| +drop procedure bug14945| create procedure bug16474_2(x int) select id from t1 order by x| call bug16474_1()| diff --git a/mysql-test/t/sp.test b/mysql-test/t/sp.test index 9e1afa53149..1658e06d518 100644 --- a/mysql-test/t/sp.test +++ b/mysql-test/t/sp.test @@ -5666,6 +5666,21 @@ begin select id from t1 order by x; end| +# +# BUG#14945: Truncate table doesn't reset the auto_increment counter +# +--disable_warnings +drop procedure if exists bug14945| +--enable_warnings +create table t3 (id int not null auto_increment primary key)| +create procedure bug14945() deterministic truncate t3| +insert into t3 values (null)| +call bug14945()| +insert into t3 values (null)| +select * from t3| +drop table t3| +drop procedure bug14945| + # This does NOT order by column index; variable is an expression. create procedure bug16474_2(x int) select id from t1 order by x| diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 56dbd423b69..37c4f9a3256 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -842,8 +842,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) table_list->db, table_list->table_name); DBUG_RETURN(TRUE); } - if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE) - || thd->lex->sphead) + if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE)) goto trunc_by_del; if (lock_and_wait_for_table_name(thd, table_list)) DBUG_RETURN(TRUE); diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index f9d04fc873e..2f589f48c57 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -3350,7 +3350,7 @@ end_with_restore_list: Don't allow this within a transaction because we want to use re-generate table */ - if ((thd->locked_tables && !lex->sphead) || thd->active_transaction()) + if (thd->locked_tables || thd->active_transaction()) { my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); From 84bfed689ddf4a94661d812b91f958f5d4d6085d Mon Sep 17 00:00:00 2001 From: "igreenhoe@mysql.com" <> Date: Thu, 6 Apr 2006 10:13:46 -0700 Subject: [PATCH 2/8] Fix for Bug #16240 --- support-files/mysql.server.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/support-files/mysql.server.sh b/support-files/mysql.server.sh index 1892e8b4a46..bf17375c0eb 100644 --- a/support-files/mysql.server.sh +++ b/support-files/mysql.server.sh @@ -72,6 +72,10 @@ else libexecdir="$basedir/libexec" fi +# datadir_set is used to determine if datadir was set (and so should be +# *not* set inside of the --basedir= handler.) +datadir_set= + # # Use LSB init script functions for printing messages, if possible # @@ -105,11 +109,15 @@ parse_server_arguments() { case "$arg" in --basedir=*) basedir=`echo "$arg" | sed -e 's/^[^=]*=//'` bindir="$basedir/bin" - datadir="$basedir/data" + if test -z "$datadir_set"; then + datadir="$basedir/data" + fi sbindir="$basedir/sbin" libexecdir="$basedir/libexec" ;; - --datadir=*) datadir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;; + --datadir=*) datadir=`echo "$arg" | sed -e 's/^[^=]*=//'` + datadir_set=1 + ;; --user=*) user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;; --pid-file=*) server_pid_file=`echo "$arg" | sed -e 's/^[^=]*=//'` ;; --use-mysqld_safe) use_mysqld_safe=1;; From be0ebd9e0ac682418243c6b457b132e16d6d8cca Mon Sep 17 00:00:00 2001 From: "sergefp@mysql.com" <> Date: Thu, 6 Apr 2006 21:42:03 +0400 Subject: [PATCH 3/8] Remove redundant code in opt_sum_query() --- sql/opt_sum.cc | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc index 8a5a5875d47..373753a7b80 100644 --- a/sql/opt_sum.cc +++ b/sql/opt_sum.cc @@ -123,8 +123,11 @@ int opt_sum_query(TABLE_LIST *tables, List &all_fields,COND *conds) If the storage manager of 'tl' gives exact row count, compute the total number of rows. If there are no outer table dependencies, this count may be used as the real count. + Schema tables are filled after this function is invoked, so we can't + get row count */ - if (tl->table->file->table_flags() & HA_NOT_EXACT_COUNT) + if ((tl->table->file->table_flags() & HA_NOT_EXACT_COUNT) || + tl->schema_table) { is_exact_count= FALSE; count= 1; // ensure count != 0 @@ -149,31 +152,15 @@ int opt_sum_query(TABLE_LIST *tables, List &all_fields,COND *conds) switch (item_sum->sum_func()) { case Item_sum::COUNT_FUNC: /* - If the expr in count(expr) can never be null we can change this + If the expr in COUNT(expr) can never be null we can change this to the number of rows in the tables if this number is exact and there are no outer joins. */ if (!conds && !((Item_sum_count*) item)->args[0]->maybe_null && !outer_tables && is_exact_count) { - longlong count= 1; - TABLE_LIST *table; - for (table= tables; table; table= table->next_leaf) - { - if (outer_tables || (table->table->file->table_flags() & - HA_NOT_EXACT_COUNT) || table->schema_table) - { - const_result= 0; // Can't optimize left join - break; - } - tables->table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK); - count*= table->table->file->records; - } - if (!table) - { - ((Item_sum_count*) item)->make_const(count); - recalc_const_item= 1; - } + ((Item_sum_count*) item)->make_const(count); + recalc_const_item= 1; } else const_result= 0; From fe7ea20764eb12b2f147158f1ef0ef2a535cd4f5 Mon Sep 17 00:00:00 2001 From: "gluh@eagle.intranet.mysql.r18.ru" <> Date: Fri, 7 Apr 2006 12:32:24 +0500 Subject: [PATCH 4/8] Bug#18469 make test fails on information_schema move test case for bug 14290 to ctype_ucs test --- mysql-test/r/ctype_ucs.result | 8 ++++++++ mysql-test/r/information_schema.result | 8 -------- mysql-test/t/ctype_ucs.test | 8 ++++++++ mysql-test/t/information_schema.test | 9 --------- 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/mysql-test/r/ctype_ucs.result b/mysql-test/r/ctype_ucs.result index d11d25f9b35..6182bd0f598 100644 --- a/mysql-test/r/ctype_ucs.result +++ b/mysql-test/r/ctype_ucs.result @@ -719,3 +719,11 @@ lily river drop table t1; deallocate prepare stmt; +create table t1(a blob, b text charset utf8, c text charset ucs2); +select data_type, character_octet_length, character_maximum_length +from information_schema.columns where table_name='t1'; +data_type character_octet_length character_maximum_length +blob 65535 65535 +text 65535 65535 +text 65535 32767 +drop table t1; diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index 770d9265830..d5fb046d319 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -1041,14 +1041,6 @@ select 1 from (select 1 from test.t1) a; 1 use test; drop table t1; -create table t1(a blob, b text charset utf8, c text charset ucs2); -select data_type, character_octet_length, character_maximum_length -from information_schema.columns where table_name='t1'; -data_type character_octet_length character_maximum_length -blob 65535 65535 -text 65535 65535 -text 65535 32767 -drop table t1; create table t1 (f1 int(11)); create view v1 as select * from t1; drop table t1; diff --git a/mysql-test/t/ctype_ucs.test b/mysql-test/t/ctype_ucs.test index d4ea8dd57ad..af46b9c385a 100644 --- a/mysql-test/t/ctype_ucs.test +++ b/mysql-test/t/ctype_ucs.test @@ -455,3 +455,11 @@ execute stmt using @param1; select utext from t1 where utext like '%%'; drop table t1; deallocate prepare stmt; + +# +# Bug #14290: character_maximum_length for text fields +# +create table t1(a blob, b text charset utf8, c text charset ucs2); +select data_type, character_octet_length, character_maximum_length + from information_schema.columns where table_name='t1'; +drop table t1; diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index 6957dcf3b6a..47f262a9d59 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -738,15 +738,6 @@ select 1 from (select 1 from test.t1) a; use test; drop table t1; -# -# Bug #14290: character_maximum_length for text fields -# - -create table t1(a blob, b text charset utf8, c text charset ucs2); -select data_type, character_octet_length, character_maximum_length - from information_schema.columns where table_name='t1'; -drop table t1; - # # Bug#14476 `information_schema`.`TABLES`.`TABLE_TYPE` with empty value # From 4ef7e5b5f73df1ad40956cdef0a2c119aa7000d6 Mon Sep 17 00:00:00 2001 From: "gluh@eagle.intranet.mysql.r18.ru" <> Date: Fri, 7 Apr 2006 13:19:31 +0500 Subject: [PATCH 5/8] Fix for bug#18281 group_concat changes charset to binary skip charset aggregation for order columns --- mysql-test/r/func_gconcat.result | 5 +++++ mysql-test/t/func_gconcat.test | 8 ++++++++ sql/item_sum.cc | 5 ++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/func_gconcat.result b/mysql-test/r/func_gconcat.result index f1c9f8b9f76..7889f8953f4 100644 --- a/mysql-test/r/func_gconcat.result +++ b/mysql-test/r/func_gconcat.result @@ -626,3 +626,8 @@ latin1 latin1 drop table t1, t2, t3; set names default; +create table t1 (c1 varchar(10), c2 int); +select charset(group_concat(c1 order by c2)) from t1; +charset(group_concat(c1 order by c2)) +latin1 +drop table t1; diff --git a/mysql-test/t/func_gconcat.test b/mysql-test/t/func_gconcat.test index 1b88ed90fa3..aa28c9d5f52 100644 --- a/mysql-test/t/func_gconcat.test +++ b/mysql-test/t/func_gconcat.test @@ -414,3 +414,11 @@ select charset(a) from t2; select charset(a) from t3; drop table t1, t2, t3; set names default; + +# +# Bug#18281 group_concat changes charset to binary +# +create table t1 (c1 varchar(10), c2 int); +select charset(group_concat(c1 order by c2)) from t1; +drop table t1; + diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 1cd1741cea6..8826144266e 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -3226,7 +3226,10 @@ Item_func_group_concat::fix_fields(THD *thd, Item **ref) } if (agg_item_charsets(collation, func_name(), - args, arg_count, MY_COLL_ALLOW_CONV)) + args, + /* skip charset aggregation for order columns */ + arg_count - arg_count_order, + MY_COLL_ALLOW_CONV)) return 1; result.set_charset(collation.collation); From 7ed2c6207af421ef24973e9219a43e737308aa62 Mon Sep 17 00:00:00 2001 From: "hartmut@mysql.com" <> Date: Fri, 7 Apr 2006 11:15:15 +0200 Subject: [PATCH 6/8] fix for wrong QUARTER calculation in EXTRACT() (Bug #18100) --- mysql-test/r/func_time.result | 36 +++++++++++++++++++++++++++++++++++ mysql-test/t/func_time.test | 18 ++++++++++++++++++ sql/item_timefunc.cc | 2 +- 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index 64dafa132b4..5d40a0ed01f 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -360,6 +360,42 @@ extract(SECOND FROM "1999-01-02 10:11:12") select extract(MONTH FROM "2001-02-00"); extract(MONTH FROM "2001-02-00") 2 +SELECT EXTRACT(QUARTER FROM '2004-01-15') AS quarter; +quarter +1 +SELECT EXTRACT(QUARTER FROM '2004-02-15') AS quarter; +quarter +1 +SELECT EXTRACT(QUARTER FROM '2004-03-15') AS quarter; +quarter +1 +SELECT EXTRACT(QUARTER FROM '2004-04-15') AS quarter; +quarter +2 +SELECT EXTRACT(QUARTER FROM '2004-05-15') AS quarter; +quarter +2 +SELECT EXTRACT(QUARTER FROM '2004-06-15') AS quarter; +quarter +2 +SELECT EXTRACT(QUARTER FROM '2004-07-15') AS quarter; +quarter +3 +SELECT EXTRACT(QUARTER FROM '2004-08-15') AS quarter; +quarter +3 +SELECT EXTRACT(QUARTER FROM '2004-09-15') AS quarter; +quarter +3 +SELECT EXTRACT(QUARTER FROM '2004-10-15') AS quarter; +quarter +4 +SELECT EXTRACT(QUARTER FROM '2004-11-15') AS quarter; +quarter +4 +SELECT EXTRACT(QUARTER FROM '2004-12-15') AS quarter; +quarter +4 SELECT "1900-01-01 00:00:00" + INTERVAL 2147483648 SECOND; "1900-01-01 00:00:00" + INTERVAL 2147483648 SECOND 1968-01-20 03:14:08 diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index 3a2eea59bed..c98c1c94609 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -139,6 +139,24 @@ select extract(MINUTE_SECOND FROM "10:11:12"); select extract(SECOND FROM "1999-01-02 10:11:12"); select extract(MONTH FROM "2001-02-00"); +# +# test EXTRACT QUARTER (Bug #18100) +# + +SELECT EXTRACT(QUARTER FROM '2004-01-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-02-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-03-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-04-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-05-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-06-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-07-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-08-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-09-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-10-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-11-15') AS quarter; +SELECT EXTRACT(QUARTER FROM '2004-12-15') AS quarter; + + # # Test big intervals (Bug #3498) # diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index 63a7f1f130b..e139eba385e 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2213,7 +2213,7 @@ longlong Item_extract::val_int() switch (int_type) { case INTERVAL_YEAR: return ltime.year; case INTERVAL_YEAR_MONTH: return ltime.year*100L+ltime.month; - case INTERVAL_QUARTER: return ltime.month/3 + 1; + case INTERVAL_QUARTER: return (ltime.month+2)/3; case INTERVAL_MONTH: return ltime.month; case INTERVAL_WEEK: { From 7cd90d0081e8acdc9fd36f5536d06289e35cb19e Mon Sep 17 00:00:00 2001 From: "jonas@perch.ndb.mysql.com" <> Date: Fri, 7 Apr 2006 15:48:13 +0200 Subject: [PATCH 7/8] ndb - bug#11033 silent valgrind warnings 5.0, ndb_autodiscover --- ndb/src/ndbapi/NdbDictionaryImpl.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ndb/src/ndbapi/NdbDictionaryImpl.cpp b/ndb/src/ndbapi/NdbDictionaryImpl.cpp index da344dc6164..f7a28eb989c 100644 --- a/ndb/src/ndbapi/NdbDictionaryImpl.cpp +++ b/ndb/src/ndbapi/NdbDictionaryImpl.cpp @@ -1109,9 +1109,14 @@ NdbDictInterface::getTable(const BaseString& name, bool fullyQualifiedNames) // Copy name to m_buffer to get a word sized buffer m_buffer.clear(); - m_buffer.grow(namelen_words*4); + m_buffer.grow(namelen_words*4+4); m_buffer.append(name.c_str(), namelen); +#ifndef IGNORE_VALGRIND_WARNINGS + Uint32 pad = 0; + m_buffer.append(&pad, 4); +#endif + LinearSectionPtr ptr[1]; ptr[0].p= (Uint32*)m_buffer.get_data(); ptr[0].sz= namelen_words; From 739b0d676b7a7ff939aa4e667d0a146a5f0d6b2b Mon Sep 17 00:00:00 2001 From: "jonas@perch.ndb.mysql.com" <> Date: Fri, 7 Apr 2006 17:10:56 +0200 Subject: [PATCH 8/8] ndb - bug#11034 fix mem leak (not during running of transactions, but a few bytes when shutting down) --- ndb/src/ndbapi/NdbLinHash.hpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ndb/src/ndbapi/NdbLinHash.hpp b/ndb/src/ndbapi/NdbLinHash.hpp index 05670534c95..0655e81ce9d 100644 --- a/ndb/src/ndbapi/NdbLinHash.hpp +++ b/ndb/src/ndbapi/NdbLinHash.hpp @@ -427,19 +427,26 @@ NdbLinHash::getNext(NdbElement_t * curr){ return curr->next; int dir = 0, seg = 0; - - if(curr != 0){ + int counts; + if(curr != 0) + { getBucket(curr->hash, &dir, &seg); + counts = seg + 1; + } + else + { + counts = 0; } for(int countd = dir; countd < DIRECTORYSIZE;countd++ ){ if (directory[countd] != 0) { - for(int counts = seg + 1; counts < SEGMENTSIZE; counts++ ){ + for(; counts < SEGMENTSIZE; counts++ ){ if (directory[countd]->elements[counts] != 0) { return directory[countd]->elements[counts]; } } } + counts = 0; } return 0;