Commit graph

2028 commits

Author SHA1 Message Date
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
Sergei Golubchik
da4d71d10d Merge branch '10.1' into 10.2 2017-03-30 12:48:42 +02:00
Alexey Botchkov
d0e8b427a1 MDEV-12078 Using spatial index changes type from point to geometry
In get_mm_tree we have to change Field_geom::geom_type to
        GEOMETRY as we have to let storing all types of the spatial features
        in the field. So now we restore the original geom_type as it's
        done.
2017-03-14 16:35:39 +04:00
Marko Mäkelä
ad0c218a44 Merge 10.0 into 10.1
Also, implement MDEV-11027 a little differently from 5.5 and 10.0:

recv_apply_hashed_log_recs(): Change the return type back to void
(DB_SUCCESS was always returned).

Report progress also via systemd using sd_notifyf().
2017-03-09 08:53:08 +02:00
Vicențiu Ciorbaru
1acfa942ed Merge branch '5.5' into 10.0 2017-03-03 01:37:54 +02:00
Oleksandr Byelkin
5ddfcb05ca MDEV-9455: [ERROR] mysqld got signal 11
Switch MEM_ROOT to non-prune_partitions() during optimizing subselect.
2017-02-20 15:49:38 +01:00
Sergei Golubchik
cff144a8ea cleanup: handler::key_read
* rename to "keyread" (to avoid conflicts with tokudb),
* change from bool to uint and store the keyread index number there
* provide a bool accessor to check if keyread is enabled
2017-02-13 18:12:05 +01:00
Sergei Golubchik
e46c42217f cleanup: TABLE::mark_columns_used_by_index()
mark_columns_used_by_index used to do
reset + mark_columns_used_by_index_no_reset + start keyread + set bitmaps

Now prepare_for_keyread does that, while mark_columns_used_by_index
does only reset + mark_columns_used_by_index_no_reset,
just as its name suggests.
2017-02-13 18:12:05 +01:00
Sergei Golubchik
bf8f70a47c cleanup: mark_columns_used_by_index_no_reset in opt_range.cc
use table->mark_columns_used_by_index, don't copy it
2017-02-13 18:12:05 +01:00
Sergei Golubchik
29ed440d44 MDEV-11836 vcol.vcol_keys_myisam fails in buildbot and outside
move TABLE::key_read into handler. Because in index merge and DS-MRR
there can be many handlers per table, and some of them use
key read while others don't. "keyread" is really per handler,
not per TABLE property.
2017-02-13 18:12:04 +01:00
Igor Babaev
f003cc8a35 Fixed bug mdev-8603.
When building different range and index-merge trees the range optimizer
could build an index-merge tree with an index scan containing less ranges
then needed. This index-merge could be chosen as the best. Following this
index-merge the executioner missed some rows in the result set.
The invalid index scan was built due to an inconsistency in the code
back-ported from mysql into 5.3 that fixed mysql bug #11765831:
the code added to key_or() could change shared keys of the second
ored tree. Partially the problem was fixed in the patch for mariadb
bug #823301, but it turned out that only partially.
2017-01-18 11:42:41 -08:00
Monty
135e144479 MDEV-11598 Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))' failed
Found and fixed 2 problems:

- Filesort addon fields didn't mark virtual columns properly
- multi-range-read calculated vcol bitmap but was not using it.
  This caused wrong vcol field to be calculated on read, which caused the assert.
2017-01-11 09:19:45 +02:00
Sergei Golubchik
4a5d25c338 Merge branch '10.1' into 10.2 2016-12-29 13:23:18 +01:00
Varun Gupta
f41bd7e545 MDEV-11060 sql/protocol.cc:532: void Protocol::end_statement(): Assertion `0' failed
In file sql/opt_range.cc,when calculate_cond_selectivity_for_table() is called with optimizer_use_condition_selectivity=4 then
	- thd->no_errors is set to 1
	- the original value of thd->no_error is not restored to its original value
	- this is causing the assertion to fail in the subsequent queries

Fixed by restoring the original value of thd->no_errors
2016-12-14 12:45:50 +05:30
Sergei Golubchik
85416269c3 MDEV-11518 Assertion `!table || (!table->read_set || bitmap_is_set(table->read_set, field_index))' failed in Field_long::val_int()
QUICK_RANGE_SELECT::init_ror_merged_scan() should
also set and restore TABLE::vcol_set
2016-12-12 20:44:46 +01:00
Sergei Petrunia
039bab2290 Undo the unfinished patch for MDEV-8359:
Patch b8b1b928ff was pushed by mistake
2016-11-20 00:26:40 +03:00
Sergei Golubchik
a98c85bb50 Merge branch '10.0-galera' into 10.1 2016-11-02 13:44:07 +01:00
Igor Babaev
d451d772fd Fixed bug mdev-9628.
In the function create_key_parts_for_pseudo_indexes()
the key part structures of pseudo-indexes created for
BLOB fields were set incorrectly.
Also the key parts for long fields must be 'truncated'
up to the maximum length acceptable for key parts.
2016-10-26 20:45:35 -07:00
Sergei Petrunia
b8b1b928ff MDEV-8359: WHERE condition referring to inner table of left join can be sargable
Implement a technique mentioned in the MDEV. Under certain conditions,
cond(inner_table.col) can be substituted for cond(outer_table.col) for
the purpose of range analysis.
2016-10-14 00:05:13 +03:00
Sergei Golubchik
06b7fce9f2 Merge branch '10.1' into 10.2 2016-09-09 08:33:08 +02:00
Sergei Golubchik
6b1863b830 Merge branch '10.0' into 10.1 2016-08-25 12:40:09 +02:00
Monty
a5051cd3b2 Minor cleanups
- Remove impossible test in test_quick_select
- Ensure that is_fatal_error is set if we run out of stack space
2016-08-22 10:19:07 +03:00
Sergei Golubchik
309c08c17c Merge branch '5.5' into 10.0 2016-08-10 19:19:05 +02:00
Sergei Petrunia
15ef38d2ea MDEV-10228: Delete missing rows with OR conditions
Fix get_quick_keys(): When building range tree from a condition
in form

  keypart1=const AND (keypart2 < 0 OR keypart2>=0)

the SEL_ARG for keypart2 represents an interval (-inf, +inf).
However, the logic that sets UNIQUE_RANGE flag fails to recognize
this, and sets UNIQUE_RANGE flag if (keypart1, keypart2) covered
a unique key.
As a result, range access executor assumes the interval can have
at most one row and only reads the first row from it.
2016-07-27 00:38:51 +03:00
Sergei Petrunia
95c286cedf MDEV-10324: Server crash in get_sel_arg_for_keypart or Assertion
The crash was caused by this problem:
get_best_group_min_max() tries to construct query plans for keys that
are not processed by the range optimizer. This wasn't a problem as long
as SEL_TREE::keys was an array of MAX_KEY elements.
However, now it is a Mem_root_array and only has elements for the used
keys, and get_best_group_min_max attempts to address beyond the end of
the array.

The obvious way to fix the crash was to port (and improve) a part of
96fcfcbd7b5120e8f64fd45985001eca8d36fbfb from mysql-5.7. This makes
get_best_group_min_max not to consider indexes that Mem_root_arrays
have no element for.

After that, I got non-sensical query plans (see MDEV-10325 for details).
Fixed that by making get_best_group_min_max to check if the index is in
table->keys_in_use_for_group_by bitmap.
2016-07-05 16:55:11 +03:00
Sergei Golubchik
932646b1ff Merge branch '10.1' into 10.2 2016-06-30 16:38:05 +02: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
Sergei Golubchik
3361aee591 Merge branch '10.0' into 10.1 2016-06-28 22:01:55 +02:00
Sergei Petrunia
3e03b89b0a MDEV-10185: Assertion `tree1->keys[key_no] && tree2->keys[key_no]' failed in
Make tree_or set correct SEL_TREE::keys_map for the result.
2016-06-22 23:20:41 +03:00
Alexander Barkov
a80dbe068c MDEV-10020 InnoDB NOT IN Query Crash When One Item Is NULL
The problem was that the loop in get_func_mm_tree()
accessed improperly initialized instances of String,
which resided in the bzero'ed part of the in_vector::base array.

Strings in in_vector::base are originally initialized
in Item_func_in::fix_length_and_dec(),
in in_vector::in_vector() using sql_calloc,
rather than using a String constructor, so their str_charset
members are originally equal to NULL.

Strings in in_vector::base are later initialized
to good values in Item_func_in::fix_length_and_dec(),
using array->set(), in this code:

      uint j=0;
      for (uint i=1 ; i < arg_count ; i++)
      {
        array->set(j,args[i]);
        if (!args[i]->null_value)                      // Skip NULL values
          j++;
        else
          have_null= 1;
      }
      if ((array->used_count= j))
        array->sort();

NULLs are not taken into account, so at the end
array->used_count can be smaller than array->count.

This patch fixes the loop in opt_range.cc, in get_func_mm_tree(),
to access only properly initialized elements in in_vector::base,
preventing access to its bzero'ed non-initialized tail.
2016-06-20 14:11:01 +04:00
Otto Kekäläinen
effbe7dd7b General spell fixing in comments and strings 2016-06-08 14:17:23 +03:00
Sergei Petrunia
7d3d75895d MDEV-9764: MariaDB does not limit memory used for range optimization
Part #2: make tree_or(tree1, tree2) to reuse tree1 for the result object
for simple cases. These include key IN (c1, ... cN).

The reuse was happening in old MySQL versions, but we stopped doing it
in the "fair choice between range and index_merge" patch.
2016-06-02 19:02:01 +03:00
Sergei Petrunia
016790403a MDEV-9764: MariaDB does not limit memory used for range optimization
A partial backport of 67f21fb3a077dedfd14b9ca720e926c55e682f93,
Bug#22283790: RANGE OPTIMIZER UTILIZES TOO MUCH MEMORY WITH MANY OR CONDITIONS

The backported part changes SEL_TREE::keys from being an array of
MAX_KEY elements (64*8=512 bytes) to a Mem_root_array<SEL_ARG*> (32 bytes +
alloc'ed array of as many elements as we need).

The patch doesn't fix the "not limiting memory" part, but the memory usage
is much lower with it.
2016-05-31 17:59:04 +03:00
Monty
9c846373f0 Merge commit 'd5822a3ad0657040114cdc185c6387b9eb3a12b2' into 10.2 2016-04-28 16:59:33 +03:00
Monty
48f02af761 MDEV-9602 crash in st_key::actual_rec_per_key when group by constant
Problem was that cost_group_min_max() could not handle if group by was optimized away.
2016-04-28 13:39:55 +03:00
Sergei Petrunia
2bd4dc38e0 Merge branch '10.2' into bb-10.2-mdev9543 2016-03-28 22:18:38 +03:00
Monty
260dd476b0 Removed TABLE->sort to make it possible to have multiple active calls to
filesort and init_read_record() for the same table.
This will simplify code for WINDOW FUNCTIONS (MDEV-6115)

- Filesort_info renamed to SORT_INFO and moved to filesort.h
- filesort now returns SORT_INFO
- init_read_record() now takes a SORT_INFO parameter.
- unique declaration is moved to uniques.h
- subselect caching of buffers is now more explicit than before
- filesort_buffer is now reusable even if rec_length has changed.
- filsort_free_buffers() and free_io_cache() calls are removed
- Remove one malloc() when using get_addon_fields()

Other things:
- Added --debug-assert-on-not-freed-memory option to make it easier to
  debug some not-freed-memory issues.
2016-03-22 23:44:52 +02: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
Monty
11c2d3c3e2 Merge branch '10.0' into 10.1
Conflicts:
	configure.cmake
2016-02-02 13:07:53 +02:00
Sergei Petrunia
74f15e2a7f MDEV-9505: Valgrind failure in SEL_ARG::store_min,find_used_partitions
create_partition_index_description() had wrong logic to calculate
length of the key value buffer that is used by the range optimizer.

For some reason it used MAX(partitioning_columns_len,
subpartitioning_columns_len) while it should use SUM of these values.
2016-02-01 19:36:22 +03:00
Monty
72dc30f217 Fixed compiler warnings 2015-11-23 19:56:03 +02:00
Monty
93d1e5ce0b table->write_set was changed if binary logging was used, which caused the
changes in query execution plans.
Fixed by introducing table->rpl_write_set which holds which columns should
be stored in the binary log.

Other things:
- Removed some not needed references to read_set and write_set to make
  code really changing read_set and write_set easier to read
  (in opt_range.cc)
- Added error handling of failed unpack_current_row()
- Added missing call to mark_columns_needed_for_insert() for DELAYED INSERT
- Removed not used functions in_read_set() and in_write_set()
- In rpl_record.cc, removed not used variable error
2015-11-10 13:46:56 +02:00
Nirbhay Choubey
7ec6558503 MDEV-9021: MYSQLD SEGFAULTS WHEN BUILT USING --WITH-MAX-INDEXES=128
The bitmap implementation defines two template Bitmap classes. One
optimized for 64-bit (default) wide bitmaps while the other is used for
all other widths.

In order to optimize the computations, Bitmap<64> class has defined its
own member functions for bitmap operations, the other one, however,
relies on mysys' bitmap implementation (mysys/my_bitmap.c).

Issue 1:
In case of non 64-bit Bitmap class, intersect() wrongly reset the
received bitmap while initialising a new local bitmap structure
(bitmap_init() clears the bitmap buffer) thus, the received bitmap was
getting cleared.

Fixed by initializing the local bitmap structure by using a temporary
buffer and later copying the received bitmap to the initialised bitmap
structure.

Issue 2:
The non 64-bit Bitmap class had the Iterator missing which caused
compilation failure.

Also added a cmake variable to hold the MAX_INDEXES value when supplied
from the command prompt. (eg. cmake .. -DMAX_INDEXES=128U). Checks have
been put in place to trigger build failure if MAX_INDEXES value is
greater than 128.

Test modifications:
* Introduced include/have_max_indexes_[64|128].inc to facilitate
skipping of tests for which the output differs with different
MAX_INDEXES.

* Introduced include/max_indexes.inc which would get modified by cmake
to reflect the MAX_INDEXES value used to build the server. This file
simply sets an mtr variable '$max_indexes' to show the MAX_INDEXES
value, which will then be consumed by the above introduced include file.

* Some tests (portions), dependent on MAX_INDEXES value, have been moved
to separate test files.
2015-11-09 09:28:00 -05: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
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
Sergei Golubchik
82e9f6d948 Merge remote-tracking branch 'mysql/5.5' into 5.5 2015-10-08 22:54:24 +02:00
Sergei Petrunia
4a602046c0 MDEV-8903: Buildbot valgrind failure: Invalid read of size 1 in sql_memdup...
When we calculate max_key_len for RANGE_OPT_PARAM::min_key/max_key, take
into account that QUICK_RANGE::QUICK_RANGE for some reason assumes
that there is one more byte there:

      max_key((uchar*) sql_memdup(max_key_arg,max_length_arg+1)),
2015-10-06 16:15:34 +03: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