Commit graph

26414 commits

Author SHA1 Message Date
Davi Arnaut
715bac92ba Bug#54457: Test suite broken for 32-bit build
The default value of the myisam_max_extra_sort_file_size could be
higher than the maximum accepted value, leading to warnings upon
the server start.

The solution is to simply set the value to the maximum value in a
32-bit built (2147483647, one less than the current). This should
be harmless as the option is currently unused in 5.1.

include/myisam.h:
  Remove now-unused macro.
sql/mysqld.cc:
  Set max value to INT_MAX32.
2010-06-28 16:20:28 -03:00
Davi Arnaut
e42d90850c Bug#54041: MySQL 5.0.92 fails when tests from Connector/C suite run
The problem was that a user could supply supply data in chunks
via the COM_STMT_SEND_LONG_DATA command to prepared statement
parameter other than of type TEXT or BLOB. This posed a problem
since other parameter types aren't setup to handle long data,
which would lead to a crash when attempting to use the supplied
data.

Given that long data can be supplied at any stage of a prepared
statement, coupled with the fact that the type of a parameter
marker might change between consecutive executions, the solution
is to validate at execution time each parameter marker for which
a data stream was provided. If the parameter type is not TEXT or
BLOB (that is, if the type is not able to handle a data stream),
a error is returned.

sql/sql_prepare.cc:
  Before converting the parameter data stream, check the type
  compatibility.
tests/mysql_client_test.c:
  Add test case.
2010-06-28 12:21:28 -03:00
Alfranio Correia
77854696c4 merge mysql-5.1-bugteam (local) --> mysql-5.1-bugteam 2010-06-27 18:31:42 +01:00
unknown
451cea3f62 The following statements support the CURRENT_USER() where a user is needed.
DROP USER 
RENAME USER CURRENT_USER() ...
GRANT ... TO CURRENT_USER()
REVOKE ... FROM CURRENT_USER()
ALTER DEFINER = CURRENT_USER() EVENTbut, When these statements are binlogged, CURRENT_USER() just is binlogged
as 'CURRENT_USER()', it is not expanded to the real user name. When slave 
executes the log event, 'CURRENT_USER()' is expand to the user of slave 
SQL thread, but SQL thread's user name always NULL. This breaks the replication.

After this patch, session's user will be written into query log events 
if these statements call CURREN_USER() or 'ALTER EVENT' does not assign a definer.


mysql-test/include/diff_tables.inc:
  Expend its abilities.
  Now it can diff not only in sessions of 'master' and 'slave', but 
  other sessions as well.
mysql-test/include/rpl_diff_tables.inc:
  Diff the same table between master and slaves.
sql/log_event.cc:
  session's user will be written into Query_log_event, if is_current_user_used() is TRUE.
  On slave SQL thread, Only thd->variables.current_user is written into Query_log_event,
  if it exists.
sql/sql_acl.cc:
  On slave SQL thread, grantor should copy from thd->variables.current_user, if it exists
sql/sql_class.h:
  On slave SQL thread, thd->variables.current_user is used to store the applying event's
  invoker.
2010-06-27 12:42:06 +08:00
Jon Olav Hauglid
b4593605e0 Bug #54360 Deadlock DROP/ALTER/CREATE DATABASE with open HANDLER
This deadlock happened if DROP DATABASE was blocked due to an open
HANDLER table from a different connection. While DROP DATABASE
is blocked, it holds the LOCK_mysql_create_db mutex. This results
in a deadlock if the connection with the open HANDLER table tries
to execute a CREATE/ALTER/DROP DATABASE statement as they all
try to acquire LOCK_mysql_create_db.

This patch makes this deadlock scenario very unlikely by closing and
marking for re-open all HANDLER tables for which there are pending
conflicing locks, before LOCK_mysql_create_db is acquired.
However, there is still a very slight possibility that a connection
could access one of these HANDLER tables between closing/marking for
re-open and the acquisition of LOCK_mysql_create_db.

This patch is for 5.1 only, a separate and complete fix will be
made for 5.5+.

Test case added to schema.test.
2010-06-26 19:36:00 +02:00
Georgi Kodinov
8fc01031bf merge 2010-06-25 16:20:22 +03:00
Georgi Kodinov
3e1a470705 Bug #53095: SELECT column_name FROM INFORMATION_SCHEMA.STATISTICS
returns nothing
      
When looking for table or database names inside INFORMATION_SCHEMA
we must convert the table and database names to lowercase (just as it's
done in the rest of the server) when lowercase_table_names is non-zero.
This will allow us to find the same tables that we would find if there
is no condition.

Fixed by converting to lower case when extracting the database and 
table name conditions.
Test case added.
2010-06-25 15:59:44 +03:00
unknown
1a17d7e807 The following statements support the CURRENT_USER() where a user is needed.
DROP USER 
RENAME USER CURRENT_USER() ...
GRANT ... TO CURRENT_USER()
REVOKE ... FROM CURRENT_USER()
ALTER DEFINER = CURRENT_USER() EVENTbut, When these statements are binlogged, CURRENT_USER() just is binlogged
as 'CURRENT_USER()', it is not expanded to the real user name. When slave 
executes the log event, 'CURRENT_USER()' is expand to the user of slave 
SQL thread, but SQL thread's user name always NULL. This breaks the replication.

After this patch, session's user will be written into query log events 
if these statements call CURREN_USER() or 'ALTER EVENT' does not assign a definer.


mysql-test/include/diff_tables.inc:
  Expend its abilities.
  Now it can diff not only in sessions of 'master' and 'slave', but 
  other sessions as well.
sql/log_event.cc:
  session's user will be written into Query_log_event, if is_current_user_used() is TRUE.
  On slave SQL thread, Only thd->invoker is written into Query_log_event,
  if it exists.
sql/sql_acl.cc:
  On slave SQL thread, grantor should copy from thd->invoker, if it exists
sql/sql_class.h:
  On slave SQL thread, thd->invoker is used to store the applying event's
  invoker.
2010-07-04 12:02:49 +08:00
Davi Arnaut
85d281737f Fix somewhat bogus GCC warning. Although needless as the base
class is mostly empty, initialize the base class explicitly in
the copy constructor.
2010-07-03 10:20:05 -03:00
Davi Arnaut
0eb26fdfa8 Bug#53445: Build with -Wall and fix warnings that it generates
Apart strict-aliasing warnings, fix the remaining warnings
generated by GCC 4.4.4 -Wall and -Wextra flags.

One major source of warnings was the in-house function my_bcmp
which (unconventionally) took pointers to unsigned characters
as the byte sequences to be compared. Since my_bcmp and bcmp
are deprecated functions whose only difference with memcmp is
the return value, every use of the function is replaced with
memcmp as the special return value wasn't actually being used
by any caller.

There were also various other warnings, mostly due to type
mismatches, missing return values, missing prototypes, dead
code (unreachable) and ignored return values.

BUILD/SETUP.sh:
  Remove flags that are implied by -Wall and -Wextra.
  Do not warn about unused parameters in C++.
BUILD/check-cpu:
  Print only the compiler version instead of verbose banner.
  Although the option is gcc specific, the check was only
  being used for GCC specific checks anyway.
client/mysql.cc:
  bcmp is no longer defined.
client/mysqltest.cc:
  Pass a string to function expecting a format string.
  Replace use of bcmp with memcmp.
cmd-line-utils/readline/Makefile.am:
  Always define _GNU_SOURCE when compiling GNU readline.
  Required to make certain prototypes visible.
cmd-line-utils/readline/input.c:
  Condition for the code to be meaningful.
configure.in:
  Remove check for bcmp.
extra/comp_err.c:
  Use appropriate type.
extra/replace.c:
  Replace use of bcmp with memcmp.
extra/yassl/src/crypto_wrapper.cpp:
  Do not ignore the return value of fgets. Retrieve the file
  position if fgets succeed -- if it fails, the function will
  bail out and return a error.
extra/yassl/taocrypt/include/blowfish.hpp:
  Use a single array instead of accessing positions of the sbox_
  through a subscript to pbox_.
extra/yassl/taocrypt/include/runtime.hpp:
  One definition of such functions is enough.
extra/yassl/taocrypt/src/aes.cpp:
  Avoid potentially ambiguous conditions.
extra/yassl/taocrypt/src/algebra.cpp:
  Rename arguments to avoid shadowing related warnings.
extra/yassl/taocrypt/src/blowfish.cpp:
  Avoid potentially ambiguous conditions.
extra/yassl/taocrypt/src/integer.cpp:
  Do not define type within a anonymous union.
  Use a variable to return a value instead of
  leaving the result in a register -- compiler
  does not know the logic inside the asm.
extra/yassl/taocrypt/src/misc.cpp:
  Define handler for pure virtual functions.
  Remove unused code.
extra/yassl/taocrypt/src/twofish.cpp:
  Avoid potentially ambiguous conditions.
extra/yassl/testsuite/test.hpp:
  Function must have C language linkage.
include/m_string.h:
  Remove check which relied on bcmp being defined -- they weren't
  being used as bcmp is only visible when _BSD_SOURCE is defined.
include/my_bitmap.h:
  Remove bogus helpers which were used only in a few files and
  were causing warnings about dead code.
include/my_global.h:
  Due to G++ bug, always silence false-positive uninitialized
  variables warnings when compiling C++ code with G++.
  Remove bogus helper.
libmysql/Makefile.shared:
  Remove built-in implementation of bcmp.
mysql-test/lib/My/SafeProcess/safe_process.cc:
  Cast pid to largest possible type for a process identifier.
mysys/mf_loadpath.c:
  Leave space of the ending nul.
mysys/mf_pack.c:
  Replace bcmp with memcmp.
mysys/my_bitmap.c:
  Dead code removal.
mysys/my_gethwaddr.c:
  Remove unused variable.
mysys/my_getopt.c:
  Silence bogus uninitialized variable warning.
  Do not cast away the constant qualifier.
mysys/safemalloc.c:
  Cast to expected type.
mysys/thr_lock.c:
  Silence bogus uninitialized variable warning.
sql/field.cc:
  Replace bogus helper with a more appropriate logic which is
  used throughout the code.
sql/item.cc:
  Remove bogus logical condition which always evaluates to TRUE.
sql/item_create.cc:
  Simplify code to avoid signedness related warnings.
sql/log_event.cc:
  Replace use of bcmp with memcmp.
  No need to use helpers for simple bit operations.
sql/log_event_old.cc:
  Replace bmove_align with memcpy.
sql/mysqld.cc:
  Move use declaration of variable to the ifdef block where it
  is used. Remove now-unnecessary casts and arguments.
sql/set_var.cc:
  Replace bogus helpers with simple and classic bit operations.
sql/slave.cc:
  Cast to expected type and silence bogus warning.
sql/sql_class.h:
  Don't use enum values as bit flags, the supposed type safety is
  bogus as the combined bit flags are not a value in the enumeration.
sql/udf_example.c:
  Only declare variable when necessary.
sql/unireg.h:
  Replace use of bmove_align with memcpy.
storage/innobase/os/os0file.c:
  Silence bogus warning.
storage/myisam/mi_open.c:
  Remove bogus cast, DBUG_DUMP expects a pointer to unsigned
  char.
storage/myisam/mi_page.c:
  Remove bogus cast, DBUG_DUMP expects a pointer to unsigned
  char.
strings/bcmp.c:
  Remove built-in bcmp.
strings/ctype-ucs2.c:
  Silence bogus warning.
tests/mysql_client_test.c:
  Use a appropriate type as expected by simple_command().
2010-07-02 15:30:47 -03:00
Sergey Glukhov
2a86768e9e Bug#54422 query with = 'variables'
During creation of the table list of
processed tables hidden I_S table 'VARIABLES'
is erroneously added into the table list.
it leads to ER_UNKNOWN_TABLE error in
TABLE_LIST::add_table_to_list() function.
The fix is to skip addition of hidden I_S
tables into the table list.


mysql-test/r/information_schema.result:
  test case
mysql-test/t/information_schema.test:
  test case
sql/sql_show.cc:
  The fix is to skip addition of hidden I_S
  tables into the table list.
2010-06-25 12:01:47 +04:00
Martin Hansson
2b734bbee9 Bug#41660: Sort-index_merge for non-first join table may
require O(#scans) memory

When an index merge operation was restarted, it would
re-allocate the Unique object controlling the duplicate row
ID elimination. Fixed by making the Unique object a member
of QUICK_INDEX_MERGE_SELECT and thus reusing it throughout
the lifetime of this object.
2010-06-24 15:21:23 +02:00
Ramil Kalimullin
f4420a3b90 Automerge. 2010-06-24 15:26:14 +04:00
Alexey Kopytov
4b2e7aa19f Automerge. 2010-06-24 14:47:09 +04:00
Ramil Kalimullin
4e8728635b Fix for bug #54459: Assertion failed: param.sort_length,
file .\filesort.cc, line 149 (part II)

Problem: the server didn't disregard sort order 
for some zero length tuples.

Fix: skip sort order in such a case 
(zero length NOT NULL string functions).


mysql-test/r/select.result:
  Fix for bug #54459: Assertion failed: param.sort_length, 
  file .\filesort.cc, line 149 (part II)
    - test result.
mysql-test/t/select.test:
  Fix for bug #54459: Assertion failed: param.sort_length, 
  file .\filesort.cc, line 149 (part II)
    - test case.
sql/sql_select.cc:
  Fix for bug #54459: Assertion failed: param.sort_length, 
  file .\filesort.cc, line 149 (part II)
    - disregard sort order for zero length NOT NULL string functions
  along with zero length NOT NULL fields.
2010-06-24 12:00:48 +04:00
Georgi Kodinov
25bfbf684c Bug #53814: NUMERIC_PRECISION for unsigned bigint field is 19,
should be 20

Fixed the numeric precision of the unsigned BIGINT column to 
be 20 instead of 19.
2010-06-23 19:25:31 +03:00
Alexey Kopytov
53e29848a7 Manual merge. 2010-07-15 17:01:44 +04:00
Alexey Kopytov
4c28b67768 Backport of the fix for bug#25421 to 5.0.
Calculating the estimated number of records for a range scan
may take a significant time, and it was impossible for a user
to interrupt that process by killing the connection or the
query.

Fixed by checking the thread's 'killed' status in
check_quick_keys() and interrupting the calculation process if
it is set to a non-zero value.
2010-07-15 10:10:16 +04:00
Davi Arnaut
d7944b621e Bug#42733: Type-punning warnings when compiling MySQL --
strict aliasing violations.

Post-merge fix: include my_compiler.h before my_attribute.h
as the latter will undef __attribute__ if the compiler is not
GCC. Based on the compiler version, in my_compiler.h we know
for sure whether the aligned attribute is supported. Furthermore,
undefining attribute might cause bugs if some system header
uses it.

include/my_compiler.h:
  Drop aligned attribute support from Sun Studio C++ compiler
  as its not clear exactly which version of it supports the
  attribute.
2010-07-14 16:39:40 -03:00
Davi Arnaut
f317d3a6fb Bug#42733: Type-punning warnings when compiling MySQL --
strict aliasing violations.

Another rather noisy violation of strict aliasing rules
is the spatial code which makes use of stack-based memory
(of type Geometry_buffer) to provide placement for Geometry
objects. Although a placement new is allowed to dynamically
change the type of a object, the object returned by the
new placement was being ignored and the original stack-based
object was being casted to the new type, thus violating strict
aliasing rules.

The solution is to reorganize the code so that the object
returned by the new placement is used instead of casting the
original object. Also, to ensure that the stack-based object
is properly aligned with respect to the objects it provides
placement for, a set of compiler-dependent macros and types
are introduced so that the alignment of objects can be inquired
and specified.

include/Makefile.am:
  Add new header.
include/my_compiler.h:
  Add new header.
include/my_global.h:
  Remove now-unnecessary macros.
sql/spatial.cc:
  Make object creation functions return the object whose type
  was dynamically changed by the new placement.
  
  Move static method from the header in order to avoid having
  to access a forward declaration.
sql/spatial.h:
  Object creation callbacks now take a array of chars as the
  storage area.
  
  Move create_by_typeid to a source file as to not access the
  forward declaration of Geometry_buffer.
  
  Ensure that Geometry_buffer is properly aligned.
sql/sql_show.cc:
  Use newly added aligned storage helper.
2010-07-14 09:27:13 -03:00
Georgi Kodinov
dbb643d64e Bug #51876: crash/memory underrun when loading data with ucs2
and reverse() function
      
3 problems fixed : 
1. The reported problem : caused by incorrect parsing of 
the file as ucs data resulting in wrong length of the parsed
string. Fixed by truncating the invalid trailing bytes 
(non-complete multibyte characters) when reading from the file
2. LOAD DATA when reading from a proper UCS2 file wasn't 
recognizing the new line characters. Fixed by first looking 
if a byte is a new line (or any other special) character before
reading it as a part of a multibyte character.
3. When using user variables to hold the column data in LOAD
DATA the character set of the user variable was set incorrectly
to the database charset. Fixed by setting it to the charset
specified by LOAD DATA (if any).
2010-07-14 14:54:51 +03:00
Georgi Kodinov
678640019d Bug #53493 : add_to_status does not handle the longlong fields in STATUS_VAR
bytes_received/bytes_sent are ulonglong so they cannot be handled by the 
ulong handling code in add_to_status/add_diff_to_status().

Fixed by adding code to handle these two variables in 
add_to_status()/add_diff_to_status() and making sure they are not a subject
to the ulong handling code.
2010-07-14 11:50:17 +03:00
Alexey Kopytov
0e6560398c Bug#54477: Crash on IN / CASE with NULL arguments
Incorrect handling of NULL arguments could lead to a crash on
the IN or CASE operations when either NULL arguments were
passed explicitly as arguments (IN) or implicitly generated by
the WITH ROLLUP modifier (both IN and CASE).

Item_func_case::find_item() assumed all necessary comparators
to be instantiated in fix_length_and_dec(). However, in the
presence of WITH ROLLUP modifier, arguments could be
substituted with an Item_null leading to an "unexpected"
STRING_RESULT comparator being invoked.

In addition to the problem identical to the above,
Item_func_in::val_int() could crash even with explicitly passed
NULL arguments due to an optimization in fix_length_and_dec()
leading to NULL arguments being ignored during comparators
creation.


mysql-test/r/func_in.result:
  Test cases for bug#54477.
mysql-test/t/func_in.test:
  Test cases for bug#54477.
sql/item_cmpfunc.cc:
  Added additional checks for Item_nulls in 
  Item_func_case::find_item() and Item_func_in::val_int().
2010-06-22 22:53:08 +04:00
Sergey Glukhov
b36a028224 Bug#50389 Using intersect does not return all rows
In process of record search it is not taken into account
that inital quick->file->ref value could be inapplicable
to range interval. After proper row is found this value is
stored into the record buffer and later the record is
filtered out at condition evaluation stage.
The fix is store a refernce of found row to the handler ref field.


mysql-test/r/innodb_mysql.result:
  test case
mysql-test/std_data/intersect-bug50389.tsv:
  test case
mysql-test/t/innodb_mysql.test:
  test case
sql/opt_range.cc:
  store a refernce of found row to the handler ref field.
2010-06-21 15:09:58 +04:00
Ramil Kalimullin
1614c3c128 Fix for bug #54575: crash when joining tables with unique set column
Problem: a flaw (derefencing a NULL pointer) in the LIKE optimization
code may lead to a server crash in some rare cases.

Fix: check the pointer before its dereferencing.


mysql-test/r/func_like.result:
  Fix for bug #54575: crash when joining tables with unique set column
    - test result.
mysql-test/t/func_like.test:
  Fix for bug #54575: crash when joining tables with unique set column
    - test case.
sql/item_cmpfunc.cc:
  Fix for bug #54575: crash when joining tables with unique set column
    - check res2 buffer pointer before its dereferencing 
  as it may be NULL in some cases.
2010-06-20 02:02:58 +04:00
Ramil Kalimullin
5088fb1394 Fix for bug #54393: crash and/or valgrind errors in
mysql_client_binlog_statement

Problem: server may read from unassigned memory performing
"wrong" BINLOG queries.

Fix: never read from unassigned memory.


mysql-test/suite/binlog/r/binlog_base64_flag.result:
  Fix for bug #54393: crash and/or valgrind errors in
  mysql_client_binlog_statement
    - test result.
mysql-test/suite/binlog/t/binlog_base64_flag.test:
  Fix for bug #54393: crash and/or valgrind errors in
  mysql_client_binlog_statement
    - test case.
sql/sql_binlog.cc:
  Fix for bug #54393: crash and/or valgrind errors in
  mysql_client_binlog_statement
    - coded_len should not count trailing '/0';
    - never read from unassigned memory.
2010-06-18 21:32:23 +04:00
Alfranio Correia
cdc4e9ebce merge mysql-5.1-bugteam (local) --> mysql-5.1-bugteam 2010-06-17 01:25:07 +01:00
Alexey Kopytov
d2e58e4e49 Backport of the patch for bug52208 to 5.1 since the
root cause of 52208 resulted in another test failure
in 5.1.
2010-06-15 18:29:53 +04:00
Alexey Kopytov
41c3732a75 Addendum for the fix for bug #42064:
In Prepared_statement::prepare() bail out as soon as
parser_state.init() fails, trying to continue leads to crashes.
2010-06-12 09:52:31 +04:00
Alexey Kopytov
2400e54a12 Automerge. 2010-06-11 23:44:01 +04:00
Ramil Kalimullin
9be5696aa1 Automerge. 2010-06-11 18:43:36 +04:00
Alexey Kopytov
386929d3ae Manual merge from the bugfix tree.
conflicts:
   conflict      sql/sql_parse.cc
2010-06-11 16:52:06 +04:00
Martin Hansson
0823afc8bf Bug#53859: Valgrind: opt_sum_query(TABLE_LIST*, List<Item>&,
Item*) at opt_sum.cc:305
      
Queries applying MIN/MAX functions to indexed columns are
optimized to read directly from the index if all key parts
of the index preceding the aggregated key part are bound to
constants by the WHERE clause. A prefix length is also
produced, equal to the total length of the bound key
parts. If the aggregated column itself is bound to a
constant, however, it is also included in the prefix.

Such full search keys are read as closed intervals for
reasons beyond the scope of this bug. However, the procedure
missed one case where a key part meant for use as range
endpoint was being overwritten with a NULL value destined
for equality checking. In this case the key part was
overwritten but the range flag remained, causing open
interval reading to be performed.

Bug was fixed by adding more stringent checking to the
search key building procedure (matching_cond) and never
allow overwrites of range predicates with non-range
predicates.

An assertion was added to make sure open intervals are never
used with full search keys.
2010-06-11 09:38:29 +02:00
Davi Arnaut
0f9ddfa9d8 Bug#42733: Type-punning warnings when compiling MySQL --
strict aliasing violations.

One somewhat major source of strict-aliasing violations and
related warnings is the SQL_LIST structure. For example,
consider its member function `link_in_list` which takes
a pointer to pointer of type T (any type) as a pointer to
pointer to unsigned char. Dereferencing this pointer, which
is done to reset the next field, violates strict-aliasing
rules and might cause problems for surrounding code that
uses the next field of the object being added to the list.

The solution is to use templates to parametrize the SQL_LIST
structure in order to deference the pointers with compatible
types. As a side bonus, it becomes possible to remove quite
a few casts related to acessing data members of SQL_LIST.

sql/handler.h:
  Use the appropriate template type argument.
sql/item.cc:
  Remove now-unnecessary cast.
sql/item_subselect.cc:
  Remove now-unnecessary casts.
sql/item_sum.cc:
  Use the appropriate template type argument.
  Remove now-unnecessary cast.
sql/mysql_priv.h:
  Move SQL_LIST structure to sql_list.h
  Use the appropriate template type argument.
sql/sp.cc:
  Remove now-unnecessary casts.
sql/sql_delete.cc:
  Use the appropriate template type argument.
  Remove now-unnecessary casts.
sql/sql_derived.cc:
  Remove now-unnecessary casts.
sql/sql_lex.cc:
  Remove now-unnecessary casts.
sql/sql_lex.h:
  SQL_LIST now takes a template type argument which must
  match the type of the elements of the list. Use forward
  declaration when the type is not available, it is used
  in pointers anyway.
sql/sql_list.h:
  Rename SQL_LIST to SQL_I_List. The template parameter is
  the type of object that is stored in the list.
sql/sql_olap.cc:
  Remove now-unnecessary casts.
sql/sql_parse.cc:
  Remove now-unnecessary casts.
sql/sql_prepare.cc:
  Remove now-unnecessary casts.
sql/sql_select.cc:
  Remove now-unnecessary casts.
sql/sql_show.cc:
  Remove now-unnecessary casts.
sql/sql_table.cc:
  Remove now-unnecessary casts.
sql/sql_trigger.cc:
  Remove now-unnecessary casts.
sql/sql_union.cc:
  Remove now-unnecessary casts.
sql/sql_update.cc:
  Remove now-unnecessary casts.
sql/sql_view.cc:
  Remove now-unnecessary casts.
sql/sql_yacc.yy:
  Remove now-unnecessary casts.
storage/myisammrg/ha_myisammrg.cc:
  Remove now-unnecessary casts.
2010-06-10 17:45:22 -03:00
Davi Arnaut
6f3a540c37 Bug#42733: Type-punning warnings when compiling MySQL --
strict aliasing violations.

Essentially, the problem is that large parts of the server were
developed in simpler times (last decades, pre C99 standard) when
strict aliasing and compilers supporting such optimizations were
rare to non-existent. Thus, when compiling the server with a modern
compiler that uses strict aliasing rules to perform optimizations,
there are several places in the code that might trigger undefined
behavior.

As evinced by some recent bugs, GCC does a somewhat good of job
misoptimizing such code, but on the other hand also gives warnings
about suspicious code. One problem is that the warnings aren't
always accurate, yet we can't afford to just shut them off as we
might miss real cases. False-positive cases are aggravated mostly
by casts that are likely to trigger undefined behavior.

The solution is to start a cleanup process focused on fixing and
reducing the amount of strict-aliasing related warnings produced
by GCC and others compilers. A good deal of noise reduction can
be achieved by just removing useless casts that are product of
historical cruft and are likely to trigger undefined behavior if
dereferenced.

client/mysql.cc:
  Remove now-unnecessary casts.
  Break up large strings.
client/mysql_upgrade.c:
  Remove now-unnecessary casts.
client/mysqladmin.cc:
  Remove now-unnecessary casts.
  Break up large strings.
client/mysqlbinlog.cc:
  Remove now-unnecessary casts.
client/mysqlcheck.c:
  Remove now-unnecessary casts.
client/mysqldump.c:
  Remove now-unnecessary casts.
client/mysqlimport.c:
  Remove now-unnecessary casts.
client/mysqlshow.c:
  Remove now-unnecessary casts.
client/mysqlslap.c:
  Remove now-unnecessary casts.
client/mysqltest.cc:
  Remove now-unnecessary casts.
extra/comp_err.c:
  Remove now-unnecessary casts.
extra/my_print_defaults.c:
  Remove now-unnecessary casts.
  Break up large strings.
extra/mysql_waitpid.c:
  Remove now-unnecessary casts.
extra/perror.c:
  Remove now-unnecessary casts.
extra/resolve_stack_dump.c:
  Remove now-unnecessary casts.
extra/resolveip.c:
  Remove now-unnecessary casts.
include/my_getopt.h:
  Use a void pointer type as the opaque type to avoid problems with type
  incompatibility -- GCC issues warnings when the type name is not type
  compatible with a operand. As a side bonus, a explicit cast won't be
  necessary anymore.
include/sslopt-longopts.h:
  Remove now-unnecessary casts.
  Break up large strings.
mysys/my_getopt.c:
  Update opaque type and introduce a type definition for the
  argument to my_getopt_register_get_addr.
server-tools/instance-manager/options.cc:
  Remove now-unnecessary casts.
sql/mysqld.cc:
  Remove now-unnecessary casts.
  Break up large strings.
  Update mysql_getopt_value prototype (the old prototype
  was different from the definition anyway).
sql/sql_plugin.cc:
  The type of a pointer to a function must be compatible with the
  pointed-to function type, otherwise the behavior is undefined.
sql/table.cc:
  The variable buf pointer to pointer to pointer to constant char
  could improperly alias a incompatible type in call to fix_type_
  pointers. Since this was actually dead code, it is simply removed.
sql/unireg.cc:
  Remove call to get_form_pos. The code creates a new FRM file which
  is always truncated and writes the form position as 0. Hence, no
  need to retrieve it, we now for sure it is 0.
storage/archive/archive_reader.c:
  Remove now-unnecessary casts.
storage/myisam/ft_nlq_search.c:
  Read weight directly from the buffer.
storage/myisam/fulltext.h:
  Add explanation about the type duality of a key buffer.
  Add accessor macro to retrieve a FT float value.
storage/myisam/mi_test1.c:
  Remove now-unnecessary casts.
storage/myisam/myisam_ftdump.c:
  Read weight directly from the buffer.
storage/myisam/myisamchk.c:
  Remove now-unnecessary casts.
storage/myisam/myisamlog.c:
  A pointer to char was used to alias a pointer to pointer to
  unsigned char, thus violating strict aliasing rules.
storage/myisam/myisampack.c:
  Remove now-unnecessary casts.
strings/decimal.c:
  Remove aliasing violation, printing the value is enough for
  debugging purposes.
tests/mysql_client_test.c:
  Remove now-unnecessary casts.
2010-06-10 17:16:43 -03:00
Ramil Kalimullin
f4b7c50d6e Fix for bug #54007: assert in ha_myisam::index_next, HANDLER
Problem: the server missed the fact that one can read from 
2 indexes alternately using HANDLER interface.

Fix: check if the same (initialized) index is involved
reading next/prev values from the index.


mysql-test/r/handler_myisam.result:
  Fix for bug #54007: assert in ha_myisam::index_next, HANDLER
    - test result.
mysql-test/t/handler_myisam.test:
  Fix for bug #54007: assert in ha_myisam::index_next, HANDLER
    - test case.
sql/sql_handler.cc:
  Fix for bug #54007: assert in ha_myisam::index_next, HANDLER
    - check if we use the same (initialized) index 
  to read next/prev values from the index.
2010-06-09 14:45:04 +04:00
Georgi Kodinov
04f4786c08 Merge 2010-06-09 11:29:27 +03:00
Kristofer Pettersson
e484e89d3d automerge 2010-06-08 13:50:54 +02:00
Kristofer Pettersson
cf2e7c770c Bug#53191 Lock_time in slow log is negative when logging stored routines
Logging slow stored procedures caused the slow log to write 
very large lock times. The lock times was a result of a 
negative number being cast to an unsigned integer.
The reason the lock time appeard negative was because 
one of the measurements points was reset after execution
causing it to change order with the start time of the 
statement.
      
This bug is related to bug 47905 which in turn was 
introduced because of a joint fix for 12480,12481,12482 and 11587.

The fix is to only reset the start_time before any statement
execution in a SP while not resetting start_utime or
utime_after_lock which are used for measuring the 
performance of the SP. Start_time is used to set the
timestamp on the replication event which controlls how
the slave interprets time functions like NOW().
2010-06-08 10:58:19 +02:00
Sergey Glukhov
81e6a98250 5.0-bugteam->5.1-bugteam merge 2010-06-08 10:28:30 +04:00
Sergey Glukhov
66c621ba3b Bug#53933 crash when using uncacheable subquery in the having clause of outer query
The problem is in the Item_func_isnull::update_used_tables() function,
bracket is at the wrong place. Because of that isnull item erroneously
is treated as const item. The fix is to set brackets in the right place.


mysql-test/r/func_isnull.result:
  test case
mysql-test/t/func_isnull.test:
  test case
sql/item_cmpfunc.h:
  set brackets in the right place.
2010-06-08 10:22:40 +04:00
Georgi Kodinov
e1e3293da5 merge 2010-06-07 13:01:54 +03:00
Georgi Kodinov
df088b8de2 Addendum to the fix for bug #52315: need to set a proper shutdown type
when an out-of-supported-range date is detected.
2010-06-07 12:49:52 +03:00
Ramil Kalimullin
44fc4b8b38 Automerge. 2010-06-04 22:01:27 +04:00
Ramil Kalimullin
9a38126497 Fix for bug #53912: Fails to build from source
NET::skip_big_packet isn't defined for the embedded server,
hide it in such a case.


sql/sql_connect.cc:
  Fix for bug #53912: Fails to build from source
    - hide net.skip_big_packet for the embedded server,
  as it isn't defined there.
2010-06-04 21:58:41 +04:00
Georgi Kodinov
ac738d8265 merge 2010-06-04 17:10:22 +03:00
Georgi Kodinov
121e04732e Bug #52315: utc_date() crashes when system time > year 2037
Some of the server implementations don't support dates later
than 2038 due to the internal time type being 32 bit.
Added checks so that the server will refuse dates that cannot
be handled by either throwing an error when setting date at 
runtime or by refusing to start or shutting down the server if 
the system date cannot be stored in my_time_t.
2010-06-04 16:21:19 +03:00
Luis Soares
1b61dcf434 BUG#53893: RBR: nullable unique key can lead to out-of-sync slave
Post-push fix.
  
There was a valgrind issue on the loop that checks whether there
are NULL fields in the UNIQUE KEY or not. In detail, for the last 
iteration the server may read out of the key_part array boundaries,
making valgrind to output warnings.

We fix this by correcting the loop, ie, moving the part that reads
from the key_part to be inside the loop statement block. This way
the assignment is protected by the loop condition.
2010-06-04 00:45:07 +01:00
Luis Soares
20fc48fc38 BUG 53893: automerged bug branch into mysql-5.1-bugteam latest. 2010-06-03 00:04:27 +01:00
Luis Soares
1b27674429 BUG#53893: RBR: nullable unique key can lead to out-of-sync slave
When using Unique Keys with nullable parts in RBR, the slave can
choose the wrong row to update. This happens because a table with
an unique key containing nullable parts cannot strictly guarantee 
uniqueness. As stated in the manual, for all engines, a UNIQUE 
index allows multiple NULL values for columns that can contain 
NULL.

We fix this at the slave by extending the checks before assuming
that the row found through an unique index is is the correct
one. This means that when a record (R) is fetched from the storage
engine and a key that is not primary (K) is used, the server does 
the following: 

 - If K is unique and has no nullable parts, it returns R;
 - Otherwise, if any field in the before image that is part of K
   is null do an index scan;
 - If there is no NULL field in the BI part of K, then return R.

A side change: renamed the existing test case file and added a
test case covering the changes in this patch.
2010-06-02 23:26:12 +01:00
Alexey Kopytov
40d4c07cd0 Automerge. 2010-06-02 13:54:40 +04:00
Sergey Glukhov
89b83c05e0 Bug#53942 valgrind warnings with timestamp() function and incomplete datetime values
Field_time::get_date method does not initialize MYSQL_TIME::time_type field.
The fix is to init this field.


mysql-test/r/type_time.result:
  test case
mysql-test/t/type_time.test:
  test case
sql/field.cc:
  --use Field_time::get_time in Field_time::get_date
  --removed duplicated code in Field_time::get_date method
2010-05-31 13:25:11 +04:00
Alexey Kopytov
f3a8307397 Bug #48537: difference of index selection between rpm binary
and .tar.gz, windows vs linux..

On Intel x86 machines index selection by the MySQL query
optimizer could sometimes depend on the compiler version and
optimization flags used to build the server binary.

The problem was a result of a known issue with floating point
calculations on x86: since internal FPU precision (80 bit)
differs from precision used by programs (32-bit float or 64-bit
double), the result of calculating a complex expression may
depend on how FPU registers are allocated by the compiler and
whether intermediate values are spilled from FPU to memory. In
this particular case compiler versions and optimization flags
had an effect on cost calculation when choosing the best index
in best_access_path().

A possible solution to this problem which has already been
implemented in mysql-trunk is to limit FPU internal precision
to 64 bits. So the fix is a backport of the relevant code to
5.1 from mysql-trunk.

configure.in:
  Configure check for fpu_control.h
mysql-test/r/explain.result:
  Test case for bug #48537.
mysql-test/t/explain.test:
  Test case for bug #48537.
sql/mysqld.cc:
  Backport of the code to switch FPU on x86 to 64-bit precision.
2010-05-29 22:16:45 +04:00
Mattias Jonsson
9731b3852b merge 2010-05-28 14:49:25 +02:00
Dmitry Lenev
0a35e5bd18 A 5.1-only version of fix for bug #46947 "Embedded SELECT
without FOR UPDATE is causing a lock".

SELECT statements with subqueries referencing InnoDB tables
were acquiring shared locks on rows in these tables when they
were executed in REPEATABLE-READ mode and with statement or
mixed mode binary logging turned on.

This was a regression which were introduced when fixing
bug 39843.

The problem was that for tables belonging to subqueries
parser set TL_READ_DEFAULT as a lock type. In cases when
statement/mixed binary logging at open_tables() time this
type of lock was converted to TL_READ_NO_INSERT lock at
open_tables() time and caused InnoDB engine to acquire
shared locks on reads from these tables. Although in some
cases such behavior was correct (e.g. for subqueries in
DELETE) in case of SELECT it has caused unnecessary locking.

This patch implements minimal version of the fix for the
specific problem described in the bug-report which supposed
to be not too risky for pushing into 5.1 tree.
The 5.5 tree already contains a more appropriate solution
which also addresses other related issues like bug 53921
"Wrong locks for SELECTs used stored functions may lead
to broken SBR".

This patch tries to solve the problem by ensuring that
TL_READ_DEFAULT lock which is set in the parser for
tables participating in subqueries at open_tables()
time is interpreted as TL_READ_NO_INSERT or TL_READ.
TL_READ is used only if we know that this is a SELECT
and that this particular table is not used by a stored
function.

Test coverage is added for both InnoDB and MyISAM.

This patch introduces an "incompatible" change in locking
scheme for subqueries used in SELECT ... FOR UPDATE and
SELECT .. IN SHARE MODE.

In 4.1 (as well as in 5.0 and 5.1 before fix for bug 39843)
the server would use a snapshot InnoDB read for subqueries
in SELECT FOR UPDATE and SELECT .. IN SHARE MODE statements,
regardless of whether the binary log is on or off.

If the user required a different type of read (i.e. locking
read), he/she could request so explicitly by providing FOR
UPDATE/IN SHARE MODE clause for each individual subquery.

The patch for bug 39843 broke this behaviour (which was not
documented or tested), and started to use locking reads for
all subqueries in SELECT ... FOR UPDATE/IN SHARE MODE.
This patch restores 4.1 behaviour.

This patch should be mostly null-merged into 5.5 tree.

mysql-test/include/check_concurrent_insert.inc:
  Added auxiliary script which allows to check if statement
  reading table allows concurrent inserts in it.
mysql-test/include/check_no_concurrent_insert.inc:
  Added auxiliary script which allows to check that statement
  reading table doesn't allow concurrent inserts in it.
mysql-test/include/check_no_row_lock.inc:
  Added auxiliary script which allows to check if statement
  reading table doesn't take locks on its rows.
mysql-test/include/check_shared_row_lock.inc:
  Added auxiliary script which allows to check if statement
  reading table takes shared locks on some of its rows.
mysql-test/r/bug39022.result:
  After bug #46947 'Embedded SELECT without FOR UPDATE is
  causing a lock' was fixed test case for bug 39022 has to
  be adjusted in order to trigger execution path on which
  original problem was encountered.
mysql-test/r/innodb_mysql_lock2.result:
  Added coverage for handling of locking in various cases when
  we read data from InnoDB tables (includes test case for
  bug #46947 'Embedded SELECT without FOR UPDATE is causing a
  lock').
mysql-test/r/lock_sync.result:
  Added coverage for handling of locking in various cases when
  we read data from MyISAM tables.
mysql-test/t/bug39022.test:
  After bug #46947 'Embedded SELECT without FOR UPDATE is
  causing a lock' was fixed test case for bug 39022 has to
  be adjusted in order to trigger execution path on which
  original problem was encountered.
mysql-test/t/innodb_mysql_lock2.test:
  Added coverage for handling of locking in various cases when
  we read data from InnoDB tables (includes test case for
  bug #46947 'Embedded SELECT without FOR UPDATE is causing a
  lock').
mysql-test/t/lock_sync.test:
  Added coverage for handling of locking in various cases when
  we read data from MyISAM tables.
sql/mysql_priv.h:
  Function read_lock_type_for_table() now takes pointers to
  LEX and TABLE_LIST elements as its arguments since to
  correctly determine lock type it needs to know what
  statement is being performed and whether table element for
  which lock type to be determined belongs to prelocking list.
sql/sql_base.cc:
  Changed read_lock_type_for_table() to return a weak TL_READ
  type of lock in cases when we are executing SELECT (and so
  won't update tables directly) and table doesn't belong to
  statement's prelocking list and thus can't be used by a
  stored function. It is OK to do so since in this case table
  won't be used by statement or function call which will be
  written to the binary log, so serializability requirements
  for it can be relaxed.
  One of results from this change is that SELECTs on InnoDB
  tables no longer takes shared row locks for tables which
  are used in subqueries (i.e. bug #46947 is fixed).
  Another result is that for similar SELECTs on MyISAM tables
  concurrent inserts are allowed.
  In order to implement this change signature of
  read_lock_type_for_table() function was changed to
  take pointers to LEX and TABLE_LIST objects.
sql/sql_update.cc:
  Function read_lock_type_for_table() now takes pointers to
  LEX and TABLE_LIST elements as its arguments since to
  correctly determine lock type it needs to know what
  statement is being performed and whether table element for
  which lock type to be determined belongs to prelocking list.
2010-05-28 00:07:40 +04:00
Sergey Glukhov
8ede529b36 Bug#52005 'JOIN_TAB->dependent' may be incorrectly propageted for multilevel outer joins
There are two problems:
1. In simplify_joins function we calculate table dependencies. If STRAIGHT_JOIN hint
is used for whole SELECT we do not count it and as result some dependendecies
might be lost. It leads to incorrect table order which is returned by
join_tab_cmp_straight() function.
2. make_join_statistics() calculate the transitive closure for relations a particular
JOIN_TAB is 'dependent on'.
We aggregate the dependent table_map of a JOIN_TAB by adding dependencies from other
tables which we depend on. However, this may also cause new dependencies to be
available after we have completed processing a certain JOIN_TAB.
Both these problems affect condition pushdown and as result condition might be pushed
into wrong table which leads to crash or even omitted which leads to wrong result.
The fix:
1. Use modified 'transitive closure' algorithm provided by Ole John Aske
2. Update table dependences in simplify_joins according to 
   global STRAIGHT_JOIN hint.
Note: the patch also fixes bugs 46091 & 51492


mysql-test/r/join_outer.result:
  test case
mysql-test/t/join_outer.test:
  test case
sql/sql_select.cc:
  1. Use modified 'transitive closure' algorithm provided by Ole John Aske
  2. Update table dependences in simplify_joins according to 
     global STRAIGHT_JOIN hint.
2010-05-27 19:13:53 +04:00
Alexey Kopytov
4c31276e66 Automerge. 2010-05-27 14:14:27 +04:00
Kristofer Pettersson
f0df2886c1 automerge 2010-05-26 17:17:33 +02:00
Kristofer Pettersson
b01407461b Bug#52107 Comment in sql/net_serv.cc still makes "GPL protocol" claim
Removed misleading comments.
2010-05-26 17:13:02 +02:00
Ramil Kalimullin
d98c981fad Manual merge. 2010-05-25 22:30:08 +04:00
Alexey Kopytov
1d0acc7754 Bug #53830: !table || (!table->read_set ||
bitmap_is_set(table->read_set, field_index))

UPDATE on an InnoDB table modifying the same index that is used
to satisfy the WHERE condition could trigger a debug assertion
under some circumstances.

Since for engines with the HA_PRIMARY_KEY_IN_READ_INDEX flag
set results of an index scan on a secondary index are appended
by the primary key value, if a query involves only columns from
the primary key and a secondary index, the latter is considered
to be covering.

That tricks mysql_update() to mark for reading only columns
from the secondary index when it does an index scan to retrieve
rows to update in case a part of that key is also being
updated. However, there may be other columns in WHERE that are
part of the primary key, but not the secondary one.

What we actually want to do in this case is to add index
columns to the existing WHERE columns bitmap rather than
replace it.

mysql-test/r/innodb_mysql.result:
  Test case for bug #53830.
mysql-test/t/innodb_mysql.test:
  Test case for bug #53830.
sql/sql_update.cc:
  Add index columns to the read_set bitmap, don't replace it.
sql/table.cc:
  Added a new add_read_columns_used_by_index() function to 
  st_table.
sql/table.h:
  Added a new add_read_columns_used_by_index() function to 
  st_table.
2010-05-25 18:43:45 +04:00
Ramil Kalimullin
32d6a7fc8f Automerge. 2010-05-25 18:07:47 +04:00
Ramil Kalimullin
eef9ce8c1a Fix for bug #53907: Table dump command can be abused to dump arbitrary tables.
Problem: one with SELECT privilege on some table may dump other table
performing COM_TABLE_DUMP command due to missed check of the table name.

Fix: check the table name.


sql/sql_parse.cc:
  Fix for bug #53907: Table dump command can be abused to dump arbitrary tables.
    - check given table name performing COM_TABLE_DUMP command.
tests/mysql_client_test.c:
  Fix for bug #53907: Table dump command can be abused to dump arbitrary tables.
    - test case.
2010-05-25 17:56:23 +04:00
Mattias Jonsson
0fdd97af48 Bug#49161: Out of memory; restart server and try again (needed 2 bytes)
Problem was reporting wrong error

Fixed by adding a new error which better explain the problem.

mysql-test/r/partition_error.result:
  Bug#49161: Out of memory; restart server and try again (needed 2 bytes)
  
  Updated test result
mysql-test/t/partition_error.test:
  Bug#49161: Out of memory; restart server and try again (needed 2 bytes)
  
  Added test case
sql/ha_partition.cc:
  Bug#49161: Out of memory; restart server and try again (needed 2 bytes)
  
  Better error message. (used ER_UNKNOWN_ERROR to avoid merge
  problems in mysql-trunk+)
2010-05-25 15:41:00 +02:00
Davi Arnaut
342819f168 Bug#53908: compile failure with embedded enabled
This fixes a recently introduced regression, where a variable is
not defined for the embedded server. Although the embedded server
is not supported in 5.0, make it at least compile.
2010-05-25 10:36:48 -03:00
Luis Soares
fc11d74d13 BUG#53657: Slave crashed with error 22 when trying to lock mutex
at mf_iocache.c, line 1722

The slave crashed while two threads: IO thread and user thread
raced for the same mutex (the append_buffer_lock protecting the
relay log's IO_CACHE). The IO thread was trying to flush the
cache, and for that was grabbing the append_buffer_lock. 

However, the other thread was closing and reopening the relay log
when the IO thread tried to lock. Closing and reopening the log
includes destroying and reinitialising the IO_CACHE
mutex. Therefore, the IO thread tried to lock a destroyed mutex.

We fix this by backporting patch for BUG#50364 which fixed this
bug in mysql server 5.5+. The patch deploys missing
synchronization when flush_master_info is called and the relay
log is flushed by the IO thread. In detail the patch backports
revision (from mysql-trunk):
- luis.soares@sun.com-20100203165617-b1yydr0ee24ycpjm

This patch already includes the post-push fix also in BUG#50364:
- luis.soares@sun.com-20100222002629-0cijwqk6baxhj7gr
2010-05-24 17:43:27 +01:00
Mattias Jonsson
f4e46c5ce1 merge 2010-05-23 18:08:33 +02:00
Gleb Shchepa
d72a4710aa Bug #53804: serious flaws in the alter database .. upgrade
data directory name command

The check_db_name function has been modified to validate tails of
#mysql50#-prefixed database names for compliance with MySQL 5.0
database name encoding rules (the check_table_name function call
has been reused).


mysql-test/r/renamedb.result:
  Updated test case.
mysql-test/r/upgrade.result:
  Test case for bug #53804.
mysql-test/t/renamedb.test:
  Updated test case.
mysql-test/t/upgrade.test:
  Test case for bug #53804.
sql/mysql_priv.h:
  Bug #53804: serious flaws in the alter database .. upgrade
              data directory name command
  
  The check_mysql50_prefix has been added.
sql/sql_table.cc:
  Bug #53804: serious flaws in the alter database .. upgrade
              data directory name command
  
  - The check_mysql50_prefix has been added.
  - The check_n_cut_mysql50_prefix function has been refactored
  to share code with new check_mysql50_prefix function.
sql/table.cc:
  Bug #53804: serious flaws in the alter database .. upgrade
              data directory name command
  
  The check_db_name function has been modified to validate tails of
  #mysql50#-prefixed database names for compliance with MySQL 5.0
  database name encoding rules.
2010-05-21 22:47:32 +04:00
Mattias Jonsson
6ef03ea37c merge into mysql-5.1-bugteam
sql/ha_partition.cc:
  Bug#49477, added safety that a partitioned table cannot be
  temporary.
2010-05-21 14:18:14 +02:00
Alexey Kopytov
c2ebb0ac88 Bug #42064: low memory crash when importing hex strings, in
Item_hex_string::Item_hex_string

The status of memory allocation in the Lex_input_stream (called
from the Parser_state constructor) was not checked which led to
a parser crash in case of the out-of-memory error.

The solution is to introduce new init() member function in
Parser_state and Lex_input_stream so that status of memory
allocation can be returned to the caller.

mysql-test/r/error_simulation.result:
  Added a test case for bug #42064.
mysql-test/t/error_simulation.test:
  Added a test case for bug #42064.
mysys/my_alloc.c:
  Added error injection code for the regression test.
mysys/my_malloc.c:
  Added error injection code for the regression test.
mysys/safemalloc.c:
  Added error injection code for the regression test.
sql/event_data_objects.cc:
  Use the new init() member function of Parser_state and check
  its return value to handle memory allocation failures.
sql/mysqld.cc:
  Added error injection code for the regression test.
sql/sp.cc:
  Use the new init() member function of Parser_state and check
  its return value to handle memory allocation failures.
sql/sql_lex.cc:
  Moved memory allocation from constructor to the separate init()
  member function.
  Added error injection code for the regression test.
sql/sql_lex.h:
  Moved memory allocation from constructor to the separate init()
  member function.
sql/sql_parse.cc:
  Use the new init() member function of Parser_state and check
  its return value to handle memory allocation failures.
sql/sql_partition.cc:
  Use the new init() member function of Parser_state and check
  its return value to handle memory allocation failures.
sql/sql_prepare.cc:
  Use the new init() member function of Parser_state and check
  its return value to handle memory allocation failures.
sql/sql_trigger.cc:
  Use the new init() member function of Parser_state and check
  its return value to handle memory allocation failures.
sql/sql_view.cc:
  Use the new init() member function of Parser_state and check
  its return value to handle memory allocation failures..
sql/thr_malloc.cc:
  Added error injection code for the regression test.
2010-05-21 15:23:48 +04:00
Sergey Glukhov
b8af4ab216 Bug#52884 mysql-test-run does not work with --debug option
Server crashes on 64bit linux with 'double free or corruption'
message, on 32bit mysql-test-run silently fails on bootstrap
stage. The problem is that FreeState() is called twice
for init_settings struct in _db_end_ function.
The fix is to remove superfluous FreeState() call.
Additional fix:
fixed discrepancy of result file when
debug & valgrind options are enabled
for MTR.

dbug/dbug.c:
  The problem is that FreeState() is called twice
  for init_settings struct in _db_end_ function.
  The fix is to remove superfluous FreeState() call.
mysql-test/r/variables_debug.result:
  fixed discrepancy of result file when
  debug & valgrind options are enabled
  for MTR.
mysql-test/t/variables_debug.test:
  fixed discrepancy of result file when
  debug & valgrind options are enabled
  for MTR.
sql/set_var.cc:
  fixed discrepancy of result file when
  debug & valgrind options are enabled
  for MTR.
2010-05-20 10:31:03 +04:00
Luis Soares
779241bc94 BUG 52868: automerged bzr bundle from bug report. 2010-05-20 00:50:42 +01:00
Luis Soares
3b8cae37cc BUG 49522: automerged bzr bundle from bug report. 2010-05-20 00:49:18 +01:00
Alfranio Correia
3f8bde448c BUG#53560 CREATE TEMP./DROP TEMP. are not binglogged correctly after a failed statement
This patch fixes two problems described as follows:

1 - If there is an on-going transaction and a temporary table is created or
dropped, any failed statement that follows the "create" or "drop commands"
triggers a rollback and by consequence the slave will go out sync because
the binary log will have a wrong sequence of events.

To fix the problem, we changed the expression that evaluates when the
cache should be flushed after either the rollback of a statment or
transaction.

2 - When a "CREATE TEMPORARY TABLE SELECT * FROM" was executed the
OPTION_KEEP_LOG was not set into the thd->options. For that reason, if
the transaction had updated only transactional engines and was rolled
back at the end (.e.g due to a deadlock) the changes were not written
to the binary log, including the creation of the temporary table.
      
To fix the problem, we have set the OPTION_KEEP_LOG into the thd->options
when a "CREATE TEMPORARY TABLE SELECT * FROM" is executed.

sql/log.cc:
  Reorganized the code based on the following functions:
  
  - bool ending_trans(const THD* thd, const bool all);
  - bool trans_has_updated_non_trans_table(const THD* thd);
  - bool trans_has_no_stmt_committed(const THD* thd, const bool all);
  - bool stmt_has_updated_non_trans_table(const THD* thd);
sql/log.h:
  Added functions to organize the code in log.cc.
sql/log_event.cc:
  Removed the OPTION_KEEP_LOG since it must be used only when
  creating and dropping temporary tables.
sql/log_event_old.cc:
  Removed the OPTION_KEEP_LOG since it must be used only when
  creating and dropping temporary tables.
sql/sql_parse.cc:
  When a "CREATE TEMPORARY TABLE SELECT * FROM" was executed the
  OPTION_KEEP_LOG was not set into the thd->options.
        
  To fix the problem, we have set the OPTION_KEEP_LOG into the
  thd->options when a "CREATE TEMPORARY TABLE SELECT * FROM"
  is executed.
2010-05-19 18:01:12 +01:00
Tor Didriksen
5539f5ccf6 Backport from next-mr-bugfixing of tor.didriksen@sun.com-20100106140051-3j2iuag63eltsr2e
Bug #50087 Interval arithmetic for Event_queue_element is not portable.

Subtraction of two unsigned months yielded a (very large) positive value.
Conversion of this to a signed value was not necessarily well defined.
              
Solution: do the subtraction on signed values.



mysql-test/r/events_scheduling.result:
  Add test case.
mysql-test/t/events_scheduling.test:
  Add test case.
sql/event_data_objects.cc:
  Convert month to signed before doing the subtraction.
2010-05-19 11:18:59 +02:00
Sergey Glukhov
36be33b0ad Bug#48729 SELECT ... FROM INFORMATION_SCHEMA.ROUTINES causes memory to grow
Analysis showed that in case of accessing I_S table
ROUTINES we perform unnecessary allocations
with get_field() function for every processed row that
in their turn causes significant memory growth.
the fix is to avoid use of get_field().


sql/sql_show.cc:
  Functions store_schema_proc() are changed
  to avoid use of get_field() function.
2010-05-18 13:28:21 +05:00
Alfranio Correia
3404d83083 BUG#49019 Mixing self-logging eng. and regular eng. does not switch to row in mixed
mode
      
Post-push fix after backporting the patch to 5.1-bugteam:

  1 - changed the name of some variables to be equivalent to pe.
  2 - fixed that patch to mark a statement as unsafe when both a
  self-logging eng. and regular eng. are accessed and one of them
  is updated.
2010-05-16 15:37:44 +01:00
Gleb Shchepa
9cbb009b2e Bug #53450: Crash / assertion "virtual int
ha_myisam::index_first(uchar*)") at assert.c:81

Single-table DELETE crash/assertion similar to single-table
UPDATE bug 14272.

Same resolution as for the bug 14272:
Don't run index scan when we should use quick select.
This could cause failures because there are table handlers (like federated)
that support quick select scanning but do not support index scanning.


mysql-test/r/delete.result:
  Test case for bug #53450.
mysql-test/t/delete.test:
  Test case for bug #53450.
sql/sql_delete.cc:
  Bug #53450: Crash / assertion "virtual int
              ha_myisam::index_first(uchar*)") at assert.c:81
  
  The mysql_delete function has been modified to not to use
  init_read_record_idx instead of init_read_record for the
  quick select.
2010-05-14 15:36:27 +04:00
Ramil Kalimullin
feb03a82f2 Fix for bug#52051: Aggregate functions incorrectly returns
NULL from outer join query
      
      Problem: optimising MIN/MAX() queries without GROUP BY clause
      by replacing the aggregate expression with a constant, we may set it
      to NULL disregarding the fact that there may be outer joins involved.
      
      Fix: don't replace MIN/MAX() with NULL if there're outer joins.
      
      Note: the fix itself is just
      - if (!count)
      + if (!count && !outer_tables)
          set to NULL
      
      The rest of the patch eliminates repeated code to improve speed
      and for easy maintenance of the code.


mysql-test/r/group_by.result:
          Fix for bug#52051: Aggregate functions incorrectly returns
          NULL from outer join query
            - test result.
mysql-test/t/group_by.test:
          Fix for bug#52051: Aggregate functions incorrectly returns
          NULL from outer join query
            - test case.
sql/opt_sum.cc:
          Fix for bug#52051: Aggregate functions incorrectly returns
          NULL from outer join query
            - optimising MIN/MAX() queries without GROUP BY clause by
          replacing them with a constant, take into account that
          there're may be outer joins involved.
            - repeated code for MIN/MAX optimization in the opt_sum_query()
          eliminated by introducing new functions that read MIN/MAX values
          using index and combining MIN/MAX cases to one.
2010-05-12 20:10:33 +04:00
Staale Smedseng
330864fcda Bug #49756 Rows_examined is always 0 in the slow query log for
update statements
      
Only SELECT statements report any examined rows in the slow
log. Slow UPDATE, DELETE and INSERT statements report 0 rows
examined, unless the statement has a condition including a
SELECT substatement.
      
This patch adds counting of examined rows for the UPDATE and
DELETE statements. An INSERT ... VALUES statement will still 
not report any rows as examined.



sql/sql_class.h:
  Added more docs for THD::examined_row_count.
sql/sql_delete.cc:
  Add incrementing thd->examined_row_count.
sql/sql_update.cc:
  Add incrementing thd->examined_row_count.
2010-05-12 13:19:12 +02:00
Martin Hansson
79e60f0a40 Bug#48157: crash in Item_field::used_tables
MySQL handles the join syntax "JOIN ... USING( field1,
... )" and natural joins by building the same parse tree as
a corresponding join with an "ON t1.field1 = t2.field1 ..."
expression would produce. This parse tree was not cleaned up
properly in the following scenario. If a thread tries to
lock some tables and finds that the tables were dropped and
re-created while waiting for the lock, it cleans up column
references in the statement by means a per-statement free
list. But if the statement was part of a stored procedure,
column references on the stored procedure's free list
weren't cleaned up and thus contained pointers to freed
objects.
      
Fixed by adding a call to clean up the current prepared
statement's free list.

This is a backport from MySQL 5.1
2010-05-11 16:21:05 +02:00
Mattias Jonsson
6fa04cad8f merge 2010-05-10 15:17:06 +02:00
Martin Hansson
6d0425b18d Bug#50939: Loose Index Scan unduly relies on engine to
remember range endpoints

The Loose Index Scan optimization keeps track of a sequence
of intervals. For the current interval it maintains the
current interval's endpoints. But the maximum endpoint was
not stored in the SQL layer; rather, it relied on the
storage engine to retain this value in-between reads. By
coincidence this holds for MyISAM and InnoDB. Not for the
partitioning engine, however.

Fixed by making the key values iterator 
(QUICK_RANGE_SELECT) keep track of the current maximum endpoint.
This is also more efficient as we save a call through the
handler API in case of open-ended intervals.

The code to calculate endpoints was extracted into 
separate methods in QUICK_RANGE_SELECT, and it was possible to
get rid of some code duplication as part of fix.
2010-05-10 09:23:23 +02:00
Alfranio Correia
209cccf55d BUG#49019 Mixing self-logging eng. and regular eng. does not switch to row in mixed mode
Backport of the patch for 5.1-bugteam.
2010-05-09 23:45:25 +01:00
He Zhenxing
df0b6707da Bug#53189 Table map version unused and can be removed
MYSQL_BIN_LOG m_table_map_version member and it's associated 
functions were not used in the logic of binlogging and replication,
this patch removed all related code.

sql/log.cc:
  removed unused m_table_map_version variable and functions
sql/log.h:
  removed unused m_table_map_version variable and functions
sql/log_event.h:
  Removed unused LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F flag
sql/sql_class.cc:
  Removed unused LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F flag
sql/sql_load.cc:
  Removed unused LOG_EVENT_UPDATE_TABLE_MAP_VERSION_F flag
sql/table.cc:
  removed unused table_map_version variable
sql/table.h:
  removed unused table_map_version variable
2010-05-08 11:25:33 +08:00
Luis Soares
2646306cc9 BUG#49522: Replication problem with mixed MyISAM/InnoDB
When using a non-transactional table (t1) on the master 
and with autocommit disabled, no COMMIT is recorded 
in the binary log ending the statement. Therefore, if 
the slave has t1 in a transactional engine, then it will 
be as if a transaction is started but never ends. This is
actually BUG#29288 all over again.

We fix this by cherrypicking the cset for BUG#29288 which
was pushed to a later mysql version. The revision picked
was: mats@sun.com-20090923094343-bnheplq8n95opjay .

Additionally, a test case for covering the scenario depicted
in the bug report is included in this cset.
2010-05-07 18:48:35 +01:00
Martin Hansson
721ec08190 Merge of fix for Bug#52357 2010-05-07 09:12:16 +02:00
Sergey Glukhov
278ae9a8d5 Bug#53334 Incorrect result for InnoDB in LEFT JOIN with impossible condition
The fix actually reverts the change introduced
by the patch for bug 51494.
The fact is that patches for bugs 52177&48419
fix bugs 51194&50575 as well.



mysql-test/r/innodb_mysql.result:
  test case
mysql-test/t/innodb_mysql.test:
  test case
sql/sql_select.cc:
  reverted wrong fix for bug 51494
2010-05-07 10:38:42 +05:00
Gleb Shchepa
bd2a517b23 Bug #53088: mysqldump with -T & --default-character-set set
truncates text/blob to 766 chars

mysqldump and SELECT ... INTO OUTFILE truncated long BLOB/TEXT
values to size of 766 bytes (MAX_FIELD_WIDTH or 255 * 3 + 1).

The select_export::send_data method has been modified to
reallocate a conversion buffer for long field data.


mysql-test/r/mysqldump.result:
  Test case for bug #53088.
mysql-test/r/outfile_loaddata.result:
  Test case for bug #53088.
mysql-test/t/mysqldump.test:
  Test case for bug #53088.
mysql-test/t/outfile_loaddata.test:
  Test case for bug #53088.
sql/sql_class.cc:
  Bug #53088: mysqldump with -T & --default-character-set set
              truncates text/blob to 766 chars
  
  The select_export::send_data method has been modified to
  reallocate a conversion buffer for long field data.
2010-05-07 00:41:37 +04:00
Martin Hansson
0c82d3f3f4 Merge of fix for Bug#52357 2010-05-06 10:59:28 +02:00
Martin Hansson
1eada91053 Bug#52357: Assertion failed: join->best_read in
greedy_search optimizer_search_depth=0

The algorithm inside restore_prev_nj_state failed to
properly update the counters within the NESTED_JOIN
tree. The counter was decremented each time a table in the
node was removed from the QEP, the correct thing to do being
only to decrement it when the last table in the child node
was removed from the plan. This lead to node counters
getting negative values and the plan thus appeared
impossible. An assertion caught this.

Fixed by not recursing up the tree unless the last table in
the join nest node is removed from the plan
2010-05-06 10:45:00 +02:00
Georgi Kodinov
addd0a3e67 On behalf of Kristofer :
Bug#53417 my_getwd() makes assumptions on the buffer sizes which not always hold true
      
The mysys library contains many functions for rewriting file paths. Most of these
functions makes implicit assumptions on the buffer sizes they write to. If a path is put
in my_realpath() it will propagate to my_getwd() which assumes that the buffer holding
the path name is greater than 2. This is not true in cases.
      
In the special case where a VARBIN_ITEM is passed as argument to the LOAD_FILE function
this can lead to a crash.
      
This patch fixes the issue by introduce more safe guards agaist buffer overruns.
2010-05-05 11:54:52 +03:00
Alfranio Correia
ed4819bbf7 merge mysql-5.1-bugteam (local) --> mysql-5.1-bugteam 2010-05-04 23:15:10 +01:00
Georgi Kodinov
71b453fa06 Bug #53371: COM_FIELD_LIST can be abused to bypass table level grants.
This is the 5.1 merge and extension of the fix.
The server was happily accepting paths in table name in all places a table
name is accepted (e.g. a SELECT). This allowed all users that have some 
privilege over some database to read all tables in all databases in all
mysql server instances that the server file system has access to.
Fixed by :
1. making sure no path elements are allowed in quoted table name when
constructing the path (note that the path symbols are still valid in table names
when they're properly escaped by the server).
2. checking the #mysql50# prefixed names the same way they're checked for
path elements in mysql-5.0.
2010-05-04 17:03:28 +03:00
Mattias Jonsson
f33075fd16 merge 2010-05-04 14:26:44 +02:00
Alfranio Correia
3c30921662 BUG#43407 SET GLOBAL SQL_SLAVE_SKIP_COUNTER should log previous state in error log
When issuing a 'SET GLOBAL SQL_SLAVE_SKIP_COUNTER' statement, the previous
position along with the new position is dumped into the error log. Namely,
the following information is printed out: skip_counter, group_relay_log_name
and group_relay_log_pos.
2010-05-04 10:41:28 +01:00
Alfranio Correia
819caf8eb8 BUG#43406 CHANGE MASTER TO should log previous state in error log
When issuing a 'CHANGE MASTER TO' statement, key elements of the previous
state, namely the host, port, the master_log_file and the master_log_pos
are dumped into the error log.
2010-05-04 10:17:20 +01:00
Kristofer Pettersson
5dd5d70506 Bug#50373 --secure-file-priv=""
Iterative patch improvement. Previously committed patch
caused wrong result on Windows. The previous patch also
broke secure_file_priv for symlinks since not all file
paths which must be compared against this variable are
normalized using the same norm.

The server variable opt_secure_file_priv wasn't
normalized properly and caused the operations
LOAD DATA INFILE .. INTO TABLE ..
and
SELECT load_file(..)
to do different interpretations of the 
--secure-file-priv option.
     
The patch moves code to the server initialization
routines so that the path always is normalized
once and only once.
      
It was also intended that setting the option
to an empty string should be equal to 
lifting all previously set restrictions. This
is also fixed by this patch.


mysql-test/r/loaddata.result:
  * Removed test code which will currently break the much used --mem feature of mtr.
mysql-test/t/loaddata.test:
  * Removed test code which will currently break the much used --mem feature of mtr.
sql/item_strfunc.cc:
  * Replaced string comparing code on opt_secure_file_priv with an interface which guarantees that both file paths are normalized using the same norm on all platforms.
sql/mysql_priv.h:
  * Added signature for is_secure_file_path()
sql/mysqld.cc:
  * New function for checking if a path compatible with the secure path restriction.
  * Added initialization of the opt_secure_file_priv variable.
sql/sql_class.cc:
  * Replaced string comparing code on opt_secure_file_priv with an interface which guarantees that both file paths are normalized using the same norm on all platforms.
sql/sql_load.cc:
  * Replaced string comparing code on opt_secure_file_priv with an interface which guarantees that both file paths are normalized using the same norm on all platforms.
2010-05-03 18:14:39 +02:00
Georgi Kodinov
f63608ea97 Bug #53371: COM_FIELD_LIST can be abused to bypass table level grants.
The server was not checking the supplied to COM_FIELD_LIST table name
for validity and compliance to acceptable table names standards.
Fixed by checking the table name for compliance similar to how it's 
normally checked by the parser and returning an error message if 
it's not compliant.
2010-05-03 18:16:51 +03:00
Alexey Kopytov
26570994b2 Automerge. 2010-04-30 15:27:17 +04:00
Alexey Kopytov
97374a1184 Bug #48419: another explain crash..
WHERE predicates containing references to empty tables in a
subquery were handled incorrectly by the optimizer when
executing EXPLAIN. As a result, the optimizer could try to
evaluate such predicates rather than just stop with
"Impossible WHERE noticed after reading const tables" as 
it would do in a non-subquery case. This led to valgrind 
errors and crashes.

Fixed the code checking the above condition so that subqueries
are not excluded and hence are handled in the same way as top
level SELECTs.

mysql-test/r/explain.result:
  Added a test case for bug #48419.
mysql-test/r/ps.result:
  Updated test results to take the new (and more correct)
  "Extra" comments in execution plans.
mysql-test/t/explain.test:
  Added a test case for bug #48419.
sql/sql_select.cc:
  There is no point in excluding subqueries from checking
  for identically false WHERE conditions.
2010-04-30 15:10:48 +04:00
Davi Arnaut
4e378bc55b Manual merge. 2010-04-29 20:18:19 -03:00
Davi Arnaut
54705ab176 Bug#50974: Server keeps receiving big (> max_allowed_packet) packets indefinitely.
The server could be tricked to read packets indefinitely if it
received a packet larger than the maximum size of one packet.
This problem is aggravated by the fact that it can be triggered
before authentication.

The solution is to no skip big packets for non-authenticated
sessions. If a big packet is sent before a session is authen-
ticated, a error is returned and the connection is closed.

include/mysql_com.h:
  Add skip flag. Only used in server builds.
sql/net_serv.cc:
  Control whether big packets can be skipped.
2010-04-29 10:28:16 -03:00
Ramil Kalimullin
0d5dbb166b Fix for bug #53237: mysql_list_fields/COM_FIELD_LIST stack smashing
Problem: "COM_FIELD_LIST is an old command of the MySQL server, before there was real move to only
SQL. Seems that the data sent to COM_FIELD_LIST( mysql_list_fields() function) is not
checked for sanity. By sending long data for the table a buffer is overflown, which can
be used deliberately to include code that harms".

Fix: check incoming data length.


sql/sql_parse.cc:
  Fix for bug #53237: mysql_list_fields/COM_FIELD_LIST stack smashing
    - check incoming mysql_list_fields() table name arg length.
2010-04-29 08:42:32 +04:00
Alexey Kopytov
6d43510a42 Backport of the fix for bug #50335 to 5.0.
The problem was in an incorrect debug assertion. The expression
used in the failing assertion states that when finding
references matching ORDER BY expressions, there can be only one
reference to a single table. But that does not make any sense,
all test cases for this bug are valid examples with multiple
identical WHERE expressions referencing the same table which
are also present in the ORDER BY list.

Fixed by removing the failing assertion. We also have to take
care of the 'found' counter so that we count multiple
references only once. We rely on this fact later in
eq_ref_table().

mysql-test/r/join.result:
  Added a test case for bug #50335.
mysql-test/t/join.test:
  Added a test case for bug #50335.
sql/sql_select.cc:
  Removing the assertion in eq_ref_table() as it does not make
  any sense. We also have to take care of the 'found' counter so
  that we count multiple references only once. We rely on this
  fact later in eq_ref_table().
2010-04-27 00:06:00 +04:00
Ingo Struewing
e1418b14ec Bug#46339 - crash on REPAIR TABLE merge table USE_FRM
REPAIR TABLE ... USE_FRM crashed debug servers.

A wrong assert assumed that this operation would not be executed
for MERGE tables.

Removed the assert.


mysql-test/r/merge.result:
  Bug#46339 - crash on REPAIR TABLE merge table USE_FRM
  Added test result.
mysql-test/t/merge.test:
  Bug#46339 - crash on REPAIR TABLE merge table USE_FRM
  Added test.
sql/sql_table.cc:
  Bug#46339 - crash on REPAIR TABLE merge table USE_FRM
  Removed false assert.
2010-04-26 15:44:10 +02:00
Luis Soares
fbe81e3c97 BUG#52868: Wrong handling of NULL value during update, replication out
of sync

In RBR, sometimes the table->s->last_null_bit_pos can be zero. This
has impact at the slave when it compares records fetched from the
storage engine against records in the binary log event. If
last_null_bit_pos is zero the slave, while comparing in
log_event.cc:record_compare function, would set all bits in the last
null_byte to 1 (assumed all 8 were unused) . Thence it would loose the
ability to distinguish records that were similar in contents except
for the fact that some field was null in one record, but not in the
other. Ultimately this would cause wrong matches, and in the specific
case depicted in the bug report the same record would be updated
twice, resulting in a lost update.

Additionally, in the record_compare function the slave was setting the
X bit unconditionally. There are cases that the X bit does not exist
in the record header. This could also lead to wrong matches between
records.

We fix both by conditionally resetting the bits: (i) unused null_bits
are set if last_null_bit_pos > 0; (ii) X bit is set if
HA_OPTION_PACK_RECORD is in use.

mysql-test/extra/rpl_tests/rpl_record_compare.test:
  Shared part of the test case for MyISAM and InnoDB.
mysql-test/suite/rpl/t/rpl_row_rec_comp_innodb.test:
  InnoDB test case.
mysql-test/suite/rpl/t/rpl_row_rec_comp_myisam.test:
  MyISAM test case. Added also coverage for Field_bits case.
sql/log_event.cc:
  Deployed conditional setting of unused bits at record_compare.
sql/log_event_old.cc:
  Same change as in log_event.cc.
2010-04-21 13:47:55 +01:00
Kristofer Pettersson
4859951a90 automerge 2010-04-20 20:19:20 +02:00
Kristofer Pettersson
3a626d1027 Bug#50373 --secure-file-priv=""
Correcting a patch misstake. The converted file path is placed in 'buff' not in opt_secure_file_priv.

mysql-test/r/loaddata.result:
  * Updated test case; Since secure_file_priv now is normalized the previous values are changed.
sql/mysqld.cc:
  * Fixed patch misstake
2010-04-20 16:17:34 +02:00
Staale Smedseng
8b16a2a55b Bug#51591 deadlock in the plugins+status+variables
Unlocking/locking of LOCK_plugin in ha_ndbcluster.cc not 
needed anymore (but missing from the initial patch).
2010-04-19 15:48:37 +02:00
Kristofer Pettersson
95da93d7ac Automerge 2010-04-16 16:56:16 +02:00
Kristofer Pettersson
794a441317 Bug#50373 --secure-file-priv=""
The server variable opt_secure_file_priv wasn't
normalized properly and caused the operations
LOAD DATA INFILE .. INTO TABLE ..
and
SELECT load_file(..)
to do different interpretations of the 
--secure-file-priv option.

The patch moves code to the server initialization
routines so that the path always is normalized
once and only once.

It was also intended that setting the option
to an empty string should be equal to 
lifting all previously set restrictions. This
is also fixed by this patch.


sql/mysqld.cc:
  * If --secure_file_option is an empty string then the option variable
    should be unset.
  * opt_secure_file_option should be normalized once when the server starts.
sql/sql_load.cc:
  * moved variable normalization code to fix_paths()
2010-04-16 16:10:47 +02:00
Staale Smedseng
9743819d36 Bug#51591 deadlock in the plugins+status+variables
Potential deadlock situation involving LOCK_plugin,
LOCK_global_system_variables and LOCK_status.
      
This patch backports the fix from next-mr, unlocking
LOCK_plugin before calling plugin->init() and
add_status_vars().
2010-04-16 15:02:23 +02:00
Sergey Glukhov
649deaa8a1 Bug#52124 memory leaks like a sieve in datetime, timestamp, time, date fields + warnings
Arg_comparator initializes 'comparators' array in case of
ROW comparison and does not free this array on destruction.
It leads to memory leaks.
The fix:
-added Arg_comparator::cleanup() method which frees
 'comparators' array.
-added Item_bool_func2::cleanup() method which calls 
 Arg_comparator::cleanup() method


mysql-test/r/ps.result:
  test case
mysql-test/r/row.result:
  test case
mysql-test/t/ps.test:
  test case
mysql-test/t/row.test:
  test case
sql/item_cmpfunc.h:
  -added Arg_comparator::cleanup() method which frees
   'comparators' array.
  -added Item_bool_func2::cleanup() method which calls 
   Arg_comparator::cleanup() method
2010-04-16 16:42:34 +05:00
Luis Soares
8fa9a5861b automerge: merged bug clone into latest mysql-5.1-bugteam. 2010-04-16 01:59:21 +01:00
Georgi Kodinov
93013ae630 Bug #52711: Segfault when doing EXPLAIN SELECT with
union...order by (select... where...)

The problem is mysql is trying to materialize and 
cache the scalar sub-queries at JOIN::optimize
even for EXPLAIN where the number of columns is 
totally different from what's expected.
Fixed by not executing the scalar subqueries 
for EXPLAIN.
2010-04-15 17:04:24 +03:00
Sergey Vojtovich
c37bfe0ae6 Merge fix for BUG39053 to 5.1-bugteam. 2010-04-14 15:53:43 +04:00
Sergey Vojtovich
4aa36ee7b6 BUG#39053 - UNISTALL PLUGIN does not allow the storage engine
to cleanup open connections

It was possible to UNINSTALL storage engine plugin when binding
between THD object and storage engine is still active (e.g. in
the middle of transaction).

To avoid unclean deactivation (uninstall) of storage engine plugin
in the middle of transaction, additional storage engine plugin
lock is acquired by thd_set_ha_data().

If ha_data is not null and storage engine plugin was not locked
by thd_set_ha_data() in this connection before, storage engine
plugin gets locked.

If ha_data is null and storage engine plugin was locked by
thd_set_ha_data() in this connection before, storage engine
plugin lock gets released.

If handlerton::close_connection() didn't reset ha_data, server does
it immediately after calling handlerton::close_connection().

Note that this is just a framework fix, storage engines must switch
to thd_set_ha_data() from thd_ha_data() if they want to see fit.

include/mysql/plugin.h:
  As thd_{get|set}_ha_data() have some extra logic now, they
  must be implemented on server side.
include/mysql/plugin.h.pp:
  As thd_{get|set}_ha_data() have some extra logic now, they
  must be implemented on server side.
sql/handler.cc:
  Make sure ha_data is reset and ha_data lock is released.
sql/handler.h:
  hton is not supposed to be updated by ha_lock_engine(),
  make it const.
sql/sql_class.cc:
  As thd_{get|set}_ha_data() have some extra logic now, they
  must be implemented on server side.
sql/sql_class.h:
  Added ha_data lock.
2010-04-14 13:53:59 +04:00
Georgi Kodinov
287fa3caf5 Bug #52512: Assertion `! is_set()' in Diagnostics_area::set_ok_status
on LOAD DATA

Two problems :
1. LOAD DATA was not checking for SQL errors and was sending an OK
packet even when there were errors reported already. Fixed to check for
SQL errors in addition to the error conditions already detected.
2. There was an over-ambitious assert() on the server to check if the 
protocol is always followed by the client. This can cause crashes on 
debug servers by clients not completing the protocol exchange for some
reason (e.g. --send command in mysqltest). Fixed by keeping the assert
only on client side, since the server always completes the protocol 
exchange.
2010-04-07 18:17:56 +03:00
Sergey Glukhov
ba229d799a Bug#52120 create view cause Assertion failed: 0, file .\item_subselect.cc, line 817
We should disable const subselect item evaluation because
subselect transformation does not happen in view_prepare_mode
and thus val_...() methods can not be called.


mysql-test/r/ctype_ucs.result:
  test case
mysql-test/r/view.result:
  test case
mysql-test/t/ctype_ucs.test:
  test case
mysql-test/t/view.test:
  test case
sql/item.cc:
  disabled const subselect item evaluation in
  view prepare mode.
sql/item_subselect.cc:
  added Item_subselect::safe_charset_converter which
  prevents const item evaluation in view prepare mode.
sql/item_subselect.h:
  added Item_subselect::safe_charset_converter which
  prevents const item evaluation in view prepare mode.
2010-04-06 12:26:59 +05:00
Sergey Glukhov
c1ad5072b8 Bug#52336 Segfault / crash in 5.1 copy_fields (param=0x9872980) at sql_select.cc:15355
The problem is that we can not use make_cond_for_table().
This function relies on used_tables() condition
which is not set properly for subqueries.
As result subquery is not filtered out.
The fix is to use remove_eq_conds() function instead
of make_cond_for_table() func. 'remove_eq_conds()'
algorithm relies on const_item() value and it allows
to handle subqueries in right way.


mysql-test/r/having.result:
  test case
mysql-test/t/having.test:
  test case
sql/sql_select.cc:
  The fix is to use remove_eq_conds() function instead
  of make_cond_for_table() function.
2010-04-05 16:10:26 +05:00
Gleb Shchepa
e2a546aef4 Bug #40625: Concat fails on DOUBLE values in a Stored
Procedure, while DECIMAL works

Selecting of the CONCAT(...<SP variable>...) result into
a user variable may return wrong data.


Item_func_concat::val_str contains a number of memory
allocation-saving tricks. One of them concatenates
strings inplace inserting the value of one string
at the beginning of the other string. However,
this trick didn't care about strings those points
to the same data buffer: this is possible when
a CONCAT() parameter is a stored procedure variable -
Item_sp_variable::val_str() uses the intermediate
Item_sp_variable::str_value field, where it may
store a reference to an external buffer.


The Item_func_concat::val_str function has been
modified to take into account val_str functions
(such as Item_sp_variable::val_str) that return
a pointer to an internal Item member variable
that may reference to a buffer provided.


mysql-test/r/func_concat.result:
  Test case for the bug #40625.
mysql-test/t/func_concat.test:
  Test case for the bug #40625.
sql/item_strfunc.cc:
  Bug #40625: Concat fails on DOUBLE values in a Stored
              Procedure, while DECIMAL works
  
  The Item_func_concat::val_str function has been
  modified to take into account val_str functions
  (such as Item_sp_variable::val_str) that return
  a pointer to an internal Item member variable
  that may reference to a buffer provided.
2010-04-03 00:30:22 +04:00
Anurag Shekhar
ab8ff15cd1 Bug #47904 Incorrect results w/ table subquery, derived SQs, and LEFT JOIN
on index

'my_decimal' class has two members which can be used to access the 
value. The member variable buf (inherited from parent class decimal_t) 
is set to member variable buffer so that both are pointing to same value.

Item_copy_decimal::copy() uses memcpy to clone 'my_decimal'. The member
buffer is declared as an array and memcpy results in copying the values
of the array, but the inherited member buf, which should be pointing at
the begining of the array 'buffer' starts pointing to the begining of 
buffer in original object (which is being cloned). Further updates on 
'my_decimal' updates only the inherited member 'buf' but leaves 
buffer unchanged.

Later when the new object (which now holds a inconsistent value) is cloned
again using proper cloning function 'my_decimal2decimal' the buf pointer
is fixed resulting in loss of the current value.

Using my_decimal2decimal instead of memcpy in Item_copy_decimal::copy()
fixed this problem.


mysql-test/r/subselect.result:
  Updated result file after addding test case for bug#47904.
mysql-test/t/subselect.test:
  Added test case for bug#47904.
sql/item.cc:
  Memcopy shouldn't be used to clone my_decimal. Use my_decimal2decimal
  instead.
2010-04-02 01:35:36 +05:30
Davi Arnaut
7ecad98c45 Bug#50755: Crash if stored routine def contains version comments
The problem was that a syntactically invalid trigger could cause
the server to crash when trying to list triggers. The crash would
happen due to a mishap in the backup/restore procedure that should
protect parser items which are not associated with the trigger. The
backup/restore is used to isolate the parse tree (and context) of
a statement from the load (and parsing) of a trigger. In this case,
a error during the parsing of a trigger could cause the improper
backup/restore sequence.

The solution is to properly restore the original statement context
before the parser is exited due to syntax errors in the trigger body.

mysql-test/r/trigger.result:
  Add test case result for Bug#50755
mysql-test/t/trigger.test:
  Add test case for Bug#50755
sql/sp_head.cc:
  Merge sp_head::destroy() and sp_head destructor. Retrieve THD
  from the LEX so that m_thd is not necessary.
sql/sql_lex.cc:
  Explicitly restore the original environment.
2010-04-01 10:15:22 -03:00
Ramil Kalimullin
2303a8c6e4 Manual merge. 2010-04-29 08:54:09 +04:00
Georgi Kodinov
4d0e9957ac Bug #47453: InnoDB incorrectly changes TIMESTAMP columns when JOINed
during an UPDATE

Extended the fix for bug 29310 to multi-table update:

When a table is being updated it has two set of fields - fields required for
checks of conditions and fields to be updated. A storage engine is allowed
not to retrieve columns marked for update. Due to this fact records can't
be compared to see whether the data has been changed or not. This makes the
server always update records independently of data change.
  
Now when an auto-updatable timestamp field is present and server sees that
a table handle isn't going to retrieve write-only fields then all of such
fields are marked as to be read to force the handler to retrieve them.
2010-04-28 15:55:54 +03:00
Vladislav Vaintroub
f72dcc9be8 Bug #48042 The description for Event ID ( 100 ) in Source ( MySQL ) cannot be found.
The problem is that message resource  (message.rc) is compiled as part of static library
sql.lib rather than with executable mysqld.exe. resource files do not work in static
libraries.

The fix is to add message.rc to mysqld.exe source files list.
2010-04-26 23:59:50 +02:00
Ramil Kalimullin
6595861f58 Fix for bug#50946: fast index creation still seems to copy the table
Problem: ALTER TABLE ADD INDEX may lead to table copying if there's
numeric field(s) with non-default display width modificator specified.

Fix: compare numeric field's storage lenghts when we decide whether 
they can be considered 'equal' for table alteration purposes.


mysql-test/r/error_simulation.result:
  Fix for bug#50946: fast index creation still seems to copy the table
    - test result.
mysql-test/t/error_simulation.test:
  Fix for bug#50946: fast index creation still seems to copy the table
    - test case.
sql/field.cc:
  Fix for bug#50946: fast index creation still seems to copy the table
    - check numeric field's pack lengths instead of it's display lenghts
  comparing fields equality for table alteration purposes.
sql/sql_table.cc:
  Fix for bug#50946: fast index creation still seems to copy the table
    - check compare_tables() result for testing purposes.
2010-04-25 15:06:40 +04:00
Staale Smedseng
20c9177518 Bug#46261 Plugins can be installed with --skip-grant-tables
Previously installed dynamic plugins are explicitly not loaded
on startup with --skip-grant-tables enabled. However, INSTALL
PLUGIN/UNINSTALL PLUGIN commands are allowed, and result in
inconsistent error messages (reporting duplicate plugin or
plugin does not exist).

This patch adds a check for --skip-grant-tables mode, and
returns error ER_OPTION_PREVENTS_STATEMENT to the user when
the above commands are attempted.
2010-04-22 15:52:00 +02:00
Georgi Kodinov
2a873bc03e merge 2010-04-01 14:04:45 +03:00
Georgi Kodinov
e65caec138 Bug #37168: Missing variable - skip_name_resolve
Added a read-only global boolean variable skip_name_resolve.
2010-03-31 16:12:37 +03:00
Ramil Kalimullin
55852670cc Fix for bug#52397: another crash with explain extended and group_concat
Problem: EXPLAIN EXTENDED was trying to resolve references to 
freed temporary table fields for GROUP_CONCAT()'s ORDER BY arguments.

Fix: use stored original GROUP_CONCAT()'s arguments in such a case.


mysql-test/r/func_gconcat.result:
  Fix for bug#52397: another crash with explain extended and group_concat
    - test result.
mysql-test/t/func_gconcat.test:
  Fix for bug#52397: another crash with explain extended and group_concat
    - test case.
sql/item_sum.cc:
  Fix for bug#52397: another crash with explain extended and group_concat
    - use "pargs", printing ORDER BY arguments in the 
  Item_func_group_concat::print() instead of "order" to avoid
  possible reference resolving to (freed) temporary table fields.
2010-03-31 17:00:56 +04:00
Sergey Glukhov
6eca53f1d3 fixed compiler warning 2010-03-29 18:42:49 +05:00
unknown
454c003a5c Bug #50407 mysqlbinlog --database=X produces bad output for SAVEPOINTs
When mysqlbinlog was given the --database=X flag, it always printed
'ROLLBACK TO', but the corresponding 'SAVEPOINT' statement was not
printed. The replicated filter(replicated-do/ignore-db) and binlog
filter (binlog-do/ignore-db) has the same problem. They are solved
in this patch together.

After this patch, We always check whether the query is 'SAVEPOINT'
statement or not. Because this is a literal check, 'SAVEPOINT' and
'ROLLBACK TO' statements are also binlogged in uppercase with no
any comments.

The binlog before this patch can be handled correctly except one case
that any comments are in front of the keywords. for example:
 /* bla bla */ SAVEPOINT a;
 /* bla bla */ ROLLBACK TO a;
2010-03-28 19:57:33 +08:00
unknown
4775601012 Bug #50095 Multi statement including CREATE EVENT causes rotten binlog entry
The log event of 'CREATE EVENT' was being binlogged with garbage
at the end of the query if 'CREATE EVENT' is followed by another SQL statement
and they were executed as one command.
for example:
    DELIMITER |;
    CREATE EVENT e1 ON EVERY DAY DO SELECT 1; SELECT 'a';
    DELIMITER ;|
When binlogging 'CREATE EVENT', we always create a new statement with definer
and write it into the log event. The new statement is made from cpp_buf(preprocessed buffer).
which is not a c string(end with '\0'), but it is copied as a c string.

In this patch, cpp_buf is copied with its length.
2010-03-28 16:37:47 +08:00
Sergey Glukhov
f57839cd60 Bug#52177 crash with explain, row comparison, join, text field
The crash is the result of an attempt made by JOIN::optimize to evaluate
the WHERE condition when no records have been actually read.
The fix is to remove erroneous 'outer_join' variable check.


mysql-test/r/join.result:
  test result
mysql-test/t/join.test:
  test case
sql/sql_select.cc:
  removed erroneous 'outer_join' variable check.
2010-03-26 11:44:24 +04:00
Sergey Glukhov
d5325c7793 Bug#52164 Assertion failed: param.sort_length, file .\filesort.cc, line 149
The crash happens because of incorrect max_length calculation
in QUOTE function(due to overflow). max_length is set
to 0 and it leads to assert failure.
The fix is to cast expression result to
ulonglong variable and adjust it if the
result exceeds MAX_BLOB_WIDTH.


mysql-test/r/func_str.result:
  test case
mysql-test/t/func_str.test:
  test case
sql/item_strfunc.h:
  cast expression result to ulonglong variable and
  adjust it if the result exceeds MAX_BLOB_WIDTH.
2010-03-26 09:49:35 +04:00
Andrei Elkin
f05d975284 merge from 5.1-bt rep 2010-03-25 18:13:23 +02:00
Sergey Vojtovich
3b091bbaf4 Merge fixes for BUG51877, BUG51866, BUG47598 to mysql-5.1-bugteam. 2010-03-25 19:59:54 +04:00
Andrei Elkin
dc62faf440 merging bug#52304 to 5.1-bt,pe 2010-03-25 14:49:24 +02:00
Sergey Vojtovich
5eff6aed0e Merge fix for BUG51866 to mysql-5.1-bugteam. 2010-03-25 16:11:16 +04:00
Sergey Vojtovich
412798658a BUG#51866 - crash with repair by sort and fulltext keys
Repairing MyISAM table with fulltext indexes and low
myisam_sort_buffer_size may crash the server.

Estimation of number of index entries was done incorrectly,
causing further assertion failure or server crash.

Docs note: min value for myisam_sort_buffer_size has been
changed from 4 to 4096.

mysql-test/r/fulltext.result:
  A test case for BUG#51866.
mysql-test/r/myisam.result:
  Min value for myisam_sort_buffer_size is 4096.
mysql-test/r/variables.result:
  Min value for myisam_sort_buffer_size is 4096.
mysql-test/suite/sys_vars/r/myisam_sort_buffer_size_basic_32.result:
  Min value for myisam_sort_buffer_size is 4096.
mysql-test/t/fulltext.test:
  A test case for BUG#51866.
sql/mysqld.cc:
  Min value for myisam_sort_buffer_size is 4096.
storage/myisam/mi_check.c:
  When estimating number of index entries for external
  fulltext parser, take into account that key_length may
  be bigger than myisam_sort_buffer_size. Reuse logic
  from _create_index_by_sort(): force MIN_SORT_BUFFER to
  be min value for myisam_sort_buffer_size.
  
  Another problem is that ftkey_nr has no other meaning
  than serial number of fulltext index starting with 1.
  We can't say if this key using built-in or external
  parser basing on it's value. In other words we always
  entered if-branch for external parser. At this point,
  the only way to check if we use default parser is to
  compare keyinfo::parser with &ft_default_parser.
storage/myisam/sort.c:
  Get rid of MIN_SORT_MEMORY, use MIN_SORT_BUFFER instead
  (defined in myisamdef.h, has the same value and purpose).
2010-03-25 16:08:21 +04:00
Alexey Botchkov
f3b8b07a43 merging. 2010-03-24 16:14:47 +04:00
Kristofer Pettersson
61b9ce16fd Automerge 2010-03-25 13:26:48 +01:00
Kristofer Pettersson
ea7d830ad2 Bug#46615 Assertion in Query_cache::invalidate in INSERT in a VIEW of a MERGE table
If the listed columns in the view definition of 
the table used in a 'INSERT .. SELECT ..'
statement mismatched, a debug assertion would
trigger in the cache invalidation code
following the failing statement.

Although the find_field_in_view() function
correctly generated ER_BAD_FIELD_ERROR during
setup_fields(), the error failed to propagate
further than handle_select(). This patch fixes
the issue by adding a check for the return
value.


mysql-test/r/query_cache_with_views.result:
  * added test for bug 46615
mysql-test/t/query_cache_with_views.test:
  * added test for bug 46615
sql/sql_parse.cc:
  * added check for handle_select() return code before attempting to invalidate the cache.
2010-03-24 17:37:41 +01:00
Alexey Botchkov
9a9501c2aa merging. 2010-03-24 16:03:29 +04:00
Sergey Glukhov
fe25ec8f24 5.0-bugteam->5.1-bugteam merge 2010-03-24 14:45:09 +04:00
Sergey Glukhov
bccf219bfc Bug#48483 crash in get_best_combination()
The crash happens because greedy_serach
can not determine best plan due to
wrong inner table dependences. These
dependences affects join table sorting
which performs before greedy_search starting.
In our case table which has real 'no dependences'
should be put on top of the list but it does not
happen as inner tables have no dependences as well.
The fix is to exclude RAND_TABLE_BIT mask from
condition which checks if table dependences
should be updated.


mysql-test/r/join.result:
  test result
mysql-test/t/join.test:
  test case
sql/sql_select.cc:
  RAND_TABLE_BIT mask should not be counted as it
  prevents update of inner table dependences.
  For example it might happen if RAND() function
  is used in JOIN ON clause.
2010-03-24 14:37:28 +04:00
Georgi Kodinov
a9a2ceae1f Bug #51850: crash/memory overlap when using load data infile and set
col equal to itself!

There's no need to copy the value of a field into itself.
While generally harmless (except for some performance penalties)
it may be dangerous when the copy code doesn't expect this.
Fixed by checking if the source field is the same as the destination
field before copying the data.
Note that we must preserve the order of assignment of the null 
flags (hence the null_value assignment addition).
2010-03-23 17:07:00 +02:00
Andrei Elkin
649ec7758f Bug #52304 valgrind does not like to print un-inited string in Protocol_text::store()
The reason of the failure was apparent flaw in that a pointer to an uninitialized buffer was
passed to DBUG_PRINT of Protocol_text::store().

Fixed with splitting the print-out into two branches: 
one with length zero of the problematic arg and the rest.


sql/protocol.cc:
  correcting DBUG_PRINT to print out `from' with a care because one may be uninitialized in the caller.
2010-03-23 17:00:50 +02:00
Sergey Glukhov
3658bde736 5.0-bugteam->5.1-bugteam merge 2010-03-26 11:46:18 +04:00
Tatiana A. Nurnberg
28e95ba535 Bug#48525: trigger changes "Column 'id' cannot be null" behaviour
CHECK_FIELD_IGNORE was treated as CHECK_FIELD_ERROR_FOR_NULL;
UPDATE...SET...NULL on NOT NULL fields behaved differently after
a trigger.

Now distinguishes between IGNORE and ERROR_FOR_NULL and save/restores
check-field options.


mysql-test/r/trigger.result:
  Show that UPDATE...SET...NULL on NOT NULL columns doesn't behave differently
  when run after a trigger.
mysql-test/t/trigger.test:
  Show that UPDATE...SET...NULL on NOT NULL columns doesn't behave differently
  when run after a trigger.
sql/field_conv.cc:
  CHECK_FIELD_IGNORE was treated as CHECK_FIELD_ERROR_FOR_NULL.
  Distinguish between the two.
sql/sp_head.cc:
  Raise error as needed.
sql/sql_class.cc:
  Save and restore check-fields options.
sql/sql_class.h:
  Make room so we can save check-fields options.
sql/sql_insert.cc:
  Raise error as needed.
2010-03-29 03:32:30 +01:00
Luis Soares
fc34cd1c21 BUG#51987: revoke privileges logs wrong error code
A failed REVOKE statement is logged with error=0, thus causing
the slave to stop. The slave should not stop as this was an
expected error. Given that the execution failed on the master as
well the error code should be logged so that the slave can replay
the statement, get an error and compare with the master's
execution outcome. If errors match, then slave can proceed with
replication, as the error it got, when replaying the statement,
was expected.

In this particular case, the bug surfaces because the error code
is pushed to the THD diagnostics area after writing the event to
the binary log. Therefore, it would be logged with the THD
diagnostics area clean, hence its error code would not contain 
the correct code.

We fix this by moving the error reporting ahead of the call to
the routine that writes the event to the binary log.
2010-03-22 09:51:16 +00:00
Gleb Shchepa
8feadddbe4 Bug #49910: Behavioural change in SELECT/WHERE on YEAR(4) data type
(Original patch by Sinisa Milivojevic)

The YEAR(4) value of 2000 was equal to the "bad" YEAR(4) value of 0000.                              

The get_year_value() function has been modified to not adjust bad                                    
YEAR(4) value to 2000.


mysql-test/r/type_year.result:
  Test case for bug #49910.
mysql-test/t/type_year.test:
  Test case for bug #49910.
sql/item_cmpfunc.cc:
  Bug #49910: Behavioural change in SELECT/WHERE on YEAR(4) data type                                  
  
  The get_year_value() function has been modified to not adjust bad                                    
  YEAR(4) value to 2000.
2010-03-22 12:33:25 +04:00
Andrei Elkin
402d6ce67f merging bug@51648 to 5.1-bt, pe from local bugfixing branch 2010-03-21 21:30:49 +02:00
Sergey Glukhov
ad6e00e3b2 Bug#51242 HAVING clause on table join produce incorrect results
The problem is that when we make conditon for
grouped result const part of condition is cut off.
It happens because some parts of 'having' condition
which refer to outer join become const after
make_join_statistics. These parts may be lost
during further having condition transformation
in JOIN::exec. The fix is adding 'having'
condition check for const tables after
make_join_statistics is performed.


mysql-test/r/having.result:
  test case
mysql-test/t/having.test:
  test result
sql/sql_select.cc:
  added 'having' condition check for const tables
  after make_join_statistics is performed.
2010-03-19 13:09:22 +04:00
Andrei Elkin
c3cd608aef Bug #51648 DBUG_SYNC_POINT is not defined on all platforms and mtr cant pre-check that
DBUG_SYNC_POINT has at least one strong limitation that it's not defined
on all platforms. It has issues cooperating with @@debug.
All in all its functionality is superseded by DEBUG_SYNC facility and
there is no reason to maintain the old less flexible one.

Fixed with adding debug_sync_set_action() function as a facility to set up
a sync-action in the server sources code and re-writing existing simulations
(found 3) to use it.
Couple of tests have been reworked as well.

The patch offers a pattern for setting sync-points in replication threads
where the standard DEBUG_SYNC does not suffice to reach goals.





mysql-test/extra/rpl_tests/rpl_get_master_version_and_clock.test:
  rewriting the test from GET_LOCK()-based to DEBUG_SYNC-based;
  a pattern of usage DEBUG_SYNC for replication testing is provided.
mysql-test/suite/rpl/r/rpl_get_master_version_and_clock.result:
  results are changed.
mysql-test/suite/rpl/t/rpl_get_master_version_and_clock.test:
  rewriting the test from GET_LOCK()-based to DEBUG_SYNC-based;
  limiting the test to run only with MIXED binlog-format as the test last
  some 10 secs sensitively contributing to the total of tests run.
mysql-test/suite/rpl/t/rpl_show_slave_running.test:
  rewriting the test from GET_LOCK()-based to DEBUG_SYNC-based.
sql/debug_sync.cc:
  adding debug_sync_set_action() function as a facility to set up
  a sync-action in the server sources code.
sql/debug_sync.h:
  externalizing debug_sync_set_action().
sql/item_func.cc:
  purging sources from DBUG_SYNC_POINT.
sql/mysql_priv.h:
  purging sources from DBUG_SYNC_POINT.
sql/slave.cc:
  rewriting failure simulations to base on DEBUG_SYNC rather than GET_LOCK()-based DBUG_SYNC_POINT.
sql/sql_repl.cc:
  removing an orphan failure simulation line because no counterpart in tests existing.
2010-03-19 11:06:40 +02:00
Sergey Glukhov
d1c2e8508f Bug#51598 Inconsistent behaviour with a COALESCE statement inside an IN comparison
Optimizer erroneously translated LEFT JOIN into INNER JOIN.
It leads to cutting rows with NULL right side. It happens
because Item_row uses not_null_tables() method form the
base(Item) class and does not calculate 'null tables'
properly. The fix is adding calculation of 'not null tables'
to Item_row.


mysql-test/r/join_outer.result:
  test result
mysql-test/t/join_outer.test:
  test case
sql/item_row.cc:
  adding calculation of 'not null tables' to Item_row.
sql/item_row.h:
  adding calculation of 'not null tables' to Item_row.
2010-03-19 10:21:37 +04:00
Sergey Glukhov
caa1ccb0c3 Bug#51494 crash with join, explain and 'sounds like' operator
The crash happens because of discrepancy between values of
conts_tables and join->const_table_map(make_join_statisctics).
Calculation of conts_tables used condition with
HA_STATS_RECORDS_IS_EXACT flag check. Calculation of
join->const_table_map does not use this flag check.
In case of MERGE table without union with index
the table does not become const table and
thus join_read_const_table() is not called
for the table. join->const_table_map supposes
this table is const and later in make_join_select
this table is used for making&calculation const
condition. As table record buffer is not populated
it leads to crash.
The fix is adding a check if an engine supports
HA_STATS_RECORDS_IS_EXACT flag before updating
join->const_table_map.


mysql-test/r/merge.result:
  test result
mysql-test/t/merge.test:
  test case
sql/sql_select.cc:
  adding a check if an engine supports
  HA_STATS_RECORDS_IS_EXACT flag before updating
  join->const_table_map.
2010-03-19 10:01:02 +04:00
Mattias Jonsson
ca086708bc Additional fix for DEBUG_SYNC which failed for some rpl-tests,
due to DBUG_ASSERT. (added in bug#50561)

sql/sql_base.cc:
  DEBUG_SYNC asserts that thd->debug_sync_control is set.
2010-03-18 14:04:19 +01:00
Mats Kindahl
96d4a03846 Merging with mysql-5.1-bugteam 2010-03-17 19:15:41 +01:00
Mats Kindahl
2c5f439d65 BUG#49618: Field length stored incorrectly in binary log
for InnoDB
            
The class Field_bit_as_char stores the metadata for the
field incorrecly because bytes_in_rec and bit_len are set
to (field_length + 7 ) / 8 and 0 respectively, while
Field_bit has the correct values field_length / 8 and
field_length % 8.
            
Solved the problem by re-computing the values for the
metadata based on the field_length instead of using the
bytes_in_rec and bit_len variables.
            
To handle compatibility with old server, a table map
flag was added to indicate that the bit computation is
exact. If the flag is clear, the slave computes the
number of bytes required to store the bit field and
compares that instead, effectively allowing replication
*without conversion* from any field length that require
the same number of bytes to store.


mysql-test/suite/rpl/t/rpl_typeconv_innodb.test:
  Adding test to check compatibility for bit field
  replication when using InnoDB
sql/field.cc:
  Extending compatible_field_size() with flags from
  table map to allow fields to check master info.
sql/field.h:
  Extending compatible_field_size() with flags from
  table map to allow fields to check master info.
sql/log.cc:
  Removing table map flags since they are not used
  outside table map class.
sql/log_event.cc:
  Removing flags parameter from table map constructor
  since it is not used and does not have to be exposed.
sql/log_event.h:
  Adding flag to denote that bit length for bit field type
  is exact and not potentially rounded to even bytes.
sql/rpl_utility.cc:
  Adding fields to table_def to store table map flags.
sql/rpl_utility.h:
  Removing obsolete comment and adding flags to store
  table map flags from master.
2010-03-17 15:28:49 +01:00
Georgi Kodinov
ae49d9710b Bug #49838: DROP INDEX and ADD UNIQUE INDEX for same index may corrupt
definition at engine

If a single ALTER TABLE contains both DROP INDEX and ADD INDEX using 
the same index name (a.k.a. index modification) we need to disable 
in-place alter table because we can't ask the storage engine to have 
two copies of the index with the same name even temporarily (if we 
first do the ADD INDEX and then DROP INDEX) and we can't modify 
indexes that are needed by e.g. foreign keys if we first do 
DROP INDEX and then ADD INDEX.
Fixed the problem by disabling in-place ALTER TABLE for these cases.
2010-03-17 16:18:46 +02:00
Mattias Jonsson
5196beed02 Bug#50561: ALTER PARTITIONS does not have adequate lock, breaks with
concurrent I_S query

There were two problem:
1) MYSQL_LOCK_IGNORE_FLUSH also ignored name locks
2) there was a race between abort_and_upgrade_locks and
   alter_close_tables
   (i.e. remove_table_from_cache and
    close_data_files_and_morph_locks)

Which allowed the table to be opened with MYSQL_LOCK_IGNORE_FLUSH flag
resulting in renaming a partition that was already in use,
which could cause the table to be unusable.

Solution was to not allow IGNORE_FLUSH to skip waiting for
a named locked table.

And to not release the LOCK_open mutex between the
calls to remove_table_from_cache and
close_data_files_and_morph_locks by merging the functions
abort_and_upgrade_locks and alter_close_tables.

mysql-test/suite/parts/r/partition_debug_sync_innodb.result:
  Bug#50561: ALTER PARTITIONS does not have adequate lock, breaks with
  concurrent I_S query
  
  Added test result
mysql-test/suite/parts/t/partition_debug_sync_innodb-master.opt:
  Bug#50561: ALTER PARTITIONS does not have adequate lock, breaks with
  concurrent I_S query
  
  Added test option
mysql-test/suite/parts/t/partition_debug_sync_innodb.test:
  Bug#50561: ALTER PARTITIONS does not have adequate lock, breaks with
  concurrent I_S query
  
  Added test file
sql/authors.h:
  Bug#50561: ALTER PARTITIONS does not have adequate lock, breaks with
  concurrent I_S query
  
  Time to be acknowledged :)
sql/ha_partition.cc:
  Bug#50561: ALTER PARTITIONS does not have adequate lock, breaks with
  concurrent I_S query
  
  Added DEBUG_SYNC for deterministic testing
sql/mysql_priv.h:
  Bug#50561: ALTER PARTITIONS does not have adequate lock, breaks with
  concurrent I_S query
  
  Renamed function since merging alter_close_tables into
  abort_and_upgrade_lock.
sql/sql_base.cc:
  Bug#50561: ALTER PARTITIONS does not have adequate lock, breaks with
  concurrent I_S query
  
  Changed MYSQL_LOCK_IGNORE_FLUSH to not ignore name locks
  (open_placeholder).
  
  Merged alter_close_tables into abort_and_upgrade_locks
  (and added _and_close_table to the name)
  to not release LOCK_open between remove_table_from_cache
  and close_data_files_and_morph_locks.
  
  Added DEBUG_SYNC for deterministic testing.
sql/sql_partition.cc:
  Bug#50561: ALTER PARTITIONS does not have adequate lock, breaks with
  concurrent I_S query
  
  Removed alter_close_tables, (merged it into
  abort_and_upgrad_lock) so that LOCK_open never is released
  between remove_table_from_cache and
  close_data_files_and_morph_locks.
sql/sql_show.cc:
  Bug#50561: ALTER PARTITIONS does not have adequate lock, breaks with
  concurrent I_S query
  
  Added DEBUG_SYNC for deterministic testing
2010-03-17 15:10:41 +01:00
Martin Hansson
4a0dd699b1 Merge of fix for Bug#47762. 2010-03-16 17:21:38 +01:00
Martin Hansson
7dc693229f Bug#47762: Incorrect result from MIN() when WHERE tests NOT
NULL column for NULL

The optimization to read MIN() and MAX() values from an
index did not properly handle comparisons with NULL
values. Fixed by giving up the particular optimization step
if there are non-NULL safe comparisons with NULL values, as 
the result is NULL anyway.

Also, Oracle copyright notice was added to all files.
2010-03-16 15:51:00 +01:00
Mattias Jonsson
7297ec560e merge 2010-03-16 15:09:58 +01:00
Luis Soares
cc223d3883 Automerge: mysql-5.1-bugteam bug branch --> mysql-5.1-bugteam latest. 2010-03-16 11:47:15 +00:00
Martin Hansson
0ed4684547 Bug#50918: Date columns treated differently in Views than in
Base Tables

The type inferrence of a view column caused the result to be
interpreted as the wrong type: DATE colums were interpreted
as TIME and TIME as DATETIME. This happened because view
columns are represented by Item_ref objects as opposed to
Item_field's. Item_ref had no method for retrieving a TIME
value and thus was forced to depend on the default
implementation for any expression, which caused the
expression to be evaluated as a string and then parsed into
a TIME/DATETIME value.

Fixed by letting Item_ref classes forward the request for a
TIME value to the referred Item - which is a field in this
case - this reads the TIME value directly without
conversion.
2010-03-16 10:20:07 +01:00
Davi Arnaut
9fc32c2e24 Bug#51289: double Item_cache_decimal::val_real() is broken
Fix up function return value, it must return a double.
2010-03-15 09:07:16 -03:00
Staale Smedseng
c7fad393fd Bug #49829 Many "hides virtual function" warnings with
SunStudio
      
SunStudio compilers of late warn about methods that might hide
methods in base classes due to the use of overloading combined
with overriding. SunStudio also warns about variables defined
in local socpe or method arguments that have the same name as
a member attribute of the class.
      
This patch renames methods that might hide base class methods,
to make it easier both for humans and compilers to see what is
actually called. It also renames variables in local scope.


sql/field.cc:
  Local scope variable or method argument same as class 
  attribute.
sql/item_cmpfunc.cc:
  Local scope variable or method argument same as class 
  attribute.
sql/item_create.cc:
  Renaming base class create() to create_func().
sql/item_create.h:
  Renaming base class create() to create_func().
sql/protocol.cc:
  Local scope variable or method argument same as class 
  attribute.
sql/sql_profile.cc:
  Local scope variable or method argument same as class 
  attribute.
sql/sql_select.cc:
  Local scope variable or method argument same as class 
  attribute.
sql/sql_yacc.yy:
  Renaming base class create() to create_func().
storage/federated/ha_federated.cc:
  Local scope variable or method argument same as class 
  attribute.
storage/myisammrg/ha_myisammrg.cc:
  Local scope variable or method argument same as class 
  attribute.
2010-03-14 17:01:45 +01:00
Mattias Jonsson
e62c30b5f8 merge 2010-03-12 11:52:38 +01:00
Mattias Jonsson
f3190ea61f merged 2010-03-12 11:14:40 +01:00
Mattias Jonsson
459d04c639 merge 2010-03-11 14:25:33 +01:00
Mattias Jonsson
1a9ec92049 merge 2010-03-11 14:18:44 +01:00
Sergey Vojtovich
680cc263ec Merge fix for BUG51342 to 5.1-bugteam. 2010-03-10 16:26:39 +04:00
Mattias Jonsson
29b39e7a44 Bug#51830: Incorrect partition pruning on range partition
(regression)

Problem was that partition pruning did not exclude the
last partition if the range was beyond it
(i.e. not using MAXVALUE)

Fix was to not include the last partition if the
partitioning function value was not within the partition
range.

mysql-test/r/partition_innodb.result:
  Bug#51830: Incorrect partition pruning on range partition
  (regression)
  
  Updated result
mysql-test/r/partition_pruning.result:
  Bug#51830: Incorrect partition pruning on range partition
  (regression)
  
  Updated result
mysql-test/t/partition_innodb.test:
  Bug#51830: Incorrect partition pruning on range partition
  (regression)
  
  Added test for pruning in InnoDB, since it does not show
  for MyISAM due to 'Impossible WHERE noticed after reading
  const tables'.
mysql-test/t/partition_pruning.test:
  Bug#51830: Incorrect partition pruning on range partition
  (regression)
  
  Added test
sql/sql_partition.cc:
  Bug#51830: Incorrect partition pruning on range partition
  (regression)
  
  Also increase the partition id if not inside the last partition
  (and no MAXVALUE is defined).
  
  Added comments and DBUG_ASSERT.
2010-03-10 12:56:05 +01:00
Sergey Vojtovich
992f6754ac Merge fix for BUG51342 to 5.0-bugteam. 2010-03-10 15:07:35 +04:00
Sergey Vojtovich
405fd82207 BUG#51342 - more xid crashing
SET autocommit=1 while XA transaction is active may
cause various side effects, including memory corruption
and server crash.

The problem is that SET autocommit=1 and further queries
attempt to commit local transaction, whereas XA transaction
is still active.

As local and XA transactions are mutually exclusive, this
patch forbids enabling autocommit mode while XA transaction
is active.

mysql-test/r/xa.result:
  A test case for BUG#51342.
mysql-test/t/xa.test:
  A test case for BUG#51342.
sql/set_var.cc:
  Forbid enabling autocommit mode while XA transaction is
  active.
2010-03-10 15:04:32 +04:00
Georgi Kodinov
d63b0a5c62 Bug #35250: readline check breaks when doing vpath build
MySQL uses two source layouts when building : the bzr 
layout and the source package layout.
The previous fix for bug 35250 contained 1 change that is
valid for both modes and a number of changes that are valid
only for the bzr source layout.
The important thing was to fix the source package layout.
And for this the change in configure.in was sufficient.
It's not trivial (and not requested by this bug) to support 
VPATH builds from the bzr trees.
This is why the other changes are reverted and the change to
fix the VPATH build for source distributions is left intact.
2010-03-09 17:51:31 +02:00
Davi Arnaut
ed92f91549 Bug#47761: crash when killing a query during subquery execution...
The problem was that killing a query during the optimization
phase of a subselect would lead to crashes. The root of the
problem is that the subselect execution engine ignores failures
(eg: killed) during the optimization phase (JOIN::optimize),
leading to a crash once the subquery is executed due to
partially initialized structures (in this case a join tab).

The optimal solution would be to cleanup certain optimizer
structures if the optimization phase fails, but currently
there is no infrastructure to properly to track and cleanup
the structures. To workaround the whole problem one somewhat
good solution is to avoid executing a subselect if the query
has been killed. Cutting short any problems caused by failures
during the optimization phase.

sql/item_subselect.cc:
  Do not execute a subselect if the session or query has been killed.
2010-03-09 09:51:56 -03:00
Davi Arnaut
81ffd72a58 Bug#51770: UNINSTALL PLUGIN requires no privileges
The problem was that UNINSTALL PLUGIN wasn't performing privilege
checks before removing a plugin. Any user (including users without 
any kind of privileges) could uninstall any plugin.

The solution is to verify if the user has the DELETE privilege for
the mysql.plugin table before uninstalling a plugin.

mysql-test/r/plugin_not_embedded.result:
  Add test case result for Bug#51770.
mysql-test/t/plugin_not_embedded-master.opt:
  Add example plugin path.
mysql-test/t/plugin_not_embedded.test:
  Add test case for Bug#51770.
  Skip embedded as test relies on privileges checks.
2010-03-09 09:16:17 -03:00
Sergey Glukhov
b8132a8d94 Bug#41788 mysql_fetch_field returns org_table == table by a view
The problem is that Item_direct_view_ref which is inherited
from Item_ident updates orig_table_name and table_name with
the same values. The fix is introduction of new constructor
into Item_ident and up which updates orig_table_name and
table_name separately.


mysql-test/r/metadata.result:
  test case
mysql-test/t/metadata.test:
  test case
sql/item.cc:
  new constructor which updates
  orig_table_name and table_name
  separately.
sql/item.h:
  new constructor which updates
  orig_table_name and table_name
  separately.
sql/table.cc:
  used new constructor
2010-03-12 10:33:16 +04:00
Alexey Botchkov
e1addb0540 Bug#51377 Crash in information_schema / processlist on concurrent DDL workload
the fill_schema_processlist function accesses THD::query() without proper protection
    so the parallel thread killing can lead to access to the freed meemory.

per-file comments:
  sql/sql_load.cc
Bug#51377      Crash in information_schema / processlist on concurrent DDL workload
    the THD::set_query_inner() call needs to be protected.
    But here we don't need to change the original thd->query() at all.
  sql/sql_show.cc
Bug#51377      Crash in information_schema / processlist on concurrent DDL workload
    protect the THD::query() access with the THD::LOCK_thd_data mutex.
2010-03-09 14:19:10 +04:00
Davi Arnaut
f502deac11 Bug#40277: SHOW CREATE VIEW returns invalid SQL
The problem is that not all column names retrieved from a SELECT
statement can be used as view column names due to length and format
restrictions. The server failed to properly check the conformity
of those automatically generated column names before storing the
final view definition on disk.

Since columns retrieved from a SELECT statement can be anything
ranging from functions to constants values of any format and length,
the solution is to rewrite to a pre-defined format any names that
are not acceptable as a view column name.

The name is rewritten to "Name_exp_%u" where %u translates to the
position of the column. To avoid this conversion scheme, define
explict names for the view columns via the column_list clause.
Also, aliases are now only generated for top level statements.

mysql-test/include/view_alias.inc:
  Add test case for Bug#40277
mysql-test/r/compare.result:
  Bug#40277: SHOW CREATE VIEW returns invalid SQL
mysql-test/r/group_by.result:
  Bug#40277: SHOW CREATE VIEW returns invalid SQL
mysql-test/r/ps.result:
  Bug#40277: SHOW CREATE VIEW returns invalid SQL
mysql-test/r/subselect.result:
  Bug#40277: SHOW CREATE VIEW returns invalid SQL
mysql-test/r/subselect3.result:
  Bug#40277: SHOW CREATE VIEW returns invalid SQL
mysql-test/r/type_datetime.result:
  Bug#40277: SHOW CREATE VIEW returns invalid SQL
mysql-test/r/union.result:
  Bug#40277: SHOW CREATE VIEW returns invalid SQL
mysql-test/r/view.result:
  Add test case result for Bug#40277
mysql-test/r/view_alias.result:
  Add test case result for Bug#40277
mysql-test/t/view_alias.test:
  Add test case for Bug#40277
sql/sql_view.cc:
  Check if auto generated column names are conforming. Also, the
  make_unique_view_field_name function is not used as it uses the
  original name to construct a new one, which does not work if the
  name is invalid.
2010-03-09 07:36:26 -03:00
Davi Arnaut
02ac873ccf Bug#51650: crash with user variables and triggers
The problem was that bits of the destructive equality propagation
optimization weren't being undone after the execution of a stored
program. Modifications to the parse tree that are based on transient
properties must be undone to enable the re-execution of stored
programs.

The solution is to cleanup any references to predicates generated
by the equality propagation during the execution of a stored program.

mysql-test/r/trigger.result:
  Add test case result for Bug#51650.
mysql-test/t/trigger.test:
  Add test case for Bug#51650.
sql/item.cc:
  Remove reference to a equality predicate.
2010-03-09 18:55:08 -03:00
Luis Soares
15ee9a5ac8 Automerge BUG 51251 incremental bundle --> mysql-5.1-bugteam. 2010-03-09 00:03:15 +00:00
Luis Soares
f8ce47b7a5 Automerge BUG 51251 bundle from bug report --> mysql-5.1-bugteam. 2010-03-09 00:02:28 +00:00
Luis Soares
3995884714 Automerge BUG 51226 bzr bundle from bug report --> myqsl-5.1-bugteam. 2010-03-08 23:57:26 +00:00
Luis Soares
17a30e02af Automerge: BUG 48993 bundle from bug report --> mysql-5.1-bugteam. 2010-03-08 23:55:19 +00:00
Mattias Jonsson
1f77c7b49a Bug#50392: insert_id is not reset for partitioned tables
auto_increment on duplicate entry

The bug was that when INSERT_ID was used and the storage
engine was told to release any reserved but not used
auto_increment values, it set the highest auto_increment
value to INSERT_ID.

The fix was to check if the auto_increment value was forced
by user (INSERT_ID) or by slave-thread, i.e. not auto-
generated. So that it is only allowed to release generated
values.

mysql-test/r/partition_error.result:
  Bug#50392: insert_id is not reset for partitioned tables
  auto_increment on duplicate entry
  
  updated result
mysql-test/suite/parts/inc/partition_auto_increment.inc:
  Bug#50392: insert_id is not reset for partitioned tables
  auto_increment on duplicate entry
  
  Added test
mysql-test/suite/parts/r/partition_auto_increment_archive.result:
  Bug#50392: insert_id is not reset for partitioned tables
  auto_increment on duplicate entry
  
  Added result, note that archive does only allow increasing
  auto_increment values
mysql-test/suite/parts/r/partition_auto_increment_blackhole.result:
  Bug#50392: insert_id is not reset for partitioned tables
  auto_increment on duplicate entry
  
  Added result, note that blackhole accepts all inserts :)
mysql-test/suite/parts/r/partition_auto_increment_innodb.result:
  Bug#50392: insert_id is not reset for partitioned tables
  auto_increment on duplicate entry
  
  Added result, note that innodb rolls back inserts on error,
  but keeps the auto_increment value.
mysql-test/suite/parts/r/partition_auto_increment_memory.result:
  Bug#50392: insert_id is not reset for partitioned tables
  auto_increment on duplicate entry
  
  Added result, note that memory and myisam inserts all rows
  before the error.
mysql-test/suite/parts/r/partition_auto_increment_myisam.result:
  Bug#50392: insert_id is not reset for partitioned tables
  auto_increment on duplicate entry
  
  Added result, note that memory and myisam inserts all rows
  before the error.
mysql-test/suite/parts/r/partition_auto_increment_ndb.result:
  Bug#50392: insert_id is not reset for partitioned tables
  auto_increment on duplicate entry
  
  Added result, note that NDB does not seem to handle
  INSERT_ID as other engines. (Martin will look into it).
mysql-test/t/partition_error.test:
  Bug#50392: insert_id is not reset for partitioned tables
  auto_increment on duplicate entry
  
  Added test
sql/ha_partition.cc:
  Bug#50392: insert_id is not reset for partitioned tables
  auto_increment on duplicate entry
  
  If the next_insert_id comes from non generated (i.e
  forced by INSERT_ID or slave-thread) then we cannot
  lower the reserved auto_increment value, since it have
  not reserved any values.
2010-03-04 18:16:10 +01:00
Gleb Shchepa
63a88e1373 Bug #39653: find_shortest_key in sql_select.cc does not
consider clustered primary keys

Choosing a shortest index for the covering index scan,
the optimizer ignored the fact, that the clustered primary
key read involves whole table data.

The find_shortest_key function has been modified to
take into account that fact that a clustered PK has a
longest key of possible covering indices.


mysql-test/r/innodb_mysql.result:
  Test case for bug #39653.
mysql-test/t/innodb_mysql.test:
  Test case for bug #39653.
sql/sql_select.cc:
  Bug #39653: find_shortest_key in sql_select.cc does not
              consider clustered primary keys
  
  The find_shortest_key function has been modified to
  take into account that fact that a clustered PK has a
  longest key of possible covering indices.
2010-03-05 23:45:55 +04:00
Tatiana A. Nurnberg
62809e2a09 auto-merge 2010-03-04 12:39:29 +00:00
Mattias Jonsson
48d986f511 Bug#50104: Partitioned table with just 1 partion works with fk
There was no check for foreign keys when altering partitioned
tables.

Added check for FK when altering partitioned tables.

mysql-test/r/partition_innodb.result:
  Bug#50104: Partitioned table with just 1 partion works with fk
  
  Updated test result
mysql-test/t/partition_innodb.test:
  Bug#50104: Partitioned table with just 1 partion works with fk
  
  Added test for adding FK on partitioned tables (both 1 and 2
  partitions)
sql/sql_partition.cc:
  Bug#50104: Partitioned table with just 1 partion works with fk
  
  Disabled adding foreign key when altering a partitioned table.
2010-03-04 12:29:22 +01:00
Mattias Jonsson
e46d120e8e Bug#48229: group by performance issue of partitioned table
Problem was block_size on partitioned tables was not set,
resulting in keys_per_block was not correct which affects
the cost calculation for read time of indexes (including
cost for group min/max).Which resulted in a bad optimizer
decision.

Fixed by setting stats.block_size correctly.

mysql-test/r/partition_range.result:
  Bug#48229: group by performance issue of partitioned table
  
  Added result
mysql-test/t/partition_range.test:
  Bug#48229: group by performance issue of partitioned table
  
  Added test
sql/ha_partition.cc:
  Bug#48229: group by performance issue of partitioned table
  
  Added missing assignment of stats.block_size.
2010-03-04 12:09:09 +01:00
Luis Soares
7768ccbb54 BUG#51055: Replication failure on duplicate key + traditional SQL
mode

When the master was executing in sql_mode='traditional' (which
implies that really_abort_on_warning returns TRUE - because of
MODE_STRICT_ALL_TABLES), the error code (ER_DUP_ENTRY in the
reported case) was not being set in the
Query_log_event. Therefore, even if a failure was to be expected
when replaying the statement on the slave, a failure would occur,
because the Query_log_event was not transporting the expected
error code, but 0 instead.

This was because when the master was getting the error code to
set it in the Query_log_event, the executing thread would be
assumed to have been killed:
THD::killed==THD::KILL_BAD_DATA. This would make the error code
fetch routine not to check thd->main_da.sql_errno(), but instead
the thd->killed value. What's more, is that the server would
thd->killed value if thd->killed == THD::KILL_BAD_DATA and return
0 instead. So this is a double inconsistency, as the we should
not even check thd->killed but rather thd->main_da.sql_errno().

We fix this by extending the condition used to choose whether to
check the thd->main_da.sql_errno() or thd->killed, so that it
takes into consideration the case when:
thd->killed==THD::KILL_BAD_DATA.
2010-03-04 10:18:06 +00:00
Luis Soares
d13db314dd BUG#51226: mysqlbinlog replay: ERROR 1146 when using temp tables
+ failing statements

Implicit DROP event for temporary table is not getting
LOG_EVENT_THREAD_SPECIFIC_F flag, because, in the previous
executed statement in the same thread, which might even be a
failed statement, the thread_specific_used flag is set to
FALSE (in mysql_reset_thd_for_next_command) and not set to TRUE
before connection is shutdown. This means that implicit DROP
event will take the FALSE value from thread_specific_used and
will not set LOG_EVENT_THREAD_SPECIFIC_F in the event header. As
a consequence, mysqlbinlog will not print the pseudo_thread_id
from the DROP event, because one of the requirements for the
printout is that this flag is set to TRUE.

We fix this by setting thread_specific_used whenever we are
binlogging a DROP in close_temporary_tables, and resetting it to
its previous value afterward.
2010-03-03 12:16:18 +00:00
Tatiana A. Nurnberg
c610e9783a Bug#48295: explain extended crash with subquery and ONLY_FULL_GROUP_BY sql
If an outer query is broken, a subquery might not even get set up.
EXPLAIN EXTENDED did not expect this and merrily tried to de-ref all
of the half-setup info.

We now catch this case and print as much as we have, as it doesn't cost us
anything (doesn't make regular execution slower).

backport from 5.1

mysql-test/r/explain.result:
  Show that EXPLAIN EXTENDED with subquery and illegal out query doesn't crash.
  Show also that SHOW WARNINGS will render an additional Note in the hope of
  being, well, helpful.
mysql-test/t/explain.test:
  If we have only half a query for EXPLAIN EXTENDED to print (i.e.,
  incomplete subquery info as outer query is illegal), we should
  provide the user with as much info as we easily can if they ask
  for it. What we should not do is crash when they come asking for
  help, that violates etiquette in some countries.
sql/item_subselect.cc:
  If the sub-query's actually set up, print it. Otherwise, elide.
2010-03-02 18:00:53 +00:00
Tatiana A. Nurnberg
42585b098e auto-merge 2010-03-02 16:18:16 +00:00
Staale Smedseng
d6678deab8 Bug#49417 some complaints about mysqld --help --verbose output
This patch fixes some typos and poorly formulated sentences in
the output from mysqld --help --verbose.

Some of the problems described in the bug report are already
handled by the patch for Bug#49447, and are therefore not
included in this patch.
2010-03-01 14:49:51 +01:00
Georgi Kodinov
b7a63ac9e2 merge 2010-03-01 10:44:34 +02:00
Ramil Kalimullin
9715539ebd Fix for bug#51304: checksum table gives different results
for same data when using bit fields

Problem: checksum for BIT fields may be computed incorrectly 
in some cases due to its storage peculiarity.

Fix: convert a BIT field to a string then calculate its checksum.


mysql-test/r/myisam.result:
  Fix for bug#51304: checksum table gives different results 
  for same data when using bit fields
    - test result.
mysql-test/t/myisam.test:
  Fix for bug#51304: checksum table gives different results 
  for same data when using bit fields
    - test case.
sql/sql_table.cc:
  Fix for bug#51304: checksum table gives different results 
  for same data when using bit fields
    - convert BIT fields to strings calculating its checksums
  as some bits may be saved among NULL bits in the record buffer.
2010-02-28 21:29:19 +04:00
Andrei Elkin
7fcd6c5989 merging from 5.1 rep to a local branch 2010-02-26 21:07:26 +02:00
Staale Smedseng
600a283689 Bug #45058 init_available_charsets uses double checked locking
A client doing multiple mysql_library_init() and
mysql_library_end() calls over the lifetime of the process may
experience lost character set data, potentially even a
SIGSEGV.

This patch reinstates the reloading of character set data when
a mysql_library_init() is done after a mysql_library_end().
2010-02-26 15:30:14 +01:00
Sergey Glukhov
ca6691533a Bug#47669 Query showed by EXPLAIN EXTENDED gives different result from original query
Item_field::print method does not take into
account fields whose values may be null.
The fix is to print 'NULL' if field value is null.


mysql-test/r/explain.result:
  test case
mysql-test/r/func_str.result:
  result fix
mysql-test/r/having.result:
  result fix
mysql-test/r/select.result:
  result fix
mysql-test/r/subselect.result:
  result fix
mysql-test/r/union.result:
  result fix
mysql-test/t/explain.test:
  test case
sql/item.cc:
  print 'NULL' if field value is null.
2010-02-26 17:40:01 +04:00
Georgi Kodinov
318c2dd90d merge 5.0-bugteam -> 5.1-bugteam 2010-02-26 15:16:46 +02:00
Andrei Elkin
817debb65b merging from 5.1-bt rep to local branch 2010-02-26 15:14:34 +02:00
Luis Soares
8713ccb969 BUG#51251: Wrong binlogging in case of TRUNCATE <temporary InnoDB table>
Incremental commit based on previous patch.
Addresses reviewer comments to move reseting of 
thd->current_stmt_binlog_row_based to after binlog_query
takes place.
2010-02-26 12:58:33 +00:00
Sergey Glukhov
03561d35e3 automerge 2010-02-26 16:19:05 +04:00
Andrei Elkin
9adb2241dd merging fixes of bug@51089 to 5.1-bt 2010-02-26 14:02:16 +02:00
Sergey Glukhov
9245ed4a12 Bug#50995 Having clause on subquery result produces incorrect results.
The problem is that cond->fix_fields(thd, 0) breaks
condition(cuts off 'having'). The reason of that is
that NULL valued Item pointer is present in the
middle of Item list and it breaks the Item processing
loop.


mysql-test/r/having.result:
  test case
mysql-test/t/having.test:
  test case
sql/item_cmpfunc.h:
  added ASSERT to make sure that we do not add NULL valued Item pointer
sql/sql_select.cc:
  skip adding an item to condition if Item pointer is NULL.
  skip adding a list to condition if this list is empty.
2010-02-26 15:39:25 +04:00
Evgeny Potemkin
6025d0ba6b Auto-merged fox for the bug#50843. 2010-02-26 14:19:44 +03:00
Evgeny Potemkin
2d4db52eda Bug#50843: Filesort used instead of clustered index led to
performance degradation.

Filesort + join cache combination is preferred to full index scan because it
is usually faster. But it's not the case when the index is clustered one.

Now test_if_skip_sort_order function prefers filesort only if index isn't
clustered.

mysql-test/r/innodb_mysql.result:
  Added a test case for the bug#50843.
mysql-test/t/innodb_mysql.test:
  Added a test case for the bug#50843.
sql/sql_select.cc:
  Bug#50843: Filesort used instead of clustered index led to
  performance degradation.
  Now test_if_skip_sort_order function prefers filesort only if index isn't
  clustered.
2010-02-26 14:17:00 +03:00
Gleb Shchepa
936ed6ca86 Bug #45360: wrong results
Propagation of a large unsigned numeric constant
in the WHERE expression led to wrong result.

For example,
"WHERE a = CAST(0xFFFFFFFFFFFFFFFF AS USIGNED) AND FOO(a)",
where a is an UNSIGNED BIGINT, and FOO() accepts strings,
was transformed to "... AND FOO('-1')".

That has been fixed.

Also EXPLAIN EXTENDED printed incorrect numeric constants in
transformed WHERE expressions like above. That has been
fixed too.


mysql-test/r/bigint.result:
  Added test case for bug #45360.
mysql-test/t/bigint.test:
  Added test case for bug #45360.
sql/item.cc:
  Bug #45360: wrong results
  
  As far as Item_int_with_ref (and underlaying Item_int)
  class accepts both signed and unsigned 64bit values,
  Item_int::val_str and Item_int::print methods have been
  modified to take into account unsigned_flag.
2010-02-25 23:13:11 +04:00
Alexey Kopytov
1935327e74 Automerge. 2010-02-25 19:26:30 +03:00
Christopher Powers
53e8dc26ef Bug #48739 MySQL crashes on specific INTERVAL in select query
Fixed crash caused by x64 int/long incompatibility introduced
in Bug #29125.


sql/item_timefunc.cc:
  Fixed crash caused by int/long incompatibility on x64 systems.
                  
  Changed two "uint" casts and a "long" declartion to "int" in order to
  ensure that the integer sign is preserved.
                  
  See Bug #48739 for details.
2010-02-25 09:49:09 -06:00
Alexey Kopytov
9201bff16b Bug #50335: Assertion `!(order->used & map)' in eq_ref_table
The problem was in an incorrect debug assertion. The expression 
used in the failing assertion states that when finding 
references matching ORDER BY expressions, there can be only one 
reference to a single table. But that does not make any sense, 
all test cases for this bug are valid examples with multiple 
identical WHERE expressions referencing the same table which
are also present in the ORDER BY list. 
 
Fixed by removing the failing assertion. We also have to take 
care of the 'found' counter so that we count multiple 
references only once. We rely on this fact later in 
eq_ref_table(). 

mysql-test/r/join.result:
  Added a test case for bug #50335.
mysql-test/t/join.test:
  Added a test case for bug #50335.
sql/sql_select.cc:
  Removing the assertion in eq_ref_table() as it does not make
  any sense. We also have to take care of the 'found' counter so 
  that we count multiple references only once. We rely on this 
  fact later in eq_ref_table().
2010-02-25 18:48:53 +03:00
Georgi Kodinov
e3d0b6d792 Backport of the fix for bug #49552 to 5.0-bugteam 2010-02-25 16:57:15 +02:00
Andrei Elkin
9a29bd543e Bug #51089 SHOW STATUS LIKE 'Slave_running' is not compatible with `SHOW SLAVE STATUS'
backporting of bug@30703 to 5.1.
The fixes are backed up with a regression test.



mysql-test/include/test_fieldsize.inc:
  waiting to stop is to be actually exclusively for SQL thread.
mysql-test/suite/rpl/r/rpl_show_slave_running.result:
  new results file is added.
mysql-test/suite/rpl/t/rpl_show_slave_running.test:
  regression test for bug#30703 is added.
sql/mysqld.cc:
  refining `show status like slave_running' handler to correspond to one of
  `show slave status'.
sql/slave.cc:
  A dbug-sync point is added to complement the regression test.
2010-02-25 12:39:43 +02:00
Luis Soares
48d65a645e BUG#51251: Wrong binlogging in case of TRUNCATE <temporary InnoDB table>
For temporary tables that are created with an engine that does
not provide the HTON_CAN_RECREATE, the truncate operation is
performed resorting to the optimized handler::ha_delete_all_rows
method. However, this means that the truncate will share
execution path, from mysql_delete, with truncate on regular
tables and other delete operations. As a consequence the truncate
operation, for the temporary table is logged, even if in row mode
because there is no distinction between this and the other delete
operations at binlogging time.

We fix this by checking if: (i) the binlog format, when the
truncate operation was issued, is ROW; (ii) if the operation is a
truncate; and (iii) if the table is a temporary table; before
writing to the binary log. If all three conditions are met, we
skip writing to the binlog. A side effect of this fix is that we
limit the scope of setting and resetting the
current_stmt_binlog_row_based. Now we just set and reset it
inside mysql_delete in the boundaries of the
handler::ha_write_row loop. This way we have access to
thd->current_stmt_binlog_row_based real value inside
mysql_delete.

mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result:
  Updated result for spurious truncate table.
mysql-test/suite/binlog/t/binlog_row_innodb_truncate.test:
  Test case.
sql/sql_delete.cc:
  Added check in mysql_delete before writing the TRUNCATE statement
  to the binary log. Additionally, removed the set/reset of
  current_stmt_binlog_row_based so that it happens just in the 
  boundaries of the handler::ha_write_row loop inside mysql_delete.
2010-02-24 19:01:53 +00:00
Magne Mahre
710d571030 Revert of a change introduced by Bug#47974
"TYPE=storage_engine" is deprecated, and will be removed
in the Celosia release of MySQL.  Since the option is
present in the Betony release and the version number of
Celosia is still not decided, we need to bump the
deprecation version number back up to "6.0".
2010-02-23 12:17:20 +01:00
Tatiana A. Nurnberg
1d5a7cb811 auto-merge 2010-02-22 17:57:19 +00:00
Tatiana A. Nurnberg
dad7b3c55e revert 48525 2010-02-22 16:58:56 +00:00
Staale Smedseng
57a4084884 Bug #43414 Parenthesis (and other) warnings compiling
MySQL with gcc 4.3.2
      
This is the final patch in the context of this bug. 

cmd-line-utils/readline/rlmbutil.h:
  Changed in a previous patch, reverted by a backport.
cmd-line-utils/readline/text.c:
  Static var initialization.
extra/yassl/include/yassl_error.hpp:
  SetErrorString handles errors outside of the YasslError
  enum.
extra/yassl/src/ssl.cpp:
  SetErrorString handles errors outside of the YasslError
  enum.
extra/yassl/src/yassl_error.cpp:
  SetErrorString handles errors outside of the YasslError
  enum.
2010-02-22 14:23:47 +01:00
Tatiana A. Nurnberg
7d8bed112c auto-merge 2010-02-22 12:31:50 +00:00
Tatiana A. Nurnberg
60a114d838 manual merge 2010-02-19 19:06:47 +00:00
Tatiana A. Nurnberg
1fc1f462b6 Bug#49487: crash with explain extended and group_concat in a derived table
When EXPLAIN EXTENDED tries to print column names, it checks whether the
referenced table is CONST (in which case, the column's value rather than
its name will be printed). If no proper table is reference (i.e. because
a derived table was used that has since gone out of scope), this will fail
spectacularly.

This ports an equivalent of the fix for Bug 43354.

mysql-test/r/func_gconcat.result:
  Show that EXPLAIN EXTENDED on a GROUP_CONCAT() on a derived table
  no longer crashes the server.
mysql-test/t/func_gconcat.test:
  Show that EXPLAIN EXTENDED on a GROUP_CONCAT() on a derived table
  no longer crashes the server.
sql/item_sum.cc:
  Do not de-ref what cannot be, that is, temp-tables that have gone away.
  This is of questionable utility anyway, since our deref has the sole
  purpose of checking whether the table is const (in which case, we'll
  substitute the column with its value in EXPLAIN EXTENDED - that is all).
2010-02-19 15:16:43 +00:00
Tatiana A. Nurnberg
e0fbc5d248 Bug#48525: trigger changes "Column 'id' cannot be null" behaviour
CHECK_FIELD_IGNORE was treated as CHECK_FIELD_ERROR_FOR_NULL;
UPDATE...SET...NULL on NOT NULL fields behaved differently after
a trigger.

Now distinguishes between IGNORE and ERROR_FOR_NULL and save/restores
check-field options.

mysql-test/r/trigger.result:
  Show that UPDATE...SET...NULL on NOT NULL columns doesn't behave differently
  when run after a trigger.
mysql-test/t/trigger.test:
  Show that UPDATE...SET...NULL on NOT NULL columns doesn't behave differently
  when run after a trigger.
sql/field_conv.cc:
  CHECK_FIELD_IGNORE was treated as CHECK_FIELD_ERROR_FOR_NULL.
  Distinguish between the two.
sql/sp_head.cc:
  raise error as needed
sql/sql_class.cc:
  Save and restore check-fields options.
sql/sql_class.h:
  Make room so we can save check-fields options.
sql/sql_insert.cc:
  raise error as needed
2010-02-18 17:02:17 +00:00
Luis Soares
f0b38904aa BUG#48993: valgrind errors in mysqlbinlog
I found three issues during the analysis:
 1. Memory leak caused by temp_buf not being freed;
 2. Memory leak caused when handling argv;
 3. Conditional jump that depended on unitialized values.

Issue #1
--------

  DESCRIPTION: when mysqlbinlog is reading from a remote location
  the event temp_buf references the incoming stream (in NET
  object), which is not freed by mysqlbinlog explicitly. On the
  other hand, when it is reading local binary log, it points to a
  temporary buffer that needs to be explicitly freed. For both
  cases, the temp_buf was not freed by mysqlbinlog, instead was
  set to 0.  This clearly disregards the free required in the
  second case, thence creating a memory leak.

  FIX: we make temp_buf to be conditionally freed depending on
  the value of remote_opt. Found out that similar fix is already
  in most recent codebases.

Issue #2 
--------

  DESCRIPTION: load_defaults is called by parse_args, and it
  reads default options from configuration files and put them
  BEFORE the arguments that are already in argc and argv. This is
  done resorting to MEM_ROOT. However, parse_args calls
  handle_options immediately after which changes argv. Later when
  freeing the defaults, pointers to MEM_ROOT won't match, causing
  the memory not to be freed:

  void free_defaults(char **argv)
  {
    MEM_ROOT ptr
    memcpy_fixed((char*) &ptr,(char *) argv - sizeof(ptr), sizeof(ptr));
    free_root(&ptr,MYF(0));
  }

  FIX: we remove load_defaults from parse_args and call it
  before. Then we save argv with defaults in defaults_argv BEFORE
  calling parse_args (which inside can then call handle_options
  at will). Actually, found out that this is in fact kind of a
  backport for BUG#38468 into 5.1, so I merged in the test case
  as well and added error check for load_defaults call.

  Fix based on:
  revid:zhenxing.he@sun.com-20091002081840-uv26f0flw4uvo33y


Issue #3 
--------

  DESCRIPTION: the structure st_print_event_info constructor
  would not initialize the sql_mode member, although it did for
  sql_mode_inited (set to false). This would later raise the
  warning in valgrind when printing the sql_mode in the event
  header, as this print out is protected by a check against
  sql_mode_inited and sql_mode variables. Given that sql_mode was
  not initialized valgrind would output the warning.

  FIX: we add initialization of sql_mode to the
  st_print_event_info constructor.
 

client/mysqlbinlog.cc:
  - Conditionally free ev->temp_buf.
  - save defaults_argv before handle_options is called.
mysql-test/t/mysqlbinlog.test:
  Added test case from BUG#38468.
sql/log_event.cc:
  Added initialization of sql_mode for st_print_event_info.
2010-02-17 18:07:28 +00:00
Sergey Glukhov
4b260b668d Bug#33717 INSERT...(default) fails for enum. Crashes CSV tables, loads spaces for MyISAM
Table corruption happens during table reading in ha_tina::find_current_row() func.
Field::store() method returns error(true) if stored value is 0.
The fix:
added special case for enum type which correctly processes 0 value.
Additional fix:
INSERT...(default) and INSERT...() have the same behaviour now for enum type.


mysql-test/r/csv.result:
  test result
mysql-test/r/default.result:
  result fix
mysql-test/t/csv.test:
  test case
sql/item.cc:
  Changes:
  do not print warning for 'enum' type if there is no default value.
  set default value.
storage/csv/ha_tina.cc:
  Table corruption happens during table reading in ha_tina::find_current_row() func.
  Field::store() method returns error(true) if stored value is 0.
  The fix:
  added special case for enum type which correctly processes 0 value.
2010-02-17 16:13:42 +04:00
Mattias Jonsson
6cb7abe667 post push fix for bug#42438, did not compile on non debug,
due to ifdef of include file

sql/sql_table.cc:
  removed if defined since DEBUG_SYNC macro is defined in that
  include file.
2010-02-16 11:42:22 +01:00
Sergey Glukhov
b6d360876e automerge 2010-02-16 13:44:36 +04:00
Sergey Glukhov
82e2d858a4 Bug#50591 bit(31) causes Duplicate entry '1-NULL' for key 'group_key'
The problem is that during temporary table creation uneven bits
are not taken into account for hidden fields. It leads to incorrect
calculation&allocation of null bytes size for table record. And
if grouped value is null we set wrong bit for this value(see end_update()).
Fixed by adding separate calculation of uneven bit for hidden fields.


mysql-test/r/type_bit.result:
  test case
mysql-test/t/type_bit.test:
  test case
sql/sql_select.cc:
  added separate calculation of uneven bit for hidden fields
2010-02-16 13:13:49 +04:00
Mattias Jonsson
e32414df04 merge 2010-02-16 09:54:16 +01:00
Georgi Kodinov
32058ba9c6 Addendum 2 for bug #46175: NULL read_view and consistent read assertion
Fixed a compilation warning.
2010-02-15 10:54:27 +02:00
Davi Arnaut
07c30f911e Bug#50624: crash in check_table_access during call procedure
This bug is just one facet of stored routines not being able to
detect changes in meta-data (WL#4179). This particular problem
can be triggered within a single session due to the improper
management of the pre-locking list if the view is expanded after
the pre-locking list is calculated.

Since the overall solution for the meta-data detection issue is
planned for a later release, for now a workaround is used to
fix this particular aspect that only involves a single session.
The workaround is to flush the thread-local stored routine cache
every time a view is created or modified, causing locally cached
routines to be re-evaluated upon invocation.

mysql-test/r/sp-bugs.result:
  Add test case result for Bug#50624.
mysql-test/t/sp-bugs.test:
  Add test case for Bug#50624.
sql/sp_cache.cc:
  Update function description.
sql/sql_view.cc:
  Invalidate the SP cache if a view is being created or modified.
2010-02-13 08:35:14 -02:00
Georgi Kodinov
792fc9f784 Bug #35250: readline check breaks when doing vpath build
Fixed several (obvious) places that don't work with vpath
build.
2010-02-12 18:28:35 +02:00
Mattias Jonsson
afc3eba1f6 Manual merge (moved the check for log_table before name lock) 2010-02-12 10:03:10 +01:00
Sergey Glukhov
f2aee2371e Bug#45195 valgrind warnings about uninitialized values in store_record_in_cache()
The problem becomes apparent only if HAVE_purify is undefined.
It related to the part of code placed in open_table_from_share() fuction
where we initialize record buffer only if HAVE_purify is enabled.
So in case of HAVE_purify=OFF record buffer is not initialized
on open table stage.
Next we read key, find NULL value and update appropriate null bit
but do not update record buffer. After that the record is stored
in the join cache(store_record_in_cache). For CHAR fields we
strip trailing spaces and in our case this procedure uses
uninitialized record buffer.
The fix is to skip stripping space procedure in case of null values
for CHAR fields(partially based on 6.0 JOIN_CACHE implementation).


mysql-test/r/join.result:
  test case
mysql-test/t/join.test:
  test case
sql/field.cc:
  code updated according to new CACHE_FIELD struct
sql/sql_select.cc:
  code updated according to new CACHE_FIELD struct
sql/sql_select.h:
  CACHE_FIELD struct:
  added new fields: Field *field, uint type;
  removed fields: Field_blob *blob_field, bool strip;
2010-02-10 18:56:47 +04:00
Sergey Vojtovich
f2c5870f2a Merge fixes for bug49902 and 50351 to mysql-5.1-bugteam. 2010-02-09 18:40:18 +04:00
Sergey Vojtovich
7feb91e7c5 Merge fix for bug49902 to mysql-5.1-bugteam. 2010-02-09 15:43:44 +04:00
Magne Mahre
e0fb0d9d01 Bug#47974 'TYPE=storage_engine' is deprecated and will be
removed in MySQL 6.0

CREATE TABLE... TYPE= returns the warning "The syntax 
'TYPE=storage_engine' is deprecated and will be removed in 
MySQL 6.0. Please use 'ENGINE=storage_engine' instead" 

This syntax is deprecated already from version 5.4.4, so
the message has been changed.

In addition, the deprecation macro was changed to reflect
the ServerPT decision not to include version number in the
warning message.

A number of test result files have been changed as a
consequence of the change in the deprecation macro.
2010-02-09 11:30:50 +01:00
Sergey Vojtovich
0897669cba BUG#49902 - SELECT returns incorrect results
Queries optimized with GROUP_MIN_MAX didn't cleanup KEYREAD
optimization properly. As a result subsequent queries may
return incomplete rows (fields are initialized to default
values).

mysql-test/r/group_min_max.result:
  A test case for BUG#49902.
mysql-test/t/group_min_max.test:
  A test case for BUG#49902.
sql/opt_range.cc:
  Refactor of KEYREAD optimization switch so that KEYREAD
  handler state is in sync with st_table::key_read flag.
  
  All SQL code is supposed to switch KEYREAD optimization
  via st_table::set_keyread().
sql/opt_sum.cc:
  Refactor of KEYREAD optimization switch so that KEYREAD
  handler state is in sync with st_table::key_read flag.
  
  All SQL code is supposed to switch KEYREAD optimization
  via st_table::set_keyread().
sql/sql_select.cc:
  Refactor of KEYREAD optimization switch so that KEYREAD
  handler state is in sync with st_table::key_read flag.
  
  All SQL code is supposed to switch KEYREAD optimization
  via st_table::set_keyread().
sql/sql_update.cc:
  Refactor of KEYREAD optimization switch so that KEYREAD
  handler state is in sync with st_table::key_read flag.
  
  All SQL code is supposed to switch KEYREAD optimization
  via st_table::set_keyread().
sql/table.cc:
  Refactor of KEYREAD optimization switch so that KEYREAD
  handler state is in sync with st_table::key_read flag.
  
  All SQL code is supposed to switch KEYREAD optimization
  via st_table::set_keyread().
sql/table.h:
  Refactor of KEYREAD optimization switch so that KEYREAD
  handler state is in sync with st_table::key_read flag.
  
  All SQL code is supposed to switch KEYREAD optimization
  via st_table::set_keyread().
2010-02-09 12:53:13 +04:00
Gleb Shchepa
994c0f8308 Bug #45640: optimizer bug produces wrong results
Grouping by a subquery in a query with a distinct aggregate
function lead to a wrong result (wrong and unordered
grouping values).

There are two related problems:

1) The query like this:

   SELECT (SELECT t1.a) aa, COUNT(DISTINCT b) c
   FROM t1 GROUP BY aa

returned wrong result, because the outer reference "t1.a"
in the subquery was substituted with the Item_ref item.

The Item_ref item obtains data from the result_field object
that refreshes once after the end of each group. This data
is not applicable to filesort since filesort() doesn't care
about groups (and doesn't update result_field objects with
copy_fields() and so on). Also that data is not applicable
to group separation algorithm: end_send_group() checks every
record with test_if_group_changed() that evaluates Item_ref
items, but it refreshes those Item_ref-s only after the end
of group, that is a vicious circle and the grouped column
values in the output are shifted.

Fix: if
       a) we grouping by a subquery and
       b) that subquery has outer references to FROM list
          of the grouping query,
     then we substitute these outer references with
     Item_direct_ref like references under aggregate
     functions: Item_direct_ref obtains data directly
     from the current record.

2) The query with a non-trivial grouping expression like:

   SELECT (SELECT t1.a) aa, COUNT(DISTINCT b) c
   FROM t1 GROUP BY aa+0

also returned wrong result, since JOIN::exec() substitutes
references to top-level aliases in SELECT list with Item_copy
caching items. Item_copy items have same refreshing policy
as Item_ref items, so the whole groping expression with
Item_copy inside returns wrong result in filesort() and
end_send_group().

Fix: include aliased items into GROUP BY item tree instead
     of Item_ref references to them.



mysql-test/r/group_by.result:
  Test case for bug #45640
mysql-test/t/group_by.test:
  Test case for bug #45640
sql/item.cc:
  Bug #45640: optimizer bug produces wrong results
  
  Item_field::fix_fields() has been modified to resolve
  aliases in GROUP BY item trees into aliased items instead
  of Item_ref items.
sql/item.h:
  Bug #45640: optimizer bug produces wrong results
  
  - Item::find_item_processor() has been introduced.
  - Item_ref::walk() has been modified to apply processors
    to itself too (not only to referenced item).
sql/mysql_priv.h:
  Bug #45640: optimizer bug produces wrong results
  
  fix_inner_refs() has been modified to accept group_list
  parameter.
sql/sql_lex.cc:
  Bug #45640: optimizer bug produces wrong results
  
  Initialization of st_select_lex::group_fix_field has
  been added.
sql/sql_lex.h:
  Bug #45640: optimizer bug produces wrong results
  
  The st_select_lex::group_fix_field field has been introduced
  to control alias resolution in Itef_fied::fix_fields.
sql/sql_select.cc:
  Bug #45640: optimizer bug produces wrong results
  
  - The fix_inner_refs function has been modified to treat
    subquery outer references like outer fields under aggregate
    functions, if they are included in GROUP BY item tree.
  
  - The find_order_in_list function has been modified to
    fix Item_field alias fields included in the GROUP BY item
    trees in a special manner.
2010-02-06 23:54:30 +04:00
Luis Soares
3ad5d21ebc BUG#50780: 'show binary logs' debug assertion when binary
logging is disabled
      
The server would hit an assertion because of a DBUG violation.
There was a missing DBUG_RETURN and instead a plain return
was used.
      
This patch replaces the return with DBUG_RETURN.
2010-02-05 17:51:55 +00:00
Luis Soares
a0e19f6816 BUG#50620: Adding an index to a table prevents slave from logging
into slow log
      
While processing a statement, down the mysql_parse execution
stack, the thd->enable_slow_log can be assigned to
opt_log_slow_admin_statements, depending whether one is executing
administrative statements, such as ALTER TABLE, OPTIMIZE,
ANALYZE, etc, or not. This can have an impact on slow logging for
statements that are executed after an administrative statement
execution is completed.
      
When executing statements directly from the user this is fine
because, the thd->enable_slow_log is reset right at the beginning
of the dispatch_command function, ie, everytime a new statement
is set is set to execute.
      
On the other hand, for slave SQL thread (sql_thd) the story is a
bit different. When in SBR the sql_thd applies statements by
calling mysql_parse. Right after, it calls log_slow_statement
function to log them if they take too long. Calling mysql_parse
directly is fine, but also means that dispatch_command function
is bypassed. As a consequence, thd->enable_slow_log does not get
a chance to be reset before the next statement to be executed by
the sql_thd. If the statement just executed by the sql_thd was an
administrative statement and logging of admin statements was
disabled, this means that sql_thd->enable_slow_log will be set to
0 (disabled) from that moment on. End result: sql_thd stops
logging slow statements.
      
We fix this by resetting the value of sql_thd->enable_slow_log to
the value of opt_log_slow_slave_statements right after
log_slow_stement is called by the sql_thd.
2010-02-05 17:48:01 +00:00
Luis Soares
e925bd737f BUG#48632: Fix for Bug #23300 Has Not Been Backported
To 5.x Release
      
Notes
=====
      
This is a backport of BUG#23300 into 5.1 GA.
      
Original cset revid (in betony):
luis.soares@sun.com-20090929140901-s4kjtl3iiyy4ls2h

Description
===========
      
When using replication, the slave will not log any slow query
logs queries replicated from the master, even if the
option "--log-slow-slave-statements" is set and these take more
than "log_query_time" to execute.
                    
In order to log slow queries in replicated thread one needs to
set the --log-slow-slave-statements, so that the SQL thread is
initialized with the correct switch. Although setting this flag
correctly configures the slave thread option to log slow queries,
there is an issue with the condition that is used to check
whether to log the slow query or not. When replaying binlog
events the statement contains the SET TIMESTAMP clause which will
force the slow logging condition check to fail. Consequently, the
slow query logging will not take place.
                    
This patch addresses this issue by removing the second condition
from the log_slow_statements as it prevents slow queries to be
binlogged and seems to be deprecated.
2010-02-05 17:01:09 +00:00
Mattias Jonsson
16c8298a85 Bug#42438: Crash ha_partition::change_table_ptr
There was two problems:
The first was the symptom, caused by bad error handling in
ha_partition. It did not handle print_error etc. when
having no partitions (when used by dummy handler).

The second was the real problem that when dropping tables
it reused the table type (storage engine) from when the lock
was asked for, not the table type that it had when gaining
the exclusive name lock. So that it tried to delete tables
from wrong storage engines.

Solutions for the first problem was to accept some handler
calls to the partitioning handler even if it was not setup
with any partitions, and also if possible fallback
to use the base handler's default functions.

Solution for the second problem was to remove the optimization
to reuse the definition from the cache, instead always check
the frm-file when holding the LOCK_open mutex

(updated with a fix for a debug print crash and better
comments as required by reviewer, and removed optimization
to avoid reading the frm-file).

mysql-test/r/partition_debug_sync.result:
  Bug#42438: Crash ha_partition::change_table_ptr
  
  New result file using DEBUG_SYNC for deterministic results.
mysql-test/t/partition_debug_sync.test:
  Bug#42438: Crash ha_partition::change_table_ptr
  
  New test file using DEBUG_SYNC for deterministic results.
sql/ha_partition.cc:
  Bug#42438: Crash ha_partition::change_table_ptr
  
  allow some handler calls, used by error handling, even when
  no partitions are setup. Fallback to default handling if possible.
sql/sql_base.cc:
  Bug#42438: Crash ha_partition::change_table_ptr
  
  Added DEBUG_SYNC point for deterministic test cases.
sql/sql_table.cc:
  Bug#42438: Crash ha_partition::change_table_ptr
  
  Always use the table type written in the .frm-file
  (i.e. the current table type) when deleting a table.
  
  Moved the check for log-table to not depend of the cache.
  
  Added DEBUG_SYNC points for deterministic test cases.
2010-02-01 16:07:00 +01:00
Georgi Kodinov
1ff667c995 fixed a typo in bug #49897. 2010-02-01 13:40:16 +02:00
Georgi Kodinov
6d38c898a6 Bug #49324: more valgrind errors in test_if_skip_sort_order
Fixed 2 problems :
1. test_if_order_by_key() was continuing on the primary key
as if it has a primary key suffix (as the secondary keys do).
This leads to crashes in ORDER BY <pk>,<pk>.
Fixed by not treating the primary key as the secondary one
and not depending on it being clustered with a primary key.
2. The cost calculation was trying to read the records 
per key when operating on ORDER BYs that order on all of the 
secondary key + some of the primary key.
This leads to crashes because of out-of-bounds array access.
Fixed by assuming we'll find 1 record per key in such cases.
2010-01-29 17:04:37 +02:00