Commit graph

50 commits

Author SHA1 Message Date
Sergei Petrunia
33ede50f20 MDEV-22251: get_key_scans_params: Conditional jump or move depends on uninitialised value
Apply the patch based on the patch by Varun Gupta:

PARAM::is_ror_scan might be used unitialized when check_quick_select()
is invoked for a "degenerate" SEL_ARG tree (e.g. one having type
SEL_ARG::IMPOSSIBLE).

Make check_quick_select() always initialize PARAM::is_ror_scan.
2021-01-28 20:46:13 +03:00
Sergei Petrunia
8d8370e31d Forgot to add this change to previous cset 2020-12-22 19:22:41 +03:00
Daniel Black
aebb111269 MDEV-21958: postfix - result of range_mrr_icp 2020-12-16 10:26:29 +11:00
Igor Babaev
bea84aefb0 MDEV-23811: With large number of indexes optimizer chooses an inefficient plan
This bug could manifest itself for a query with WHERE condition containing
top level OR formula such that each conjunct contained a single-range
condition supported by the same index. One of these range conditions must
be fully covered by another range condition that is used later in the OR
formula. Additionally at least one of these condition should be ANDed with
a sargable range condition supported by a different index.

There were several attempts to fix related problems for OR conditions after
the backport of range optimizer code from MySQL (commit
0e19f3e36f). Unfortunately the first of these
fixes contained typo remained unnoticed until recently. This typo bug led
to rejection of valid range accesses. This patch fixed this typo bug.
The fix revealed another two bugs: one in a constructor for SEL_ARG,
the other in the function tree_or(). Both are fixed in this patch.
2020-11-09 13:51:32 -08:00
Sergei Petrunia
1404f3bea7 MDEV-24117: Memory management problem ...: Add a testcase
Add a testcase.
2020-11-09 19:29:34 +03:00
Sergei Petrunia
f81eef62e7 MDEV-24117: Memory management problem in statistics state for ... IN
Part#1: Revert the patch that caused it:

commit 291be49474
Author: Igor Babaev <igor@askmonty.org>
Date:   Thu Sep 24 22:02:00 2020 -0700

    MDEV-23811: With large number of indexes optimizer chooses an inefficient plan
2020-11-09 19:29:21 +03:00
Igor Babaev
291be49474 MDEV-23811: With large number of indexes optimizer chooses an inefficient plan
This bug could manifest itself for a query with WHERE condition containing
top level OR formula such that each conjunct contained a single-range
condition supported by the same index. One of these range conditions must
be fully covered by another range condition that is used later in the OR
formula. Additionally at least one of these condition should be ANDed with
a sargable range condition supported by a different index.

There were several attempts to fix related problems for OR conditions after
the backport of range optimizer code from MySQL (commit
0e19f3e36f). Unfortunately the first of these
fixes contained typo remained unnoticed until recently. This typo bug led
to rejection of valid range accesses. This patch fixed this typo bug.
The fix revealed another two bugs: one in a constructor for SEL_ARG,
the other in the function tree_or(). Both are fixed in this patch.
2020-10-06 13:12:11 -07:00
Marko Mäkelä
ccaec18b39 Merge 10.1 into 10.2 2020-04-14 16:13:35 +03:00
Marko Mäkelä
26f0cd8afc Merge 5.5 into 10.1 2020-04-14 15:43:12 +03:00
Varun Gupta
c1394ab6b5 MDEV-22191: Range access is not picked when index_merge_sort_union is turned off
When index_merge_sort_union is turned off only ror scans were considered for range
scans, which is wrong.
To fix the problem ensure both ror scans and non ror scans are considered for range
access
2020-04-08 23:47:03 +05:30
Varun Gupta
ab9f378b0b Backporting 273d8eb12c Proper fix for disabling warnings in read_statistics_for_table() 2019-09-23 14:11:48 +05:30
Monty
9cba6c5aa3 Updated mtr files to support different compiled in options
This allows one to run the test suite even if any of the following
options are changed:
- character-set-server
- collation-server
- join-cache-level
- log-basename
- max-allowed-packet
- optimizer-switch
- query-cache-size and query-cache-type
- skip-name-resolve
- table-definition-cache
- table-open-cache
- Some innodb options
etc

Changes:
- Don't print out the value of system variables as one can't depend on
  them to being constants.
- Don't set global variables to 'default' as the default may not
  be the same as the test was started with if there was an additional
  option file. Instead save original value and reset it at end of test.
- Test that depends on the latin1 character set should include
  default_charset.inc or set the character set to latin1
- Test that depends on the original optimizer switch, should include
  default_optimizer_switch.inc
- Test that depends on the value of a specific system variable should
  set it in the test (like optimizer_use_condition_selectivity)
- Split subselect3.test into subselect3.test and subselect3.inc to
  make it easier to set and reset system variables.
- Added .opt files for test that required specfic options that could
  be changed by external configuration files.
- Fixed result files in rockdsb & tokudb that had not been updated for
  a while.
2019-09-01 19:17:35 +03:00
Alexey Botchkov
c4ab352b67 MDEV-14576 Include full name of object in message about incorrect value for column.
The error message modified.
Then the TABLE_SHARE::error_table_name() implementation taken from 10.3,
          to be used as a name of the table in this message.
2018-12-16 02:21:41 +04:00
Igor Babaev
4eac5df3fc MDEV-16934 Query with very large IN clause lists runs slowly
This patch introduces support for the system variable eq_range_index_dive_limit
that existed in MySQL starting from 5.6. The variable sets a limit for
index dives into equality ranges. Index dives are performed by optimizer
to estimate the number of rows in range scans. Index dives usually provide
good estimate but they are pretty expensive. To estimate the number of rows
in equality ranges statistical data on indexes can be employed. Its usage gives
not so good estimates but it's cheap. So if the number of equality dives
required by an index scan exceeds the set limit no dives for equality
ranges are performed by the optimizer for this index.

As the new system variable is introduced in a stable version the default
value for it is set to a special value meaning there is no limit for the number
of index dives performed by the optimizer.

The patch partially uses the MySQL code for WL 5957
'Statistics-based Range optimization for many ranges'.
2018-08-17 14:28:39 -07:00
Sergei Golubchik
d390e501eb MDEV-11839 move value caching from get_datetime_value to fix_fields time
Refactor get_datetime_value() not to create Item_cache_temporal(),
but do it always in ::fix_fields() or ::fix_length_and_dec().

Creating items at the execution time doesn't work very well with
virtual columns and check constraints that are fixed and executed
in different THDs.
2018-03-14 12:45:28 +01:00
Sergei Golubchik
5ccaabe962 MDEV-10355 Weird error message upon CREATE TABLE with DEFAULT
post-fix for 0b52b28b91

* restore EXPLAIN output
* remove redundant code
2017-04-30 14:58:11 +02:00
Jacob Mathew
0b52b28b91 MDEV-10355 Weird error message upon CREATE TABLE with DEFAULT
Fixed handling of default values with cached temporal functions so that the
CREATE TABLE statement now succeeds.
Fixed virtual column session cleanup.
Fixed the error message.
Added quoting of date/time values in cases when this was omitted.
Added a test case in default.test.
Updated test result files.
2017-04-18 17:36:05 -07: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
Sergei Golubchik
180065ebb0 Item::print(): remove redundant parentheses
by introducing new Item::precedence() method and using it
to decide whether parentheses are required
2016-12-12 20:44:41 +01:00
Sergei Golubchik
6b1863b830 Merge branch '10.0' into 10.1 2016-08-25 12:40:09 +02:00
Sergei Golubchik
309c08c17c Merge branch '5.5' into 10.0 2016-08-10 19:19:05 +02:00
Sergei Petrunia
c6aaa2adbe MDEV-10228: update test results 2016-07-30 10:53:01 +03: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
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
Alexander Barkov
7145ca477c Recording range_mrr_icp.result (forgotten in the patch for MDEV-8613) 2015-08-14 11:11:39 +04:00
Alexander Barkov
f35386d6f3 Checking in range_mrr_icp.result forgotten in the previous patch. 2015-07-01 15:37:52 +04:00
Alexander Barkov
75d65b5f4e MDEV-6989 BINARY and COLLATE xxx_bin comparisions are not used for optimization in some cases 2015-03-13 15:48:39 +04:00
Sergei Petrunia
be00e279c6 MDEV-6480: Remove conditions for which range optimizer returned SEL_ARG::IMPOSSIBLE
Let range optimizer remove parts of OR-clauses for which range analysis
produced SEL_TREE(IMPOSSIBLE).
There is no need to remove parts of AND-clauses: either they are inside
of OR (and the whole AND-clause will be removed), or the AND-clause is
at the top level, in which case the whole WHERE (or ON) is always FALSE
and this is a degenerate case which receives special treatment.

The removal process takes care not to produce 1-way ORs (in that case
we substitute the OR for its remaining member).
2014-08-27 18:47:33 +04:00
Sergei Golubchik
e27c338634 5.5.38 merge 2014-06-06 00:07:27 +02:00
Sergei Golubchik
6d75570e99 fix range.test 2014-06-05 19:25:51 +02:00
Sergey Petrunya
f20cab1a83 BUG#13803810: TOO FEW ROWS RETURNED FOR RANGE ACCESS IN VARCHAR INDEX USING DATETIME VALUE
- Backport the testcase from mysql-5.6
2014-03-07 13:00:20 +01:00
Sergey Petrunya
7af71b74a9 BUG#13731380: RANGE OPTIMIZER CALLS RECORDS_IN_RANGE() FOR OPEN RANGE
- Backport testcase from mysql-5.6
2014-03-07 12:49:40 +01:00
Sergey Petrunya
75a3527777 MDEV-5606: range optimizer: "x < y" is sargable, while "y > x" is not
Port to mariadb-1.0 the following fix from mysql-5.6:

  Revision ID: jorgen.loland@oracle.com-20120314131055-ml54x9deueqfsff4
  BUG#13701206: WHERE A>=B DOES NOT GIVE SAME EXECUTION PLAN
                AS WHERE B<=A (RANGE OPTIMIZER)
 
that fix didn't have a public testcase, so I created one.
2014-02-04 13:27:10 +04:00
timour@askmonty.org
afed809297 MDEV-5123 Remove duplicated conditions pushed both to join_tab->select_cond and join_tab->cache_select->cond for blocked joins.
BNL and BNLH joins pre-filter the records from a joined table via JOIN_TAB::cache_select->cond.
There is no need to re-evaluate the same conditions via JOIN_TAB::select_cond. This patch removes
the duplicated conditions from the top-level conjuncts of each pushed condition.

The added "Using where" in few EXPLAINs is due to taking into account tab->cache_select->cond
in addition to tab->select_cond in JOIN::save_explain_data_intern.
2013-10-18 11:45:25 +03:00
Igor Babaev
4eddb2c221 Merge 5.3->5.5.
In particular:
Merged the patch for bug mdev-4418 from 5.3 into 5.5.
Fixed a bug in the patch that should be backported to 5.3.
2013-08-18 19:58:51 -07:00
Igor Babaev
960720b10d Merge 5.2->5.3 2013-08-15 14:04:20 -07:00
Sergey Petrunya
04684b7709 MDEV-4817: Optimizer fails to optimize expression of the form 'FOO' IS NULL
- Modify the way Item_cond::fix_fields() and Item_cond::eval_not_null_tables() 
  calculate bitmap for Item_cond_or::not_null_tables():
  if they see a "... OR inexpensive_const_false_item OR ..." then the item can
  be ignored.
- Updated test results. There can be more warnings produced since parts of WHERE 
  are evaluated more times.
2013-07-31 17:24:52 +04:00
unknown
f65e5841d7 Fix for MDEV-3948, and backport of the following collection of fixes and backports
from MariaDB 10.0.
  
The bug in mdev-3948 was an instance of the problem fixed by Sergey's patch
in 10.0 - namely that the range optimizer could change table->[read | write]_set,
and not restore it.
  
revno: 3471
committer: Sergey Petrunya <psergey@askmonty.org>
branch nick: 10.0-serg-fix-imerge
timestamp: Sat 2012-11-03 12:24:36 +0400
message:
  # MDEV-3817: Wrong result with index_merge+index_merge_intersection, InnoDB table, join, AND and OR conditions
  Reconcile the fixes from:
  #
  # guilhem.bichot@oracle.com-20110805143029-ywrzuz15uzgontr0
  # Fix for BUG#12698916 - "JOIN QUERY GIVES WRONG RESULT AT 2ND EXEC. OR
  # AFTER FLUSH TABLES [-INT VS NULL]"
  #
  # guilhem.bichot@oracle.com-20111209150650-tzx3ldzxe1yfwji6
  # Fix for BUG#12912171 - ASSERTION FAILED: QUICK->HEAD->READ_SET == SAVE_READ_SET
  # and
  #
  and related fixes from: BUG#1006164, MDEV-376:
  
  Now, ROR-merged QUICK_RANGE_SELECT objects make no assumptions about the values
  of table->read_set and table->write_set.
  Each QUICK_ROR_SELECT has (and had before) its own column bitmap, but now, all 
  QUICK_ROR_SELECT's functions that care: reset(), init_ror_merged_scan(), and 
  get_next()  will set table->read_set when invoked and restore it back to what 
  it was before the call before they return.

  This allows to avoid the mess when somebody else modifies table->read_set for 
  some reason.
2013-01-28 15:13:39 +02:00
Sergei Golubchik
a3073ecd96 merge 2012-04-05 23:07:18 +02:00
Sergei Golubchik
4933d21e5d merge with mysql-5.5.21 2012-03-09 08:06:59 +01:00
Michael Widenius
15c5a2686f Merge with MariaDB 5.2 2012-02-21 01:58:50 +02:00
Sergei Golubchik
edab37cd68 5.3 merge 2012-02-21 20:51:56 +01:00
Sergei Golubchik
d2755a2c9c 5.3->5.5 merge 2011-11-22 18:04:38 +01:00
Igor Babaev
e0c1b3f242 Fixed LP bug #886145.
The bug happened because in some cases the function JOIN::exec
did not save the value of TABLE::pre_idx_push_select_cond in
TABLE::select->pre_idx_push_select_cond for the sort table.

Noticed and fixed a bug in the function make_cond_remainder
that builds the remainder condition after extraction of an index
pushdown condition from the where condition. The code
erroneously assumed that the function make_cond_for_table left
the value of ICP_COND_USES_INDEX_ONLY in sub-condition markers.
Adjusted many result files from the regression test suite
after this fix .
2011-11-06 01:23:03 -07:00
Sergei Golubchik
76f0b94bb0 merge with 5.3
sql/sql_insert.cc:
  CREATE ... IF NOT EXISTS may do nothing, but
  it is still not a failure. don't forget to my_ok it.
  ******
  CREATE ... IF NOT EXISTS may do nothing, but
  it is still not a failure. don't forget to my_ok it.
sql/sql_table.cc:
  small cleanup
  ******
  small cleanup
2011-10-19 21:45:18 +02:00
Igor Babaev
715dc5f99d Fixed a cost estimation bug introduced into in the function best_access_path
of the 5.3 code line after a merge with 5.2 on 2010-10-28
in order not to allow the cost to access a joined table to be equal
to 0 ever.

Expanded data sets for many test cases to get the same execution plans
as before.
2011-09-30 18:55:02 -07:00
Sergey Petrunya
0e19f3e36f Backport of:
revno: 2876.47.174
revision-id: jorgen.loland@oracle.com-20110519120355-qn7eprkad9jqwu5j
parent: mayank.prasad@oracle.com-20110518143645-bdxv4udzrmqsjmhq
committer: Jorgen Loland <jorgen.loland@oracle.com>
branch nick: mysql-trunk-11765831
timestamp: Thu 2011-05-19 14:03:55 +0200
message:
  BUG#11765831: 'RANGE ACCESS' MAY INCORRECTLY FILTER 
                        AWAY QUALIFYING ROWS
        
  The problem was that the ranges created when OR'ing two 
  conditions could be incorrect. Without the bugfix, 
  "I <> 6 OR (I <> 8 AND J = 5)" would create these ranges:
  
  "NULL < I < 6",
  "6 <= I <= 6 AND 5 <= J <= 5",
  "6 < I < 8",
  "8 <= I <= 8 AND 5 <= J <= 5",
  "8 < I"
  
  While the correct ranges is
  "NULL < I < 6",
  "6 <= I <= 6 AND 5 <= J <= 5",
  "6 < I"
  
  The problem occurs when key_or() ORs
  (1) "NULL < I < 6, 6 <= I <= 6 AND 5 <= J <= 5, 6 < I" with 
  (2) "8 < I AND 5 <= J <= 5"
  
  The reason for the bug is that in key_or(), SEL_ARG *tmp is 
  used to point to the range in (1) above that is merged with 
  (2) while key1 points to the root of the red-black tree of 
  (1). When merging (1) and (2), tmp refers to the "6 < I" 
  part whereas the root is the "6 <= ... AND 5 <= J <= 5" part. 
  
  key_or() decides that the tmp range needs to be split into
  "6 < I < 8, 8 <= I <= 8, 8 < I", in which next_key_part of the 
  second range should be that of tmp. However, next_key_part is
  set to key1->next_key_part ("5 <= J <= 5") instead of 
  tmp->next_key_part (empty). Fixing this gives the correct but
  not optimal ranges:
  "NULL < I < 6",
  "6 <= I <= 6 AND 5 <= J <= 5",
  "6 < I < 8",
  "8 <= I <= 8",
  "8 < I"
  
  A second problem can be seen above: key_or() may create 
  adjacent ranges that could be replaced with a single range. 
  Fixes for this is also included in the patch so that the range
  above becomes correct AND optimal:
  "NULL < I < 6",
  "6 <= I <= 6 AND 5 <= J <= 5",
  "6 < I"
  
  Merging adjacent ranges like this gives a slightly lower cost 
  estimate for the range access.
2011-08-05 22:01:49 +04:00
Sergey Petrunya
1492de8563 Set the default to be mrr=off,mrr_sort_keys=off:
- Set the default
- Adjust the testcases so that 'new' tests are run with optimizations turned on.
- Pull out relevant tests from "irrelevant" tests and run them with optimizations on.
- Run range.test and innodb.test with both mrr=on and mrr=off
2011-07-08 18:46:47 +04:00