Commit graph

1193 commits

Author SHA1 Message Date
Varun Gupta
ddc5c65333 MDEV-14779: using left join causes incorrect results with materialization and derived tables
Conversion of a subquery to a semi-join is blocked when we have an
IN subquery predicate in the on_expr of an outer join. Currently this
scenario is handled but the cases when an IN subquery predicate is wrapped
inside a Item_in_optimizer item then this blocking is not done.
2018-03-22 03:01:53 +05:30
Oleksandr Byelkin
b8405c853f MDEV-11958: LEFT JOIN with stored routine produces incorrect result
Added forgoten method of Item_func_sp to make it correctly work with LEFT/RIGHT JOIN.
Fixed inconsistency with the null table caches.
2017-05-23 11:06:31 +02:00
Sergei Golubchik
b948b5f7c6 bugfix: Item_func_min_max stored thd internally
It was used for get_datetime_value() and for thd->is_error().

But in fact, get_datetime_value() never used thd argument, because the
cache ptr argument was NULL. And thd->is_error() check was not needed
at that place at all.
2017-01-15 00:12:16 +01:00
Alexander Barkov
2f6fede8d5 MDEV-10524 Assertion `arg1_int >= 0' failed in Item_func_additive_op::result_precision()
This change is a backport from 10.0 to 5.5 for:
1. The full patch for:
     MDEV-4841 Wrong character set of ADDTIME() and DATE_ADD()
     9adb6e991e

2. A small fragment of:
     MDEV-5298 Illegal mix of collations on timestamp
     03f6778d61
   which overrides Item_temporal_hybrid_func::cmp_type(),
   and adds a new line into cache_temporal_4265.result.
2016-12-19 14:28:08 +04:00
Sergei Golubchik
0991e19e9d Merge branch 'bb-5.5-serg' into 5.5 2016-04-20 20:25:46 +02:00
Sergei Golubchik
b069d19284 Merge branch 'mysql/5.5' into 5.5 2016-04-20 15:25:55 +02:00
Alexander Barkov
9a987142f9 MDEV-9745 Crash with CASE WHEN TRUE THEN COALESCE(CAST(NULL AS UNSIGNED)) ELSE 4 END
This is a backport of the patch for MDEV-9653 (fixed earlier in 10.1.13).

The code in Item_func_case::fix_length_and_dec() did not
calculate max_length and decimals properly.

In case of any numeric result (DECIMAL, REAL, INT) a generic method
Item_func_case::agg_num_lengths() was called, which could erroneously result
into a DECIMAL item with max_length==0 and decimals==0, so the constructor of
Field_new_decimals tried to create a field of DECIMAL(0,0) type,
which caused a crash.

Unlike Item_func_case, the code responsible for merging attributes in
Item_func_coalesce::fix_length_and_dec() works fine: it has specific execution
branches for all distinct numeric types and correctly creates a DECIMAL(1,0)
column instead of DECIMAL(0,0) for the same set of arguments.

The fix does the following:
- Moves the attribute merging code from Item_func_coalesce::fix_length_and_dec()
  to a new method Item_func_hybrid_result_type::fix_attributes()
- Removes the wrong code from Item_func_case::fix_length_and_dec()
  and reuses fix_attributes() in both Item_func_coalesce::fix_length_and_dec()
  and Item_func_case::fix_length_and_dec()
- Fixes count_real_length() and count_decimal_length() to get an array
  of Items as an argument, instead of using Item::args directly.
  This is needed for Item_func_case::fix_length_and_dec().
- Moves methods Item_func::count_xxx_length() from "public" to "protected".
- Removes Item_func_case::agg_num_length(), as it's not used any more.
- Additionally removes Item_func_case::agg_str_length(),
  as it also was not used (dead code).
2016-04-20 08:53:30 +04:00
Knut Anders Hatlen
95825fa28a Bug#21682356: STOP INJECTING DATA ITEMS IN AN ERROR MESSAGE
GENERATED BY THE EXP() FUNCTION

When generating the error message for numeric overflow, pass a flag to
Item::print() that prevents it from expanding constant expressions and
parameters to the values they evaluate to.

For consistency, also pass the flag to Item::print() when
Item_func_spatial_collection::fix_length_and_dec() generates an error
message. It doesn't make any difference at the moment, since constant
expressions haven't been evaluated yet when this function is called.
2016-01-17 20:28:00 +01:00
Oleksandr Byelkin
02a38fd27e MDEV-8624: MariaDB hangs on query with many logical condition
Made no_rows_in_result()/restore_to_before_no_rows_in_result() not looking
annecessary deep with walk() method.
2015-09-28 11:56:33 +02:00
Oleksandr Byelkin
102a85f9f3 MDEV-8663: IF Statement returns multiple values erroneously (or Assertion `!null_value' failed in Item::send(Protocol*, String*))
Postreview addons by Bar

Fix: keeping contract: NULL value mean NULL pointer in val_str and val_deciman.
2015-09-04 15:56:58 +02:00
Sergei Golubchik
a978bdda1e mysql-5.5.41 merge 2014-12-19 11:35:44 +01:00
Sergei Golubchik
5d0122bd77 MDEV-7113 difference between check_vcol_func_processor and check_partition_func_processor
MDEV-6789 segfault in Item_func_from_unixtime::get_date on updating table with virtual columns

* prohibit VALUES in partitioning expression
* prohibit user and system variables in virtual column expressions
* fix Item_func_date_format to cache locale (for %M/%W to return the same as MONTHNAME/DAYNAME)
* fix Item_func_from_unixtime to cache time_zone directly, not THD (and not to crash)
* added tests for other incorrectly allowed (in vcols) functions to see that they don't crash
2014-11-18 15:42:40 +01:00
mithun
73b99f055e Bug #19372926 : 5.5.38 FAILS FUNC_MATH MTR TEST.
Issue :
-------
This seems for some platform -(LONGLONG_MIN) is
not flagged as out of range.

Fix:
----
Fix is backported from mysql-5.6 bug 14314156.
Fixed by adding an explicit test for this value in
Item_func_neg::int_op().

sql/item_func.cc:
  For some platforms we need special handling of
  LONGLONG_MIN to guarantee overflow.
2014-11-03 18:10:28 +05:30
mithun
c5dfdec568 Bug #19372926 : 5.5.38 FAILS FUNC_MATH MTR TEST.
Issue :
-------
This seems for some platform -(LONGLONG_MIN) is
not flagged as out of range.

Fix:
----
Fix is backported from mysql-5.6 bug 14314156.
Fixed by adding an explicit test for this value in
Item_func_neg::int_op().
2014-11-03 18:10:28 +05:30
Sergei Golubchik
4b4de01fae 5.3 merge 2014-08-01 16:51:12 +02:00
Alexander Barkov
5b452ae027 MDEV-4511 Assertion `scale <= precision' fails on GROUP BY TIMEDIFF with incorrect types
MDEV-6302 Wrong result set when using GROUP BY FROM_UNIXTIME(...)+0
Fixed.
2014-07-28 13:47:55 +04:00
Sergei Golubchik
5d0c01608c 5.2 merge 2014-03-16 21:03:01 +01:00
Sergei Golubchik
e772cbd7b7 5.1 merge 2014-03-16 13:59:44 +01:00
Sergei Golubchik
d7304375e5 mysql-5.1.73 merge 2014-03-15 18:24:15 +01:00
Sergei Golubchik
84651126c0 MySQL-5.5.36 merge
(without few incorrect bugfixes and with 1250 files where only a copyright year was changed)
2014-02-17 11:00:51 +01:00
Murthy Narkedimilli
c92223e198 Updated/added copyright headers 2014-01-06 10:52:35 +05:30
Murthy Narkedimilli
496abd0814 Updated/added copyright headers 2014-01-06 10:52:35 +05:30
Sergei Golubchik
e68bccc743 5.3 merge 2013-12-13 13:00:38 +01:00
Alexander Barkov
62e959437e MDEV-5374 main.func_time fails with valgrind warning
"Conditional jump or move depends on uninitialised"
in Item_time_typecast::get_date.

Adding "null_value" into the debug assert condition.
2013-12-03 15:08:43 +04:00
Alexander Barkov
b97b9536c7 MDEV-4857 Wrong result of HOUR('1 00:00:00')
modified:
  mysql-test/r/func_time.result
  mysql-test/t/func_time.test
  sql-common/my_time.c
  sql/item_func.h
  sql/item_timefunc.cc
  sql/mysql_priv.h
  sql/time.cc
2013-12-02 15:09:34 +04:00
Alexander Barkov
5a8bd446ad Merge 5.3->5.5
pending merges:
  Alexander Barkov 2013-12-02 MDEV-4857 Wrong result of HOUR('1 00:00:00')
2013-12-02 15:50:35 +04:00
Igor Babaev
092a238864 Fixed a problem of the patch for mdev-5105 that caused valgrind complains. 2013-10-11 12:50:30 -07:00
Igor Babaev
7c87385e30 Fixed bug mdev-5105.
The bug caused a memory overwrite in the function update_ref_and_keys()
It happened due to a wrong value of SELECT_LEX::cond_count. This value
historically was calculated by the fix_fields method. Now the logic of
calling this method became too complicated and, as a result, this value
is calculated not always correctly.
The patch changes the way how and when  the values of SELECT_LEX::cond_count
and of SELECT_LEX::between_count are calculated. The new code does it just at
the beginning of update_ref_and_keys().
2013-10-10 10:08:26 -07:00
Igor Babaev
c7db46a242 Merge 5.3-5.5 2013-10-13 13:43:29 -07:00
unknown
64d6d8334f merge 5.3 -> 5.5 2013-09-25 17:16:13 +03:00
unknown
ec7da1561e MDEV-5039: incorrect Item_func_regex::update_used_tables()
Other fix of maybe_null problem and revert of revno: 3608 "MDEV-3873 & MDEV-3876 & MDEV-3912 : Wrong result (extra rows) with ALL subquery from a MERGE view."
2013-09-25 15:30:13 +03:00
Alexander Barkov
cf9cc19e91 MDEV-4724 Some temporal functions do not preserve microseconds 2013-09-13 14:43:10 +04:00
Alexander Barkov
51dcf4dcff Merge from 5.3.
pending merges:
  Alexander Barkov 2013-09-12 MDEV-4724 Some temporal functions do not pre...
2013-09-13 12:06:17 +04:00
Alexander Barkov
499ddea576 MDEV-4724 Some temporal functions do not preserve microseconds 2013-09-12 21:31:14 +04:00
Alexander Barkov
8b5da9f73b Merge from 5.3
pending merges:
  Alexander Barkov 2013-09-09 MDEV-4863 COALESCE(time_or_datetime) returns...
2013-09-10 10:08:11 +04:00
Alexander Barkov
c2b38529a9 MDEV-4863 COALESCE(time_or_datetime) returns wrong results in numeric context 2013-09-09 15:32:25 +04:00
Sergei Golubchik
b838d081ad mysql-5.5.33 merge 2013-09-06 22:31:30 +02:00
Sergei Golubchik
005c7e5421 mysql-5.5.32 merge 2013-07-16 19:09:54 +02:00
Alexander Barkov
c51ed128b0 Merge from 5.3 2013-07-10 02:05:06 +04:00
Sergei Golubchik
782d86af44 MDEV-4257 Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))' fails on FROM subquery with fulltext search, derived_merge=on
remove emtpty Item_func_match::update_used_tables() method
2013-07-05 16:02:02 +02:00
Chaithra Gopalareddy
4bd94e7d1c Bug #16119355: PREPARED STATEMENT: READ OF FREED MEMORY WITH
STRING CONVERSION FUNCTIONS
            
Problem:
While executing the prepared statement, user variable is
set to memory which would be freed at the end of
execution.
If the statement is executed again, valgrind throws
error when accessing this pointer.
                  
Analysis:
                
1. First time when Item_func_set_user_var::check is called,
   memory is allocated for "value" to store the result.
   (In the call to copy_if_not_alloced).
2. While sending the result, Item_func_set_user_var::check
   is called again. But, this time, its called with
   "use_result_field" set to true. 
   As a result, we call result_field->val_str(&value).
3. Here memory allocated for "value" gets freed. And "value"
   gets set to "result_field", with "str_length" being that of
   result_field's.
4. In the call to JOIN::cleanup, result_field's memory gets
   freed as this is allocated in a chunk as part of the
   temporary table which is needed to execute the query.
5. Next time, when execute of the same statement is called,
   "value" will be set to memory which is already freed.
   Valgrind error occurs as "str_length" is positive 
   (set at Step 3)
                  
Note that user variables list is stored as part of the Lex object
in set_var_list. Hence the persistance across executions.
            
Solution:
Patch for Bug#11764371 fixed in mysql-5.6+ fixes this problem 
as well.So backporting the same.
            
In the solution for Bug#11764371, we create another object of 
user_var and repoint it to temp_table's field. As a result while 
deleting the alloced buffer in Step 3, since the cloned object 
does not own the buffer, deletion will not happen.
So at step 5 when we execute the statement second time, the 
original object will be used and since deletion did not happen 
valgrind will not complain about dangling pointer.


sql/item_func.h:
  Add constructors.
sql/sql_select.cc:
  Change user variable assignment functions to read from fields after
  tables have been unlocked.
2013-05-23 15:00:31 +05:30
Chaithra Gopalareddy
07ef11b2cc Bug#16119355:PREPARED STATEMENT: READ OF FREED MEMORY WITH STRING CONVERSION FUNCTIONS
Reverting fix for Bug#16119355 in 5.1 as this needs two patches 
from 5.5+ to work for a certain case
2013-05-10 19:18:21 +05:30
Chaithra Gopalareddy
c334bc8cfd Merge from 5.1 to 5.5 2013-05-07 18:00:00 +05:30
Chaithra Gopalareddy
ff55c9da68 Merge from 5.1 to 5.5 2013-05-07 18:00:00 +05:30
Sergei Golubchik
b381cf843c mysql-5.5.31 merge 2013-05-07 13:05:09 +02:00
Chaithra Gopalareddy
266dd9c097 Bug #16119355: PREPARED STATEMENT: READ OF FREED MEMORY WITH
STRING CONVERSION FUNCTIONS
            
Problem:
While executing the prepared statement, user variable is
set to memory which would be freed at the end of
execution.
If the statement is executed again, valgrind throws
error when accessing this pointer.
            
Analysis:
            
1. First time when Item_func_set_user_var::check is called,
memory is allocated for "value" to store the result.
(In the call to copy_if_not_alloced).
2. While sending the result, Item_func_set_user_var::check
is called again. But, this time, its called with
"use_result_field" set to true. 
As a result, we call result_field->val_str(&value).
3. Here memory allocated for "value" gets freed. And "value"
gets set to "result_field", with "str_length" being that of
result_field's.
4. In the call to JOIN::cleanup, result_field's memory gets
freed as this is allocated in a chunk as part of the
temporary table which is needed to execute the query.
5. Next time, when execute of the same statement is called,
"value" will be set to memory which is already freed.
Valgrind error occurs as "str_length" is positive 
(set at Step 3)
            
Note that user variables list is stored as part of the Lex object
in set_var_list. Hence the persistance across executions.
      
Solution:
Patch for Bug#11764371 fixed in mysql-5.6+ fixes this problem 
as well.So backporting the same.
      
In the solution for Bug#11764371, we create another object of 
user_var and repoint it to temp_table's field. As a result while 
deleting the alloced buffer in Step 3, since the cloned object 
does not own the buffer, deletion will not happen.
So at step 5 when we execute the statement second time, the 
original object will be used and since deletion did not happen 
valgrind will not complain about dangling pointer.


sql/item_func.h:
  Add constructors.
sql/sql_select.cc:
  Change user variable assignment functions to read from fields after
  tables have been unlocked.
2013-05-07 16:08:48 +05:30
Chaithra Gopalareddy
12a26cd6e0 Bug #16119355: PREPARED STATEMENT: READ OF FREED MEMORY WITH
STRING CONVERSION FUNCTIONS
            
Problem:
While executing the prepared statement, user variable is
set to memory which would be freed at the end of
execution.
If the statement is executed again, valgrind throws
error when accessing this pointer.
            
Analysis:
            
1. First time when Item_func_set_user_var::check is called,
memory is allocated for "value" to store the result.
(In the call to copy_if_not_alloced).
2. While sending the result, Item_func_set_user_var::check
is called again. But, this time, its called with
"use_result_field" set to true. 
As a result, we call result_field->val_str(&value).
3. Here memory allocated for "value" gets freed. And "value"
gets set to "result_field", with "str_length" being that of
result_field's.
4. In the call to JOIN::cleanup, result_field's memory gets
freed as this is allocated in a chunk as part of the
temporary table which is needed to execute the query.
5. Next time, when execute of the same statement is called,
"value" will be set to memory which is already freed.
Valgrind error occurs as "str_length" is positive 
(set at Step 3)
            
Note that user variables list is stored as part of the Lex object
in set_var_list. Hence the persistance across executions.
      
Solution:
Patch for Bug#11764371 fixed in mysql-5.6+ fixes this problem 
as well.So backporting the same.
      
In the solution for Bug#11764371, we create another object of 
user_var and repoint it to temp_table's field. As a result while 
deleting the alloced buffer in Step 3, since the cloned object 
does not own the buffer, deletion will not happen.
So at step 5 when we execute the statement second time, the 
original object will be used and since deletion did not happen 
valgrind will not complain about dangling pointer.
2013-05-07 16:08:48 +05:30
Sergei Golubchik
6599fd3e9c 5.3 merge 2013-03-27 10:03:28 +01:00
Murthy Narkedimilli
8afe262ae5 Fix for Bug 16395495 - OLD FSF ADDRESS IN GPL HEADER 2013-03-19 15:53:48 +01:00
Murthy Narkedimilli
d978016d93 Fix for Bug 16395495 - OLD FSF ADDRESS IN GPL HEADER 2013-03-19 15:53:48 +01:00