Commit graph

1193 commits

Author SHA1 Message Date
Igor Babaev
89cf840cd9 Merge 2011-05-20 12:47:39 -07:00
Igor Babaev
8e33aa9aa7 Merged the fix for bug 777745 into 5.3. 2011-05-19 20:01:43 -07:00
Igor Babaev
016a09cb7d Fixed LP bug #777745.
Fields belonging to views in general cannot be substituted for 
equal items, in particular for constants, because all references
to a view field refer to the same Item_field object while they 
could be used in different OR parts of the where condition and
belong to different equivalence classes (to different Item_equals).
That's why substitution for equal items in any context is allowed
only in place of Item_direct_view_ref objects, but not in place of
Item_fields these objects refer to.
Due to some erroneous code in the patch for bug 717577 substitution
for view fields were allowed in some context.This could lead
to wrong results returned by queries using views.

The fix prohibits substitution of view fields for equal items 
in any context.

The patch also changes slightly the compile method for the Item_func
class. Now if the analyze method returns NULL in his parameter the
compile method is not called for the arguments of the function
at all. A similar change was made for the Item_ref class.
2011-05-19 18:28:38 -07:00
Igor Babaev
704f97035f Merged the code of MWL#106 into 5.3
Resolved all conflicts, bad merges and fixed a few minor bugs in the code.
Commented out the queries from multi_update, view, subselect_sj, func_str,
derived_view, view_grant that failed either with crashes in ps-protocol or
with wrong results.
The failures are clear indications of some bugs in the code and these bugs
are to be fixed.
2011-05-16 22:39:43 -07:00
Michael Widenius
f09f1c7c7d Merge with dynamic column code 2011-05-12 14:30:34 +03:00
Michael Widenius
f34be18938 Merge with MariaDB 5.2 2011-05-10 18:17:43 +03:00
Michael Widenius
5ab92b1f85 Adding support for Dynamic columns (WL#34):
- COLUMN_CREATE(column_nr, value, [column_nr,value]...)
- COLUMN_ADD(blob,column_nr, value, column_nr,value]...)
- COLUMN_DELETE(blob, column_nr, column_nr...)
- COLUMN_EXISTS(blob, column_nr)
- COLUMN_LIST(blob, column_nr)
- COLUMN_GET(string, column_nr AS type)

Added cast(X as DOUBLE) and cast(x as INT)
Better warning and error messages for wrong cast's
Created some sub functions to simplify and reuse code.
Added a lot of conversation functions with error/warnings for what went wrong.
Fixed some issues when casting time to datetime.
Added functions to dynamic strings and Strings to allow one to move a string buffer from dynamic strings to String (to save malloc+ copy)
Added dynamic columns library to libmysqlclient


include/Makefile.am:
  Added ma_dyncol.h
include/decimal.h:
  Added 'const' to arguments for some functions.
include/my_sys.h:
  Added dynstr_reassociate()
include/my_time.h:
  Added TIME_SUBSECOND_RANGE
  Added double_to_datetime()
  Added flag argument to str_to_time()
libmysql/CMakeLists.txt:
  Added mysys/ma_dyncol.c
libmysql/Makefile.shared:
  Added ma_dyncol
libmysql/libmysql.c:
  Added argument to str_to_time()
mysql-test/r/bigint.result:
  Better error messages
mysql-test/r/cast.result:
  Better warning and error messages
  A lot of new cast() tests
mysql-test/r/func_math.result:
  Better warning messages
mysql-test/r/func_str.result:
  Better warning messages
mysql-test/r/func_time.result:
  Better warning messages
mysql-test/r/sp-vars.result:
  Better warning messages
mysql-test/r/strict.result:
  Better warning messages
  New test result
mysql-test/r/type_newdecimal.result:
  Better warning messages
mysql-test/r/warnings.result:
  Better warning messages
mysql-test/suite/funcs_1/r/innodb_func_view.result:
  Updated results after better cast warnings
mysql-test/suite/funcs_1/r/memory_func_view.result:
  Updated results after better cast warnings
mysql-test/suite/funcs_1/r/myisam_func_view.result:
  Updated results after better cast warnings
mysql-test/suite/optimizer_unfixed_bugs/t/bug43448.test:
  Added begin...commit to speed up test.
mysql-test/suite/parts/inc/part_supported_sql_funcs_delete.inc:
  Added begin...commit to speed up test.
mysql-test/suite/parts/inc/partition_supported_sql_funcs.inc:
  Added begin...commit to speed up test.
mysql-test/suite/parts/r/part_supported_sql_func_innodb.result:
  Added begin...commit to speed up test.
mysql-test/suite/parts/r/part_supported_sql_func_myisam.result:
  Added begin...commit to speed up test.
mysql-test/suite/parts/r/rpl_partition.result:
  Added begin...commit to speed up test.
mysql-test/suite/parts/t/part_supported_sql_func_innodb.test:
  Removed duplicated --big_test
mysql-test/suite/parts/t/rpl_partition.test:
  Added begin...commit to speed up test.
mysql-test/suite/pbxt/r/cast.result:
  Updated results after better cast warnings
mysql-test/suite/pbxt/r/func_str.result:
  Updated results after better cast warnings
mysql-test/suite/pbxt/r/type_newdecimal.result:
  Updated results after better cast warnings
mysql-test/suite/rpl/r/rpl_innodb_bug28430.result:
  Added begin...commit to speed up test.
mysql-test/suite/rpl/t/rpl_innodb_bug28430.test:
  Added begin...commit to speed up test.
mysql-test/suite/vcol/r/vcol_supported_sql_funcs_innodb.result:
  More warnings
mysql-test/suite/vcol/r/vcol_supported_sql_funcs_myisam.result:
  More warnings
mysql-test/t/cast.test:
  A lot of new cast() tests
mysql-test/t/strict.test:
  Added new test
mysys/CMakeLists.txt:
  Added ma_dyncol.c
mysys/Makefile.am:
  Added ma_dyncol.c
mysys/string.c:
  Added dynstr_reassociate() to move a buffer from dynamic_strings to some other allocator
sql-common/my_time.c:
  Added 'fuzzydate' flag to str_to_time()
  Added support for microseconds to my_time_to_str() and my_datetime_to_str()
  Reset second_parts in number_to_datetime()
  Added double_to_datetime()
sql/field.cc:
  Added double_to_longlong() and truncate_double() to simplify and reuse code
sql/field.h:
  New prototypes
sql/item.cc:
  Changed Item::get_date(MYSQL_TIME *ltime,uint fuzzydate) to be aware of type of argument.
  (Needed to make it microsecond safe and get better warnings).
  Updated call to str_to_time_with_warn()
sql/item.h:
  Added struct st_dyncall_create_def used by dynamic columns
  Added virtual bool dynamic_result() to tell if type of argument may change over calls.
sql/item_cmpfunc.cc:
  Added Item_func_dyncol_exists()
sql/item_cmpfunc.h:
  Added class Item_func_dyncol_exists
sql/item_create.cc:
  Added get_length_and_scale() to simplify other functions
  Simplified and extended create_func_cast()
  Added support for cast(X as double(X,Y))
  Added functions to create dynamic column functions.
sql/item_create.h:
  Added prototypes
sql/item_func.cc:
  Extended cast functions Item_func_signed() and Item_func_unsigned() to work with dynamic types
  Added Item_double_typecast()
sql/item_func.h:
  Added class Item_double_typecast()
sql/item_strfunc.cc:
  Added functions for COLUMN_CREATE(), COLUMN_ADD(), COLUMN_GET() and COLUMN_LIST()
sql/item_strfunc.h:
  Added classes for COLUMN_CREATE(), COLUMN_ADD(), COLUMN_GET() and COLUMN_LIST()
sql/item_timefunc.cc:
  Added flag argument to str_to_time_with_warn()
  Updated Item_char_typecast() to handle result type that may change between calls (for dynamic columns)
  Added Item_time_typecast::get_date() to ensure that we cast a datetime to time properly.
sql/item_timefunc.h:
  Added get_date() to Item_time_typecast() to allow proper results for casting time to datetime
sql/lex.h:
  Added new SQL function names
sql/my_decimal.cc:
  Added 'const' to some arguments.
  Better error message in case of errors (we now print out the wrong value)
  Added my_decimal2int()
sql/my_decimal.h:
  Moved some constants to my_decimal_limits.h
  Updated prototypes.
  Made my_decimal2int() a function as it's rather long (no reason to have it inline)
  Added decimal2my_decimal() function.
sql/mysql_priv.h:
  Prototypes for new functions
sql/share/errmsg.txt:
  New error messages for wrong casts and dynamic columns
sql/sql_acl.cc:
  Fixed indentation
sql/sql_base.cc:
  Added dynamic_column_error_message()
sql/sql_string.h:
  Added reassociate() to move a buffer to be owned by String object.
sql/sql_yacc.yy:
  Added syntax for COLUMN_ functions.
sql/time.cc:
  Updated str_to_datetime_with_warn() flag argument to same type as other functions
  Added conversion flag to str_to_time_with_warn() (Similar to all datetime functions)
  Added conversion functions with warnings: double_to_datetime_with_warn() and decimal_to_datetime_with_warn()
strings/decimal.c:
  Added 'const' to arguments for some functions.
unittest/mysys/Makefile.am:
  Added test for dynamic columns code
2011-05-08 13:24:06 +03:00
Michael Widenius
1be5462d59 Merge with MariaDB 5.1 2011-05-03 19:10:10 +03:00
Michael Widenius
e415ba0fb2 Merge with MySQL 5.1.57/58
Moved some BSD string functions from Unireg
2011-05-02 20:58:45 +03:00
Alexander Barkov
a1c762b9df Bug#11926811 / Bug#60625 Illegal mix of collations
Problem: comparison of a DATETIME sp variable and NOW()
led to Illegal mix of collations error when 
character_set_connection=utf8.
Introduced by "WL#2649 Number-to-string conversions".

Error happened in Arg_comparator::set_compare_func(),
because the first argument was errouneously converted to utf8,
while the second argument was not.

Fix: separate agg_arg_charsets_for_comparison() into two functions:

- agg_arg_charsets_for_comparison() - for pure comparison,
  when we don't need to return any string result and therefore
  don't need to convert arguments to @@character_set_connection:
    SELECT a = b;

- agg_arg_charsets_for_string_results_with_comparison() - when
  we need to return a string result, but we also need to do
  comparison internally: SELECT REPLACE(a,b,c)
  If all arguments are numbers:
    SELECT REPLACE(123,2,3) -> 133
  we convert arguments to @@character_set_connection.


  @ mysql-test/include/ctype_numconv.inc
  @ mysql-test/r/ctype_binary.result
  @ mysql-test/r/ctype_cp1251.result
  @ mysql-test/r/ctype_latin1.result
  @ mysql-test/r/ctype_ucs.result
  @ mysql-test/r/ctype_utf8.result
  Adding tests

  @ sql/item.cc
  @ sql/item.h
  @ sql/item_func.cc
  @ sql/item_func.h
  @ sql/item_strfunc.cc

  Introducing and using new function
   agg_item_charsets_for_string_result_with_comparison() and
  its Item_func wrapper agg_arg_charsets_for_string_result_with_comparison().
2011-04-08 17:15:23 +04:00
Alexander Barkov
ece1996b5a Bug#11926811 / Bug#60625 Illegal mix of collations
Problem: comparison of a DATETIME sp variable and NOW()
led to Illegal mix of collations error when 
character_set_connection=utf8.
Introduced by "WL#2649 Number-to-string conversions".

Error happened in Arg_comparator::set_compare_func(),
because the first argument was errouneously converted to utf8,
while the second argument was not.

Fix: separate agg_arg_charsets_for_comparison() into two functions:

- agg_arg_charsets_for_comparison() - for pure comparison,
  when we don't need to return any string result and therefore
  don't need to convert arguments to @@character_set_connection:
    SELECT a = b;

- agg_arg_charsets_for_string_results_with_comparison() - when
  we need to return a string result, but we also need to do
  comparison internally: SELECT REPLACE(a,b,c)
  If all arguments are numbers:
    SELECT REPLACE(123,2,3) -> 133
  we convert arguments to @@character_set_connection.


  @ mysql-test/include/ctype_numconv.inc
  @ mysql-test/r/ctype_binary.result
  @ mysql-test/r/ctype_cp1251.result
  @ mysql-test/r/ctype_latin1.result
  @ mysql-test/r/ctype_ucs.result
  @ mysql-test/r/ctype_utf8.result
  Adding tests

  @ sql/item.cc
  @ sql/item.h
  @ sql/item_func.cc
  @ sql/item_func.h
  @ sql/item_strfunc.cc

  Introducing and using new function
   agg_item_charsets_for_string_result_with_comparison() and
  its Item_func wrapper agg_arg_charsets_for_string_result_with_comparison().
2011-04-08 17:15:23 +04:00
unknown
ec23949158 Fix LP BUG#715738
Analysis:
A query with implicit grouping is one with aggregate functions and
no GROUP BY clause. MariaDB inherits from MySQL an SQL extenstion
that allows mixing aggregate functions with non-aggregate fields.
If a query with such mixed select clause produces an empty result
set, the meaning of aggregate functions is well defined - either
NULL (MIN, MAX, etc.), or 0 (count(*)). However the non-aggregated
fields must also have some value, and the only reasonable value in
the case of empty result is NULL.

The cause of the many wrong results was that if a field is declared
as non-nullable (e.g. because it is a PK or NOT NULL), the semantic
analysis and the optimization phases treat this field as non-nullable,
and generate all related query plan elements based on this assumption.

Later during execution, these incorrectly configured/generated query
plan elements result in a wrong result because the selected fields
are not null due to the not-null assumption during optimization.

Solution:
Detect before the context analysys phase that a query uses implicit
grouping with mixed aggregates/non-aggregates, and set all fields
as nullable. The parser already walks the SELECT clause, and
already sets Item::with_sum_func for Items that reference aggreagate
functions. The patch adds a symmetric Item::with_field so that all
Items that reference an Item_field are marked during their
construction at parse time in the same way as with aggregate function
use.
2011-03-24 16:34:06 +02:00
Sergei Golubchik
5122e43a93 lp:737450 Second Assertion `item->null_value' failed in 5.1-micro
implement Item_func_min_max::get_date()
2011-03-18 19:23:32 +01:00
Michael Widenius
139a2b64bf Merge with 5.2 2011-03-09 15:47:59 +02:00
Sergei Golubchik
a8a757c6bb wl#173 - temporal types with sub-second resolution
and collateral changes.

* introduce my_hrtime_t, my_timediff_t, and conversion macros
* inroduce TIME_RESULT, but it can only be returned from Item::cmp_type(),
  never from Item::result_type()
* pack_time/unpack_time function for "packed" representation of
  MYSQL_TIME in a longlong that can be compared
* ADDTIME()/SUBTIME()/+- INTERVAL now work with TIME values
* numbers aren't quoted in EXPLAIN EXTENDED
* new column I_S.COLUMNS.DATETIME_PRECISION
* date/time values are compares to anything as date/time, not as strings or numbers.
* old timestamp(X) is no longer supported
* MYSQL_TIME to string conversion functions take precision as an argument
* unified the warnings from Field_timestamp/datetime/time/date/newdate store methods
* Field_timestamp_hires, Field_datetime_hires, Field_time_hires
* Field_temporal
* Lazy_string class to pass a value (string, number, time) polymorphically down the stack
* make_truncated_value_warning and Field::set_datetime_warning use Lazy_string as an argument, removed char*/int/double variants
* removed Field::can_be_compared_as_longlong(). Use Field::cmp_type() == INT_RESULT instead
* introduced Item::cmp_result() instead of Item::is_datetime() and Item::result_as_longlong()
* in many cases date/time types are treated like other types, not as special cases
* greatly simplified Arg_comparator (regarding date/time/year code)
* SEC_TO_TIME is real function, not integer.
* microsecond precision in NOW, CURTIME, etc
* Item_temporal. All items derived from it only provide get_date, but no val* methods
* replication of NOW(6)
* Protocol::store(time) now takes the precision as an argument
* @@TIMESTAMP is a double

client/mysqlbinlog.cc:
  remove unneded casts
include/my_sys.h:
  introduce my_hrtime_t, my_timediff_t, and conversion macros
include/my_time.h:
  pack_time/unpack_time, etc.
  convenience functions to work with MYSQL_TIME::second_part
libmysql/libmysql.c:
  str_to_time() is gone. str_to_datetime() does it now.
  my_TIME_to_str() takes the precision as an argument
mysql-test/include/ps_conv.inc:
  time is not equal to datetime anymore
mysql-test/r/distinct.result:
  a test for an old MySQL bug
mysql-test/r/explain.result:
  numbers aren't quoted in EXPLAIN EXTENDED
mysql-test/r/func_default.result:
  numbers aren't quoted in EXPLAIN EXTENDED
mysql-test/r/func_sapdb.result:
  when decimals=NOT_FIXED_DEC it means "not fixed" indeed
mysql-test/r/func_test.result:
  numbers aren't quoted in EXPLAIN EXTENDED
mysql-test/r/func_time.result:
  ADDTIME()/SUBTIME()/+- INTERVAL now work with TIME values
mysql-test/r/having.result:
  numbers aren't quoted in EXPLAIN EXTENDED
mysql-test/r/information_schema.result:
  new column I_S.COLUMNS.DATETIME_PRECISION
mysql-test/r/join_outer.result:
  numbers aren't quoted in EXPLAIN EXTENDED
mysql-test/r/metadata.result:
  TIMESTAMP no longer has zerofill flag
mysql-test/r/range.result:
  invalid datetime is not compared with as a string
mysql-test/r/select.result:
  NO_ZERO_IN_DATE, etc only affect storage - according to the manual
  numbers aren't quoted in EXPLAIN EXTENDED
mysql-test/r/subselect.result:
  numbers aren't quoted in EXPLAIN EXTENDED
mysql-test/r/sysdate_is_now.result:
  when decimals=NOT_FIXED_DEC it means "not fixed" indeed
mysql-test/r/type_blob.result:
  TIMESTAMP(N) is not deprecated
mysql-test/r/type_timestamp.result:
  old TIMESTAMP(X) semantics is not supported anymore
mysql-test/r/union.result:
  numbers aren't quoted in EXPLAIN EXTENDED
mysql-test/r/varbinary.result:
  numbers aren't quoted in EXPLAIN EXTENDED
mysql-test/t/distinct.test:
  test for an old MySQL bug
mysql-test/t/func_time.test:
  +- INTERVAL now works with TIME values
mysql-test/t/select.test:
  typo
mysql-test/t/subselect.test:
  only one error per statement, please
mysql-test/t/system_mysql_db_fix40123.test:
  old timestamp(X) is no longer supported
mysql-test/t/system_mysql_db_fix50030.test:
  old timestamp(X) is no longer supported
mysql-test/t/system_mysql_db_fix50117.test:
  old timestamp(X) is no longer supported
mysql-test/t/type_blob.test:
  old timestamp(X) is no longer supported
mysql-test/t/type_timestamp.test:
  old timestamp(X) is no longer supported
mysys/my_getsystime.c:
  functions to get the time with microsecond precision
mysys/my_init.c:
  move the my_getsystime.c initialization code to my_getsystime.c
mysys/my_static.c:
  no need to make these variables extern
mysys/my_static.h:
  no need to make these variables extern
scripts/mysql_system_tables.sql:
  old timestamp(X) is no longer supported
scripts/mysql_system_tables_fix.sql:
  old timestamp(X) is no longer supported
scripts/mysqlhotcopy.sh:
  old timestamp(X) is no longer supported
sql-common/my_time.c:
  * call str_to_time from str_to_datetime, as appropriate
  * date/time to string conversions take precision as an argument
  * number_to_time()
  * TIME_to_double()
  * pack_time() and unpack_time()
sql/event_data_objects.cc:
  cast is not needed
  my_datetime_to_str() takes precision as an argument
sql/event_db_repository.cc:
  avoid dangerous downcast (because the pointer is
  not always Field_timestamp, see events_1.test)
sql/event_queue.cc:
  avoid silly double-work for cond_wait
  (having an endpoint of wait, subtract the current time to get the timeout,
  and use set_timespec() macro to fill in struct timespec, by adding the current
  time to the timeout)
sql/field.cc:
  * remove virtual Field::get_time(), everyone should use only Field::get_date()
  * remove lots of #ifdef WORDS_BIGENDIAN
  * unified the warnings from Field_timestamp/datetime/time/date/newdate store methods
  * Field_timestamp_hires, Field_datetime_hires, Field_time_hires
  * Field_temporal
  * make_truncated_value_warning and Field::set_datetime_warning use Lazy_string as an argument, removed char*/int/double variants
sql/field.h:
  * remove virtual Field::get_time(), everyone should use only Field::get_date()
  * remove lots of #ifdef WORDS_BIGENDIAN
  * unified the warnings from Field_timestamp/datetime/time/date/newdate store methods
  * Field_timestamp_hires, Field_datetime_hires, Field_time_hires
  * Field_temporal
  * make_truncated_value_warning and Field::set_datetime_warning use Lazy_string as an argument, removed char*/int/double variants
  * removed Field::can_be_compared_as_longlong(). Use Field::cmp_type() == INT_RESULT instead
sql/filesort.cc:
  TIME_RESULT, cmp_time()
sql/item.cc:
  * numbers aren't quoted in EXPLAIN EXTENDED
  * Item::cmp_result() instead of Item::is_datetime() and Item::result_as_longlong()
  * virtual Item::get_time() is gone
  * Item_param::field_type() is set correctly
  * Item_datetime, for a datetime constant
  * time to anything is compared as a time
  * Item_cache::print() prints the value is available
  * bug fixed in Item_cache_int::val_str()
sql/item.h:
  * Item::print_value(), to be used from Item_xxx::print() when needed
  * Item::cmp_result() instead of Item::is_datetime() and Item::result_as_longlong()
  * virtual Item::get_time() is gone
  * Item_datetime, for a datetime constant
  * better default for cast_to_int_type()
  * Item_cache objects now *always* have the field_type() set
sql/item_cmpfunc.cc:
  * get_year_value, get_time_value are gone. get_datetime_value does it all
  * get_value_a_func, get_value_b_func are gone
  * can_compare_as_dates() is gone too, TIME_RESULT is used instead
  * cmp_type() instead or result_type() when doing a comparison
  * compare_datetime and compate_e_datetime in the comparator_matrix, is_nulls_eq is gone
  * Item::cmp_result() instead of Item::is_datetime() and Item::result_as_longlong()
sql/item_cmpfunc.h:
  greatly simplified Arg_comparator
sql/item_create.cc:
  * fix a bug in error messages in CAST
sql/item_func.cc:
  Item::cmp_result() instead of Item::is_datetime() and Item::result_as_longlong()
  mention all possibitiles in switch over Item_result values, or use default:
sql/item_row.h:
  overwrite the default cmp_type() for Item_row,
  as no MYSQL_TYPE_xxx value corresponds to ROW_RESULT
sql/item_timefunc.cc:
  rewrite make_datetime to support precision argument
  SEC_TO_TIME is real function, not integer.
  many functions that returned temporal values had duplicate code in val_* methods,
  some of them did not have get_date() which resulted in unnecessary date->str->date conversions. 
  Now they all are derived from Item_temporal_func and *only* provide get_date, not val* methods.
  many fixes to set decimals (datetime precision) correctly.
sql/item_timefunc.h:
  SEC_TO_TIME is real function, not integer.
  many functions that returned temporal values had duplicate code in val_* methods,
  some of them did not have get_date() which resulted in unnecessary date->str->date conversions. 
  Now they all are derived from Item_temporal_func and *only* provide get_date, not val* methods.
  many fixes to set decimals (datetime precision) correctly.
sql/log_event.cc:
  replication of NOW(6)
sql/log_event.h:
  replication of NOW(6)
sql/mysql_priv.h:
  Lazy_string class to pass a value (string, number, time) polymorphically down the stack.
  make_truncated_value_warning() that uses it.
sql/mysqld.cc:
  datetime in Arg_comparator::comparator_matrix
sql/opt_range.cc:
  cleanup: don't disable warnings before calling save_in_field_no_warnings()
sql/protocol.cc:
  Protocol::store(time) now takes the precision as an argument
sql/protocol.h:
  Protocol::store(time) now takes the precision as an argument
sql/rpl_rli.cc:
  small cleanup
sql/set_var.cc:
  SET TIMESTAMP=double
sql/set_var.h:
  @@TIMESTAMP is a double
sql/share/errmsg.txt:
  precision and scale are unsigned
sql/slave.cc:
  replication of NOW(6)
sql/sp_head.cc:
  cleanup
sql/sql_class.cc:
  support for NOW(6)
sql/sql_class.h:
  support for NOW(6)
sql/sql_insert.cc:
  support for NOW(6)
sql/sql_select.cc:
  use item->cmp_type().
  move a comment where it belongs
sql/sql_show.cc:
  new column I_S.COLUMNS.DATETIME_PRECISION
sql/sql_yacc.yy:
  TIME(X), DATETIME(X), cast, NOW(X), CURTIME(X), etc
sql/time.cc:
  fix date_add_interval() to support MYSQL_TIMESTAMP_TIME argument
storage/myisam/ha_myisam.cc:
  TIMESTAMP no longer carries ZEROFIELD flag, still we keep MYI file compatible.
strings/my_vsnprintf.c:
  warnings
tests/mysql_client_test.c:
  old timestamp(X) does not work anymore
  datetime is no longer equal to time
2011-03-01 13:24:36 +01:00
Michael Widenius
3358cdd504 Merge with 5.1 to get in changes from MySQL 5.1.55 2011-02-28 19:39:30 +02:00
Michael Widenius
58bb0769bd Merge with MySQL 5.1.55
- Fixed some issues with partitions and connection_string, which also fixed lp:716890 "Pre- and post-recovery crash in Aria"
- Fixed wrong assert in Aria

Now need to merge with latest xtradb before pushing 

sql/ha_partition.cc:
  Ensure that m_ordered_rec_buffer is not freed before close.
sql/mysqld.cc:
  Changed to use opt_stack_trace instead of opt_pstack.
  Removed references to pstack
sql/partition_element.h:
  Ensure that connect_string is initialized
storage/maria/ma_key_recover.c:
  Fixed wrong assert
2011-02-20 18:51:43 +02:00
Mattias Jonsson
62ab200343 Update of copyright headers for files I changed this year. 2011-01-27 23:47:24 +01:00
Mattias Jonsson
fa8cdca34f Update of copyright headers for files I changed this year. 2011-01-27 23:47:24 +01:00
Mattias Jonsson
bede87d353 merge 2011-01-28 13:28:15 +01:00
Mattias Jonsson
c5e525f879 merge 2011-01-28 13:28:15 +01:00
Michael Widenius
050c004f5e Merge with 5.1
Fixes to get Aria handler tests to work.
Fixes LP#697597 "HANDLER + Aria asserts in maria-5.3-handler"
2011-01-11 15:36:41 +02:00
Georgi Kodinov
b831c6dbbb automerge 2011-01-07 15:28:36 +02:00
Georgi Kodinov
0bb9123f64 automerge 2011-01-07 15:28:36 +02:00
Michael Widenius
215043b7c2 Merge with 5.1 2011-01-05 16:03:58 +02:00
Mattias Jonsson
544451bbd8 merge 2011-01-04 14:13:20 +01:00
Mattias Jonsson
16994abf9a merge 2011-01-04 14:13:20 +01:00
Mattias Jonsson
b56308e63d Manual merge from 5.1 2011-01-10 15:08:31 +01:00
Mattias Jonsson
1a46e493dd Manual merge from 5.1 2011-01-10 15:08:31 +01:00
Kent Boortz
be6c3fd8aa Merge 2010-12-29 01:26:31 +01:00
Kent Boortz
94cde4c951 Merge 2010-12-29 01:26:31 +01:00
Kent Boortz
4acfdb9df1 Merge 2010-12-29 00:47:05 +01:00
Kent Boortz
920d185fd8 Merge 2010-12-29 00:47:05 +01:00
Kent Boortz
85323eda8a - Added/updated copyright headers
- Removed files specific to compiling on OS/2
- Removed files specific to SCO Unix packaging
- Removed "libmysqld/copyright", text is included in documentation
- Removed LaTeX headers for NDB Doxygen documentation
- Removed obsolete NDB files
- Removed "mkisofs" binaries
- Removed the "cvs2cl.pl" script
- Changed a few GPL texts to use "program" instead of "library"
2010-12-28 19:57:23 +01:00
Kent Boortz
fddb1f1b13 - Added/updated copyright headers
- Removed files specific to compiling on OS/2
- Removed files specific to SCO Unix packaging
- Removed "libmysqld/copyright", text is included in documentation
- Removed LaTeX headers for NDB Doxygen documentation
- Removed obsolete NDB files
- Removed "mkisofs" binaries
- Removed the "cvs2cl.pl" script
- Changed a few GPL texts to use "program" instead of "library"
2010-12-28 19:57:23 +01:00
Igor Babaev
efbb3c6c90 Fixed LP bug #639935 (bug #58727).
When the optimizer creates items out of other items it does
not have to call the fix_fields method. Usually in these
cases it calls quick_fix_field() that just marks the 
created item as fixed. If the created item is an Item_func
object then calling quick_fix_field() works fine if the
arguments of the created functional item are already fixed.
Otherwise some unfixed nodes remain in the item tree and
it triggers an assertion failure whenever the item is 
evaluated.

Fixed the problem by making the method quick_fix_field
virtual and providing an implementation for the class
Item_func objects that recursively calls the method
for unfixed arguments of any functional item.
2010-12-24 15:30:23 -08:00
Mattias Jonsson
8715503810 Bug#54483: valgrind errors when making warnings for
multiline inserts into partition
Bug#57071: EXTRACT(WEEK from date_col) cannot be
allowed as partitioning function

Renamed function according to reviewers comments.

sql/item.h:
  better name of processor function
sql/item_func.h:
  better name of processor function
sql/item_timefunc.h:
  better name of processor function
sql/sql_partition.cc:
  better name of processor function
  Updated comment.
2010-12-22 15:45:17 +01:00
Mattias Jonsson
9918153522 Bug#54483: valgrind errors when making warnings for
multiline inserts into partition
Bug#57071: EXTRACT(WEEK from date_col) cannot be
allowed as partitioning function

Renamed function according to reviewers comments.
2010-12-22 15:45:17 +01:00
Mattias Jonsson
1615419d72 Bug#54483: valgrind errors when making warnings for multiline inserts into partition
Bug#57071: EXTRACT(WEEK from date_col) cannot be allowed as partitioning function

There were functions allowed as partitioning functions
that implicit allowed cast. That could result in unacceptable
behaviour.

Solution was to check that the arguments of date and time functions
have allowed types (field and date/datetime/time depending on function).

mysql-test/r/partition.result:
  Updated result
mysql-test/r/partition_error.result:
  Updated result
mysql-test/suite/parts/inc/part_supported_sql_funcs_main.inc:
  disabled test with not allowed arguments.
mysql-test/suite/parts/r/part_supported_sql_func_innodb.result:
  Updated result
mysql-test/suite/parts/r/part_supported_sql_func_myisam.result:
  Updated result
mysql-test/t/partition.test:
  Fixed typo in bug number and removed non allowed function (bad argument)
mysql-test/t/partition_error.test:
  Added tests to verify correct type of argument.
sql/item.h:
  Renamed processor since it is no longer only for timezone
sql/item_func.h:
  Added help functions for checking date/time/datetime arguments.
sql/item_timefunc.h:
  Added processors for argument correctness
sql/sql_partition.cc:
  renamed the processor for checking arguments.
2010-12-22 10:50:36 +01:00
Mattias Jonsson
966d0ebaf3 Bug#54483: valgrind errors when making warnings for multiline inserts into partition
Bug#57071: EXTRACT(WEEK from date_col) cannot be allowed as partitioning function

There were functions allowed as partitioning functions
that implicit allowed cast. That could result in unacceptable
behaviour.

Solution was to check that the arguments of date and time functions
have allowed types (field and date/datetime/time depending on function).
2010-12-22 10:50:36 +01:00
Michael Widenius
b7b25dc666 Merge with 5.1-release.
- Fixed problem with oqgraph and 'make dist'

Note that after this merge we have a problem show in join_outer where we examine too many rows in one specific case (related to BUG#57024).
This will be fixed when mwl#128 is merged into 5.3.
2010-12-06 10:25:44 +02:00
Georgi Kodinov
a4b106c882 Backport of bug #55564 to 5.0-security 2010-12-03 16:56:36 +02:00
Georgi Kodinov
5df7f9bc26 Backport of bug #55564 to 5.0-security 2010-12-03 16:56:36 +02:00
Michael Widenius
1e5061fe3b merge with 5.1 2010-11-30 23:11:03 +02:00
Georgi Kodinov
6fe1b33f20 merge 2010-11-26 16:32:51 +02:00
Georgi Kodinov
96d45ed2f6 merge 2010-11-26 16:32:51 +02:00
Sergei Golubchik
65ca700def merge.
checkpoint.
does not compile.
2010-11-25 18:17:28 +01:00
Michael Widenius
1a6373e8e2 Merge with MySQL 5.1.53
Open issues:
- A better fix for #57688; Igor is working on this
- Test failure in index_merge_innodb.test ; Igor promised to look at this
- Some Innodb tests fails (need to merge with latest xtradb) ; Kristian promised to look at this.
 - Failing tests: innodb_plugin.innodb_bug56143 innodb_plugin.innodb_bug56632 innodb_plugin.innodb_bug56680 innodb_plugin.innodb_bug57255 
- Werror is disabled;  Should be enabled after merge with xtradb.
2010-11-25 00:57:34 +02:00
Sergei Golubchik
bc2e383e4a mysql-5.1 -> mysql-5.5 merge 2010-11-05 10:59:51 +01:00
Sergei Golubchik
8e7ebfbce8 5.2 merge 2010-10-28 19:04:23 +02:00
Sergei Golubchik
04a4b43346 merge with 5.1 2010-10-25 15:21:16 +02:00
Sergei Golubchik
745cc74c33 5.1.51 merge 2010-10-19 15:58:35 +02:00
Sergey Glukhov
127c721cef Bug#54484 explain + prepared statement: crash and Got error -1 from storage engine
Subquery executes twice, at top level JOIN::optimize and ::execute stages.
At first execution create_sort_index() function is called and
FT_SELECT object is created and destroyed. HANDLER::ft_handler is cleaned up
in the object destructor and at second execution FT_SELECT::get_next() method
returns error.
The fix is to reinit HANDLER::ft_handler field before re-execution of subquery.


mysql-test/r/fulltext.result:
  test case
mysql-test/t/fulltext.test:
  test case
sql/item_func.cc:
  reinit ft_handler before re-execution of subquery
sql/item_func.h:
  Fixed method name
sql/sql_select.cc:
  reinit ft_handler before re-execution of subquery
2010-10-18 14:47:26 +04:00
Sergey Glukhov
9a8f22fa2d Bug#54484 explain + prepared statement: crash and Got error -1 from storage engine
Subquery executes twice, at top level JOIN::optimize and ::execute stages.
At first execution create_sort_index() function is called and
FT_SELECT object is created and destroyed. HANDLER::ft_handler is cleaned up
in the object destructor and at second execution FT_SELECT::get_next() method
returns error.
The fix is to reinit HANDLER::ft_handler field before re-execution of subquery.
2010-10-18 14:47:26 +04:00
Sergey Petrunya
72dd7575cd Merge 5.2->5.3
- Re-commit Monty's merge, partially fixed by Igor and SergeyP, 
  but still broken
2010-10-10 17:18:11 +03:00
Michael Widenius
bdba1d11c4 Change some my_bool in C++ classes and a few functions to bool to detect wrong usage of bool/my_bool.
Fix some bugs where we stored values other than 0 or 1 in my_bool
Fixed some compiler warnings


client/mysql.cc:
  Changed interrupted_query from my_bool to int, as we stored 2 in it.
client/mysqladmin.cc:
  Changed return variable type to same type as function value type
client/mysqltest.cc:
  Changed 'found' to int as we store other values than 0 or 1 into it
  Changed type for parameter of set_reconnect() to match usage.
extra/libevent/evbuffer.c:
  Added __attribute__((unused))
extra/libevent/event.c:
  Added __attribute__((unused))
extra/libevent/signal.c:
  Added __attribute__((unused))
sql/event_data_objects.h:
  my_bool -> bool
sql/event_db_repository.cc:
  my_bool -> bool
sql/event_db_repository.h:
  my_bool -> bool
sql/event_parse_data.h:
  my_bool -> bool
sql/events.cc:
  my_bool -> bool
sql/events.h:
  my_bool -> bool
sql/field.cc:
  my_bool -> bool
sql/field.h:
  my_bool -> bool
sql/hash_filo.h:
  my_bool -> bool
sql/item.cc:
  my_bool -> bool
sql/item.h:
  my_bool -> bool
sql/item_cmpfunc.h:
  my_bool -> bool
  Changed result_for_null_param from my_bool to int as we stored -1 in it.
sql/item_func.cc:
  my_bool -> bool
  Modified udf wrapper functions so that the UDF functions would continue to use my_bool. (To keep compatibility with UDF:s)
sql/item_func.h:
  my_bool -> bool
sql/item_subselect.h:
  my_bool -> bool
sql/item_sum.cc:
  Modified udf wrapper functions so that the UDF functions would continue to use my_bool. (To keep compatibility with UDF:s)
sql/parse_file.h:
  my_bool -> bool
sql/rpl_mi.h:
  my_bool -> bool
sql/sp_rcontext.h:
  my_bool -> bool
sql/sql_analyse.h:
  my_bool -> bool
sql/sql_base.cc:
  Change some assignments so that we don't initialize bool variables with int's.
sql/sql_bitmap.h:
  my_bool -> bool
sql/sql_cache.cc:
  my_bool -> bool
sql/sql_cache.h:
  my_bool -> bool
sql/sql_class.h:
  my_bool -> bool
sql/sql_insert.cc:
  Change some assignments so that we don't initialize bool variables with int's.
sql/sql_prepare.cc:
  my_bool -> bool
sql/table.h:
  my_bool -> bool
storage/maria/ma_check.c:
  Removed duplicate assignment
strings/decimal.c:
  Fixed wrong variable usage.
  Don't do complex arithmetic on bool when simple works.
2010-09-24 01:00:32 +03:00
Michael Widenius
58a75bb18b Automerge with 5.1 2010-08-25 01:44:50 +03:00
Michael Widenius
b6fe4713fe Fix for LP#612894 Some aggregate functions (such as MIN MAX) work incorrectly in subqueries after getting NULL value
mysql-test/r/group_by.result:
  Added test that showed problems that no_rows_in_results() didn't work for expressions
mysql-test/r/subselect4.result:
  Test case for LP#612894
mysql-test/t/group_by.test:
  Added test that showed problems that no_rows_in_results() didn't work for expressions
mysql-test/t/subselect4.test:
  Test case for LP#612894
sql/item.h:
  Added restore_to_before_no_rows_in_result()
  Added function processor for no_rows_in_results() and restore_to_before_no_rows_in_results() to ensure it works with functions
  Fix that above functions are handled by Item_ref()
sql/item_func.h:
  Ensure that no_rows_in_results() and restore_to_before_no_rows_in_result() are called for all function arguments
sql/item_sum.cc:
  Added restore_to_before_no_rows_in_result() to restore settings after Item_sum_hybrid::no_rows_in_result() was called.
  This is needed to handle the case where we have made 'make_const()' on the item in opt_sum(), but the item will be reused again in a sub query.
  Ignore multiple calls to no_rows_in_result() as Item_ref is calling it twice.
sql/item_sum.h:
  Added restore_to_before_no_rows_in_result();
sql/sql_select.cc:
  Added reset of no_rows_in_result() for JOIN::reinit()
sql/sql_select.h:
  Added marker if no_rows_in_result() is called.
2010-08-23 12:46:25 +03:00
Georgi Kodinov
53e0b31e9c merge 2010-08-13 14:20:49 +03:00
Georgi Kodinov
2ecc81cb30 merge 2010-08-13 14:20:49 +03:00
Georgi Kodinov
4bf81165e4 Bug #55615 and bug #55564
An user assignment variable expression that's 
evaluated in a logical expression context 
(Item::val_bool()) can be pre-calculated in a 
temporary table for GROUP BY.
However when the expression value is used after the
temp table creation it was re-evaluated instead of
being read from the temp table due to a missing 
val_bool_result() method.
Fixed by implementing the method.
2010-08-13 14:18:46 +03:00
Georgi Kodinov
a557509653 Bug #55615 and bug #55564
An user assignment variable expression that's 
evaluated in a logical expression context 
(Item::val_bool()) can be pre-calculated in a 
temporary table for GROUP BY.
However when the expression value is used after the
temp table creation it was re-evaluated instead of
being read from the temp table due to a missing 
val_bool_result() method.
Fixed by implementing the method.
2010-08-13 14:18:46 +03:00
Igor Babaev
709a0a1310 MWL#106: Backport optimizations for derived tables and views.
The main consolidated patch.
2010-05-26 13:18:18 -07:00
Alexander Barkov
3c93a784d4 Bug#51571 load xml infile causes server crash
Problem:
  item->name was NULL for Item_user_var_as_out_param
  which made strcmp(something, item->name) crash in the LOAD XML code.
  
  Fix:
  - item_func.h: Adding set_name() in constuctor for Item_user_var_as_out_param
  - sql_load.cc: Changing the condition in write_execute_load_query_log_event() which
  distiguished between Item_user_var_as_out_param and Item_field
  from
    if (item->name == NULL)
  to
    if (item->type() == Item::FIELD_ITEM)
  - loadxml.result, loadxml.test: adding tests
2010-05-05 14:34:20 +04:00
Alexander Barkov
25d31b8f7c Bug#51571 load xml infile causes server crash
Problem:
  item->name was NULL for Item_user_var_as_out_param
  which made strcmp(something, item->name) crash in the LOAD XML code.
  
  Fix:
  - item_func.h: Adding set_name() in constuctor for Item_user_var_as_out_param
  - sql_load.cc: Changing the condition in write_execute_load_query_log_event() which
  distiguished between Item_user_var_as_out_param and Item_field
  from
    if (item->name == NULL)
  to
    if (item->type() == Item::FIELD_ITEM)
  - loadxml.result, loadxml.test: adding tests
2010-05-05 14:34:20 +04:00
Mats Kindahl
23d8586dbf WL#5030: Split and remove mysql_priv.h
This patch:

- Moves all definitions from the mysql_priv.h file into
  header files for the component where the variable is
  defined
- Creates header files if the component lacks one
- Eliminates all include directives from mysql_priv.h
- Eliminates all circular include cycles
- Rename time.cc to sql_time.cc
- Rename mysql_priv.h to sql_priv.h
2010-03-31 16:05:33 +02:00
Mats Kindahl
e409d6f69c WL#5030: Split and remove mysql_priv.h
This patch:

- Moves all definitions from the mysql_priv.h file into
  header files for the component where the variable is
  defined
- Creates header files if the component lacks one
- Eliminates all include directives from mysql_priv.h
- Eliminates all circular include cycles
- Rename time.cc to sql_time.cc
- Rename mysql_priv.h to sql_priv.h
2010-03-31 16:05:33 +02:00
Sergey Petrunya
7df026676b Merge MariaDB-5.2 -> MariaDB 5.3 2010-03-20 15:01:47 +03:00
Alexey Kopytov
72afe82ab9 Manual merge. 2010-03-19 11:29:12 +03:00
Alexey Kopytov
53afccc829 Manual merge. 2010-03-19 11:29:12 +03:00
Alexey Kopytov
2acfdc5092 Bug #8433: Overflow must be an error
All numeric operators and functions on integer, floating point 
and DECIMAL values now throw an 'out of range' error rather 
than returning an incorrect value or NULL,  when the result is 
out of supported range for the corresponding data type. 
 
Some test cases in the test suite had to be updated 
accordingly either because the test case itself relied on a 
value returned in case of a numeric overflow, or because a 
numeric overflow was the root cause of the corresponding bugs. 
The latter tests are no longer relevant, since the expressions 
used to trigger the corresponding bugs are not valid anymore. 
However, such test cases have been adjusted and kept "for the 
record". 

mysql-test/r/func_math.result:
  Added test cases for bug #8433. 
  Updated results of the test case for bug #31236.
mysql-test/r/func_misc.result:
  Streamlined test cases.
mysql-test/r/func_test.result:
  Streamlined test cases.
mysql-test/r/select.result:
  Streamlined test cases.
mysql-test/r/sp.result:
  Streamlined test cases.
mysql-test/r/strict.result:
  Streamlined test cases.
mysql-test/r/type_newdecimal.result:
  Streamlined test cases.
mysql-test/suite/sys_vars/r/sql_slave_skip_counter_basic.result:
  Streamlined test cases.
mysql-test/suite/sys_vars/t/sql_slave_skip_counter_basic.test:
  Streamlined test cases.
mysql-test/t/func_math.test:
  Added test cases for bug #8433. 
  Updated results of the test case for bug #31236.
mysql-test/t/func_misc.test:
  Streamlined test cases.
mysql-test/t/func_test.test:
  Streamlined test cases.
mysql-test/t/select.test:
  Streamlined test cases.
mysql-test/t/sp.test:
  Streamlined test cases.
mysql-test/t/strict.test:
  Streamlined test cases.
mysql-test/t/type_newdecimal.test:
  Streamlined test cases.
sql/item_create.cc:
  Changed Item_func_cot() to be defined as a standalone Item
  rather than a combination of "1 / TAN(x)".
sql/item_func.cc:
  Throw an 'out of range' error rather than returning an  
  incorrect value or NULL,  when the result of a numeric 
  operator or a function is out of supported range for  
  the corresponding data type.
sql/item_func.h:
  Added validation helpers as inline methods of Item_func.
sql/share/errmsg-utf8.txt:
  New ER_DATA_OUT_OF_RANGE error.
2010-03-18 13:38:29 +03:00
Alexey Kopytov
aef97cadfa Bug #8433: Overflow must be an error
All numeric operators and functions on integer, floating point 
and DECIMAL values now throw an 'out of range' error rather 
than returning an incorrect value or NULL,  when the result is 
out of supported range for the corresponding data type. 
 
Some test cases in the test suite had to be updated 
accordingly either because the test case itself relied on a 
value returned in case of a numeric overflow, or because a 
numeric overflow was the root cause of the corresponding bugs. 
The latter tests are no longer relevant, since the expressions 
used to trigger the corresponding bugs are not valid anymore. 
However, such test cases have been adjusted and kept "for the 
record".
2010-03-18 13:38:29 +03:00
Sergei Golubchik
f09ca00e08 merged 2010-03-15 12:51:23 +01:00
unknown
4bf849c23c Merge MySQL 5.1.44 into MariaDB. 2010-03-04 09:03:07 +01:00
Alexander Barkov
702166bcde WL#2649 Number-to-string conversions
added:
  include/ctype_numconv.inc
  mysql-test/include/ctype_numconv.inc
  mysql-test/r/ctype_binary.result
  mysql-test/t/ctype_binary.test
  Adding tests

modified:

  mysql-test/r/bigint.result
  mysql-test/r/case.result
  mysql-test/r/create.result
  mysql-test/r/ctype_cp1251.result
  mysql-test/r/ctype_latin1.result
  mysql-test/r/ctype_ucs.result
  mysql-test/r/func_gconcat.result
  mysql-test/r/func_str.result
  mysql-test/r/metadata.result
  mysql-test/r/ps_1general.result
  mysql-test/r/ps_2myisam.result
  mysql-test/r/ps_3innodb.result
  mysql-test/r/ps_4heap.result
  mysql-test/r/ps_5merge.result
  mysql-test/r/show_check.result
  mysql-test/r/type_datetime.result
  mysql-test/r/type_ranges.result
  mysql-test/r/union.result
  mysql-test/suite/ndb/r/ps_7ndb.result
  mysql-test/t/ctype_cp1251.test
  mysql-test/t/ctype_latin1.test
  mysql-test/t/ctype_ucs.test
  mysql-test/t/func_str.test
    Fixing tests


  @ sql/field.cc
     - Return str result using my_charset_numeric.
     - Using real multi-byte aware str_to_XXX functions
       to handle tricky charset values propely (e.g. UCS2)
  @ sql/field.h
     - Changing derivation of non-string field types to DERIVATION_NUMERIC.
     - Changing binary() for numeric/datetime fields to always
     return TRUE even if charset is not my_charset_bin. We need
     this to keep ha_base_keytype() return HA_KEYTYPE_BINARY.
     - Adding BINARY_FLAG into some fields, because it's not
     being set automatically anymore with
     "my_charset_bin to my_charset_numeric" change.
    - Changing derivation for numeric/datetime datatypes to a weaker
      value, to make "SELECT concat('string', field)" use character
      set of the string literal for the result of the function.
  @ sql/item.cc
     - Implementing generic val_str_ascii().
     - Using max_char_length() instead of direct read of max_length
       to make "tricky" charsets like UCS2 work.
       NOTE: in the future we'll possibly remove all direct reads of max_length
     - Fixing Item_num::safe_charset_converter().
       Previously it alligned binary string to
       character string (for example by adding leading 0x00
       when doing binary->UCS2 conversion). Now it just
       converts from my_charset_numbner to "tocs".
     - Using val_str_ascii() in Item::get_time() to make UCS2 arguments work.
     - Other misc changes
  @ sql/item.h
     - Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to
       bit operations instead of hard-coded bit masks.
     - Addding new method DTCollation.set_numeric().
     - Adding new methods to Item.
     - Adding helper functions to make code look nicer:
       agg_item_charsets_for_string_result()
       agg_item_charsets_for_comparison()
     - Changing charset for Item_num-derived items
       from my_charset_bin to my_charset_numeric
       (which is an alias for latin1).
  @ sql/item_cmpfunc.cc
     - Using new helper functions
     - Other misc changes
  @ sql/item_cmpfunc.h
     - Fixing strcmp() to return max_length=2.
       Previously it returned 1, which was wrong,
       because it did not fit '-1'.
  @ sql/item_func.cc
     - Using new helper functions
     - Other minor changes
  @ sql/item_func.h
     - Removing unused functions
     - Adding helper functions
       agg_arg_charsets_for_string_result()
       agg_arg_charsets_for_comparison()
     - Adding set_numeric() into constructors of numeric items.
     - Using fix_length_and_charset() and fix_char_length()
       instead of direct write to max_length.
  @ sql/item_geofunc.cc
     - Changing class for Item_func_geometry_type and
       Item_func_as_wkt from Item_str_func to
       Item_str_ascii_func, to make them return UCS2 result
       properly (when character_set_connection=ucs2).
  @ sql/item_geofunc.h
     - Changing class for Item_func_geometry_type and
       Item_func_as_wkt from Item_str_func to
       Item_str_ascii_func, to make them return UCS2 result
       properly (when @@character_set_connection=ucs2).
  @ sql/item_strfunc.cc
     - Implementing Item_str_func::val_str().
     - Renaming val_str to val_str_ascii for some items,
       to make them work with UCS2 properly.
     - Using new helper functions
     - All single-argument functions that expect string
       result now call this method:
       agg_arg_charsets_for_string_result(collation, args, 1);
       This enables character set conversion to @@character_set_connection
       in case of pure numeric input.
  @ sql/item_strfunc.h
     - Introducing Item_str_ascii_func - for functions
       which return pure ASCII data, for performance purposes,
       as well as for the cases when the old implementation
       of val_str() was heavily 8-bit oriented and implementing
       a UCS2-aware version is tricky.
  @ sql/item_sum.cc
     - Using new helper functions.
  @ sql/item_timefunc.cc
     - Using my_charset_numeric instead of my_charset_bin.
     - Using fix_char_length(), fix_length_and_charset()
       and fix_length_and_charset_datetime()
       instead of direct write to max_length.
     - Using tricky-charset aware function str_to_time_with_warn()
  @ sql/item_timefunc.h
     - Using new helper functions for charset and length initialization.
     - Changing base class for Item_func_get_format() to make
       it return UCS2 properly (when character_set_connection=ucs2).
  @ sql/item_xmlfunc.cc
     - Using new helper function
  @ sql/my_decimal.cc
     - Adding a new DECIMAL to CHAR converter
       with real multibyte support (e.g. UCS2)

  @ sql/mysql_priv.h
     - Introducing a new derivation level for numeric/datetime data types.
     - Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC.
     - Adding prototypes for str_set_decimal()
     - Adding prototypes for character-set aware str_to_xxx() functions.
  @ sql/protocol.cc
     - Changing charsetnr to "binary" client-side metadata for
       numeric/datetime data types.
  @ sql/time.cc
     - Adding to_ascii() helper function, to convert a string
       in any character set to ascii representation. In the
       future can be extended to understand digits written
       in various non-Latin word scripts.
     - Adding real multy-byte character set aware versions for str_to_XXXX,
       to make these these type of queries work correct:
         INSERT INTO t1 SET datetime_column=ucs2_expression;
   @  strings/ctype-ucs2.c
     - endptr was not calculated correctly. INSERTing of UCS2
       values into numeric columns returned warnings about
       truncated wrong data.
2010-02-11 08:17:25 +04:00
Alexander Barkov
1094ffd572 WL#2649 Number-to-string conversions
added:
  include/ctype_numconv.inc
  mysql-test/include/ctype_numconv.inc
  mysql-test/r/ctype_binary.result
  mysql-test/t/ctype_binary.test
  Adding tests

modified:

  mysql-test/r/bigint.result
  mysql-test/r/case.result
  mysql-test/r/create.result
  mysql-test/r/ctype_cp1251.result
  mysql-test/r/ctype_latin1.result
  mysql-test/r/ctype_ucs.result
  mysql-test/r/func_gconcat.result
  mysql-test/r/func_str.result
  mysql-test/r/metadata.result
  mysql-test/r/ps_1general.result
  mysql-test/r/ps_2myisam.result
  mysql-test/r/ps_3innodb.result
  mysql-test/r/ps_4heap.result
  mysql-test/r/ps_5merge.result
  mysql-test/r/show_check.result
  mysql-test/r/type_datetime.result
  mysql-test/r/type_ranges.result
  mysql-test/r/union.result
  mysql-test/suite/ndb/r/ps_7ndb.result
  mysql-test/t/ctype_cp1251.test
  mysql-test/t/ctype_latin1.test
  mysql-test/t/ctype_ucs.test
  mysql-test/t/func_str.test
    Fixing tests


  @ sql/field.cc
     - Return str result using my_charset_numeric.
     - Using real multi-byte aware str_to_XXX functions
       to handle tricky charset values propely (e.g. UCS2)
  @ sql/field.h
     - Changing derivation of non-string field types to DERIVATION_NUMERIC.
     - Changing binary() for numeric/datetime fields to always
     return TRUE even if charset is not my_charset_bin. We need
     this to keep ha_base_keytype() return HA_KEYTYPE_BINARY.
     - Adding BINARY_FLAG into some fields, because it's not
     being set automatically anymore with
     "my_charset_bin to my_charset_numeric" change.
    - Changing derivation for numeric/datetime datatypes to a weaker
      value, to make "SELECT concat('string', field)" use character
      set of the string literal for the result of the function.
  @ sql/item.cc
     - Implementing generic val_str_ascii().
     - Using max_char_length() instead of direct read of max_length
       to make "tricky" charsets like UCS2 work.
       NOTE: in the future we'll possibly remove all direct reads of max_length
     - Fixing Item_num::safe_charset_converter().
       Previously it alligned binary string to
       character string (for example by adding leading 0x00
       when doing binary->UCS2 conversion). Now it just
       converts from my_charset_numbner to "tocs".
     - Using val_str_ascii() in Item::get_time() to make UCS2 arguments work.
     - Other misc changes
  @ sql/item.h
     - Changing MY_COLL_CMP_CONV and MY_COLL_ALLOW_CONV to
       bit operations instead of hard-coded bit masks.
     - Addding new method DTCollation.set_numeric().
     - Adding new methods to Item.
     - Adding helper functions to make code look nicer:
       agg_item_charsets_for_string_result()
       agg_item_charsets_for_comparison()
     - Changing charset for Item_num-derived items
       from my_charset_bin to my_charset_numeric
       (which is an alias for latin1).
  @ sql/item_cmpfunc.cc
     - Using new helper functions
     - Other misc changes
  @ sql/item_cmpfunc.h
     - Fixing strcmp() to return max_length=2.
       Previously it returned 1, which was wrong,
       because it did not fit '-1'.
  @ sql/item_func.cc
     - Using new helper functions
     - Other minor changes
  @ sql/item_func.h
     - Removing unused functions
     - Adding helper functions
       agg_arg_charsets_for_string_result()
       agg_arg_charsets_for_comparison()
     - Adding set_numeric() into constructors of numeric items.
     - Using fix_length_and_charset() and fix_char_length()
       instead of direct write to max_length.
  @ sql/item_geofunc.cc
     - Changing class for Item_func_geometry_type and
       Item_func_as_wkt from Item_str_func to
       Item_str_ascii_func, to make them return UCS2 result
       properly (when character_set_connection=ucs2).
  @ sql/item_geofunc.h
     - Changing class for Item_func_geometry_type and
       Item_func_as_wkt from Item_str_func to
       Item_str_ascii_func, to make them return UCS2 result
       properly (when @@character_set_connection=ucs2).
  @ sql/item_strfunc.cc
     - Implementing Item_str_func::val_str().
     - Renaming val_str to val_str_ascii for some items,
       to make them work with UCS2 properly.
     - Using new helper functions
     - All single-argument functions that expect string
       result now call this method:
       agg_arg_charsets_for_string_result(collation, args, 1);
       This enables character set conversion to @@character_set_connection
       in case of pure numeric input.
  @ sql/item_strfunc.h
     - Introducing Item_str_ascii_func - for functions
       which return pure ASCII data, for performance purposes,
       as well as for the cases when the old implementation
       of val_str() was heavily 8-bit oriented and implementing
       a UCS2-aware version is tricky.
  @ sql/item_sum.cc
     - Using new helper functions.
  @ sql/item_timefunc.cc
     - Using my_charset_numeric instead of my_charset_bin.
     - Using fix_char_length(), fix_length_and_charset()
       and fix_length_and_charset_datetime()
       instead of direct write to max_length.
     - Using tricky-charset aware function str_to_time_with_warn()
  @ sql/item_timefunc.h
     - Using new helper functions for charset and length initialization.
     - Changing base class for Item_func_get_format() to make
       it return UCS2 properly (when character_set_connection=ucs2).
  @ sql/item_xmlfunc.cc
     - Using new helper function
  @ sql/my_decimal.cc
     - Adding a new DECIMAL to CHAR converter
       with real multibyte support (e.g. UCS2)

  @ sql/mysql_priv.h
     - Introducing a new derivation level for numeric/datetime data types.
     - Adding macros for my_charset_numeric and MY_REPERTOIRE_NUMERIC.
     - Adding prototypes for str_set_decimal()
     - Adding prototypes for character-set aware str_to_xxx() functions.
  @ sql/protocol.cc
     - Changing charsetnr to "binary" client-side metadata for
       numeric/datetime data types.
  @ sql/time.cc
     - Adding to_ascii() helper function, to convert a string
       in any character set to ascii representation. In the
       future can be extended to understand digits written
       in various non-Latin word scripts.
     - Adding real multy-byte character set aware versions for str_to_XXXX,
       to make these these type of queries work correct:
         INSERT INTO t1 SET datetime_column=ucs2_expression;
   @  strings/ctype-ucs2.c
     - endptr was not calculated correctly. INSERTing of UCS2
       values into numeric columns returned warnings about
       truncated wrong data.
2010-02-11 08:17:25 +04:00
unknown
e5099a2c85 merge 5.1->5.2 2010-02-01 08:14:12 +02:00
Sergey Petrunya
f47b2d38f6 Subquery optimizations: non-semijoin materialization
- Backport into Maria DB 5.3, part 1
2010-01-28 16:48:33 +03:00
Sergey Petrunya
b83cb52e9e Backport of subquery optimizations to 5.3.
There are still test failures because of:
- Wrong query results in outer join + semi join
- EXPLAIN output differences
2010-01-17 17:51:10 +03:00
Michael Widenius
d8ecbbe634 Merge with MySQL 5.1.42
- Marked a couple of tests with --big
- Fixed xtradb/handler/ha_innodb.cc to call explain_filename()

storage/xtradb/handler/ha_innodb.cc:
  Call explain_filename() to get proper names for partitioned tables
2010-01-15 17:27:55 +02:00
Alexey Kopytov
3ba6a2a9fa Manual merge of mysql-5.1-bugteam into mysql-trunk-merge.
Conflicts:

mysql-test/collections/default.experimental
2009-12-25 13:56:50 +03:00
Alexey Kopytov
24fc798fc7 Manual merge of mysql-5.1-bugteam into mysql-trunk-merge.
Conflicts:

mysql-test/collections/default.experimental
2009-12-25 13:56:50 +03: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
Georgi Kodinov
ef22a7bfb9 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
Alexey Kopytov
f1e83a4163 Manual merge of mysql-5.1-bugteam into mysql-trunk-merge. 2009-12-16 16:47:07 +03:00
Alexey Kopytov
efe6195858 Manual merge of mysql-5.1-bugteam into mysql-trunk-merge. 2009-12-16 16:47:07 +03:00
Alexey Kopytov
d65fdb3168 Automerge 2009-12-13 23:57:57 +03:00
Alexey Kopytov
4a12f66cc9 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
Alexey Kopytov
a8cfe3d4f7 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.
2009-12-13 23:29:50 +03:00
Alexander Nozdrin
5676713687 Manual merge from mysql-trunk.
Conflicts:
  - client/mysqltest.cc
  - mysql-test/collections/default.experimental
  - mysql-test/suite/rpl/t/disabled.def
  - sql/mysqld.cc
  - sql/opt_range.cc
  - sql/sp.cc
  - sql/sql_acl.cc
  - sql/sql_partition.cc
  - sql/sql_table.cc
2009-12-11 12:39:38 +03:00
Alexander Nozdrin
69cfd5c8ec Manual merge from mysql-trunk.
Conflicts:
  - client/mysqltest.cc
  - mysql-test/collections/default.experimental
  - mysql-test/suite/rpl/t/disabled.def
  - sql/mysqld.cc
  - sql/opt_range.cc
  - sql/sp.cc
  - sql/sql_acl.cc
  - sql/sql_partition.cc
  - sql/sql_table.cc
2009-12-11 12:39:38 +03:00
unknown
08e4635fba merge 5.1-> 5.2 2009-12-08 23:47:54 +02:00
Evgeny Potemkin
9f638f535e Manual merge of the fix for bug#43668. 2009-11-24 18:26:13 +03:00
Evgeny Potemkin
438b795ff7 Manual merge of the fix for bug#43668. 2009-11-24 18:26:13 +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
Evgeny Potemkin
726e83907c 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.
2009-11-17 17:06:46 +03:00
unknown
a962160eec Merge with MySQL 5.1, with following additions:
- Moved some code from innodb_plugin to xtradb, to ensure that all tests runs
- Did changes in pbxt and maria storage engines becasue of changes in thd->query
- Reverted wrong code in sql_table.cc for how ROW_FORMAT is used.

This is a re-commit of Monty's merge to eliminate an extra commit from
MySQL-5.1.42 that was accidentally included in the merge.

This is a merge of the MySQL 5.1.41 clone-off (clone-5.1.41-build). In
case there are any extra changes done before final MySQL 5.1.41
release, these will need to be merged later before MariaDB 5.1.41
release.
2009-11-16 21:49:51 +01:00
Igor Babaev
d749c7e600 Merge 2009-11-09 18:32:39 -08:00
Alexander Nozdrin
7cd11f45be Manual merge from mysql-trunk-merge. 2009-11-06 17:20:27 +03:00
Alexander Nozdrin
2ca5b2c791 Manual merge from mysql-trunk-merge. 2009-11-06 17:20:27 +03:00
Davi Arnaut
1ca80ed19e Bug#48370: Absolutely wrong calculations with GROUP BY and decimal fields when using IF
Bug#45261: Crash, stored procedure + decimal

Revert fix for Bug#45261 due to unforeseen bugs.
2009-11-02 09:21:39 -02:00
Davi Arnaut
9a08362897 Bug#48370: Absolutely wrong calculations with GROUP BY and decimal fields when using IF
Bug#45261: Crash, stored procedure + decimal

Revert fix for Bug#45261 due to unforeseen bugs.
2009-11-02 09:21:39 -02:00
Igor Babaev
f7a75b999b The main commit of Andrey Zhakov's patch introducing vurtual(computed) columns.
The original patch has been ameliorated by Sanja and Igor.
2009-10-16 15:57:48 -07:00
unknown
6aad537a6a Merge MySQL 5.1.39 into MariaDB 5.1. 2009-10-15 23:38:29 +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
4ad8ef0602 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
Sergey Petrunya
29f0dcb563 Merge MySQL->MariaDB
* Finished Monty and Jani's merge
* Some InnoDB tests still fail (because it's old xtradb code run against
  newer testsuite). They are expected to go after mergning with the latest
  xtradb.
2009-09-08 00:50:10 +04: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
Davi Arnaut
31afccc407 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.
2009-08-24 16:47:08 -03:00
Anurag Shekhar
0ad57bef5d merging with 5.0 bugteam tree 2009-07-15 15:43:45 +05:30
Anurag Shekhar
c77b836ab8 Bug#37740 Server crashes on execute statement with full text search and
match against.


Server crashes when executing prepared statement with duplicating
MATCH() function calls in SELECT and ORDER BY expressions, e.g.:
SELECT MATCH(a) AGAINST('test') FROM t1 ORDER BY MATCH(a) AGAINST('test')

This query gets optimized by the server, so the value returned
by MATCH() from the SELECT list is reused for ORDER BY purposes.
To make this optimization server is comparing items from
SELECT and ORDER BY lists. We were getting server crash because
comparision function for MATCH() item is not intended to be called
at this point of execution.

In 5.0 and 5.1 this problem is workarounded by resetting MATCH()
item to the state as it was during PREPARE.

In 6.0 correct comparision function will be implemented and
duplicating MATCH() items from the ORDER BY list will be
optimized.

mysql-test/r/fulltext.result:
  Updated with the test case for Bug#37740
mysql-test/t/fulltext.test:
  A test case for Bug#37740.
sql/item_func.h:
  True initialization of 'table' happens in ::fix_fields(). As
  Item_func_match::eq() may be called before ::fix_fields(), it is
  expected that 'table' is initialized to 0 when it is reused.
  
  This is mostly affecting prepared statements, when the same item
  doesn't get destroyed, but rather cleaned up and reused.
2009-07-15 15:00:58 +05:30
Anurag Shekhar
064c990b12 merging with 5.0 bugteam tree 2009-07-15 15:43:45 +05:30
Anurag Shekhar
7c670fc3e1 Bug#37740 Server crashes on execute statement with full text search and
match against.


Server crashes when executing prepared statement with duplicating
MATCH() function calls in SELECT and ORDER BY expressions, e.g.:
SELECT MATCH(a) AGAINST('test') FROM t1 ORDER BY MATCH(a) AGAINST('test')

This query gets optimized by the server, so the value returned
by MATCH() from the SELECT list is reused for ORDER BY purposes.
To make this optimization server is comparing items from
SELECT and ORDER BY lists. We were getting server crash because
comparision function for MATCH() item is not intended to be called
at this point of execution.

In 5.0 and 5.1 this problem is workarounded by resetting MATCH()
item to the state as it was during PREPARE.

In 6.0 correct comparision function will be implemented and
duplicating MATCH() items from the ORDER BY list will be
optimized.
2009-07-15 15:00:58 +05:30
Alexey Kopytov
2d4df13ef2 Manual merge. 2009-07-03 14:36:04 +04:00
Alexey Kopytov
c936b6444a Manual merge. 2009-07-03 14:36:04 +04:00
Alexey Kopytov
096c12b2c4 Bug #45262: Bad effects with CREATE TABLE and DECIMAL
Using DECIMAL constants with more than 65 digits in CREATE 
TABLE ... SELECT led to bogus errors in release builds or 
assertion failures in debug builds. 
 
The problem was in inconsistency in how DECIMAL constants and 
fields are handled internally. We allow arbitrarily long 
DECIMAL constants, whereas DECIMAL(M,D) columns are limited to 
M<=65 and D<=30. my_decimal_precision_to_length() was used in 
both Item and Field code and truncated precision to 
DECIMAL_MAX_PRECISION when calculating value length without 
adjusting precision and decimals. As a result, a DECIMAL 
constant with more than 65 digits ended up having length less 
than precision or decimals which led to assertion failures. 
 
Fixed by modifying my_decimal_precision_to_length() so that 
precision is truncated to DECIMAL_MAX_PRECISION only for Field 
object which is indicated by the new 'truncate' parameter. 
 
Another inconsistency fixed by this patch is how DECIMAL 
constants and expressions are handled for CREATE ... SELECT. 
create_tmp_field_from_item() (which is used for constants) was 
changed as a part of the bugfix for bug #24907 to handle long 
DECIMAL constants gracefully. Item_func::tmp_table_field() 
(which is used for expressions) on the other hand was still 
using a simplistic approach when creating a Field_new_decimal 
from a DECIMAL expression. 

mysql-test/r/type_newdecimal.result:
  Added a test case for bug #45262.
mysql-test/t/type_newdecimal.test:
  Added a test case for bug #45262.
sql/item.cc:
  Use the new 'truncate' parameter in 
  my_decimal_precision_to_length().
sql/item_cmpfunc.cc:
  Use the new 'truncate' parameter in 
  my_decimal_precision_to_length().
sql/item_func.cc:
  1. Use the new 'truncate' parameter in 
  my_decimal_precision_to_length().
  
  2. Do not truncate decimal precision to DECIMAL_MAX_PRECISION
  for additive expressions involving long DECIMAL constants.
  
  3. Fixed an incosistency in how DECIMAL constants and 
  expressions are handled for CREATE ... SELECT.
sql/item_func.h:
  Use the new 'truncate' parameter in 
  my_decimal_precision_to_length().
sql/item_sum.cc:
  Use the new 'truncate' parameter in 
  my_decimal_precision_to_length().
sql/my_decimal.h:
  Do not truncate precision to DECIMAL_MAX_PRECISION
  when calculating length in 
  my_decimal_precision_to_length() if 'truncate' parameter
  is FALSE.
sql/sql_select.cc:
  1. Use the new 'truncate' parameter in 
  my_decimal_precision_to_length().
  
  2. Use a more correct logic when adjusting value's length.
2009-07-03 11:41:19 +04:00
Alexey Kopytov
4692566f9e Bug #45262: Bad effects with CREATE TABLE and DECIMAL
Using DECIMAL constants with more than 65 digits in CREATE 
TABLE ... SELECT led to bogus errors in release builds or 
assertion failures in debug builds. 
 
The problem was in inconsistency in how DECIMAL constants and 
fields are handled internally. We allow arbitrarily long 
DECIMAL constants, whereas DECIMAL(M,D) columns are limited to 
M<=65 and D<=30. my_decimal_precision_to_length() was used in 
both Item and Field code and truncated precision to 
DECIMAL_MAX_PRECISION when calculating value length without 
adjusting precision and decimals. As a result, a DECIMAL 
constant with more than 65 digits ended up having length less 
than precision or decimals which led to assertion failures. 
 
Fixed by modifying my_decimal_precision_to_length() so that 
precision is truncated to DECIMAL_MAX_PRECISION only for Field 
object which is indicated by the new 'truncate' parameter. 
 
Another inconsistency fixed by this patch is how DECIMAL 
constants and expressions are handled for CREATE ... SELECT. 
create_tmp_field_from_item() (which is used for constants) was 
changed as a part of the bugfix for bug #24907 to handle long 
DECIMAL constants gracefully. Item_func::tmp_table_field() 
(which is used for expressions) on the other hand was still 
using a simplistic approach when creating a Field_new_decimal 
from a DECIMAL expression.
2009-07-03 11:41:19 +04:00
Gleb Shchepa
06142cd545 Bug #42778: delete order by null global variable causes
assertion .\filesort.cc, line 797

A query with the "ORDER BY @@some_system_variable" clause,
where @@some_system_variable is NULL, causes assertion
failure in the filesort procedures.

The reason of the failure is in the value of
Item_func_get_system_var::maybe_null: it was unconditionally
set to false even if the value of a variable was NULL.


mysql-test/r/variables.result:
  Added test case for bug #42778.
mysql-test/suite/sys_vars/r/innodb_data_home_dir_basic.result:
  Updated test case for bug #42778:
  system variables were NOT NULL, now they are nullable.
mysql-test/suite/sys_vars/r/innodb_flush_method_basic.result:
  Updated test case for bug #42778:
  system variables were NOT NULL, now they are nullable.
mysql-test/suite/sys_vars/r/rpl_init_slave_func.result:
  Updated test case for bug #42778:
  system variables were NOT NULL, now they are nullable.
mysql-test/suite/sys_vars/r/ssl_capath_basic.result:
  Updated test case for bug #42778:
  system variables were NOT NULL, now they are nullable.
mysql-test/suite/sys_vars/r/ssl_cipher_basic.result:
  Updated test case for bug #42778:
  system variables were NOT NULL, now they are nullable.
mysql-test/suite/sys_vars/t/innodb_data_home_dir_basic.test:
  Updated test case for bug #42778:
  system variables were NOT NULL, now they are nullable.
mysql-test/suite/sys_vars/t/innodb_flush_method_basic.test:
  Updated test case for bug #42778:
  system variables were NOT NULL, now they are nullable.
mysql-test/suite/sys_vars/t/ssl_capath_basic.test:
  Updated test case for bug #42778:
  system variables were NOT NULL, now they are nullable.
mysql-test/suite/sys_vars/t/ssl_cipher_basic.test:
  Updated test case for bug #42778:
  system variables were NOT NULL, now they are nullable.
mysql-test/t/variables.test:
  Added test case for bug #42778.
sql/item.cc:
  Bug #42778: delete order by null global variable causes
              assertion .\filesort.cc, line 797
  
  The longlong_from_string_with_check function has been modified
  to skip unwanted warnings: now it uses the THD::no_errors
  flag to suppress warnings.
  The Item_func_get_system_var::update_null_value method
  sets the no_error flag.
sql/item_func.cc:
  Bug #42778: delete order by null global variable causes
              assertion .\filesort.cc, line 797
  
  1. The Item_func_get_system_var::fix_length_and_dec method
     has been modified to make system variables truly nullable.
  
  2. The Item_func_get_system_var::update_null_value method
     method has been overloaded with a simple wrapper (like
     Item_field::update_null_value) to suppress unwanted warnings
     from Item_func_get_system_var::val_int() calls on non-numeric
     variable values: the Item_func_get_system_var::update_null_value
     method sets and restores THD::no_errors flag for a nested
     call of the longlong_from_string_with_check function.
sql/item_func.h:
  Bug #42778: delete order by null global variable causes
              assertion .\filesort.cc, line 797
  
  The Item_func_get_system_var::update_null_value method
  method has been overloaded.
2009-05-22 01:22:46 +05:00
Gleb Shchepa
387a54fbbd Bug #42778: delete order by null global variable causes
assertion .\filesort.cc, line 797

A query with the "ORDER BY @@some_system_variable" clause,
where @@some_system_variable is NULL, causes assertion
failure in the filesort procedures.

The reason of the failure is in the value of
Item_func_get_system_var::maybe_null: it was unconditionally
set to false even if the value of a variable was NULL.
2009-05-22 01:22:46 +05:00
Gleb Shchepa
405bd2af11 Bug #44768: SIGFPE crash when selecting rand from a view containing null
The RAND(N) function where the N is a field of "constant" table
(table of single row) failed with a SIGFPE.

Evaluation of RAND(N) rely on constant status of its argument.
Current server "seeded" random value for each constant argument
only once, in the Item_func_rand::fix_fields method.
Then the server skipped a call to seed_random() in the
Item_func_rand::val_real method for such constant arguments.

However, non-constant state of an argument may be changed
after the call to fix_fields, if an argument is a field of
"constant" table. Thus, pre-initialization of random value
in the fix_fields method is too early.


Initialization of random value by seed_random() has been
removed from Item_func_rand::fix_fields method.
The Item_func_rand::val_real method has been modified to
call seed_random() on the first evaluation of this method
if an argument is a function.


mysql-test/r/func_math.result:
  Added test case for bug #44768.
mysql-test/t/func_math.test:
  Added test case for bug #44768.
sql/item_func.cc:
  Bug #44768: SIGFPE crash when selecting rand from a view containing null
  
  1. Initialization of random value by seed_random() has been
     removed from Item_func_rand::fix_fields method.
  2. The Item_func_rand::val_real method has been modified to
     call seed_random() on the first evaluation of this method
     if an argument is a function.
sql/item_func.h:
  Bug #44768: SIGFPE crash when selecting rand from a view containing null
  
  1. The Item_func_rand::first_eval has been added to trace
     the first evaluation of the val_real method.
  2. The Item_func_rand::cleanup method has been added to
     cleanup the first_eval flag.
2009-05-18 09:21:25 +05:00
Gleb Shchepa
9cc4cb0ea1 Bug #44768: SIGFPE crash when selecting rand from a view containing null
The RAND(N) function where the N is a field of "constant" table
(table of single row) failed with a SIGFPE.

Evaluation of RAND(N) rely on constant status of its argument.
Current server "seeded" random value for each constant argument
only once, in the Item_func_rand::fix_fields method.
Then the server skipped a call to seed_random() in the
Item_func_rand::val_real method for such constant arguments.

However, non-constant state of an argument may be changed
after the call to fix_fields, if an argument is a field of
"constant" table. Thus, pre-initialization of random value
in the fix_fields method is too early.


Initialization of random value by seed_random() has been
removed from Item_func_rand::fix_fields method.
The Item_func_rand::val_real method has been modified to
call seed_random() on the first evaluation of this method
if an argument is a function.
2009-05-18 09:21:25 +05:00
Ramil Kalimullin
3c08b9b1ab Manual merge. 2009-05-10 21:20:35 +05:00
Ramil Kalimullin
c754cc84c1 Manual merge. 2009-05-10 21:20:35 +05:00
Ramil Kalimullin
bd414485de Fix for bug#42009: SELECT into variable gives different results to direct SELECT
Problem: storing "SELECT ... INTO @var ..." results in variables we used val_xxx()
methods which returned results of the current row. 
So, in some cases (e.g. SELECT DISTINCT, GROUP BY or HAVING) we got data
from the first row of a new group (where we evaluate a clause) instead of
data from the last row of the previous group.

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


mysql-test/r/distinct.result:
  Fix for bug#42009: SELECT into variable gives different results to direct SELECT
    - results adjusted.
mysql-test/r/user_var.result:
  Fix for bug#42009: SELECT into variable gives different results to direct SELECT
    - test result.
mysql-test/t/user_var.test:
  Fix for bug#42009: SELECT into variable gives different results to direct SELECT
    - test case.
sql/item_func.cc:
  Fix for bug#42009: SELECT into variable gives different results to direct SELECT
    - Item_func_set_user_var::save_item_result() added to evaluate and store 
      an item's result into a user variable.
sql/item_func.h:
  Fix for bug#42009: SELECT into variable gives different results to direct SELECT
    - Item_func_set_user_var::save_item_result() added to evaluate and store 
      an item's result into a user variable.
sql/sql_class.cc:
  Fix for bug#42009: SELECT into variable gives different results to direct SELECT
    - use Item_func_set_user_var::save_item_result() to store results into user 
      variables.
2009-02-24 18:47:12 +04:00
Ramil Kalimullin
71943e3628 Fix for bug#42009: SELECT into variable gives different results to direct SELECT
Problem: storing "SELECT ... INTO @var ..." results in variables we used val_xxx()
methods which returned results of the current row. 
So, in some cases (e.g. SELECT DISTINCT, GROUP BY or HAVING) we got data
from the first row of a new group (where we evaluate a clause) instead of
data from the last row of the previous group.

Fix: use val_xxx_result() counterparts to get proper results.
2009-02-24 18:47:12 +04:00
Guilhem Bichot
704b4845aa merge of 5.1-main into 5.1-maria. Myisam->Maria change propagation will follow.
There were so many changes into mtr (this is the new mtr coming) that I rather
copied mtr from 6.0-main here (at least this one knows how to run Maria tests).
I also fixed suite/maria tests to be accepted by the new mtr.

mysys/thr_mutex.c:
  adding DBUG_PRINT here, so that we can locate where the warning is issued.
2009-02-12 15:08:56 +01:00
Gleb Shchepa
93991b6be9 Bug#42188: crash and/or memory corruption with user variables
in trigger

Interchangeable calls to the mysql_change_user client function
and invocations of a trigger changing some user variable caused
a memory corruption and a crash.

The mysql_change_user API call forces TDH::cleanup() on a server
that frees user variable entries.
However it didn't reset Item_func_set_user_var::entry to NULL
because Item_func_set_user_var::cleanup() was not overloaded.
So, Item_func_set_user_var::entry held a pointer to freed memory,
that caused a crash.

The Item_func_set_user_var::cleanup method has been overloaded
to cleanup the Item_func_set_user_var::entry field.


mysql-test/r/user_var.result:
  Added test case for bug #42188.
mysql-test/t/user_var.test:
  Added test case for bug #42188.
sql/item_func.cc:
  Bug#42188: crash and/or memory corruption with user variables
             in trigger
  
  The Item_func_set_user_var::cleanup method has been overloaded
  to cleanup the Item_func_set_user_var::entry field.
sql/item_func.h:
  Bug#42188: crash and/or memory corruption with user variables
             in trigger
  
  The Item_func_set_user_var::cleanup method has been overloaded
  to cleanup the Item_func_set_user_var::entry field.
2009-01-23 22:18:02 +04:00
Gleb Shchepa
33a09cdcc8 Bug#42188: crash and/or memory corruption with user variables
in trigger

Interchangeable calls to the mysql_change_user client function
and invocations of a trigger changing some user variable caused
a memory corruption and a crash.

The mysql_change_user API call forces TDH::cleanup() on a server
that frees user variable entries.
However it didn't reset Item_func_set_user_var::entry to NULL
because Item_func_set_user_var::cleanup() was not overloaded.
So, Item_func_set_user_var::entry held a pointer to freed memory,
that caused a crash.

The Item_func_set_user_var::cleanup method has been overloaded
to cleanup the Item_func_set_user_var::entry field.
2009-01-23 22:18:02 +04:00
Georgi Kodinov
4d8e73c818 merged 5.0-bugteam -> 5.1-bugteam 2009-01-16 17:38:38 +02:00
Georgi Kodinov
c34491360f merged 5.0-bugteam -> 5.1-bugteam 2009-01-16 17:38:38 +02:00
Georgi Kodinov
bdec5458ae auto merge 2009-01-16 16:48:41 +02:00
Georgi Kodinov
7fc8286257 auto merge 2009-01-16 16:48:41 +02:00
Georgi Kodinov
f97ef7a40e merged 5.1-main -> 5.1-bugteam 2009-01-05 18:10:20 +02:00
Georgi Kodinov
8c25823f94 merged 5.1-main -> 5.1-bugteam 2009-01-05 18:10:20 +02:00
Gleb Shchepa
cd42f4ba2c auto merge 5.0-bugteam --> 5.1-bugteam (bug 40761) 2008-12-12 18:19:33 +04:00
Gleb Shchepa
e1f93509e1 auto merge 5.0-bugteam --> 5.1-bugteam (bug 40761) 2008-12-12 18:19:33 +04:00
Gleb Shchepa
af5cf536bc Bug #40761: Assert on sum function on
IF(..., CAST(longtext AS UNSIGNED), signed_val)
            (was: LEFT JOIN on inline view crashes server)

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

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

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


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

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

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

CAST AS UNSIGNED function has been modified to limit maximal
length of resulting number to 67 (maximal length of DECIMAL
and two characters for minus sign and dot).
2008-12-12 17:16:25 +04:00
Gleb Shchepa
749847686c rollback of bug #40761 fix 2008-12-12 15:13:11 +04:00
Gleb Shchepa
5772a50b7d rollback of bug #40761 fix 2008-12-12 15:13:11 +04:00
Gleb Shchepa
5ff1bcbc2a rollback of bug #40761 fix 2008-12-12 14:59:10 +04:00
Gleb Shchepa
03f9b2cea6 rollback of bug #40761 fix 2008-12-12 14:59:10 +04:00
Gleb Shchepa
a4467c9798 manual merge 5.0-bugteam -> 5.1-bugteam (bug 40761) 2008-12-12 02:04:06 +04:00
Gleb Shchepa
09219a03b9 manual merge 5.0-bugteam -> 5.1-bugteam (bug 40761) 2008-12-12 02:04:06 +04:00
Gleb Shchepa
ffe23f0eb7 Bug #40761: Assert on sum function on
IF(..., CAST(longtext AS UNSIGNED), signed_val)
            (was: LEFT JOIN on inline view crashes server)

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

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

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


mysql-test/r/func_if.result:
  Added test case for bug #40761.
mysql-test/t/func_if.test:
  Added test case for bug #40761.
sql/item_cmpfunc.cc:
  Bug #40761: Assert on sum function on
              IF(..., CAST(longtext AS UNSIGNED), signed_val)
  
  1. Item_func_case::agg_str_lengths method has been moved
     to the Item_func superclass.
  2. Item_func_ifnull/Item_func_if::fix_length_and_dec methods
     have been updated to calculate max_length, decimals and
     unsigned flag like Item_func_case.
sql/item_cmpfunc.h:
  Bug #40761: Assert on sum function on
              IF(..., CAST(longtext AS UNSIGNED), signed_val)
  
  Item_func_case::agg_str_lengths method has been moved to
  the Item_func superclass.
sql/item_func.cc:
  Bug #40761: Assert on sum function on
              IF(..., CAST(longtext AS UNSIGNED), signed_val)
  
  Item_func_case::agg_str_lengths method has been moved to
  the Item_func superclass.
sql/item_func.h:
  Bug #40761: Assert on sum function on
              IF(..., CAST(longtext AS UNSIGNED), signed_val)
  
  Item_func_case::agg_str_lengths method has been moved to
  the Item_func superclass.
2008-12-12 00:57:32 +04:00
Gleb Shchepa
ce8ad64dd2 Bug #40761: Assert on sum function on
IF(..., CAST(longtext AS UNSIGNED), signed_val)
            (was: LEFT JOIN on inline view crashes server)

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

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

The bug has been fixed by the same solution as in the CASE
function implementation.
2008-12-12 00:57:32 +04:00
Joerg Bruehe
2181c95918 Merge main 5.1 into 5.1-build 2008-12-10 21:14:50 +01:00
Joerg Bruehe
c7d03ca35b Merge main 5.1 into 5.1-build 2008-12-10 21:14:50 +01:00
Guilhem Bichot
926aaf4635 Merge of 5.1-main into 5.1-maria. There were no changes to storage/myisam, mysys/mf_keycache.c, mysql-test/t/*myisam*
since previous merge. MARIA_PAGECACHE_READS in maria-preload.test are down a little bit (5%), which must be a good
side-effect of some sql/ change.
2008-12-10 10:02:25 +01:00