Commit graph

55 commits

Author SHA1 Message Date
Sergey Glukhov
56bff85247 Bug#11766212 59270: NOT IN (YEAR( ... ), ... ) PRODUCES MANY VALGRIND WARNINGS
Valgrind warning happens due to early null values check
in Item_func_in::fix_length_and_dec(before item evaluation).
As result null value items with uninitialized values are
placed into array and it leads to valgrind warnings during
value array sorting.
The fix is to check null value after item evaluation, item
is evaluated in in_array::set() method.
2011-04-12 13:51:36 +04:00
Alexey Kopytov
07e95b39c4 Bug#54477: Crash on IN / CASE with NULL arguments
Incorrect handling of NULL arguments could lead to a crash on
the IN or CASE operations when either NULL arguments were
passed explicitly as arguments (IN) or implicitly generated by
the WITH ROLLUP modifier (both IN and CASE).

Item_func_case::find_item() assumed all necessary comparators
to be instantiated in fix_length_and_dec(). However, in the
presence of WITH ROLLUP modifier, arguments could be
substituted with an Item_null leading to an "unexpected"
STRING_RESULT comparator being invoked.

In addition to the problem identical to the above,
Item_func_in::val_int() could crash even with explicitly passed
NULL arguments due to an optimization in fix_length_and_dec()
leading to NULL arguments being ignored during comparators
creation.
2010-06-22 22:53:08 +04:00
Gleb Shchepa
2b78dbff54 Bug #44139: Table scan when NULL appears in IN clause
SELECT ... WHERE ... IN (NULL, ...) does full table scan,
even if the same query without the NULL uses efficient range scan.

The bugfix for the bug 18360 introduced an optimization:
if
  1) all right-hand arguments of the IN function are constants
  2) result types of all right argument items are compatible
     enough to use the same single comparison function to
     compare all of them to the left argument,

then

  we can convert the right-hand list of constant items to an array
  of equally-typed constant values for the further
  QUICK index access etc. (see Item_func_in::fix_length_and_dec()).

The Item_null constant item objects have STRING_RESULT
result types, so, as far as Item_func_in::fix_length_and_dec()
is aware of NULLs in the right list, this improvement efficiently
optimizes IN function calls with a mixed right list of NULLs and
string constants. However, the optimization doesn't affect mixed
lists of NULLs and integers, floats etc., because there is no
unique common comparator.


New optimization has been added to ignore the result type
of NULL constants in the static analysis of mixed right-hand lists.
This is safe, because at the execution phase we care about
presence of NULLs anyway.

1. The collect_cmp_types() function has been modified to optionally
   ignore NULL constants in the item list.
2. NULL-skipping code of the Item_func_in::fix_length_and_dec()
   function has been modified to work not only with in_string
   vectors but with in_vectors of other types.
2009-10-05 10:27:36 +05:00
Georgi Kodinov
8fb82e3fe0 Bug #44399 : crash with statement using TEXT columns, aggregates, GROUP BY, and
HAVING
            
When calculating GROUP BY the server caches some expressions. It does
that by allocating a string slot (Item_copy_string) and assigning the 
value of the expression to it. This effectively means that the result
type of the expression can be changed from whatever it was to a string.
As this substitution takes place after the compile-time result type 
calculation for IN but before the run-time type calculations, 
it causes the type calculations in the IN function done at run time 
to get unexpected results different from what was prepared at compile time.
                  
In the CASE ... WHEN ... THEN ... statement there was a similar problem
and it was solved by artificially adding a STRING argument to the set of 
types of the IN/CASE arguments at compile time, so if any of the 
arguments of the CASE function changes its type to a string it will 
still be covered by the information prepared at compile time.
2009-05-25 11:00:40 +03:00
Georgi Kodinov
f68a992043 Revert of the fix for bug #44399 (joro@sun.com-20090512135917-kal1dvtqpqgnj3yc). 2009-05-20 14:14:33 +03:00
Georgi Kodinov
e16c3d866e Bug #44399: crash with statement using TEXT columns, aggregates, GROUP BY,
and HAVING

When calculating GROUP BY the server caches some expressions. It does
that by allocating a string slot (Item_copy_string) and assigning the 
value of the expression to it. This effectively means that the result
type of the expression can be changed from whatever it was to a string.
As this substitution takes place after the compile-time result type 
calculation for IN but before the run-time type calculations, 
it causes the type calculations in the IN function done at run time 
to get unexpected results different from what was prepared at compile time.

In the CASE ... WHEN ... THEN ... statement there was a similar problem
and it was solved by artificially adding a STRING argument to the matrix
at compile time, so if any of the arguments of the CASE function changes 
its type to a string it will still be covered by the information prepared 
at compile time.
Extended the CASE fix for cover the IN case.
An alternative way of fixing this problem is by caching the result type of 
the arguments at compile time and using the cached information at run time
instead of re-calculating the result types.
Preferred the CASE approach for uniformity and fix localization.
2009-05-12 16:59:17 +03:00
Gleb Shchepa
33cbf93ced Bug #41363: crash of mysqld on windows with aggregate in case
Execution of queries containing the CASE function of
aggregate function like in "SELECT ... CASE ARGV(...) WHEN ..."
crashed the server.


The CASE function caches pointers to concrete comparison
functions for an each pair of types of CASE-WHERE clause
parameters, i.e. for the "CASE INT_RESULT WHERE REAL_RESULT
THEN ... WHERE DECIMAL_RESULT ... END" function call it
caches comparisons for INT_RESULT with REAL_RESULT and
for INT_RESULT with DECIMAL_RESULT. Usually a result
type is known after a call to the fix_fields function,
however, the setup_copy_fields function call may
wrap aggregate items with Item_copy_string that has
STRING_RESULT result type, so setup_copy_fields may
change argument result types of the CASE function after
call to Item_func_case::fix_fields/fix_length_and_dec.
Then the Item_func_case::find_item function tries to
use comparison function for unexpected pair of the
STRING_RESULT and some other type - that caused
an assertion failure of server crash.

The Item_func_case::fix_length_and_dec function has
been modified to take into account possible STRING_RESULT
result type in the presence of aggregate arguments of
the CASE function.
2008-12-31 15:55:04 +04:00
Gleb Shchepa
211164ff8c Bug #37761: IN handles NULL differently for table-subquery
and value-list

The server returns unexpected results if a right side of the 
NOT IN clause consists of NULL value and some constants of
the same type, for example:

  SELECT * FROM t WHERE NOT t.id IN (NULL, 1, 2) 
  
may return 3, 4, 5 etc if a table contains these values.


The Item_func_in::val_int method has been modified:
unnecessary resets of an Item_func_case::has_null field 
value has been moved outside of an argument comparison
loop. (Also unnecessary re-initialization of the null_value
field has been moved).
2008-07-14 14:06:49 +05:00
gshchepa@devsrv-b.mysql.com
7f0e9065f8 Fixed bug #31075.
The `SELECT col FROM t WHERE col NOT IN (col, ...) GROUP BY col'
crashed in the range optimizer.

The get_func_mm_tree function has been modified to check the
Item_func_in::array field for the NULL value before using of that
value.
2007-09-26 12:45:08 +02:00
ramil/ram@ramil.myoffice.izhnet.ru
722f9305e0 Merge mysql.com:/home/ram/work/b28748/b28748.5.0
into  mysql.com:/home/ram/work/b28748/b28748.5.1
2007-06-13 14:16:39 +05:00
ramil/ram@mysql.com/ramil.myoffice.izhnet.ru
e570a72b13 Fix for bug #28748: "Select" returning one value too few
Problem: we may get unexpected results comparing [u]longlong values as doubles.
Fix: adjust the test to use integer comparators.
Note: it's not a real fix, we have to implement some new comparators 
to completely solve the original problem (see my comment in the bug report).
2007-06-09 17:13:33 +05:00
holyfoot/hf@hfmain.(none)
ecbf43a3f1 Merge mysql.com:/home/hf/work/mrg/mysql-5.0-opt
into  mysql.com:/home/hf/work/mrg/mysql-5.1-opt
2007-03-22 11:50:24 +04:00
igor@olga.mysql.com
03ae298ec3 Fixed bug #27362: crash at evaluation of IN predicate when one
of its argument happened to be a decimal expression returning
the NULL value.
The crash was due to the fact the function in_decimal::set did
not take into account that val_decimal() could return 0 if 
the decimal expression had been evaluated to NULL.
2007-03-22 00:05:36 -07:00
holyfoot/hf@hfmain.(none)
75be7cd1ae Merge mysql.com:/home/hf/work/mrg/mysql-5.0-opt
into  mysql.com:/home/hf/work/mrg/mysql-5.1-opt
2007-03-08 19:08:28 +04:00
gkodinov/kgeorge@macbook.gmz
f5e9c10d58 Bug#19342: additional test case for code coverage 2007-03-06 18:52:00 +02:00
gkodinov/kgeorge@macbook.gmz
be75593165 Bug #19342:
Several problems here :
 1. The conversion to double of an hex string const item
 was not taking into account the unsigned flag.
 
 2. IN was not behaving in the same was way as comparisons
 when performed over an INT/DATE/DATETIME/TIMESTAMP column
 and a constant. The ordinary comparisons in that case 
 convert the constant to an INTEGER value and do int 
 comparisons. Fixed the IN to do the same.
 
 3. IN is not taking into account the unsigned flag when 
 calculating <expr> IN (<int_const1>, <int_const2>, ...).
 Extended the implementation of IN to store and process
 the unsigned flag for its arguments.
2007-03-02 16:25:56 +02:00
gkodinov/kgeorge@rakia.gmz
7ffb94edcf Merge gkodinov@bk-internal.mysql.com:/home/bk/mysql-5.1-opt
into  rakia.gmz:/home/kgeorge/mysql/autopush/B20420-5.1-opt
2007-02-16 14:05:09 +02:00
gkodinov/kgeorge@macbook.gmz
138e9c403e BUG#20420: optimizer reports wrong keys on left join with IN
When checking if an IN predicate can be evaluated using a key
 the optimizer makes sure that all the arguments of IN are of
 the same result type. To assure that it check whether 
 Item_func_in::array is filled in. 
 However Item_func_in::array is set if the types are
 the same AND all the arguments are compile time constants.
 Fixed by introducing Item_func_in::arg_types_compatible
 flag to allow correct checking of the desired condition.
2007-02-16 13:56:06 +02:00
gluh@eagle.(none)
7b291e36cf Merge mysql.com:/home/gluh/MySQL/Merge/5.1
into  mysql.com:/home/gluh/MySQL/Merge/5.1-opt
2007-01-24 19:54:40 +04:00
gkodinov/kgeorge@macbook.gmz
13238b0e3d merge of 5.0-opt -> 5.1-opt 2007-01-24 15:55:16 +02:00
gkodinov/kgeorge@macbook.gmz
17a0207ece Merge macbook.gmz:/Users/kgeorge/mysql/work/mysql-5.0-opt
into  macbook.gmz:/Users/kgeorge/mysql/work/merge-5.1-opt
2007-01-23 12:34:50 +02:00
gluh@mysql.com/eagle.(none)
e34b0056f2 Merge mysql.com:/home/gluh/MySQL/Merge/5.0
into  mysql.com:/home/gluh/MySQL/Merge/5.0-opt
2007-01-23 14:08:58 +04:00
gkodinov/kgeorge@macbook.gmz
134e949317 BUG#20420: optimizer reports wrong keys on left join with IN
The optimizer needs to evaluate whether predicates are better
 evaluated using an index. IN is one such predicate.
 To qualify an IN predicate must involve a field of the index
 on the left and constant arguments on the right.
 However whether an expression is a constant can be determined only
 by knowing the preceding tables in the join order. 
 Assuming that only IN predicates with expressions on the right that
 are constant for the whole query qualify limits the scope of 
 possible optimizations of the IN predicate (more specifically it
 doesn't allow the "Range checked for each record" optimization for
 such an IN predicate.
 Fixed by not pre-determining the optimizability of the IN predicate
 in the case when all right IN operands are not SQL constant expressions
2007-01-15 19:15:52 +02:00
kaa@polly.local
d9dc018226 Merge polly.local:/tmp/maint/bug24261/my51-bug24261
into  polly.local:/home/kaa/src/maint/mysql-5.1-maint
2006-12-08 23:47:49 +03:00
kaa@polly.local
6d1e7bcf7b Merge polly.local:/tmp/maint/bug24261/my50-bug24261
into  polly.local:/home/kaa/src/maint/mysql-5.0-maint
2006-12-08 22:38:03 +03:00
kaa@polly.local
439ce0307b Merge polly.local:/tmp/maint/bug24261/my50-bug24261
into  polly.local:/tmp/maint/bug24261/my51-bug24261
2006-12-08 16:02:42 +03:00
kaa@polly.local
32d1ad79b0 Fix for bug #24261 "crash when WHERE contains NOT IN ('<negative value>') for unsigned column type"
When calculating a SEL_TREE for the "c_{i-1} < X < c_i" interval, check if the tree returned for the "-inf < X < c_0" interval is NULL
2006-11-27 19:12:10 +03:00
kroki/tomash@moonlight.intranet
0f94e84fd2 Merge moonlight.intranet:/home/tomash/src/mysql_ab/mysql-5.0-bug17047
into  moonlight.intranet:/home/tomash/src/mysql_ab/mysql-5.1-bug17047
2006-11-16 14:13:03 +03:00
kroki/tomash@moonlight.intranet
23efecdb3c Merge moonlight.intranet:/home/tomash/src/mysql_ab/mysql-4.1-bug17047
into  moonlight.intranet:/home/tomash/src/mysql_ab/mysql-5.0-bug17047
2006-11-16 13:25:55 +03:00
kroki/tomash@moonlight.intranet
b8d5451565 BUG#17047: CHAR() and IN() can return NULL without signaling NULL result
The problem was that some functions (namely IN() starting with 4.1, and
CHAR() starting with 5.0) were returning NULL in certain conditions,
while they didn't set their maybe_null flag.  Because of that there could
be some problems with 'IS NULL' check, and statements that depend on the
function value domain, like CREATE TABLE t1 SELECT 1 IN (2, NULL);.

The fix is to set maybe_null correctly.
2006-11-16 13:21:38 +03:00
evgen@moonbone.local
9fc769ff72 Fixed bug #18360: Type aggregation for IN and CASE may lead to a wrong
result

The IN function aggregates result types of all expressions. It uses that 
type in comparison of left expression and expressions in right part. 
This approach works in most cases. But let's consider the case when the
right part contains both strings and integers. In that case this approach may
cause wrong results because all strings which do not start with a digit are
evaluated as 0.
CASE uses the same approach when a CASE expression is given thus it's also
affected.

The idea behind this fix is to make IN function to compare expressions with
different result types differently. For example a string in the left
part will be compared as string with strings specified in right part and
will be converted to real for comparison to int or real items in the right
part.

A new function called collect_cmp_types() is added. It collects different
result types for comparison of first item in the provided list with each 
other item in the list. 

The Item_func_in class now can refer up to 5 cmp_item objects: 1 for each
result type for comparison purposes. cmp_item objects are allocated according
to found result types. The comparison of the left expression with any
right part expression is now based only on result types of these expressions.

The Item_func_case class is modified in the similar way when a CASE
expression is specified. Now it can allocate up to 5 cmp_item objects
to compare CASE expression with WHEN expressions of different types.
The comparison of the CASE expression with any WHEN expression now based only 
on result types of these expressions.
2006-09-26 20:52:54 +04:00
evgen@moonbone.local
de8f05956d Merge 2006-06-20 00:52:26 +04:00
evgen@moonbone.local
279c310b66 item_cmpfunc.cc, func_in.result, func_in.test:
Reverted fix for bug#18360
2006-06-20 00:50:09 +04:00
evgen@moonbone.local
de96d52999 Manually merged 2006-05-30 19:16:30 +04:00
evgen@moonbone.local
641f852de8 Fixed bug#18360: Incorrect type coercion in IN() results in false comparison
The IN() function uses agg_cmp_type() to aggregate all types of its arguments
to find out some common type for comparisons. In this particular case the 
char() and the int was aggregated to double because char() can contain values
like '1.5'. But all strings which do not start from a digit are converted to
0. thus 'a' and 'z' become equal. 
This behaviour is reasonable when all function arguments are constants. But 
when there is a field or an expression this can lead to false comparisons. In
this case it makes more sense to coerce constants to the type of the field
argument.

The agg_cmp_type() function now aggregates types of constant and non-constant
items separately. If some non-constant items will be found then their
aggregated type will be returned. Thus after the aggregation constants will be
coerced to the aggregated type.
2006-05-30 00:36:48 +04:00
sergefp@mysql.com
e5ae30fdef BUG#19618: Crash for unsigned_col NOT IN (-1, ... )
- When manually constructing a SEL_TREE for "t.key NOT IN(...)", take into account that 
  get_mm_parts may return a tree with type SEL_TREE::IMPOSSIBLE
- Added missing OOM checks
- Added comments
2006-05-15 14:18:23 +04:00
sergefp@mysql.com
1d4acfb668 BUG#15872: Don't run the range analyzer on "t1.keypart NOT IN (const1, ..., )", as that consumes
too much memory. Instead, either create the equvalent SEL_TREE manually, or create only two ranges that
strictly include the area to scan
(Note: just to re-iterate: increasing NOT_IN_IGNORE_THRESHOLD will make optimization run slower for big 
IN-lists, but the server will not run out of memory. O(N^2) memory use has been eliminated)
2006-04-25 23:33:31 +04:00
bar@mysql.com
39b0712cf7 type_binary.result, type_binary.test:
new file
mysql_fix_privilege_tables.sql, mysql_create_system_tables.sh:
  Adding true BINARY/VARBINARY: fixing "password" type, not to be 0x00-padding.
Many files:
  Adding true BINARY/VARBINARY: fixing tests not to output 0x00 bytes.
  Adding true BINARY/VARBINARY: new pad_char structure member.
ctype-bin.c:
  Adding true BINARY/VARBINARY: new pad_char structure member.
  New strnxfrm, with two trailing length bytes.
field.cc:
  Adding true BINARY/VARBINARY.
2005-10-13 19:16:19 +05:00
sergefp@mysql.com
9a05a887de Manually merged 2005-09-24 02:39:52 +04:00
sergefp@mysql.com
40ba88ca07 Fix for BUG#13419: In "ref" optimizer, take into account that item=Item_func_in(x,y) is
not equivalent to "x=y" when item->negated == TRUE.
2005-09-23 13:43:20 +04:00
monty@mysql.com
15d48525af Merge mysql.com:/home/my/mysql-4.1
into  mysql.com:/home/my/mysql-5.0
2005-07-28 17:09:54 +03:00
monty@mysql.com
3c12d0ae54 Added end marker for tests to make future merges easier 2005-07-28 03:22:47 +03:00
igor@rurik.mysql.com
bff3507b1d func_in.result, func_in.test:
Fixed bug #11885.
sql_select.cc:
  Fixed bug #11885.
  Predicates of the forms 'a IN (v)' 'a NOT IN (v)' now
  is replaced by 'a=v' and 'a<>v' at the parsing stage.
sql_yacc.yy:
  Fixed bug #11885.
  Predicates of the forms 'a IN (v)' 'a NOT IN (v)' now 
  is replaced by 'a=v' and 'a<>v' at the parsing stage.
2005-07-16 18:06:34 -07:00
bar@mysql.com
ca48cfbfcc item_cmpfunc.cc:
Bug#7834 Illegal mix of collations in IN operator
  IN was the first function supporting 
  character set convertion.
  agg_arg_charsets() was written afterwards,
  which is more flexible.
  Now IN just reuses this function.
2005-01-20 15:38:56 +04:00
igor@rurik.mysql.com
4df18b1aae func_in.result, func_in.test:
Added a case for bug #6365.
item_cmpfunc.cc:
  Fixed bug #6365 : Server crashed when list of values
  in IN predicate contains NULL while the tested field is
  of the character type and not of the default set;
  e.g. when f in 'f IN (NULL,'aa') belongs to binary
  character set, while the default character set is latin1.
2004-11-04 20:39:52 -08:00
bar@mysql.com
153e18a252 Allow IN to convert arguments into Unicode in some cases. 2004-09-01 15:39:15 +05:00
monty@mysql.com
f43093ec0e After merge fixes
Added more DBUG statements
Ensure that we are comparing end space with BINARY strings
Use 'any_db' instead of '' to mean any database. (For HANDLER command)
Only strip ' ' when comparing CHAR, not other space-like characters (like \t)
2004-02-16 10:03:25 +02:00
bell@sanja.is.com.ua
33346e26af added code covarage for functions convert(), nullif(), crc32(), is_used_lock(), char_lengtrh(), bit_xor()
added string length for more speed
made code covarage for print() method of Item
fixed printability of some items (SCRUM) (WL#1274)
2003-10-30 12:57:26 +02:00
monty@mashka.mysql.fi
4f7512160b After merge fixes
Use server character set if --default-character-set is not used
Added convert_string() for more efficient alloc+character-set convert of strings
2003-08-19 00:08:08 +03:00
bar@bar.mysql.r18.ru
e6cd54379e IN now aggregates all argument types for comparison 2003-07-18 14:03:54 +05:00