Commit graph

966 commits

Author SHA1 Message Date
Gleb Shchepa
dff10afb20 Bug #11827369: ASSERTION FAILED: !THD->LEX->CONTEXT_ANALYSIS_ONLY
Manual up-merge from 5.1 to 5.5.
2013-01-31 09:13:42 +04:00
Gleb Shchepa
19ea7c031d Bug #11827369: ASSERTION FAILED: !THD->LEX->CONTEXT_ANALYSIS_ONLY
Some queries with the "SELECT ... FROM DUAL" nested subqueries
failed with an assertion on debug builds.
Non-debug builds were not affected.

There were a few different issues with similar assertion
failures on different queries:

1. The first problem was related to the incomplete propagation
of the "non-constant" item status from underlying subquery
items to the outer item tree: in some cases non-constants were
interpreted as constants and evaluated at the preparation stage
(val_int() calls withing fix_fields() etc).

Thus, the default implementation of Item_ref::const_item() from
the Item parent class didn't take into account the "const_item"
status of the referenced item tree -- it used the insufficient
"used_tables() == 0" check instead. This worked in most cases
since our "non-constant" functions like RAND() and SLEEP() set
the RAND_TABLE_BIT in the used table map, so they aren't
non-constant from Item_ref's "point of view". However, the
"SELECT ... FROM DUAL" subquery may have an empty map of used
tables, but at the same time subqueries are never "constant" at
the context analysis stage (preparation, view creation etc).
So, the non-contantness of such subqueries was missed.

Fix: the Item_ref::const_item() function has been overloaded to
take into account both (*ref)->const_item() status and tricky
Item_ref::used_tables() return values, since the only
(*ref)->const_item() call is not enough there.

2. In some cases instead of the const_item() call we check a
value of the Item::with_subselect field to recognize items
with nested subqueries. However, the Item_ref class didn't
propagate this value from the referenced item tree.

Fix: Item::has_subquery() and Item_ref::has_subquery()
functions have been backported from 5.6. All direct
references to the with_subselect fields of nested items have
been with the has_subquery() function call.

3. The Item_func_regex class didn't propagate with_subselect
as well, since it overloads the Item_func::fix_fields()
function with insufficient fix_fields() implementation.

Fix: the Item_func_regex::fix_fields() function has been
modified to gather "constant" statuses from inner items.

4. The Item_func_isnull::update_used_tables() function has
a special branch for the underlying item where the maybe_null
value is false: in this case it marks the Item_func_isnull
as a "const_item" and sets the cached_value to false.
However, the Item_func_isnull::val_int() was not in sync with
update_used_tables(): it didn't take into account neither
const_item_cache nor cached_value for the case of
"args[0]->maybe_null == false optimization".
As far as such an Item_func_isnull has "const_item() == true",
it's ok to call Item_func_isnull::val_int() etc from outer
items on preparation stage. In this case the server tried to
call Item_func_isnull::args[0]->isnull(), and if the args[0]
item contained a nested not-nullable subquery, it failed
with an assertion.

Fix: take the value of Item_func_isnull::const_item_cache into
account in the val_int() function.

5. The auxiliary Item_is_not_null_test class has a similar
optimization in the update_used_tables() function as the
Item_func_isnull class has, and the same issue in the val_int()
function.
In addition to that the Item_is_not_null_test::update_used_tables()
doesn't update the const_item_cache value, so the "maybe_null"
optimization is useless there. Thus, we missed some optimizations
of cases like these (before and after the fix):
  <  <is_not_null_test>(a),
  ---
  >  <cache>(<is_not_null_test>(a)),
or
  < having (<is_not_null_test>(a) and <is_not_null_test>(a))
  ---
  > having 1
etc.

Fix: update Item_is_not_null_test::const_item_cache in
update_used_tables() and take in into account in val_int().
2013-01-23 09:51:50 +04:00
Chaithra Gopalareddy
cb72ecbe2c Merge from 5.1 to 5.5 2013-01-11 06:36:53 +05:30
Chaithra Gopalareddy
8b41f491c8 Bug#11760726: LEFT JOIN OPTIMIZED INTO JOIN LEADS TO
INCORRECT RESULTS

This is a backport of fix for Bug#13068506.

mysql-test/r/join_outer.result:
  Added test result for Bug#13068506
mysql-test/t/join_outer.test:
  Added test case for Bug#13068506
sql/item.h:
  Implement Item_outer_ref::not_null_tables()
2013-01-10 16:17:13 +05:30
Tor Didriksen
a16e00a6c4 Bug#14463247 ORDER BY SUBQUERY REFERENCING OUTER ALIAS FAILS
Documentation for class Item_outer_ref was wrong:
(*ref) may point to Item_field as well
(see e.g. Item_outer_ref::fix_fields)

So this casting in get_store_key() was wrong:
(*(Item_ref**)((Item_ref*)keyuse->val)->ref)->ref_type()
2012-08-23 16:29:41 +02:00
Praveenkumar Hulakund
c22c9270fb Bug#12601974 - STORED PROCEDURE SQL_MODE=NO_BACKSLASH_ESCAPES IGNORED AND BREAKS REPLICATION
Analysis:
========================
sql_mode "NO_BACKSLASH_ESCAPES": When user want to use backslash as character input,
instead of escape character in a string literal then sql_mode can be set to 
"NO_BACKSLASH_ESCAPES". With this mode enabled, backslash becomes an ordinary 
character like any other. 

SQL_MODE set applies to the current client session. And while creating the stored 
procedure, MySQL stores the current sql_mode and always executes the stored 
procedure in sql_mode stored with the Procedure, regardless of the server SQL 
mode in effect when the routine is invoked.  

In the scenario (for which bug is reported), the routine is created with 
sql_mode=NO_BACKSLASH_ESCAPES. And routine is executed with the invoker sql_mode
is "" (NOT SET) by executing statement "call testp('Axel\'s')".
Since invoker sql_mode is "" (NOT_SET), the '\' in 'Axel\'s'(argument to function)
is considered as escape character and column "a" (of table "t1") values are 
updated with "Axel's". The binary log generated for above update operation is as below,

  set sql_mode=XXXXXX (for no_backslash_escapes)
  update test.t1 set a= NAME_CONST('var',_latin1'Axel\'s' COLLATE 'latin1_swedish_ci');

While logging stored procedure statements, the local variables (params) used in
statements are replaced with the NAME_CONST(var_name, var_value) (Internal function) 
(http://dev.mysql.com/doc/refman/5.6/en/miscellaneous-functions.html#function_name-const)

On slave, these logs are applied. NAME_CONST is parsed to get the variable and its
value. Since, stored procedure is created with sql_mode="NO_BACKSLASH_ESCAPES", the sql_mode
is also logged in. So that at slave this sql_mode is set before executing the statements
of routine.  So at slave, sql_mode is set to "NO_BACKSLASH_ESCAPES" and then while
parsing NAME_CONST of string variable, '\' is considered as NON ESCAPE character
and parsing reported error for "'" (as we have only one "'" no backslash). 

At slave, parsing was proper with sql_mode "NO_BACKSLASH_ESCAPES".
But above error reported while writing bin log, "'" (of Axel's) is escaped with
"\" character. Actually, all special characters (n, r, ', ", \, 0...) are escaped
while writing NAME_CONST for string variable(param, local variable) in bin log 
Airrespective of "NO_BACKSLASH_ESCAPES" sql_mode. So, basically, the problem is 
that logging string parameter does not take into account sql_mode value.

Fix:
========================
So when sql_mode is set to "NO_BACKSLASH_ESCAPES", escaping  characters as 
(n, r, ', ", \, 0...) should be avoided. To do so, added a check to not to
escape such characters while writing NAME_CONST for string variables in bin 
log. 
And when sql_mode is set to NO_BACKSLASH_ESCAPES, quote character "'" is
represented as ''.
http://dev.mysql.com/doc/refman/5.6/en/string-literals.html (There are several 
ways to include quote characters within a string: )



mysql-test/r/sql_mode.result:
  Added test case for Bug#12601974.
mysql-test/suite/binlog/r/binlog_sql_mode.result:
  Appended result of test cases added for Bug#12601974.
mysql-test/suite/binlog/t/binlog_sql_mode.test:
  Added test case for Bug#12601974.
mysql-test/t/sql_mode.test:
  Appended result of test cases added for Bug#12601974.
2012-02-29 12:23:15 +05:30
Praveenkumar Hulakund
a0b46059ee Merge from 5.1 to 5.5 2012-02-29 14:15:15 +05:30
Alexander Nozdrin
c86fa2b243 Auto-merge from mysql-5.5. 2011-10-24 13:21:32 +04:00
Sergey Glukhov
bd4785a6b7 Bug#11750518 41090: ORDER BY TRUNCATES GROUP_CONCAT RESULT
When temporary tables is used for result sorting
result field for gconcat function is created using
group_concat_max_len size. It leads to result truncation
when character_set_results is multi-byte character set due
to insufficient tmp table field size.
The fix is to increase temporary table field size for
gconcat. Method make_string_field() is overloaded
for Item_func_group_concat class and uses
max_characters * collation.collation->mbmaxlen size for
result field. max_characters is maximum number of characters
what can fit into max_length size.


mysql-test/r/ctype_utf16.result:
  test result
mysql-test/r/ctype_utf32.result:
  test result
mysql-test/r/ctype_utf8.result:
  test result
mysql-test/t/ctype_utf16.test:
  test case
mysql-test/t/ctype_utf32.test:
  test case
mysql-test/t/ctype_utf8.test:
  test case
sql/item.h:
  make Item::make_string_field() virtual
sql/item_sum.cc:
  added Item_func_group_concat::make_string_field(TABLE *table) method
  which uses max_characters * collation.collation->mbmaxlen size for
  result item. max_characters is maximum number of characters what can
  fit into max_length size.
sql/item_sum.h:
  added Item_func_group_concat::make_string_field(TABLE *table) method
2011-10-12 17:41:25 +04:00
Dmitry Shulga
644db66446 Fixed Bug#12621017 - CRASH IF A SP VARIABLE IS USED IN THE LIMIT CLAUSE OF A
SET STATEMENT.

Server built with debug asserts, without debug crashes if a user tries
to run a stored procedure that constains query with subquery that include
either LIMIT or LIMIT OFFSET clauses.

The problem was that Item::fix_fields() was not called for the items
representing LIMIT or OFFSET clauses.

The solution is to call Item::fix_fields() right before evaluation in
st_select_lex_unit::set_limit().

mysql-test/r/sp.result:
  Added testcase result for bug#12621017. Updated testcase result for
  bug 11918.
mysql-test/t/sp.test:
  Added testcase for bug#12621017. Addressed review comments for Bug 11918
  (added tests for use LIMIT at stored function).
sql/item.h:
  Addressed review comments for Bug 11918.
sql/share/errmsg-utf8.txt:
  Addressed review comments for Bug 11918.
sql/sp_head.cc:
  Addressed review comments for Bug 11918.
sql/sql_lex.cc:
  Added call fix_fields() for item just before its evaluation.
sql/sql_yacc.yy:
  Addressed review comments for Bug 11918.
2011-08-13 13:34:00 +07:00
Mayank Prasad
eecaad9dcc Bug#12337762 : MYSQL_LIST_FIELDS() RETURNS WRONG CHARSET FOR CHAR/VARCHAR/TEXT
COLUMNS IN VIEWS

Issue:
charset value for a Column, returned by MYSQL_LIST_FIELDS(), was not same
for Table and View. This was because, for view, field charset was not being
returned.

Solution:
Added definition of function "charset_for_protocol()" in calss 
Item_ident_for_show to return field charset value.

sql/item.h:
  Added definition for charset_for_protocol() function to return field charset.
tests/mysql_client_test.c:
  Added a test case test_bug12337762 for the changes done.
2011-06-10 19:56:35 +05:30
Gleb Shchepa
a77bc59896 Bug #11829681 - 60295: ERROR 1356 ON VIEW THAT EXECUTES FINE AS A QUERY
Select from a view with the underlying HAVING clause failed with a
message: "1356: View '...' references invalid table(s) or column(s)
or function(s) or definer/invoker of view lack rights to use them"

The bug is a regression of the fix for bug 11750328 - 40825 (similar
case, but the HAVING cause references an aliased field).
In the old fix for bug 40825 the Item_field::name_length value has
been used in place of the real length of Item_field::name. However,
in some cases Item_field::name_length is not in sync with the
actual name length (TODO: combine name and name_length into a
solid String field).

The Item_ref::print() method has been modified to calculate actual
name length every time.


mysql-test/r/view.result:
  Test case for bug #11829681
mysql-test/t/view.test:
  Test case for bug #11829681
sql/item.cc:
  Bug #11829681 - 60295: ERROR 1356 ON VIEW THAT EXECUTES FINE AS A QUERY
  
  The Item_ref::print() method has been modified to calculate actual
  name length every time.
sql/item.h:
  Minor commentary.
2011-04-08 12:05:20 +04: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
Gleb Shchepa
b2fee393b0 manual merge 5.1-->5.5 (bug 11829681) 2011-04-08 12:09:24 +04:00
Tor Didriksen
08c8d21f2b Bug #11766860 - 60085: CRASH IN ITEM::SAVE_IN_FIELD() WITH TIME DATA TYPE
This assumption in Item_cache_datetime::cache_value_int
was wrong:
-  /* Assume here that the underlying item will do correct conversion.*/
-  int_value= example->val_int_result();


mysql-test/r/subselect_innodb.result:
  New test case.
mysql-test/t/subselect_innodb.test:
  New test case.
sql/item.cc:
  In Item_cache_datetime::cache_value_int()
   - call get_time() or get_date() depending on desired type
   - convert the returned MYSQL_TIME value to longlong depending on desired type
sql/item.h:
  The cached int_value in Item_cache_datetime should not be unsigned:
   - it is used mostly in signed context
   - it can actually have negative value (for TIME data type)
sql/item_cmpfunc.cc:
  Add comment on Bug#59685
sql/item_subselect.cc:
  Add some DBUG_TRACE for easier bug-hunting.
2011-02-17 13:41:25 +01:00
Jonathan Perkin
f13788c9fd Merge from mysql-5.5.9-release 2011-02-08 14:59:03 +01:00
Mattias Jonsson
bede87d353 merge 2011-01-28 13:28:15 +01:00
Mattias Jonsson
62ab200343 Update of copyright headers for files I changed this year. 2011-01-27 23:47:24 +01:00
Karen Langford
de3c4428b8 Updating header copyright/README in source for 2011 2011-01-25 15:42:40 +01:00
Georgi Kodinov
b0bbc00899 merge 2011-01-12 17:10:12 +02:00
Georgi Kodinov
7f9ce73d49 merge 2011-01-12 17:08:52 +02:00
Oystein Grovlen
17cd0bccdb Merge fix for Bug#59211 to mysql-5.5-security 2011-01-12 11:27:31 +01:00
Oystein Grovlen
651313bf91 Bug#59211: Select Returns Different Value for min(year) Function
get_year_value() contains code to convert 2-digits year to
4-digits.  The fix for Bug#49910 added a check on the size of
the underlying field so that this conversion is not done for
YEAR(4) values. (Since otherwise one would convert invalid
YEAR(4) values to valid ones.)

The existing check does not work when Item_cache is used, since
it is not detected when the cache is based on a Field.  The
reported change in behavior is due to Bug#58030 which added
extra cached items in min/max computations.

The elegant solution would be to implement
Item_cache::real_item() to return the underlying Item.
However, some side effects are observed (change in explain
output) that indicates that such a change is not straight-
forward, and definitely not appropriate for an MRU.

Instead, a Item_cache::field() method has been added in order
to get access to the underlying field.  (This field() method
eliminates the need for Item_cache::eq_def() used in
test_if_ref(), but in order to limit the scope of this fix,
that code has been left as is.)


mysql-test/r/type_year.result:
  Added test case for Bug#59211.
mysql-test/t/type_year.test:
  Added test case for Bug#59211.
sql/item.h:
  Added function Item_cache::field() to get access to the
  underlying Field of a cached field Value.
sql/item_cmpfunc.cc:
  Also check underlying fields of Item_cache, not just Item_Field,
  when checking whether the value is of type YEAR(4) or not.
2011-01-12 10:37:15 +01:00
Mattias Jonsson
b56308e63d Manual merge from 5.1 2011-01-10 15:08:31 +01:00
Davi Arnaut
d00b9f103a Bug#58765: Warning in item.h on Windows
Truncate the maximum result length (64-bit wide type) to fit into
the item maximum length (32-bit wide type). This is possible as
this specific branch is only used if the maximum result length
is less than 0x1000000 (MAX_BLOB_WIDTH), which fits comfortably
in a 32-bit wide type.
2011-01-07 17:32:41 -02:00
Mattias Jonsson
544451bbd8 merge 2011-01-04 14:13:20 +01:00
Kent Boortz
be6c3fd8aa Merge 2010-12-29 01:26:31 +01:00
Kent Boortz
4acfdb9df1 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
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
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
Ramil Kalimullin
bd557f04f6 Manual merge from mysql-5.5-bugteam. 2010-11-22 14:47:28 +03:00
Magne Mahre
54d6357837 Bug#58199 name_const in the having clause crashes
NAME_CONST(..) was used wrongly in a HAVING clause, and
should have caused a user error.  Instead, it caused a
segmentation fault.
      
During parsing, the value parameter to NAME_CONST was
specified to be an uninitialized Item_ref object (it
would be resolved later).   During the semantic analysis,
the object is tested, and since it was not initialied,
the server seg.faulted.
      
The fix is to check if the object is initialized
before testing it.  The same pattern has already been
applied to most other methods in the Item_ref class.
      
Bug was introduced by the optimization done as part of
Bug#33546.
2010-11-18 14:02:24 +01:00
Evgeny Potemkin
368ac9f03e Bug#57278: Crash on min/max + with date out of range.
MySQL officially supports DATE values starting from 1000-01-01. This is
enforced for int values, but not for string values, thus one
could easily insert '0001-01-01' value. Int values are checked by
number_to_datetime function and Item_cache_datetime::val_str uses it
to fill MYSQL_TIME struct out of cached int value. This leads to the
scenario where Item_cache_datetime caches a non-null datetime value and when
it tries to convert it from int to string number_to_datetime function
treats the value as out-of-range and returns an error and
Item_cache_datetime::val_str returns NULL for a non-null value. Due to this
inconsistency server crashes.

Now number_to_datetime allows DATE values below 1000-01-01 if the
TIME_FUZZY_DATE flag is set. Better NULL handling for Item_cache_datetime.
Added the Item_cache_datetime::store function to reset str_value_cached flag
when an item is stored.

mysql-test/r/type_date.result:
  Added a test case for the bug#57278.
mysql-test/t/type_date.test:
  Added a test case for the bug#57278.
sql-common/my_time.c:
  Bug#57278: Crash on min/max + with date out of range.
  Now number_to_datetime allows DATE values below 1000-01-01 if the
  TIME_FUZZY_DATE flag is set.
sql/item.cc:
  Bug#57278: Crash on min/max + with date out of range.
  Item_cache_datetime::val_str now better handles
  null_value.
2010-11-04 16:18:27 +03:00
Alexander Barkov
7f98714247 Bug#54916 GROUP_CONCAT + IFNULL truncates output
Problem: a few functions did not calculate their max_length correctly.
This is an after-fix for WL#2649 Number-to-string conversions".

Fix: changing the buggy functions to calculate max_length
using fix_char_length() introduced in WL#2649,
instead of setting max_length directly

  mysql-test/include/ctype_numconv.inc
     Adding new tests

  mysql-test/r/ctype_binary.result
     Adding new tests

  mysql-test/r/ctype_cp1251.result
     Adding new tests

  mysql-test/r/ctype_latin1.result
     Adding new tests

  mysql-test/r/ctype_ucs.result
     Adding new tests

  mysql-test/r/ctype_utf8.result
     Adding new tests

  mysql-test/t/ctype_utf8.test
    Including ctype_numconv

  sql/item.h
    - Introducing new method fix_char_length_ulonglong(),
    for the cases when length is potentially greater
    than UINT_MAX32. This method removes a few
    instances of duplicate code, e.g. in item_strfunc.cc.
    - Setting collation in Item_copy properly. This change
    fixes wrong metadata on client side in some cases, when
    "binary" instead of the real character set was reported.

  sql/item_cmpfunc.cc
    - Using fix_char_length() and max_char_length() methods,
    instead of direct access to max_length, to calculate
    item length properly.
    - Moving count_only_length() in COALESCE after
    agg_arg_charsets_for_string_result(). The old
    order was incorrect and led to wrong length
    calucation in case of multi-byte character sets.
    
  sql/item_func.cc
    Fixing that count_only_length() didn't work
    properly for multi-byte character sets.
    Using fix_char_length() and max_char_length()
    instead of direct access to max_length.

  sql/item_strfunc.cc
    - Using fix_char_length(), fix_char_length_ulonglong(),
    max_char_length() instead of direct access to max_length.
    - Removing wierd condition: "if (collation.collation->mbmaxlen > 0)",
    which is never FALSE.
2010-08-19 15:55:35 +04:00
Alexander Nozdrin
e28d6ee66a Auto-merge from mysql-5.5. 2010-08-18 11:48:38 +04:00
Evgeny Potemkin
827a89996a Bug#49746: Const expression caching led to NDB not using engine condition
pushdown.
      
NDB supports only a limited set of item nodes for use in engine condition
pushdown. Because of this adding cache for const expression effectively
disabled this optimization.
      
The ndb_serialize_cond function is extended to support Item_cache and treat
it as a constant values.
A helper function called ndb_serialize_const is added. It is used to create
Ndb_cond value node from given const item.


mysql-test/suite/ndb/t/disabled.def:
  Bug#49746: Const expression caching led to NDB not using engine condition
  pushdown.
  Enabled ndb_condition_pushdown test after fixing appropriate bug.
sql/ha_ndbcluster_cond.cc:
  Bug#49746: Const expression caching led to NDB not using engine condition
  pushdown.
  The ndb_serialize_cond function is extended to support Item_cache and treat
  it as a constant values.
  A helper function called ndb_serialize_const is added. It is used to create
  Ndb_cond value node from given const item.
sql/item.cc:
  Bug#49746: Const expression caching led to NDB not using engine condition
  pushdown.
  The Item::cache_const_expr_analyzer function is adjusted to not create
  cache for Item_int_with_ref objects.
sql/item.h:
  Bug#49746: Const expression caching led to NDB not using engine condition
  pushdown.
  The result_type() method is added to Item_cache class.
  The Item_cache_str now initializes its collation.
2010-08-14 13:11:33 +04:00
Georgi Kodinov
1560eab136 merge 2010-07-30 16:56:57 +03:00
Georgi Kodinov
de5029a458 Bug #55188: GROUP BY, GROUP_CONCAT and TEXT - inconsistent results
In order to be able to check if the set of the grouping fields in a 
GROUP BY has changed (and thus to start a new group) the optimizer
caches the current values of these fields in a set of Cached_item 
derived objects.
The Cached_item_str, used for caching varchar and TEXT columns,
is limited in length by the max_sort_length variable.
A String buffer to store the value with an alloced length of either
the max length of the string or the value of max_sort_length 
(whichever is smaller) in Cached_item_str's constructor.
Then, at compare time the value of the string to compare to was 
truncated to the alloced length of the string buffer inside 
Cached_item_str.
This is all fine and valid, but only if you're not assigning 
values near or equal to the alloced length of this buffer.
Because when assigning values like this the alloced length is 
rounded up and as a result the next set of data will not match the
group buffer, thus leading to wrong results because of the changed
alloced_length.
Fixed by preserving the original maximum length in the 
Cached_item_str's constructor and using this instead of the 
alloced_length to limit the string to compare to.
Test case added.
2010-07-30 16:35:06 +03:00
Evgeny Potemkin
4777370bb3 Bug#49771: Incorrect MIN/MAX for date/time values.
This bug is a design flaw of the fix for the bug#33546. It assumed that an
item can be used only in one comparison context, but actually it isn't the
case. Item_cache_datetime is used to store result for MIX/MAX aggregate
functions. Because Arg_comparator always compares datetime values as INTs when
possible the Item_cache_datetime most time caches only INT value. But
since all datetime values has STRING result type MIN/MAX functions are asked
for a STRING value when the result is being sent to a client. The
Item_cache_datetime was designed to avoid conversions and get INT/STRING
values from an underlying item, but at the moment the values is asked
underlying item doesn't hold it anymore thus wrong result is returned.
Beside that MIN/MAX aggregate functions was wrongly initializing cached result
and this led to a wrong result.

The Item::has_compatible_context helper function is added. It checks whether
this and given items has the same comparison context or can be compared as
DATETIME values by Arg_comparator. The equality propagation optimization is
adjusted to take into account that items which being compared as DATETIME
can have different comparison contexts.
The Item_cache_datetime now converts cached INT value to a correct STRING
DATETIME value by means of number_to_datetime & my_TIME_to_str functions.
The Arg_comparator::set_cmp_context_for_datetime helper function is added. 
It sets comparison context of items being compared as DATETIMEs to INT if
items will be compared as longlong.
The Item_sum_hybrid::setup function now correctly initializes its result
value.
In order to avoid unnecessary conversions Item_sum_hybrid now states that it
can provide correct longlong value if the item being aggregated can do it
too.

mysql-test/r/group_by.result:
  Added a test case for the bug#49771.
sql/item.cc:
  Bug#49771: Incorrect MIN/MAX for date/time values.
  The equality propagation mechanism is adjusted to take into account that
  items which being compared as DATETIME can have different comparison
  contexts.
  The Item_cache_datetime now converts cached INT value to a correct STRING
  DATETIME/TIME value.
sql/item.h:
  Bug#49771: Incorrect MIN/MAX for date/time values.
  The Item::has_compatible_context helper function is added. It checks whether
  this and given items has the same comparison context or can be compared as
  DATETIME values by Arg_comparator.
  Added Item_cache::clear helper function.
sql/item_cmpfunc.cc:
  Bug#49771: Incorrect MIN/MAX for date/time values.
  The Arg_comparator::set_cmp_func now sets the correct comparison context
  for items being compared as DATETIME values.
sql/item_cmpfunc.h:
  Bug#49771: Incorrect MIN/MAX for date/time values.
  The Arg_comparator::set_cmp_context_for_datetime helper function is added. 
  It sets comparison context of items being compared as DATETIMEs to INT if
  items will be compared as longlong.
sql/item_sum.cc:
  Bug#49771: Incorrect MIN/MAX for date/time values.
  The Item_sum_hybrid::setup function now correctly initializes its result
  value.
sql/item_sum.h:
  Bug#49771: Incorrect MIN/MAX for date/time values.
  In order to avoid unnecessary conversions Item_sum_hybrid now states that it
  can provide correct longlong value if the item being aggregated can do it
  too.
2010-07-19 21:11:47 +04:00
Alexander Barkov
72bb9b7acb Bug#52159 returning time type from function and empty left join causes debug assertion
Problem: Item_copy did not set "fixed", which resulted in DBUG_ASSERT in some cases.
Fix: adding  initialization of the "fixed" member

Adding tests:
  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

Adding initialization of the "fixed" member:
  sql/item.h
2010-07-07 10:00:46 +04:00
Alexander Barkov
eed26e92a6 Bug#52520 Difference in tinytext utf column metadata
Problems:
      - regression (compating to version 5.1) in metadata for BLOB types
      - inconsistency between length metadata in server and embedded for BLOB types
      - wrong max_length calculation in items derived from BLOB columns
     @ libmysqld/lib_sql.cc
        Calculating length metadata in embedded similary to server version,
        using new function char_to_byte_length_safe().
     @ mysql-test/r/ctype_utf16.result
        Adding tests
     @ mysql-test/r/ctype_utf32.result
        Adding tests
     @ mysql-test/r/ctype_utf8.result
        Adding tests
     @ mysql-test/r/ctype_utf8mb4.result
        Adding tests
     @ mysql-test/t/ctype_utf16.test
        Adding tests
     @ mysql-test/t/ctype_utf32.test
        Adding tests
     @ mysql-test/t/ctype_utf8.test
        Adding tests
     @ mysql-test/t/ctype_utf8mb4.test
        Adding tests
     @ sql/field.cc
        Overriding char_length() for Field_blob:
        unlike in generic Item::char_length() we don't
        divide to mbmaxlen for BLOBs.
     @ sql/field.h
        - Making Field::char_length() virtual
        - Adding prototype for Field_blob::char_length()
     @ sql/item.h
        - Adding new helper function char_to_byte_length_safe()
        - Using new function
     @ sql/protocol.cc
        Using new function char_to_byte_length_safe().

    modified:
      libmysqld/lib_sql.cc
      mysql-test/r/ctype_utf16.result
      mysql-test/r/ctype_utf32.result
      mysql-test/r/ctype_utf8.result
      mysql-test/r/ctype_utf8mb4.result
      mysql-test/t/ctype_utf16.test
      mysql-test/t/ctype_utf32.test
      mysql-test/t/ctype_utf8.test
      mysql-test/t/ctype_utf8mb4.test
      sql/field.cc
      sql/field.h
      sql/item.h
      sql/protocol.cc
2010-06-02 16:23:50 +04:00
Gleb Shchepa
fefbd756db Bug #38745: MySQL 5.1 optimizer uses filesort for ORDER BY
when it should use index

Sometimes the LEFT/RIGHT JOIN with an empty table caused an
unnecessary filesort.

Sample query, where t1.i1 is indexed and t3 is empty:

  SELECT t1.*, t2.* FROM t1 JOIN t2 ON t1.i1 = t2.i2
                       LEFT JOIN t3 ON t2.i2 = t3.i3
    ORDER BY t1.i1 LIMIT 5;

The server erroneously used an item of empty outer-joined
table as a common constant of a Item_equal (multi-equivalence
expression).
By the fix for the bug 16590 the constant status of such
an item has been propagated to st_table::const_key_parts
map bits related to other Item_equal argument-related
key parts (those are obviously not constant in our case).
As far as test_if_skip_sort_order function skips constant
prefixes of testing keys, this caused an ignorance of
available indices, since some prefixes were marked as
constant by mistake.


mysql-test/r/order_by.result:
  Test case for bug #38745.
mysql-test/t/order_by.test:
  Test case for bug #38745.
sql/item.h:
  Bug #38745: MySQL 5.1 optimizer uses filesort for ORDER BY
              when it should use index
  
  Item::is_outer_field() has been added and overloaded for
  Item_field and Item_ref classes.
sql/item_cmpfunc.cc:
  Bug #38745: MySQL 5.1 optimizer uses filesort for ORDER BY
              when it should use index
  
  Item_equal::update_const() and Item_equal::update_used_tables()
  have been updated to not take into account the constantness
  of outer-joined table items.
2010-05-31 16:52:19 +04:00
Tor Didriksen
8231f082e5 Bug #49829 Many "hides virtual function" warnings with SunStudio
Backport from mysql-pe (of those parts which have not been upmerged from 5.1)



sql/field.cc:
  Local scope variable or method argument same as class attribute.
sql/item.cc:
  Rename auto variable to avoid name clash.
sql/item.h:
  Item_ref::basic_const_item had wrong signature (missing const)
  and was thus never called.
sql/partition_info.cc:
  Rename, to avoid name clashes.
sql/sql_load.cc:
  Rename, to avoid name clashes.
2010-05-31 12:59:58 +02:00
unknown
229cc4e191 Bug#52168 decimal casting catastrophes: crashes and valgrind errors on simple casts
The problem is that if a NULL is stored in an Item_cache_decimal object,
the associated my_decimal object is not initialized.  However, it is still
accessed when val_int() is called. The fix is to check for null_value
within val_int(), and return without accessing the my_decimal object when
the cached value is NULL.

Bug#52122 reports the same issue for val_real(), and this patch also includes
fixes for val_real() and val_str() and corresponding test cases from that
bug report.  

Also, NULL is returned from val_decimal() when value is null. This will
avoid that callers access an uninitialized my_decimal object.

Made similar changes to all other Item_cache classes.  Now all val_*
methods should return a well defined value when actual value is NULL.

mysql-test/r/type_decimal.result:
  Updated result file with test cases for Bug#52168 and Bug#52122.
mysql-test/t/type_decimal.test:
  Added test cases for Bug#52168 and Bug#52122.
sql/item.cc:
  In Item_cache_*::val_* methods, return a well defined value
  when actual value is NULL.
  
  This is especially important for Item_cache_decimal since
  otherwise one risk accessing an uninitialized my_decimal object.
sql/item.h:
  Added method Item_cache::has_value() which returns TRUE if cache 
  object contains a non-null value.
2010-05-28 17:30:39 +02:00
Martin Hansson
79e60f0a40 Bug#48157: crash in Item_field::used_tables
MySQL handles the join syntax "JOIN ... USING( field1,
... )" and natural joins by building the same parse tree as
a corresponding join with an "ON t1.field1 = t2.field1 ..."
expression would produce. This parse tree was not cleaned up
properly in the following scenario. If a thread tries to
lock some tables and finds that the tables were dropped and
re-created while waiting for the lock, it cleans up column
references in the statement by means a per-statement free
list. But if the statement was part of a stored procedure,
column references on the stored procedure's free list
weren't cleaned up and thus contained pointers to freed
objects.
      
Fixed by adding a call to clean up the current prepared
statement's free list.

This is a backport from MySQL 5.1
2010-05-11 16:21:05 +02:00
Alexey Kopytov
5ef2bdea81 Manual merge of mysql-5.1-bugteam to mysql-trunk-merge.
Conflicts:

Text conflict in mysql-test/r/grant.result
Text conflict in mysql-test/t/grant.test
Text conflict in mysys/mf_loadpath.c
Text conflict in sql/slave.cc
Text conflict in sql/sql_priv.h
2010-05-09 02:03:35 +04:00
Georgi Kodinov
addd0a3e67 On behalf of Kristofer :
Bug#53417 my_getwd() makes assumptions on the buffer sizes which not always hold true
      
The mysys library contains many functions for rewriting file paths. Most of these
functions makes implicit assumptions on the buffer sizes they write to. If a path is put
in my_realpath() it will propagate to my_getwd() which assumes that the buffer holding
the path name is greater than 2. This is not true in cases.
      
In the special case where a VARBIN_ITEM is passed as argument to the LOAD_FILE function
this can lead to a crash.
      
This patch fixes the issue by introduce more safe guards agaist buffer overruns.
2010-05-05 11:54:52 +03:00
Konstantin Osipov
4288e329dd A fix for Bug#11918 "SP does not accept variables in LIMIT clause"
Allow stored procedure variables in LIMIT clause.
Only allow variables of INTEGER types. 
Handle negative values by means of an implicit cast to UNSIGNED 
(similarly to prepared statement placeholders).
Add tests.
Make sure replication works by not doing NAME_CONST substitution
for variables in LIMIT clause.
Add replication tests.

mysql-test/r/sp.result:
  Update results (Bug#11918).
mysql-test/suite/rpl/r/rpl_sp.result:
  Update results (Bug#11918).
mysql-test/suite/rpl/t/rpl_sp.test:
  Add a test case for Bug#11918.
mysql-test/t/sp.test:
  Add a test case for Bug#11918.
sql/item.cc:
  Mark sp variables in LIMIT clause (a hack for replication).
sql/item.h:
  Mark sp variables in LIMIT clause (a hack for replication).
sql/share/errmsg-utf8.txt:
  Add a new error message (a type mismatch for LIMIT
  clause parameter).
sql/sp_head.cc:
  Binlog rewrite sp variables in LIMIT clause without NAME_CONST
  substitution.
sql/sql_string.cc:
  Implement append_ulonglong method.
sql/sql_string.h:
  Declare append_ulonglong().
sql/sql_yacc.yy:
  Support stored procedure variables in LIMIT.
2010-04-14 01:56:19 +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