Commit graph

18523 commits

Author SHA1 Message Date
Leonard Zhou
5fdc5510ec BUG#41719 delayed INSERT into timestamp col needs set time_zone for concurrent binlogging
When do 'insert delayed' operation, the time_zone info doesn't be keeped in the row info.
So when we do insert sometime later, time_zone didn't write into binlog.
This will cause wrong result for timestamp column in slave.

Our solution is that adding time_zone info with the delayed-row and
restoring time_zone from row-info when execute that row in the furture by another thread.
So we can write correct time_zone info into binlog and got correct result in slave.


mysql-test/r/rpl_timezone.result:
  Test result
mysql-test/t/rpl_timezone.test:
  Add test for bug#41719
sql/sql_insert.cc:
  Add time_zone info in the delayed-row and restore time_zone when execute the row in the furture by another thread.
2009-03-24 08:45:05 +08:00
Davi Arnaut
27e3214b49 Bug#43461: invalid comparison with string literal in default.c
Don't compare string literals as it results in unspecified behavior.

mysys/default.c:
  Test for a empty string.
2009-03-19 17:20:15 -03:00
Ignacio Galarza
e8c13e6a54 auto-merge 2009-03-19 09:58:56 -04:00
Ignacio Galarza
675c3ce2bb auto-merge 2009-03-19 09:44:58 -04:00
Staale Smedseng
28f4090bda Bug #42502 huge memory leak possible with timezone
functions
      
Unknown timezone specifications are properly rejected
by the server, but are copied into tz_storage before
rejection, and hence is retained until end of server 
life. With sufficiently large bogus timezone specs, 
it is easy to exhaust system memory.
      
Allocation of memory for a copy of the timezone
name is delayed until after verification of validity,
at the cost of a memcpy of the timezone info. This 
only happens once, future lookups will hit the cached
structure.
2009-03-19 11:27:45 +01:00
Sergey Glukhov
af016f72b9 Bug#41627 Illegal mix of collations in LEAST / GREATEST / CASE
Don't throw an error after checking the first and the second arguments.
Continue with checking the third and higher arguments and if some of
them is stronger according to coercibility rules,
then this argument's collation is set as result collation.


mysql-test/r/ctype_collate.result:
  test result
mysql-test/t/ctype_collate.test:
  test case
sql/item.cc:
  Don't throw an error after checking the first and the second arguments.
  Continue with checking the third and higher arguments and if some of
  them is stronger according to coercibility rules,
  then this argument's collation is set as result collation.
2009-03-19 12:20:28 +04:00
Georgi Kodinov
f35b4218ea Bug #22047 : Time in SHOW PROCESSLIST for SQL thread in replication
seems to become negative

THD::start_time has a dual meaning : it's either the time since the process
entered a given state or is the transaction time returned by e.g. NOW().
This causes problems, as sometimes THD::start_time may be set to a value
that is correct and needed when used as a base for NOW(), but these times
may be arbitrary (SET @@timestamp) or non-local (coming from the master 
through the replication feed).
If one such non-local time is set there's no way to return a correct value
for e.g. SHOW PROCESSLIST or SELECT ... FROM INFORMATION_SCHEMA.PROCESSLIST.
Fixed by making the Time column in SHOW PROCESSLIST SIGNED LONG instead of 
UNSIGNED LONG and doing the correct conversions.
      
Note that no reliable test suite can be constructed, since it would require
knowing the local time and can't be achieved by the means of the current test
suite.

sql/sql_show.cc:
  Bug #22047: make the Time in SHOW PROCESSLIST LONG from 
  LONG UNSIGNED
2009-03-13 15:51:25 +02:00
Georgi Kodinov
3033ea85a2 Bug #42434: license of mysys MD5 implementation is not GPL-compatible
Took the Xfree implementation (based on the same rewrite as the NDB one)
and added it instead of the current implementation.
Added a macro to make the calls to MD5 more streamlined. 

client/mysqlmanager-pwgen.c:
  Bug #42434: changed to call the macro
include/my_md5.h:
  Bug #42434: use the Xfree implementation
mysys/md5.c:
  Bug #42434: use the Xfree implementation
sql/item_strfunc.cc:
  Bug #42434: changed to call the macro
sql/table.cc:
  Bug #42434: changed to call the macro
tools/mysqlmanager.c:
  Bug #42434: changed to call the macro
2009-03-09 20:57:03 +02:00
Georgi Kodinov
d3d6f4fdad Bug #43354: Use key hint can crash server in explain extended query
The copy of the original arguments of a aggregate function was not
initialized until after fix_fields().
Sometimes (e.g. when there's an error processing the statement)
the print() can be called with no corresponding fix_fields() call.
      
Fixed by adding a check if the Item is fixed before using the arguments
copy.

mysql-test/r/explain.result:
  Bug #43354: test case
mysql-test/t/explain.test:
  Bug #43354: test case
sql/item_sum.cc:
  Bug #43354: use the argument list copy only if it's initialized
2009-03-11 14:10:44 +02:00
Georgi Kodinov
7541fec52d fixed a typo 2009-03-09 12:49:18 +02:00
Georgi Kodinov
56ae3bd155 fixed a win32 compile warning 2009-03-09 12:22:52 +02:00
Kristofer Pettersson
55c779cdbf Manual merge 2009-03-06 11:49:39 +01:00
Kristofer Pettersson
ac821c6570 Bug#40363 Bug 20023 is not fixed on 5.0
This is a back port from 5.1 to 5.0.

Fix for BUG 20023: mysql_change_user() resets the value
of SQL_BIG_SELECTS.
  
The bug was that SQL_BIG_SELECTS was not properly set
in COM_CHANGE_USER.
  
The fix is to update SQL_BIG_SELECTS properly.



sql/sql_class.cc:
  Update THD::options with the respect to SQL_BIG_SELECTS
  in COM_CHANGE_USER.
tests/mysql_client_test.c:
  Add a test case BUG#20023.
2009-03-05 13:37:46 +01:00
He Zhenxing
b4fdb8aec1 BUG#37051 Replication rules not evaluated correctly
Backporting patch to 5.0.
2009-03-05 18:10:44 +08:00
Timothy Smith
c3fec5d22f Applying InnoDB snashot 5.0-ss4007, part 2. Fixes
Bug #18828: If InnoDB runs out of undo slots, it returns misleading 'table is full'

This is a backport of code already in 5.1+.  The error message change referred
to in the detailed revision comments is still pending.

Detailed revision comments:

r3937 | calvin | 2009-01-15 03:11:56 +0200 (Thu, 15 Jan 2009) | 17 lines
branches/5.0:

Backport the fix for Bug#18828. Return DB_TOO_MANY_CONCURRENT_TRXS
when we run out of UNDO slots in the rollback segment. The backport
is requested by MySQL under bug#41529 - Safe handling of InnoDB running
out of undo log slots.

This is a partial fix since the MySQL error code requested to properly
report the error condition back to the client has not yet materialized.
Currently we have #ifdef'd the error code translation in ha_innodb.cc.
This will have to be changed as and when MySQl add the new requested
code or an equivalent code that we can then use.

Given the above, currently we will get the old behavior, not the
"fixed" and intended behavior.

Approved by:	Heikki (on IM)
2009-03-02 17:57:09 -07:00
Staale Smedseng
a2231e59c5 Commit after merge from 5.0-bugteam 2009-02-27 18:07:58 +02:00
Staale Smedseng
97b68934bc Recommit for merging and pushing 2009-02-27 16:11:15 +02:00
Georgi Kodinov
15760fe9d8 Bug #41610: key_infix_len can be overwritten causing some group by queries to
return no rows

The algorithm of determining the best key for loose index scan is doing a loop
over the available indexes and selects the one that has the best cost.
It retrieves the parameters of the current index into a set of variables.
If the cost of using the current index is lower than the best cost so far it 
copies these variables into another set of variables that contain the 
information for the best index so far.
After having checked all the indexes it uses these variables (outside of the 
index loop) to create the table read plan object instance.
The was a single omission : the key_infix/key_infix_len variables were used 
outside of the loop without being preserved in the loop for the best index 
so far.
This causes these variables to get overwritten by the next index(es) checked.
Fixed by adding variables to hold the data for the current index, passing 
the new variables to the function that assigns values to them and copying 
the new variables into the existing ones when selecting a new current best 
index.
To avoid further such problems moved the declarations of the variables used 
to keep information about the current index inside the loop's compound 
statement.

mysql-test/r/group_min_max.result:
  Bug #41610: test case
mysql-test/t/group_min_max.test:
  Bug #41610: test case
sql/opt_range.cc:
  Bug #41610: copy the infix data for the current best index
2009-02-27 15:25:06 +02:00
Georgi Kodinov
a9d707037a Bug #41354: Access control is bypassed when all columns
of a view are selected by * wildcard

Backported a part of the fix for 36086 to 5.0

mysql-test/r/view_grant.result:
  Bug #41354: test case
mysql-test/t/view_grant.test:
  Bug #41354: test case
sql/sql_acl.cc:
  Bug #41354: return table error when no access and *
sql/sql_base.cc:
  Bug #41354: backported the check in bug 36086 to 5.0
2009-02-26 19:00:44 +02:00
Ramil Kalimullin
c9e1884cd6 Fix for bug#19829:make test Failed in mysql_client_test
*with --with-charset=utf8*

Problem: wrong LONG TEXT field length is sent to a client 
when multibyte server character set used.

Fix: always limit field length sent to a client to 2^32,
as we store it in 4 byte slot.

Note: mysql_client_test changed accordingly.


sql/protocol.cc:
  Fix for bug#19829:make test Failed in mysql_client_test 
  *with --with-charset=utf8*
    - limit field length sent to client to UINT_MAX32 as 
      it may exceeds 32 bit slot for LONG TEXT fields if
      thd_charset->mbmaxlen > 1.
tests/mysql_client_test.c:
  Fix for bug#19829:make test Failed in mysql_client_test
  *with --with-charset=utf8*
    - checking field members have in mind that field length
      is limited to UINT_MAX32.
2009-02-26 12:34:15 +04:00
Sergey Glukhov
5d2fc53354 Bug#40345 MySQLDump prefixes view name with database name when view references other db
print compact view name if the view belongs to the current database


mysql-test/r/information_schema_db.result:
  result fix
mysql-test/r/mysqldump.result:
  result fix
mysql-test/r/view_grant.result:
  result fix
sql/sql_show.cc:
  print compact view name if the view belongs to the current database
2009-02-25 15:44:50 +04:00
Sergey Glukhov
2bc4ad4f1f Bug#30305 Create routine in wrong context in SHOW PRIVILEGES
Changed context of Create routine to Databases.


mysql-test/r/grant.result:
  result fix
mysql-test/r/sp.result:
  result fix
sql/sql_show.cc:
  Changed context of Create routine to Databases.
2009-02-25 14:20:20 +04:00
Ramil Kalimullin
bd414485de Fix for bug#42009: SELECT into variable gives different results to direct SELECT
Problem: storing "SELECT ... INTO @var ..." results in variables we used val_xxx()
methods which returned results of the current row. 
So, in some cases (e.g. SELECT DISTINCT, GROUP BY or HAVING) we got data
from the first row of a new group (where we evaluate a clause) instead of
data from the last row of the previous group.

Fix: use val_xxx_result() counterparts to get proper results.


mysql-test/r/distinct.result:
  Fix for bug#42009: SELECT into variable gives different results to direct SELECT
    - results adjusted.
mysql-test/r/user_var.result:
  Fix for bug#42009: SELECT into variable gives different results to direct SELECT
    - test result.
mysql-test/t/user_var.test:
  Fix for bug#42009: SELECT into variable gives different results to direct SELECT
    - test case.
sql/item_func.cc:
  Fix for bug#42009: SELECT into variable gives different results to direct SELECT
    - Item_func_set_user_var::save_item_result() added to evaluate and store 
      an item's result into a user variable.
sql/item_func.h:
  Fix for bug#42009: SELECT into variable gives different results to direct SELECT
    - Item_func_set_user_var::save_item_result() added to evaluate and store 
      an item's result into a user variable.
sql/sql_class.cc:
  Fix for bug#42009: SELECT into variable gives different results to direct SELECT
    - use Item_func_set_user_var::save_item_result() to store results into user 
      variables.
2009-02-24 18:47:12 +04:00
Andrei Elkin
a6ac350b3a merging from 5.0-bt rep to a local branch 2009-02-24 16:35:45 +02:00
Andrei Elkin
d091deaf89 fixing compilation warning and adding flush logs to test of bug#37313 2009-02-24 16:17:34 +02:00
Alexey Kopytov
315748a41d Automerge. 2009-02-25 10:48:05 +02:00
Alexey Kopytov
0f6e7f1176 Fixed a build failure on Ubuntu 8.10 introduced by the patch
for bug #15936.

On some platforms fenv.h may #undef the min/max macros
defined in my_global.h.

Fixed by moving the #include directive for fenv.h from
mysqld.cc to my_global.h before definitions for min/max.

include/my_global.h:
  Moved #include <fenv.h> from mysqld.cc.
sql/mysqld.cc:
  Moved #include <fenv.h> to my_global.h.
2009-02-25 10:36:11 +02:00
Alexey Botchkov
f94eafb262 merging. 2009-02-24 15:22:37 +04:00
Davi Arnaut
11b20f27af Bug#41110: crash with handler command when used concurrently with alter table
Bug#41112: crash in mysql_ha_close_table/get_lock_data with alter table

The problem is that the server wasn't handling robustly failures
to re-open a table during a HANDLER .. READ statement. If the
table needed to be re-opened due to it's storage engine being
altered to one that doesn't support HANDLER, a reference (dangling
pointer) to a closed table could be left in place and accessed in
later attempts to fetch from the table using the handler. Also,
if the server failed to set a error message if the re-open
failed. These problems could lead to server crashes or hangs.

The solution is to remove any references to a closed table and
to set a error if reopening a table during a HANDLER .. READ
statement fails.

There is no test case in this change set as the test depends on
a testing feature only available on 5.1 and later.

sql/sql_handler.cc:
  Remove redundant reopen check.
  Set errors even if reopening table.
  Reset TABLE_LIST::table reference when the table is closed.
2009-02-24 10:15:21 +01:00
Alexey Kopytov
d86c8af30e Automerge. 2009-02-23 14:53:51 +02:00
Alexey Kopytov
0e62c9aa63 Fix for bug #15936: "round" differs on Windows to Unix
Both of our own implementations of rint(3) were inconsistent with the
most common behavior of rint() on those platforms that have it: round
to nearest, break ties by rounding to nearest even.

Fixed by leaving just one implementation of rint() in our source tree,
and changing its behavior to match the most common native
implementations on other platforms.

configure.in:
  Added checks for fenv.h and fesetround().
include/config-win.h:
  Removed the incorrect implementation of rint() for Windows.
include/my_global.h:
  Added an rint() implementation for platforms that do not have it.
mysql-test/r/func_math.result:
  Added a test case for bug #15936.
mysql-test/t/func_math.test:
  Added a test case for bug #15936.
sql/mysqld.cc:
  Explicitly set the FPU rounding mode with fesetround().
2009-02-23 14:28:26 +02:00
Andrei Elkin
4712e6b9b8 Bug #37313 BINLOG Contains Incorrect server id
Signed integer format specifier forced to print the binlog header with server_id
negative if the unsigned value sets the sign-bit ON.
  
Fixed with correcting the specifier to correspond to typeof(server_id) == ulong.

mysql-test/r/mysqlbinlog.result:
  results changed.
mysql-test/t/mysqlbinlog.test:
  displaying the expected unsignedly formatted server_id value, bug#37313.
sql/log_event.cc:
  Format specifier is corrected to correspond to typeof(server_id).
2009-02-20 13:55:43 +02:00
Georgi Kodinov
c1ddc60c69 fixed a warning 2009-02-20 11:42:35 +02:00
Georgi Kodinov
cf42f6689f merged bug 42419 to 5.0-bugteam 2009-02-19 18:26:19 +02:00
Georgi Kodinov
29476d879f Bug #42419: Server crash with "Pure virtual method called" on two concurrent
connections
The problem is that tables can enter open table cache for a thread without 
being properly cleaned up. This can happen if make_join_statistics() fails 
to read a const table because of e.g. a deadlock. It does set a member of 
TABLE structure to a value it allocates, but doesn't clean-up this setting 
on error nor does it set the rest of the members in JOIN to allow for 
automatic cleanup.
As a result when such an error occurs and the next statement depends re-uses 
the table from the open tables cache it will get it with this 
TABLE::reginfo.join_tab pointing to a memory area that's freed.
Fixed by making sure make_join_statistics() cleans up TABLE::reginfo.join_tab 
on error.

mysql-test/r/innodb_mysql.result:
  Bug #42419: test case
mysql-test/t/innodb_mysql-master.opt:
  Bug #42419: increase the timeout so it covers te conservative 
  sleep 3 in the test
mysql-test/t/innodb_mysql.test:
  Bug #42419: test case
sql/sql_select.cc:
  Bug #42419: clean up the members of TABLE on failure in 
          make_join_statisitcs()
2009-02-19 17:30:03 +02:00
Sergey Glukhov
c2e23208ef Bug#37601 Cast Is Not Done On Row Comparison
In case of ROW item each compared pair does not
check if argumet collations can be aggregated and
thus appropiriate item conversion does not happen.
The fix is to add the check and convertion for ROW
pairs.


mysql-test/r/row.result:
  test result
mysql-test/t/row.test:
  test case
sql/item.cc:
  added agg_item_set_converter() function which was a part of
  agg_item_charsets() func. The only difference is that
  agg_item_set_converter() checks and converts items 
  using already known collation.
sql/item.h:
  added agg_item_set_converter() function
sql/item_cmpfunc.cc:
  In case of ROW item each compared pair does not
  check if argumet collations can be aggregated and
  thus appropiriate item conversion does not happen.
  The fix is to add the check and convertion for ROW
  pairs.
2009-02-19 17:20:44 +04:00
Alexey Kopytov
0c96241b15 Automerge. 2009-02-19 12:02:11 +03:00
Alexey Kopytov
321646095d Fix for bug #41078: With CURSOR_TYPE_READ_ONLY mysql_stmt_fetch()
returns short string value. 
 
Multibyte character sets were not taken into account when 
calculating max_length in Item_param::convert_str_value(). As a 
result, string parameters of a prepared statement could be 
truncated later when calculating string length in characters by 
dividing length in bytes by the charset's mbmaxlen value (e.g. in 
Field_varstring::store()). 
 
Fixed by taking charset's mbmaxlen into account when calculating 
max_length in Item_param::convert_str_value().


sql/item.cc:
  Multiply string's length in characters by charset's mbmaxlen when 
  calculating max_length.
tests/mysql_client_test.c:
  Added a test case for bug #41078.
2009-02-19 11:49:35 +03:00
Sergey Glukhov
544fa7593b Bug#25830 SHOW TABLE STATUS behaves differently depending on table name(for 5.0 only)
replace wild_case_compare with my_wildcmp which is multibyte safe function


mysql-test/r/lowercase_utf8.result:
  test result
mysql-test/t/lowercase_utf8-master.opt:
  test case
mysql-test/t/lowercase_utf8.test:
  test case
sql/sql_show.cc:
  replace wild_case_compare with my_wildcmp which is multibyte safe function
2009-02-17 18:22:48 +04:00
Alexey Kopytov
fb3e5910ec Merge from dev tree. 2009-02-14 12:09:35 +03:00
Alexey Kopytov
9373b1b880 Merge from dev tree. 2009-02-13 19:17:07 +03:00
Georgi Kodinov
47c53135fd merged 5.0-bugteam to a working tree 2009-02-12 16:39:33 +02:00
Georgi Kodinov
1c5fa3b6a9 Bug #33813: Schema names are case-sensitive in DROP FUNCTION
Additional fix:
 1. Revert the unification of DROP FUNCTION
and DROP PROCEDURE, because DROP FUNCTION can be used to
drop UDFs (that have a non-qualified name and don't require
database name to be present and valid).
 2. Fixed the case sensitivity problem by adding a call to 
check_db_name() (similar to the sp_name production).
2009-02-12 16:36:43 +02:00
Sergey Vojtovich
5803e10628 BUG#36737 - having + full text operator crashes mysql
MATCH() function accepts column list as an argument. It was possible to override
this requirement with aliased non-column select expression. Which results in
server crash.

With this fix aliased non-column select expressions are not accepted by MATCH()
function, returning an error.

mysql-test/r/fulltext.result:
  A test case for BUG#36737.
mysql-test/t/fulltext.test:
  A test case for BUG#36737.
sql/item_func.cc:
  Only accept fields as arguments to MATCH().
2009-02-12 13:49:44 +04:00
Georgi Kodinov
7df0e72c7f merged bug 33813 to 5.0-bugteam 2009-02-12 11:27:06 +02:00
Ignacio Galarza
54fbbf9591 Bug#29125 Windows Server X64: so many compiler warnings
- Remove bothersome warning messages.  This change focuses on the warnings 
that are covered by the ignore file: support-files/compiler_warnings.supp.
- Strings are guaranteed to be max uint in length
2009-02-10 17:47:54 -05:00
Alexey Kopytov
fd8bf58ca9 Fix for bug #41868: crash or memory overrun with concat + upper,
date_format functions

String::realloc() did not check whether the existing string data fits in
the newly allocated buffer for cases when reallocating a String object
with external buffer (i.e.alloced == FALSE).  This could lead to memory
overruns in some cases.

client/sql_string.cc:
  Fixed String::realloc() to check whether the existing string data fits
  in the newly allocated buffer for cases when reallocating a String
  object with external buffer.
mysql-test/r/func_str.result:
  Added a test case for bug #41868.
mysql-test/t/func_str.test:
  Added a test case for bug #41868.
sql/sql_class.cc:
  After each call to Item::send() in select_send::send_data() reset
  buffer to its original state to reduce unnecessary malloc() calls. See
  comments for bug #41868 for detailed analysis.
sql/sql_string.cc:
  Fixed String::realloc() to check whether the existing string data fits
  in the newly allocated buffer for cases when reallocating a String
  object with external buffer.
2009-02-10 15:38:56 +03:00
Georgi Kodinov
0669b79363 Bug #33813: Schema names are case-sensitive in DROP FUNCTION
The parser was not using the correct fully-qualified-name
production for DROP FUNCTION.
Fixed by copying the production from DROP PROCEDURE.
Tested in the windows specific suite to make sure it's 
tested on a case-insensitive file system.

mysql-test/r/windows.result:
  Bug #33813: test case
mysql-test/t/windows.test:
  Bug #33813: test case
sql/sql_yacc.yy:
  Bug #33813: use the correct production for the name in
  DROP PROCEDURE
2009-02-10 11:58:19 +02:00
Tatiana A. Nurnberg
0eca4824c3 auto-merge 2009-02-06 18:47:54 +01:00
Tatiana A. Nurnberg
d66dc23065 Bug#42525: TIMEDIFF function
In 37553 we declared longlong results for
class Item_str_timefunc as per comments/docs,
but didn't add a method for that. And the
default just wasn't good enough for some
cases.

Changeset adds dedicated val_int() to class.

mysql-test/r/func_sapdb.result:
  More tests for casts of TIME() / TIMEDIFF() with negative results.
mysql-test/t/func_sapdb.test:
  More tests for casts of TIME() / TIMEDIFF() with negative results.
sql/item_timefunc.h:
  Since we claim to provide longlong results, we should have
  a suitable function to provide them (the default won't do).
  This one matches the val_real() variant.
2009-02-06 18:25:08 +01:00
Alexey Kopytov
b30239bc1a Temporarily reverted patch for bug #41868 as it was causing problems in PB. 2009-02-06 12:51:11 +03:00
Alexey Kopytov
759b626d11 Merge to team tree. 2009-02-05 15:48:30 +03:00
Alexey Kopytov
20cdcaa3d5 Merge from team tree. 2009-02-05 15:07:11 +03:00
Gleb Shchepa
061bf717e0 Bug #42037: Queries containing a subquery with DISTINCT and
ORDER BY could cause a server crash

Dependent subqueries like

  SELECT COUNT(*) FROM t1, t2 WHERE t2.b
   IN (SELECT DISTINCT t2.b FROM t2 WHERE t2.b = t1.a)

caused a memory leak proportional to the
number of outer rows.


The make_simple_join() function has been modified to
JOIN class method to store join_tab_reexec and
table_reexec values in the parent join only
(make_simple_join of tmp_join may access these values
via 'this' pointer of the parent JOIN).

NOTE: this patch doesn't include standard test case (this is
"out of memory" bug). See bug #42037 page for test cases.


sql/sql_select.cc:
  Bug #42037: Queries containing a subquery with DISTINCT and
              ORDER BY could cause a server crash
  
  The make_simple_join() function has been modified to
  JOIN class method to store join_tab_reexec and
  table_reexec values in the parent join only.
sql/sql_select.h:
  Bug #42037: Queries containing a subquery with DISTINCT and
              ORDER BY could cause a server crash
  
  1. The make_simple_join() function has been modified to
     JOIN class method.
  
  2. Type of JOIN::table_reexec field has been changed from
     TABLE** to TABLE *table_reexec[1]: this field always was
     NULL or a pointer to one-element array of pointers, so
     a pointer to a pointer has been replaced with one pointer
     and unnecessary memory allocation has been eliminated.
2009-02-05 13:30:39 +04:00
Ramil Kalimullin
31d908d70b Fix for bug#42014: Crash, name_const with collate
Problem: some queries using NAME_CONST(.. COLLATE ...)
lead to server crash due to failed type cast.

Fix: return the underlying item's type in case of
NAME_CONST(.. COLLATE ...) to avoid wrong casting.


mysql-test/r/func_misc.result:
  Fix for bug#42014: Crash, name_const with coll
    - test result.
mysql-test/t/func_misc.test:
  Fix for bug#42014: Crash, name_const with coll
    - test case.
sql/item.cc:
  Fix for bug#42014: Crash, name_const with coll
    - in case of NAME_CONST('name', 'value' COLLATE collation)
  Item_name_const::type() returns type of 'value' argument 
  to awoid wrong type casting of the Item_name_const items.
2009-02-05 11:43:39 +04:00
Alexey Kopytov
dfbba6e7fd Fix for bug #41868: crash or memory overrun with concat + upper, date_format
functions
      
String::realloc() did not check whether the existing string data fits in the newly
allocated buffer for cases when reallocating a String object with external buffer
(i.e.alloced == FALSE).  This could lead to memory overruns in some cases.


mysql-test/r/func_str.result:
  Added a test case for bug #41868.
mysql-test/t/func_str.test:
  Added a test case for bug #41868.
sql/sql_class.cc:
  After each call to Item::send() in select_send::send_data() reset buffer to its
  original state to reduce unnecessary malloc() calls. See comments for bug #41868
  for detailed analysis.
sql/sql_string.cc:
  Fixed String::realloc() to check whether the existing string data fits in the newly allocated buffer for cases when reallocating a String object with external buffer.
2009-02-03 20:19:01 +03:00
Tatiana A. Nurnberg
518cfea483 auto-merge 2009-01-31 02:07:36 +01:00
Tatiana A. Nurnberg
ce563480b7 Bug#41370: TIMESTAMP field does not accepts NULL from FROM_UNIXTIME()
When storing a NULL to a TIMESTAMP NOT NULL DEFAULT ...,
NULL returned from some functions threw a 'cannot be NULL error.'

NULL-returns now correctly result in the timestamp-field being
assigned its default value.

mysql-test/r/type_timestamp.result:
  Show that for TIMESTAMP NOT NULL DEFAULT, NULL function returns
  set default now.
mysql-test/t/type_timestamp.test:
  Show that for TIMESTAMP NOT NULL DEFAULT, NULL function returns
  set default now.
sql/item.cc:
  When storing a returned NULL (from a time- or date-related
  function), make sure to apply NULL-means-DEFAULT magic where
  applicable.
2009-01-30 17:12:24 +01:00
Georgi Kodinov
b367d2fd1f merged 35396 to 5.0-bugteam 2009-01-29 14:45:24 +02:00
Georgi Kodinov
37e88536e3 Bug #35396: Abnormal query times in slow query log
If the system time is adjusted back during a query execution
(resulting in the end time being earlier than the start time)
the code that prints to the slow query log gets confused and 
prints unsigned negative numbers.
            
Fixed by not logging the statements that would have negative
execution time due to time shifts.
No test case since this would involve changing the system time.

sql/sql_parse.cc:
  Bug #35396: don't log queries with negative execution times 
  (due to shifts in system time).
2009-01-29 14:40:48 +02:00
Gleb Shchepa
334e249f91 Bug #39069: <row constructor> IN <table-subquery> seriously
messed up

"ROW(...) IN (SELECT ... FROM DUAL)" always returned TRUE.

Item_in_subselect::row_value_transformer rewrites "ROW(...)
IN SELECT" conditions into the "EXISTS (SELECT ... HAVING ...)"
form.
For a subquery from the DUAL pseudotable resulting HAVING
condition is an expression on constant values, so further
transformation with optimize_cond() eliminates this HAVING
condition and resets JOIN::having to NULL.
Then JOIN::exec treated that NULL as an always-true-HAVING
and that caused a bug.

To distinguish an optimized out "HAVING TRUE" clause from
"HAVING FALSE" we already have the JOIN::having_value flag.
However, JOIN::exec() ignored JOIN::having_value as described
above as if it always set to COND_TRUE.

The JOIN::exec method has been modified to take into account
the value of the JOIN::having_value field.


mysql-test/r/subselect3.result:
  Added test case for bug #39069.
mysql-test/t/subselect3.test:
  Added test case for bug #39069.
sql/sql_select.cc:
  Bug #39069: <row constructor> IN <table-subquery> seriously
              messed up
  
  The JOIN::exec method has been modified to take into account
  the value of the JOIN::having_value field.
2009-01-28 22:46:45 +04:00
Alexey Kopytov
a01946373d Fix for bug #21205: Different number of digits for float/double/real in --ps-protocol
Various parts of code used different 'precision' arguments for sprintf("%g") when converting
floating point numbers to a string. This led to differences in results in some cases 
depending on whether the text-based or prepared statements protocol is used for a query.

Fixed by changing arguments to sprintf("%g") to always be 15 (DBL_DIG) so that results are
consistent regardless of the protocol.

This patch will be null-merged to 6.0 as the problem does not exists there (fixed by the
patch for WL#2934).

client/sql_string.cc:
  Use 15 (DBL_DIG) as a precision argument for sprintf(), as Field_double::val_str() does.
libmysql/libmysql.c:
  Use 15 (DBL_DIG) as a precision argument for sprintf(), as Field_double::val_str() does.
mysql-test/r/archive_gis.result:
  Fixed test results to take additional precision into account.
mysql-test/r/func_group.result:
  Fixed test results to take additional precision into account.
mysql-test/r/func_math.result:
  Fixed test results to take additional precision into account.
mysql-test/r/func_str.result:
  Fixed test results to take additional precision into account.
mysql-test/r/gis.result:
  Fixed test results to take additional precision into account.
mysql-test/r/innodb_gis.result:
  Fixed test results to take additional precision into account.
mysql-test/r/select.result:
  Fixed test results to take additional precision into account.
mysql-test/r/sp.result:
  Fixed test results to take additional precision into account.
mysql-test/r/type_float.result:
  Fixed test results to take additional precision into account.
mysql-test/t/type_float.test:
  Fixed test results to take additional precision into account.
sql/sql_string.cc:
  Use 15 (DBL_DIG) as a precision argument for sprintf(), as Field_double::val_str() does.
2009-01-28 20:59:08 +03:00
Chad MILLER
d81f6d6104 Merge from team tree. 2009-01-26 12:34:55 -05:00
Davi Arnaut
ecfdc3560c Bug#40264: Aborted cached query causes query to hang indefinitely on next cache hit
The problem is that the query cache was storing partial results
if the statement failed when sending the results to the client.
This could cause clients to hang when trying to read the results
from the cache as they would, for example, wait indefinitely for
a eof packet that wasn't saved.

The solution is to always discard the caching of a query that
failed to send its results to the associated client.

mysql-test/r/query_cache_notembedded.result:
  Add test case result for Bug#40264
mysql-test/t/query_cache_notembedded.test:
  Add test case for Bug#40264
sql/sql_cache.cc:
  Abort if a unreported error was raised.
2009-01-22 08:28:01 -02:00
Chad MILLER
d3629d7489 Merge from Tim's 5.0.76-release tree to make 5.0.77 . 2009-01-21 13:45:23 -05:00
Georgi Kodinov
bdec5458ae auto merge 2009-01-16 16:48:41 +02:00
Georgi Kodinov
683542698f merged Bug 38795 to 5.0-bugteam 2009-01-15 16:15:38 +02:00
Alexander Nozdrin
852d1d66f6 Pull from 5.0-bugteam 2009-01-15 13:10:20 +03:00
Alexander Nozdrin
9a6e05d8b9 Backport patch for Bug#31222 (com_% global status counters behave randomly
with mysql_change_user) to 5.0.
2009-01-15 12:36:34 +03:00
Chad MILLER
9b1b1d507e Merge from dev tree. 2009-01-14 11:15:11 -05:00
Chad MILLER
e85a3f7bc2 Bug#38145: .frm file isn't sync'd with sync_frm enabled
Views weren't sync()d the same way other structures were.

In creating the FRM for views, obey the same rules for variable 
"sync_frm" as for everything else.
2009-01-14 11:11:31 -05:00
Chad MILLER
73688c5e21 Fix comment. Boolean function returns true/false, not zero/one. 2009-01-14 11:10:36 -05:00
Davi Arnaut
3d6cea324a Bug#36326: nested transaction and select
The problem is that the query cache stores packets containing
the server status of the time when the cached statement was run.
This might lead to a wrong transaction status in the client side
if a statement is cached during a transaction and is later served
outside a transaction context (and vice-versa).

The solution is to take into account the transaction status when
storing in and serving from the query cache.

mysql-test/r/innodb_cache.result:
  Update test case result.
mysql-test/r/query_cache.result:
  Add test case result for Bug#36326
mysql-test/t/query_cache.test:
  Add test case for Bug#36326
sql/mysql_priv.h:
  Add new flags.
sql/sql_cache.cc:
  Remember the transaction and autocommit status stored in the packet.
tests/mysql_client_test.c:
  Add test case for Bug#36326
2009-01-13 20:07:06 -02:00
Georgi Kodinov
ba47e3bc4d Bug #38795: Automatic search depth and nested join's results in server crash
The greedy optimizer tracks the current level of nested joins and the position
inside these by setting and maintaining a state that's global for the whole FROM
clause.
This state was correctly maintained inside the selection of the next partial plan
table (in best_extension_by_limited_search()). 
greedy_search() also moves the current position by adding the last partial match 
table when there's not enough tables in the partial plan found by 
best_extension_by_limited_search().
This may require update of the global state variables that describe the current
position in the plan if the last table placed by greedy_search is not a top-level 
join table.
Fixed by updating the state after placing the partial plan table in greedy_search()
in the same way this is done on entering the best_extension_by_limited_search().
Fixed the signature of the function called to update the state : 
check_interleaving_with_nj

mysql-test/r/greedy_optimizer.result:
  Bug #38795: test case
mysql-test/t/greedy_optimizer.test:
  Bug #38795: test case
sql/sql_select.cc:
  Bug #38795: correctly update current position when placing
  the next partial plan table in greedy_search().
2009-01-13 13:09:12 +02:00
Joerg Bruehe
75d276ad61 Backport of a 5.0.74 fix into 5.0.72sp1:
Bug #39920: MySQL cannot deal with Leap Second expression in string literal.

Updated MySQL time handling code to react correctly on UTC leap second additions.
MySQL functions that return the OS current time, like e.g. CURDATE(), NOW() etc
will return :59:59 instead of :59:60 or 59:61.
As a result the reader will receive :59:59 for 2 or 3 consecutive seconds
during the leap second.

Original changesets:
> revision-id: kgeorge@mysql.com-20081201141835-rg8nnnadujj5wl9f
> parent: gshchepa@mysql.com-20081114172557-xh0jlzwal8ze3cy6
> committer: Georgi Kodinov <kgeorge@mysql.com>
> branch nick: B39920-5.0-bugteam
> timestamp: Mon 2008-12-01 16:18:35 +0200

> revision-id: kgeorge@mysql.com-20081201154106-c310zzy5or043rqa
> parent: kgeorge@mysql.com-20081201145656-6kjq91oga5nxbbob
> committer: Georgi Kodinov <kgeorge@mysql.com>
> branch nick: B39920-merge-5.0-bugteam
> timestamp: Mon 2008-12-01 17:41:06 +0200
2009-01-12 17:40:29 +01:00
Joerg Bruehe
3055db5c0e Backport of a 5.0.74 fix into 5.0.72sp1:
Bug#34760 Character set autodetection appears to fail
the problem is the same as reported in bug#20835,
so the fix is backport of bug#20835 patch.

Original changeset:
> revision-id: sergey.glukhov@sun.com-20081121123959-58ffhp2nitg7f40h
> parent: ramil@mysql.com-20081120100836-gct60cm67b1rui29
> committer: Sergey Glukhov <Sergey.Glukhov@sun.com>
> branch nick: mysql-5.0-bugteam
> timestamp: Fri 2008-11-21 16:39:59 +0400
2009-01-12 17:24:00 +01:00
Joerg Bruehe
3b23a99b87 Backport of a 5.0.74 fix into 5.0.72sp1:
BUG#38842 - Fix for 25951 seems incorrect

Original changeset:
> revision-id: svoj@mysql.com-20081111091051-54pr96nf1z2s30gx
> parent: vvaintroub@mysql.com-20081110201804-bi98gcs9avsf58ff
> committer: Sergey Vojtovich <svoj@mysql.com>
> branch nick: mysql-5.0-bugteam-bug38842
> timestamp: Tue 2008-11-11 13:10:51 +0400
2009-01-12 17:18:53 +01:00
Joerg Bruehe
16f374ef65 Backport of a 5.0.74 fix into 5.0.72sp1:
Bug #40021: Renaming view fails, archived .frm for view is
            missing after downgrade

Original changeset:
> revision-id: gshchepa@mysql.com-20081114172557-xh0jlzwal8ze3cy6
> parent: ramil@mysql.com-20081114074229-vj4fvfrpmz8jfub9
> committer: Gleb Shchepa <gshchepa@mysql.com>
> branch nick: mysql-5.0-bugteam
> timestamp: Fri 2008-11-14 21:25:57 +0400
2009-01-12 17:09:03 +01:00
Georgi Kodinov
ac885d5dfb Bug #41437: Value stored in 'case' lacks charset, causes segfault
When substituting system constant functions with a constant result
the server was not expecting that the function may return NULL.
Fixed by checking for NULL and returning Item_null (in the relevant
collation) if the result of the system constant function was NULL.

mysql-test/r/mysql.result:
  Bug #41437: test case
mysql-test/t/mysql.test:
  Bug #41437: test case.
  Relies on database() returning NULL if no database is
  selected.
sql/item_strfunc.cc:
  Bug #41437: Check for NULL result on evaluating the system
  constant function and return a constant NULL item.
2009-01-09 13:50:18 +02:00
Georgi Kodinov
4978004e8d Reverted the fix for bug #25830 because of omissions and non-complete test
case.
2009-01-05 12:37:56 +02:00
Tatiana A. Nurnberg
728c75cc0b auto-merge 2008-12-30 12:47:34 +01:00
Sergey Glukhov
3b617acb87 Bug#41131 "Questions" fails to increment - ignores statements instead stored procs(5.0 ver)
Added global status variable 'Queries' which represents
total amount of queries executed by server including
statements executed by SPs.
note: It's old behaviour of 'Questions' variable.


mysql-test/r/status.result:
  test result
mysql-test/t/status.test:
  test case
sql/mysqld.cc:
  Added global status variable 'Queries' which represents
  total amount of queries executed by server including
  statements executed by SPs.
  note: It's old behaviour of 'Questions' variable.
sql/sql_show.cc:
  Added global status variable 'Queries' which represents
  total amount of queries executed by server including
  statements executed by SPs.
  note: It's old behaviour of 'Questions' variable.
sql/structs.h:
  Added global status variable 'Queries' which represents
  total amount of queries executed by server including
  statements executed by SPs.
  note: It's old behaviour of 'Questions' variable.
2008-12-29 16:06:53 +04:00
Sergey Glukhov
ce985aa36e Bug#40953 SELECT query throws "ERROR 1062 (23000): Duplicate entry..." error
Table could be marked dependent because it is
either 1) an inner table of an outer join, or 2) it is a part of
STRAIGHT_JOIN. In case of STRAIGHT_JOIN table->maybe_null should not
be assigned. The fix is to set st_table::maybe_null to 'true' only
for those tables which are used in outer join.



mysql-test/r/select.result:
  test result
mysql-test/t/select.test:
  test case
sql/sql_select.cc:
  Table could be marked dependent because it is
  either 1) an inner table of an outer join, or 2) it is a part of
  STRAIGHT_JOIN. In case of STRAIGHT_JOIN table->maybe_null should not
  be assigned. The fix is to set st_table::maybe_null to 'true' only
  for those tables which are used in outer join.
sql/sql_select.h:
  added comment
2008-12-24 19:24:11 +04:00
Sergey Glukhov
7103f4c916 Bug#41456 SET PASSWORD hates CURRENT_USER()
init user->user struct with 
thd->security_ctx->priv_user context
if user->user is not initializied

mysql-test/r/grant.result:
  test result
mysql-test/t/grant.test:
  test case
sql/set_var.cc:
  init user->user struct with 
  thd->security_ctx->priv_user context
  if user->user is not initializied
2008-12-24 19:14:59 +04:00
Sergey Glukhov
65c3d37111 Bug#25830 SHOW TABLE STATUS behaves differently depending on table name
replace wild_case_compare with my_wildcmp which is multibyte safe function


mysql-test/r/lowercase_utf8.result:
  test result
mysql-test/t/lowercase_utf8-master.opt:
  test case
mysql-test/t/lowercase_utf8.test:
  test case
sql/sql_show.cc:
  replace wild_case_compare with my_wildcmp which is multibyte safe function
2008-12-24 19:01:41 +04:00
Sergey Glukhov
4794f463b6 compiler warning fix 2008-12-24 18:45:47 +04:00
Sergey Glukhov
e138336894 Bug#41079 information_schema.schema_privileges is limited to 7680 records.
The problem is that we cannot insert new record into memory table
when table size exceeds max memory table size.
The fix is to use schema_table_store_record() function which
converts memory table into MyISAM in case of table size exceeding.

Note:
There is no test case for this bug, the reason is that
1. The code  that was added already is checked(i.e. works) with existing tests
2. Correct work of schema_table_store_record() is checked with other test cases
   (information_schema tests)
So new code is fully covered with existing test cases.


sql/mysql_priv.h:
  make schema_table_store_record() function global
sql/sql_acl.cc:
  The problem is that we cannot insert new record into memory table
  when table size exceeds max memory table size.
  The fix is to use schema_table_store_record() function which
  converts memory table into MyISAM in case of table size exceeding.
sql/sql_show.cc:
  make schema_table_store_record() function global
2008-12-23 18:56:08 +04:00
Sergey Glukhov
c06df92af6 Bug#37575 UCASE fails on monthname
The MONTHNAME/DAYNAME functions
returns binary string, so the LOWER/UPPER functions
are not effective on the result of MONTHNAME/DAYNAME call.  
Character set of the MONTHNAME/DAYNAME function
result has been changed to connection character set.


include/m_ctype.h:
  added my_charset_repertoire function
mysql-test/r/ctype_ucs.result:
  test result
mysql-test/r/func_time.result:
  test result
mysql-test/t/ctype_ucs.test:
  test case
mysql-test/t/func_time.test:
  test case
sql/item_timefunc.cc:
  Item_func_monthname::fix_length_and_dec and
  Item_func_dayname::fix_length_and_dec methods have been
  modified to use connection character set
sql/item_timefunc.h:
  Item_func_monthname::fix_length_and_dec and
  Item_func_dayname::fix_length_and_dec methods have been
  modified to use connection character set
sql/mysql_priv.h:
  added max_month_name_length, max_day_name_length fields into MY_LOCALE struct
sql/mysqld.cc:
  The test_lc_time_sz function controls modifications
  of the locale database in debugging mode.
sql/sql_locale.cc:
  initialization of max_month_name_length, max_day_name_length fields
strings/ctype.c:
  added my_charset_repertoire function
2008-12-23 18:08:04 +04:00
Sergey Petrunia
7658444b97 Merge 2008-12-22 23:28:08 +03:00
Sergey Petrunia
7976735a0c BUG#40974: Incorrect query results when using clause evaluated using range check
- QUICK_INDEX_MERGE_SELECT deinitializes its rnd_pos() scan when it reaches EOF, but we 
  need to make the deinitialization in QUICK_INDEX_MERGE_SELECT destructor also. This is because
  certain execution strategies can stop scanning without reaching EOF, then then try to do a full
  table scan on this table. Failure to deinitialize caused the full scan to use (already empty) 
  table->sort and produce zero records.

mysql-test/r/index_merge.result:
  BUG#40974: Incorrect query results when using clause evaluated using range check
  - Testcase
mysql-test/t/index_merge.test:
  BUG#40974: Incorrect query results when using clause evaluated using range check
  - Testcase
2008-12-19 16:38:39 +03:00
Chad MILLER
926e5f6694 Merged from 5.0 (enterprise). 2008-12-17 15:01:34 -05:00
Timothy Smith
45c97126af Merge from upstream 5.0-bugteam. 2008-12-15 13:09:23 -07:00
Timothy Smith
001aaedcb6 r2629 | inaam | 2008-09-16 18:46:00 +0300 (Tue, 16 Sep 2008) | 9 lines
branches/5.0   bug#39483 InnoDB hang on adaptive hash because of out
of order ::open() call by MySQL

Under some conditions MySQL calls ::open with search_latch leading
to a deadlock as we try to acquire dict_sys->mutex inside ::open
breaking the latching order. The fix is to release search_latch.

Reviewed by: Heikki
2008-12-12 17:42:34 -07:00
Gleb Shchepa
af5cf536bc Bug #40761: Assert on sum function on
IF(..., CAST(longtext AS UNSIGNED), signed_val)
            (was: LEFT JOIN on inline view crashes server)

Select from a LONGTEXT column wrapped with an expression
like "IF(..., CAST(longtext_column AS UNSIGNED), smth_signed)"
failed an assertion or crashed the server. IFNULL function was
affected too.

LONGTEXT column item has a maximum length of 32^2-1 bytes,
at the same time this is a maximum possible length of any
MySQL item. CAST(longtext_column AS UNSIGNED) returns some
unsigned numeric result of length 32^2-1, so the result of
IF/IFNULL function of this number and some other signed number
will have text length of (32^2-1)+1=32^2 (one byte for the
minus sign) - there is integer overflow, and the length is
equal to zero. That caused assert/crash.

CAST AS UNSIGNED function has been modified to limit maximal
length of resulting number to 67 (maximal length of DECIMAL
and two characters for minus sign and dot).


mysql-test/r/func_if.result:
  Added test case for bug #40761.
mysql-test/t/func_if.test:
  Added test case for bug #40761.
sql/item_func.h:
  Bug #40761: Assert on sum function on
              IF(..., CAST(longtext AS UNSIGNED), signed_val)
  
  CAST AS UNSIGNED function has been modified to limit maximal
  length of resulting number to 67 (maximal length of DECIMAL
  and two characters for minus sign and dot).
2008-12-12 17:16:25 +04:00
Gleb Shchepa
5ff1bcbc2a rollback of bug #40761 fix 2008-12-12 14:59:10 +04:00
Gleb Shchepa
ffe23f0eb7 Bug #40761: Assert on sum function on
IF(..., CAST(longtext AS UNSIGNED), signed_val)
            (was: LEFT JOIN on inline view crashes server)

Select from a LONGTEXT column wrapped with an expression
like "IF(..., CAST(longtext_column AS UNSIGNED), smth_signed)"
failed an assertion or crashed the server. IFNULL function was
affected too.

LONGTEXT column item has a maximum length of 32^2-1 bytes,
at the same time this is a maximum possible length of any
MySQL item. CAST(longtext_column AS UNSIGNED) returns some
unsigned numeric result of length 32^2-1, so the result of
IF/IFNULL function of this number and some other signed number
will have text length of (32^2-1)+1=32^2 (one byte for the
minus sign) - there is integer overflow, and the length is
equal to zero. That caused assert/crash.

The bug has been fixed by the same solution as in the CASE
function implementation.


mysql-test/r/func_if.result:
  Added test case for bug #40761.
mysql-test/t/func_if.test:
  Added test case for bug #40761.
sql/item_cmpfunc.cc:
  Bug #40761: Assert on sum function on
              IF(..., CAST(longtext AS UNSIGNED), signed_val)
  
  1. Item_func_case::agg_str_lengths method has been moved
     to the Item_func superclass.
  2. Item_func_ifnull/Item_func_if::fix_length_and_dec methods
     have been updated to calculate max_length, decimals and
     unsigned flag like Item_func_case.
sql/item_cmpfunc.h:
  Bug #40761: Assert on sum function on
              IF(..., CAST(longtext AS UNSIGNED), signed_val)
  
  Item_func_case::agg_str_lengths method has been moved to
  the Item_func superclass.
sql/item_func.cc:
  Bug #40761: Assert on sum function on
              IF(..., CAST(longtext AS UNSIGNED), signed_val)
  
  Item_func_case::agg_str_lengths method has been moved to
  the Item_func superclass.
sql/item_func.h:
  Bug #40761: Assert on sum function on
              IF(..., CAST(longtext AS UNSIGNED), signed_val)
  
  Item_func_case::agg_str_lengths method has been moved to
  the Item_func superclass.
2008-12-12 00:57:32 +04:00
Luis Soares
ac27e637ba Fix PB warnings for parenthesis and valgrind leak report.
BUG#38826
2008-12-11 11:06:50 +00:00
Sergey Glukhov
84de3b930b Bug#37956 memory leak and / or crash with geometry and prepared statements!
Bug#37671 crash on prepared statement + cursor + geometry + too many open files!
if mysql_execute_command() returns error then free materialized_cursor object.
is_rnd_inited is added to satisfy rnd_end() assertion
(handler may be uninitialized in some cases)


sql/sql_cursor.cc:
  if mysql_execute_command() returns error then free materialized_cursor object.
  is_rnd_inited is added to satisfy rnd_end() assertion
  (handler may be uninitialized in some cases)
sql/sql_select.cc:
  added result check
tests/mysql_client_test.c:
  test case
2008-12-10 18:13:11 +04:00
Luis Soares
a6be137556 push to 5.0-bugteam tree. 2008-12-10 10:53:22 +00:00
V Narayanan
59c9168c77 updating with mysql-5.0-bugteam 2008-12-10 14:26:57 +05:30
Georgi Kodinov
979974c53b backported the fix for bug #34773 to 5.0 2008-12-09 20:35:02 +02:00
Sergey Glukhov
4ce563e01c Bug#31399 Wrong query result when doing join buffering over BIT fields
if table has bit fields then uneven bits(if exist) are stored into null bits place.
So we need to copy null bits in case of uneven bit field presence.


mysql-test/r/type_bit.result:
  test result
mysql-test/t/type_bit.test:
  test case
sql/sql_select.cc:
  if table has bit fields then uneven bits(if exist) are stored into null bits place.
  So we need to copy null bits in case of uneven bit field presence.
2008-12-09 16:59:47 +04:00
Sergey Glukhov
419e053a41 Bug#31291 ALTER TABLE CONVERT TO CHARACTER SET does not change some data types
added ability for TINY[MEDIUM] text fields 
to be converted to greater subtype during
alter if necessary(altered charset)


mysql-test/r/alter_table.result:
  test result
mysql-test/t/alter_table.test:
  test case
sql/sql_table.cc:
  added ability for TINY[MEDIUM] text fields 
  to be converted to greater subtype during
  alter if necessary(altered charset)
2008-12-09 16:38:52 +04:00
Sergey Glukhov
d49d4298e9 automerge 2008-12-09 16:11:01 +04:00
Alexey Kopytov
06c4ff1c13 Added a missing bit from the original patch for bug #27483 which was lost when re-applying
the patch manually to another tree.
2008-12-09 13:19:46 +03:00
Sergey Glukhov
681a2d1a53 bug#35558 Wrong server metadata blows up the client
the problem: FORMAT func max_length value was calculated incorrectly
the fix: correct calculation of max_length


mysql-test/r/func_str.result:
  test result
mysql-test/t/func_str.test:
  test case
sql/item_strfunc.h:
  the problem: FORMAT func max_length value was calculated incorrectly
  the fix: correct calculation of max_length
2008-12-09 14:00:43 +04:00
Sergey Glukhov
cbb368aa88 Bug#35796 SHOW CREATE TABLE and default value for BIT field
show default value for BIT field in printable format


mysql-test/r/type_bit.result:
  Bug#35796 SHOW CREATE TABLE and default value for BIT field
  test result
mysql-test/t/type_bit.test:
  Bug#35796 SHOW CREATE TABLE and default value for BIT field
  test case
sql/item.cc:
  Bug#35796 SHOW CREATE TABLE and default value for BIT field
  issue an error if BIN|HEX deafult value is empty value
  (behaviour like for INT fields)
2008-12-09 13:53:23 +04:00
Luis Soares
da1bf24852 BUG#38826 Race in MYSQL_LOG::purge_logs is impossible to debug in production
BUG#39325 Server crash inside MYSQL_LOG::purge_first_log halts replicaiton

The patch reverses the order of the purging and updating events for log and relay-log.info/index files respectively.
This solves the problem of having holes caused by crashes happening between updating info/index files and purging logs.

NOTE: This is a combined patch for BUG#38826 and BUG#39325. This patch is based on bugteam tree and takes into account reviewers suggestions.
2008-12-04 01:01:03 +00:00
V Narayanan
c75cd3d70f merging with mysql-5.0-bugteam tree. 2008-12-03 17:52:55 +05:30
Tatiana A. Nurnberg
3edacb4f6d auto-merge 2008-12-03 07:38:26 +01:00
Tatiana A. Nurnberg
085262146e auto-merge 2008-12-03 07:19:26 +01:00
Georgi Kodinov
7114fde7c0 merged bug 39920 to 5.0-bugteam 2008-12-01 16:41:22 +02:00
Georgi Kodinov
f56e43ce52 Bug #39920: MySQL cannot deal with Leap Second expression in string literal.
Updated MySQL time handling code to react correctly on UTC leap second additions.
MySQL functions that return the OS current time, like e.g. CURDATE(), NOW() etc
will return :59:59 instead of :59:60 or 59:61.
As a result the reader will receive :59:59 for 2 or 3 consecutive seconds 
during the leap second.
This fix will not affect the values returned by UNIX_TIMESTAMP() for leap seconds.
But note that when converting the value returned by UNIX_TIMESTAMP() to broken 
down time the correction of leap seconds will still be applied.
Note that this fix will make a difference *only* if the OS is specially configured
to return leap seconds from the OS time calls or when using a MySQL time zone 
defintion that has leap seconds.
Even after this change date/time literals (or other broken down time 
representations) with leap seconds (ending on :59:60 or 59:61) will still be 
considered illegal and discarded by the server with an error or 
a warning depending on the sql mode.
Added a test case to demonstrate the effect of the fix.

mysql-test/r/timezone3.result:
  Bug #39920: test case
mysql-test/std_data/Moscow_leap:
  Bug #39920: updated the Moscow time zone to Dr. Olson's tzdata 2008i 
  to accomodate for the 2008 leap second
mysql-test/t/timezone3.test:
  Bug #39920: test case
sql/tztime.cc:
  Bug #39920: adjust leap seconds (:60 or :61) to :59
sql/tztime.h:
  Bug #39920: adjust leap seconds (:60 or :61) to :59
2008-12-01 16:18:35 +02:00
Gleb Shchepa
4f75f58b7a After-push commit for bug #33461 to make valgrind happy:
TABLE_LIST doesn't free Strings in its string lists
(TABLE_LIST::use_index and TABLE_liST::ignore_index), so
calling c_ptr_safe() on that Strings leads to memleaks.
OTOH "safe" c_ptr_safe() is not necessary there and we can
replace it with c_ptr().
2008-12-01 12:14:02 +04:00
Gleb Shchepa
41ccbefcc4 Bug #33461: SELECT ... FROM <view> USE INDEX (...) throws
an error

Even after the fix for bug 28701 visible behaviors of
SELECT FROM a view and SELECT FROM a regular table are
little bit different:

1. "SELECT FROM regular table USE/FORCE/IGNORE(non
   existent index)" fails with a "ERROR 1176 (HY000):
   Key '...' doesn't exist in table '...'"

2. "SELECT FROM view USING/FORCE/IGNORE(any index)" fails
   with a "ERROR 1221 (HY000): Incorrect usage of
   USE/IGNORE INDEX and VIEW".  OTOH "SHOW INDEX FROM
   view" always returns empty result set, so from the point
   of same behaviour view we trying to use/ignore non
   existent index.

To harmonize the behaviour of USE/FORCE/IGNORE(index)
clauses in SELECT from a view and from a regular table the
"ERROR 1221 (HY000): Incorrect usage of USE/IGNORE INDEX
and VIEW" message has been replaced with the "ERROR 1176
(HY000): Key '...' doesn't exist in table '...'" message
like for tables and non existent keys.


mysql-test/r/view.result:
  Added test case for bug #33461.
  Updated test case for bug 28701.
mysql-test/t/view.test:
  Added test case for bug #33461.
  Updated test case for bug 28701.
sql/sql_view.cc:
  Bug #33461: SELECT ... FROM <view> USE INDEX (...) throws
              an error
  
  To harmonize the behaviour of USE/FORCE/IGNORE(index)
  clauses in SELECT from a view and from a regular table the
  "ERROR 1221 (HY000): Incorrect usage of USE/IGNORE INDEX
  and VIEW" message has been replaced with the "ERROR 1176
  (HY000): Key '...' doesn't exist in table '...'" message
  like for tables and non existent keys.
2008-11-28 20:13:12 +04:00
Georgi Kodinov
f1a9d567c1 merged bug 37339 to 5.0-bugteam 2008-11-28 16:32:04 +02:00
Georgi Kodinov
8e688a7a02 Bug #37339: SHOW VARIABLES not working properly with multi-byte datadir
The SHOW VARIABLES LIKE .../SELECT @@/SELECT ... FROM INFORMATION_SCHEMA.VARIABLES
were assuming that all the system variables are in system charset (UTF-8).
However the variables that are settable through command line will have a different
character set (character_set_filesystem).
Fixed the server to remember the correct character set of basedir, datadir, tmpdir,
ssl, plugin_dir, slave_load_tmpdir, innodb variables; init_connect and init_slave 
variables and use it when processing data.

mysql-test/r/ctype_filesystem.result:
  Bug #37339: test case (should be in utf-8)
mysql-test/t/ctype_filesystem-master.opt:
  Bug #37339: test case (should be in ISO-8859-1)
mysql-test/t/ctype_filesystem.test:
  Bug #37339: test case
sql/mysqld.cc:
  Bug #37339: remember the correct character set for init_slave and init_connect
sql/set_var.cc:
  Bug #37339: 
    - remember the character set of the relevant variables
    - implement storing and using the correct 
      character set
sql/set_var.h:
  Bug #37339: implement storing and using the correct 
  character set
sql/sql_show.cc:
  Bug #37339: implement storing and using the correct 
  character set
2008-11-28 16:25:16 +02:00
Sergey Glukhov
78119b2d04 pushbuild failure fixes
mysql-test/r/perror-win.result:
  pushbuild failure fix
mysql-test/t/perror-win.test:
  pushbuild failure fix
sql/item_func.cc:
  pushbuild failure fix
2008-11-28 14:50:13 +04:00
Tatiana A. Nurnberg
50cfde5328 auto-merge 2008-11-27 17:17:16 +01:00
Sergey Glukhov
1182c0979a Bug#37284 Crash in Field_string::type()
The bug is repeatable with latest(1.0.1) InnoDB plugin on Linux, Win,
If MySQL is compiled with valgrind there are errors about
using of uninitialized variable(orig_table).
The fix is to set field->orig_table correct value.


mysql-test/r/innodb_mysql.result:
  test result
mysql-test/t/innodb_mysql.test:
  test case
sql/sql_base.cc:
  set field->orig_table to 'table' value because it may be bogus and
  it leads to crash on Field_string::type() function.
2008-11-27 18:54:23 +04:00
Sergey Glukhov
89d044062c Bug#37460 Assertion failed: !table->file || table->file->inited == handler::NONE
enable uncacheable flag if we update a view with check option
and check option has a subselect, otherwise, the check option
can be evaluated after the subselect was freed as independent
(See full_local in JOIN::join_free())


mysql-test/r/subselect.result:
  test result
mysql-test/t/subselect.test:
  test case
sql/mysql_priv.h:
  added UNCACHEABLE_CHECKOPTION flag
sql/sql_update.cc:
  enable uncacheable flag if we update a view with check option
  and check option has a subselect, otherwise, the check option
  can be evaluated after the subselect was freed as independent
  (See full_local in JOIN::join_free())
2008-11-27 17:57:34 +04:00
Tatiana A. Nurnberg
57ead840c5 auto-merge 2008-11-27 14:45:41 +01:00
Sergey Glukhov
73960af037 Bug#40365 Prepared statements may insert invalid dates.
set DATE|DATETIME value to 0 if ALLOW_INVALID_DATES sql_mode is not enabled.


sql/field.cc:
  set DATE|DATETIME value to 0 if ALLOW_INVALID_DATES sql_mode is not enabled.
tests/mysql_client_test.c:
  test case
2008-11-27 16:41:25 +04:00
Tatiana A. Nurnberg
b7b603d0fc auto-merge 2008-11-27 12:50:51 +01:00
Tatiana A. Nurnberg
d096079d33 Bug#37553: MySql Error Compare TimeDiff & Time
We pretended that TIMEDIFF() would always return positive results;
this gave strange results in comparisons of the TIMEDIFF(low,hi)<TIME(0)
type that rendered a negative result, but still gave false in comparison.
We also inadvertantly dropped the sign when converting times to
decimal.

CAST(time AS DECIMAL) handles signs of the times correctly.
TIMEDIFF() marked up as signed. Time/date comparison code switched to
signed for clarity.

mysql-test/r/func_sapdb.result:
  show that time-related comparisons work with negative
  time values now.
  show that converting time to DECIMAL no longer drops sign.
mysql-test/t/func_sapdb.test:
  show that time-related comparisons work with negative
  time values now.
  show that converting time to DECIMAL no longer drops sign.
sql/item_cmpfunc.cc:
  signed returns
sql/item_cmpfunc.h:
  signed now (time/date < > =)
sql/item_func.cc:
  signed now
sql/item_timefunc.h:
  Functions such as TIMEDIFF() return signed results!
  The file-comments pretended we were doing that all along, anyway...
sql/my_decimal.cc:
  heed sign when converting time to my_decimal;
  times may actually be negative!
  Needed for SELECT CAST(time('-73:42:12') AS DECIMAL);
sql/mysql_priv.h:
  using signed for dates and times now
2008-11-26 09:28:17 +01:00
Vladislav Vaintroub
bc08b15849 merge 2008-11-25 20:18:43 +01:00
Ramil Kalimullin
df8a5474f8 Fix for bug#40984: backport fix from 39585 into 5.0
Problem: in 5.0 'check table for upgrade' doesn't detect
incompatible collation changes made in 5.0.48.

Fix: backport #39585 fix to 5.0


sql/handler.cc:
  Fix for bug#40984: backport fix from 39585 into 5.0
    - backport of #39585 fix
sql/handler.h:
  Fix for bug#40984: backport fix from 39585 into 5.0
    - backport of #39585 fix
2008-11-25 10:22:02 +04:00
Georgi Kodinov
c9be1c9f88 merged bug 39656 to 5.0-bugteam 2008-11-24 17:38:52 +02:00
Georgi Kodinov
d795963cba Bug #39656: Behaviour different for agg functions with & without where -
ONLY_FULL_GROUP_BY

The check for non-aggregated columns in queries with aggregate function, but without
GROUP BY was treating all the parts of the query as if they are in the SELECT list.
Fixed by ignoring the non-aggregated fields in the WHERE clause.

mysql-test/r/func_group.result:
  Bug #39656: test case
mysql-test/t/func_group.test:
  Bug #39656: test case
sql/sql_select.cc:
  Bug #39656: ignore the new non-aggregated column refs in a WHERE
  by saving the state so far and then adding only the new values of the other
  parts of the bitmask.
2008-11-24 17:30:47 +02:00
Alexey Botchkov
d445b215d1 Bug#25058 ignored return codes in memory allocation functions
memory allocation error checks added for functions
   calling insert_dynamic()

per-file messages:
  myisam/mi_delete.c
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
  myisam/mi_write.c
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
  server-tools/instance-manager/instance_options.cc
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
  sql/slave.cc
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
  sql/sp_head.cc
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
  sql/sp_head.h
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
  sql/sp_pcontext.cc
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
  sql/sp_pcontext.h
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
  sql/sql_select.cc
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
  sql/sql_yacc.yy
Bug#25058 ignored return codes in memory allocation functions
    out-of-memory errors handled
2008-11-21 17:38:42 +04:00
Ramil Kalimullin
bb38a57abb Auto-merge 2008-11-21 17:20:58 +04:00
Sergey Glukhov
bd6376f1d1 Bug#34760 Character set autodetection appears to fail
the problem is the same as reported in bug#20835,
so the fix is backport of bug#20835 patch.


mysql-test/r/subselect.result:
  test result
mysql-test/t/subselect.test:
  test case
2008-11-21 16:39:59 +04:00
Ramil Kalimullin
39efef853b Fix for bug#36772: When using UTF8, CONVERT with GROUP BY
returns truncated results

Problem: performig conversion from {INT, DECIMAL, REAL} to CHAR
we incorrectly set its max length in some cases that may lead
to truncated results returned.

Fix: properly set CONVERT({INT, DECIMAL, REAL}, CHAR) result's
max length.


mysql-test/r/ctype_utf8.result:
  Fix for bug#36772: When using UTF8, CONVERT with GROUP BY
  returns truncated results
    - test result.
mysql-test/t/ctype_utf8.test:
  Fix for bug#36772: When using UTF8, CONVERT with GROUP BY
  returns truncated results
    - test case.
sql/item_timefunc.cc:
  Fix for bug#36772: When using UTF8, CONVERT with GROUP BY
  returns truncated results
    - calculating Item_char_typecast::max_length use initial
  argument's charset mbmaxlen instead of from_cs->mbmaxlen,
  as from_cs may differ in some case (see comment above).
2008-11-21 13:48:22 +04:00
Tatiana A. Nurnberg
85c04371d7 Bug#39591: Crash if table comment is longer than 62 characters
It was possible to crash a mysqld build with EXTRA_DEBUG using
CREATE TABLE ... COMMENT with a specially-crafted UTF-8 string.

This CS removes the check that caused it since it no longer
applies in current servers anyway, and adds comments instead
to avoid future confusion. 

mysql-test/r/strict.result:
  Try to crash mysqld with a "suitable" multi-byte (3-byte UTF-8) string
  for a table comment.
mysql-test/t/strict.test:
  Try to crash mysqld with a "suitable" multi-byte (3-byte UTF-8) string
  for a table comment.
sql/unireg.cc:
  Talk at length about limits in .frm form-info, characters vs bytes,
  inlined vs extra-segement TABLE-COMMENTS, and the differences in
  6.0+ vs <6.0 when it comes to UTF-8.
  
  Also, remove a check that no longer applies and that could lead to
  problems in pathological cases.
2008-11-20 15:39:39 +01:00
Ramil Kalimullin
1cd8b9f700 Fix for bug#40875: Memory leak in FEDERATED handler
Problem: memory leak occurs when we open a federated table
that has its share in the hash.

Fix: free not used memory.

Note: the fix should NOT be merged to 5.1 (the code changed).


sql/ha_federated.cc:
  Fix for bug#40875: Memory leak in FEDERATED handler
    - free memory (tmp_share.scheme) allocated in the parse_url()
  if it isn't used anymore.
2008-11-20 14:08:36 +04:00
Sergey Vojtovich
780186f962 Merge. 2008-11-18 15:10:52 +04:00
V Narayanan
065321f0be Bug#39616: Missing quotes from .CSV crashes server
When a CSV file contained comma separated elements 
that were not enclosed in quotes, it was causing the
mysql server to crash.
      
The old algorithm that parsed the content of a row in
mysql 5.0 was assuming that the values of the fields
in a .CSV file will be enclosed in quotes and will be
separated by commas.

This was causing the old algorithm to fail when the 
content of the file resembled the following
3,"sans quotes"
The CSV engine that is part of mysql 5.0 was expecting
the above to be
"3","sans quotes"
      
The above is just one example of where the engine was
failing for what would be recognized as a valid .CSV 
file content otherwise.
      
The proposed fix changes the old algorithm being used
to parse rows from the .CSV file to handle two separate
cases

1) When the current field of the row is enclosed in quotes
2) When the current field of the row is not enclosed in 
   quotes

mysql-test/r/csv.result:
  Contains additional test output corresponding to the new 
  tests added.
mysql-test/t/csv.test:
  Contains additional tests for testing the behaviour of the CSV 
  storage engine when the fields are not enclosed in quotes.
sql/examples/ha_tina.cc:
  Changes the parsing logic of the rows in a CSV file to account for
  fields that are not enclosed in quotes.
2008-11-18 11:31:03 +05:30
Alexey Botchkov
88a8863627 Bug#31616 div_precision_increment description looks wrong
Item_func_div didn't calculate the precision of the result properly.
  The result of 5/0.0001 is 5000 so we have to add decimals of the divisor
  to the planned precision.

per-file comments:
  mysql-test/r/type_newdecimal.result
Bug#31616 div_precision_increment description looks wrong
    test result fixed

  mysql-test/t/type_newdecimal.test
Bug#31616 div_precision_increment description looks wrong
    test case

  sql/item_func.cc
Bug#31616 div_precision_increment description looks wrong
    precision must be increased with args[1]->decimals parameter
2008-11-17 19:41:09 +04:00
Gleb Shchepa
56b9586fd1 Bug #40021: Renaming view fails, archived .frm for view is
missing after downgrade

Obsolete arc/ directory and view .frm file backup support
has been removed by the patch for bug 17823. However, that
bugfix caused a problem with "live downgrades" of the
server: if we rename some view 4 times under 5.1.29/5.0.72
and then try to rename it under 5.1.28/5.0.70 on the same
database, the server fails with a error:

  query 'RENAME TABLE ... TO ...' failed: 6: Error on
  delete of '....frm-0001' (Errcode: 2)

Also .frm file of that view may be lost (renamed to .frm~).

The server failed because it tried to rename latest 3
backup .frm files renaming the view: the server used an
integer value of the "revision" field of .frm file to
extract those file names. After the fix for bug 17823 those
files were not created/maintained any more, however the
"revision" field was incremented as usual. So, the server
failed renaming non existent files.

This fix solves the problem by removing the support for
"revision" .frm file field:
1. New server silently ignores existent "revision" fields
   in old .frm files and never write it down;
2. Old server assumes, that missing "revision" field in new
   .frm files means default value of 0.
3. Accordingly to the fix for bug 17823 the new server
   drops arc/ directory on alter/rename view, so after
   "live downgrade" old server begins maintenance of the
   arc/ directory from scratch without conflicts with .frm
   files.


sql/parse_file.cc:
  Bug #40021: Renaming view fails, archived .frm for view is
              missing after downgrade
  
  1. static write_parameter(): the old_version parameter
     and the section for FILE_OPTIONS_REV have been re moved.
  2. write_parameter(): the max_versions parameter has been
     removed;
  3. sql_create_definition_file(): removal of dead code;
  4. rename_in_schema_file(): revision and num_view_backups
     parameters and dead code have been removed;
  5. File_parser::parse(): FILE_OPTIONS_REV section has been
     removed.
sql/parse_file.h:
  Bug #40021: Renaming view fails, archived .frm for view is
              missing after downgrade
  
  1. The FILE_OPTIONS_REV constant has been removed.
  2. sql_create_definition_file and rename_in_schema_file
     functions: obsolete versions, revision and
     num_view_backups parameters have been removed.
sql/sql_db.cc:
  Bug #40021: Renaming view fails, archived .frm for view is
              missing after downgrade
  
  Commentary update.
sql/sql_trigger.cc:
  Bug #40021: Renaming view fails, archived .frm for view is
              missing after downgrade
  
  sql_create_definition_file() calls have been updates to
  new parameter lists.
sql/sql_view.cc:
  Bug #40021: Renaming view fails, archived .frm for view is
              missing after downgrade
  
  1. The mysql_create_view function code is used for both
     CREATE VIEW and ALTER queries, but query cache is
     necessary for ALTER command only. Check for a non first
     view revision has been replaced with a direct check for
     ALTER query.
  2. The num_view_backups global constant has been removed.
  3. view_parameters: the "revision" .frm field support has
     been removed.
  4. sql_create_definition_file and rename_in_schema_file
     function calls have been updates to new parameter lists.
sql/table.h:
  Bug #40021: Renaming view fails, archived .frm for view is
              missing after downgrade
  
  TABLE_LIST: the revision field has been removed.
2008-11-14 21:25:57 +04:00
Vladislav Vaintroub
f2a610e1e0 Bug #20430 mysqld.exe windows service stuck in "SERVICE_STOP_PENDING"
status

The problem appears to be a race condition, when service is being
stopped right after startup. We set the service status to SERVICE_RUNNING
way too early it cannot yet handle stop requests -  initialization has
not finished and  hEventShutdown  that signals server to stop is not yet
created. If somebody issues "net stop MySQL" at this time, MySQL is not
informed about the stop and continues to run as usual, while
NTService::ServiceMain() stucks forever waiting for mysql's "main" thread
to finish.

Solution is to remain in SERVICE_START_PENDING status until after server
initialization  is fully complete and only then change the status to
SERVICE_RUNNING. In  SERVICE_START_PENDING we do not accept service control
requests, i.e it is not possible to stop service in that time.

sql/mysqld.cc:
  Set service status to running after all initialization is complete
sql/nt_servc.cc:
  New method SetRunning() to be called  by application
  to set service status to SERVICE_RUNNING when apllication
  has finished initialization.
sql/nt_servc.h:
  New method SetRunning() to be called  by application
  when initialization completes
2008-11-14 02:01:41 +01:00
Sergey Glukhov
c049fc6bd6 Bug#39541 CHECK TABLE on information_schema myisam tables produces error
issue 'The storage engine for the table doesn't support check' note for I_S tables


mysql-test/r/mysqlcheck.result:
  test result
mysql-test/t/mysqlcheck.test:
  test case
sql/sql_table.cc:
  issue 'The storage engine for the table doesn't support check' note for I_S tables
2008-11-13 17:06:48 +04:00
Alexey Botchkov
ff707d56d4 Bug#31435 ha_innodb.cc:3983: ulint convert_search_mode_to_innobase(ha_rkey_function): Asse
I think we don't need to issue an error statement in the convert_search_mode_to_innobase().
    Returning the PAGE_CUR_UNSUPP value is enough as allows to handle this
    case depending on the requirements.

per-file comments:
  sql/ha_innodb.cc 
Bug#31435 ha_innodb.cc:3983: ulint convert_search_mode_to_innobase(ha_rkey_function): Asse 
     no error issued in convert_search_mode_to_innobase.
     ha_innobase::records_in_range() returns HA_POS_ERROR if search mode isn't supported.
2008-11-11 14:42:32 +04:00
Sergey Vojtovich
ab9ecae47b BUG#38842 - Fix for 25951 seems incorrect
With fix for bug 25951 index hints are ignored for fulltext
searches, as handling of fulltext indexes is different from
handling regular indexes. Meaning it is not possible to
implement true index hints support for fulltext indexes within
the scope of current fulltext architecture.

The problem is that prior to fix for bug 25951, some useful
index hints still could be given for boolean mode searches.

This patch implements special index hints support for fulltext
indexes with the following characteristics:
- all index hints are still ignored for NLQ mode searches -
  it cannot work without an index;
- for 5.1 and up index hints FOR ORDER BY and FOR GROUP BY are
  still ignored for fulltext indexes;
- boolean mode searches honor USE/FORCE/IGNORE INDEX hints;
- as opposed to index hints for regular indexes, index hints
  for fulltext BOOLEAN mode searches affect the usage of the
  index for the whole query.

mysql-test/r/fulltext.result:
  A test case for BUG#38842.
mysql-test/t/fulltext.test:
  A test case for BUG#38842.
sql/item_func.cc:
  For boolean mode searches, which can work without fulltext
  index, use keys_in_use_for_query bitmap instead of keys_in_use.
  
  The effect is that boolean mode searches now honor index hints.
2008-11-11 13:10:51 +04:00
Kristofer Pettersson
0ed8e66e4b automerge 2008-11-07 16:23:01 +01:00
Georgi Kodinov
6af9982569 merged 5.0-bugteam -> bug 33811-5.0-bugteam working tree 2008-11-03 11:50:32 +02:00
Sergey Glukhov
380f1a8440 Bug#39040 valgrind errors/crash when creating views with binlog logging enabled
A string buffers which were included in the 'view' data structure
were allocated on the stack, causing an invalid pointer when used
after the function returned.
The fix: use copy of values for view->md5 & view->queries


mysql-test/r/view.result:
  test result
mysql-test/t/view.test:
  test case
sql/sql_view.cc:
  A string buffers which were included in the 'view' data structure
  were allocated on the stack, causing an invalid pointer when used
  after the function returned.
  The fix: use copy of values for view->md5 & view->queries
2008-10-27 14:22:38 +04:00
Sergey Petrunia
d5202ddd31 Merge 2008-10-24 06:37:29 +04:00
Sergey Petrunia
844797c492 BUG#38072: Wrong result: HAVING not observed in a query with aggregate
- Make send_row_on_empty_set() return FALSE when simplify_cond() has found out
  that HAVING is always FALSE
re-committing to put the fix into 5.0 and 5.1

mysql-test/r/group_by.result:
  BUG#38072: Wrong result: HAVING not observed in a query with aggregate
  - Testcase
mysql-test/t/group_by.test:
  BUG#38072: Wrong result: HAVING not observed in a query with aggregate
  - Testcase
sql/sql_select.h:
  BUG#38072: Wrong result: HAVING not observed in a query with aggregate
  - Make send_row_on_empty_set() return FALSE when simplify_cond() has found out
    that HAVING is always FALSE
2008-10-24 06:16:22 +04:00
Vladislav Vaintroub
2559cd1ce5 merge 2008-10-23 22:05:47 +02:00
Vladislav Vaintroub
49ff055736 Bug#40280: Message compiler(mc.exe) needed to compile MySQL on windows.
Visual Studio 2008 Express edition does not include message compiler mc.exe
It is not possible to build MySQL server if only VC2008 Express is installed,
because we use mc.exe to generate event log messages.

This patch removes the mc.exe dependency. Generated files message.h, 
message.rc and MSG00001.bin  are checked into source code repository.
Instructions on how to add or change messages are added to messages.mc
2008-10-23 15:28:53 +02:00
Davi Arnaut
9ad8d64439 Bug#28323: Server crashed in xid cache operations
The problem was that the server did not robustly handle a
unilateral roll back issued by the Resource Manager (RM)
due to a resource deadlock within the transaction branch.
By not acknowledging the roll back, the server (TM) would
eventually corrupt the XA transaction state and crash.

The solution is to mark the transaction as rollback-only
if the RM indicates that it rolled back its branch of the
transaction.

mysql-test/r/xa.result:
  Add test case result for Bug#28323
mysql-test/t/xa.test:
  Add test case for Bug#28323
sql/handler.cc:
  Reset XID only at the end of the global transaction.
sql/share/errmsg.txt:
  Add new error codes.
sql/sql_class.h:
  Remember the error reported by the Resource Manager.
sql/sql_parse.cc:
  Rollback the transaction if the Resource Manager reported
  a error and rolled back its branch of the transaction.
2008-10-21 15:45:43 -02:00
Georgi Kodinov
d501f48757 merge 5.0-bugteam -> bug 38693-5.0-bugteam 2008-10-20 16:26:07 +03:00
Kristofer Pettersson
195db07ff3 Auto commit 2008-10-20 13:39:33 +02:00
Georgi Kodinov
697b2839db Bug #33811: Call to stored procedure with SELECT * / RIGHT JOIN
fails after the first time
  
Two separate problems : 
  1. When flattening joins the linked list used for name resolution 
  (next_name_resolution_table) was not updated.
  Fixed by updating the pointers when extending the table list
  
  2. The items created by expanding a * (star) as a column reference
  were marked as fixed, but no cached table was assigned to them 
  (unlike what Item_field::fix_fields does).
  Fixed by assigning a cached table (so the re-preparation is done
  faster).
  
Note that the fix for #2 hides the fix for #1 in most cases
(except when a table reference cannot be cached).

mysql-test/r/sp.result:
  Bug #33811: test case
mysql-test/t/sp.test:
  Bug #33811: test case
sql/sql_base.cc:
  Bug #33811: cache the table for Item_fields created by expanding '*'
sql/sql_select.cc:
  Bug #33811: maintain a correct name resolution chain when
  flattening joins.
2008-10-17 17:55:06 +03:00
Georgi Kodinov
e7a6e86f78 Bug #38637: COUNT DISTINCT prevents NULL testing in HAVING clause
IS NULL was not checking the correct row in a HAVING context.
At the first row of a new group (where the HAVING clause is evaluated)
the column and SELECT list references in the HAVING clause should 
refer to the last row of the previous group and not to the current one. 
This was not done for IS NULL, because it was using Item::is_null() doesn't
have a  Item_is_null_result() counterpart to access the data from the 
last row of the previous group. Note that all the Item::val_xxx() functions 
(e.g. Item::val_int()) have their _result counterparts (e.g. Item::val_int_result()).

Fixed by implementing a is_null_result() (similarly to int_result()) and
calling this instead of is_null() column and SELECT list references inside
the HAVING clause.

mysql-test/r/having.result:
  Bug #38637: test case
mysql-test/t/having.test:
  Bug #38637: test case
sql/item.cc:
  Bug #38637: implement Item::is_null_result() and call it
  from Item_ref and Item_field as appropriate.
sql/item.h:
  Bug #38637: implement Item::is_null_result() and call it
  from Item_ref and Item_field as appropriate.
sql/item_func.cc:
  Bug #38637: implement Item::is_null_result() and call it
  from Item_ref and Item_field as appropriate.
sql/item_func.h:
  Bug #38637: implement Item::is_null_result() and call it
  from Item_ref and Item_field as appropriate.
2008-10-17 13:55:16 +03:00
Gleb Shchepa
b591793496 Bug #39844: Query Crash Mysql Server 5.0.67
Server crashed during a sort order optimization
of a dependent subquery:

SELECT
    (SELECT t1.a FROM t1, t2
      WHERE t1.a = t2.b AND t2.a = t3.c
      ORDER BY t1.a)
  FROM t3;


Bitmap of tables, that the reference to outer table
column uses, in addition to the regular table bit
has the OUTER_REF_TABLE_BIT bit set.
The only_eq_ref_tables function traverses this map
bit by bit simultaneously with join->map2table list.
Obviously join->map2table never contains an entry
for the OUTER_REF_TABLE_BIT pseudo-table, so the
server crashed there.


The only_eq_ref_tables function has been modified
to traverse regular table bits only like the
update_depend_map function (resetting of the
OUTER_REF_TABLE_BIT there is enough, but
resetting of the whole set of PSEUDO_TABLE_BITS
is used there for sure).


mysql-test/r/order_by.result:
  Added test case for bug #39844.
mysql-test/t/order_by.test:
  Added test case for bug #39844.
sql/sql_select.cc:
  Bug #39844: Query Crash Mysql Server 5.0.67
  
  The only_eq_ref_tables function has been modified
  to traverse regular table bits only like the
  update_depend_map function (resetting of the
  OUTER_REF_TABLE_BIT there is enough, but
  resetting of the whole set of PSEUDO_TABLE_BITS
  is used there for sure).
2008-10-16 21:37:17 +05:00
Davi Arnaut
3ad228d7fb Bug#37075: offset of limit clause might be truncated on 32-bits server w/o big tables
The problem is that the offset argument of the limit clause
might be truncated on a 32-bits server built without big
tables support. The truncation was happening because the
original 64-bits long argument was being cast to a 32-bits
(ha_rows) offset counter.

The solution is to check if the conversing resulted in value
truncation and if so, the offset is set to the maximum possible
value that can fit on the type.

mysql-test/r/limit.result:
  Add test case result for Bug#37075
mysql-test/t/limit.test:
  Add test case for Bug#37075
sql/sql_lex.cc:
  Check for truncation of the offset value. If value was
  truncated, set to the maximum possible value.
2008-10-15 18:34:51 -03:00
Georgi Kodinov
747351836c Bug #38693: leaked memory with blobs!
If delayed insert fails to upgrade the lock it was not
freeing the temporary memory storage used to keep
newly constructed blob values in memory.
Fixed by iterating over the remaining rows in the delayed
insert rowset and freeing the blob storage for each row.

No test suite because it involves concurrent delayed inserts 
on a table and cannot easily be made deterministic. 

Added a correct valgrind suppression for Fedora 9.

mysql-test/valgrind.supp:
  Added a vagrind suppression for Fedora 9
sql/sql_insert.cc:
  Bug #38693: free the blobs temp storage on error.
2008-10-15 16:55:52 +03:00
Kristofer Pettersson
7fa3897e8a automerge 2008-10-15 12:06:44 +02:00
Davi Arnaut
017307f216 Bug#38823: Invalid memory access when a SP statement does wildcard expansion
The problem is that field names constructed due to wild-card
expansion done inside a stored procedure could point to freed
memory if the expansion was performed after the first call to
the stored procedure.

The problem was solved by patch for Bug#38691. The solution
was to allocate the database, table and field names in the
in the statement memory instead of table memory.

mysql-test/r/sp.result:
  Add test case result for Bug#38823
mysql-test/t/sp.test:
  Add test case for Bug#38823
sql/item.cc:
  Remark that this also impacts wildcard expansion inside SPs.
2008-10-14 11:04:36 -03:00
Kristofer Pettersson
d02b8a3bcc Bug#37416 When SQL_NO_CACHE is used, MySQL still lookup into the query cache
The query cache module did not check for the SQL_NO_CACHE keyword before
attempting to query the hash lookup table. This had a small performance impact.
      
By introducing a check on the query string before obtaining the hash mutex
we can gain some performance if the SQL_NO_CACHE directive is used often.
2008-10-14 15:41:35 +02:00
Georgi Kodinov
9b6347f0ab merged 5.0-main -> 5.0-bugteam 2008-10-10 17:27:16 +03:00
Gleb Shchepa
097b60bd06 Bug #37894: Assertion in init_read_record_seq in handler.h line 1444
Select with a "NULL NOT IN" condition containing complex
subselect from the same table as in the outer select failed
with an assertion.


The failure was caused by a concatenation of circumstances:
1) an inner select was optimized by make_join_statistics to use
   the QUICK_RANGE_SELECT access method (that implies an index
   scan of the table);
2) a subselect was independent (constant) from the outer select;
3) a condition was pushed down into inner select.

During the evaluation of a constant IN expression an optimizer
temporary changed the access method from index scan to table
scan, but an engine handler was already initialized for index
access by make_join_statistics. That caused an assertion.


Unnecessary index initialization has been removed from
the QUICK_RANGE_SELECT::init method (QUICK_RANGE_SELECT::reset
reinvokes this initialization).


mysql-test/r/subselect3.result:
  Added test case for bug #37894.
mysql-test/t/subselect3.test:
  Added test case for bug #37894.
sql/opt_range.cc:
  Bug #37894: Assertion in init_read_record_seq in handler.h line 1444
  
  Unnecessary index initialization has been removed from
  the QUICK_RANGE_SELECT::init method (QUICK_RANGE_SELECT::reset
  reinvokes this initialization).
2008-10-10 15:27:58 +05:00
Gleb Shchepa
8bfbcbd981 Bug #39283: Date returned as VARBINARY to client for queries
with COALESCE and JOIN

The server returned to a client the VARBINARY column type
instead of the DATE type for a result of the COALESCE,
IFNULL, IF, CASE, GREATEST or LEAST functions if that result
was filesorted in an anonymous temporary table during
the query execution.

For example:
  SELECT COALESCE(t1.date1, t2.date2) AS result
    FROM t1 JOIN t2 ON t1.id = t2.id ORDER BY result;


To create a column of various date/time types in a
temporary table the create_tmp_field_from_item() function
uses the Item::tmp_table_field_from_field_type() method
call. However, fields of the MYSQL_TYPE_NEWDATE type were
missed there, and the VARBINARY columns were created
by default.
Necessary condition has been added.


mysql-test/r/metadata.result:
  Added test case for bug #39283.
mysql-test/t/metadata.test:
  Added test case for bug #39283.
sql/sql_select.cc:
  Bug #39283: Date returned as VARBINARY to client for queries
              with COALESCE and JOIN
  
  To create a column of various date/time types in a
  temporary table the create_tmp_field_from_item() function
  uses the Item::tmp_table_field_from_field_type() method
  call. However, fields of the MYSQL_TYPE_NEWDATE type were
  missed there, and the VARBINARY columns were created
  by default.
  Necessary condition has been added.
2008-10-10 15:13:12 +05:00
Gleb Shchepa
a83f5b18ef Bug#38499: flush tables and multitable table update with
derived table cause crash

When a multi-UPDATE command fails to lock some table, and
subsequently succeeds, the tables need to be reopened if
they were altered. But the reopening procedure failed for
derived tables.

Extra cleanup has been added.


mysql-test/r/lock_multi.result:
  Added test case for bug #38499.
mysql-test/t/lock_multi.test:
  Added test case for bug #38499.
sql/sql_union.cc:
  Bug#38499: flush tables and multitable table update with
             derived table cause crash
  
  Obsolete assertion has been removed.
sql/sql_update.cc:
  Bug#38499: flush tables and multitable table update with
             derived table cause crash
  
  Extra cleanup for derived tables has been added:
  1) unit.cleanup(),
  2) unit->reinit_exec_mechanism().
2008-10-09 20:24:31 +05:00
Kristofer Pettersson
f985e78775 Bug#24289 Status Variable "Questions" gets wrong values with Stored Routines
When running Stored Routines the Status Variable "Questions" was wrongly
incremented. According to the manual it should contain the "number of
statements that clients have sent to the server"
              
Introduced a new status variable 'questions' to replace the query_id
variable which currently corresponds badly with the number of statements
sent by the client.
            
The new behavior is ment to be backward compatible with 4.0 and at the
same time work with new features in a similar way.
            
This is a backport from 6.0

mysql-test/r/status2.result:
  Added test case
mysql-test/t/status2.test:
  Added test case
sql/mysqld.cc:
  Introduced a new status variable 'questions' to replace the query_id
  variable which currently corresponds badly with the number of statements
  sent by the client.
sql/sql_class.h:
  Introduced a new status variable 'questions' to replace the query_id
  variable which currently corresponds badly with the number of statements
  sent by the client.
sql/sql_parse.cc:
  To be backward compatible with 4.0 and at the same time extend the 
  interpretation of the Question variable, it should be increased on
  all COM-commands but COM_STATISTICS, COM_PING, COM_STMT_PREPARE,
  COM_STMT_CLOSE and COM_STMT_RESET.
  Since COM_QUERY can process multiple statements, there has to be an
  extra increase there as well.
sql/sql_show.cc:
  Removed deprecated SHOW_QUESTION status code.
sql/structs.h:
  Removed deprecated SHOW_QUESTION status code.
2008-10-09 09:26:42 +02:00
Georgi Kodinov
7b628ade5f merged 5.0-5.1.29-rc -> 5.0-bugteam 2008-10-08 11:36:24 +03:00
Gleb Shchepa
f48b42e776 Bug #38691: segfault/abort in ``UPDATE ...JOIN'' while
``FLUSH TABLES WITH READ LOCK''

Concurrent execution of 1) multitable update with a
NATURAL/USING join and 2) a such query as "FLUSH TABLES
WITH READ LOCK" or "ALTER TABLE" of updating table led
to a server crash.


The mysql_multi_update_prepare() function call is optimized
to lock updating tables only, so it postpones locking to
the last, and if locking fails, it does cleanup of modified
syntax structures and repeats a query analysis.  However,
that cleanup procedure was incomplete for NATURAL/USING join
syntax data: 1) some Field_item items pointed into freed
table structures, and 2) the TABLE_LIST::join_columns fields
was not reset.

Major change:
  short-living Field *Natural_join_column::table_field has
  been replaced with long-living Item*.


mysql-test/r/lock_multi.result:
  Added test case for bug #38691.
mysql-test/t/lock_multi.test:
  Added test case for bug #38691.
sql/item.cc:
  Bug #38691: segfault/abort in ``UPDATE ...JOIN'' while
            ``FLUSH TABLES WITH READ LOCK''
  
  The Item_field constructor has been modified to allocate
  and copy original database/table/field names always (not
  during PS preparation/1st execution only), because
  an initialization of Item_field items with a pointer to
  short-living Field structures is a common practice.
sql/sql_base.cc:
  Bug #38691: segfault/abort in ``UPDATE ...JOIN'' while
            ``FLUSH TABLES WITH READ LOCK''
  
  1) Type adjustment for Natural_join_column::table_field
     (Field to Item_field);
  2) The setup_natural_join_row_types function has been
     updated to take into account new
     first_natural_join_processing flag to skip unnecessary
     reinitialization of Natural_join_column::join_columns
     during table reopening after lock_tables() failure
     (like the 'first_execution' flag for PS).
sql/sql_lex.cc:
  Bug #38691: segfault/abort in ``UPDATE ...JOIN'' while
            ``FLUSH TABLES WITH READ LOCK''
  
  Initialization of the new
  st_select_lex::first_natural_join_processing flag has
  been added.
sql/sql_lex.h:
  Bug #38691: segfault/abort in ``UPDATE ...JOIN'' while
            ``FLUSH TABLES WITH READ LOCK''
  
  The st_select_lex::first_natural_join_processing flag
  has been added to skip unnecessary rebuilding of
  NATURAL/USING JOIN structures during table reopening
  after lock_tables failure.
sql/sql_update.cc:
  Bug #38691: segfault/abort in ``UPDATE ...JOIN'' while
            ``FLUSH TABLES WITH READ LOCK''
  
  Extra cleanup calls have been added to reset
  Natural_join_column::table_field items.
sql/table.cc:
  Bug #38691: segfault/abort in ``UPDATE ...JOIN'' while
            ``FLUSH TABLES WITH READ LOCK''
  
  Type adjustment for Natural_join_column::table_field
  (Field to Item_field).
sql/table.h:
  Bug #38691: segfault/abort in ``UPDATE ...JOIN'' while
            ``FLUSH TABLES WITH READ LOCK''
  
  Type of the Natural_join_column::table_field field has
  been changed from Field that points into short-living
  TABLE memory to long-living Item_field that can be
  linked to (fixed) reopened table.
2008-10-08 02:34:00 +05:00
Georgi Kodinov
5a3086221d merged 5.0-5.1.29-rc -> 5.0-bugteam 2008-10-07 18:24:25 +03:00
Sergey Glukhov
d51e2c0760 Bug#35924 DEFINER should be stored 'quoted' in I_S
The '@' symbol can not be used in the host name according to rfc952.
The fix:
added function check_host_name(LEX_STRING *str)
which checks that all symbols in host name string are valid and
host name length is not more than max host name length
(just moved check_string_length() function from the parser into check_host_name()).


mysql-test/r/create.result:
  test result
mysql-test/t/create.test:
  test case
sql/mysql_priv.h:
  added function check_host_name(LEX_STRING *str)
sql/sql_parse.cc:
  added function check_host_name(LEX_STRING *str)
  which checks that all symbols in host name string are valid and
  host name length is not more than max host name length(HOSTNAME_LENGTH).
sql/sql_yacc.yy:
  using newly added function check_host_name()
2008-10-02 16:57:52 +05:00
Sergey Glukhov
7e60f71001 Bug#22763 Disrepancy between SHOW CREATE VIEW and I_S.VIEWS
The problem:
I_S views table does not check the presence of SHOW_VIEW_ACL|SELECT_ACL
privileges for a view. It leads to discrepancy between SHOW CREATE VIEW
and I_S.VIEWS.
The fix:
added appropriate check.


mysql-test/r/information_schema_db.result:
  test result
mysql-test/t/information_schema_db.test:
  test case
sql/sql_show.cc:
  The problem:
  I_S views table does not check the presence of SHOW_VIEW_ACL|SELECT_ACL
  privileges for a view. It leads to discrepancy between SHOW CREATE VIEW
  and I_S.VIEWS.
  The fix:
  added appropriate check.
2008-10-02 14:37:07 +05:00
Ramil Kalimullin
1ce81aac15 merge 2008-10-02 13:10:06 +05:00
Georgi Kodinov
eb3c08069d Bug#37943: Reproducible mysqld crash/sigsegv in sel_trees_can_be_ored
When analyzing the possible index use cases the server was re-using an internal structure.
This is wrong, as this internal structure gets updated during the analysis.
Fixed by making a copy of the internal structure for every place it needs to be used.
Also stopped the generation of empty SEL_TREE structures that unnecessary 
complicate the analysis.

mysql-test/r/index_merge.result:
  Bug#37943: test case
mysql-test/t/index_merge.test:
  Bug#37943: test case
sql/opt_range.cc:
  Bug#37943: 
   - Make copy constructors for SEL_TREE and sub-structures and use them when OR-ing trees.
   - don't generate empty SEL_TREEs. Return NULL instead.
2008-10-01 18:50:55 +03:00
Ramil Kalimullin
d3e317d16b Fix for bug#39182: Binary log producing incompatible character set query
from stored procedure. 

Problem: we replace all references to local variables in stored procedures     
with NAME_CONST(name, value) logging to the binary log. However, if the
value's collation differs we might get an 'illegal mix of collation'           
error as we don't pass the collation to the function.

Fix: pass the value's collation to NAME_CONST().

Note: actually we should pass to NAME_CONST() the value's derivation as well.
It's impossible without the parser modifying. Now we always set the 
derivation to DERIVATION_IMPLICIT, the same as local variables have.


mysql-test/r/binlog.result:
  Fix for bug#39182: Binary log producing incompatible character set query
  from stored procedure.
    - test result.
mysql-test/r/ctype_cp932_binlog.result:
  Fix for bug#39182: Binary log producing incompatible character set query
  from stored procedure.
    - results adjusted.
mysql-test/r/rpl_sp.result:
  Fix for bug#39182: Binary log producing incompatible character set query
  from stored procedure.
    - results adjusted.
mysql-test/t/binlog.test:
  Fix for bug#39182: Binary log producing incompatible character set query
  from stored procedure.
    - test case.
sql/item.cc:
  Fix for bug#39182: Binary log producing incompatible character set query
  from stored procedure.
    - allow NAME_CONST() to get _charset'foo' COLLATE 'bar' strings
  (see Item_func_set_collation).
sql/sp_head.cc:
  Fix for bug#39182: Binary log producing incompatible character set query
  from stored procedure. 
    - pass the value's collation to NAME_CONST().
2008-10-01 14:48:47 +05:00
Georgi Kodinov
dca2c113c6 merged 5.0-5.1.29-rc into 5.0-bugteam 2008-10-01 12:41:13 +03:00
Gleb Shchepa
3c9d4ea821 Fixed bug #17823: 'arc' directories inside database directories.
Server created "arc" directories inside database directories and
maintained there useless copies of .frm files.

Creation and renaming procedures of those copies as well as
creation of "arc" directories has been discontinued.
Removal procedure has been kept untouched to be able to
cleanup existent database directories by the DROP DATABASE
query. Also view renaming procedure has been updated to remove
these directories.


sql/parse_file.cc:
  Fixed bug #17823: 'arc' directories inside database directories.
  View/table creation and renaming procedures maintained
  backup copies of .frm files. Those copies are unused yet,
  so this feature was incomplete and unnecessary.
  
  1. Unwanted code has been hidden by FRM_ARCHIVE ifdefs
  (the FRM_ARCHIVE macro is not defined).
  
  2. Renaming procedure has been modified to remove obsolete
  "arc" directories.
sql/parse_file.h:
  Fixed bug #17823: 'arc' directories inside database directories.
  The "thd" parameter has been added to the rename_in_schema_file()
  function.
sql/sql_db.cc:
  Fixed bug #17823: 'arc' directories inside database directories.
  Scope of the mysql_rm_arc_files() function has been changed to
  global for use from the parse_file.cc file.
sql/sql_view.cc:
  Fixed bug #17823: 'arc' directories inside database directories.
  Added the "thd" argument to rename_in_schema_file() calls.
2008-09-30 17:50:28 +05:00
Alexey Botchkov
ce64a16b75 Bug#37949 Crash if argument to SP is a subquery that returns more than one row
JOIN for the subselect wasn't cleaned if we came upon an error
     during sub_select() execution. That leads to the assertion failure
     in close_thread_tables()

     part of the 6.0 code backported

per-file comments:
  mysql-test/r/sp-error.result
Bug#37949 Crash if argument to SP is a subquery that returns more than one row 
    test result

  mysql-test/t/sp-error.test
Bug#37949 Crash if argument to SP is a subquery that returns more than one row 
    test case

  sql/sp_head.cc
Bug#37949 Crash if argument to SP is a subquery that returns more than one row 
    lex->unit.cleanup() call added if not substatement
2008-09-29 19:11:34 +05:00
Kristofer Pettersson
119c5aaeba Automerge 2008-09-20 16:45:39 +02:00
Kristofer Pettersson
f0352e346a Bug#38469 invalid memory read and/or crash with utf8 text field, stored procedure, uservar
A stored procedure involving substrings could crash the server on certain
platforms because of invalid memory reads.
          
During storing the new blob-field value, the cached value's address range
overlapped that of the new field value. This caused problems when the 
cached value storage was reallocated to provide access for a new 
characater set representation. The patch checks the address ranges, and if
they overlap, the new field value is copied to a new storage before it is
converted to the new character set.


mysql-test/r/sp.result:
  Added result set
mysql-test/t/sp.test:
  Added test case
sql/field.cc:
  The source and destination address ranges of a character conversion must not overlap or the 'from' address will be invalidated as the temporary value-
  object is re-allocated to fit the new character set.
sql/field.h:
  Added comments
2008-09-20 10:51:03 +02:00
Georgi Kodinov
71fe190172 Bug #39353: Multiple conditions on timestamp column crashes server
The fix for bug 31887 was incomplete : it assumes that all the 
field types returned by the IS_NUM macro are descendants of 
Item_num and tries to zero-fill the values before doing constant
substitution with such fields when they are compared to constant string
values.
The only exception to this is Field_timestamp : it's in the IS_NUM
macro, but is not a descendant of Field_num.
Fixed by excluding timestamp fields (Field_timestamp) when zero-filling
when converting the constant to compare with to a string.
Note that this will not exclude the timestamp columns from const 
propagation.

mysql-test/r/compare.result:
  Bug #39353: test case
mysql-test/t/compare.test:
  Bug #39353: test case
sql/item.cc:
  Bug #39353: don't zero-fill timestamp fields when const propagating
  to a string : they'll be converted to a string in a date/time format
  and not as an integer.
2008-09-18 15:55:36 +03:00
Tatiana A. Nurnberg
8d10051b9a auto-merge 2008-09-17 17:44:15 +02:00
Tatiana A. Nurnberg
2f082d9d42 Bug#37114: sql_mode NO_BACKSLASH_ESCAPES does not work properly with LOAD DATA INFILE
NO_BACKSLASH_ESCAPES was not heeded in LOAD DATA INFILE
and SELECT INTO OUTFILE.  It is now.

mysql-test/r/loaddata.result:
  Show that SQL-mode NO_BACKSLASH_ESCAPES is heeded in
  INFILE/OUTFILE, and that dump/restore cycles work!
mysql-test/t/loaddata.test:
  Show that SQL-mode NO_BACKSLASH_ESCAPES is heeded in
  INFILE/OUTFILE, and that dump/restore cycles work!
sql/sql_class.cc:
  Add function to enquire whether ESCAPED BY was given.
  When doing SELECT...OUTFILE, use ESCAPED BY if specifically
  given; otherwise use sensible default value depending on
  SQL-mode features NO_BACKSLASH_ESCAPES.
sql/sql_class.h:
  Add function to enquire whether ESCAPED BY was given.
sql/sql_load.cc:
  When doing LOAD DATA INFILE, use ESCAPED BY if specifically
  given; otherwise use sensible default value depending on
  SQL-mode features NO_BACKSLASH_ESCAPES.
2008-09-17 08:34:00 +02:00
Vladislav Vaintroub
a4987b4433 Bug#35987 - post-review fix
Correct usage of strncat() in get_symbol_path()

3rd parameter to strncat is changed to be count of 
remaining bytes in the output buffer minus 1.
2008-09-16 13:16:41 +02:00
Vladislav Vaintroub
5343b7ae59 Bug#35987 - crash report on windows doesn't resolve stack traces.
The problem here is that symbols can not be loaded, because symbol
path is not set and  default path does not include the directory
where PDB is located.

The problem is _not_ reproducible on the same machine where
mysqld.exe is built - if PDB is not found in the symbol path,
dbghelp would fallback to fully qualified PDB path as given in the
executable header and on the build host this will succeed.

The solution is to calculate symbol path and pass it to SymInitialize()
call.
2008-09-15 14:58:32 +02:00
Ramil Kalimullin
776793a97c Fix for bug#37526: asymertic operator <=> in trigger
Problem: <=> operator may return wrong results 
comparing NULL and a DATE/DATETIME/TIME value.

Fix: properly check NULLs.


mysql-test/r/type_datetime.result:
  Fix for bug#37526: asymertic operator <=> in trigger
    - test result.
mysql-test/t/type_datetime.test:
  Fix for bug#37526: asymertic operator <=> in trigger
    - test case.
sql/item_cmpfunc.cc:
  Fix for bug#37526: asymertic operator <=> in trigger
    - if is_nulls_eq is TRUE Arg_comparator::compare_datetime() 
  should return 1 only if both arguments are NULL.
2008-09-09 20:05:27 +05:00
Ramil Kalimullin
788be2aebd Fix for bug #39021: SELECT REGEXP BINARY NULL never returns
Problem: SELECT ... REGEXP BINARY NULL may lead to server crash/hang.

Fix: properly handle NULL regular expressions.


mysql-test/r/func_regexp.result:
  Fix for bug #39021: SELECT REGEXP BINARY NULL never returns
    - test result.
mysql-test/t/func_regexp.test:
  Fix for bug #39021: SELECT REGEXP BINARY NULL never returns
    - test case.
sql/item_cmpfunc.cc:
  Fix for bug #39021: SELECT REGEXP BINARY NULL never returns
    - checking regular expressions' null_value
  we tested it without a val_xxx() call before, which is wrong.
  Now Item_func_regex::regcomp() returns -1 in the case
  and allows to handle NULL expessions properly.
sql/item_cmpfunc.h:
  Fix for bug #39021: SELECT REGEXP BINARY NULL never returns
    - checking regular expressions' null_value
  we tested it without a val_xxx() call before, which is wrong.
  Now Item_func_regex::regcomp() returns -1 in the case
  and allows to handle NULL expessions properly.
2008-09-05 13:30:01 +05:00
Ramil Kalimullin
bcbff0b93b Merge 2008-09-05 12:48:56 +05:00
Ramil Kalimullin
f0a50bd969 Fix for bug#38821: Assert table->auto_increment_field_not_null failed
in open_table()

Problem: repeating "CREATE... ( AUTOINCREMENT) ... SELECT" may lead to
an assertion failure.

Fix: reset table->auto_increment_field_not_null after each record 
writing.


mysql-test/r/create.result:
  Fix for bug#38821: Assert table->auto_increment_field_not_null failed 
  in open_table()
    - test result.
mysql-test/t/create.test:
  Fix for bug#38821: Assert table->auto_increment_field_not_null failed 
  in open_table()
    - test case.
sql/sql_insert.cc:
  Fix for bug#38821: Assert table->auto_increment_field_not_null failed 
  in open_table()
    - reset table->auto_increment_field_not_null after writing a record
  for "{CREATE, INSERT}..SELECT".
2008-09-03 15:17:19 +05:00
Gleb Shchepa
dd1d9adbb0 merge with local tree 2008-09-03 12:59:48 +05:00
Gleb Shchepa
59b9d50c8a Bug #39002: The server crashes on the query:
INSERT .. SELECT .. ON DUPLICATE KEY UPDATE col=DEFAULT

In order to get correct values from update fields that
belongs to the SELECT part in the INSERT .. SELECT .. ON
DUPLICATE KEY UPDATE statement, the server adds referenced
fields to the select list. Part of the code that does this
transformation is shared between implementations of
the DEFAULT(col) function and the DEFAULT keyword (in
the col=DEFAULT expression), and an implementation of
the DEFAULT keyword is incomplete.


mysql-test/r/default.result:
  Added test case for bug #39002.
mysql-test/t/default.test:
  Added test case for bug #39002.
sql/item.cc:
  The Item_default_value::transform() function has been
  modified to take into account the fact that the DEFAULT
  keyword has no arguments unlike the DEFAULT(col) function
  that always has an argument.
2008-09-03 12:32:43 +05:00
Gleb Shchepa
54a59681d6 Bug #37799: SELECT with a BIT column in WHERE clause
returns unexpected result

If:
  1. a table has a not nullable BIT column c1 with a length
     shorter than 8 bits and some additional not nullable
     columns c2 etc, and
  2. the WHERE clause is like: (c1 = constant) AND c2 ...,
the SELECT query returns unexpected result set.


The server stores BIT columns in a tricky way to save disk
space: if column's bit length is not divisible by 8, the
server places reminder bits among the null bits at the start
of a record. The rest bytes are stored in the record itself,
and Field::ptr points to these rest bytes.

However if a bit length of the whole column is less than 8,
there are no remaining bytes, and there is nothing to store in
the record at its regular place. In this case Field::ptr points
to bytes actually occupied by the next column in a record.
If both columns (BIT and the next column) are NOT NULL,
the Field::eq function incorrectly deduces that this is the
same column, so query transformation/equal item elimination
code (see build_equal_items_for_cond) may mix these columns
and damage conditions containing references to them.


mysql-test/r/type_bit.result:
  Added test case for bug #37799.
mysql-test/t/type_bit.test:
  Added test case for bug #37799.
sql/field.h:
  1. The Field::eq function has been modified to take types of
  comparing columns into account to distinguish between BIT and
  not BIT columns referencing the same bytes in a record.
  
  2. Unnecessary type comparison has been removed from the
  Field_bit::eq function (moved to Field::eq).
2008-08-28 02:10:37 +05:00
Evgeny Potemkin
06bf25e4d4 Bug#38195: Incorrect handling of aggregate functions when loose index scan is
used causes server crash.
      
When the loose index scan access method is used values of aggregated functions
are precomputed by it. Aggregation of such functions shouldn't be performed
in this case and functions should be treated as normal ones.
The create_tmp_table function wasn't taking this into account and this led to
a crash if a query has MIN/MAX aggregate functions and employs temporary table
and loose index scan.
Now the JOIN::exec and the create_tmp_table functions treat MIN/MAX aggregate
functions as normal ones when the loose index scan is used.


mysql-test/r/group_min_max.result:
  Added a test case for the bug#38195.
mysql-test/t/group_min_max.test:
  Added a test case for the bug#38195.
sql/sql_select.cc:
  Bug#38195: Incorrect handling of aggregate functions when loose index scan is
  used causes server crash.
  The JOIN::exec and the create_tmp_table functions treat MIN/MAX aggregate
  functions as normal ones when the loose index scan is used.
2008-08-27 17:03:17 +04:00
Sergey Petrunia
c770161ae8 BUG#36639: subselect.test crashes on 64 bit pentium4 when compiled for valgrind, commit into 5.0
- Use the compiler's default copy constructor for QUICK_RANGE_SELECT. 
  bcopy(this, copy, ...) call caused some odd action on gcc-4.1.2 on x86_64

sql/opt_range.cc:
  BUG#36639: subselect.test crashes on 64 bit pentium4 when compiled for valgrind
  - Set QUICK_SELECT_DESC not to use MRR implementation (code moved to here
    from opt_range.h)
sql/opt_range.h:
  BUG#36639: subselect.test crashes on 64 bit pentium4 when compiled for valgrind
  - Use the compiler's default copy constructor for QUICK_RANGE_SELECT. 
    bcopy(this, copy, ...) call caused some odd action on gcc-4.1.2 on x86_64
2008-08-25 21:02:54 +04:00
Alexey Botchkov
8d3eb141e0 merging fix 2008-08-26 13:32:43 +05:00
Sergey Glukhov
c546559a62 Bug#37428 Potential security issue with UDFs - linux shellcode execution.
plugin_dir option backported from 5.1

mysql-test/r/udf.result:
  result fix
sql/mysql_priv.h:
  opt_plugin_dir and opt_plugin_dir_ptr declared.
sql/mysqld.cc:
  'plugin_dir' option added
sql/set_var.cc:
  'plugin_dir' option added.
sql/sql_udf.cc:
  opt_plugin_dir added to the udf->dl path. Warn if it's not specified.
sql/unireg.h:
  PLUGINDIR defined.
2008-08-25 17:11:59 +05:00
Alexey Botchkov
ec524d50a8 Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY.
test_if_data_home_dir fixed to look into real path.
            Checks added to mi_open for symlinks into data home directory.

per-file messages:
        include/my_sys.h
          Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY.
          
          my_is_symlink interface added
        include/myisam.h
          Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY.
          
          myisam_test_invalid_symlink interface added
        myisam/mi_check.c
          Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY.
          
          mi_open_datafile calls modified
        myisam/mi_open.c
          Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY.
          
          code added to mi_open to check for symlinks into data home directory.
          mi_open_datafile now accepts 'original' file path to check if it's
          an allowed symlink.
        myisam/mi_static.c
          Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY.
          
          myisam_test_invlaid_symlink defined
        myisam/myisamchk.c
          Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY.
          
          mi_open_datafile call modified
        myisam/myisamdef.h
          Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY.
          
          mi_open_datafile interface modified - 'real_path' parameter added
        mysql-test/r/symlink.test
          Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY.
          
          error codes corrected as some patch now rejected pointing inside datahome
        mysql-test/r/symlink.result
          Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY.
          
          error messages corrected in the result
        mysys/my_symlink.c
          Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY.
          
          my_is_symlink() implementsd
          my_realpath() now returns the 'realpath' even if a file isn't a symlink
        sql/mysql_priv.h
          Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY.
          
          test_if_data_home_dir interface
        sql/mysqld.cc
          Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY.
          
          myisam_test_invalid_symlik set with the 'test_if_data_home_dir'
        sql/sql_parse.cc
          Bug#32167 another privilege bypass with DATA/INDEX DIRECTORY.
          
          error messages corrected
          test_if_data_home_dir code fixed
2008-08-22 17:31:53 +05:00
Sergey Glukhov
de73b72954 Bug#38291 memory corruption and server crash with view/sp/function
Send_field.org_col_name has broken value on secondary execution.
It happens when result field is created from the field which belongs to view
due to forgotten assignment of some Send_field attributes. 
The fix:
set Send_field.org_col_name,org_table_name with correct value during Send_field intialization.

mysql-test/r/metadata.result:
  result fix
  The result file was changed because now forgotten attributes are properly set.
mysql-test/r/sp.result:
  test result
mysql-test/t/sp.test:
  test case
sql/item.cc:
  Send_field.org_col_name has broken value on secondary execution.
  It happens when result field is created from the field which belongs to view
  due to forgotten assignment of some Send_field attributes. 
  The fix:
  set Send_field.org_col_name,org_table_name with correct value during Send_field intialization.
tests/mysql_client_test.c:
  test case fix
  The test was changed because now forgotten attributes are properly set.
2008-08-20 14:49:28 +05:00
Georgi Kodinov
40bd9a4218 merged 5.0-main to 5.0-bugteam 2008-08-19 14:55:36 +03:00
Georgi Kodinov
6387cac94b Bug#38195: Incorrect handling of aggregate functions when loose index scan
is used causes server crash.
  Revert the fix : unstable test case revealed by pushbuild
2008-08-19 13:36:24 +03:00
Chad MILLER
21598ea0e6 Bug#37301 Length and Max_length differ with no obvious reason(2nd version)
Length value is the length of the field,
Max_length is the length of the field value.
So Max_length can not be more than Length.
The fix: fixed calculation of the Item_empty_string item length

(Patch applied and queued on demand of Trudy/Davi.)

sql/item.h:
  fixed calculation of the item length
sql/sql_show.cc:
  removed unnecessary code
2008-08-15 16:13:27 -04:00
Ramil Kalimullin
2b179caf9a Fix for bug #34779: crash in checksum table on federated tables
with blobs containing nulls

Problem: FEDERATED SE improperly stores NULL fields in the record buffer.

Fix: store them properly.


mysql-test/r/federated.result:
  Fix for bug #34779: crash in checksum table on federated tables 
  with blobs containing nulls
    - test result.
mysql-test/t/federated.test:
  Fix for bug #34779: crash in checksum table on federated tables 
  with blobs containing nulls
    - test case.
sql/ha_federated.cc:
  Fix for bug #34779: crash in checksum table on federated tables 
  with blobs containing nulls
    - storing a NULL field in the record buffer
      we must initialize its data as other code
      may rely on it.
2008-08-15 11:40:05 +05:00
Evgeny Potemkin
b789b4f33c Bug#38195: Incorrect handling of aggregate functions when loose index scan is
used causes server crash.

When the loose index scan access method is used values of aggregated functions
are precomputed by it. Aggregation of such functions shouldn't be performed
in this case and functions should be treated as normal ones.
The create_tmp_table function wasn't taking this into account and this led to
a crash if a query has MIN/MAX aggregate functions and employs temporary table
and loose index scan.
Now the JOIN::exec and the create_tmp_table functions treat MIN/MAX aggregate
functions as normal ones when the loose index scan is used.


mysql-test/r/group_min_max.result:
  Added a test case for the bug#38195.
mysql-test/t/group_min_max.test:
  Added a test case for the bug#38195.
sql/sql_select.cc:
  Bug#38195: Incorrect handling of aggregate functions when loose index scan is
  used causes server crash.
  Now the JOIN::exec and the create_tmp_table functions treat MIN/MAX aggregate
  functions as normal ones when the loose index scan is used.
2008-08-13 22:24:55 +04:00
Timothy Smith
d7c36eb334 Merge some 5.0 innodb changes 2008-08-13 00:11:11 -06:00
Marc Alff
2f3b860305 Merge mysql-5.0-bugteam -> local bugfix branch 2008-08-11 15:21:29 -06:00
Marc Alff
e04dfffb59 Bug#38296 (low memory crash with many conditions in a query)
This fix is for 5.0 only : back porting the 6.0 patch manually

The parser code in sql/sql_yacc.yy needs to be more robust to out of
memory conditions, so that when parsing a query fails due to OOM,
the thread gracefully returns an error.

Before this fix, a new/alloc returning NULL could:
- cause a crash, if dereferencing the NULL pointer,
- produce a corrupted parsed tree, containing NULL nodes,
- alter the semantic of a query, by silently dropping token values or nodes

With this fix:
- C++ constructors are *not* executed with a NULL "this" pointer
when operator new fails.
This is achieved by declaring "operator new" with a "throw ()" clause,
so that a failed new gracefully returns NULL on OOM conditions.

- calls to new/alloc are tested for a NULL result,

- The thread diagnostic area is set to an error status when OOM occurs.
This ensures that a request failing in the server properly returns an
ER_OUT_OF_RESOURCES error to the client.

- OOM conditions cause the parser to stop immediately (MYSQL_YYABORT).
This prevents causing further crashes when using a partially built parsed
tree in further rules in the parser.

No test scripts are provided, since automating OOM failures is not
instrumented in the server.
Tested under the debugger, to verify that an error in alloc_root cause the
thread to returns gracefully all the way to the client application, with
an ER_OUT_OF_RESOURCES error.
2008-08-11 10:10:00 -06:00
Kristofer Pettersson
861c06f0b8 Automerge 2008-08-11 13:00:48 +02:00
Kristofer Pettersson
75a5ecbd72 Bug#38486 Crash when using cursor protocol
Server side cursors were not initialized properly and this caused a reference to
uninitialized memory.
2008-08-11 11:40:54 +02:00
Kristofer Pettersson
be7d4dc8ee automerge 2008-08-04 14:37:28 +02:00
Timothy Smith
dc593c3ec4 Cherry-pick InnoDB fixes for Bug#34286, Bug#35352, and Bug#36600 from snapshot
innodb-5.0-ss2475.

Bug #34286  Assertion failure in thread 2816 in file .\row\row0sel.c line 3500
Since autoinc init performs a MySQL SELECT query to determine the auto-inc
value, set prebuilt->sql_stat_start = TRUE so that it is performed like any
normal SELECT, regardless of the context in which it was invoked.


Bug #35352  If InnoDB crashes with UNDO slots full error the error persists on restart
We've added a heuristic that checks the size of the UNDO slots cache lists
(insert and upate). If either of cached lists has more than 500 entries then we
add any UNDO slots that are freed, to the common free list instead of the cache
list, this is to avoid the case where all the free slots end up in only one of
the lists on startup after a crash.

Tested with test case for 26590 and passes all mysql-test(s).

Bug #36600  SHOW STATUS takes a lot of CPU in buf_get_latched_pages_number
Fixed by removing the Innodb_buffer_pool_pages_latched variable from SHOW
STATUS output in non-UNIV_DEBUG compilation.
2008-07-31 15:47:57 -06:00
Georgi Kodinov
ae4a35fd5c Bug#37662 nested if() inside sum() is parsed in exponential time
min() and max() functions are implemented in MySQL as macros.
This means that max(a,b) is expanded to: ((a) > (b) ? (a) : (b))
Note how 'a' is quoted two times.
Now imagine 'a' is a recursive function call that's several 10s of levels deep.
And the recursive function does max() with a function arg as well to dive into
recursion.
This means that simple function call can take most of the clock time.
Identified and fixed several such calls to max()/min() : including the IF() 
sql function implementation.

mysql-test/r/func_if.result:
  Bug#37662 test case
mysql-test/t/func_if.test:
  Bug#37662 test case
sql/item.cc:
  Bug#37662 don't call expensive functions as arguments to min/max
sql/item_cmpfunc.cc:
  Bug#37662 don't call expensive functions as arguments to min/max
sql/item_func.cc:
  Bug#37662 don't call expensive functions as arguments to min/max
2008-07-30 14:07:37 +03:00
Kristofer Pettersson
0a415f62fd Bug#29738 Error message not properly translated to Serbian
Community contribution fix for Serbian translation in error message list.
2008-07-29 15:58:15 +02:00
Kristofer Pettersson
f0dfb82fcb Bug#37781 mysql_drop_user calls get_current_user() twice for no reason
Fixed typo and removed duplicate call to get_current_user.
2008-07-29 15:37:09 +02:00
Kristofer Pettersson
0b918cfd7d auto merge 2008-07-29 15:15:04 +02:00
Alexey Botchkov
2d590c2825 Bug#37428 Potential security issue with UDFs - linux shellcode execution.
plugin_dir option backported from 5.1

per-file messages:
  sql/mysql_priv.h
    Bug#37428 Potential security issue with UDFs - linux shellcode execution.
    
    opt_plugin_dir and opt_plugin_dir_ptr declared.
  sql/mysqld.cc
    Bug#37428 Potential security issue with UDFs - linux shellcode execution.
    
    'plugin_dir' option added
  sql/set_var.cc
    Bug#37428 Potential security issue with UDFs - linux shellcode execution.
    
    'plugin_dir' option added.
  sql/sql_udf.cc
    Bug#37428 Potential security issue with UDFs - linux shellcode execution.
    
    opt_plugin_dir added to the udf->dl path. Warn if it's not specified.
  sql/unireg.h
    Bug#37428 Potential security issue with UDFs - linux shellcode execution.
    
    PLUGINDIR defined.
2008-07-28 19:22:12 +05:00
Igor Babaev
7f615b2c14 Merge 2008-07-28 01:24:56 -07:00
Igor Babaev
b6e3a9e28c Fixed bug #38191.
Calling List<Cached_item>::delete_elements for the same list twice
caused a crash of the server in the function JOIN::cleaunup.
Ensured that delete_elements() in JOIN::cleanup would be called only once.


mysql-test/r/subselect.result:
  Added a test case for bug #38191.
mysql-test/t/subselect.test:
  Added a test case for bug #38191.
sql/sql_select.cc:
  Fixed bug #38191.
  Ensured that delete_elements() in JOIN::cleanup would be called only once.
2008-07-26 13:44:07 -07:00
Davi Arnaut
14887bb2ab Cherry-pick Bug#33362 from mysql-5.1 2008-07-24 11:14:34 -03:00
Georgi Kodinov
dd85aa78ba Bug#37830 : ORDER BY ASC/DESC - no difference
Range scan in descending order for c <= <col> <= c type of
ranges was ignoring the DESC flag.
However some engines like InnoDB have the primary key parts 
as a suffix for every secondary key.
When such primary key suffix is used for ordering ignoring 
the DESC is not valid.
But we generally would like to do this because it's faster.
            
Fixed by performing only reverse scan if the primary key is used.
Removed some dead code in the process.

mysql-test/r/innodb_mysql.result:
  Bug#37830 : test case
mysql-test/t/innodb_mysql.test:
  Bug#37830 : test case
sql/opt_range.cc:
  Bug#37830 : 
  - preserve and use used_key_parts to
    distinguish when a primary key suffix is used
  - removed some dead code
sql/opt_range.h:
  Bug#37830 : 
  - preserve used_key_parts
  - dead code removed
sql/sql_select.cc:
  Bug#37830 : Do only reverse order traversal
  if the primary key suffix is used.
2008-07-23 14:25:00 +03:00
Kristofer Pettersson
6da6bbc75e Auto merge 2008-07-21 12:24:31 +02:00
Kristofer Pettersson
b7d4c76a54 Bug#37027 expire_logs_days and missing binlogs cause a crash !
If the server failed to expired log files during start up it could crash.

sql/log.cc:
  Added predicate to protect againt cases when current_thd might be NULL.
2008-07-24 14:28:21 +02:00
Jonathan Perkin
2ade957b07 Merge from mysql-5.0.66-release 2008-07-17 17:39:33 +02:00
Georgi Kodinov
430aaacdaf Folow-up on Bug#37069: fix a valgrind warning
Don't initalize federated if it's disabled by a command line option.

sql/ha_federated.cc:
  Folow-up on Bug#37069: Don't initalize federated if it's disabled 
  by a command line option.
2008-07-17 17:33:41 +03:00
Marc Alff
95ca2c6d96 Bug#30087 Set query_cache_size, if the value is too small, get a unclear warning
Reverting the previous patch
2008-07-16 16:29:22 -06:00
Kristofer Pettersson
76bd3a55a6 Auto merged 2008-07-16 16:12:20 +02:00
Sergey Petrunia
7315a7002a Merge 2008-07-15 21:49:28 +04:00
Chad MILLER
a8cbbef15c Fixed packet-test bug caused by if block that didn't have curly braces. 2008-07-15 12:51:05 -04:00
Kristofer Pettersson
f81c2f070b auto merge 2008-07-15 17:29:26 +02:00
Sergey Petrunia
62513bb1bc BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
- In QUICK_INDEX_MERGE_SELECT::read_keys_and_merge: when we got table->sort from Unique,
  tell init_read_record() not to use rr_from_cache() because a) rowids are already sorted
  and b) it might be that the the data is used by filesort(), which will need record rowids
  (which rr_from_cache() cannot provide).
- Fully de-initialize the table->sort read in QUICK_INDEX_MERGE_SELECT::get_next(). This fixes BUG#35477.
(bk trigger: file as fix for BUG#35478).

sql/filesort.cc:
  BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
  - make find_all_keys() use quick->get_next() instead of init_read_record(r)/r.read_record() calls
  - added dbug printout
sql/mysql_priv.h:
  BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
  - Added parameter to init_read_record
sql/opt_range.cc:
  BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
  - In QUICK_INDEX_MERGE_SELECT::read_keys_and_merge: when we got table->sort from Unique,
    tell init_read_record() not to use rr_from_cache() because a) rowids are already sorted
    and b) it might be that the the data is used by filesort(), which will need record rowids
    (which rr_from_cache() cannot provide).
  - Fully de-initialize the table->sort read in QUICK_INDEX_MERGE_SELECT::get_next().
sql/records.cc:
  BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
  - Added disable_rr_cache parameter to init_read_record
  - Added comment
sql/sql_acl.cc:
  BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
  - Added parameter to init_read_record
sql/sql_delete.cc:
  BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
  - Added parameter to init_read_record
sql/sql_help.cc:
  BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
  - Added parameter to init_read_record
sql/sql_select.cc:
  BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
  - Added parameter to init_read_record
sql/sql_table.cc:
  BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
  - Added parameter to init_read_record
sql/sql_udf.cc:
  BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
  - Added parameter to init_read_record
sql/sql_update.cc:
  BUG#35478: sort_union() returns bad data when sort_buffer_size is hit
  - Added parameter to init_read_record
2008-07-15 18:13:21 +04:00
Marc Alff
5f9f35e291 Merge 2008-07-14 15:47:34 -06:00
Marc Alff
e73e7bb9ae Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on
build)

The crash was caused by freeing the internal parser stack during the parser
execution.
This occured only for complex stored procedures, after reallocating the parser
stack using my_yyoverflow(), with the following C call stack:
- MYSQLparse()
- any rule calling sp_head::restore_lex()
- lex_end()
- x_free(lex->yacc_yyss), xfree(lex->yacc_yyvs)

The root cause is the implementation of stored procedures, which breaks the
assumption from 4.1 that there is only one LEX structure per parser call.

The solution is to separate the LEX structure into:
- attributes that represent a statement (the current LEX structure),
- attributes that relate to the syntax parser itself (Yacc_state),
so that parsing multiple statements in stored programs can create multiple
LEX structures while not changing the unique Yacc_state.

Now, Yacc_state and the existing Lex_input_stream are aggregated into
Parser_state, a structure that represent the complete state of the (Lexical +
Syntax) parser.


mysql-test/r/parser_stack.result:
  Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on
  build)
mysql-test/t/parser_stack.test:
  Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on
  build)
sql/sp.cc:
  Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on
  build)
sql/sp_head.cc:
  Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on
  build)
sql/sql_class.cc:
  Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on
  build)
sql/sql_class.h:
  Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on
  build)
sql/sql_lex.cc:
  Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on
  build)
sql/sql_lex.h:
  Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on
  build)
sql/sql_parse.cc:
  Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on
  build)
sql/sql_prepare.cc:
  Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on
  build)
sql/sql_trigger.cc:
  Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on
  build)
sql/sql_view.cc:
  Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on
  build)
sql/sql_yacc.yy:
  Bug#35577 (CREATE PROCEDURE causes either crash or syntax error depending on
  build)
2008-07-14 15:41:30 -06:00
Chad MILLER
a4e7283a92 Merge from 5.0 trunk. 2008-07-14 16:16:37 -04:00
Gleb Shchepa
d5077086f7 warning elimination 2008-07-11 04:51:58 +05:00
Gleb Shchepa
547ca13975 warning elimination 2008-07-11 02:32:54 +05:00
Chad MILLER
c425bf421d Merge chunk from trunk. 2008-07-10 14:50:07 -04:00
Chad MILLER
6a6e77eeff Merge chunk from trunk. 2008-07-10 14:47:53 -04:00
Tatiana A. Nurnberg
0833d66847 Bug#35848: UUID() returns UUIDs with the wrong time
offset for time part in UUIDs was 1/1000 of what it
should be. In other words, offset was off.

Also handle the case where we count into the future
when several UUIDs are generated in one "tick", and
then the next call is late enough for us to unwind
some but not all of those borrowed ticks.

Lastly, handle the case where we keep borrowing and
borrowing until the tick-counter overflows by also
changing into a new "numberspace" by creating a new
random suffix.


mysql-test/r/func_misc.result:
  Show that time-part of UUIDs is correct now.
mysql-test/t/func_misc.test:
  Show that time-part of UUIDs is correct now
  by replicating the C-code's resultin SQL.
  Results also decode to expect date-data on
  command-line (external validation).
  
  No test for unwinding of borrowed ticks as
  this a) is a race and b) depends on what timer
  we get.
sql/item_strfunc.cc:
  correct offset for date/time-part of UUID.
  also make sure that when we counted into
  the future earlier (several UUIDs generated
  in same tick), we only give back as many
  "borrowed" ticks as we can without duplicating
  past timestamps. If our tick-counter overflows
  before we can give back, or if the system-clock
  is set back (by user or Daylight Saving Time),
  we create a new random suffix to avoid
  collisions and clear the tick-counter.
2008-07-10 03:58:30 +02:00
Mats Kindahl
b93fcb9b0e Manual merge with mysql-5.0-bugteam 2008-07-08 10:37:42 +02:00
Marc Alff
c7724872d8 Bug#26030 (Parsing fails for stored routine w/multi-statement execution
enabled)

Before this fix, the lexer and parser would treat the ';' character as a
different token (either ';' or END_OF_INPUT), based on convoluted logic,
which failed in simple cases where a stored procedure is implemented as a
single statement, and used in a multi query.

With this fix:
- the character ';' is always parsed as a ';' token in the lexer,
- parsing multi queries is implemented in the parser, in the 'query:' rules,
- the value of thd->client_capabilities, which is the capabilities
  negotiated between the client and the server during bootstrap,
  is immutable and not arbitrarily modified during parsing (which was the
  root cause of the bug)
2008-07-07 10:00:08 -06:00
Mats Kindahl
914cae3a2d Bug #37150 Risk for crash in User_var_log_event::exec_event()
On certain kinds of errors (e.g., out of stack), a call to Item_func_
set_user_var::fix_fields() might fail.  Since the return value of this
call was not checked inside User_var_log_event::exec_event(), continuing
execution after this will cause a crash inside Item_func_set_user_var::
update_hash().

The bug is fixed by aborting execution of the event with an error if
fix_fields() fails, since it is not possible to continue execution anyway.


sql/log_event.cc:
  Aborting execution of event if fix_fields() fails since execution
  of update_hash() might cause a crash.
2008-07-07 09:58:27 +02:00
Gleb Shchepa
b83b4697d2 backport from 6.0
Bug#35658 (An empty binary value leads to mysqld crash)
        
Before this fix, the following token
  b''
caused the parser to crash when reading the binary value from the empty string.
The crash was caused by:
  ptr+= max_length - 1;
because max_length is unsigned and was 0, causing an overflow.
        
With this fix, an empty binary literal b'' is parsed as a binary value 0,
in Item_bin_string.

mysql-test/r/varbinary.result:
  Bug#35658 (An empty binary value leads to mysqld crash)
mysql-test/t/varbinary.test:
  Bug#35658 (An empty binary value leads to mysqld crash)
sql/item.cc:
  Bug#35658 (An empty binary value leads to mysqld crash)
2008-06-27 20:56:41 +05:00
Kristofer Pettersson
681236e100 Bug#30087 Set query_cache_size, if the value is too small, get a unclear warning
This bugs clarifies a warning message issued when the query cache data
size becomes smaller than the minium allowed size.



mysql-test/r/query_cache.result:
  New warning message when a too small value has been set for query cache
  size.
sql/set_var.cc:
  To avoid poluting the QC API the warning messages are moved into the 
  QC module.
sql/share/errmsg.txt:
  Changed error message so that minimal cache size always is hinted.
sql/sql_cache.cc:
  Modified the warning message so that the minimal cache size always is
  hinted.
      
  Added interface method Query_cache::get_minimal_size_limit().
sql/sql_cache.h:
  Modified the warning message so that the minimal cache size always is
  hinted.
      
  Added interface method Query_cache::get_minimal_size_limit().
2008-06-19 02:40:35 +02:00
Kristofer Pettersson
12db5ab0d6 Bug#21226 FLUSH PRIVILEGES does not provided feedback when it fails.
If during a FLUSH PRIVILEGES the server fails to load the new privilege
tables, the error message is lost. This patch is a back port from 5.1 which
adresses this issue by setting the server in an error state if a failure
occurrs.
  
This patch also corrects an incorrect variable assignment which might
cause an error state to be reverted by coincidence.

sql/sql_parse.cc:
  * Set error state if acl_reload or grant_reload fails.
  * Fix bad variable assignment which cancels previous error status.
2008-06-18 21:09:30 +02:00
Georgi Kodinov
1e17f242f3 atuomatically merged 5.0 main to 5.0-bugteam 2008-06-12 17:32:31 +03:00
Georgi Kodinov
da4cfa6d1e Bug#37069 (5.0): implement --skip-federated
mysql-test/r/federated_disabled.result:
  Bug#37069 (5.0): test case
mysql-test/t/federated_disabled-master.opt:
  Bug#37069 (5.0): test case
mysql-test/t/federated_disabled.test:
  Bug#37069 (5.0): test case
2008-06-03 13:12:37 +03:00
Alexander Barkov
c9232b936d Updating charset doc files.
Thanks to Paul for preparing the up-to-date files
reflecting 4.1 changes.
2008-05-28 15:03:47 +05:00
unknown
8bc987ab5b Merge host.loc:/work/bugs/5.0-bugteam-36676
into  host.loc:/work/bk/5.0-bugteam
2008-05-18 14:27:17 +05:00
unknown
29e7fa258d Fixed bug#36676: multiupdate using LEFT JOIN updates only
first row or fails with an error:
  ERROR 1022 (23000): Can't write; duplicate key in table ''

The server uses intermediate temporary table to store updated
row data.  The first column of this table contains rowid.
Current server implementation doesn't reset NULL flag of that
column even if the server fills a column with rowid.
To keep each rowid unique, there is an unique index.
An insertion into an unique index takes into account NULL
flag of key value and ignores real data if NULL flag is set.
So, insertion of actually different rowids may lead to two
kind of problems.  Visible effect of each of these problems
depends on an initial engine type of temporary table:

1. If multiupdate initially creates temporary table as
a MyISAM table (a table contains blob columns, and the
create_tmp_table function assumes, that this table is
large), it inserts only one single row and updates
only rows with one corresponding rowid. Other rows are
silently ignored. 

2. If multiupdate initially creates MEMORY temporary
table, fills it with data and reaches size limit for
MEMORY tables (max_heap_table_size), multiupdate
converts MEMORY table into MyISAM table and fails
with an error:
  ERROR 1022 (23000): Can't write; duplicate key in table ''


Multiupdate has been fixed to update the NULL flag of
temporary table rowid columns.



mysql-test/r/multi_update_tiny_hash.result:
  Added test case for bug#36676.
mysql-test/t/multi_update_tiny_hash-master.opt:
  Added test case for bug#36676.
mysql-test/t/multi_update_tiny_hash.test:
  Added test case for bug#36676.
sql/sql_update.cc:
  Fixed bug#36676: multiupdate using LEFT JOIN updates only
                   first row or fails with an error:
    ERROR 1022 (23000): Can't write; duplicate key in table ''
  
  The multi_update::send_data method has been modified to reset null bits of
  fields containing rowids.
2008-05-18 14:21:25 +05:00
unknown
f197f3abb4 Bug #36705 key_buffer_size of >= 2G allocates all availabel virtual memory on 64-bit wondo.
temporary variables of 'long' types were used to store ulong values,
that causes init_key_cache to receive distorted parameters


sql/handler.cc:
  Bug #36705 key_buffer_size of >= 2G allocates all availabel virtual memory on 64-bit wondo.
  
  types of temporary variables changed to match init_key_cache() parameters
2008-05-17 12:53:47 +05:00
unknown
eee5b97258 Merge bk-internal.mysql.com:/home/bk/mysql-5.0-bugteam
into  zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-bugteam
2008-05-16 17:48:07 -04:00
unknown
290b6c00c9 Merge zippy.cornsilk.net:/home/cmiller/work/mysql/bug36570/my50-bug36570
into  zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-5.0-bugteam
2008-05-16 17:40:01 -04:00