Commit graph

103 commits

Author SHA1 Message Date
Igor Babaev
9380850d87 MDEV-15777 Use inferred IS NOT NULL predicates in the range optimizer
This patch introduces the optimization that allows range optimizer to
consider index range scans that are built employing NOT NULL predicates
inferred from WHERE conditions and ON expressions.
The patch adds a new optimizer switch not_null_range_scan.
2019-08-30 18:47:14 -07:00
Alexander Barkov
e6ff3f9d1c MDEV-20052 Add a MEM_ROOT pointer argument to Type_handler::make_xxx_field() 2019-07-12 06:58:51 +04:00
Oleksandr Byelkin
c07325f932 Merge branch '10.3' into 10.4 2019-05-19 20:55:37 +02:00
Marko Mäkelä
be85d3e61b Merge 10.2 into 10.3 2019-05-14 17:18:46 +03:00
Marko Mäkelä
26a14ee130 Merge 10.1 into 10.2 2019-05-13 17:54:04 +03:00
Vicențiu Ciorbaru
cb248f8806 Merge branch '5.5' into 10.1 2019-05-11 22:19:05 +03:00
Vicențiu Ciorbaru
5543b75550 Update FSF Address
* Update wrong zip-code
2019-05-11 21:29:06 +03:00
Alexander Barkov
ad8e02ac45 MDEV-17317 Add THD* parameter into Item::get_date() and stricter data type control to "fuzzydate" 2018-09-28 14:01:17 +04:00
Alexander Barkov
e213b20e07 MDEV-16592 Change Item::with_sum_func from a member to a virtual method 2018-06-27 14:48:03 +04:00
Alexander Barkov
f4dfc609cf MDEV-16388 Replace member Item::fixed to virtual method is_fixed() 2018-06-05 11:56:19 +04:00
Alexander Barkov
637af78383 MDEV-16309 Split ::create_tmp_field() into virtual methods in Item
Detailed: changes:
1. Moving Field specific code into new methods on Field:
   - Field *Field::create_tmp_field(...)
   - virtual void init_for_tmp_table(...)

2. Removing virtual Item::create_tmp_field().
   Adding instead a new virtual method Item::create_tmp_field_ex().

   Note, a virtual create_tmp_field() still exists, but only for Item_sum.
   This resembles 10.0 code structure. Perhaps create_tmp_field() should
   be removed from Item_sum and Item_sum descendants should override
   create_tmp_field_ex() directly. This can be done in a separate commit.

3. Adding helper classes Tmp_field_src and Tmp_field_param,
   to make the API for Item::create_tmp_field_ex() smaller
   and easier to extend in the future.

4. Decomposing the public function create_tmp_field() into
   virtual implementations for Item and a number of its descendants:
   - Item_basic_value
   - Item_sp_variable
   - Item_name_const
   - Item_result_field
   - Item_field
   - Item_ref
   - Item_type_holder
   - Item_row
   - Item_func_sp
   - Item_func_user_var
   - Item_sum
   - Item_sum_field
   - Item_proc

5. Adding DBUG_ASSERT-only virtual implementations for
   Item types that should not appear in create_tmp_table_ex(),
   for easier debugging:
   - Item_nodeset_func
   - Item_nodeset_to_const_comparator
   - Item_null_result
   - Item_copy
   - Item_ident_for_show
   - Item_user_var_as_out_param

6. Moving public function create_tmp_field_from_field()
   as a method to Item_field.

7. Removing Item::set_result_field(). It's not needed any more.

8. Cleanup: Removing the enum value "EXPR_CACHE_ITEM",
   as it's not used for a very long time.
2018-05-28 16:57:59 +04:00
Galina Shalygina
d3ff133390 MDEV-12387 Push conditions into materialized subqueries
The logic and the implementation scheme are similar with the
MDEV-9197 Pushdown conditions into non-mergeable views/derived tables

How the push down is made on the example:

select * from t1
where a>3 and b>10 and
 (a,b) in (select x,max(y) from t2 group by x);

-->

select * from t1
where a>3 and b>10 and
  (a,b) in (select x,max(y)
            from t2
            where x>3
            group by x
            having max(y)>10);

The implementation scheme:

1. Search for the condition cond that depends only on the fields
   from the left part of the IN subquery (left_part)
2. Find fields F_group in the select of the right part of the
   IN subquery (right_part) that are used in the GROUP BY
3. Extract from the cond condition cond_where that depends only on the
   fields from the left_part that stay at the same places in the left_part
   (have the same indexes) as the F_group fields in the projection of the
   right_part
4. Transform cond_where so it can be pushed into the WHERE clause of the
   right_part and delete cond_where from the cond
5. Transform cond so it can be pushed into the HAVING clause of the right_part

The optimization is made in the
Item_in_subselect::pushdown_cond_for_in_subquery() and is controlled by the
variable condition_pushdown_for_subquery.

New test file in_subq_cond_pushdown.test is created.

There are also some changes made for setup_jtbm_semi_joins().
Now it is decomposed into the 2 procedures: setup_degenerate_jtbm_semi_joins()
that is called before optimize_cond() for cond and setup_jtbm_semi_joins()
that is called after optimize_cond().
New setup_jtbm_semi_joins() is made in the way so that the result of its work is
the same as if it was called before optimize_cond().

The code that is common for pushdown into materialized derived and into materialized
IN subqueries is factored out into pushdown_cond_for_derived(),
Item_in_subselect::pushdown_cond_for_in_subquery() and
st_select_lex::pushdown_cond_into_where_clause().
2018-05-15 23:45:59 +02:00
Alexander Barkov
a1a966fc0e Cleanup: renaming methods make_field(Send_field*) to make_send_field(..)
Renaming methods:
- Field::make_field(Send_field*) to make_send_field(..)
- Item::make_field(THD *,Send_field *) to make_send_field(..)
- Item::init_make_field(Send_field *, enum_field_type) to init_make_send_field(..)

These names looked similar to other functions that are used
for a very different purpose (creating Field instances):
- Public function "Field * make_field(..)"
- Method "Field *Column_defitinion::make_field(..)"

The rename makes it's easier to search the code using "grep".
2018-04-05 21:27:33 +04:00
Sergei Golubchik
622115ee07 cleanup: extend Item_cache::get_cache() to accept f_type
Do not assume that it's always item->field_type() - this is not the case
in temporal comparisons (e.g. when comparing DATETIME column with a TIME
literal).
2018-03-14 12:40:00 +01:00
Marko Mäkelä
b006d2ead4 Merge bb-10.2-ext into 10.3 2018-02-15 10:22:03 +02:00
Alexander Barkov
95d075a0e5 MDEV-15293 CAST(AS TIME) returns bad results for LAST_VALUE(),NAME_CONST(),SP variable 2018-02-13 20:37:31 +04:00
Marko Mäkelä
7cb3520c06 Merge bb-10.2-ext into 10.3 2017-11-30 08:16:37 +02:00
Alexander Barkov
590400f743 MDEV-14517 Cleanup for Item::with_subselect and Item::has_subquery() 2017-11-28 06:25:14 +04:00
Michael Widenius
166056f744 Remove not used mem_root argument from build_clone(), get_copy() and get_item_copy()
TODO:
- Make get_thd_memroot() inline
  - To do this, we need to reduce dependence of include files, especially
    so that sql_class.h is not depending in item.h
2017-11-23 09:49:45 +02:00
Monty
0bb0d52221 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext
Conflicts:
	mysql-test/r/cte_recursive.result
	mysql-test/r/derived_cond_pushdown.result
	mysql-test/t/cte_recursive.test
	mysql-test/t/derived_cond_pushdown.test
	sql/datadict.cc
	sql/handler.cc
2017-11-09 23:21:41 +02:00
Alexander Barkov
62333983e4 Merge remote-tracking branch 'origin/10.1' into 10.2 2017-11-09 15:41:26 +04:00
Alexander Barkov
0fdb0bdf27 Merge remote-tracking branch 'origin/10.0' into 10.1 2017-11-09 14:05:53 +04:00
Oleksandr Byelkin
c2c93fc6e4 MDEV-14164: Unknown column error when adding aggregate to function in oracle style procedure FOR loop
Make differentiation between pullout for merge and pulout of outer field during exists2in transformation.
In last case the field was outer and so we can safely start from name resolution context of the SELECT where it was pulled.
Old behavior lead to inconsistence between list of tables and outer name resolution context (which skips one SELECT for merge purposes) which creates problem vor name resolution.
2017-11-09 09:31:03 +01:00
Alexander Barkov
003cb2f424 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-10-30 16:42:46 +04:00
Sergei Golubchik
e0a1c745ec Merge branch '10.1' into 10.2 2017-10-24 14:53:18 +02:00
Sergei Golubchik
9d2e2d7533 Merge branch '10.0' into 10.1 2017-10-22 13:03:41 +02:00
Oleksandr Byelkin
235b68299b MDEV-9619: Assertion `null_ref_table' failed in virtual table_map Item_direct_view_ref::used_tables() const on 2nd execution of PS
Refer left expression indirectly in case it changes from execution to execution.
2017-10-13 19:32:38 +02:00
Marko Mäkelä
43c77bb937 Merge 10.2 into bb-10.2-ext 2017-06-27 08:13:59 +03:00
Igor Babaev
9f3622191d Fixed the bug mdev-12845.
This patch fills in a serious flaw in the
code that supports condition pushdown into
materialized views / derived tables.

If a predicate happened to contain a reference
to a mergeable view / derived table and it does
not depended directly on the target materialized
view / derived table then the predicate was not
considered as a subject to pusdown to this view
/ derived table.
2017-06-22 22:06:03 -07:00
Alexander Barkov
da63db1e3b MDEV-12719 Determine Item::result_type() from Item::type_handler() 2017-05-07 19:29:23 +04:00
Alexander Barkov
4e9022b48b MDEV-12718 Determine Item::cmp_type() from Item::type_handler() 2017-05-07 09:12:54 +04:00
Alexander Barkov
c898de84b7 MDEV-12714 Determine Item::field_type() from Item::type_handler() 2017-05-06 20:44:05 +04:00
Alexander Barkov
5a644e177f Adding "const" qualifier to Item::cols(), and to the "Item *cmp" parameter to Type_handler::make_const_item_for_comparison() 2017-05-06 15:05:59 +04:00
Alexander Barkov
e34acc838b Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-04-05 14:42:14 +04:00
Igor Babaev
00ab154d49 Fixed bug mdev-10454.
The patch actually fixes the old defect of the optimizer that
could not extract keys for range access from IN predicates
with row arguments.

This problem was resolved in the mysql-5.7 code. The patch
supersedes what was done there:
 - it can build range access when not all components of
 the first row argument are refer to the columns of the table
 for which the range access is constructed.
 - it can use equality predicates to build range access
 to the table that is not referred to in this argument.
2017-04-03 15:59:38 -07:00
Alexander Barkov
2637828065 MDEV-11344 Split Arg_comparator::set_compare_func() into virtual methods in Type_handler
This patch:
- Introduces a new virtuial method Type_handler::set_comparator_func
  and moves pieces of the code from the switch in
  Arg_comparator::set_compare_func into the corresponding
  Type_handler_xxx::set_comparator_func.
- Adds Type_handler::get_handler_by_cmp_type()
- Moves Type_handler_hybrid_field_type::get_handler_by_result_type() to
  a static method Type_handler::get_handler_by_result_type(),
  for symmetry with similar methods:
  * Type_handler::get_handler_by_field_type()
  * Type_handler::get_handler_by_real_type()
  * Type_handler::get_handler_by_cmp_type()
- Introduces Type_handler_row, to unify the code for the scalar
  data types and the ROW data type (currently for comparison purposes only).
- Adds public type_handler_row, as it's now needed in item_row.h
- Makes type_handler_null public, as it's now needed in item_cmpfunc.h
  Note, other type_handler_xxx will become public as well later.
- Removes the global variable Arg_comparator::comparator_matrix,
  as it's not needed any more.
2016-12-16 18:23:21 +04:00
Igor Babaev
3fb4f9bb93 Merge branch '10.2-mdev9197-cons' of github.com:shagalla/server
into branch 10.2-mdev9197.
2016-08-31 16:16:54 -07:00
Galina Shalygina
eb2c147475 The consolidated patch for mdev-9197. 2016-08-23 00:39:12 +03:00
Sergei Golubchik
ed77ee1aab cleanup: change Item::walk() to take void* not uchar*
and remove all related casts to uchar*
also remove a couple of unused methods
2016-06-30 11:43:02 +02:00
Michael Widenius
db7edfed17 MDEV-7563 Support CHECK constraint as in (or close to) SQL Standard
MDEV-10134 Add full support for DEFAULT

- Added support for using tables with MySQL 5.7 virtual fields,
  including MySQL 5.7 syntax
- Better error messages also for old cases
- CREATE ... SELECT now also updates timestamp columns
- Blob can now have default values
- Added new system variable "check_constraint_checks", to turn of
  CHECK constraint checking if needed.
- Removed some engine independent tests in suite vcol to only test myisam
- Moved some tests from 'include' to 't'. Should some day be done for all tests.
- FRM version increased to 11 if one uses virtual fields or constraints
- Changed to use a bitmap to check if a field has got a value, instead of
  setting HAS_EXPLICIT_VALUE bit in field flags
- Expressions can now be up to 65K in total
- Ensure we are not refering to uninitialized fields when handling virtual fields or defaults
- Changed check_vcol_func_processor() to return a bitmap of used types
- Had to change some functions that calculated cached value in fix_fields to do
  this in val() or getdate() instead.
- store_now_in_TIME() now takes a THD argument
- fill_record() now updates default values
- Add a lookahead for NOT NULL, to be able to handle DEFAULT 1+1 NOT NULL
- Automatically generate a name for constraints that doesn't have a name
- Added support for ALTER TABLE DROP CONSTRAINT
- Ensure that partition functions register virtual fields used. This fixes
  some bugs when using virtual fields in a partitioning function
2016-06-30 11:43:02 +02:00
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
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
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
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
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
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