Commit graph

734 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
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
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
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
c3494e19cb MDEV-9215 Detect cmp_type() and result_type() from field_type()
A cleanup: removing members and functions that become unused:
- Item_func_hybrid_field_type::cached_result_type
- sp_map_result_type()
2015-12-02 12:14:06 +04:00
Alexander Barkov
607ef786fc MDEV-9215 Detect cmp_type() and result_type() from field_type()
(A dependency task for MDEV-4912 Add a plugin to field types)
2015-12-01 13:13:23 +04:00
Sergey Vojtovich
0746a07708 MDEV-8718 - Obsolete sql_strmake() in favor of THD::strmake() and thd_strmake() 2015-11-26 11:34:16 +04:00
Alexander Barkov
d73cf394a5 MDEV-9170 Get rid of LEX::length and LEX::dec
A preparatory task for:
  MDEV-4912 Add a plugin to field types (column types)
2015-11-23 18:55:01 +04:00
Oleksandr Byelkin
fb4358f432 MDEV-7949: Item_field::used_tables() takes 0.29% in OLTP RO
small sixes of used_tables() usage
2015-10-29 21:05:00 +01:00
Alexander Barkov
b867ade591 Removing Used_tables_and_const_cache from "class udf_handler".
It was used only temporary, during udf_handler::fix_fields() time,
and then copied to the owner Item_func_or_sum object.
Changing the code to use the Used_tables_and_const_cache part
of the owner Item_sum_or_func object directly.
2015-10-14 18:33:16 +04:00
Sergei Golubchik
e19a6f3dca Merge branch 'bb-10.1-serg' into 10.1 2015-10-12 10:03:04 +02:00
Alexander Barkov
0b4c3ad818 Moving Used_tables_and_const_chache from Item_func to Item_func_or_sum
and thus reusing Used_tables_and_const_cache for Item_sum instead of
declaring the same members inside Item_sum.
2015-10-12 10:49:37 +04:00
Sergei Golubchik
dfb74dea30 Merge branch '10.0' into 10.1 2015-10-12 00:37:58 +02:00
Sergei Golubchik
cfeedbfd3e Merge branch '5.5' into 10.0 2015-10-09 17:12:26 +02:00
Alexander Barkov
de1a48e7d9 A clean-up for a few recent result set metadata related bug fixes:
- MDEV-8875 Wrong metadata for MAX(CAST(time_column AS DATETIME))
- MDEV-8873 Wrong field type or metadata for LEAST(int_column,string_column)
- MDEV-8912 Wrong metadata or type for @c:=string_or_blob_field

Adding Item_hybrid_func as a common parent for Item_func_hybrid_field_type,
Item_func_min_max, Item_func_user_var. This removes some duplicate code.
2015-10-08 08:59:58 +04:00
Alexander Barkov
8777724901 MDEV-8912 Wrong metadata or type for @c:=string_or_blob_field 2015-10-07 20:19:29 +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
accf9b5675 MDEV-5694 GREATEST(date, time) returns a wrong data type 2015-10-01 20:01:35 +04:00
Alexander Barkov
b50c607056 MDEV-4848 Wrong metadata or column type for LEAST(1.0,'10')
MDEV-8873 Wrong field type or metadata for LEAST(int_column,string_column)
2015-10-01 14:07:42 +04:00
Alexander Barkov
cc9cfecab7 MDEV-8865 Wrong field type or metadata for COALESCE(signed_int_column, unsigned_int_column)
Item_func_hybrid_field_type did not return correct field_type(), cmp_type()
and result_type() in some cases, because cached_result_type and
cached_field_type were set in independent pieces of the code and
did not properly match to each other.
Fix:
- Removing Item_func_hybrid_result_type
- Deriving Item_func_hybrid_field_type directly from Item_func
- Introducing a new class Type_handler which guarantees that
  field_type(), cmp_type() and result_type() are always properly synchronized
  and using the new class in Item_func_hybrid_field_type.
2015-09-30 12:37:34 +04: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
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
2dc32c02ab Removing "DTCollation user_var_entry::collation", using a CHARSET_INFO
pointer instread, as the "derivation" and "repertoire" parts of
DTCollation were not really used by user_var_entry.
2015-09-21 15:52:50 +04:00
Alexander Barkov
1956340247 Removing global function agg_item_charsets_for_string_result().
Moving agg_arg_charsets_for_string_result() and
agg_arg_charsets_for_string_result_with_comparison() inside
"protected" section in Item_func_or_sum.
2015-09-21 12:21:46 +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
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
Alexander Barkov
aa1002a35c MDEV-8723 Wrong result for SELECT..WHERE COLLATION(a)='binary' AND a='a' 2015-09-02 08:20:49 +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
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
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
Monty
86377d078e Fixes done while working on MDEV-4119:
Fixed several optimizer issues relatied to GROUP BY:

a) Refering to a SELECT column in HAVING sometimes calculated it twice, which caused problems with non determinstic functions

b) Removing duplicate fields and constants from GROUP BY was done too late for "using index for group by" optimization to work

c) EXPLAIN SELECT ... GROUP BY did wrongly show 'Using filesort' in some cases involving "Using index for group-by"


a) was fixed by:
- Changed last argument to Item::split_sum_func2() from bool to int to allow more flags
- Added flag argument to Item::split_sum_func() to allow on to specify if the item was in the SELECT part
- Mark all split_sum_func() calls from SELECT with SPLIT_SUM_SELECT
- Changed split_sum_func2() to do nothing if called with an argument that is not a sum function and doesn't include sum functions, if we are not an argument to SELECT.

This ensures that in a case like
select a*sum(b) as f1 from t1 where a=1 group by c having f1 <= 10;

That 'a' in the SELECT part is stored as a reference in the temporary table togeher with sum(b) while the 'a' in having isn't (not needed as 'a' is already a reference to a column in the result)

b) was fixed by:
- Added an extra remove_const() pass for GROUP BY arguments before make_join_statistics() in case of one table SELECT.

This allowes get_best_group_min_max() to optimize things better.

c) was fixed by:
- Added test for group by optimization in JOIN::exec_inner for
  select->quick->get_type() == QUICK_SELECT_I::QS_TYPE_GROUP_MIN_MAX

item.cc:
- Simplifed Item::split_sum_func2()
  - Split test to make them faster and easier to read
  - Changed last argument to Item::split_sum_func2() from bool to int to allow more flags
  - Added flag argument to Item::split_sum_func() to allow on to specify if the item was in the SELECT part
  - Changed split_sum_func2() to do nothing if called with an argument that is not a sum function and doesn't include sum functions, if we are not an argument to SELECT.

opt_range.cc:
- Simplified get_best_group_min_max() by calcuating first how many group_by elements.
- Use join->group instead of join->group_list to test if group by, as join->group_list may be NULL if everything was optimized away.

sql_select.cc:
- Added an extra remove_const() pass for GROUP BY arguments before make_join_statistics() in case of one table SELECT.
- Use group instead of group_list to test if group by, as group_list may be NULL if everything was optimized away.
- Moved printing of "Error in remove_const" to remove_const() instead of having it in caller.
- Simplified some if tests by re-ordering code.
- update_depend_map_for_order() and remove_const() fixed to handle the case where make_join_statistics() has not yet been called (join->join_tab is 0 in this case)
2015-07-05 12:39:46 +03:00
Alexander Barkov
ee0237fe89 MDEV-8330 Get rid of Item_func::select_optimize() and Item_func::optimize_type 2015-06-28 14:29:51 +04:00
Alexander Barkov
40e5aceaff Removing Item_int_func::sargable. Adding virtual implementations of
count_sargable_conds() instead for Item_func_in, Item_func_null_predicate,
Item_bool_func2. There other Item_int_func descendants that used to set
"sargable" to true (Item_func_between, Item_equal) already have their
own implementation of count_sargable_conds(). There is no sense to
have two parallel coding models for the same thing.
2015-06-26 17:46:34 +04:00
Alexander Barkov
5991efc382 MDEV-7950 Item_func::type() takes 0.26% in OLTP RO
Step #8: Adding get_mm_tree() in Item_func, Item_func_between,
Item_func_in, Item_equal. This removes one virtual call item->type()
in queries like:
  SELECT * FROM t1 WHERE c BETWEEN const1 AND const2;
  SELECT * FROM t1 WHERE c>const;
  SELECT * FROM t1 WHERE c IN (const_list);
2015-05-27 21:32:35 +04:00
Alexander Barkov
be2038e3cb MDEV-7950 Item_func::type() takes 0.26% in OLTP RO
Step 4 (there will be more)
2015-05-13 17:08:24 +04:00
Alexander Barkov
462bca365a MDEV-7950 Item_func::type() takes 0.26% in OLTP RO
Step 2c:

After discussion with Igor, it appeared that Item_field and Item_ref
could not appear in this context in the old function build_equal_item_for_cond:

  else if (cond->type() == Item::FUNC_ITEM ||
           cond->real_item()->type() == Item::FIELD_ITEM)

The part of the condition checking for Item_field::FIELD_ITEM was a dead code.
- Moving implementation of Item_ident_or_func_or_sum::build_equal_items()
to Item_func::build_equal_items()
- Restoring deriving of Item_ident and Item_sum_or_func from Item_result_field.
  Removing Item_ident_or_func_or_sum.
2015-05-04 18:12:31 +04:00
Alexander Barkov
04fb09d781 Deriving Item_row from Item_args and sharing more code
between Item_func, Item_sum, Item_row.
2015-04-24 12:59:21 +04:00
Alexander Barkov
fc1f301e91 MDEV-8024 Remove excessive update_used_tables() calls 2015-04-22 12:40:23 +04:00
Alexander Barkov
99898c6f76 Minor reorganization in Item hierarchy, to remove duplicate code.
- Adding a new class Item_args, represending regular function or
  aggregate function arguments array.

- Adding a new class Item_func_or_sum,
  a parent class for Item_func and Item_sum

- Moving Item_result_field::name() to Item_func_or_sum(),
  as name() is not needed on Item_result_field level.
2015-04-17 09:52:44 +04:00
Alexander Barkov
e91bc2e91d MDEV-7759 NULLIF(x,y) is not equal to CASE WHEN x=y THEN NULL ELSE x END 2015-03-12 11:40:37 +04:00
Sergei Golubchik
4b21cd21fe Merge branch '10.0' into merge-wip 2015-01-31 21:48:47 +01:00
Sergei Golubchik
d9c01e4b4a 5.5 merge 2015-01-21 12:03:02 +01:00
Sergei Golubchik
a978bdda1e mysql-5.5.41 merge 2014-12-19 11:35:44 +01:00
Sergei Golubchik
853077ad7e Merge branch '10.0' into bb-10.1-merge
Conflicts:
	.bzrignore
	VERSION
	cmake/plugin.cmake
	debian/dist/Debian/control
	debian/dist/Ubuntu/control
	mysql-test/r/join_outer.result
	mysql-test/r/join_outer_jcl6.result
	mysql-test/r/null.result
	mysql-test/r/old-mode.result
	mysql-test/r/union.result
	mysql-test/t/join_outer.test
	mysql-test/t/null.test
	mysql-test/t/old-mode.test
	mysql-test/t/union.test
	packaging/rpm-oel/mysql.spec.in
	scripts/mysql_config.sh
	sql/ha_ndbcluster.cc
	sql/ha_ndbcluster_binlog.cc
	sql/ha_ndbcluster_cond.cc
	sql/item_cmpfunc.h
	sql/lock.cc
	sql/sql_select.cc
	sql/sql_show.cc
	sql/sql_update.cc
	sql/sql_yacc.yy
	storage/innobase/buf/buf0flu.cc
	storage/innobase/fil/fil0fil.cc
	storage/innobase/include/srv0srv.h
	storage/innobase/lock/lock0lock.cc
	storage/tokudb/CMakeLists.txt
	storage/xtradb/buf/buf0flu.cc
	storage/xtradb/fil/fil0fil.cc
	storage/xtradb/include/srv0srv.h
	storage/xtradb/lock/lock0lock.cc
	support-files/mysql.spec.sh
2014-12-02 22:25:16 +01:00
Alexey Botchkov
d0d6284cab MDEV-4045 Missing OGC Spatial functions.
Missing GIS functions added:
        IsRing()
        PointOnSurface
        PointOnSurface
        Relate
        Distance
        Intersection
        ConvexHull
   Other old OpenGis standard inconsistencies fixed.
2014-11-28 00:29:37 +04:00
Alexander Barkov
969f491845 MDEV-7005 NULLIF does not work as documented
MDEV-7146 NULLIF returns unexpected result with a YEAR field
2014-11-20 11:59:00 +04:00
Sergei Golubchik
3495801e2e 5.5 merge 2014-11-19 17:23:39 +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