summaryrefslogtreecommitdiff
path: root/mysql-test/t/range.test
Commit message (Collapse)AuthorAgeFilesLines
* MDEV-23811: With large number of indexes optimizer chooses an inefficient planmariadb-10.2.36Igor Babaev2020-11-091-0/+42
| | | | | | | | | | | | | | | | | 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 0e19f3e36f7842583feb6bead2c2600cd620bced). 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.
* MDEV-24117: Memory management problem ...: Add a testcaseSergei Petrunia2020-11-091-0/+46
| | | | Add a testcase.
* MDEV-24117: Memory management problem in statistics state for ... INSergei Petrunia2020-11-091-42/+0
| | | | | | | | | | Part#1: Revert the patch that caused it: commit 291be494744abe90f4bdf6b5a35c4c26ee8ddda5 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
* MDEV-23811: With large number of indexes optimizer chooses an inefficient planIgor Babaev2020-10-061-0/+42
| | | | | | | | | | | | | | | | | 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 0e19f3e36f7842583feb6bead2c2600cd620bced). 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.
* Merge 10.1 into 10.2Marko Mäkelä2020-04-141-0/+16
|\
| * Merge 5.5 into 10.1Marko Mäkelä2020-04-141-0/+16
| |\
| | * MDEV-22191: Range access is not picked when index_merge_sort_union is turned offbb-5.5-varunVarun Gupta2020-04-081-0/+14
| | | | | | | | | | | | | | | | | | | | | 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
* | | Updated mtr files to support different compiled in optionsMonty2019-09-011-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | MDEV-16934 Query with very large IN clause lists runs slowlyIgor Babaev2018-08-171-0/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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'.
* | | Fixed bug mdev-10454.Igor Babaev2017-04-031-0/+192
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Merge branch '10.0' into 10.1Sergei Golubchik2016-08-251-0/+29
|\ \
| * \ Merge branch '5.5' into 10.0Sergei Golubchik2016-08-101-0/+29
| |\ \ | | |/
| | * MDEV-10228: Delete missing rows with OR conditionsSergei Petrunia2016-07-271-0/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | | MDEV-10185: Assertion `tree1->keys[key_no] && tree2->keys[key_no]' failed inSergei Petrunia2016-06-221-0/+9
| | | | | | | | | | | | Make tree_or set correct SEL_TREE::keys_map for the result.
* | | Merge branch '10.0' into 10.1Sergei Golubchik2015-12-211-0/+12
|\ \ \ | |/ /
| * | Merge branch '5.5' into 10.0Sergei Golubchik2015-12-131-0/+12
| |\ \ | | |/
| | * Merge branch 'mysql/5.5' into 5.5Sergei Golubchik2015-12-091-0/+12
| | |\
| | | * Fixes for:Guilhem Bichot2012-01-261-0/+76
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | BUG#13519696 - 62940: SELECT RESULTS VARY WITH VERSION AND WITH/WITHOUT INDEX RANGE SCAN BUG#13453382 - REGRESSION SINCE 5.1.39, RANGE OPTIMIZER WRONG RESULTS WITH DECIMAL CONVERSION BUG#13463488 - 63437: CHAR & BETWEEN WITH INDEX RETURNS WRONG RESULT AFTER MYSQL 5.1. Those are all cases where the range optimizer got it wrong with > and >=.
| | | * Fix for bug#57030: ('BETWEEN' evaluation is incorrect')Ole John Aske2011-02-011-0/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Root cause for this bug is that the optimizer try to detect& optimize the special case: '<field> BETWEEN c1 AND c1' and handle this as the condition '<field> = c1' This was implemented inside add_key_field(.. *field, *value[]...) which assumed field to refer key Field, and value[] to refer a [low...high] constant pair. value[0] and value[1] was then compared for equality. In a 'normal' BETWEEN condition of the form '<field> BETWEEN val1 and val2' the BETWEEN operation is represented with an argementlist containing the values [<field>, val1, val2] - add_key_field() is then called with parameters field=<field>, *value=val1. However, if the BETWEEN predicate specified: 1) '<const1> BETWEEN<const2> AND<field> the 'field' and 'value' arguments to add_key_field() had to be swapped. This was implemented by trying to cheat add_key_field() to handle it like: 2) '<const1> GE<const2> AND<const1> LE<field>' As we didn't really replace the BETWEEN operation with 'ge' and 'le', add_key_field() still handled it as a 'BETWEEN' and compared the (swapped) arguments<const1> and<const2> for equality. If they was equal, the condition 1) was incorrectly 'optimized' to: 3) '<field> EQ <const1>' This fix moves this optimization of '<field> BETWEEN c1 AND c1' into add_key_fields() which then calls add_key_equal_fields() to collect key equality / comparison for the key fields in the BETWEEN condition.
| | | * Bug #54802: 'NOT BETWEEN' evaluation is incorrectAlexey Kopytov2010-08-241-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Queries involving predicates of the form "const NOT BETWEEN not_indexed_column AND indexed_column" could return wrong data due to incorrect handling by the range optimizer. For "c NOT BETWEEN f1 AND f2" predicates, get_mm_tree() produces a disjunction of the SEL_ARG trees for "f1 > c" and "f2 < c". If one of the trees is empty (i.e. one of the arguments is not sargable) the resulting tree should be empty as well, since the whole expression in this case is not sargable. The above logic is implemented in get_mm_tree() as follows. The initial state of the resulting tree is NULL (aka empty). We then iterate through arguments and compute the corresponding SEL_ARG tree (either "f1 > c" or "f2 < c"). If the resulting tree is NULL, it is simply replaced by the generated tree. Otherwise it is replaced by a disjunction of itself and the generated tree. The obvious flaw in this implementation is that if the first argument is not sargable and thus produces a NULL tree, the resulting tree will simply be replaced by the tree for the second argument. As a result, "c NOT BETWEEN f1 AND f2" will end up as just "f2 < c". Fixed by adding a check so that when the first argument produces an empty tree for the NOT BETWEEN case, the loop is aborted with an empty tree as a result. The whole idea of using a loop for 2 arguments does not make much sense, but it was probably used to avoid code duplication for several BETWEEN variants.
| | | * Bug#54444: Do not run main.range test for products without partitioningMartin Hansson2010-08-111-41/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | feature The test for bug no 50939 was put in range.test which isn't such a good idea since it requires partitioning. Fixed by moving the test case to partitioning_range.test.
| | | * Bug#50939: Loose Index Scan unduly relies on engine toMartin Hansson2010-05-101-0/+41
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | remember range endpoints The Loose Index Scan optimization keeps track of a sequence of intervals. For the current interval it maintains the current interval's endpoints. But the maximum endpoint was not stored in the SQL layer; rather, it relied on the storage engine to retain this value in-between reads. By coincidence this holds for MyISAM and InnoDB. Not for the partitioning engine, however. Fixed by making the key values iterator (QUICK_RANGE_SELECT) keep track of the current maximum endpoint. This is also more efficient as we save a call through the handler API in case of open-ended intervals. The code to calculate endpoints was extracted into separate methods in QUICK_RANGE_SELECT, and it was possible to get rid of some code duplication as part of fix.
| | | * Bug#48459: valgrind errors with query using 'Range checkedMartin Hansson2009-11-251-1/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | for each record' There was an error in an internal structure in the range optimizer (SEL_ARG). Bad design causes parts of a data structure not to be initialized when it is in a certain state. All client code must check that this state is not present before trying to access the structure's data. Fixed by - Checking the state before trying to access data (in several places, most of which not covered by test case.) - Copying the keypart id when cloning SEL_ARGs
| | | * Bug #48665: sql-bench's insert test fails due to wrong resultGeorgi Kodinov2009-11-191-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When merging ranges during calculation of the result of OR to two range sets the current range may be obsoleted by the resulting merged range. The first overlapping range can be obsoleted as well. Fixed by moving the pointer to the first overlapping range to the pointer of the resulting union range. Added few comments at key places in key_or().
| | | * Bug#47925: regression of range optimizer and date comparison in 5.1.39!Martin Hansson2009-11-021-0/+79
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a query was using a DATE or DATETIME value formatted using any other separator characters beside hyphen '-', a query with a greater-or-equal '>=' condition matching only the greatest value in an indexed column, the result was empty if index range scan was employed. The range optimizer got a new feature between 5.1.38 and 5.1.39 that changes a greater-or-equal condition to a greater-than if the value matching that in the query was not present in the table. But the value comparison function compared the dates as strings instead of dates. The bug was fixed by splitting the function get_date_from_str in two: One part that parses and does error checking. This function is now visible outside the module. The old get_date_from_str now calls the new function.
| | | * Bug #47123: Endless 100% CPU loop with STRAIGHT_JOIN Alexey Kopytov2009-10-171-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The problem was in incorrect handling of predicates involving NULL as a constant value by the range optimizer. For example, when creating a SEL_ARG node from a condition of the form "field < const" (which would normally result in the "NULL < field < const" SEL_ARG), the special case when "const" is NULL was not taken into account, so "NULL < field < NULL" was produced for the "field < NULL" condition. As a result, SEL_ARG structures of this form could not be further optimized which in turn could lead to incorrectly constructed SEL_ARG trees. In particular, code assuming SEL_ARG structures to always form a sequence of ordered disjoint intervals could enter an infinite loop under some circumstances. Fixed by changing get_mm_leaf() so that for any sargable predicate except "<=>" involving NULL as a constant, "empty" SEL_ARG is returned, since such a predicate is always false.
| | | * Revert the fix for bug #47123 until test suite failures are resolved.Georgi Kodinov2009-10-161-11/+0
| | | |
| | | * Manual merge.Alexey Kopytov2009-10-151-0/+11
| | | |\
| | | | * Bug #47123: Endless 100% CPU loop with STRAIGHT_JOIN Alexey Kopytov2009-10-131-0/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The problem was in incorrect handling of predicates involving NULL as a constant value by the range optimizer. For example, when creating a SEL_ARG node from a condition of the form "field < const" (which would normally result in the "NULL < field < const" SEL_ARG), the special case when "const" is NULL was not taken into account, so "NULL < field < NULL" was produced for the "field < NULL" condition. As a result, SEL_ARG structures of this form could not be further optimized which in turn could lead to incorrectly constructed SEL_ARG trees. In particular, code assuming SEL_ARG structures to always form a sequence of ordered disjoint intervals could enter an infinite loop under some circumstances. Fixed by changing get_mm_leaf() so that for any sargable predicate except "<=>" involving NULL as a constant, "empty" SEL_ARG is returned, since such a predicate is always false.
| | | * | Bug#42846: wrong result returned for range scan when usingMartin Hansson2009-10-091-0/+125
| | | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | covering index When two range predicates were combined under an OR predicate, the algorithm tried to merge overlapping ranges into one. But the case when a range overlapped several other ranges was not handled. This lead to 1) ranges overlapping, which gave repeated results and 2) a range that overlapped several other ranges was cut off. Fixed by 1) Making sure that a range got an upper bound equal to the next range with a greater minimum. 2) Removing a continue statement
| | | * Merge mysql.com:/misc/mysql/34731/50-34731tnurnberg@white.intern.koehntopp.de2008-03-271-0/+46
| | | |\ | | | | | | | | | | | | | | | into mysql.com:/misc/mysql/34731/51-34731
| | | | * Merge mysql.com:/misc/mysql/34731_/50-34731tnurnberg@white.intern.koehntopp.de2008-03-271-0/+46
| | | | |\ | | | | | | | | | | | | | | | | | | into mysql.com:/misc/mysql/34731/50-34731
| | | | | * Bug#34731: highest possible value for INT erroneously filtered by WHEREtnurnberg@mysql.com/white.intern.koehntopp.de2008-03-101-0/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | WHERE f1 < n ignored row if f1 was indexed integer column and f1 = TYPE_MAX ^ n = TYPE_MAX+1. The latter value when treated as TYPE overflowed (obviously). This was not handled, it is now.
| | | * | | Merge kaamos.(none):/data/src/opt/mysql-5.0-optkaa@kaamos.(none)2008-02-131-0/+17
| | | |\ \ \ | | | | |/ / | | | | | | | | | | | | into kaamos.(none):/data/src/opt/mysql-5.1-opt
| | | | * | Fixed bug #33833.igor@olga.mysql.com2008-01-261-0/+17
| | | | |/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Two disjuncts containing equalities of the form key=const1 and key=const2 can be merged into one if const1 is equal to const2. To check it the common collation of the constants were used rather than the collation of the field key. For example when the default collation of the constants was cases insensitive while the collation of the field was case sensitive, then two or-ed equality predicates key='b' and key='B' incorrectly were merged into one f='b'. As a result ref access was used instead of range access and wrong result sets were returned in many cases. Fixed the problem by comparing constant in the or-ed predicate with collation of the key field.
| | | * | Merge mysql.com:/home/gluh/MySQL/Merge/5.0-optgluh@eagle.(none)2007-12-131-0/+20
| | | |\ \ | | | | |/ | | | | | | | | | | into mysql.com:/home/gluh/MySQL/Merge/5.1-opt
| | | | * BUG#32198: Comparison of DATE with DATETIME still not using indexes correctlysergefp@mysql.com2007-12-131-0/+20
| | | | | | | | | | | | | | | | | | | | - Make conditions like "date_col $CMP$ 'datetime-const'" range-sargable
| | | * | Merge mysql.com:/home/psergey/bk-trees/mysql-5.0-optsergefp@pylon.mylan2007-03-311-19/+130
| | | |\ \ | | | | |/ | | | | | | | | | | into mysql.com:/home/psergey/mysql-5.1-merge2
| | | | * BUG#26624, pushbuild fixes: Merge to 5.0sergefp@mysql.com2007-03-311-19/+130
| | | | |\
| | | | | * BUG#26624: high mem usage (crash) in range optimizersergefp@mysql.com2007-03-311-19/+130
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Pushbuild fixes: - Make MAX_SEL_ARGS smaller (even 16K records_in_range() calls is more than it makes sense to do in typical cases) - Don't call sel_arg->test_use_count() if we've already allocated more than MAX_SEL_ARGs elements. The test will succeed but will take too much time for the test suite (and not provide much value).
| | | * | | Merge mysql.com:/home/psergey/mysql-5.0-mergesergefp@pylon.mylan2007-03-291-0/+32
| | | |\ \ \ | | | | |/ / | | | | | | | | | | | | into mysql.com:/home/psergey/mysql-5.1-merge
| | | | * | Merge of BUG#26624 and BUG#26625sergefp@mysql.com2007-03-291-0/+32
| | | | |\ \ | | | | | |/
| | | | | * BUG#26624: high mem usage (crash) in range optimizersergefp@mysql.com2007-03-281-0/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Added PARAM::alloced_sel_args where we count the # of SEL_ARGs created by SEL_ARG tree cloning operations. - Made the range analyzer to shortcut and not do any more cloning if we've already created MAX_SEL_ARGS SEL_ARG objects in cloning. - Added comments about space complexity of SEL_ARG-graph representation.
| | | | | * Merge bk-internal.mysql.com:/home/bk/mysql-4.1cmiller@zippy.cornsilk.net2007-01-311-2/+2
| | | | | |\ | | | | | | | | | | | | | | | | | | | | | into zippy.cornsilk.net:/home/cmiller/work/mysql/mysql-4.1-maint
| | | | * | \ Merge mysql.com:/home/gluh/MySQL/Merge/5.0gluh@mysql.com/eagle.(none)2007-01-231-0/+43
| | | | |\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | into mysql.com:/home/gluh/MySQL/Merge/5.0-opt
| | | * | \ \ \ Merge mysql.com:/home/gluh/MySQL/Merge/5.1gluh@eagle.(none)2007-01-241-0/+43
| | | |\ \ \ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | into mysql.com:/home/gluh/MySQL/Merge/5.1-opt
| | | | * \ \ \ \ Merge macbook.gmz:/Users/kgeorge/mysql/work/mysql-5.0-optgkodinov/kgeorge@macbook.gmz2007-01-231-0/+43
| | | | |\ \ \ \ \ | | | | | | |/ / / | | | | | |/| | | | | | | | | | | | into macbook.gmz:/Users/kgeorge/mysql/work/merge-5.1-opt
| | | | | * | | | Merge olga.mysql.com:/home/igor/mysql-4.1-optigor@olga.mysql.com2007-01-151-0/+43
| | | | | |\ \ \ \ | | | | | | | |/ / | | | | | | |/| | | | | | | | | | | into olga.mysql.com:/home/igor/mysql-5.0-opt
| | | | | | * | | Fixed bug #24776: an assertion abort in handler::ha_index_initigor@olga.mysql.com2007-01-131-0/+43
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | for queries using 'range checked for each record'. The problem was fixed in 5.0 by the patch for bug 12291. This patch down-ported the corresponding code from 5.0 into QUICK_SELECT::init() and added a new test case.
| | | * | | | | | Merge mysql.com:/usr/home/ram/work/bug22533/my50-bug22533ramil/ram@myoffice.izhnet.ru2007-01-181-2/+2
| | | |\ \ \ \ \ \ | | | | |/ / / / / | | | |/| | | / / | | | | | |_|/ / | | | | |/| | | into mysql.com:/usr/home/ram/work/bug22533/my51-bug22533