Commit graph

25566 commits

Author SHA1 Message Date
Alfranio Correia
25162d0166 BUG#43789 different master/slave table defs cause crash: text/varchar null
vs not null

NOTE: Backporting the patch to next-mr.
                        
The replication was generating corrupted data, warning messages on Valgrind
and aborting on debug mode while replicating a "null" to "not null" field.
Specifically the unpack_row routine, was considering the slave's table
definition and trying to retrieve a field value, where there was nothing to be
retrieved, ignoring the fact that the value was defined as "null" by the master.
                        
To fix the problem, we proceed as follows:
                        
1 - If it is not STRICT sql_mode, implicit default values are used, regardless
if it is multi-row or single-row statement.
                        
2 - However, if it is STRICT mode, then a we do what follows:
                        
2.1 If it is a transactional engine, we do a rollback on the first NULL that is
to be set into a NOT NULL column and return an error.
                        
2.2 If it is a non-transactional engine and it is the first row to be inserted
with multi-row, we also return the error. Otherwise, we proceed with the
execution, use implicit default values and print out warning messages.
                  
Unfortunately, the current patch cannot mimic the behavior showed by the master
for updates on multi-tables and multi-row inserts. This happens because such
statements are unfolded in different row events. For instance, considering the
following updates and strict mode:
                  
(master)
create table t1 (a int);
create table t2 (a int not null);
insert into t1 values (1);
insert into t2 values (2);
update t1, t2 SET t1.a=10, t2.a=NULL;
                  
t1 would have (10) and t2 would have (0) as this would be handled as a
multi-row update. On the other hand, if we had the following updates:
                  
(master)
create table t1 (a int);
create table t2 (a int);
                  
(slave)
create table t1 (a int);
create table t2 (a int not null);
                  
(master)
insert into t1 values (1);
insert into t2 values (2);
update t1, t2 SET t1.a=10, t2.a=NULL;
                  
On the master t1 would have (10) and t2 would have (NULL). On
the slave, t1 would have (10) but the update on t1 would fail.
2009-09-29 15:18:44 +01:00
Alfranio Correia
cc9e25af54 BUG#38173 Field doesn't have a default value with row-based replication
NOTE: Backporting the patch to next-mr.
      
The reason of  the bug was incompatibile with the master side behaviour.
INSERT query on the master is allowed to insert into a table without specifying
values of DEFAULT-less fields if sql_mode is not strict.
            
Fixed with checking sql_mode by the sql thread to decide how to react.
Non-strict sql_mode should allow Write_rows event to complete.
            
todo: warnings can be shown via show slave status, still this is a 
separate rather general issue how to show warnings for the slave threads.
2009-09-29 15:04:21 +01:00
Alfranio Correia
b7f887652b WL#4828 and BUG#45747
NOTE: Backporting the patch to next-mr.

WL#4828 Augment DBUG_ENTER/DBUG_EXIT to crash MySQL in different functions
-------

The assessment of the replication code in the presence of faults is extremely
import to increase reliability. In particular, one needs to know if servers
will either correctly recovery or print out appropriate error messages thus
avoiding unexpected problems in a production environment.

In order to accomplish this, the current patch refactories the debug macros
already provided in the source code and introduces three new macros that
allows to inject faults, specifically crashes, while entering or exiting a
function or method. For instance, to crash a server while returning from
the init_slave function (see module sql/slave.cc), one needs to do what
follows:

1 - Modify the source replacing DBUG_RETURN by DBUG_CRASH_RETURN;

  DBUG_CRASH_RETURN(0);

2 - Use the debug variable to activate dbug instructions:

  SET SESSION debug="+d,init_slave_crash_return";

The new macros are briefly described below:

DBUG_CRASH_ENTER (function) is equivalent to DBUG_ENTER which registers the
beginning of a function but in addition to it allows for crashing the server
while entering the function if the appropriate dbug instruction is activate.
In this case, the dbug instruction should be "+d,function_crash_enter".

DBUG_CRASH_RETURN (value) is equivalent to DBUG_RETURN which notifies the
end of a function but in addition to it allows for crashing the server
while returning from the function if the appropriate dbug instruction is
activate. In this case, the dbug instruction should be
"+d,function_crash_return". Note that "function" should be the same string
used by either the DBUG_ENTER or DBUG_CRASH_ENTER.

DBUG_CRASH_VOID_RETURN (value) is equivalent to DBUG_VOID_RETURN which
notifies the end of a function but in addition to it allows for crashing
the server while returning from the function if the appropriate dbug
instruction is activate. In this case, the dbug instruction should be
"+d,function_crash_return". Note that "function" should be the same string
used by either the DBUG_ENTER or DBUG_CRASH_ENTER.

To inject other faults, for instance, wrong return values, one should rely
on the macros already available. The current patch also removes a set of
macros that were either not being used or were redundant as other macros
could be used to provide the same feature. In the future, we also consider
dynamic instrumentation of the code.


BUG#45747 DBUG_CRASH_* is not setting the strict option
---------
      
When combining DBUG_CRASH_* with "--debug=d:t:i:A,file" the server crashes
due to a call to the abort function in the DBUG_CRASH_* macro althought the
appropriate keyword has not been set.
2009-09-29 14:55:36 +01:00
Alfranio Correia
569ca8590c BUG#44663 Unused replication options prevent server from starting.
NOTE: Backporting the patch to next-mr.
            
The use of option log_slave_updates without log_bin was preventing the server
from starting. To fix the problem, we replaced the error message and the exit
call by a warning message.
2009-09-29 14:38:32 +01:00
Luis Soares
f0886a4d9d BUG#28777, WL#4293: SHOW BINLOG EVENTS does not work on relay log
files

NOTE: this is the backport to next-mr.
            
SHOW BINLOG EVENTS does not work with relay log files. If issuing
"SHOW BINLOG EVENTS IN 'relay-log.000001'" in a non-empty relay
log file (relay-log.000001), mysql reports empty set.
            
This patch addresses this issue by extending the SHOW command
with RELAYLOG. Events in relay log files can now be inspected by
issuing SHOW RELAYLOG EVENTS [IN 'log_name'] [FROM pos] [LIMIT
[offset,] row_count].

mysql-test/extra/rpl_tests/rpl_show_relaylog_events.inc:
  Shared part of the test case.
mysql-test/include/show_binlog_events.inc:
  Added options $binary_log_file, $binary_log_limit_row, 
  $binary_log_limit_offset so that show_binlog_events can take 
  same parameters as SHOW BINLOG EVENTS does.
mysql-test/include/show_relaylog_events.inc:
  Clone of show_binlog_events for relaylog events.
mysql-test/suite/rpl/t/rpl_row_show_relaylog_events.test:
  Test case for row based replication.
mysql-test/suite/rpl/t/rpl_stm_mix_show_relaylog_events.test:
  Test case for statement and mixed mode replication.
sql/lex.h:
  Added RELAYLOG symbol.
sql/mysqld.cc:
  Added "show_relaylog_events" to status_vars.
sql/sp_head.cc:
  Set SQLCOM_SHOW_RELAYLOG_EVENTS to return flags=
  sp_head::MULTI_RESULTS; in sp_get_flags_for_command as
  SQLCOM_SHOW_BINLOG_EVENTS does.
sql/sql_lex.h:
  Added sql_command SQLCOM_SHOW_RELAYLOG_EVENTS to lex enum_sql_command.
sql/sql_parse.cc:
  Added handling of SQLCOM_SHOW_RELAYLOG_EVENTS.
sql/sql_repl.cc:
  mysql_show_binlog_events set to choose the log file to use based on
  the command issued (SHOW BINLOG|RELAYLOG EVENTS).
sql/sql_yacc.yy:
  Added RELAYLOG to the grammar.
2009-09-29 00:04:20 +01:00
Mats Kindahl
5d2f79def9 Bug #47645: Segmentation fault when out of memory during handlerton initialization
There is a missing check for memory allocation failure when allocating
memory for the handlerton structure. If the handlerton init function
tries to de-reference the pointer, it will cause a segmentation fault
and crash the server.

This patch fixes the problem by not calling the init function if memory
allocation failed, and instead prints an informative error message and
reports the error to the caller.

sql/handler.cc:
  Add a check if memory allocation succeeded before calling the init
  function. If it failed, it is not necessary to free the memory,
  but the plugin->data is set to NULL to ensure that it can be checked
  for failure.
2009-09-25 11:47:15 +02:00
Mats Kindahl
d47710c8dc WL#5016: Fix header file include guards
Adding header include file guards to files that are missing such.
2009-09-23 23:32:31 +02:00
Mats Kindahl
124e830125 Bug #37221: SET AUTOCOMMIT=1 does not commit binary log
When setting AUTOCOMMIT=1 after starting a transaction, the binary log
did not commit the outstanding transaction. The reason was that the binary
log commit function saw the values of the new settings, deciding that there
were nothing to commit.

Fixed the problem by moving the implicit commit to before the thread option
flags were changed, so that the binary log sees the old values of the flags
instead of the values they will take after the statement.


mysql-test/extra/binlog_tests/implicit.test:
  New test file to check implicit commits both inside and outside transactions.
mysql-test/suite/binlog/t/binlog_implicit_commit.test:
  Test for implicit commit of SET AUTOCOMMIT and LOCK/UNLOCK TABLES.
sql/set_var.cc:
  Adding code to commit pending transaction before changing option flags.
2009-09-23 13:20:48 +02:00
Mats Kindahl
8249fd6eef BUG#29288: myisam transactions replicated to a transactional
slave leaves slave unstable

Problem: when replicating from non-transactional to
transactional engine with autocommit off, no BEGIN/COMMIT
is written to the binlog. When the slave replicates, it
will start a transaction that never ends.

Fix: Force autocommit=on on slave by always replicating
autocommit=1 from the master.
2009-09-23 11:43:43 +02:00
Bjorn Munch
31f9d5fd16 second merge from main, with adaptions 2009-09-02 23:29:11 +02:00
Bjorn Munch
a829604260 first merge from main 2009-09-02 18:58:17 +02:00
Georgi Kodinov
b64e7fb5be fixed a valgrind warning in partition_pruning 2009-09-02 18:42:08 +03:00
Georgi Kodinov
7c9e39f5c5 fixed a valgrind warning in partitioning code 2009-09-02 15:20:47 +03:00
Georgi Kodinov
f0720480dc Fixed win32 compilation warnings 2009-09-02 13:22:47 +03:00
Georgi Kodinov
38cb188e24 automerge 2009-08-31 16:40:35 +03:00
Staale Smedseng
4d7202a02b Merge from 5.1-bugteam 2009-08-30 19:01:48 +02:00
Alexey Kopytov
54e4516063 Automerge. 2009-08-30 11:38:49 +04:00
Alexey Kopytov
6ce48392ea Bug #46607: Assertion failed: (cond_type == Item::FUNC_ITEM)
results in server crash 
 
check_group_min_max_predicates() assumed the input condition 
item to be one of COND_ITEM, SUBSELECT_ITEM, or FUNC_ITEM. 
Since a condition of the form "field" is also a valid condition 
equivalent to "field <> 0", using such a condition in a query 
where the loose index scan was chosen resulted in a debug 
assertion failure. 
 
Fixed by handling conditions of the FIELD_ITEM type in 
check_group_min_max_predicates(). 

mysql-test/r/group_min_max.result:
  Added a test case for bug #46607.
mysql-test/t/group_min_max.test:
  Added a test case for bug #46607.
sql/opt_range.cc:
  Handle conditions of the FUNC_ITEM type in 
  check_group_mix_max_predicates().
2009-08-30 11:03:37 +04:00
unknown
f32c08bd0c Bug #44331 Restore of database with events produces warning in replication
If an EVENT is created without the DEFINER clause set explicitly or with it set  
to CURRENT_USER, the master and slaves become inconsistent. This issue stems from 
the fact that in both cases, the DEFINER is set to the CURRENT_USER of the current 
thread. On the master, the CURRENT_USER is the mysqld's user, while on the slave,  
the CURRENT_USER is empty for the SQL Thread which is responsible for executing 
the statement.

To fix the problem, we do what follows. If the definer is not set explicitly,  
a DEFINER clause is added when writing the query into binlog; if 'CURRENT_USER' is 
used as the DEFINER, it is replaced with the value of the current user before 
writing to binlog.

mysql-test/suite/rpl/r/rpl_create_if_not_exists.result:
  Updated the result file after fixing bug#44331
mysql-test/suite/rpl/r/rpl_drop_if_exists.result:
  Updated the result file after fixing bug#44331
mysql-test/suite/rpl/r/rpl_events.result:
  Test result of Bug#44331
mysql-test/suite/rpl/r/rpl_innodb_mixed_dml.result:
  Updated the result file after fixing bug#44331
mysql-test/suite/rpl/t/rpl_events.test:
  Added test to verify if the definer is consistent between master and slave
  when the event is created without the DEFINER clause set explicitly or the
  DEFINER is set to CURRENT_USER
sql/events.cc:
  The "create_query_string" function is added to create a new query string 
  for removing executable comments.
sql/sql_yacc.yy:
  The remember_name token was added for recording the offset of EVENT_SYM.
2009-08-29 16:52:22 +08:00
Staale Smedseng
5be4c38226 Merge from 5.0 for 43414 2009-08-28 18:21:54 +02:00
Staale Smedseng
1ba25ae47c Bug #43414 Parenthesis (and other) warnings compiling MySQL
with gcc 4.3.2
      
This patch fixes a number of GCC warnings about variables used
before initialized. A new macro UNINIT_VAR() is introduced for
use in the variable declaration, and LINT_INIT() usage will be
gradually deprecated. (A workaround is used for g++, pending a
patch for a g++ bug.)
      
GCC warnings for unused results (attribute warn_unused_result)
for a number of system calls (present at least in later
Ubuntus, where the usual void cast trick doesn't work) are
also fixed.


client/mysqlmanager-pwgen.c:
  A fix for warn_unused_result, adding fallback to use of
  srand()/rand() if /dev/random cannot be used. Also actually
  adds calls to rand() in the second branch so that it actually
  creates a random password.
2009-08-28 17:51:31 +02:00
Davi Arnaut
169f7da04c Fix for a few assorted compiler warnings.
client/mysql.cc:
  Remove leading whitespace.
  Remove extra text after #else directive.
client/mysqldump.c:
  Function does not take a parameter.
mysys/array.c:
  buffer is a uchar pointer.
sql/item.cc:
  Assert if it should not happen.
storage/myisam/mi_check.c:
  Cast to expected type. This is probably a bug, but it is
  casted in a similar way in another part of the code.
storage/ndb/include/mgmapi/ndb_logevent.h:
  Apply fix from cluster team.
tests/mysql_client_test.c:
  Remove extraneous slash.
2009-08-28 12:06:59 -03:00
Mattias Jonsson
99413e461f merge 2009-08-28 13:54:17 +02:00
Mattias Jonsson
0a76397171 Manual merge between bug#46362 and bug#20577.
sql/opt_range.cc:
  Removed duplicate code (if statement must have been duplicated during earlier merge).
sql/sql_partition.cc:
  After mergeing bug#46362 and bug#20577, the NULL partition was also searched
  when col = const, fixed by checking if = or range.
2009-08-28 12:55:59 +02:00
Alfranio Correia
f9e413a1a5 merge mysql-5.0-bugteam --> mysql-5.1-bugteam 2009-08-28 10:45:57 +01:00
Alfranio Correia
5edd807a7a auto-merge mysql-5.0-bugteam (local) --> mysql-5.0-bugteam 2009-08-28 10:29:04 +01:00
Alfranio Correia
ea06bbd2b0 BUG#46861 Auto-closing of temporary tables broken by replicate-rewrite-db
When a connection is dropped any remaining temporary table is also automatically
dropped and the SQL statement of this operation is written to the binary log in
order to drop such tables on the slave and keep the slave in sync. Specifically,
the current code base creates the following type of statement:
DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `db`.`table`;

Unfortunately, appending the database to the table name in this manner circumvents
the replicate-rewrite-db option (and any options that check the current database).
To solve the issue, we started writing the statement to the binary as follows:
use `db`; DROP /*!40005 TEMPORARY */ TABLE IF EXISTS `table`;
2009-08-27 17:28:09 +01:00
Alfranio Correia
354f5f7bac BUG#46864 Incorrect update of InnoDB table on slave when using trigger with myisam table
Slave does not correctly handle "expected errors" leading to inconsistencies
between the mater and slave. Specifically, when a statement changes both
transactional and non-transactional tables, the transactional changes are
automatically rolled back on the master but the slave ignores the error and
does not roll them back thus leading to inconsistencies.
      
To fix the problem, we automatically roll back a statement that fails on
the slave but note that the transaction is not rolled back unless a "rollback"
command is in the relay log file.

mysql-test/extra/rpl_tests/rpl_mixing_engines.test:
  Enabled item 13.e which was disabled because of the bug fixed by the
  current and removed item 14 which was introduced by mistake.
2009-08-27 13:46:29 +01:00
Georgi Kodinov
a22c29d5e4 Bug #46749: Segfault in add_key_fields() with outer subquery level
field references

This error requires a combination of factors : 
1. An "impossible where" in the outermost SELECT
2. An aggregate in the outermost SELECT
3. A correlated subquery with a WHERE clause that includes an outer 
field reference as a top level WHERE sargable predicate

When JOIN::optimize detects an "impossible WHERE" it will bail out
without doing the rest of the work and initializations. It will not
call make_join_statistics() as well.  And make_join_statistics fills 
in various structures for each table referenced.
When processing the result of the "impossible WHERE" the query must
send a single row of data if there are aggregate functions in it.
In this case the server marks all the aggregates as having received 
no rows and calls the relevant Item::val_xxx() method on the SELECT
list. However if this SELECT list happens to contain a correlated 
subquery this subquery is evaluated in a normal evaluation mode.
And if this correlated subquery has a reference to a field from the 
outermost "impossible where" SELECT the add_key_fields will mistakenly
consider the outer field reference as a "local" field reference when 
looking for sargable predicates.
But since the SELECT where the outer field reference refers to is not
completely initialized due to the "impossible WHERE" in this level
we'll get a NULL pointer reference.
Fixed by making a better condition for discovering if a field is "local"
to the SELECT level being processed. 
It's not enough to look for OUTER_REF_TABLE_BIT in this case since 
for outer references to constant tables the Item_field::used_tables() 
will return 0 regardless of whether the field reference is from the 
local SELECT or not.
2009-08-27 14:40:42 +03:00
Sergey Glukhov
51f4ccfa43 5.0-bugteam->5.1-bugteam merge 2009-08-27 15:59:25 +05:00
Sergey Glukhov
367c14b854 Bug#46184 Crash, SELECT ... FROM derived table procedure analyze
The crash happens because select_union object is used as result set
for queries which have derived tables.
select_union use temporary table as data storage and if
fields count exceeds 10(count of values for procedure ANALYSE())
then we get a crash on fill_record() function.


mysql-test/r/analyse.result:
  test result
mysql-test/r/subselect.result:
  result fix
mysql-test/t/analyse.test:
  test case
mysql-test/t/subselect.test:
  test fix
sql/sql_yacc.yy:
  The crash happens because select_union object is used as result set
  for queries which have derived tables.
  select_union use temporary table as data storage and if
  fields count exceeds 10(count of values for procedure ANALYSE())
  then we get a crash on fill_record() function.
2009-08-27 15:22:19 +05:00
Georgi Kodinov
f10e85f5f2 merged 5.0-bugteam -> 5.1-bugteam 2009-08-27 10:46:35 +03:00
Alfranio Correia
6c2b32515e BUG#28976 Mixing trans and non-trans tables in one transaction results in incorrect
binlog

Mixing transactional (T) and non-transactional (N) tables on behalf of a
transaction may lead to inconsistencies among masters and slaves in STATEMENT
mode. The problem stems from the fact that although modifications done to
non-transactional tables on behalf of a transaction become immediately visible
to other connections they do not immediately get to the binary log and therefore
consistency is broken. Although there may be issues in mixing T and M tables in
STATEMENT mode, there are safe combinations that clients find useful.

In this bug, we fix the following issue. Mixing N and T tables in multi-level
(e.g. a statement that fires a trigger) or multi-table table statements (e.g.
update t1, t2...) were not handled correctly. In such cases, it was not possible
to distinguish when a T table was updated if the sequence of changes was N and T.
In a nutshell, just the flag "modified_non_trans_table" was not enough to reflect
that both a N and T tables were changed. To circumvent this issue, we check if an
engine is registered in the handler's list and changed something which means that
a T table was modified.

Check WL 2687 for a full-fledged patch that will make the use of either the MIXED or
ROW modes completely safe.

mysql-test/suite/binlog/r/binlog_row_mix_innodb_myisam.result:
  Truncate statement is wrapped in BEGIN/COMMIT.
mysql-test/suite/binlog/r/binlog_stm_mix_innodb_myisam.result:
  Truncate statement is wrapped in BEGIN/COMMIT.
2009-08-27 00:13:03 +01:00
Mattias Jonsson
cb57e856b6 merge 2009-08-26 14:45:50 +02:00
Mattias Jonsson
0000c9417a merge 2009-08-26 14:40:18 +02:00
Mattias Jonsson
67214ef433 Bug#20577: Partitions: use of to_days() function leads to selection failures
Problem was that the partition containing NULL values
was pruned away, since '2001-01-01' < '2001-02-00' but
TO_DAYS('2001-02-00') is NULL.

Added the NULL partition for RANGE/LIST partitioning on TO_DAYS()
function to be scanned too.

Also fixed a bug that added ALLOW_INVALID_DATES to sql_mode
(SELECT * FROM t WHERE date_col < '1999-99-99' on a RANGE/LIST
partitioned table would add it).

mysql-test/include/partition_date_range.inc:
  Bug#20577: Partitions: use of to_days() function leads to selection failures
  
  Added include file to decrease test code duplication
mysql-test/r/partition_pruning.result:
  Bug#20577: Partitions: use of to_days() function leads to selection failures
  
  Added test results
mysql-test/r/partition_range.result:
  Bug#20577: Partitions: use of to_days() function leads to selection failures
  
  Updated test result.
  This fix adds the partition containing NULL values to
  the list of partitions to be scanned.
mysql-test/t/partition_pruning.test:
  Bug#20577: Partitions: use of to_days() function leads to selection failures
  
  Added test case
sql/item.h:
  Bug#20577: Partitions: use of to_days() function leads to selection failures
  
  Added MONOTONIC_*INCREASE_NOT_NULL values to be used by TO_DAYS.
sql/item_timefunc.cc:
  Bug#20577: Partitions: use of to_days() function leads to selection failures
  
  Calculate the number of days as return value even for invalid dates.
  This is so that pruning can be used even for invalid dates.
sql/opt_range.cc:
  Bug#20577: Partitions: use of to_days() function leads to selection failures
  
  Fixed a bug that added ALLOW_INVALID_DATES to sql_mode
  (SELECT * FROM t WHERE date_col < '1999-99-99' on a RANGE/LIST
  partitioned table would add it).
sql/partition_info.h:
  Bug#20577: Partitions: use of to_days() function leads to selection failures
  
  Resetting ret_null_part when a single partition is to be used, this
  to avoid adding the NULL partition.
sql/sql_partition.cc:
  Bug#20577: Partitions: use of to_days() function leads to selection failures
  
  Always include the NULL partition if RANGE or LIST.
  Use the returned value for the function for pruning, even if
  it is marked as NULL, so that even '2000-00-00' can be
  used for pruning, even if TO_DAYS('2000-00-00') is NULL.
  
  Changed == to >= in get_next_partition_id_list to avoid
  crash if part_iter->part_nums is not correctly setup.
2009-08-26 12:59:49 +02:00
Mattias Jonsson
4655118bea Bug#46362: Endpoint should be set to false for TO_DAYS(DATE)
There were a problem since pruning uses the field
for comparison (while evaluate_join_record uses longlong),
resulting in pruning failures when comparing DATE to DATETIME.

Fix was to always comparing DATE vs DATETIME as DATETIME,
by adding ' 00:00:00' to the DATE string.

And adding optimization for comparing with 23:59:59, so that
DATETIME_col > '2001-02-03 23:59:59' ->
TO_DAYS(DATETIME_col) > TO_DAYS('2001-02-03 23:59:59') instead
of '>='.

mysql-test/r/partition_pruning.result:
  Bug#46362: Endpoint should be set to false for TO_DAYS(DATE)
  
  Updated result-file
mysql-test/t/partition_pruning.test:
  Bug#46362: Endpoint should be set to false for TO_DAYS(DATE)
  
  Added testcases.
sql-common/my_time.c:
  Bug#46362: Endpoint should be set to false for TO_DAYS(DATE)
  
  removed duplicate assignment.
sql/item.cc:
  Bug#46362: Endpoint should be set to false for TO_DAYS(DATE)
  
  Changed field_is_equal_to_item into field_cmp_to_item, to
  better handling DATE vs DATETIME comparision.
sql/item.h:
  Bug#46362: Endpoint should be set to false for TO_DAYS(DATE)
  
  Updated comment
sql/item_timefunc.cc:
  Bug#46362: Endpoint should be set to false for TO_DAYS(DATE)
  
  Added optimization (pruning) of DATETIME where time-part is
  23:59:59
sql/opt_range.cc:
  Bug#46362: Endpoint should be set to false for TO_DAYS(DATE)
  
  Using the new stored_field_cmp_to_item for better pruning.
2009-08-26 12:51:23 +02:00
Davi Arnaut
fc39459504 Bug#45261: Crash, stored procedure + decimal
The problem was that creating a DECIMAL column from a decimal
value could lead to a failed assertion as decimal values can
have a higher precision than those attached to a table. The
assert could be triggered by creating a table from a decimal
with a large (> 30) scale. Also, there was a problem in
calculating the number of digits in the integral and fractional
parts if both exceeded the maximum number of digits permitted
by the new decimal type.

The solution is to ensure that truncation procedure is executed
when deducing a DECIMAL column from a decimal value of higher
precision. If the integer part is equal to or bigger than the
maximum precision for the DECIMAL type (65), the integer part
is truncated to fit and the fractional becomes zero. Otherwise,
the fractional part is truncated to fit into the space left
after the integer part is copied.

This patch borrows code and ideas from Martin Hansson's patch.

mysql-test/r/type_newdecimal.result:
  Add test case result for Bug#45261. Also, update test case to
  reflect that an additive operation increases the precision of
  the resulting type by 1.
mysql-test/t/type_newdecimal.test:
  Add test case for Bug#45261
sql/field.cc:
  Added DBUG_ASSERT to ensure object's invariant is maintained.
  Implement method to create a field to hold a decimal value
  from an item.
sql/field.h:
  Explain member variable. Add method to create a new decimal field.
sql/item.cc:
  The precision should only be capped when storing the value
  on a table. Also, this makes it impossible to calculate the
  integer part if Item::decimals (the scale) is larger than the
  precision.
sql/item.h:
  Simplify calculation of integer part.
sql/item_cmpfunc.cc:
  Do not limit the precision. It will be capped later.
sql/item_func.cc:
  Use new method for allocating a new decimal field.
  Add a specialized method for retrieving the precision
  of a user variable item.
sql/item_func.h:
  Add method to return the precision of a user variable.
sql/item_sum.cc:
  Use new method for allocating a new decimal field.
sql/my_decimal.h:
  The integer part could be improperly calculated for a decimal
  with 31 digits in the fractional part.
sql/sql_select.cc:
  Use new method which truncates the integer or decimal parts
  as needed.
2009-08-24 16:47:08 -03:00
Georgi Kodinov
7492d622e4 Bug #37044: Read overflow in opt_range.cc found during "make test"
The code was using a special global buffer for the value of IS NULL ranges.
This was not always long enough to be copied by a regular memcpy. As a 
result read buffer overflows may occur.
Fixed by setting the null byte to 1 and setting the rest of the field disk image
to NULL with a bzero (instead of relying on the buffer and memcpy()).
2009-08-24 15:28:03 +03:00
Alfranio Correia
e31a41d10b auto-merge mysql-5.1-bugteam (local) --> mysql-5.1-bugteam 2009-08-24 11:37:44 +01:00
Alfranio Correia
9a632549da auto-merge mysql-5.1-bugteam (local) --> mysql-5.1-bugteam 2009-08-24 10:24:52 +01:00
Mattias Jonsson
8b0ec01448 merge 2009-08-21 18:00:38 +02:00
Mattias Jonsson
a4e832d69d Bug#46639: 1030 (HY000): Got error 124 from storage engine on
INSERT ... SELECT ...

Problem was that when bulk insert is used on an empty
table/partition, it disables the indexes for better
performance, but in this specific case it also tries
to read from that partition using an index, which is
not possible since it has been disabled.

Solution was to allow index reads on disabled indexes
if there are no records.

Also reverted the patch for bug#38005, since that was a workaround
in the partitioning engine instead of a fix in myisam.

mysql-test/r/partition.result:
  Bug#46639: 1030 (HY000): Got error 124 from storage engine on
  INSERT ... SELECT ...
  
  updated result file
mysql-test/t/partition.test:
  Bug#46639: 1030 (HY000): Got error 124 from storage engine on
  INSERT ... SELECT ...
  
  Added testcase
sql/ha_partition.cc:
  Bug#46639: 1030 (HY000): Got error 124 from storage engine on
  INSERT ... SELECT ...
  
  reverted the patch for bug#38005, since that was a workaround
  around this problem, not needed after fixing it in myisam.
storage/myisam/mi_search.c:
  Bug#46639: 1030 (HY000): Got error 124 from storage engine on
  INSERT ... SELECT ...
  
  Return HA_ERR_END_OF_FILE instead of HA_ERR_WRONG_INDEX
  when there are no rows.
2009-08-21 17:38:29 +02:00
Georgi Kodinov
787a4940ca reverted the fix for bug #46019 from 5.1-bugteam 2009-08-21 17:41:48 +03:00
Georgi Kodinov
8723e9d226 automerge 2009-08-21 17:12:03 +03:00
Georgi Kodinov
66ce3dee92 Revert of the fix for bug #46019. 2009-08-21 17:10:55 +03:00
Martin Hansson
8f75260b7d Merge. 2009-08-21 14:31:40 +02:00
Martin Hansson
b011f1ea1c Merge. 2009-08-21 12:13:03 +02:00
Ramil Kalimullin
fb9ba3734b Fix for bug #46456 [Ver->Prg]: HANDLER OPEN + TRUNCATE + DROP
(temporary) TABLE, crash

Problem: if one has an open "HANDLER t1", further "TRUNCATE t1" 
doesn't close the handler and leaves handler table hash in an 
inconsistent state, that may lead to a server crash.

Fix: TRUNCATE should implicitly close all open handlers.

Doc. request: the fact should be described in the manual accordingly.


mysql-test/r/handler_myisam.result:
  Fix for bug #46456 [Ver->Prg]: HANDLER OPEN + TRUNCATE + DROP
  (temporary) TABLE, crash
    - test result.
mysql-test/t/handler_myisam.test:
  Fix for bug #46456 [Ver->Prg]: HANDLER OPEN + TRUNCATE + DROP
  (temporary) TABLE, crash
    - test case.
sql/sql_delete.cc:
  Fix for bug #46456 [Ver->Prg]: HANDLER OPEN + TRUNCATE + DROP
   (temporary) TABLE, crash
    - remove all truncated tables from the HANDLER's hash.
2009-08-21 10:55:35 +05:00
Georgi Kodinov
1317d24b33 merge of bug #46019 to 5.1-bugteam 2009-08-20 17:11:22 +03:00