Commit graph

779 commits

Author SHA1 Message Date
Igor Babaev
597934eedf Fixed compiler warnings. 2010-12-10 20:58:28 -08:00
Igor Babaev
212e42263d Merge. 2010-12-10 01:17:09 -08:00
Igor Babaev
c4080280df Merge 2010-12-09 21:55:14 -08:00
Igor Babaev
afcefa97d9 Addemdum for bug #685952.
Also:
Changed the value of TIME_FOR_COMPARE_ROWID to make it the same as for MWL 21.
Changed some queries in range_vs_index_merge.test to make them generate
the same plans as earlier.
2010-12-09 11:06:32 -08:00
Igor Babaev
93fb6ce1fd The function records_in_index_intersect_extension tried to
read after the last element of the array of rec_per_key
values for an index. This caused a valgrind complain and
probably could result in wrong estimates of the cardinality
of index intersections.
2010-12-07 19:45:28 -08:00
Igor Babaev
c44c9207f0 Fixed LP bug #685952.
When ORing two AND-OR formulas the range optimizer could miss
a conjunct in one of AND-OR formulas in the result. If the
index merge union plan to access a table is formed by this 
formula that, in general, is not inferred from the original
where/on condition,the query could return an incorrect result set.
2010-12-07 12:14:28 -08:00
Igor Babaev
f7ab607a11 Merge. 2010-12-05 19:30:05 -08:00
Igor Babaev
67180d655a Fixed LP bug #684117.
A crash may happenin the cases when the range optimizer tried to OR
two index merge such that the second one contained less range trees
than the first one.
The bug was introduced by the patch of MWL#24: 
"index_merge: fair choice between index_merge union and range access".
2010-12-05 19:09:37 -08:00
Igor Babaev
1684c3e9a0 Fixed LP bug#684086.
If a primary key was used in the index intersection for
an InnoDB database the size of the memory allocated
for the best index intersection plan was one element less
than it was needed. That could cause a memory overwrite
and a crash as a result of it.
2010-12-05 13:49:04 -08:00
Igor Babaev
bfb7727526 Fixed LP bug #684117.
A crash may happenin the cases when the range optimizer tried to OR
two index merge such that the second one contained less range trees
than the first one.
The bug was introduced by the patch of MWL#24: 
"index_merge: fair choice between index_merge union and range access".
2010-12-04 19:19:55 -08:00
Igor Babaev
e13406b29b Changed the queries of index_intersect.test to ensure platform
independent execution plans.
Fixed a bug in Unique::unique_add that caused a crash for a query from
index_intersect_innodb on some platforms.
Fixed two bugs in opt_range.cc that led to the choice of not the
cheapest plans for index intersections.
2010-12-03 20:26:15 -08:00
Igor Babaev
80377bbf6d MWL #21: "index_merge: non-ROR intersection".
The second (final) patch.
2010-12-01 23:39:39 -08:00
Michael Widenius
b8b3716ae0 Patch from Sergey Petrunya:
Fix post-merge failure in 5.1-merge 
- Let QUICK_RANGE_INTERSECT_SELECT not make assumption that HA_EXTRA_KEYREAD 
  scans do not touch parts of table->record[0] that refer to fields that are 
  not covered by the used index.
  This assumption is not true for XtraDB (e.g. grep row/row0sel.c for 
  "init null bytes with default values as they might be").
2010-11-26 17:18:51 +02:00
Michael Widenius
b52020221e Merge with MySQL 5.1.52 2010-11-23 23:39:59 +02:00
Sergei Golubchik
60c15066db better fix for MySQL bugs
BUG#26447 prefer a clustered key for an index scan, as secondary index is always slower
  ... which was fixed to cause
BUG#35850 queries take 50% longer
  ... and was reverted

and

BUG#39653 prefer a secondary index for an index scan, as clustered key is always slower
  ... which was fixed to cause
BUG#55656 mysqldump takes six days instead of half an hour
  ... and was amended with a special case workaround


sql/opt_range.cc:
  move get_index_only_read_time() into the handler class
sql/sql_select.cc:
  use cost not an index length when choosing a cheaper index
2010-10-20 12:58:43 +02:00
Sergei Golubchik
745cc74c33 5.1.51 merge 2010-10-19 15:58:35 +02:00
Igor Babaev
7970b3346a Merge 2010-09-27 23:24:46 -07:00
Sergey Glukhov
31a38c0fc5 Bug#50402 Optimizer producing wrong results when using Index Merge on InnoDB
Subselect executes twice, at JOIN::optimize stage
and at JOIN::execute stage. At optimize stage
Innodb prebuilt struct which is used for the
retrieval of column values is initialized in.
ha_innobase::index_read(), prebuilt->sql_stat_start is true.
After QUICK_ROR_INTERSECT_SELECT finished his job it
restores read_set/write_set bitmaps with initial values
and deactivates one of the handlers used by
QUICK_ROR_INTERSECT_SELECT in JOIN::cleanup
(it's the case when we reuse original handler as one of
 handlers required by QUICK_ROR_INTERSECT_SELECT object).
On second subselect execution inactive handler is activated
in  QUICK_RANGE_SELECT::reset, file->ha_index_init().
In ha_index_init Innodb prebuilt struct is reinitialized
with inappropriate read_set/write_set bitmaps. Further
reinitialization in ha_innobase::index_read() does not
happen as prebuilt->sql_stat_start is false.
It leads to partial retrieval of required field values
and we get a mix of field values from different records
in the record buffer.
The fix is to reset
read_set/write_set bitmaps as these values
are required for proper intialization of
internal InnoDB struct which is used for
the retrieval of column values
(see build_template(), ha_innodb.cc)


mysql-test/include/index_merge_ror_cpk.inc:
  test case
mysql-test/r/index_merge_innodb.result:
  test case
mysql-test/r/index_merge_myisam.result:
  test case
sql/opt_range.cc:
  if ROR merge scan is used we need to reset
  read_set/write_set bitmaps as these values
  are required for proper intialization of
  internal InnoDB struct which is used for
  the retrieval of column values
  (see build_template(), ha_innodb.cc)
2010-09-16 16:13:53 +04:00
Igor Babaev
1a3bb0c5c2 Fixed bug #637978.
Fixed a bug in the new code for WL#24 that caused generation of
an invalid index-merge access plan.
2010-09-15 16:42:56 -07:00
Igor Babaev
69dd773b67 An implementation of index intersect via a modified Unique class.
This code is planned to be used for mwl#21.
2010-09-13 15:22:11 -07:00
Igor Babaev
5719ca5c51 Pulled in the latest changes of 5.1 2010-09-11 23:56:51 -07:00
Igor Babaev
93c22e0699 Pulled in the ltest changes of 5.1 2010-09-11 13:27:22 -07:00
Igor Babaev
3a61fbe972 WL#24: post review fixes. 2010-09-11 12:18:58 -07:00
Igor Babaev
56d3674ba5 Merge 2010-08-31 15:45:25 -07:00
Michael Widenius
ad6d95d3cb Merge with MySQL 5.1.50
- Changed to still use bcmp() in certain cases becasue
  - Faster for short unaligneed strings than memcmp()
  - Bettern when using valgrind
- Changed to use my_sprintf() instead of sprintf() to get higher portability for old systems
- Changed code to use MariaDB version of select->skip_record()
- Removed -%::SCCS/s.% from Makefile.am:s to remove automake warnings
2010-08-27 17:12:44 +03:00
Alexey Kopytov
e7b2688271 Bug #54802: 'NOT BETWEEN' evaluation is incorrect
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.
2010-08-24 19:51:32 +04:00
Michael Widenius
e0a6b02c5d Merge with MySQL 5.1.49
Fixed Bug#52005 'JOIN_TAB->dependent' may be incorrectly propageted for multilevel outer joins' in a better way (patch from Sergey Petrunya)
2010-08-02 12:01:24 +03:00
Martin Hansson
2b734bbee9 Bug#41660: Sort-index_merge for non-first join table may
require O(#scans) memory

When an index merge operation was restarted, it would
re-allocate the Unique object controlling the duplicate row
ID elimination. Fixed by making the Unique object a member
of QUICK_INDEX_MERGE_SELECT and thus reusing it throughout
the lifetime of this object.
2010-06-24 15:21:23 +02:00
Alexey Kopytov
53e29848a7 Manual merge. 2010-07-15 17:01:44 +04:00
Alexey Kopytov
4c28b67768 Backport of the fix for bug#25421 to 5.0.
Calculating the estimated number of records for a range scan
may take a significant time, and it was impossible for a user
to interrupt that process by killing the connection or the
query.

Fixed by checking the thread's 'killed' status in
check_quick_keys() and interrupting the calculation process if
it is set to a non-zero value.
2010-07-15 10:10:16 +04:00
Sergey Glukhov
b36a028224 Bug#50389 Using intersect does not return all rows
In process of record search it is not taken into account
that inital quick->file->ref value could be inapplicable
to range interval. After proper row is found this value is
stored into the record buffer and later the record is
filtered out at condition evaluation stage.
The fix is store a refernce of found row to the handler ref field.


mysql-test/r/innodb_mysql.result:
  test case
mysql-test/std_data/intersect-bug50389.tsv:
  test case
mysql-test/t/innodb_mysql.test:
  test case
sql/opt_range.cc:
  store a refernce of found row to the handler ref field.
2010-06-21 15:09:58 +04:00
Michael Widenius
6659ad49fe Fixes after last merge of MySQL 5.1
- INSERT with RAND() doesn't require row based logging again
- Some bugs fixed in opt_range() where we table->key_read was wrongly used



.bzrignore:
  Ignore new xtstat binary
mysql-test/r/index_merge_myisam.result:
  Update results (old result was wrong)
mysql-test/suite/binlog/r/binlog_stm_binlog.result:
  Added drop table first
mysql-test/suite/binlog/r/binlog_stm_unsafe_warning.result:
  Added test for when RAND() requires row based logging
mysql-test/suite/binlog/t/binlog_stm_binlog.test:
  Added drop table first
mysql-test/suite/binlog/t/binlog_stm_unsafe_warning.test:
  Added test for when RAND() requires row based logging
scripts/make_binary_distribution.sh:
  Removed type from last commit
sql/item_create.cc:
  Don't require row based logging when using RAND() with INSERT
sql/opt_range.cc:
  Revert wrong patch from Oracle:
  - As QUICK_RANGE_SELECT uses it's own 'file' handler to the tables, one can't use 'table->key_read' as a flag to detect if index only read (keyread) is used or not
  - Don't set keyread if keyread is already enabled
  - Don't disable key read, if we didn't enable it ourselves
  - Simplify code (and ensure that we do proper cleanup of index only read)
sql/opt_range.h:
  Added flags to detect if the range optimizer enabled index only read (key read) or not
sql/opt_sum.cc:
  Use our more optimized macros
sql/sql_lex.h:
  Added 'readable' function to check if we are in a sub query function or not (not normal query or sub query in FROM clause)
sql/sql_select.cc:
  Use our more optimized keyread macros
  Added ASSERTS early
  Simplify code on eliminate_item_equal()
  Fixed that substitute_for_best_equal_field() doesn't core dump in case of out of memory conditions.
  Removed not needed test for 'field->maybe_null()'
  Replaced master_unit()->item with is_subquery_function() (More readable)
sql/sql_update.cc:
  Use our more optimized keyread macros
sql/table.cc:
  Use our more optimized keyread macros
sql/table.h:
  Use separate functions to enable/disable Index only reads
  - Safer, more readable, better logging and faster.
2010-05-13 14:00:53 +03:00
Martin Hansson
6d0425b18d Bug#50939: Loose Index Scan unduly relies on engine to
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.
2010-05-10 09:23:23 +02:00
unknown
b1e00b6be8 Merge MySQL 5.1.46 into MariaDB.
Still two test failures to be solved: main.myisam and main.subselect.
2010-04-28 14:52:24 +02:00
Sergey Vojtovich
0897669cba BUG#49902 - SELECT returns incorrect results
Queries optimized with GROUP_MIN_MAX didn't cleanup KEYREAD
optimization properly. As a result subsequent queries may
return incomplete rows (fields are initialized to default
values).

mysql-test/r/group_min_max.result:
  A test case for BUG#49902.
mysql-test/t/group_min_max.test:
  A test case for BUG#49902.
sql/opt_range.cc:
  Refactor of KEYREAD optimization switch so that KEYREAD
  handler state is in sync with st_table::key_read flag.
  
  All SQL code is supposed to switch KEYREAD optimization
  via st_table::set_keyread().
sql/opt_sum.cc:
  Refactor of KEYREAD optimization switch so that KEYREAD
  handler state is in sync with st_table::key_read flag.
  
  All SQL code is supposed to switch KEYREAD optimization
  via st_table::set_keyread().
sql/sql_select.cc:
  Refactor of KEYREAD optimization switch so that KEYREAD
  handler state is in sync with st_table::key_read flag.
  
  All SQL code is supposed to switch KEYREAD optimization
  via st_table::set_keyread().
sql/sql_update.cc:
  Refactor of KEYREAD optimization switch so that KEYREAD
  handler state is in sync with st_table::key_read flag.
  
  All SQL code is supposed to switch KEYREAD optimization
  via st_table::set_keyread().
sql/table.cc:
  Refactor of KEYREAD optimization switch so that KEYREAD
  handler state is in sync with st_table::key_read flag.
  
  All SQL code is supposed to switch KEYREAD optimization
  via st_table::set_keyread().
sql/table.h:
  Refactor of KEYREAD optimization switch so that KEYREAD
  handler state is in sync with st_table::key_read flag.
  
  All SQL code is supposed to switch KEYREAD optimization
  via st_table::set_keyread().
2010-02-09 12:53:13 +04:00
Michael Widenius
d8ecbbe634 Merge with MySQL 5.1.42
- Marked a couple of tests with --big
- Fixed xtradb/handler/ha_innodb.cc to call explain_filename()

storage/xtradb/handler/ha_innodb.cc:
  Call explain_filename() to get proper names for partitioned tables
2010-01-15 17:27:55 +02:00
Martin Hansson
14f2eb1244 Bug#48459: valgrind errors with query using 'Range checked
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


mysql-test/r/range.result:
  Bug#48459: Test result.
mysql-test/t/range.test:
  Bug#48459: Test case.
sql/opt_range.cc:
  Bug#48459: Fix + doxygenated count_key_part_usage comment.
2009-11-25 11:02:25 +01:00
Alexey Kopytov
908323304e Automerge. 2009-11-23 13:07:18 +03:00
Alexey Kopytov
38ed9324be Automerge. 2009-11-23 13:04:17 +03:00
Georgi Kodinov
405c9310cf Bug #48665: sql-bench's insert test fails due to wrong result
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().
2009-11-19 18:26:19 +02:00
Alexey Kopytov
8cfa50e677 Bug #48472: Loose index scan inappropriately chosen for some
WHERE conditions 
 
check_group_min_max() checks if the loose index scan 
optimization is applicable for a given WHERE condition, that is 
if the MIN/MAX attribute participates only in range predicates 
comparing the corresponding field with constants. 
 
The problem was that it considered the whole predicate suitable 
for the loose index scan optimization as soon as it encountered 
a constant as a predicate argument. This is obviously wrong for 
cases when a constant is the first argument of a predicate 
which does not satisfy the above condition. 
 
Fixed check_group_min_max() so that all arguments of the input 
predicate are considered to decide if it passes the test, even 
though a constant has already been encountered.

mysql-test/r/group_min_max.result:
  Added a test case for bug #48472.
mysql-test/t/group_min_max.test:
  Added a test case for bug #48472.
sql/opt_range.cc:
  Fixed check_group_min_max() so that all arguments of the input 
  predicate are considered to decide if it passes the test, even 
  though a constant has already been encountered.
2009-11-17 17:07:14 +03:00
unknown
a962160eec Merge with MySQL 5.1, with following additions:
- Moved some code from innodb_plugin to xtradb, to ensure that all tests runs
- Did changes in pbxt and maria storage engines becasue of changes in thd->query
- Reverted wrong code in sql_table.cc for how ROW_FORMAT is used.

This is a re-commit of Monty's merge to eliminate an extra commit from
MySQL-5.1.42 that was accidentally included in the merge.

This is a merge of the MySQL 5.1.41 clone-off (clone-5.1.41-build). In
case there are any extra changes done before final MySQL 5.1.41
release, these will need to be merged later before MariaDB 5.1.41
release.
2009-11-16 21:49:51 +01:00
Martin Hansson
740b7c4e36 Bug#47925: regression of range optimizer and date comparison in 5.1.39!
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.


mysql-test/r/range.result:
  Bug#47925: Test result
mysql-test/t/range.test:
  Bug#47925: Test case
sql/item.cc:
  Bug#47925: Fix + some edit on the comments
sql/item.h:
  Bug#47925: Changed function signature
sql/item_cmpfunc.cc:
  Bug#47925: Split function in two
sql/item_cmpfunc.h:
  Bug#47925: Declaration of new function
sql/opt_range.cc:
  Bug#47925: Added THD to function call
sql/time.cc:
  Bug#47925: Added microsecond comparison
2009-11-02 13:24:07 +01:00
Igor Babaev
914f33f2ca Fixed a bug in the code of the patch for WL#24 that manifested
itself when running the pbxt.group_min_max test leading to
wrong result sets and execution plans for many test cases.
When evaluating the index merge scans the code ignored the following:
if an index merge contains a range tree, such that none of its
SEL_ARG trees represents index ranges, then the index merge must be
discarded as not usable for any index merge retrieval.
2009-10-29 17:36:35 -07:00
Igor Babaev
27191a30c0 Replaced a lame implementation of the function sel_trees_must_be_ored
that blocked building index merge plans for the queries with where
conditions of the form 
(key1|2_p1=c AND range(key1_p2)) OR (key1|2_p1=c AND range(key2_p2)).

The problem was discovered by Sergey Petrunia when he reviewed the patch
for WL#24.

Added new test cases. One of them failed to produce an index merge plan
before the patch was applied.
2009-10-29 11:49:58 -07:00
Ramil Kalimullin
1339fb17fe Auto-merge. 2009-10-23 23:37:57 +05:00
Ramil Kalimullin
b7ce2a01bc Fix for bug#48258: Assertion failed when using a spatial index
Problem: involving a spatial index for "non-spatial" queries
(that don't containt MBRXXX() functions) may lead to failed assert.

Fix: don't use spatial indexes in such cases.


mysql-test/r/gis-rtree.result:
  Fix for bug#48258: Assertion failed when using a spatial index
    - test result.
mysql-test/t/gis-rtree.test:
  Fix for bug#48258: Assertion failed when using a spatial index
    - test case.
sql/opt_range.cc:
  Fix for bug#48258: Assertion failed when using a spatial index
    - allow only spatial functions (MBRXXX) for itMBR keyparts.
2009-10-23 16:26:48 +05:00
Alexey Kopytov
f6868a4eb4 Bug #47123: Endless 100% CPU loop with STRAIGHT_JOIN
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. 

mysql-test/r/partition_pruning.result:
  Fixed a broken test case.
mysql-test/r/range.result:
  Added a test case for bug #47123.
mysql-test/r/subselect.result:
  Fixed a broken test cases.
mysql-test/t/range.test:
  Added a test case for bug #47123.
sql/opt_range.cc:
  Fixed 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.
2009-10-17 00:19:51 +04:00
Georgi Kodinov
d80e35f26f Revert the fix for bug #47123 until test suite failures are resolved. 2009-10-16 11:42:16 +03:00
unknown
6aad537a6a Merge MySQL 5.1.39 into MariaDB 5.1. 2009-10-15 23:38:29 +02:00