Commit graph

26208 commits

Author SHA1 Message Date
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
Davi Arnaut
b8eaa81dd9 Bug#49025: mysqld-debug: missing DBUG_RETURN or DBUG_VOID_RETURN macro in function "?func"
The problem was that the dbug facility was being used after the
per-thread dbug state had already been finalized. The was present
in a few functions which invoked decrement_handler_count, which
in turn invokes my_thread_end on Windows. In my_thread_end, the
per-thread dbug state is finalized. Any use after the state is
finalized ends up creating a new state.

The solution is to process the exit of a function before the
decrement_handler_count function is called.


sql/mysqld.cc:
  Process the function exit before decrement_handler_count is
  called, as it can end the per-thread dbug state on Windows.
2010-02-05 10:55:20 -02:00
Ramil Kalimullin
172af3722e Fix for bug#49897: crash in ptr_compare when char(0) NOT NULL
column is used for ORDER BY

Problem: filesort isn't meant for null length sort data
(e.g. char(0)), that leads to a server crash.

Fix: disregard sort order if sort data record length is 0 (nothing
to sort).


mysql-test/r/select.result:
  Fix for bug#49897: crash in ptr_compare when char(0) NOT NULL 
  column is used for ORDER BY
    - test result.
mysql-test/t/select.test:
  Fix for bug#49897: crash in ptr_compare when char(0) NOT NULL 
  column is used for ORDER BY
    - test case.
sql/filesort.cc:
  Fix for bug#49897: crash in ptr_compare when char(0) NOT NULL 
  column is used for ORDER BY
    - assert added as filesort cannot handle null length sort data.
sql/sql_select.cc:
  Fix for bug#49897: crash in ptr_compare when char(0) NOT NULL 
  column is used for ORDER BY
    - don't sort null length data e.g. in case of ORDER BY CHAR(0).
2010-01-29 13:17:57 +04:00
Davi Arnaut
d6ab925c5e Bug#50423: Crash on second call of a procedure dropping a trigger
The problem was that a DROP TRIGGER statement inside a stored
procedure could cause a crash in subsequent invocations. This
was due to the addition, on the first execution, of a temporary
table reference to the stored procedure query table list. In
a subsequent invocation, there would be a attempt to reinitialize
the temporary table reference, which by then was already gone.

The solution is to backup and reset the query table list each
time a trigger needs to be dropped. This ensures that any temp
changes to the query table list are discarded. It is safe to
do so at this time as drop trigger is restricted from more
complicated scenarios (ie, not allowed within stored functions,
etc).

mysql-test/r/sp-bugs.result:
  Add test case result for Bug#50423
mysql-test/t/sp-bugs.test:
  Add test case for Bug#50423
sql/sql_trigger.cc:
  Backup and reset the query table list.
  Remove now unnecessary manual reset of the query table list.
2010-01-28 12:41:14 -02:00
Sergey Glukhov
1805fcdcfb automerge 2010-02-12 14:11:13 +04:00
Sergey Glukhov
46cffd7f5b Bug#48294 assertion when creating a view based on some row() construct in select query
In case of 'CREATE VIEW' subselect transformation does not happen(see JOIN::prepare).
During fix_fields Item_row may call is_null() method for its arugmens which
leads to item calculation(wrong subselect in our case as
transformation did not happen before). This is_null() call
does not make sence for 'CREATE VIEW'.
Note:
Only Item_row is affected because other items don't call is_null() 
during fix_fields() for arguments.

mysql-test/r/view.result:
  test case
mysql-test/t/view.test:
  test case
sql/item_row.cc:
  skip is_null() call in case of 'CREATE VIEW' as unnecessary.
2010-02-12 13:44:20 +04:00
Georgi Kodinov
32902dad00 Addendum to bug #46175 : use and check for the correct error values
when converting to a enumerated type.
2010-02-11 19:41:53 +02:00
Davi Arnaut
63817720b4 Bug#48449: hang on show create view after upgrading when view contains function of view
SHOW CREATE TABLE on a view (v1) that contains a function whose
statement uses another view (v2), could trigger a infinite loop
if the view referenced within the function causes a warning to
be raised while opening the said view (v2).

The problem was a infinite loop over the stack of internal error
handlers. The problem would be triggered if the stack contained
two or more handlers and the first two handlers didn't handle the
raised condition. In this case, the loop variable would always
point to the second handler in the stack.

The solution is to correct the loop variable assignment so that
the loop is able to iterate over all handlers in the stack.

mysql-test/r/view.result:
  Add test case result for Bug#48449.
mysql-test/std_data/bug48449.frm:
  Add a incomplete view definition that causes a warning to be
  issued.
mysql-test/t/view.test:
  Add test case for Bug#48449
sql/sql_class.cc:
  Iterate over all handlers in the stack.
2010-02-10 16:11:08 -02:00
Davi Arnaut
ee66332ce4 Bug#47734: Assertion failed: ! is_set() when locking a view with non-existing definer
The problem was that a failure to open a view wasn't being
properly handled. When opening a view with unknown definer,
the open procedure would be treated as successful and would
later crash when attempting to lock the view (which wasn't
opened to begin with).

The solution is to skip further processing when opening a
table if it fails with a fatal error.

mysql-test/r/view.result:
  Add test case result for Bug#47734.
mysql-test/t/view.test:
  Add test case for Bug#47734.
sql/sql_base.cc:
  Skip further processing if opening a table failed due to
  a fatal error (for the statement).
2010-01-27 11:10:53 -02:00
Staale Smedseng
f4a16558c8 Bug #47905 stored procedures with conditional statements not
being logged to slow query log

The problem is that the execution time for a multi-statement
stored procedure as a whole may not be accurate, and thus not
be entered into the slow query log even if the total time
exceeds long_query_time. The reason for this is that
THD::utime_after_lock used for time calculation may be reset
at the start of each new statement, possibly leaving the total
SP execution equal to the time spent executing the last
statement in the SP.

This patch stores the utime on start of SP execution, and
restores it on exit of SP execution. A test is added.


mysql-test/suite/sys_vars/r/slow_query_log_func.result:
  New test results for #47905.
mysql-test/suite/sys_vars/t/slow_query_log_func.test:
  New test case for #47905.
sql/sp_head.cc:
  Save and restore the THD::utime_after_lock on entry and 
  exit of execute_procedure().
2010-02-11 21:10:13 +01:00
Martin Hansson
323a8ddc83 Merge of Bug#49534 2010-02-11 15:56:24 +01:00
Martin Hansson
630fa243c9 Bug#49534: multitable IGNORE update with sql_safe_updates
error causes debug assertion

The IGNORE option of the multiple-table UPDATE command was
not intended to suppress errors caused by the
sql_safe_updates mode. This flag will raise an error if the
execution of UPDATE does not use a key for row retrieval,
and should continue do so regardless of the IGNORE option.

However the implementation of IGNORE does not support
exceptions to the rule; it always converts errors to
warnings and cannot be extended. The Internal_error_handler
interface offers the infrastructure to handle individual
errors, making sure that the error raised by
sql_safe_updates is not silenced.

Fixed by implementing an Internal_error_handler and using it
for UPDATE IGNORE commands.
2010-02-10 15:37:34 +01:00
Staale Smedseng
694d50c71e Bug#50409 Solaris 8 compatibility broken by assumption about
printstack() being present

When Bug#47391 was fixed, no assumption was made that support
for Solaris 8 was needed. Solaris 8 lacks printstack(), and 
the build breaks because of this.

This patch adds a test for the presence of printstack() to
configure.in for 5.0, and uses HAVE_PRINTSTACK to make
decisions rather than the __sun define.
2010-01-27 11:38:50 +01:00
Davi Arnaut
7920e89a47 Bug#49491: Much overhead for MD5() and SHA1() on short strings
MySQL's hash functions MD5 and SHA relied on the somewhat slow 
sprintf function to convert the digests to hex representations.
This patch replaces the sprintf with a specific and inline hex
conversion function.

Patch contributed by Jan Steemann.

sql/item_strfunc.cc:
  Add a hex conversion function.
2010-01-26 15:05:19 -02:00
Luis Soares
9ac2343cc3 automerge: mysql-5.1-bugteam branch --> mysql-5.1-bugteam latest
NOTE: added TODO to the comments requested by reviewer during this
      merge.
2010-01-26 08:55:22 +00:00
Georgi Kodinov
c7cb4b3c42 fix a windows test run bug with debug binaries : dbug frame
should be exited before destroying the thread local storage.
2010-01-26 10:47:43 +02:00
unknown
dad4291b78 Manual merge with Conflicts:
sql_udf.cc
2010-01-25 10:55:05 +08:00
He Zhenxing
2b16517522 Backport Bug#37148 to 5.1 2010-01-24 15:03:23 +08:00
Sergey Glukhov
4a10f7b46c Bug#49501 Inefficient information_schema check (system collation), addon
removed wrongly introduced strlen calls


sql/events.cc:
  removed wrongly introduced strlen calls
sql/mysql_priv.h:
  removed wrongly introduced strlen calls
sql/repl_failsafe.cc:
  removed wrongly introduced strlen calls
sql/sql_db.cc:
  removed wrongly introduced strlen calls
sql/sql_parse.cc:
  removed wrongly introduced strlen calls
sql/sql_show.cc:
  removed wrongly introduced strlen calls
2010-01-22 14:58:21 +04:00
unknown
3cae7d1187 Bug #49132 Replication failure on temporary table + DDL
In RBR, DDL statement will change binlog format to non row-based
format before it is binlogged, but the binlog format was not be
restored, and then manipulating a temporary table can not reset binlog
format to row-based format rightly. So that the manipulated statement
is binlogged with statement-based format.

To fix the problem, restore the state of binlog format after the DDL
statement is binlogged.

mysql-test/extra/rpl_tests/rpl_tmp_table_and_DDL.test:
  Added the test file to verify if executing DDL statement before
  trying to manipulate a temporary table causes row-based replication
  to break with error 'table does not exist'.
mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result:
  Correct the test result, all the above binlog event
  should be row-based after the bug49132 is fixed IN RBR.
mysql-test/suite/ndb/r/ndb_tmp_table_and_DDL.result:
  Test result for bug#49132 base on ndb engine.
mysql-test/suite/ndb/t/ndb_tmp_table_and_DDL.test:
  Added the test file to verify if executing DDL statement before
  trying to manipulate a temporary table causes row-based replication
  to break with error 'table does not exist' base on ndb engine.
mysql-test/suite/rpl/r/rpl_tmp_table_and_DDL.result:
  Test result for bug#49132 base on myisam engine.
mysql-test/suite/rpl/t/rpl_tmp_table_and_DDL.test:
  Added the test file to verify if executing DDL statement before
  trying to manipulate a temporary table causes row-based replication
  to break with error 'table does not exist' base on myisam engine.
sql/event_db_repository.cc:
  Added code to restore the state of binlog format after the DDL
  statement is binlogged.
sql/events.cc:
  Added code to restore the state of binlog format after the DDL
  statement is binlogged.
sql/sp.cc:
  Added code to restore the state of binlog format after the DDL
  statement is binlogged.
sql/sql_acl.cc:
  Added code to restore the state of binlog format after the DDL
  statement is binlogged.
sql/sql_udf.cc:
  Added code to restore the state of binlog format after the DDL
  statement is binlogged.
2010-01-22 17:38:21 +08:00
Luis Soares
73f10f0662 BUG#49481: RBR: MyISAM and bit fields may cause slave to stop on delete:
cant find record

Some engines return data for the record. Despite the fact that
the null bit is set for some fields, their old value may still in
the row. This can happen when unpacking an AI from the binlog on
top of a previous record in which a field is set to NULL, which
previously contained a value. Ultimately, this may cause the
comparison of records to fail when the slave is doing an index or
range scan.

We fix this by deploying a call to reset() for each field that is
set to null while unpacking a row from the binary log.
Furthermore, we also add mixed mode test case to cover the
scenario where updating and setting a field to null through a
Query event and later searching it through a rows event will
succeed.

Finally, we also change the reset() method, from Field_bit class,
so that it takes into account bits stored among the null bits and
not only the ones stored in the record.

mysql-test/suite/rpl/t/rpl_set_null_innodb.test:
  InnoDB test.
mysql-test/suite/rpl/t/rpl_set_null_myisam.test:
  MyISAM test.
mysql-test/suite/rpl_ndb/t/rpl_ndb_set_null.test:
  NDB test.
sql/field.h:
  Changed reset so that it also clears the bits
  among the null_bits for the Field_bit class.
sql/rpl_record.cc:
  Resetting field after setting it to null when unpacking
  row.
2010-01-21 17:20:24 +00:00
Magne Mahre
132b46e96e WL#5154 Remove deprecated 4.1 features
Several items said to be deprecated in the 4.1 manual
have never been removed.  This worklog adds deprecation
warnings when these items are used, and warns the user 
that the items will be removed in MySQL 5.6.

A couple of previously deprecation decision have been
reversed (see single file comments)



client/client_priv.h:
  Macro similar to the one in the server (mysql_priv.h)
  for printing a deprecation warning message
client/mysql.cc:
  no-auto-rehash  will not be deprecated
  skip-line-numbers will not be deprecated
  skip-column-names will not be deprecated
  no-pager is deprecated
  set-variable is deprecated
  no-named-commands is deprecated
client/mysqladmin.cc:
  set-variable is deprecated
client/mysqlbinlog.cc:
  position is deprecated
client/mysqldump.c:
  first-slave is deprecated
  no-set-names is deprecated
  set-variable is deprecated
mysql-test/r/mysqlbinlog.result:
  Adding the [Warning] to the test case, just to show that the
  deprecation works.
  The test case will be changed in Celosia to use --start-position.
mysys/my_getopt.c:
  set-variable (include -O) is deprecated
scripts/mysqld_multi.sh:
  Warning for mysqld_multi
sql/mysqld.cc:
  default-collation is deprecated
  log-bin-trust-routine-creators is deprecated
  set-variable is deprecated
  default-character-set is deprecated
  safe-show-database is deprecated
sql/share/errmsg.txt:
  Added version number for sql_log_update deprecation message.
2010-01-21 09:10:05 +01:00
Alfranio Correia
985c06d0a9 BUG#46364 MyISAM transbuffer problems (NTM problem)
It is well-known that due to concurrency issues, a slave can become
inconsistent when a transaction contains updates to both transaction and
non-transactional tables in statement and mixed modes.

In a nutshell, the current code-base tries to preserve causality among the
statements by writing non-transactional statements to the txn-cache which
is flushed upon commit. However, modifications done to non-transactional
tables on behalf of a transaction become immediately visible to other
connections but may not immediately get into the binary log and therefore
consistency may be broken.

In general, it is impossible to automatically detect causality/dependency
among statements by just analyzing the statements sent to the server. This
happen because dependency may be hidden in the application code and it is
necessary to know a priori all the statements processed in the context of
a transaction such as in a procedure. Moreover, even for the few cases that
we could automatically address in the server, the computation effort
required could make the approach infeasible.

So, in this patch we introduce the option
    - "--binlog-direct-non-transactional-updates" that can be used to bypass
    the current behavior in order to write directly to binary log statements
    that change non-transactional tables.

mysql-test/extra/rpl_tests/rpl_mixing_engines.inc:
  Backported this from Celosia to improve the test cases related to the NTM issue.
sql/log.cc:
  Checks the --binlog-direct-non-transactional-updates before choosing
  to either use the trxn-cache or not.
sql/mysqld.cc:
  Introduces the option --binlog-direct-non-transactional-updates.
sql/set_var.cc:
  Introduces the option --binlog-direct-non-transactional-updates.
sql/sql_class.h:
  Introduces the option --binlog-direct-non-transactional-updates.
2010-01-20 19:08:16 +00:00
Mattias Jonsson
4839c42619 post-push patch for bug#47343.
Missing ha_rnd_end in copy_partitions, found due to a
DBUG_ASSERT in mysql-pe

sql/ha_partition.cc:
  Post-push patch for bug#47343
  
  Must call ha_rnd_end since ha_rnd_init has been called.
2010-01-19 17:02:51 +01:00
Luis Soares
d1d16f9c3f Fix for BUG#49481 and BUG#49482 reverted.
PB2 run uncovered issue that needs further analysis.
2010-01-19 00:10:00 +00:00
Mattias Jonsson
ae3e094191 merge 2010-01-17 22:00:37 +01:00
unknown
377d710296 BUG#47418 RBR fails, failure with mixup of base/temporary/view
'CREATE TABLE IF NOT EXISTS ... SELECT' statement were causing 'CREATE
TEMPORARY TABLE ...' to be written to the binary log in row-based 
mode (a.k.a. RBR), when there was a temporary table with the same name.
Because the 'CREATE TABLE ... SELECT' statement was executed as 
'INSERT ... SELECT' into the temporary table. Since in RBR mode no 
other statements related to temporary tables are written into binary log,
this sometimes broke replication.

This patch changes behavior of 'CREATE TABLE [IF NOT EXISTS] ... SELECT ...'.
it ignores existence of temporary table with the 
same name as table being created and is interpreted
as attempt to create/insert into base table. This makes behavior of
'CREATE TABLE [IF NOT EXISTS] ... SELECT' consistent with
how ordinary 'CREATE TABLE' and 'CREATE TABLE ... LIKE' behave.
2010-01-16 15:44:24 +08:00
Georgi Kodinov
7a7147c5b4 Bug #46175: NULL read_view and consistent read assertion
The optimizer must not continue executing the current query
if e.g. the storage engine reports an error.
This is somewhat hard to implement with Item::val_xxx()
because they do not have means to return error code.
This is why we need to check the thread's error state after
a call to one of the Item::val_xxx() methods.

Fixed store_key_item::copy_inner() to return an error state 
if an error happened during the call to Item::save_in_field() 
because it calls Item::val_xxx().
Also added similar checks to related places.
2010-01-15 16:09:20 +02:00
Luis Soares
32aa612819 Fix for BUG#49481 and BUG#49482.
BUG#49481: RBR: MyISAM and bit fields may cause slave to stop on delete: 
cant find record
      
BUG#49482: RBR: Replication may break on deletes when MyISAM tables + 
char field are used

When using MyISAM tables, despite the fact that the null bit is
set for some fields, their old value is still in the row. This
can cause the comparison of records to fail when the slave is
doing an index or range scan.

We fix this by avoiding memcmp for MyISAM tables when comparing
records. Additionally, when comparing field by field, we first
check if both fields are not null and if so, then we compare
them. If just one field is null we return failure immediately. If
both fields are null, we move on to the next field.
2010-01-14 14:26:51 +00:00
Luis Soares
ebc009c9b3 BUG#50018: automerge from 5.1-bt local --> 5.1-bt local latest. 2010-01-14 10:47:23 +00:00
Kristofer Pettersson
a0fe99a859 automerge 2010-01-13 15:01:49 +01:00
Kristofer Pettersson
b3dd4d9486 Bug#33982 debug assertion and crash reloading grant tables after sighup or kill
In certain rare cases when a process was interrupted
during a FLUSH PRIVILEGES operation the diagnostic
area would be set to an error state but the function
responsible for the operation would still signal
success. This would lead to a debug assertion error
later on when the server would attempt to reset the
DA before sending the error message.

This patch fixes the issue by assuring that
reload_acl_and_cache() always fails if an error
condition is raised.

The second issue was that a KILL could cause
a console error message which referred to a DA
state without first making sure that such a
state existed.

This patch fixes this issue in two different
palces by first checking DA state before
fetching the error message.

 

sql/sql_acl.cc:
  * Make sure that there is an error to print before attempting to do so.
  * Minor style change: change 1 to TRUE for clarity.
sql/sql_parse.cc:
  * Always fail reload_acl_and_cache() if the query was killed.
sql/sql_servers.cc:
  * Make sure that there is an error to print before attempting to do so.
2010-01-13 12:39:00 +01:00
Martin Hansson
34e5c6750d Merge of fix for Bug#48157. 2010-01-13 12:38:06 +01:00
Georgi Kodinov
6e72f4171f merge 5.1-main to 5.1-bugteam 2010-01-13 12:28:42 +02:00
Sven Sandberg
4dc7be62a9 BUG#49222: Mark RAND() as unsafe
Problem: When RAND() is binlogged in statement mode, the seed is
binlogged too, so the replication slave generates the same
sequence of random numbers. This makes replication work in many
cases, but not in all cases: the order of rows is not guaranteed
for, e.g., UPDATE or INSERT...SELECT statements, so the row data
will be different if master and slave retrieve the rows in
different orders.
Fix: Mark RAND() as unsafe. It will generate a warning if
binlog_format=STATEMENT and switch to row-logging if
binlog_format=ROW.


mysql-test/extra/rpl_tests/rpl_row_func003.test:
  updated test case to ignore new warnings
mysql-test/suite/binlog/r/binlog_unsafe.result:
  updated result file
mysql-test/suite/binlog/t/binlog_unsafe.test:
  Added test for RAND().
  Also clarified some old comments.
mysql-test/suite/rpl/r/rpl_misc_functions.result:
  updated result file
mysql-test/suite/rpl/r/rpl_nondeterministic_functions.result:
  updated test case to ignore new warnings
mysql-test/suite/rpl/r/rpl_optimize.result:
  updated result file
mysql-test/suite/rpl/r/rpl_row_func003.result:
  updated result file
mysql-test/suite/rpl/t/rpl_misc_functions.test:
  updated test case to ignore new warnings
mysql-test/suite/rpl/t/rpl_nondeterministic_functions.test:
  updated test case to ignore new warnings
mysql-test/suite/rpl/t/rpl_optimize.test:
  updated test case to ignore new warnings
mysql-test/suite/rpl/t/rpl_trigger.test:
  updated test case to ignore new warnings
mysql-test/suite/rpl_ndb/r/rpl_ndb_func003.result:
  updated result file
sql/item_create.cc:
  Mark RAND() unsafe.
2010-01-13 10:00:03 +01:00
Gleb Shchepa
71fd38e488 Bug #50096: CONCAT_WS inside procedure returning wrong data
Selecting of the CONCAT_WS(...<PS parameter>...) result into
a user variable may return wrong data.

Item_func_concat_ws::val_str contains a number of memory
allocation-saving optimization tricks. After the fix
for bug 46815 the control flow has been changed to a
branch that is commented as "This is quite uncommon!":
one of places where we are trying to concatenate
strings inplace. However, that "uncommon" place
didn't care about PS parameters, that have another
trick in Item_sp_variable::val_str(): they use the
intermediate Item_sp_variable::str_value field,
where they may store a reference to an external
argument's buffer.

The Item_func_concat_ws::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:
  Added test case for bug #50096.
mysql-test/t/func_concat.test:
  Added test case for bug #50096.
sql/item_strfunc.cc:
  Bug #50096: CONCAT_WS inside procedure returning wrong data
  
  The Item_func_concat_ws::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-01-13 08:16:36 +04:00
Martin Hansson
c8b5804f29 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.


mysql-test/r/sp_sync.result:
  Bug#48157: Test case
mysql-test/t/sp_sync.test:
  Bug#48157: Test result
sql/item.h:
  Bug#48157: Commented field.
sql/sql_parse.cc:
  Bug#48157: Commented function.
sql/sql_update.cc:
  Bug#48157: fix
2010-01-12 15:16:26 +01:00
unknown
c1043021c8 BUG #28421 Infinite loop on slave relay logs
Manually deleteing one or more entries from 'master-bin.index', will
cause master infinitely loop to send one binlog file. 

When starting a dump session, master opens index file and search the binlog file
which is being requested by the slave. The position of the binlog file in the
index file is recorded. it will be used to find the next binlog file when current
binlog file has dumped completely. As only the position is used, it may
not get the correct file if some entries has been removed manually from the index file.
the master will reopen the current binlog file which has been dump completely
and redump it if it can not get the next binlog file's name from index file.
It obviously is a logical error.


Even though it is allowed to manually change index file,
but it is not recommended. so after this patch, master
sends a fatal error to slave and close the dump session if a new binlog file
has been generated and master can not get it from the index file.
2010-01-08 13:42:23 +08:00
Luis Soares
4d090ed4f3 merge: 5.1-bugteam bug branch --> 5.1 bugteam latest. 2010-01-07 10:34:27 +00:00
unknown
efcbc34910 Bug #49137 Replication failure on SBR/MBR + multi-table DROP TEMPORARY TABLE
Fixed valgrind failure on PB2.

sql/log_event.cc:
  Added code to fix valgrind failure on PB2.
2010-01-06 13:28:06 +08:00
unknown
98b989d7b1 Bug #49137 Replication failure on SBR/MBR + multi-table DROP TEMPORARY TABLE
Fixed valgrind failure on PB2.

sql/log_event.cc:
  Added code to fix valgrind failure on PB2.
2010-01-06 13:12:40 +08:00
unknown
8868847109 Bug #49137 Replication failure on SBR/MBR + multi-table DROP TEMPORARY TABLE
Fixed valgrind failure on PB2.

sql/log_event.cc:
  Added code to fix valgrind failure on PB2.
2010-01-06 10:44:14 +08:00
unknown
0a64fbc517 Bug #49137 Replication failure on SBR/MBR + multi-table DROP TEMPORARY TABLE
Fixed valgrind failure on PB2.

sql/log_event.cc:
  Added code to fix valgrind failure on PB2.
2010-01-06 10:36:29 +08:00
Luis Soares
f8758031f3 BUG#50018: binlog corruption when table has many columns
For tables with metadata sizes ranging from 251 to 255 the size
of the event data (m_data_size) was being improperly calculated
in the Table_map_log_event constructor. This was due to the fact
that when writing the Table_map_log_event body (in
Table_map_log_event::write_data_body) a call to net_store_length
is made for packing the m_field_metadata_size. It happens that
net_store_length uses *one* byte for storing
m_field_metadata_size when it is smaller than 251 but *three*
bytes when it exceeds that value. BUG 42749 had already
pinpointed and fix this fact, but the fix was incomplete, as the
calculation in the Table_map_log_event constructor considers 255
instead of 251 as the threshold to increment m_data_size by
three. Thence, the window for having a mismatch between the
number of bytes written and the number of bytes accounted in the
event length (m_data_size) was left open for
m_field_metadata_size values between 251 and 255.

We fix this by changing the condition in the Table_map_log_event
constructor to match the one in the net_store_length, ie,
increment one byte if m_field_metadata_size < 251 and three if it
exceeds this value.

mysql-test/suite/rpl/r/rpl_row_tbl_metadata.result:
  Updated result file.
mysql-test/suite/rpl/t/rpl_row_tbl_metadata.test:
  Changes to the original test case: added slave and moved
  file into the rpl suite.
  
  New test case: replicates two tables one with 250 and 
  another with 252 metadata sizes. This exercises the usage
  of 1 or 3 bytes while packing the m_field_metadata_size.
sql/log_event.cc:
  Made the m_data_size calculation for the table map log event
  to match the number of bytes used while packing the 
  m_field_metadata_size value (according to net_store_length
  function in pack.c).
2010-01-06 00:44:31 +00:00
He Zhenxing
af27d4e200 Bug#48776 row based replication breaks with spatial / geometry types, cause crashes!
This bug is the same problem as Bug 49836 for 5.1 versions.

mysql-test/suite/rpl/r/rpl_geometry.result:
  Test case for bug 48776
mysql-test/suite/rpl/t/rpl_geometry.test:
  Test case for bug 48776
sql/rpl_utility.h:
  Add missing case MYSQL_TYPE_GEOMETRY
2010-01-05 14:25:29 +08:00
unknown
be397eb400 Bug #49137 Replication failure on SBR/MBR + multi-table DROP TEMPORARY TABLE
In statement-based or mixed-mode replication, use DROP TEMPORARY TABLE
to drop multiple tables causes different errors on master and slave, 
when one or more of these tables do not exist. Because when executed
on slave, it would automatically add IF EXISTS to the query to ignore
all ER_BAD_TABLE_ERROR errors.

To fix the problem, do not add IF EXISTS when executing DROP TEMPORARY
TABLE on the slave, and clear the ER_BAD_TABLE_ERROR error after
execution if the query does not expect any errors.

mysql-test/suite/rpl/r/rpl_drop_temp.result:
  Updated for the patch of bug#49137.
mysql-test/suite/rpl/t/rpl_drop_temp.test:
  Added the test file to verify if DROP MULTI TEMPORARY TABLE
  will cause different errors on master and slave, when one or
  more of these tables do not exist.
sql/log_event.cc:
  Added code to handle above cases which are 
  removed from sql_parse.cc
sql/sql_parse.cc:
  Remove the code to issue the 'Unknown table' error, 
  if the temporary table does not exist when dropping 
  it on slave. The above cases decribed in comments
  will be handled later in log_event.cc.
2009-12-31 12:04:19 +08:00
unknown
2b2ce3d6cb Bug #49137 Replication failure on SBR/MBR + multi-table DROP TEMPORARY TABLE
In statement-based or mixed-mode replication, use DROP TEMPORARY TABLE
to drop multiple tables causes different errors on master and slave, 
when one or more of these tables do not exist. Because when executed
on slave, it would automatically add IF EXISTS to the query to ignore
all ER_BAD_TABLE_ERROR errors.

To fix the problem, do not add IF EXISTS when executing DROP TEMPORARY
TABLE on the slave, and clear the ER_BAD_TABLE_ERROR error after
execution if the query does not expect any errors.


mysql-test/r/rpl_drop_temp.result:
  Updated for the patch of bug#49137.
mysql-test/t/rpl_drop_temp.test:
  Added the test file to verify if DROP MULTI TEMPORARY TABLE
  will cause different errors on master and slave, when one or
  more of these tables do not exist.
sql/log_event.cc:
  Added code to handle above cases which are
  removed from sql_parse.cc
sql/sql_parse.cc:
  Remove the code to issue the 'Unknown table' error,
  if the temporary table does not exist when dropping
  it on slave. The above cases decribed in comments
  will be handled later in log_event.cc.
2009-12-31 11:33:10 +08:00
Ramil Kalimullin
041baac326 Auto-merge. 2009-12-26 15:25:56 +04:00
Ramil Kalimullin
732a6a9e36 Auto-merge. 2009-12-26 14:59:56 +04:00
Georgi Kodinov
d2f61748cd Bug #49512 : subquery with aggregate function crash
subselect_single_select_engine::exec()

When a subquery doesn't need to be evaluated because
it returns only aggregate functions and these aggregates
can be calculated from the metadata about the table it
was not updating all the relevant members of the JOIN 
structure to reflect that this is a constant query.
This caused problems to the enclosing subquery 
('<> SOME' in the test case above) trying to read some
data about the tables.

Fixed by setting const_tables to the number of tables 
when the SELECT is optimized away.
2009-12-23 17:11:22 +02:00
Georgi Kodinov
2fa49930ca revert of the fix for bug #45989: pushed by mistake. 2010-01-19 14:48:41 +02:00
Mattias Jonsson
8c6d6c0c6c merge 2010-01-19 12:18:48 +01:00
Georgi Kodinov
b60d59b958 merge 2010-01-19 12:45:34 +02:00
Sergey Glukhov
81391bd00c Bug#49501 Inefficient information_schema check (system collation)
added check_length optimization for I_S_NAME comparison


sql/event_data_objects.cc:
  added check_length optimization for I_S_NAME comparison
sql/events.cc:
  added check_length optimization for I_S_NAME comparison
sql/mysql_priv.h:
  added check_length optimization for I_S_NAME comparison
sql/repl_failsafe.cc:
  added check_length optimization for I_S_NAME comparison
sql/sql_db.cc:
  added check_length optimization for I_S_NAME comparison
sql/sql_parse.cc:
  added check_length optimization for I_S_NAME comparison
sql/sql_show.cc:
  added check_length optimization for I_S_NAME comparison
sql/sql_view.cc:
  added check_length optimization for I_S_NAME comparison
sql/table.cc:
  added check_length optimization for I_S_NAME comparison
2010-01-19 13:03:40 +04:00
Mattias Jonsson
eab2be0aee Bug#47343: InnoDB fails to clean-up after lock wait timeout on
REORGANIZE PARTITION

There were several problems which lead to this this,
all related to bad error handling.

1) There was several bugs preventing the ddl-log to be used for
   cleaning up created files on error.

2) The error handling after the copy partition rows did not close
   and unlock the tables, resulting in deletion of partitions
   which were in use, which lead InnoDB to put the partition to
   drop in a background queue.

sql/ha_partition.cc:
  Bug#47343: InnoDB fails to clean-up after lock wait timeout on
             REORGANIZE PARTITION
  
  Better error handling, if partition has been created/opened/locked
  then make sure it is unlocked and closed before returning error.
  The delete of the newly created partition is handled by the ddl-log.
sql/sql_parse.cc:
  Bug#47343: InnoDB fails to clean-up after lock wait timeout on
             REORGANIZE PARTITION
  
  Fix a bug found when experimenting, thd could really be NULL here,
  as mentioned in the function header.
sql/sql_partition.cc:
  Bug#47343: InnoDB fails to clean-up after lock wait timeout on
             REORGANIZE PARTITION
  
  Used the correct .frm shadow name to put into the ddl-log.
  Really use the ddl-log to handle errors.
sql/sql_table.cc:
  Bug#47343: InnoDB fails to clean-up after lock wait timeout on
             REORGANIZE PARTITION
  
  Fixes of the ddl-log when used as error recovery (no crash).
  When executing an entry from memory (not read from disk)
  the name_len was not set correctly.
2010-01-18 17:49:18 +01:00
Georgi Kodinov
5ba1dd0474 Bug #45989 take 2 : memory leak after explain encounters an
error in the query.

Fixes a leak after materializing a GROUP BY subquery to a 
temp table when the subquery has a blob column in the SELECT
list.
Fixed by correctly destructing temporary buffers after doing
the conversion.
2010-01-18 17:50:46 +02:00
Georgi Kodinov
6b8ec684c7 Bug #39022: Mysql randomly crashing in lock_sec_rec_cons_read_sees
flush_cached_records() was not correctly checking for errors after calling
Item::val_xxx() methods. The expressions may contain subqueries
or stored procedures that cause errors that should stop the statement.
Fixed by correctly checking for errors and propagating them up the call stack.
2009-12-23 12:45:18 +02:00
Sergey Glukhov
2be07c7094 Bug#47736 killing a select from a view when the view is processing a function, asserts
hide_view_error() does not take into account that thread query may be killed.
Added a check for thd->killed.
Addon: backported bug32140 fix from 6.0


mysql-test/r/sp_notembedded.result:
  test case
mysql-test/t/sp_notembedded.test:
  test case
sql/sp.cc:
  backported bug32140 fix from 6.0
sql/table.cc:
  Added a check for thd->killed.
2010-02-05 13:39:46 +04:00
Georgi Kodinov
3c9bfe8334 Addendum to the fix for bug #45989
Need to make sure the tmp join doesn't point to the structure already 
freed by the cleanup() for the "base" join, as this can lead to 
double free, because sometimes both tmp_join and join point to the 
same tmp_table_params.copy_field array.
2010-02-04 18:51:55 +02:00
Georgi Kodinov
a89d88dc0a Bug #45989 take 2 : memory leak after explain encounters an
error in the query.

Fixes a leak after materializing a GROUP BY subquery to a 
temp table when the subquery has a blob column in the SELECT
list.
Fixed by correctly destructing temporary buffers for re-usable
queries
2010-02-02 18:30:23 +02:00
Staale Smedseng
8c65b726a5 Recommit of Bug#49447. 2010-02-04 13:39:42 +01:00
Georgi Kodinov
679de2bb5e Bug #50276: Security flaw in INFORMATION_SCHEMA.TABLES
check_access() returning false for a database does not
guarantee that the access is granted to it.
This wrong condition in filling the INFORMATION_SCHEMA
tables causes extra tables to be returned to the user
even if he has no rights to see them.
Fixed by correcting the condition.
2010-01-21 17:14:10 +02:00
Georgi Kodinov
e4b7138561 Bug #49445: Assertion failed: 0, file .\item_row.cc, line 55 with
fulltext search and row op.

The search for fulltext indexes is searching for some special 
predicate layouts. While doing so it's not checking for the number
of columns of the expressions it tries to calculate.
And since row expressions can't return a single scalar value there
was a crash.
Fixed by checking if the expressions are scalar (in addition to 
being constant) before calling Item::val_xxx() methods.
2010-02-02 18:37:56 +02:00
Magne Mahre
090c75d2b0 Cleanup fix for WL#5154 that splits commands handling for
--default-character-set and --character-set-server such
that only the first will give a deprecation warning.
Apart from that, the two options should do the same.
2010-02-02 16:34:32 +01:00
Alexander Nozdrin
59f1be1b63 Revert a patch for Bug#48231, which introduced valgrind warnings.
Original revision:
------------------------------------------------------------
revision-id: li-bing.song@sun.com-20100130124925-o6sfex42b6noyc6x
parent: joro@sun.com-20100129145427-0n79l9hnk0q43ajk
committer: <Li-Bing.Song@sun.com>
branch nick: mysql-5.1-bugteam
timestamp: Sat 2010-01-30 20:49:25 +0800
message:
  Bug #48321  CURRENT_USER() incorrectly replicated for DROP/RENAME USER;
              REVOKE/GRANT; ALTER EVENT.
  
  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() EVENT
  but, 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, All above statements are rewritten when they are binlogged.
  The CURRENT_USER() is expanded to the real user's name and host.
------------------------------------------------------------
2010-02-02 16:38:44 +03:00
Georgi Kodinov
1dafac6f35 fixed various pb2 test failures on windows. 2010-02-02 14:17:21 +02:00
Georgi Kodinov
92de86293a merge 2010-02-01 13:50:30 +02:00
unknown
d9e9a73e8f Bug #48321 CURRENT_USER() incorrectly replicated for DROP/RENAME USER;
REVOKE/GRANT; ALTER EVENT.

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() EVENT
but, 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, All above statements are rewritten when they are binlogged.
The CURRENT_USER() is expanded to the real user's name and host.
2010-01-30 20:49:25 +08:00
Tor Didriksen
181f753e8b Bug #50271: Debug output of JOIN structures is garbled
sql/sql_test.cc:
  Assemble results of all the calls to full_name() first,
  in order not to garble the tabular output.
2010-01-28 12:10:57 +01:00
Ramil Kalimullin
7805a2c7c0 Auto-merge. 2010-01-29 15:08:49 +04:00
Georgi Kodinov
443003a467 Bug #49552 : sql_buffer_result cause crash + not found records
in multitable delete/subquery

SQL_BUFFER_RESULT should not have an effect on non-SELECT 
statements according to our documentation.
Fixed by not passing it through to multi-table DELETE (similarly
to how it's done for multi-table UPDATE).
2010-01-29 11:36:28 +02:00
Davi Arnaut
c3a73a8f6d Fix for compiler warnings:
Rename method as to not hide a base.
Reorder attributes initialization.
Remove unused variable.
Rework code to silence a warning due to assignment used as truth value.


sql/item_strfunc.cc:
  Rename method as to not hide a base.
sql/item_strfunc.h:
  Rename method as to not hide a base.
sql/log_event.cc:
  Reorder attributes initialization.
sql/rpl_injector.cc:
  Rework code to silence a warning due to assignment used as truth value.
sql/rpl_record.cc:
  Remove unused variable.
sql/sql_db.cc:
  Rework code to silence a warning due to assignment used as truth value.
sql/sql_parse.cc:
  Rework code to silence a warning due to assignment used as truth value.
sql/sql_table.cc:
  Rework code to silence a warning due to assignment used as truth value.
2010-01-28 19:51:40 -02:00
Andrei Elkin
0c0eb1d44a merging from 5.1-bt to a local bugfix branch 2010-01-28 11:51:57 +02:00
Andrei Elkin
a589499986 bug#47142
merging patches prepared for 5.0 to 5.1-bt. That caused a few changes in the test file
2010-01-27 19:27:49 +02:00
Andrei Elkin
29cd733fce bug#47142
improving comments
2010-01-27 15:20:03 +02:00
Magne Mahre
35c6bb89e6 WL#5182 Remove more deprecated 4.1/5.0 features
WL#5182 is a follow-up to WL#5154, deprecating a few more options
and system variables.


client/client_priv.h:
  The warning message has been changed to not include
  a specific version number in the text.
client/mysql.cc:
  --no-tee is deprecated
client/mysqldump.c:
  --all is deprecated
  -a now points to create-options
mysql-test/r/mysqlbinlog.result:
  Warning text changed
mysql-test/suite/rpl/r/rpl_row_mysqlbinlog.result:
  Warning text changed
sql/mysql_priv.h:
  The warning message has been changed to not include
  a specific version number in the text.
sql/mysqld.cc:
  --use-symbolic-links is deprecated
  -s now points to --symbolic-links
  --warnings is deprecated
  -W now points to --log-warnings
          
  myisam_max_extra_sort_file_size is deprecated
  record_buffer is deprecated
          
  --log-update is deprecated
  --sql-bin-update-same is deprecated
  --skip-locking is deprecated
  --skip-symlink is deprecated
  --enable-locking is deprecated
  --delay-key-write-for-all-tables is deprecated
2010-01-27 13:23:28 +01:00
Andrei Elkin
cfa7e83d6d Bug #47142 "slave start until" stops 1 event too late in 4.1 to 5.0 replication
When replicating from 4.1 master to 5.0 slave START SLAVE UNTIL can stop too late.
The necessary in calculating of the beginning of an event the event's length
did not correspond to the master's genuine information at the event's execution time.
That piece of info was changed at the event's relay-logging due to binlog_version<4 event
conversion by IO thread.

Fixed with storing the master genuine Query_log_event size into a new status
variable at relay-logging of the event. The stored info is extacted at the event
execution and participate further to caclulate the correct start position of the event
in the until-pos stopping routine.
The new status variable's algorithm will be only active when the event comes
from the master of version < 5.0 (binlog_version < 4).


mysql-test/r/rpl_until.result:
  results changed.
mysql-test/std_data/bug47142_master-bin.000001:
  a binlog from 4.1 master to replace one of the running 5.x master is added as 
  part of Bug #47142 regression test.
mysql-test/t/rpl_until.test:
  Regression test for Bug #47142 is added.
sql/log_event.cc:
  Storing and extracting the master's genuine size of the event from the status
  var of the event packet header.
  The binlog_version<4 query-log-event is 
  a. converted into the modern binlog_version==4 to store the original size of the event
     into a new status var; the converted representation goes into the relay log.
  b. the converted event is read out and the stored size is engaged in the start pos calculation.
  
  The new status is active only for events that IO thread instantiates for the sake of the conversion.
sql/log_event.h:
  Incrementing the max szie of MAX_SIZE_LOG_EVENT_STATUS because of the new status var;
  Defining the new status variable to hold the master's genuine event size;
  Augmenting the Query_log_event with a new member to hold a value to store/extact from the status
  var of the event packet header.
2010-01-25 17:46:48 +02:00
Mattias Jonsson
28e64daf2d Bug#49742: Partition Pruning not working correctly for RANGE
Problem was when calculating the range of partitions for
pruning.

Solution was to get the calculation correct. I also simplified
it a bit for easier understanding.

mysql-test/r/partition_pruning.result:
  Bug#49742: Partition Pruning not working correctly for RANGE
  
  Added results.
mysql-test/t/partition_pruning.test:
  Bug#49742: Partition Pruning not working correctly for RANGE
  
  Added tests to prevent regressions.
sql/sql_partition.cc:
  Bug#49742: Partition Pruning not working correctly for RANGE
  
  Simplified calculation for partition id for ranges.
  Easier to get right and understand.
  
  Added comments.
2009-12-22 18:59:37 +01:00
Georgi Kodinov
2d8869d248 Bug #49734: Crash on EXPLAIN EXTENDED UNION ... ORDER BY <any non-const-function>
Several problems fixed : 
1. Non constant expressions in UNION ... ORDER BY were not correctly cleaned up
in st_select_lex_unit::cleanup() causing crashes in EXPLAIN EXTENDED because of
fields quoted by these expressions pointing to the already freed temporary table
used to calculate the UNION.
Fixed by correctly cleaning up expressions of any depth.

2. Subqueries in the order by part of UNION ... ORDER BY ... caused a crash in 
EXPLAIN EXTENDED because of a transformation attempt made during EXPLAIN EXTENDED
execution. Fixed by not doing the transformation when in EXPLAIN.

3. Fulltext functions caused crash when in the ORDER BY part of an un-parenthesized
UNION that gets "promoted" to be valid for the whole union, e.g. 
SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY MATCHES (a) AGAINST ('abc' IN BOOLEAN MODE).
This is a case that demonstrates a more general problem of parts of the query being
moved to another level. When doing such transformation late in the optimization run
when most of the flags about the contents of the query are already aggregated it's possible 
to "split" the flags so that they correctly reflect the new queries after the transformation.
In specific the ST_SELECT_LEX::ftfunc_list is holding all the free text function for all the 
parts of the second SELECT in the UNION and we don't know what part of that is in the ORDER BY
that we're to move to the UNION level and what part is about the other parts of the second SELECT.
Fixed by throwing and error when such statements are about to be processed by adding a check 
for the presence of MATCH() inside the ORDER BY clause that's going to get promoted to UNION.
To workaround this new limitation one must parenthesize the UNION SELECTs and provide a real 
global ORDER BY for the UNION outside of the parenthesis.
2009-12-22 17:52:15 +02:00
Sergey Glukhov
c0bd23ddbf 5.0-bugteam->5.1-bugteam merge 2009-12-22 14:38:33 +04:00
Sergey Glukhov
081bcb3b8b Bug#47371 reference by same column name
At the end of execution top level join execution
we cleanup this join with true argument.
It leads to underlying join cleanup(subquery) with true argument too
and to tmp_table_param->field array cleanup which is required later.
The problem is that Item_func_set_user_var does not set
result_filed which leads to unnecessary repeated excution of subquery
on final stage.
The fix is to set result_field for Item_func_set_user_var.


mysql-test/r/count_distinct.result:
  test result
mysql-test/r/user_var.result:
  test result
mysql-test/t/count_distinct.test:
  test case
mysql-test/t/user_var.test:
  test case
sql/item_func.cc:
  At the end of execution top level join execution
  we cleanup this join with true argument.
  It leads to underlying join cleanup(subquery) with true argument too
  and to tmp_table_param->field array cleanup which is required later.
  The problem is that Item_func_set_user_var does not set
  result_filed which leads to unnecessary repeated excution of subquery
  on final stage.
  The fix is to set result_field for Item_func_set_user_var.
2009-12-22 13:52:23 +04:00
Ramil Kalimullin
7344b58c32 Fix for bug#49570: Assertion failed: !(order->used & map)
on re-execution of prepared statement

Problem: some (see eq_ref_table()) ORDER BY/GROUP BY optimization
is called before each PS execution. However, we don't properly 
initialize its stucture every time before the call.

Fix: properly initialize the sturture used.



mysql-test/r/ps.result:
  Fix for bug#49570: Assertion failed: !(order->used & map) 
  on re-execution of prepared statement
    - test result.
mysql-test/t/ps.test:
  Fix for bug#49570: Assertion failed: !(order->used & map) 
  on re-execution of prepared statement
    - test case.
sql/sql_select.cc:
  Fix for bug#49570: Assertion failed: !(order->used & map) 
  on re-execution of prepared statement
    - set order->used to 0 before each eq_ref_table() call,
  as the function relies on that.
2009-12-22 10:39:29 +04:00
Mattias Jonsson
df357ed514 merge 2009-12-22 00:06:36 +01:00
Davi Arnaut
25be2b28d1 Bug#48983: Bad strmake calls (length one too long)
MySQL 5.1 specific fixes.
2009-12-18 17:14:09 -02:00
Davi Arnaut
61ae928898 Manual merge. 2009-12-18 16:44:24 -02:00
Georgi Kodinov
a21a0b47ca Bug #31145: ALTER TABLE DROP COLUMN, ADD COLUMN crashes (linux) or
freezes (win) the server

The check for equality was assuming the field object is always 
created. If it's not it was de-referencing a NULL pointer.
Fixed to use the data in the create object instead.
2009-12-18 14:00:30 +02:00
Sergey Glukhov
877311779d Bug#47649 crash during CALL procedure
If first call of the procedure is failed on
the open_table stage stmt_arena->state is set to
EXECUTED state. On second call(if no errors on
open_table stage) it leads to use of worng memory arena
in find_field_in_view() function as
thd->stmt_arena->is_stmt_prepare_or_first_sp_execute()
returns FALSE for EXECUTED state. The item is created 
not in its own arena and it leads to crash on further
calls of the procedure.
The fix: 
change state of arena only if
no errors on open_table stage happens.


mysql-test/r/sp.result:
  test result
mysql-test/t/sp.test:
  test case
sql/sp_head.cc:
  If first call of the procedure is failed on
  the open_table stage stmt_arena->state is set to
  EXECUTED state. On second call(if no errors on
  open_table stage) it leads to use of worng memory arena
  in find_field_in_view() function as
  thd->stmt_arena->is_stmt_prepare_or_first_sp_execute()
  returns FALSE for EXECUTED state. The item is created 
  not in its own arena and it leads to crash on further
  calls of the procedure.
  The fix: 
  change state of arena only if
  no errors on open_table stage happens.
2009-12-23 17:44:03 +04:00
Magne Mahre
f815246486 Backport to 5.1 branch (next-mr revid: 2921)
Bug#35589 SET PASSWORD caused a crash
Bug#35591 FLUSH PRIVILEGES caused a crash
      
A race condition on the privilege hash tables (proc_priv_hash
and func_priv_hash) caused one thread to try to delete elements
that had already been deleted by another thread.
      
The bug was caused by reading and saving the pointers to 
the hash tables outside mutex protection.  This led to an
inconsistency where a thread copied a pointer to a hash,
another thread did the same, the first thread then deleted
the hash, and the second then crashed when it in turn tried to
delete the deleted hash.
      
The fix is to ensure that operations on the shared hash structures
happens under mutex protection (moving the locking up a little)
2009-12-18 11:48:34 +01:00
Davi Arnaut
06a1df9181 Bug#48983: Bad strmake calls (length one too long)
The problem is a somewhat common misusage of the strmake function.
The strmake(dst, src, len) function writes at most /len/ bytes to
the string pointed to by src, not including the trailing null byte.
Hence, if /len/ is the exact length of the destination buffer, a
one byte buffer overflow can occur if the length of the source
string is equal to or greater than /len/.

client/mysqldump.c:
  Make room for the trailing null byte.
libmysql/libmysql.c:
  Add comment, there is enough room in the buffer.
  Increase buffer length, two strings are concatenated.
libmysqld/lib_sql.cc:
  Make room for the trailing null byte.
mysys/default.c:
  Make room for the trailing null bytes.
mysys/mf_pack.c:
  Make room for the trailing null byte.
server-tools/instance-manager/commands.cc:
  Copy only if overflow isn't possible in both cases.
server-tools/instance-manager/listener.cc:
  Make room for the trailing null byte.
sql/log.cc:
  Make room for the trailing null byte.
sql/sp_pcontext.h:
  Cosmetic fix.
sql/sql_acl.cc:
  MAX_HOSTNAME already specifies space for the trailing null byte.
sql/sql_parse.cc:
  Make room for the trailing null byte.
sql/sql_table.cc:
  Make room for the trailing null byte.
2009-12-17 15:58:38 -02:00
Alfranio Correia
b1090b13fc merge mysql-5.1-bugteam (local) --> mysql-5.1-bugteam 2009-12-17 15:47:22 +00:00
Satya B
5db5e19ad6 merge to mysql-5.1-bugteam 2009-12-17 17:47:34 +05:30
Satya B
bbf079cf2c merge mysql-5.0-bugteam to mysql-5.1-bugteam 2009-12-17 17:15:13 +05:30
Satya B
cf9966f86f Fix for Bug#37408 - Compressed MyISAM files should not require/use mmap()
When compressed myisam files are opened, they are always memory mapped
sometimes causing memory swapping problems.

When we mmap the myisam compressed tables of size greater than the memory 
available, the kswapd0 process utilization is very high consuming 30-40% of 
the cpu. This happens only with linux kernels older than 2.6.9

With newer linux kernels, we don't have this problem of high cpu consumption
and this option may not be required.
 
The option 'myisam_mmap_size' is added to limit the amount of memory used for
memory mapping of myisam files. This option is not dynamic.

The default value on 32 bit system is 4294967295 bytes and on 64 bit system it
is 18446744073709547520 bytes.

Note: Testcase only tests the option variable. The actual bug has be to 
tested manually.

include/my_global.h:
  Fix for Bug #37408 - Compressed MyISAM files should not require/use mmap()
  
  define SIZE_T_MAX
include/myisam.h:
  Fix for Bug #37408 - Compressed MyISAM files should not require/use mmap()
  
  declare 'myisam_mmap_size' and 'myisam_mmap_used' variables and the mutex
  THR_LOCK_myisam_mmap
myisam/mi_packrec.c:
  Fix for Bug #37408 - Compressed MyISAM files should not require/use mmap()
  
  add 'myisam_mmap_size' option which limits the memory available to mmap of 
  myisam files
myisam/mi_static.c:
  Fix for Bug #37408 - Compressed MyISAM files should not require/use mmap()
  
  declare 'myisam_mmap_size' and 'myisam_mmap_used' variables and the mutex
  THR_LOCK_myisam_mmap
myisam/myisamdef.h:
  Fix for Bug #37408 - Compressed MyISAM files should not require/use mmap()
  
  move MEMMAP_EXTRA_MARGIN to myisam.h so that it can be used in mysqld.cc
mysql-test/r/variables.result:
  Fix for Bug #37408 - Compressed MyISAM files should not require/use mmap()
  
  Testcase for BUG#37408 to test the myisam_mmap_size option
mysql-test/t/variables.test:
  Fix for Bug #37408 - Compressed MyISAM files should not require/use mmap()
  
  Testcase for BUG#37408 to test the myisam_mmap_size option
mysys/my_thr_init.c:
  Fix for Bug #37408 - Compressed MyISAM files should not require/use mmap()
  
  intialize the lock THR_LOCK_myisam_mmap
sql/mysqld.cc:
  Fix for Bug #37408 - Compressed MyISAM files should not require/use mmap()
  
  add the 'myisam_mmap_size' option
sql/set_var.cc:
  Fix for Bug #37408 - Compressed MyISAM files should not require/use mmap()
  
  add the 'myisam_mmap_size' to the SHOW VARIABLES list
2009-12-17 16:55:50 +05:30
Martin Hansson
6863f7dc2d Bug#47650: using group by with rollup without indexes
returns incorrect results with where

An outer join of a const table (outer) and a normal table
(inner) with GROUP BY on a field from the outer table would
optimize away GROUP BY, and thus trigger the optimization to
do away with a temporary table if grouping was performed on
columns from the const table, hence executing the query with
filesort without temporary table. But this should not be
done if there is a non-indexed access to the inner table,
since filesort does not handle joins. It expects either ref
access, range ditto or table scan. The join condition will
thus not be applied.

Fixed by always forcing execution with temporary table in
the case of ROLLUP with a query involving an outer join. This
is a slightly broader class of queries than need fixing, but
it is hard to ascertain the position of a ROLLUP field wrt
outer join with current query representation.

mysql-test/r/join_outer.result:
  Bug#47650: Test result
mysql-test/t/join_outer.test:
  Bug#47650: Test case
sql/sql_select.cc:
  Bug#47650: Fix
2009-12-17 10:55:18 +01:00
Ramil Kalimullin
4621d480fc Auto-merge. 2009-12-17 10:52:43 +04:00
Ramil Kalimullin
06be03f77c Fix for bug#49465: valgrind warnings and incorrect live checksum...
Problem: inserting a record we don't set unused null bits in the
record buffer if no default field values used.
That may lead to wrong live checksum calculation.

Fix: set unused null bits in the record buffer in such cases.


mysql-test/r/myisam.result:
  Fix for bug#49465: valgrind warnings and incorrect live checksum...
    - test result.
mysql-test/t/myisam.test:
  Fix for bug#49465: valgrind warnings and incorrect live checksum...
    - test case.
sql/sql_insert.cc:
  Fix for bug#49465: valgrind warnings and incorrect live checksum...
    - set unused null bits to 1 in the record buffer in case we
  don't call restore_record() before a fill_record() call
  (when no default values used).
2009-12-17 09:55:03 +04:00
Alfranio Correia
ad4bbb281f BUG#49638 binlog_index fails in mysql-trunk-merge
Calling push_warning/push_warning_printf with a level of
WARN_LEVEL_ERROR *is* a bug. We should either use my_error(),
or WARN_LEVEL_WARN.
2009-12-16 19:52:56 +00:00
Luis Soares
d5925fb1d0 BUG#48738: merge local branch into mysql-5.0-bugteam latest. 2009-12-24 02:26:29 +00:00
Georgi Kodinov
b72f278958 Bug #48709: Assertion failed in sql_select.cc:11782:
int join_read_key(JOIN_TAB*)

The eq_ref access method TABLE_REF (accessed through 
JOIN_TAB) to save state and to track if this is the 
first row it finds or not.
This state was not reset on subquery re-execution
causing an assert.

Fixed by resetting the state before the subquery 
re-execution.
2009-12-15 19:10:06 +02:00
Ramil Kalimullin
c5e6a11e14 Fix for bug#49517: Inconsistent behavior while using
NULLable BIGINT and INT columns in comparison

Problem: a consequence of the fix for 43668.
Some Arg_comparator inner initialization missed,
that may lead to unpredictable (wrong) comparison
results.

Fix: always properly initialize Arg_comparator
before its usage.


mysql-test/r/select.result:
  Fix for bug#49517: Inconsistent behavior while using 
  NULLable BIGINT and INT columns in comparison
    -test result.
mysql-test/t/select.test:
  Fix for bug#49517: Inconsistent behavior while using 
  NULLable BIGINT and INT columns in comparison
    -test case.
sql/item_cmpfunc.cc:
  Fix for bug#49517: Inconsistent behavior while using 
  NULLable BIGINT and INT columns in comparison
    - now all Arg_comparator::set_cmp_func() set
  Arg_comparator::set_null to ensure its proper initialization
  in all cases (by default it's set to TRUE in constructors).
sql/item_cmpfunc.h:
  Fix for bug#49517: Inconsistent behavior while using 
  NULLable BIGINT and INT columns in comparison
    - now all Arg_comparator::set_cmp_func() set
  Arg_comparator::set_null to ensure its proper initialization
  in all cases (by default it's set to TRUE in constructors).
2009-12-15 21:08:21 +04:00
Georgi Kodinov
188c6f8c74 Bug #48709: Assertion failed in sql_select.cc:11782:
int join_read_key(JOIN_TAB*)

The eq_ref access method TABLE_REF (accessed through 
JOIN_TAB) to save state and to track if this is the 
first row it finds or not.
This state was not reset on subquery re-execution
causing an assert.

Fixed by resetting the state before the subquery 
re-execution.
2009-12-15 14:20:29 +02:00
Jon Olav Hauglid
4578a5c61b Bug #48995 abort missing DBUG_RETURN or .. in function "check_key_in_view"
check_key_in_view() had one code branch which returned with "return TRUE"
rather than "DBUG_RETURN(TRUE)". Only affected debug builds.

No test case added.
2009-12-15 10:05:20 +01:00
Georgi Kodinov
d2e723bf53 Bug #48985: show create table crashes if previous access to the table
was killed

Merge the fix from 5.1-bugteam to 5.1-main
2009-12-15 11:03:24 +02:00
Georgi Kodinov
838adcf2ff Bug#49489: Uninitialized cache led to a wrong result.
Merge the fix from 5.1-bugteam to 5.1-main
2009-12-15 10:54:53 +02:00
Georgi Kodinov
915cc3e9b0 Bug #49480: WHERE using YEAR columns returns unexpected results
Merge the fix from 5.1-bugteam to 5.1-main
2009-12-15 10:37:10 +02:00
He Zhenxing
fb7214ae4b bug#49536 - deadlock on rotate_and_purge when using expire_logs_days
Problem is that purge_logs implementation in ndb (ndbcluster_binlog_index_purge_file)
calls mysql_parse (with (thd->options & OPTION_BIN_LOG) === 0)) 
but MYSQL_BIN_LOG first takes LOCK_log and then checks thd->options

Solution in this patch, changes so that rotate_and_purge does not hold
LOCK_log when calling purge_logs_before_date. I think this is safe
as other "purge"-function(s) is called wo/ holding LOCK_log, e.g purge_master_logs
2009-12-15 14:48:28 +08:00
unknown
e813587b40 Bug #34628 LOAD DATA CONCURRENT INFILE drops CONCURRENT in binary log
'LOAD DATA CONCURRENT [LOCAL] INFILE ...' statment only is binlogged as
'LOAD DATA [LOCAL] INFILE ...' in SBR and MBR.  As a result, if replication is on, 
queries on slaves will be blocked by the replication SQL thread.

This patch write code to write 'CONCURRENT' into the log event if 'CONCURRENT' option
is in the original statement in SBR and MBR.
2009-12-15 13:14:14 +08:00
Andrei Elkin
8948664470 correction to the earlier merging: s/return/DBUG_RETURN/ 2009-12-14 18:50:22 +02:00
Andrei Elkin
c00bfe59b3 merging 5.0-bt -> 5.1-bt to local branch with bug@47210 2009-12-14 18:32:22 +02:00
Andrei Elkin
efc5e0a8a6 merging 5.0-bt to local branch with bug@47210 2009-12-14 16:44:10 +02:00
unknown
6fd71b12b8 Merging 2009-12-14 01:16:50 +01:00
unknown
71c54b8c0c This is a patch for Bug#48500
5.0 buffer overflow for ER_UPDATE_INFO, or truncated info message in 5.1
      
5.0.86 has a buffer overflow/crash, and 5.1.40 has a truncated message.
      
errmsg.txt contains this:
      
ER_UPDATE_INFO
rum "Linii identificate (matched): %ld  Schimbate: %ld  Atentionari 
(warnings): %ld"
When that is sprintf'd into a buffer of STRING_BUFFER_USUAL_SIZE size,
a buffer overflow can happen.
      
The solution to this is to use MYSQL_ERRMSG_SIZE for the buffer size, 
instead of STRING_BUFFER_USUAL_SIZE. This will allow longer strings. 
To avoid potential crashes, we will also use my_snprintf instead of
sprintf.

sql/sql_update.cc:
  sing MYSQL_ERRMSG_SIZE instead of STRING_BUFFER_USUAL_SIZE.
  Using my_snprintf instead of sprintf.
2009-12-14 00:58:16 +01:00
Alexey Kopytov
d65fdb3168 Automerge 2009-12-13 23:57:57 +03:00
Alexey Kopytov
c08e6c8867 Bug #42849: innodb crash with varying time_zone on partitioned
timestamp primary key 
 
Since TIMESTAMP values are adjusted by the current time zone  
settings in both numeric and string contexts, using any 
expressions involving TIMESTAMP values as a  
(sub)partitioning function leads to undeterministic behavior of  
partitioned tables. The effect may vary depending on a storage  
engine, it can be either incorrect data being retrieved or  
stored, or an assertion failure. The root cause of this is the  
fact that the calculated partition ID may differ from a  
previously calculated ID for the same data due to timezone  
adjustments of the partitioning expression value. 
 
Fixed by disabling any expressions involving TIMESTAMP values  
to be used in partitioning functions with the follwing two 
exceptions: 
 
1. Creating or altering into a partitioned table that violates 
the above rule is not allowed, but opening existing such tables 
results in a warning rather than an error so that such tables 
could be fixed. 
 
2. UNIX_TIMESTAMP() is the only way to get a 
timezone-independent value from a TIMESTAMP column, because it 
returns the internal representation (a time_t value) of a 
TIMESTAMP argument verbatim. So UNIX_TIMESTAMP(timestamp_column)
is allowed and should be used to fix existing tables if one 
wants to use TIMESTAMP columns with partitioning.

mysql-test/r/partition_bug18198.result:
  Corrected the error.
mysql-test/r/partition_error.result:
  Corrected error texts.
  Added test cases for bug #42849.
mysql-test/t/partition_bug18198.test:
  Corrected error code.
mysql-test/t/partition_error.test:
  Corrected error codes.
  Added test cases for bug #42849.
sql/item.h:
  Added is_timezone_dependent_processor() to Item.
sql/item_func.h:
  Added has_timestamp_args() and the implementation of
  is_timezone_dependent_processor() for Item_func.
sql/item_timefunc.h:
  Added is_timezone_dependent_processor() to 
  Item_func_unix_timestamp.
sql/share/errmsg.txt:
  Renamed ER_CONST_EXPR_IN_PARTITION_FUNC_ERROR to
  ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR to better reflect the
  meaning. Adjusted the error message.
sql/sql_partition.cc:
  Modified fix_fields_part_func() to walk through partitioning
  expression tree with is_timezone_dependent_processor() and issue
  a warning/error if it depends on the timezone settings.
  
  Changed fix_fields_part_func() to a static function since it is
  not used anywhere except sql_partition.cc
sql/sql_partition.h:
  Removed the unneeded declaration of fix_fields_part_func()
  since it is now a static function.
sql/sql_yacc.yy:
  ER_CONST_EXPR_IN_PARTITION_FUNC_ERROR ->
  ER_WRONG_EXPR_IN_PARTITION_FUNC_ERROR.
2009-12-13 23:29:50 +03:00
Staale Smedseng
8969530cff Bug #45058 init_available_charsets uses double checked locking
As documented in the bug report, the double checked locking
pattern has inherent issues, and cannot guarantee correct
initialization.

This patch replaces the logic in init_available_charsets()
with the use of pthread_once(3). A wrapper function,
my_pthread_once(), is introduced and is used in lieu of direct
calls to init_available_charsets(). Related defines
MY_PTHREAD_ONCE_* are also introduced.

For the Windows platform, the implementation in lp:sysbench is
ported. For single-thread use, a simple define calls the
function and sets the pthread_once control variable.

Charset initialization is modified to use my_pthread_once().

include/my_no_pthread.h:
  Dummy my_pthread_once() for single thread use.
include/my_pthread.h:
  Declaration for new function my_pthread_once().
mysys/charset.c:
  Logic in init_available_charsets() is simplified. 
  Using my_pthread_once() for all calls to this func.
mysys/my_winthread.c:
  Windows implementation of my_pthread_once().
2009-12-12 19:11:25 +01:00
Mattias Jonsson
d72a15fcaa Bug#49477: Assertion `0' failed in ha_partition.cc:5530
with temporary table and partitions

It was possible to create temporary partitioned tables
via create table ... like ... (which is not allowed with
create temporary table). This lead to a new HA_EXTRA flag
(HA_EXTRA_MMAP) was sent to the partitioning handler,
which was caught on an assert in debug builds.

Solution was to check for partitioned tables when
doing create table ... like ... and disallow it.

mysql-test/r/partition_error.result:
  Bug#49477: Assertion `0' failed in ha_partition.cc:5530
  with temporary table and partitions
  
  Added result
mysql-test/t/partition_error.test:
  Bug#49477: Assertion `0' failed in ha_partition.cc:5530
  with temporary table and partitions
  
  Added test
sql/sql_table.cc:
  Bug#49477: Assertion `0' failed in ha_partition.cc:5530
  with temporary table and partitions
  
  Added check to prevent creation of partitioned temporary
  tables.
  
  Only copy .par file for partitioned tables.
2009-12-11 18:41:31 +01:00
Georgi Kodinov
35adb5cf7a merge 2009-12-11 17:24:09 +02:00
Georgi Kodinov
492ff989fb merge 2009-12-11 16:07:19 +02:00
Georgi Kodinov
a72c4259c8 merge 2009-12-11 16:07:09 +02:00
Georgi Kodinov
97620e3ba8 merge of bug #49250 to 5.1-bugteam 2009-12-11 16:02:47 +02:00
Evgeny Potemkin
684c7aba09 Auto-merged fix for bug#49489. 2009-12-11 16:08:29 +03:00
unknown
ba71a9e5d6 Bug #48742 Replication: incorrect help text for --init-slave
The help text for --init-slave=name:
"Command(s) that are executed when a slave connects to this master".
This text indicate that the --init-slave option is set on a  master 
server, and the master server passes the option's argument to slave 
which connects to it. This is wrong. Actually the --init-slave option 
just can be set on a slave server, and then the slave server executes 
the argument each time the SQL thread starts.

Correct the help text for --init-slave option as following:
"Command(s) that are executed by a slave server each time the SQL thread starts."


sql/mysqld.cc:
  Correct the help text for --init-slave option.
2009-12-11 10:12:18 +08:00
unknown
18d09c0183 Bug #48742 Replication: incorrect help text for --init-slave
The help text for --init-slave=name:
"Command(s) that are executed when a slave connects to this master".
This text indicate that the --init-slave option is set on a  master 
server, and the master server passes the option's argument to slave 
which connects to it. This is wrong. Actually the --init-slave option 
just can be set on a slave server, and then the slave server executes 
the argument each time the SQL thread starts.

Correct the help text for --init-slave option as following:
"Command(s) that are executed by a slave server each time the SQL thread starts."


sql/mysqld.cc:
  Correct the help text for --init-slave option.
2009-12-11 09:57:38 +08:00
Georgi Kodinov
7b174dcafc merge 2009-12-10 17:38:01 +02:00
Georgi Kodinov
30e51fe854 Bug #49250 : spatial btree index corruption and crash
SPATIAL and FULLTEXT indexes don't support algorithm
selection. 
Disabled by creating a special grammar rule for these
in the parser.
Added some encasulation of duplicate parser code.
2009-12-10 11:28:38 +02:00
Ramil Kalimullin
e1d4ad3931 Auto-merge. 2009-12-10 11:03:23 +04:00
Ramil Kalimullin
c888a4a239 Manual merge. 2009-12-10 10:31:52 +04:00
Gleb Shchepa
3246383301 Bug #49480: WHERE using YEAR columns returns unexpected results
A few problems were found in the fix for bug 43668:
1) Comparison of the YEAR column with NULL always returned TRUE;
2) Comparison of the YEAR column with constants always returned
   unpredictable result;
3) Unnecessary conversion warnings when comparing a non-integer
   constant with a NULL value in the YEAR column;

The problems described above have been resolved with an
exception: zero (i.e. invalid) YEAR column value comparison
with 00 or 2000 still fail (it is not a regression and it was
not a regression), so MIN/MAX on YEAR column containing zero
value still fail.


mysql-test/r/type_year.result:
  Test case for bug #49480.
mysql-test/t/type_year.test:
  Test case for bug #49480.
sql/item_cmpfunc.cc:
  - The get_year_value() function has been modified to make its
    return value compatible with the get_datetime_value() return
    value (i.e. to convert numeric values into the YYYY0000000000
    (YYYY-00-00 00:00:00) form.
  
  - The Arg_comparator::set_cmp_func method has been modified to
    use the get_year_value function if get_datetime_value() is not
    applicable.
    From now only 2 cases have a special processing there:
    * both comparing items have MYSQL_TYPE_YEAR field type
            or
    * one item have is MYSQL_TYPE_YEAR and other one is
      is_datetime()-compliant.
  
  - New helper function try_year_cmp_func() has been
    added for the better code readability to call from
    Arg_comparator::set_cmp_func().
  
  - The Arg_comparator::compare_year method has been removed
    since get_year_value() is compatible with the old
    Arg_comparator::compare_datetime method that doesn't have
    problems #1-#3 (see whole patch entry commentary).
sql/item_cmpfunc.h:
  - New helper function try_year_cmp_func() has been
    added for the better code readability to call from
    Arg_comparator::set_cmp_func().
  
  - Unnecessary Arg_comparator::year_as_datetime and
    Arg_comparator::compare_year() declarations have been
    removed.
2009-12-10 10:05:44 +04:00
Ramil Kalimullin
36e019c933 Auto-merge. 2009-12-10 09:51:08 +04:00
He Zhenxing
34c08c158c Auto merge 2009-12-10 12:56:10 +08:00
Evgeny Potemkin
1285ecd468 Bug#49489: Uninitialized cache led to a wrong result.
Arg_comparator uses Item_cache objects to store constants being compared when
they're need a type conversion. Because this cache wasn't initialized properly
Arg_comparator might produce wrong comparison result.

The Arg_comparator::cache_converted_constant function now initializes cache
prior to usage.

mysql-test/r/select.result:
  Added a test case for he bug#49489.
mysql-test/t/select.test:
  Added a test case for he bug#49489.
sql/item_cmpfunc.cc:
  Bug#49489: Uninitialized cache led to a wrong result.
  The Arg_comparator::cache_converted_constant function now initializes cache
  prior to usage.
2009-12-09 18:43:45 +03:00
Olav Sandstaa
9060aa68af Fix for Bug#49506 Valgrind error in make_cond_for_table_from_pred
This fix has been proposed by Sergey Petrunya and has been contributed
under SCA by sca@askmonty.org.
      
The cause for this valgrind error is that in the function
add_cond_and_fix() in sql_select.cc an Item_cond_and object is
created. This is marked as fixed but does not have a correct
table_map() attribute. Later, in make_join_select(), if
engine_condition_pushdown is in use, this table map is used and
results in the valgrind error.
      
The fix is to add a call to update_used_tables() in add_cond_and_fix()
so that the table map is updated correctly.
      
This patch is tested by multiple existing tests (e.g. the tests
innodb_mysql, innodb, fulltext, compress all produces this valgrind
warning/error without this fix).


sql/sql_select.cc:
  In add_cond_and_fix() add a call to update_used_tables() to ensure
  the table map is updated.
2009-12-09 10:16:11 +01:00
He Zhenxing
b13541ff31 Merge Bug#45520 fix from 5.0-bugteam 2009-12-09 14:24:54 +08:00
He Zhenxing
bc2b3d2ccc BUG#45520 rpl_killed_ddl fails sporadically in pb2
There are three issues that caused rpl_killed_ddl fails sporadically
in pb2:

 1) thd->clear_error() was not called before create Query event
if operation is executed successfully.
 2) DATABASE d2 might do exist because the statement to CREATE or
ALTER it was killed
 3) because of bug 43353, kill the query that do DROP FUNCTION or
    DROP PROCEDURE can result in SP not found

This patch fixed all above issues by:
 1) Called thd->clear_error() if the operation succeeded.
 2) Add IF EXISTS to the DROP DATABASE d2 statement
 3) Temporarily disabled testing DROP FUNCTION/PROCEDURE IF EXISTS.

mysql-test/t/rpl_killed_ddl.test:
  DATABASE d2 might not exists, add IF EXITS to the DROP statement
sql/sql_db.cc:
  Called thd->clear_error() if the operation succeeded
2009-12-09 14:13:56 +08:00
Georgi Kodinov
bd308d1256 Bug #42760: Select doesn't return desired results when we have null values
Part 2 : 
There was a special optimization on the ref access method for 
ORDER BY ... DESC that was set without actually looking on the type of the 
selected index for ORDER BY.
Fixed the SELECT ... ORDER BY .. DESC (it uses a different code path compared
to the ASC that has been fixed with the previous fix).
2009-12-07 16:38:56 +02:00
Luis Soares
3a733bb4d8 Automerge bzr bundle in bug report into local mysql-5.1-bugteam latest. 2009-12-07 00:28:14 +00:00
Luis Soares
7948403b05 Automerge bzr bundle from bug report.
Removed rpl_cross_version from experimental list.
2009-12-06 23:36:07 +00:00
Luis Soares
a437804ab0 automerge: mysql-5.1-bugteam bug branch --> mysql-5.1-bugteam latest 2009-12-06 23:14:45 +00:00
Luis Soares
c75712caa8 BUG#49119: Master crashes when executing 'REVOKE ... ON
{PROCEDURE|FUNCTION} FROM ...'

The master would hit an assertion when binary log was
active. This was due to the fact that the thread's diagnostics
area was being cleared before writing to the binlog,
independently of mysql_routine_grant returning an error or
not. When mysql_routine_grant was to return an error, the return
value and the diagnostics area contents would
mismatch. Consequently, neither my_ok would be called nor an
error would be signaled in the diagnostics area, eventually
triggering the assertion in net_end_statement.

We fix this by not clearing the diagnostics area at binlogging
time.
2009-12-06 23:12:11 +00:00
Staale Smedseng
63ff2b4c2e Bug #47391 no stack trace printed to error log on
solaris after a crash
      
This patch adds a Solaris-specific version of
print_stacktrace() which uses printstack(2), available on all
Solaris versions since Solaris 9. (While Solaris 11 adds
support for the glibc functions backtrace_*() as of
PSARC/2007/162, printstack() is used for consistency over all
Solaris versions.)

The symbol names are mangled, so use of c++filt may be
required as described in the MySQL documentation.


sql/stacktrace.c:
  Added Solaris-specific print_stacktrace().
2009-12-06 18:11:37 +01:00
Luis Soares
595719280e BUG#49479: Slave stops with syntax error: LOAD DATA event without
escaped field names

When in mixed or statement mode, the master logs LOAD DATA
queries by resorting to an Execute_load_query_log_event. This
event does not contain the original query, but a rewritten
version of it, which includes the table field names. However, the
rewrite does not escape the field names. If these names match a
reserved keyword, then the slave will stop with a syntax error
when executing the event.

We fix this by escaping the fields names as it happens already
for the table name.

mysql-test/extra/rpl_tests/rpl_loaddata.test:
  Added test case for the reported bug.
mysql-test/r/mysqlbinlog.result:
  Changed result to support escaped field name.
mysql-test/suite/binlog/r/binlog_killed_simulate.result:
  Changed result to support escaped field name.
mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result:
  Changed result to support escaped field name.
mysql-test/suite/binlog/r/binlog_stm_blackhole.result:
  Changed result to support escaped field name.
mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result:
  Changed result to support escaped field name.
mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result:
  Changed result to support escaped field name.
mysql-test/suite/rpl/r/rpl_loaddata.result:
  Added result for new test. 
  Changed show slave status positions which are now different because of
  extra escape character in field names.
mysql-test/suite/rpl/r/rpl_loaddata_fatal.result:
  Changed show slave status positions which are now different because of
  extra escape character.
mysql-test/suite/rpl/r/rpl_loaddata_map.result:
  Changed result to support escaped field name.
mysql-test/suite/rpl/r/rpl_stm_log.result:
  Changed result to support escaped field name.
mysql-test/t/mysqlbinlog.test:
  Changed positions which is now different because of extra escape 
  character in field names.
sql/sql_load.cc:
  Appended escape characters before and after field names.
2009-12-06 01:11:32 +00:00
Ramil Kalimullin
f5b51bc1e2 Fix for bug#49199: Optimizer handles incorrectly:
field='const1' AND field='const2' in some cases

Building multiple equality predicates containing
a constant which is compared as a datetime (with a field)
we should take this fact into account and compare the 
constant with another possible constatns as datetimes 
as well.

E.g. for the
SELECT ... WHERE a='2001-01-01' AND a='2001-01-01 00:00:00'
we should compare '2001-01-01' with '2001-01-01 00:00:00' as
datetimes but not as strings.


mysql-test/r/select.result:
  Fix for bug#49199: Optimizer handles incorrectly: 
  field='const1' AND field='const2' in some cases
    - test result.
mysql-test/t/select.test:
  Fix for bug#49199: Optimizer handles incorrectly: 
  field='const1' AND field='const2' in some cases
    - test case.
sql/item_cmpfunc.cc:
  Fix for bug#49199: Optimizer handles incorrectly: 
  field='const1' AND field='const2' in some cases
    - adding a constant to Item_equal compare it as
  a datetime value with stored one if there's a 
  date[time] field in a equality predicate.
sql/item_cmpfunc.h:
  Fix for bug#49199: Optimizer handles incorrectly: 
  field='const1' AND field='const2' in some cases
    - adding a constant to Item_equal compare it as
  a datetime value with stored one if there's a 
  date[time] field in a equality predicate.
sql/sql_select.cc:
  Fix for bug#49199: Optimizer handles incorrectly: 
  field='const1' AND field='const2' in some cases
    - adding a constant to Item_equal compare it as
  a datetime value with stored one if there's a 
  date[time] field in a equality predicate.
2009-12-04 21:58:40 +04:00
Davi Arnaut
e53ecf2dc2 Bug#49141: Encode function is significantly slower in 5.1 compared to 5.0
The problem was that the multiple evaluations of a ENCODE or
DECODE function within a single statement caused the random
generator to be reinitialized at each evaluation, even though
the parameters were constants.

The solution is to initialize the random generator only once
if the password (seed) parameter is constant.

This patch borrows code and ideas from Georgi Kodinov's patch.

mysql-test/r/func_str.result:
  Add test case result.
mysql-test/r/ps.result:
  Add test case result.
mysql-test/t/func_str.test:
  Add test case for Bug#49141
mysql-test/t/ps.test:
  Add test case for Bug#49141
sql/item_strfunc.cc:
  Move seed generation code to a separate method.
  Seed only once if the password (seed) argument
  is constant.
  Remove duplicated code and use a transform method
  to apply encoding or decoding.
sql/item_strfunc.h:
  Add parameter to signal whether the PRNG is already seeded.
  Introduce transform method.
  Combine val_str methods.
sql/sql_crypt.cc:
  Remove method.
sql/sql_crypt.h:
  Seed is supplied as two long integers.
2009-12-04 13:36:58 -02:00
Alfranio Correia
a4c50983f4 BUG#45292 orphan binary log created when starting server twice
This patch fixes three bugs as follows. First, aborting the server while purging
binary logs might generate orphan files due to how the purge operation was
implemented:

          (purge routine - sql/log.cc - MYSQL_BIN_LOG::purge_logs)

      1 - register the files to be removed in a temporary buffer.
      2 - update the log-bin.index.
      3 - flush the log-bin.index.
      4 - erase the files whose names where register in the temporary buffer
      in step 1.

Thus a failure while  executing step 4 would generate an orphan file. Second,
a similar issue might happen while creating a new binary as follows:

          (create routine - sql/log.cc - MYSQL_BIN_LOG::open)

      1 - open the new log-bin.
      2 - update the log-bin.index.

Thus a failure while executing step 1 would generate an orphan file.

To fix these issues, we record the files to be purged or created before really
removing or adding them. So if a failure happens such records can be used to
automatically remove dangling files. The new steps might be outlined as follows:

          (purge routine - sql/log.cc - MYSQL_BIN_LOG::purge_logs)

      1 - register the files to be removed in the log-bin.~rec~ placed in
      the data directory.
      2 - update the log-bin.index.
      3 - flush the log-bin.index.
      4 - delete the log-bin.~rec~.

          (create routine - sql/log.cc - MYSQL_BIN_LOG::open)

      1 - register the file to be created in the log-bin.~rec~
      placed in the data directory.
      2 - open the new log-bin.
      3 - update the log-bin.index.
      4 - delete the log-bin.~rec~.

          (recovery routine - sql/log.cc - MYSQL_BIN_LOG::open_index_file)

      1 - open the log-bin.index.
      2 - open the log-bin.~rec~.
      3 - for each file in log-bin.~rec~.
        3.1 Check if the file is in the log-bin.index and if so ignore it.
        3.2 Otherwise, delete it.

The third issue can be described as follows. The purge operation was allowing
to remove a file in use thus leading to the loss of data and possible
inconsistencies between the master and slave. Roughly, the routine was only
taking into account the dump threads and so if a slave was not connect the
file might be delete even though it was in use.
2009-12-04 14:40:42 +00:00
Georgi Kodinov
9091535c5f Bug #48985: show create table crashes if previous access to the table was killed
When checking for an error after removing the special view error handler the code
was not taking into account that open_tables() may fail because of the current
statement being killed. 
Added a check for thd->killed.
Added a client program to test it.
2009-12-03 14:07:46 +02:00
Alexander Barkov
7622134333 Bug#44131 Binary-mode "order by" returns records in incorrect order for UTF-8 strings
Problem: Item_char_typecast reported wrong max_length when
casting to BINARY, which lead, in particular, in wrong
"ORDER BY BINARY(char_column)" results.

Fix: making Item_char_typecast report correct max_length.

  @ mysql-test/r/ctype_utf16.result
    Fixing old incorrect test result.
  @ mysql-test/r/ctype_utf32.result
    Fixing old incorrect test result.
  @ mysql-test/r/ctype_utf8.result
    Adding new test
  @ mysql-test/t/ctype_utf8.test
    Adding new test
  @ sql/item_timefunc.cc
    Making Item_char_typecast report correct max_length
    when cast is done to BINARY.
2009-12-03 13:22:34 +04:00
Evgeny Potemkin
1eda9dc777 Auto-merged. 2009-12-02 16:49:21 +03:00
Evgeny Potemkin
d969cbc578 Auto-merged fix for the bug#48508. 2009-12-02 16:47:12 +03:00
Alexander Barkov
d7abca9ac3 Bug#48766 SHOW CREATE FUNCTION returns extra data in return clause
Problem: SHOW CREATE FUNCTION and SELECT DTD_IDENTIFIER FROM I_S.ROUTINES
returned wrong values in case of ENUM return data type and UCS2
character set.

Fix: the string to collect returned data type was incorrectly set to
"binary" character set, therefore UCS2 values where returned with
extra '\0' characters.
Setting string character set to creation_ctx->get_client_cs()
in sp_find_routine(), and to system_charset_info in sp_create_routine
fixes the problem.

Adding tests:
- the original test with Latin letters
- an extra test with non-Latin letters
2009-12-02 15:17:08 +04:00
Evgeny Potemkin
7853f553be Bug#48508: Crash on prepared statement re-execution.
Actually there is two different bugs.
The first one caused crash on queries with WHERE condition over views
containing WHERE condition. A wrong check for prepared statement phase led
to items for view fields being allocated in the execution memory and freed
at the end of execution. Thus the optimized WHERE condition refers to
unallocated memory on the second execution and server crashed.
The second one caused by the Item_cond::compile function not saving changes
it made to the item tree. Thus on the next execution changes weren't
reverted and server crashed on dereferencing of unallocated space.

The new helper function called is_stmt_prepare_or_first_stmt_execute
is added to the Query_arena class.
The find_field_in_view function now uses
is_stmt_prepare_or_first_stmt_execute() to check whether
newly created view items should be freed at the end of the query execution.
The Item_cond::compile function now saves changes it makes to item tree.

mysql-test/r/ps.result:
  Added a test case for the bug#48508.
mysql-test/t/ps.test:
  Added a test case for the bug#48508.
sql/item_cmpfunc.cc:
  Bug#48508: Crash on prepared statement re-execution.
  The Item_cond::compile function now saves changes it makes to item tree.
sql/sql_base.cc:
  Bug#48508: Crash on prepared statement re-execution.
  The find_field_in_view function now uses
  is_stmt_prepare_or_first_stmt_execute() to check whether
  newly created view items should be freed at the end of the query execution.
sql/sql_class.h:
  Bug#48508: Crash on prepared statement re-execution.
  The Query_arena::is_stmt_prepare_or_first_sp_execute function now correctly
  do its check.
2009-12-01 21:28:45 +03:00
Gleb Shchepa
60b76cd729 Bug #38883 (reopened): thd_security_context is not thread safe, crashes?
manual merge 5.0-->5.1, updating InnoDB plugin.
2009-12-01 14:38:40 +04:00
Gleb Shchepa
ee136e3fa5 Bug #38883 (reopened): thd_security_context is not thread safe, crashes?
The bug 38816 changed the lock that protects THD::query from
LOCK_thread_count to LOCK_thd_data, but didn't update the associated
InnoDB functions.

1. The innobase_mysql_prepare_print_arbitrary_thd and the
innobase_mysql_end_print_arbitrary_thd InnoDB functions have been
removed, since now we have a per-thread mutex: now we don't need to wrap
several inter-thread access tries to THD::query with a single global
LOCK_thread_count lock, so we can simplify the code.

2. The innobase_mysql_print_thd function has been modified to lock
LOCK_thd_data in direct way.
2009-12-01 14:24:44 +04:00
Georgi Kodinov
248a74eaa1 Revert of the push of bug #20837 due to failing regression tests. 2009-12-01 11:19:51 +02:00
Magne Mahre
732e5a2634 Bug #20837 Apparent change of isolation level during transaction
SET TRANSACTION ISOLATION LEVEL is used to temporarily set
the trans.iso.level for the next transaction.  After the
transaction, the iso.level is (re-)set to value of the 
session variable 'tx_isolation'.

The bug is caused by setting the thd->variables.tx_isolation 
field to the value of the session variable upon each
statement commit.  It should only be set at the end of the
full transaction.

The fix has been to remove the setting of the variable in
ha_autocommit_or_rollback if we're in a transaction, as it 
will be correctly set in  either ha_rollback or 
ha_commit_one_phase.  

If, on the other hand, we're in  autocommit mode, tx_isolation 
will be explicitly set here.



mysql-test/t/innodb_mysql.test:
  "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED" sets
  the trans.isolation for the next transaction.  We test
  that @@tx_isolation keeps this value during the transaction,
  and is only reset back to the session value at the end
  of the transaction.
2009-11-30 12:30:28 +01:00
unknown
b9f9fe2e1a Bug #43913 rpl_cross_version can't pass on conflicts complainig clash with --slave-load-tm
The 'slave_patternload_file' is assigned to the real path of the load data file 
when initializing the object of Relay_log_info. But the path of the load data
file is not formatted to real path when executing event from relay log. So the 
error will be encountered if the path of the load data file is a symbolic link.

Actually the global 'opt_secure_file_priv' is not formatted to real path when 
loading data from file. So the same thing will happen too.

      
To fix these errors, the path of the load data file should be formatted to 
real path when executing event from relay log. And the 'opt_secure_file_priv' 
should be formatted to real path when loading data infile.


mysql-test/suite/rpl/r/rpl_loaddata_symlink.result:
  Test result for bug#43913.
mysql-test/suite/rpl/t/rpl_loaddata_symlink-master.sh:
  Added the test file to create a link from $MYSQLTEST_VARDIR/std_data 
  to $MYSQLTEST_VARDIR/std_data_master_link
mysql-test/suite/rpl/t/rpl_loaddata_symlink-slave.sh:
  Added the test file to create a link from $MYSQLTEST_VARDIR/std_data 
  to $MYSQLTEST_VARDIR/std_data_slave_link
mysql-test/suite/rpl/t/rpl_loaddata_symlink.test:
  Added the test file to verify if loading data infile will work fine 
  if the path of the load data file is a symbolic link.
sql/rpl_rli.cc:
  Added call 'my_realpath' function for avoiding sometimes the 'fn_format' 
  function can't format real path rightly.
2009-11-28 12:43:16 +08:00
Alfranio Correia
95e420c636 BUG#48506 crash in CREATE TABLE IF NOT EXISTS <existing_view> LIKE
<tmp_tbl> with RBL

When binlogging the statement, the server always handle the existing
object as a table, even though it is a view. However a view is
handled differently in other parts of the code thus leading the
statement to crash in RBL if the view exists.

This happens because the underlying tables for the view are not opened
when we try to call store_create_info() on the view in order to build
a CREATE TABLE statement.

This patch will only address the crash problem, other binlogging
problems related to CREATE TABLE IF NOT EXISTS LIKE when the existing
object is a view will be solved by BUG 47442.
2009-11-27 13:34:39 +00:00
Georgi Kodinov
c431088d03 merge 2009-11-27 12:32:15 +02:00
Georgi Kodinov
2ac344ecf6 Bug #48872 : Privileges for stored functions ignored if function name
is mixed case

Transcode the procedure name to lowercase when searching for it in the 
hash. This is the missing part of the fix for bug #41049.
2009-11-27 11:59:44 +02:00
Martin Hansson
4afa24086f Merge of fix for Bug#48459 2009-11-26 10:41:40 +01:00
Davi Arnaut
8022ff5cf5 Automerge. 2009-11-25 11:09:12 -02:00
Martin Hansson
14f2eb1244 Bug#48459: valgrind errors with query using 'Range checked
for each record'

There was an error in an internal structure in the range
optimizer (SEL_ARG). Bad design causes parts of a data
structure not to be initialized when it is in a certain
state. All client code must check that this state is not
present before trying to access the structure's data. Fixed
by

- Checking the state before trying to access data (in
several places, most of which not covered by test case.)

- Copying the keypart id when cloning SEL_ARGs


mysql-test/r/range.result:
  Bug#48459: Test result.
mysql-test/t/range.test:
  Bug#48459: Test case.
sql/opt_range.cc:
  Bug#48459: Fix + doxygenated count_key_part_usage comment.
2009-11-25 11:02:25 +01:00
Satya B
97d74332c2 Applying InnoDB snapshot 5.0-ss6230, part 2. Fixes BUG#46000
BUG#46000 - using index called GEN_CLUST_INDEX crashes server

Detailed revision comments:

r6180 | jyang | 2009-11-17 10:54:57 +0200 (Tue, 17 Nov 2009) | 7 lines
branches/5.0: Merge/Port fix for bug #46000 from branches/5.1
-r5895 to branches/5.0. Disallow creating index with the
name of "GEN_CLUST_INDEX" which is reserved for the default
system primary index. Minor adjusts on table name screening
format for added tests.
2009-11-25 15:29:25 +05:30
Evgeny Potemkin
c45da99235 Auto-merge. 2009-11-25 12:57:08 +03:00
Evgeny Potemkin
0039944e0c Additional fix for the bug#43668.
Arg_comparator now takes into account that some of
optimizations aren't done in the PREPARE stmt.
2009-11-25 12:52:03 +03:00
Satya B
2bf2e8f9dd Applying InnoDB snapshot 5.0-ss6230, Part 1. Fixes BUG#47777
BUG#47777 - innodb dies with spatial pk: Failing assertion: buf <= original_buf + buf_len

Detailed revision comments:

r6178 | jyang | 2009-11-17 08:52:11 +0200 (Tue, 17 Nov 2009) | 6 lines
branches/5.0: Merge fix for bug #47777 from branches/5.1 -r6045
to bracnches/5.0. Treat the Geometry data same as Binary BLOB
in ha_innobase::store_key_val_for_row(), since the Geometry
data is stored as Binary BLOB in Innodb.
2009-11-25 15:08:52 +05:30
Luis Soares
dfe177aa22 BUG#48340: rpl_cross_version: Found warnings/errors in server log file!
Valgrind reports a conditional jump that depends on uninitialized
data while doing a LOAD DATA and for this test case only. This
test case, tests that loading data from a 4.0 or 4.1 instance
into a 5.1 instance is working. As such it handles old binary log
with a different set of events than currently 5.1 codebase uses.
See the following reference for details:

http://forge.mysql.com/wiki/MySQL_Internals_Binary_Log#LOAD_DATA_INFILE_Events

Problem:
 
 The server is handling an Execute_load_log_event, which results
 in reading a Load_log_event from the binary log and applying
 it. When applying the Load_log_event, some variable setup is
 done and then mysql_load is called. Late in mysql_load
 execution, if not in row mode logging, the event is
 binlogged write_execute_load_query_log_event.

 In write_execute_load_query_log_event, thd->lex->local_file is
 inspected. The problem is that it has not been set before in the
 execution stack. This causes valgrind to report the warning.

Fix: 
  
 We fix this by initializing thd->lex->local_file to be the same
 as the value of Load_log_event::local_fname, when lex_start is
 called inside Load_log_event::do_apply_event.
2009-11-24 20:04:02 +00:00
Tatiana A. Nurnberg
9ae245009c auto-merge 2009-11-24 10:22:22 -08:00
Evgeny Potemkin
8af680218e Auto-merge. 2009-11-24 18:30:21 +03:00
Evgeny Potemkin
9f638f535e Manual merge of the fix for bug#43668. 2009-11-24 18:26:13 +03:00
Alexey Kopytov
908323304e Automerge. 2009-11-23 13:07:18 +03:00
Alexey Kopytov
6780169613 Automerge. 2009-11-23 13:05:35 +03:00
Alexey Kopytov
38ed9324be Automerge. 2009-11-23 13:04:17 +03:00
unknown
a2ed682967 Bug #48350 truncate temporary table crashes replication
In RBR, All statements operating on temporary tables should not be binlogged.
Despite this fact, after executing 'TRUNCATE... ' on a temporary table, 
the command is still logged, even if in row-based mode. Consequently, this raises
problems in the slave as the table may not exist, resulting in an
execution failure. Ultimately, this causes the slave to report
an error and abort.

After this patch, 'TRUNCATE ...' statement on a temporary table will not be
binlogged in RBR.
2009-11-22 13:10:33 +08:00
Alfranio Correia
897d87f63a merge 5.1-bugteam (local) --> 5.1-bugteam 2009-11-21 13:02:18 +00:00
Davi Arnaut
c70a9fa1e3 Bug#41726: upgrade from 5.0 to 5.1.30 crashes if you didn't run mysql_upgrade
The problem is that the server could crash when attempting
to access a non-conformant proc system table. One such case
was a crash when invoking stored procedure related statements
on a 5.1 server with a proc system table in the 5.0 format.

The solution is to validate the proc system table format
before attempts to access it are made. If the table is not
in the format that the server expects, a message is written
to the error log and the statement that caused the table to
be accessed fails.

mysql-test/r/sp-destruct.result:
  Add test case result for Bug#41726
mysql-test/t/sp-destruct.test:
  Add test case for Bug#41726
sql/event_db_repository.cc:
  Update code to use new structures.
sql/sp.cc:
  Describe the proc table format and use it to validate when
  opening a instance of the table.
  Add a check to insure that a error message is written to
  the error log only once.
sql/sql_acl.cc:
  Remove unused variable and use new structure.
sql/sql_acl.h:
  Export field definition.
sql/table.cc:
  Accept the field count and definition in a single structure.
sql/table.h:
  Combine the field count and definition in a single structure.
  Transform function into a class in order to support different
  ways of reporting a error.
  Add a pointer cache to TABLE_SHARE.
2009-11-21 09:18:21 -02:00
Kristofer Pettersson
f9af124e7d merge 2009-11-20 21:56:43 +01:00
Kristofer Pettersson
3596983d7a automerge 2009-11-20 16:24:48 +01:00
Kristofer Pettersson
0a68603058 Bug#45613 handle failures from my_hash_insert
Not all my_hash_insert() calls are checked for return value.

This patch adds appropriate checks and failure responses
where needed.


mysys/hash.c:
  * Debug hook for testing failures in my_hash_insert()
2009-11-20 16:18:01 +01:00
Vladislav Vaintroub
ff3b424565 merge 2009-11-20 14:20:01 +01:00
Kristofer Pettersson
5181325c27 automerge 2009-11-20 13:57:31 +01:00
Kristofer Pettersson
41085809c3 Bug#39253 Large query cache still freezes server after fix for bug #21074
This patch introduce a limit on the time the query cache can
block with a lock on SELECTs.

Other operations which causes a change in the table
data will still be blocked.


sql/sql_cache.cc:
  * Introduced a timeout value for the qc lock when entering send_result_to_client()
  and store_query() methods.
sql/sql_cache.h:
  * New signature for Query_cache::try_lock()
2009-11-20 13:49:06 +01:00
Vladislav Vaintroub
26a37b36ef Bug#47571 : idle named pipe connection is unkillable
implement Davi's review suggestions (post-push fixes)


include/violite.h:
  Use official abbreviation for milliseconds (ms)
sql/mysqld.cc:
  Fix formatting
  Add error handling for the case of CreateEvent error
vio/vio.c:
  Use official abbreviation for milliseconds(ms)
  Remove superfluous memset
  Fix formatting
vio/viosocket.c:
  Use official abbreviation for milliseconds (ms)
  Use size_t  datatype instead of int in pipe_complete_io
2009-11-20 13:09:50 +01:00
Georgi Kodinov
a21cd97c35 Bug #45261 : Crash, stored procedure + decimal
Bug #48370  Absolutely wrong calculations with GROUP BY and
  decimal fields when using IF

Added the test cases in the above two bugs for regression
testing.
Added additional tests that demonstrate a incomplete fix.
Added a new factory method for Field_new_decimal to 
create a field from an (decimal returning) Item.
In the new method made sure that all the precision and 
length variables are capped in a proper way. 
This is required because Item's can have larger precision
than the decimal fields and thus need to be capped when
creating a field based on an Item type.
Fixed the wrong typecast to Item_decimal.
2009-11-20 12:10:47 +02:00
Christopher Powers
c74609b126 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.
2009-11-19 16:49:13 -06:00
Georgi Kodinov
405c9310cf Bug #48665: sql-bench's insert test fails due to wrong result
When merging ranges during calculation of the result of OR
to two range sets the current range may be obsoleted by the 
resulting merged range.
The first overlapping range can be obsoleted as well.

Fixed by moving the pointer to the first overlapping range to the
pointer of the resulting union range.
Added few comments at key places in key_or().
2009-11-19 18:26:19 +02:00
Sven Sandberg
2f78abd21b BUG#47995: Mark system functions as unsafe
Problem: Some system functions that could return different values on
master and slave were not marked unsafe. In particular:
 GET_LOCK
 IS_FREE_LOCK
 IS_USED_LOCK
 MASTER_POS_WAIT
 RELEASE_LOCK
 SLEEP
 SYSDATE
 VERSION
Fix: Mark these functions unsafe.


mysql-test/extra/rpl_tests/rpl_stm_000001.test:
  - The test does not work in mixed mode any more, since it tries to
    simulate an error in the sql thread in a query that uses get_lock.
    Since get_lock now causes the query to be logged in row format,
    the error didn't happen. Hence, we now force statement mode.
  - Warnings must be disabled when the unsafe query is issued.
  - Replaced some save_master_pos+connection slave+sync_with_master
    by sync_slave_with_master.
mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result:
  updated result file
mysql-test/suite/binlog/r/binlog_stm_row.result:
  updated result file
mysql-test/suite/binlog/r/binlog_unsafe.result:
  updated result file
mysql-test/suite/binlog/t/binlog_killed.test:
  binlog_killed only works in statement format now, since
  it switches to row mode in mixed mode.
mysql-test/suite/binlog/t/binlog_stm_mix_innodb_myisam.test:
  suppress warnings for unsafe statements
mysql-test/suite/binlog/t/binlog_stm_row.test:
  - Suppress warnings in test that causes warnings.
  - The test sets binlog format explicitly, so no need to execute it
    twice.
mysql-test/suite/binlog/t/binlog_unsafe.test:
  Added test for all unsafe system functions. This test also includes
  system functions that were unsafe prior to BUG#47995.
mysql-test/suite/rpl/r/rpl_err_ignoredtable.result:
  updated result file
mysql-test/suite/rpl/r/rpl_get_lock.result:
  updated result file
mysql-test/suite/rpl/r/rpl_nondeterministic_functions.result:
  new result file
mysql-test/suite/rpl/r/rpl_stm_000001.result:
  updated result file
mysql-test/suite/rpl/r/rpl_trigger.result:
  updated result file
mysql-test/suite/rpl/t/rpl_err_ignoredtable.test:
  - suppress warnings for unsafe statement
  - replaced save_master_pos+connection slave+sync_with_master
    with sync_slave_with_master
mysql-test/suite/rpl/t/rpl_get_lock.test:
  update test case that causes new warnings
mysql-test/suite/rpl/t/rpl_nondeterministic_functions.test:
  Added new test case for nondeterministic functions.
mysql-test/suite/rpl/t/rpl_trigger.test:
  update test case that causes new warnings
sql/item_create.cc:
  Marked some system functions unsafe.
sql/item_strfunc.cc:
  Clarified comment related to this bug.
sql/sql_yacc.yy:
  Marked sysdate unsafe.
2009-11-18 15:50:31 +01:00
Mattias Jonsson
f6ec131ff9 merge 2009-11-18 11:21:26 +01:00
Magne Mahre
58f4345957 merge 2009-11-18 10:45:32 +01:00
Magne Mahre
3987c7ac4b Bug #46425 crash in Diagnostics_area::set_ok_status , empty statement,
DELETE IGNORE

The ER_CANT_UPDATE_USED_TABLE_IN_SF_OR_TRG error was set in the
diagnostics area when it happened, but the DELETE cleanup code
never checked for a non-fatal error condition, thus trying to
set diag.area to "ok".  This triggered an assert checking that
the diag.area was empty.

The fix was to test if there existed a non-fatal error condition
(thd->is_error() before ok'ing the operation.
2009-11-18 10:32:03 +01:00
Jon Olav Hauglid
41ba429286 Bug #47682 strange behaviour of INSERT DELAYED
The problem was a "self-deadlock" if the connection issuing INSERT DELAYED
had both the global read lock (FLUSH TABLES WITH READ LOCK) and LOCK TABLES
mode active. The table being inserted into had to be different from the 
table(s) locked by LOCK TABLES.

For INSERT DELAYED, the connection thread waits until the handler thread has
opened and locked its table before returning. But since the global read lock
was active, the handler thread would be unable to lock and would wait for the
global read lock to go away.

So the handler thread would be waiting for the connection thread to release
the global read lock while the connection thread was waiting for the handler
thread to lock the table. This gave a "self-deadlock" (same connection,
different threads).

The deadlock would only happen if we also had LOCK TABLES mode since the
INSERT otherwise will try to get protection against global read lock before
starting the handler thread. It will then notice that the global read lock
is owned by the same connection and report ER_CANT_UPDATE_WITH_READLOCK.

This patch removes the deadlock by reporting ER_CANT_UPDATE_WITH_READLOCK
also if we are inside LOCK TABLES mode.

Test case added to delayed.test.
2009-11-18 10:02:21 +01:00
Mattias Jonsson
3faaf33333 merge 2009-11-17 22:51:49 +01:00
Mattias Jonsson
7a6ab645ab merge 2009-11-17 22:48:28 +01:00
Mattias Jonsson
98fd304278 backport of bug#45904 from mysql-pe to 5.1
sql/sql_partition.cc:
  Bug#45904 Used list_of_part_fields instead of list_of_subpart_fields to discover if KEY subpartitioning => caused failure when charset=utf8 even for subpartitioning by key, would also allow for subpartitioning by hash with utf8 erroneously
2009-11-17 22:47:34 +01:00
Mattias Jonsson
8734933400 Bug#48846: Too much time spent in ha_partition::records_in_range if not able to prune
Problem was that ha_partition::records_in_range called
records_in_range for all non pruned partitions, even if
an estimate should be given.

Solution is to only use 1/3 of the partitions (up to 10) for
records_in_range and estimate the total from this subset.
(And continue until a non zero return value from the called
partitions records_in_range is given, since 0 means no rows
will match.)

sql/ha_partition.cc:
  Bug#48846: Too much time spent in ha_partition::records_in_range if not able to prune
  
  estimate_rows_upper_bound and records_in_range are very similar
  (the only difference is the function and its parameters to use)
  so I created a common function for this.
  
  Since these calls from the optimizer are only estimates, it is
  not neccesary to call them for every partition, it can use
  a much smaller subset of the used partitions instead,
  which improves performance for selects.
sql/ha_partition.h:
  Bug#48846: Too much time spent in ha_partition::records_in_range if not able to prune
  
  Added two private functions to help some
  optimizer calls.
2009-11-17 20:02:16 +01:00
Mattias Jonsson
e6d02a127e merge 2009-11-17 16:24:46 +01:00
Alexey Kopytov
8cfa50e677 Bug #48472: Loose index scan inappropriately chosen for some
WHERE conditions 
 
check_group_min_max() checks if the loose index scan 
optimization is applicable for a given WHERE condition, that is 
if the MIN/MAX attribute participates only in range predicates 
comparing the corresponding field with constants. 
 
The problem was that it considered the whole predicate suitable 
for the loose index scan optimization as soon as it encountered 
a constant as a predicate argument. This is obviously wrong for 
cases when a constant is the first argument of a predicate 
which does not satisfy the above condition. 
 
Fixed check_group_min_max() so that all arguments of the input 
predicate are considered to decide if it passes the test, even 
though a constant has already been encountered.

mysql-test/r/group_min_max.result:
  Added a test case for bug #48472.
mysql-test/t/group_min_max.test:
  Added a test case for bug #48472.
sql/opt_range.cc:
  Fixed check_group_min_max() so that all arguments of the input 
  predicate are considered to decide if it passes the test, even 
  though a constant has already been encountered.
2009-11-17 17:07:14 +03:00
Evgeny Potemkin
bc43bff7ed Bug#43668: Wrong comparison and MIN/MAX for YEAR(2)
MySQL manual describes values of the YEAR(2) field type as follows:
values 00 - 69 mean 2000 - 2069 years and values 70 - 99 mean 1970 - 1999
years. MIN/MAX and comparison functions was comparing them as int values
thus producing wrong result.

Now the Arg_comparator class is extended with compare_year function which
performs correct comparison of the YEAR type.
The Item_sum_hybrid class now uses Item_cache and Arg_comparator objects to
correctly calculate its value.
To allow Arg_comparator to use func_name() function for Item_func and Item_sum
objects the func_name declaration is moved to the Item_result_field class.
A helper function is_owner_equal_func is added to the Arg_comparator class.
It checks whether the Arg_comparator object owner is the <=> function or not.
A helper function setup is added to the Item_sum_hybrid class. It sets up
cache item and comparator.

mysql-test/r/func_group.result:
  Added a test case for the bug#43668.
mysql-test/t/func_group.test:
  Added a test case for the bug#43668.
sql/item.cc:
  Bug#43668: Wrong comparison and MIN/MAX for YEAR(2)
  Now Item_cache_int returns the type of cached item.
sql/item.h:
  Bug#43668: Wrong comparison and MIN/MAX for YEAR(2)
  To allow Arg_comparator to use func_name() function for Item_func and Item_sum
  objects the func_name declaration is moved to the Item_result_field class.
sql/item_cmpfunc.cc:
  Bug#43668: Wrong comparison and MIN/MAX for YEAR(2)
  The Arg_comparator class is extended with compare_year function which
  performs correct comparison of the YEAR type.
sql/item_cmpfunc.h:
  Bug#43668: Wrong comparison and MIN/MAX for YEAR(2)
  The year_as_datetime variable is added to the Arg_comparator class.
  It's set to TRUE when YEAR value should be converted to the
  YYYY-00-00 00:00:00 format for correct YEAR-DATETIME comparison.
sql/item_geofunc.cc:
  Bug#43668: Wrong comparison and MIN/MAX for YEAR(2)
  Item_func_spatial_rel::val_int chenged to use Arg_comparator's string
  buffers.
sql/item_subselect.h:
  Bug#43668: Wrong comparison and MIN/MAX for YEAR(2)
  Added an implementation of the virtual func_name function.
sql/item_sum.cc:
  Bug#43668: Wrong comparison and MIN/MAX for YEAR(2)
  The Item_sum_hybrid class now uses Item_cache and Arg_comparator objects to
  correctly calculate its value.
  A helper function setup is added to the Item_sum_hybrid class. It sets up
  cache item and comparator.
sql/item_sum.h:
  Bug#43668: Wrong comparison and MIN/MAX for YEAR(2)
  The Item_sum_hybrid class now uses Item_cache and Arg_comparator objects to
  correctly calculate its value.
  Added an implementation of the virtual func_name function.
2009-11-17 17:06:46 +03:00
Jorgen Loland
a120e969a8 Bug#48052: Valgrind warning - uninitialized value in
init_read_record() - (records.cc:274)
      
Item_cond::used_tables_cache was accessed in
records.cc#init_read_record() without being initialized. It had
not been initialized because it was wrongly assumed that the
Item's variables would not be accessed, and hence
quick_fix_field() was used instead of fix_fields() to save a few
CPU cycles at creation time.

The fix is to properly initilize the Item by replacing
quick_fix_field() with fix_fields().


mysql-test/r/select.result:
  Add test for BUG#48052
mysql-test/t/select.test:
  Add test for BUG#48052
sql/sql_select.cc:
  Properly initialize Item_cond_and by calling fix_fields (instead of quick_fix_field) when the Item that "ANDs" WHERE clause conditions with HAVING clause conditions is created.
2009-11-13 12:22:39 +01:00
Luis Soares
9c23a442b2 BUG#48738: Backport patch for Bug 34582 to 5.0 codebase.
From BUG 34582 commit message:

Issuing 'FLUSH LOGS' does not close and reopen indexfile.
Instead a SEEK_SET is performed.
            
This patch makes index file to be closed and reopened whenever a
rotation happens (FLUSH LOGS is issued or binary log exceeds 
maximum configured size).
2009-11-13 10:30:56 +00:00
Davi Arnaut
356b3df743 Bug#47627 SET @@{global.session}.local_variable in stored routine causes crash
This patch borrows ideas, text and code from Kristofer
Pettersson's patch.

An assignment of a system variable sharing the same base
name as a declared stored procedure variable in the same
context could lead to a crash.

The reason was that during the parsing of the syntactic
rule 'option_value' an uninitialized set_var object was
pushed to the parameter stack of the SET statement. The
parent rule 'option_type_value' interpreted the existence
of variables on the parameter stack as an assignment and
wrapped it in a sp_instr_set object.

As the procedure later was executed an attempt was made
to run the method 'check()' on an uninitialized member
object (NULL value) belonging to the previously created
but uninitialized object.

This patch refactors the 'internal_variable_name' rule and
copies the semantic analysis part to the depending parent
rule: 'option_value'. This makes it possible to account
for any prefixes affecting the interpretation of the
internal_variable_name.

mysql-test/r/sp.result:
  Add test case result.
mysql-test/t/sp.test:
  Add test case for bug.
sql/sql_yacc.yy:
  - Reduce churn in rule sys_option_value by moving to
    specialized functions.
  - Comment the the lookup in the rule internel_variable_name
    is a best effort operation.
  - Lookup for a system variable in the option_value if one was
    not found (the variable could have been shadowed)
2009-11-12 23:03:26 -02:00
Alexey Kopytov
cf872354a8 Automerge. 2009-11-12 20:14:07 +03:00
Alexey Kopytov
b31c544eec Automerge. 2009-11-12 20:13:08 +03:00
Alexey Kopytov
fb2e17903f Fixed a gcc warning introduced by the patch for bug #48475. 2009-11-12 20:11:33 +03:00
Andrei Elkin
f1abd015dc Bug #47210 first execution of "start slave until" stops too early
Until-pos guarding did not distiguish the master originated events from ones that the slave 
can introduce to the relay log e.g Rotate to the next relay log at slave restarting.
The local Rotate's coordinate are incomparable with the Until-master-pos.
That led to the unexpectable stop this bug describes.

Fixed with to avoid Until-master-pos comparison for a local slave's event.
Notice that if --replicate-same-server is true such event is treated as coming from
the master side.


mysql-test/r/rpl_until.result:
  results changed.
mysql-test/t/rpl_until.test:
  regression test for bug#47210 is added.
sql/slave.cc:
  st_relay_log_info::is_until_satisfied() is augmented with avoidance of 
  Until-master-pos comparison for a local slave's event.
  if --replicate-same-server is true such event is treated as coming from
  the master side.
sql/slave.h:
  signature of is_until_satisfied() changed to supply THD and Event to the routine.
2009-11-12 17:10:19 +02:00
Luis Soares
46ca22b093 BUG#48357: SHOW BINLOG EVENTS: Wrong offset or I/O error
In function log_event.cc:Query_log_event::write, there was a cast that
was triggering undefined behavior. The offending cast is the
following:

  write_str_with_code_and_len((char **)(&start),
                              catalog, catalog_len, Q_CATALOG_NZ_CODE);

This results in calling write_str_with_code_and_len with first
argument pointing to a (char **) while "start" is itself a pointer to
uchar (uchar *). Inside write_str_with_..., the content of start is
then be updated:

  (*dst)+= len;

The instruction above would cause the (*dst) pointer (ie, the "start"
argument, from the caller point of view, and which actually points to
uchar instead of pointing to char) to be updated so that it would
increment catalog_len. However, this seems to break strict-aliasing
rules ultimately causing the increment and assignment to behave
unexpectedly.

We fix this by removing the cast and by making the types match.
2009-11-09 17:36:13 +00:00
Georgi Kodinov
4519d5e4f1 Bug #48458: simple query tries to allocate enormous amount of
memory

The server was doing a bad class typecast causing setting of 
wrong value for the maximum number of items in an internal
structure used in equality propagation.
Fixed by not doing the wrong typecast and asserting the type
of the Item where it should be done.
2009-11-09 16:09:46 +02:00
Georgi Kodinov
ddd90017e7 Bug #42760: Select doesn't return desired results when we have null
values
 
 We should re-set the access method functions when changing the access
 method when switching to another index to avoid sorting.
 
 Fixed by doing a little re-engineering : encapsulating all the function
 assignment into a special function and calling it when flipping the 
 indexes.
2009-11-10 10:21:41 +02:00