Commit graph

1095 commits

Author SHA1 Message Date
Sergei Petrunia
2bd4dc38e0 Merge branch '10.2' into bb-10.2-mdev9543 2016-03-28 22:18:38 +03:00
Sergei Golubchik
f67a2211ec Merge branch '10.1' into 10.2 2016-03-23 22:36:46 +01:00
Alexander Barkov
9476854211 MDEV-9369 IN operator with ( num, NULL ) gives inconsistent result
Based on this commit into MySQL-5.7:
> commit 8e51b845aafc8b4cdebd763c8aebda262ac2d4cd
> Author: Guilhem Bichot <guilhem.bichot@oracle.com>
> Date:   Mon Nov 4 15:44:55 2013 +0100
>
>    Bug#13944462 'NULL IN (XX)' RETURNS WRONG RESULTS
2016-03-21 11:21:44 +04:00
Alexander Barkov
b25373beb5 MDEV-9653 Assertion `length || !scale' failed in uint my_decimal_length_to_precision(uint, uint, bool)
MDEV-9752 Wrong data type for COALEASCE(?,1) in prepared statements
2016-03-18 17:50:18 +04:00
Sergei Golubchik
ff93b77fd6 MDEV-9641 MDEV-9644 NULLIF assertions
* only copy args[0] to args[2] after fix_fields (when all item
  substitutions have already happened)

* change QT_ITEM_FUNC_NULLIF_TO_CASE (that allows to print NULLIF
  as CASE) to QT_ITEM_ORIGINAL_FUNC_NULLIF (that prohibits it).
  So that NULLIF-to-CASE is allowed by default and only disabled
  explicitly for SHOW VIEW|FUNCTION|PROCEDURE and mysql_make_view.
  By default it is allowed (in particular in error messages and
  debug output, that can happen anytime before or after optimizer).
2016-03-05 16:25:29 +01:00
Sergei Golubchik
00d1db7a38 Merge branch '10.1' into 10.2 2016-02-25 18:19:55 +01:00
Sergei Golubchik
a5679af1b1 Merge branch '10.0' into 10.1 2016-02-23 21:35:05 +01:00
Sergei Golubchik
271fed4106 Merge branch '5.5' into 10.0 2016-02-15 22:50:59 +01:00
Igor Babaev
2cfc450bf7 This is the consolidated patch for mdev-8646:
"Re-factor the code for post-join operations".

The patch mainly contains the code ported from mysql-5.6 and
created for two essential architectural changes:
1. WL#5558: Resolve ORDER BY execution method at the optimization stage
2. WL#6071: Inline tmp tables into the nested loops algorithm

The first task was implemented for mysql-5.6 by Ole John Aske.
It allows to make all decisions on ORDER BY operation at the optimization
stage.

The second task implemented for mysql-5.6 by Evgeny Potemkin adds JOIN_TAB
nodes for post-join operations that require temporary tables. It allows
to execute these operations within the nested loops algorithm that used to
be used before this task only for join queries. Besides these task moves
all planning on the execution of these operations from the execution phase
to the optimization phase.

Some other re-factoring changes of mysql-5.6 were pulled in, mainly because
it was easier to pull them in than roll them back. In particular all
changes concerning Ref_ptr_array were incorporated.

The port required some changes in the MariaDB code that concerned the
functionality of EXPLAIN and ANALYZE. This was done mainly by Sergey
Petrunia.
2016-02-09 12:35:59 -08:00
Sergei Golubchik
f3444df415 Merge branch 'mysql/5.5' into 5.5
reverted about half of commits as either not applicable or
outright wrong
2016-02-09 11:27:40 +01:00
Monty
b2f8d7b410 Merge branch '10.1' into 10.2
Conflicts:
	VERSION
	cmake/plugin.cmake
	config.h.cmake
	configure.cmake
	plugin/server_audit/server_audit.c
	sql/sql_yacc.yy
2016-02-06 18:14:54 +02:00
Alexander Barkov
ce40ccaf24 MDEV-9181 (NULLIF(count(table.col)), 0) gives wrong result on 10.1.x
Wrapping args[0] and args[2] into an Item_cache for aggregate functions.
2016-01-28 13:58:39 +04:00
Alexander Barkov
7b50447aa6 MDEV-9407 Illegal mix of collation when using GROUP_CONCAT in a VIEW
MDEV-9408 CREATE TABLE SELECT MAX(int_column) creates different columns for table vs view

There were three almost identical pieces of the code:
- Field *Item_func::tmp_table_field();
- Field *Item_sum::create_tmp_field();
- Field *create_tmp_field_from_item();
with a difference in very small details (hence the bugs):
Only Item_func::tmp_table_field() was correct, the other two were not.
Removing the two incorrect pieces of the redundant code.
Joining these three functions/methods into a single virtual method
Item::create_tmp_field().
Additionally, moving Item::make_string_field() and
Item::tmp_table_field_from_field_type() from the public into the
protected section of the class declaration, as they are now not
needed outside of Item.
2016-01-16 18:45:26 +04:00
Alexander Barkov
2ba7ed77aa Merge remote-tracking branch 'origin/10.1' into 10.2 2015-12-29 19:37:11 +04:00
Sergei Golubchik
a2bcee626d Merge branch '10.0' into 10.1 2015-12-21 21:24:22 +01:00
Sergei Golubchik
1623995158 Merge branch '5.5' into 10.0 2015-12-13 00:10:40 +01:00
Sergei Golubchik
abf9d35213 Merge branch 'mysql/5.5' into 5.5 2015-12-09 10:00:49 +01:00
Sergey Vojtovich
753d1f868c MDEV-8716 - Obsolete sql_calloc() in favor of THD::calloc() and thd_calloc() 2015-11-26 11:34:16 +04:00
Chaithra Gopalareddy
a7fb5aecfd Bug#19941403: FATAL_SIGNAL(SIG 6) IN BUILD_EQUAL_ITEMS_FOR_COND | IN SQL/SQL_OPTIMIZER.CC:1657
Problem:
At the end of first execution select_lex->prep_where is pointing to
a runtime created object (temporary table field). As a result
server exits trying to access a invalid pointer during second
execution.

Analysis:
While optimizing the join conditions for the query, after the
permanent transformation, optimizer makes a copy of the new
where conditions in select_lex->prep_where. "prep_where" is what
is used as the "where condition" for the query at the start of execution.
W.r.t the query in question, "where" condition is actually pointing
to a field in the temporary table. As a result, for the  second
execution the pointer is no more valid resulting in server exit.

Fix:
At the end of the first execution, select_lex->where will have the
original item of the where condition.
Make prep_where the new place where the original item of select->where
has to be rolled back.
Fixed in 5.7 with the wl#7082 - Move permanent transformations from
JOIN::optimize to JOIN::prepare

Patch for 5.5 includes the following backports from 5.6:

Bugfix for Bug12603141 - This makes the first execute statement in the testcase
pass in 5.5

However it was noted later in in Bug16163596 that the above bugfix needed to
be modified. Although Bug16163596 is reproducible only with changes done for
Bug12582849, we have decided include the fix.

Considering that Bug12582849 is related to Bug12603141, the fix is
also included here. However this results in Bug16317817, Bug16317685,
Bug16739050. So fix for the above three bugs is also part of this patch.
2015-11-20 12:30:15 +05:30
Alexander Barkov
23d4c95b50 MDEV-8896 Dead code in stored_field_cmp_to_item() 2015-10-05 16:16:13 +04:00
Alexander Barkov
ba0b668551 A clean-up for MDEV-7950:
- Turning get_mm_tree_for_const() from a static function into
  a protected method in Item.
- Adding a new class Item_bool_func2_with_rev, for the functions and operators
  that have a reverse function and can use the range optimizer for
  to optimize "value OP field" as "field REV_OP value". Deriving
  Item_bool_rowready_func2 and Item_funt_spatial_rel from the new class.
- Removing Item_bool_func2::have_rev_func().
2015-10-04 09:37:57 +04:00
Alexander Barkov
100d77e69d Clean-up: removing the unused "Item_result cmp_type" parameter from the methods:
- Item_bool_func::get_func_mm_tree()
- Item_bool_func::get_mm_parts()
- Item_bool_func::get_ne_mm_tree()
2015-10-02 14:48:32 +04:00
Alexander Barkov
22cc8f990b Changing a number of functions to aggregate argument character sets
and collations from the global name space into private and protected
methods in Item_func_or_sum.
2015-09-21 19:04:32 +04:00
Alexander Barkov
c8db0df2da Removing "DTCollation Arg_comparator::cmp_collation".
Using a CHARSET_INFO pointer instead.
2015-09-21 16:18:20 +04:00
Alexander Barkov
b75c003372 MDEV-8816 Equal field propagation is not applied for WHERE varbinary_column>=_utf8'a' COLLATE utf8_general_ci AND varbinary_column='A';
1. Removing the legacy code that disabled equal field propagation in cases
   when comparison is done as VARBINARY. This is now correctly handled by
   the new propagation code in Item_xxx::propagate_equal_fields() and
   Field_str::can_be_substituted_to_equal_item (the bug fix).
2. Also, removing legacy (pre-MySQL-4.1) Arg_comparator methods
   compare_binary_string() and compare_e_binary_string(), as VARBINARY
   comparison is correcty handled in compare_string() and compare_e_string() by
   the corresponding VARBINARY collation handler implemented in my_charset_bin.
   (not really a part of the bug fix)
2015-09-18 23:03:35 +04:00
Alexander Barkov
79140b0383 MDEV-8793 Wrong result set for SELECT ...
WHERE COALESCE(time_column)=TIME('00:00:00')
            AND COALESCE(time_column)=DATE('2015-09-11')
MDEV-8814 Wrong result for WHERE datetime_column > TIME('00:00:00')
2015-09-18 13:30:44 +04:00
Sreeharsha Ramanavarapu
4acc7615ee Bug #19929406: HANDLE_FATAL_SIGNAL (SIG=11) IN
__MEMMOVE_SSSE3_BACK FROM STRING::COPY

Issue:
-----
While using row comparators, the store_value functions call
val_xxx functions in the prepare phase. This can cause
valgrind issues.

SOLUTION:
---------
Setting up of the comparators should be done by
alloc_comparators in the prepare phase. Also, make sure
store_value will be called only during execute phase.

This is a backport of the fix for Bug#17755540.
2015-09-18 07:34:32 +05:30
Alexander Barkov
6f302d9f6c MDEV-8755 Equal field propagation is not performed any longer for the IN list when multiple comparison types 2015-09-11 11:35:15 +04:00
Alexander Barkov
0302efca7f MDEV-8705 Wrong result for SELECT..WHERE latin1_bin_column='a' AND latin1_bin_column='A'
MDEV-8712 Wrong result for SELECT..WHERE latin1_bin_column=_latin1'a' AND latin1_bin_column='A'
2015-09-11 09:20:40 +04:00
Alexander Barkov
4aebba3aeb MDEV-8740 Wrong result for SELECT..WHERE year_field=10 AND NULLIF(year_field,2011.1)='2011'
MDEV-8754 Wrong result for SELECT..WHERE year_field=2020 AND NULLIF(year_field,2010)='2020'
Problems:
1. Item_func_nullif stored a copy of args[0] in a private member m_args0_copy,
   which was invisible for the inherited Item_func menthods, like
   update_used_tables(). As a result, after equal field propagation
   things like Item_func_nullif::const_item() could return wrong result
   and a non-constant NULLIF() was erroneously treated as a constant
   at optimize_cond() time.
   Solution: removing m_args0_copy and storing the return value item
   in args[2] instead.
2. Equal field propagation did not work well for Item_fun_nullif.
   Solution: using ANY_SUBST for args[0] and args[1], as they are in
   comparison, and IDENTITY_SUBST for args[2], as it's not in comparison.
2015-09-10 17:13:35 +04:00
Alexander Barkov
8e553c455c MDEV-8785 Wrong results for EXPLAIN EXTENDED...WHERE NULLIF(latin1_col, _utf8'a' COLLATE utf8_bin) IS NOT NULL 2015-09-10 15:01:44 +04:00
Alexander Barkov
39b46ae934 MDEV-8706 Wrong result for SELECT..WHERE time_column=TIMESTAMP'2015-08-30 00:00:00' AND time_column='00:00:00' 2015-09-09 15:39:09 +04:00
Alexander Barkov
e0df116056 A clean-up after the patch for MDEV-8747 and MDEV-8749:
removing IMPOSSIBLE_RESULT from Item_result, as it's not
needed any more. The fact that an Item is not in a comparison
context is now always designated by IDENTITY_SUBST in Subst_constraint.
Previously IMPOSSIBLE_RESULT and IDENTITY_SUBST co-existed but
actually meant the same thing.
2015-09-06 13:25:47 +04:00
Alexander Barkov
c108019a48 MDEV-8747 Wrong result for SELECT..WHERE derived_table_column='a' AND derived_table_column<>_latin1'A' COLLATE latin1_bin
MDEV-8749 Wrong result for SELECT..WHERE derived_table_enum_column='number' AND derived_table_enum_column OP number
2015-09-06 01:30:46 +04:00
Alexander Barkov
3d9abaf052 MDEV-8752 Wrong result for SELECT..WHERE CASE enum_field WHEN 1 THEN 1 ELSE 0 END AND a='5' 2015-09-05 23:54:18 +04:00
Alexander Barkov
5088cbf4ed MDEV-8671 Wrong result for SELECT..WHERE varchar_column=' 1' AND (varchar_column XOR '1') 2015-09-02 15:56:24 +04:00
Alexander Barkov
8ea9b8c0b1 MDEV-8722 The patch for MDEV-8688 disabled equal field propagation for temporal column and BETWEEN and IN
Item::cmp_context was inconsistently used in combination with cmp_type()
and result_type() in different places of the code. Fixed to use cmp_type()
in all places where cmp_context is involved, to avoid unexpected results
for temporal data types (which have result_type()==STRING_RESULT and
cmp_type==TIME_RESULT).
2015-09-01 19:24:58 +04:00
Alexander Barkov
a3c24ee739 MDEV-8707 Wrong result for
SELECT..WHERE varchar_column=DATE'2001-01-01' AND varchar_column='2001-01-01'
2015-08-31 18:18:10 +04:00
Alexander Barkov
f071a12498 MDEV-8688 Wrong result for
SELECT..WHERE varchar_column IN (1,2,3) AND varchar_column=' 1';
2015-08-29 19:26:30 +04:00
Alexander Barkov
09fb51255a Clean-up: removing duplicate code: removing
Item_func_in::compare_collation() and Item_func_between::compare_collation(),
and adding Item_func_opt_neg::compare_collation() instead.
2015-08-29 18:45:04 +04:00
Alexander Barkov
b4e56a5658 Moving common members of Item_func_in and Item_func_between to their
parent Item_func_opt_neg. A pre-requisite patch for a number of
upcoming equal field propagation related bug fixes.
2015-08-29 16:31:11 +04:00
Alexander Barkov
3ba2a958be MDEV-8694 Wrong result for SELECT..WHERE a NOT LIKE 'a ' AND a='a'
Note, the patch for MDEV-8661 unintentionally fixed MDEV-8694 as well,
as a side effect. Adding a real clear fix: implementing
Item_func_like::propagate_equal_fields() with comments.
2015-08-28 17:03:09 +04:00
Monty
3bca8db4f9 MDEV-6152: Remove calls to current_thd while creating Item
- Part 4: Removing calls to sql_alloc() and sql_calloc()

Other things:
- Added current_thd in some places to make it clear that it's called (easier to remove later)
- Move memory allocation from Item_func_case::fix_length_and_dec() to Item_func_case::fix_fields()
- Added mem_root to some new calls
- Fixed some wrong UNINIT_VAR() calls
- Fixed a bug in generate_partition_syntax() in case of errors
- Added mem_root to argument to new thread_info
- Simplified my_parse_error() call in sql_yacc.yy
2015-08-27 22:29:11 +03:00
Monty
3cb578c001 MDEV-6152: Remove calls to current_thd while creating Item
- Part 3: Adding mem_root to push_back() and push_front()

Other things:
- Added THD as an argument to some partition functions.
- Added memory overflow checking for XML tag's in read_xml()
2015-08-27 22:21:08 +03:00
Alexander Barkov
1b6b44b6b5 MDEV-8661 Wrong result for SELECT..WHERE a='a' AND a='a' COLLATE latin1_bin
MDEV-8679 Equal field propagation is not used for VARCHAR when it safely could
2015-08-26 22:32:01 +04:00
Alexander Barkov
98ba2bf424 Clean-up: moving compare_collation() from Item to Item_bool_func. 2015-08-21 17:08:55 +04:00
Monty
1bae0d9e56 Stage 2 of MDEV-6152:
- Added mem_root to all calls to new Item
- Added private method operator new(size_t size) to Item to ensure that
  we always use a mem_root when creating an item.

This saves use once call to current_thd per Item creation
2015-08-21 10:40:51 +04:00
Sergey Vojtovich
31e365efae MDEV-8010 - Avoid sql_alloc() in Items (Patch #1)
Added mandatory thd parameter to Item (and all derivative classes) constructor.
Added thd parameter to all routines that may create items.
Also removed "current_thd" from Item::Item. This reduced number of
pthread_getspecific() calls from 290 to 177 per OLTP RO transaction.
2015-08-21 10:40:39 +04:00
Alexander Barkov
9d884fd3d3 MDEV-8599 "WHERE varchar_field LIKE temporal_const" does not use range optimizer 2015-08-12 17:28:45 +04:00
Alexander Barkov
6e091dc7ff Splitting a static function get_func_mm_tree() into virtual
methods in Item_bool_func descendants, which gives some advantages:
- Removing the "bool inv" parameter, as its now available through "this"
  for Item_func_between and Item_func_in, and is not needed for the other
  Item_func_xxx.
- Removing casts
- Making a step to data types plugings
2015-08-12 14:43:17 +04:00