Commit graph

7101 commits

Author SHA1 Message Date
Michael Widenius
4aaa38d26e Enusure that my_global.h is included first
- Added sql/mariadb.h file that should be included first by files in sql
  directory, if sql_plugin.h is not used (sql_plugin.h adds SHOW variables
  that must be done before my_global.h is included)
- Removed a lot of include my_global.h from include files
- Removed include's of some files that my_global.h automatically includes
- Removed duplicated include's of my_sys.h
- Replaced include my_config.h with my_global.h
2017-08-24 01:05:44 +02:00
Alexander Barkov
6db1b0188c Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.3 2017-08-15 07:52:48 +04:00
Igor Babaev
bf75dcac89 This is a modification of the first patch committed for mdev-13369
developed to cover the case of mdev-13389: "Optimization for equi-joins
of derived tables with window functions".
2017-08-10 14:26:29 -07:00
Igor Babaev
b14e2b044b This first patch prepared for the task MDEV-13369:
"Optimization for equi-joins of derived tables with GROUP BY"
should be considered rather as a 'proof of concept'.

The task itself is targeted at an optimization that employs re-writing
equi-joins with grouping derived tables / views into lateral
derived tables. Here's an example of such transformation:
  select t1.a,t.max,t.min
  from t1 [left] join
       (select a, max(t2.b) max, min(t2.b) min from t2
       group by t2.a) as t
       on t1.a=t.a;
=>
  select t1.a,tl.max,tl.min
  from t1 [left] join
       lateral (select a, max(t2.b) max, min(t2.b) min from t2
                where  t1.a=t2.a) as t
       on 1=1;
The transformation pushes the equi-join condition t1.a=t.a into the
derived table making it dependent on table t1. It means that for
every row from t1 a new derived table must be filled out. However
the size of any of these derived tables is just a fraction of the
original derived table t. One could say that transformation 'splits'
the rows used for the GROUP BY operation into separate groups
performing aggregation for a group only in the case when there is
a match for the current row of t1.
Apparently the transformation may produce a query with a better
performance only in the case when
 - the GROUP BY list refers only to fields returned by the derived table
 - there is an index I on one of the tables T used in FROM list of
   the specification of the derived table whose prefix covers the
   the fields from the proper beginning of the GROUP BY list or
   fields that are equal to those fields.
Whether the result of the re-writing can be executed faster depends
on many factors:
  - the size of the original derived table
  - the size of the table T
  - whether the index I is clustering for table T
  - whether the index I fully covers the GROUP BY list.

This patch only tries to improve the chosen execution plan using
this transformation. It tries to do it only when the chosen
plan reaches the derived table by a key whose prefix covers
all the fields of the derived table produced by the fields of
the table T from the GROUP BY list.
The code of the patch does not evaluates the cost of the improved
plan. If certain conditions are met the transformation is applied.
2017-08-10 14:26:29 -07:00
Marko Mäkelä
620ba97cfc Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.3 2017-08-09 12:59:39 +03:00
Alexander Barkov
988a9daa94 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext
Conflicts:
	mysql-test/r/func_json.result
	mysql-test/r/win.result
	mysql-test/t/func_json.test
	mysql-test/t/win.test
	sql/share/errmsg-utf8.txt
	storage/rocksdb/ha_rocksdb.cc
	storage/rocksdb/mysql-test/rocksdb/r/tbl_opt_data_index_dir.result
2017-08-07 21:35:34 +04:00
Sergei Petrunia
0b30ce4f31 MDEV-13374: Server crashes in first_linear_tab / st_select_lex::set_explain_type
- Support first_linear_tab() traversal for degenerate joins
2017-08-07 16:04:38 +03:00
Alexander Barkov
c431eafd62 Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.3 2017-07-31 23:00:59 +04:00
Alexander Barkov
23290e42e3 Merge commit 'e2afdb1ee430cb9d030aeeedc85eb903cda5e5d1' into bb-10.2-ext 2017-07-21 23:38:30 +04:00
Sergei Petrunia
17fc288b30 MDEV-13352: Server crashes in st_join_table::remove_duplicates
Do not run the window function computation step when the select
produces no rows (zero_result_cause!=NULL).
This may cause reads from uninitialized memory.

We still need to run the window function computation step when
the output includes just one row  (for example
SELECT MAX(col), RANK() OVER (...) FROM t1 WHERE 1=0).

This fix also resolves an issue with queries with window functions
producing an output row where should be none, like in
SELECT ROW_NUMBER() FROM t1 WHERE 1=0.

Updated a few test results in the existing tests to reflect this.
2017-07-21 13:53:58 +03:00
Marko Mäkelä
57fea53615 Merge bb-10.2-ext into 10.3 2017-07-07 12:39:43 +03:00
Alexander Barkov
8b2c7c9444 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-07-07 12:43:10 +04:00
Sergei Golubchik
f6633bf058 Merge branch '10.1' into 10.2 2017-07-05 19:08:55 +02:00
Alexander Barkov
3b9273d203 Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.3 2017-07-05 17:43:32 +04:00
Alexander Barkov
5c0df0e4a8 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-07-04 15:31:25 +04:00
Monty
2e9b55f763 MDEV-13226 Server crashes when tmpdir runs out of space
There was a missing test in CTE handling if creating a temporary table
failed (in this case as a result of out of space). This caused a table
handler to be used even if it was not allocated.
2017-07-01 14:26:42 +03:00
Monty
dd8474b1dc Added tmp_disk_table_size to limit size of Aria temp tables in tmpdir
- Added variable tmp_disk_table_size
- Added variable tmp_memory_table_size as an alias for tmp_table_size
- Changed internal variable tmp_table_size to tmp_memory_table_size
- create_info.data_file_length is now set with tmp_disk_table_size
- Fixed that Aria doesn't reset max_data_file_length for internal tables
- Added status flag if table is full so that we can detect this on next insert.
  This ensures that the table is always 'correct', but we get the error one
  row after the row that grow the table too big.
- Removed some mutex lock for internal temporary tables
2017-06-30 22:31:37 +03:00
Vicențiu Ciorbaru
330792f3c3 Merge branch 'bb-10.1-vicentiu' into 10.1 2017-06-27 16:34:36 +03:00
Oleksandr Byelkin
b76b69cd5f MDEV-10880: Assertions keypart_map' or prebuilt->search_tuple->n_fields > 0' fail on DISTINCT and GROUP BY constant
add_group_and_distinct_keys() should take into account JOIN::simple_group.
2017-06-23 09:16:27 +02:00
Vicențiu Ciorbaru
2e335a471c Merge remote-tracking branch '10.0' into 10.1 2017-06-21 16:19:43 +03:00
Vicențiu Ciorbaru
8baf9b0c46 Merge remote-tracking branch '5.5' into 10.0 2017-06-20 12:31:17 +03:00
Marko Mäkelä
1e3886ae80 Merge bb-10.2-ext into 10.3 2017-06-19 17:28:08 +03:00
Marko Mäkelä
3a7201ea92 Merge 10.2 into bb-10.2-ext 2017-06-19 16:56:13 +03:00
Igor Babaev
cf4a6abea1 Fixed the bug mdev-13064.
This is another attempt to fix the bug mdev-12992.
This patch introduces st_select_lex::context_analysis_place for
the place in SELECT where context analysis is currently performed.
It's similar to st_select_lex::parsing_place, but it is used at
the preparation stage.
2017-06-16 09:50:57 -07:00
Alexander Barkov
765347384a Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-06-15 15:27:11 +04:00
Marko Mäkelä
2d8fdfbde5 Merge 10.1 into 10.2
Replace have_innodb_zip.inc with innodb_page_size_small.inc.
2017-06-08 12:45:08 +03:00
Igor Babaev
b850fc66ca Fixed the bug mdev-12855.
This is actually a legacy bug:
SQL_SELECT::test_quick_select() was called
with SQL_SELECT::head not set.
It looks like that this problem can be
reproduced only on queries with ORDER BY
that use IN predicates converted to semi-joins.
2017-06-07 22:54:57 -07:00
Igor Babaev
151f4e9b4a Fixed the bug mdev-12963.
This patch corrects the fix for bug mdev-7599.
When the min/max optimization of the function
opt_sum_query() optimizes away all tables of
a subquery it should not ever be rolled back.
2017-06-07 16:29:55 -07:00
Igor Babaev
c258ca2463 Fixed the bug mdev-12838.
If the optimizer chose an execution plan where
a semi-join nest were materialized and the
result of materialization was scanned to access
other tables by ref access it could build a key
over columns of the tables from the nest that
were actually inaccessible.
The patch performs a proper check whether a key
that uses columns of the tables from a materialized
semi-join nest can be employed to access outer tables.
2017-06-07 12:45:32 -07:00
Marko Mäkelä
3d615e4b1a Merge branch 'bb-10.2-ext' into 10.3
This excludes MDEV-12472 (InnoDB should accept XtraDB parameters,
warning that they are ignored). In other words, MariaDB 10.3 will not
recognize any XtraDB-specific parameters.
2017-06-02 09:36:04 +03:00
Igor Babaev
af4421e82d Fixed the bug mdev-12931.
This corrects the patch for mdev-10006.
The current code supports only those semi-join nests that are placed at
the join top level. So such nests cannot depend on other tables or nests.
2017-05-29 00:27:14 -07:00
Alexander Barkov
9bc3225642 Merge tag 'mariadb-10.2.6' into bb-10.2-ext 2017-05-26 19:32:28 +04:00
Alexander Barkov
109bc47084 Fixing a few data type related problems: MDEV-12875, MDEV-12886, MDEV-12916
This is a joint patch fixing the following problems:

MDEV-12875 Wrong VIEW column data type for COALESCE(int_column)
MDEV-12886 Different default for INT and BIGINT column in a VIEW for a SELECT with ROLLUP
MDEV-12916 Wrong column data type for an INT field of a cursor-anchored ROW variable

All above problem happened because the global function ::create_tmp_field()
called the top-level Item::create_tmp_field(), which made some tranformation
for INT-result data types. For example, INT(11) became BIGINT(11), because 11
is a corner case and it's not known if it fits or does not fit into INT range,
so Item::create_tmp_field() converted it to BIGINT(11) for safety.

The main idea of this patch is to avoid such tranformations.

1. Fixing Item::create_tmp_field() not to have a special case for INT_RESULT.

   Item::create_tmp_field() is changed not to have a special case
   for INT_RESULT (which earlier made a decision based on Item's max_length).
   It now calls tmp_table_field_from_field_type() for INT_RESULT,
   therefore preserves the original data type (e.g. INT, YEAR) without
   conversion to BIGINT.

   This change is valid, because a number of recent fixes
   (e.g. in Item_func_int, Item_hybrid_func, Item_int, Item_splocal)
   guarantee that item->type_handler() now properly returns
   type_handler_long vs type_handler_longlong. So no adjustment by length
   is needed any more for Items returning INT_RESULT.

   After this change, Item::create_tmp_field() calls
   tmp_table_field_from_field_type() for all XXX_RESULT, except REAL_RESULT.

2. Fixing Item::create_tmp_field() not to have a special case for REAL_RESULT.

   Note, the reason for a special case for REAL_RESULT is to have a special
   constructor for Field_double(), forcing Field_real::not_fixed to be set
   to true.

   Taking into account that only Item_sum descendants actually need a special
   constructor call Field_double(not_fixed=true), not too loose precision
   when mixing individual rows to the aggregate result:
   - renaming Item::create_tmp_field() to Item_sum::create_tmp_field().
   - changing Item::create_tmp_field() just to call
     tmp_table_field_from_field_type() for all XXX_RESULT types.

   A special case for REAL_RESULT in Item::create_tmp_field() is now gone.
   Item::create_tmp_field() is now symmetric for all XXX_RESULT types,
   and now just calls tmp_table_field_from_field_type().

3. Fixing Item_func::create_field_for_create_select() not to have
   a special case for STRING_RESULT.

   After changes #1 and #2, the code in
   Item_func::create_field_for_create_select(), testing result_type(),
   becomes useless, because: now Item::create_tmp_field() and
   tmp_table_field_from_field_type() do exactly the same thing for all
   XXX_RESULT types for Item_func descendants:
   a. It calls tmp_table_field_from_field_type for STRING_RESULT directly.
   b. For other XXX_RESULT, it goes through Item::create_tmp_field(),
      which calls the global function ::create_tmp_field(),
      which calls item->create_tmp_field() for FUNC_ITEM,
      which calls tmp_table_field_from_field_type() again.

   So removing the virtual implementation of
   Item_func::create_field_for_create_select().
   The inherited Item::create_field_for_create_select() now perfectly
   does the job, as it also calls tmp_table_field_from_field_type()
   for FUNC_ITEM, independently from XXX_RESULT type.

4. Taking into account #1 and #2, as well as some recent changes,
   removing virtual implementations:
   - Item_hybrid_func::create_tmp_field()
   - Item_hybrid_func::create_field_for_create_select()
   - Item_int_func::create_tmp_field()
   - Item_int_func::create_field_for_create_select()
   - Item_temporal_func::create_field_for_create_select()
   The derived versions from Item now perfectly work.

5. Moving a piece of code from create_tmp_field_from_item()
   to a new function create_tmp_field_from_item_finalize(),
   to reuse it in two places (see #6).

6. Changing the code responsible for BIT->INT/BIGIN tranformation
   (which is called for the cases when the created table, e.g. HEAP,
    does not fully support BIT) not to call create_tmp_field_from_item(),
   because the latter now calls tmp_table_field_from_field_type() instead
   of create_tmp_field() and thefore cannot do BIT transformation.
   So rewriting this code using a sequence of these calls:
   - item->type_handler_long_or_longlong()
   - handler->make_and_init_table_field()
   - create_tmp_field_from_item_finalize()

7. Miscelaneous changes:
   - Moving type_handler_long_or_longlong() from "protected" to "public",
     as it's now needed in the global function create_tmp_field().

8. The above changes fixed MDEV-12875, MDEV-12886, MDEV-12916.
   So adding tests for these bugs.
2017-05-25 15:15:39 +04:00
Marko Mäkelä
8f643e2063 Merge 10.1 into 10.2 2017-05-23 11:09:47 +03:00
Alexander Barkov
c84bbeda7f MDEV-12858 + MDEV+12859 + MDEV-12862 - a join patch fixing a few data type problems with CREATE..SELECT
MDEV-12858 Out-of-range error for CREATE..SELECT unsigned_int_column+1
MDEV-12859 Out-of-range error for CREATE..SELECT @a:=EXTRACT(MINUTE_MICROSECOND FROM..)
MDEV-12862 Data type of @a:=1e0 depends on the session character set

1. Moving a part of Item::create_tmp_field() into a new helper method
   Item::create_tmp_field_int() and reusing it in Item::create_tmp_field()
   and Item_func_signed::create_tmp_field().
   Fixing the code in Item::create_tmp_field_int() to call
   Type_handler::make_table_field() instead of doing "new Field_long[long]"
   directly. This change revealed a problem reported in MDEV-12862.

2. Changing the "long vs longlong" cut-off length for
     - Item_func::create_tmp_field()
     - Item_sum::create_tmp_field()
     - Item_func_get_user_var::create_tmp_field()
   from MY_INT32_NUM_DECIMAL_DIGITS to (MY_INT32_NUM_DECIMAL_DIGITS - 2).
   This fixes MDEV-12858.
   After this change, the "convert_int_length" parameter to
   Item::create_tmp_field() is not needed any more, because
   (MY_INT32_NUM_DECIMAL_DIGITS - 2) is always passed.
   So removing the "convert_int_length" parameter.

3. Fixing Item::create_tmp_field() to pass max_char_length() instead
   of max_length to the constructor of Field_double().
   This fixes MDEV-12862.

4. Additionally, fixing
   - Type_handler_{tiny|short|int24|long|longlong}::make_table_field()
   - Type_handler_{float|double}::make_table_field()
   to pass max_char_length() instead of max_length to Field contructors.
   This is needed by the change (1).

5. Adding new tests, and recording new correct results in the old tests in:
   - mysql-test/r/type_ranges.result
   - storage/tokudb/mysql-test/tokudb/r/type_ranges.result
2017-05-22 13:44:26 +04:00
Marko Mäkelä
65e1399e64 Merge 10.0 into 10.1
Significantly reduce the amount of InnoDB, XtraDB and Mariabackup
code changes by defining pfs_os_file_t as something that is
transparently compatible with os_file_t.
2017-05-20 08:41:20 +03:00
Igor Babaev
5e9d651108 Fixed the bug mdev-12788.
In some rare cases queries with UNION ALL
using a derived table specified by
a grouping select with a subquery in WHERE and
impossible HAVING detected after constant row
substitution could hang.
The cause was not a proper return from the
function subselect_single_select_engine::exec()
in the case when the subquery was not optimized
beforehand and the optimization performed
in this function requested for a change of the
subquery engine. This was fixed.
Also a change was applied that avoided execution
of a subquery if impossible having was detected
for the main query at the optimization stage.
2017-05-18 23:56:49 -07:00
Vicențiu Ciorbaru
339a290d22 Merge remote-tracking branch 'origin/5.5' into 10.0 2017-05-17 15:42:36 +03:00
Igor Babaev
934b831281 Fixed the bug mdev-7791.
When an IN subquery predicate was converted to a semi-join that were
materialized and the result of the materialization happened to be
the last in the execution plan then any conjunctive condition with RAND()
turned out to be lost.

Fixed by attaching this condition to the last top base table.
2017-05-16 08:25:32 -07:00
Sergei Golubchik
c91ecf9e9b Merge branch '10.1' into 10.2
Revert commit db0917f68f, because the fix for MDEV-12696
is coming from 5.5 and 10.1 in this merge.
2017-05-09 13:24:52 +02:00
Sergei Golubchik
d738722eee Merge branch '10.0' into 10.1 2017-05-08 14:58:49 +02:00
Sergei Golubchik
1c418df722 Merge branch '5.5' into 10.0 2017-05-08 12:12:48 +02:00
Sergei Golubchik
d53eb85997 MDEV-12580 Wrong query result in join when using an index (Version > "10.2.3")
JOIN_TAB::remove_redundant_bnl_scan_conds() removes select_cond
from a JOIN_TAB if join cache is enabled, and tab->cache_select->cond
is the equal to tab->select_cond.

But after 8d99166c69 the code to initialize join cache was moved
to happen much later than JOIN_TAB::remove_redundant_bnl_scan_conds(),
and that code might, under certain conditions, revert to *not* using
join cache (set_join_cache_denial()).

If JOIN_TAB::remove_redundant_bnl_scan_conds() removes the WHERE
condition from the JOIN_TAB and later set_join_cache_denial() disables
join cache, we end up with no WHERE condition at all.

Fix: move JOIN_TAB::remove_redundant_bnl_scan_conds() to happen
after all possible set_join_cache_denial() calls.
2017-05-08 11:08:18 +02:00
Alexander Barkov
314350a722 Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.3 2017-05-07 23:51:18 +04:00
Alexander Barkov
cc694792c9 MDEV-12717 Change Item_equal to operate Type_handler rather than Item_result 2017-05-07 01:02:37 +04:00
Alexander Barkov
aea54a11a6 MDEV-12716 Change Value_source::Context to operate Type_handler rather than Item_result 2017-05-06 23:06:18 +04:00
Alexander Barkov
ac53b49b1b Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-05-05 16:12:54 +04:00
Igor Babaev
15f9931f6d Fixed the bug mdev-12673.
This patch corrects the fix for the bug mdev-10693.
It is critical for the function get_best_combination() not to call
create_ref_for_key() for constant tables.
This bug could manifest itself only in multi-table subqueries where
one of the tables is accessed by a constant primary key.
2017-05-04 22:45:32 -07:00
Igor Babaev
ce8ee7d90b Fixed the bug mdev-11990.
The usage of windows functions when all tables were optimized away
by min/max optimization were not supported. As result a result,
the queries that used window functions with min/max aggregation
over the whole table returned wrong result sets.
The patch fixed this problem.
2017-05-03 13:50:35 -07:00
Alexander Barkov
280866d38d Merge remote-tracking branch 'origin/bb-10.2-ext' into 10.3 2017-05-02 13:52:45 +04:00