Commit graph

26294 commits

Author SHA1 Message Date
Sven Sandberg
d7c1b752cd merged BUG#55322 to 5.1-bugteam 2010-07-26 11:56:30 +02:00
Alexey Kopytov
1837dcfee7 Bug #54476: crash when group_concat and 'with rollup' in
prepared statements

Using GROUP_CONCAT() together with the WITH ROLLUP modifier
could crash the server.

The reason was a combination of several facts:

1. The Item_func_group_concat class stores pointers to ORDER
objects representing the columns in the ORDER BY clause of
GROUP_CONCAT().

2. find_order_in_list() called from
Item_func_group_concat::setup() modifies the ORDER objects so
that their 'item' member points to the arguments list
allocated in the Item_func_group_concat constructor.

3. In some cases (e.g. in JOIN::rollup_make_fields) a copy of
the original Item_func_group_concat object could be created by
using the Item_func_group_concat::Item_func_group_concat(THD
*thd, Item_func_group_concat *item) copy constructor. The
latter essentially creates a shallow copy of the source
object. Memory for the arguments array is allocated on
thd->mem_root, but the pointers for arguments and ORDER are
copied verbatim.

What happens in the test case is that when executing the query
for the first time, after a copy of the original
Item_func_group_concat object has been created by
JOIN::rollup_make_fields(), find_order_in_list() is called for
this new object. It then resolves ORDER BY by modifying the
ORDER objects so that they point to elements of the arguments
array which is local to the cloned object. When thd->mem_root
is freed upon completing the execution, pointers in the ORDER
objects become invalid. Those ORDER objects, however, are also
shared with the original Item_func_group_concat object which is
preserved between executions of a prepared statement. So the
first call to find_order_in_list() for the original object on
the second execution tries to dereference an invalid pointer.

The solution is to create copies of the ORDER objects when
copying Item_func_group_concat to not leave any stale pointers
in other instances with different lifecycles.



mysql-test/r/func_gconcat.result:
  Test case for bug #54476.
mysql-test/t/func_gconcat.test:
  Test case for bug #54476.
sql/item_sum.cc:
  Copy the ORDER objects pointed to by the elements of the 
  'order' array in the copy constructor of 
  Item_func_group_concat.
sql/table.h:
  Removed the unused 'item_copy' member of the ORDER class.
2010-07-23 15:52:54 +04:00
Dmitry Shulga
25c849dbd3 Merge 5.1-bugteam -> 5.1-bug-42496 2010-07-23 18:15:56 +07:00
unknown
9293e4308a Merge 2010-07-22 11:17:26 -05:00
unknown
e9a52f962f Bug#49542 - Do as the comment suggests and downgrade directory errors from find_file() to a warning unless they happen during a SHOW command. 2010-07-22 11:15:15 -05:00
Georgi Kodinov
b7d0890f39 merge 2010-07-21 18:54:11 +03:00
Georgi Kodinov
e24abd9091 Addendum #4 to bug #53095
SHOW DATABASES LIKE ... was not converting to lowercase on comparison as the
documentation is suggesting. 
Fixed it to behave similarly to SHOW TABLES LIKE ... and updated the failing
on MacOSX lowercase_table2 test case.
2010-07-21 18:05:57 +03:00
Alexey Kopytov
d26c6d62a3 Automerge. 2010-07-21 14:14:11 +04:00
Dmitry Shulga
bd41af86eb Fixed bug #42496 - the server could crash on a debug assert after a failure
to write into a closed socket

sql/protocol.cc:
  Protocol::flush modified: set thd->main_da.can_overwrite_status= TRUE
  before call to net_flush() in order to prevent crash on assert in case
  of socket write failure, reset it to FALSE when net_flush() returned;
  Protocol::send_fields modified: return from method with error if call to
  my_net_write(), proto.write() or write_eof_packet() failed.
sql/sql_cache.cc:
  Query_cache::send_result_to_client modified: call to
  thd->main_da.disable_status() only if write to socket
  was successful.
sql/sql_cursor.cc:
  Materialized_cursor::fetch modified: leave method if call to
  result->send_data() failed.
sql/sql_prepare.cc:
  send_prep_stmt() modified: call to thd->main_da.disable_status()
  only if thd->protocol_text.send_fields() completed successfully.
2010-07-21 14:56:43 +07:00
Davi Arnaut
9a5fa17fd3 Bug#45288: pb2 returns a lot of compilation warnings on linux
Fix warnings flagged by the new warning option -Wunused-but-set-variable
that was added to GCC 4.6 and that is enabled by -Wunused and -Wall. The
option causes a warning whenever a local variable is assigned to but is
later unused. It also warns about meaningless pointer dereferences.

client/mysql.cc:
  Meaningless pointer dereferences.
client/mysql_upgrade.c:
  Check whether reading from the file succeeded.
extra/comp_err.c:
  Unused.
extra/yassl/src/yassl_imp.cpp:
  Skip instead of reading data that is discarded.
include/my_pthread.h:
  Variable is only used in debug builds.
include/mysys_err.h:
  Add new error messages.
mysys/errors.c:
  Add new error message for permission related functions.
mysys/mf_iocache.c:
  Variable is only checked under THREAD.
mysys/my_copy.c:
  Raise a error if chmod or chown fails.
mysys/my_redel.c:
  Raise a error if chmod or chown fails.
regex/engine.c:
  Use a equivalent variable for the assert.
server-tools/instance-manager/instance_options.cc:
  Unused.
sql/field.cc:
  Unused.
sql/item.cc:
  Unused.
sql/log.cc:
  Do not ignore the return value of freopen: only set buffer if
  reopening succeeds.
  
  Adjust doxygen comment to the right function.
  
  Pass message lenght to log function.
sql/mysqld.cc:
  Do not ignore the return value of freopen: only set buffer if
  reopening succeeds.
sql/partition_info.cc:
  Unused.
sql/slave.cc:
  No need to set pointer to the address of '\0'.
sql/spatial.cc:
  Unused. Left for historical purposes.
sql/sql_acl.cc:
  Unused.
sql/sql_base.cc:
  Pointers are always set to the same variables.
sql/sql_parse.cc:
  End statement if reading fails.
  
  Store the buffer after it has actually been updated.
sql/sql_repl.cc:
  No need to set pointer to the address of '\0'.
sql/sql_show.cc:
  Put variable under the same ifdef block.
sql/udf_example.c:
  Set null pointer flag appropriately.
storage/csv/ha_tina.cc:
  Meaningless dereferences.
storage/example/ha_example.cc:
  Return the error since it's available.
storage/myisam/mi_locking.c:
  Remove unused and dead code.
2010-07-20 15:07:36 -03:00
Davi Arnaut
b0035c76d4 Bug#54453: Failing assertion: trx->active_trans when renaming a
table with active trx

Essentially, the problem is that InnoDB does a implicit commit
when a cursor (table handler) is unlocked/closed, creating
a dissonance between the transaction state within the server
layer and the storage engine layer. Theoretically, a statement
transaction can encompass several table instances in a similar
manner to a multiple statement transaction, hence it does not
make sense to limit a statement transaction to the lifetime of
the table instances (cursors) used within it.

Since this particular instance of the problem is only triggerable
on 5.1 and is masked on 5.5 due 2PC being skipped (assertion is in
the prepare phase of a 2PC), the solution (which is less risky) is
to explicitly end the transaction before the cached table is unlock
on rename table.

The patch is to be null merged into trunk.

mysql-test/include/commit.inc:
  Fix counters, the binlog engine does not get involved anymore.
mysql-test/suite/innodb_plugin/r/innodb_bug54453.result:
  Add test case result for Bug#54453
mysql-test/suite/innodb_plugin/t/innodb_bug54453.test:
  Add test case for Bug#54453
sql/sql_table.cc:
  End transaction as otherwise InnoDB will end it behind our backs.
2010-07-20 14:36:15 -03:00
Sven Sandberg
689a96fcce BUG#55322: SHOW BINLOG EVENTS increases @@SESSION.MAX_ALLOWED_PACKET
Problem: when SHOW BINLOG EVENTS was issued, it increased the value of
@@session.max_allowed_packet. This allowed a non-root user to increase
the amount of memory used by her thread arbitrarily. Thus, it removes
the bound on the amount of system resources used by a client, so it
presents a security risk (DoS attack).

Fix: it is correct to increase the value of @@session.max_allowed_packet
while executing SHOW BINLOG EVENTS (see BUG 30435). However, the
increase should only be temporary. Thus, the fix is to restore the value
when SHOW BINLOG EVENTS ends.
The value of @@session.max_allowed_packet is also increased in
mysql_binlog_send (i.e., the binlog dump thread). It is not clear if this
can cause any trouble, since normally the client that issues
COM_BINLOG_DUMP will not issue any other commands that would be affected
by the increased value of @@session.max_allowed_packet. However, we
restore the value just in case.


mysql-test/suite/rpl/r/rpl_packet.result:
  update result file
mysql-test/suite/rpl/t/rpl_packet.test:
  Add test that verifies that @@session.max_allowed_packet does not change
  when issuing SHOW BINLOG EVENTS.
  Make previous sub-test clean up.
  Add comments listing the bugs in this test case.
sql/sql_repl.cc:
  Restore the old value of thd->variables.max_allowed_packet at the
  end of mysql_binlog_send and mysql_show_binlog_events.
2010-07-20 17:27:13 +02:00
Jon Olav Hauglid
85e5ce0ba0 Bug #54734 assert in Diagnostics_area::set_ok_status
This assert checks that the server does not try to send OK to the
client if there has been some error during processing. This is done
to make sure that the error is in fact sent to the client.

The problem was that view errors during processing of WHERE conditions
in UPDATE statements where not detected by the update code. It therefore
tried to send OK to the client, triggering the assert.
The bug was only noticeable in debug builds.

This patch fixes the problem by making sure that the update code
checks for errors during condition processing and acts accordingly.
2010-07-19 11:03:52 +02:00
Alexey Kopytov
e98169d52c Bug#55061: Build failing on sol 8 x86 - assembler code vs
compiler problem

GCC-style inline assembly is not supported by the Sun Studio
compilers prior to version 12.

Added a check for the Sun Studio version to avoid using 
_FPU_GETCW() / _FPU_SETCW() when inline assembly is
 unsupported. This can lead to some differences in floating
point calculations on Solaris 8/x86 which, however, is not worth
bothering with Sun-style assembly .il templates.
2010-07-12 18:58:55 +04:00
Mattias Jonsson
52d5941bf1 merge 2010-07-09 15:00:33 +02:00
Mattias Jonsson
50561461ea merge 2010-07-09 14:59:40 +02:00
Davi Arnaut
11fae04527 Bug#45288: pb2 returns a lot of compilation warnings on linux
Although the C standard mandates that sprintf return the number
of bytes written, some very ancient systems (i.e. SunOS 4)
returned a pointer to the buffer instead. Since these systems
are not supported anymore and are hopefully long dead by now,
simply remove the portability wrapper that dealt with this
discrepancy. The autoconf check was causing trouble with GCC.
2010-07-09 09:00:17 -03:00
Mattias Jonsson
70b02d3aed Bug#52517: Regression in ROW level replication performance with partitions
In bug-28430 HA_PRIMARY_KEY_REQUIRED_FOR_POSITION
was disabled in the partitioning engine in the first patch,
That bug was later fixed a second time, but that flag
was not removed.

No need to disable this flag, as it leads to bad
choise in row replication.

sql/ha_partition.h:
  Not disabling HA_PRIMARY_KEY_REQUIRED_FOR_POSITION flag.
  Updated comment (has nothing to do with hidden key.
sql/handler.h:
  Updated comments to about HA_PRIMARY_KEY_REQUIRED_FOR_POSITION.
2010-07-09 13:15:26 +02:00
Sergey Glukhov
013136364c Bug#54416 MAX from JOIN with HAVING returning NULL with 5.1 and Empty set
The problem there is that HAVING condition evaluates const
parts of condition despite the condition has references
on aggregate functions. Table t1 became const tables
after make_join_statistics and table1.pk = 1, HAVING is
transformed into MAX(1) < 7 and taken away from HAVING.
The fix is to skip evaluation of HAVING conts parts if
HAVING condition has references on aggregate functions.


mysql-test/r/having.result:
  test case
mysql-test/t/having.test:
  test case
sql/sql_select.cc:
  skip evaluation of HAVING conts parts if
  HAVING condition has references on aggregate functions.
2010-07-09 14:39:47 +04:00
Mattias Jonsson
9edde02ebb Bug#52455: Subpar INSERT ON DUPLICATE KEY UPDATE performance with many partitions
The handler function for reading one row from a specific index
was not optimized in the partitioning handler since it
used the default implementation.

No test case since it is performance only, verified by hand.

sql/ha_partition.cc:
  Implemented a optimized version of index_read_idx_map
  for the case when find flag == HA_READ_KEY_EXACT,
  which is the common case.
sql/ha_partition.h:
  Declared ha_partition::index_read_idx_map
2010-07-09 01:09:31 +02:00
Mattias Jonsson
b7ad17d06a Bug#46086: crash when dropping a partitioned table
and the original engine is disabled

Missing check that engine is available.

mysql-test/include/not_blackhole.inc:
  new include file
mysql-test/r/partition_not_blackhole.result:
  new result file
mysql-test/std_data/parts/t1_blackhole.frm:
  blackhole partitioned table .frm file:
  create table `t1` (`id` int primary key) engine=blackhole
  partition by key () partitions 1;
mysql-test/std_data/parts/t1_blackhole.par:
  .par file matching blackhole partitioned .frm
mysql-test/t/partition_not_blackhole-master.opt:
  new master-opt to disable blackhole if compiled in.
mysql-test/t/partition_not_blackhole.test:
  New test
sql/ha_partition.cc:
  Added check that engine is available.
2010-07-08 14:36:55 +02:00
unknown
625ae7185a Postfix bug#48321
Fix the memory leak
2010-07-08 10:44:26 +08:00
Jon Olav Hauglid
223f42b715 Bug #54117 crash in thr_multi_unlock, temporary table
This crash occured after ALTER TABLE was used on a temporary
transactional table locked by LOCK TABLES. Any later attempts to
execute LOCK/UNLOCK TABLES, caused the server to crash.

The reason for the crash was the list of locked tables would
end up having a pointer to a free'd table instance. This happened
because ALTER TABLE deleted the table without also removing the
table reference from the locked tables list.

This patch fixes the problem by making sure ALTER TABLE also
removes the table from the locked tables list.

Test case added to innodb_mysql.test.
2010-07-07 13:55:09 +02:00
Georgi Kodinov
d9e7c4efb6 Addendum to the fix for bug #53095 (failing information_schema.test on windows)
Since the original fix for this bug lowercases the search pattern it's not a 
good idea to copy the search pattern to the output instead of the real table 
name found (since, depending on the case mode these two names may differ in 
case).
Fixed the infrmation_schema.test failure by making sure the actual table 
name of an inoformation schema table is passed instead of the lookup pattern
even when the pattern doesn't contain wildcards.
2010-07-07 12:15:58 +03:00
Alexey Kopytov
82b8bc6e6b Automerge. 2010-07-01 12:10:35 +04:00
Alexey Kopytov
f3ccf5061f Bug#54667: Unnecessary signal handler redefinition
POSIX requires that a signal handler defined with sigaction()
is not reset on delivering a signal unless SA_NODEFER or
SA_RESETHAND is set. It is therefore unnecessary to redefine
the handler on signal delivery on platforms where sigaction()
is used without those flags.

include/my_alarm.h:
  Renamed DONT_REMEMBER_SIGNAL ->
  SIGNAL_HANDLER_RESET_ON_DELIVERY.
include/my_global.h:
  Renamed DONT_REMEMBER_SIGNAL ->
  SIGNAL_HANDLER_RESET_ON_DELIVERY. The latter is now defined
  only on non-BSD platforms missing the POSIX sigaction()
  function.
libmysql/libmysql.c:
  Renamed DONT_REMEMBER_SIGNAL ->
  SIGNAL_HANDLER_RESET_ON_DELIVERY
mysys/thr_alarm.c:
  Renamed DONT_REMEMBER_SIGNAL ->
  SIGNAL_HANDLER_RESET_ON_DELIVERY
sql/mysqld.cc:
  Renamed DONT_REMEMBER_SIGNAL ->
  SIGNAL_HANDLER_RESET_ON_DELIVERY
2010-07-01 12:02:00 +04:00
Sergey Glukhov
1c5388765f Bug#51431 Wrong sort order after import of dump file
The problem is that QUICK_SELECT_DESC behaviour depends
on used_key_parts value which can be bigger than selected
best_key_parts value if an engine supports clustered key.
But used_key_parts is overwritten with best_key_parts
value that prevents from correct selection of index
access method. The fix is to preserve used_key_parts
value for further use in QUICK_SELECT_DESC.


mysql-test/r/innodb_mysql.result:
  test case
mysql-test/t/innodb_mysql.test:
  test case
sql/sql_select.cc:
  preserve used_key_parts value for further use in QUICK_SELECT_DESC
2010-06-30 17:06:25 +04:00
Dmitry Shulga
7ccbf9b817 Fixed bug #51855. Race condition in XA START. If several threads
concurrently execute the statement XA START 'x', then mysqld
server could crash.

sql/sql_class.cc:
  xid_cache_insert: added checking for element in cache before
  insert it, return TRUE if such element already exists.
sql/sql_parse.cc:
  mysql_execute_command modified:
  * sequence of calls to xid_cache_search(..)/xid_cache_insert(...)
  replaced by call to xid_cache_insert(...) in alternative
  'case SQLCOM_XA_START:'
  * added comment to alternative 'case SQLCOM_XA_COMMIT:'.
2010-06-29 16:32:03 +07:00
Luis Soares
08c627c35e BUG 53657: automerge bzr bundle from bug report into mysql-5.1-bugteam. 2010-06-28 23:09:00 +01:00
Davi Arnaut
bfd3b7a109 Revert Bug#48321 due to build breakage and failing tests. 2010-06-28 17:59:41 -03:00
Davi Arnaut
407b68bf99 Merge of mysql-5.0-bugteam into mysql-5.1-bugteam. 2010-06-28 17:29:19 -03:00
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