Commit graph

27772 commits

Author SHA1 Message Date
Igor Babaev
07e9d34c54 Added a test case for LP bug #823835 - a duplicate of bug 823189. 2011-08-11 22:34:41 -07:00
Igor Babaev
8b56830f7b Fixed LP bug #823189.
The method Item_ref::not_null_tables() returned incorrect bitmap
for outer references to view columns. This could cause an invalid
conversion of an outer join into an inner join that could lead
to a wrong result set for a query with a correlated subquery over
an outer join whose where condition had an outer reference to a view.
2011-08-11 20:24:32 -07:00
Igor Babaev
4ddea0cb93 Fixed LP bug #823826.
The method Item_func_isnull::update_used_tables() erroneously did not
update cached values stored in the fields used_tables_cache and
const_item_cache of the Item_func_isnull objects. As a result the
Item_func_isnull::used_tables() returned wrong bitmaps and, as a
consequence, push-down predicates could be attached to wrong tables.
2011-08-11 12:11:04 -07:00
unknown
209682577f Bug lp:781508: Take relevant test cases from MySQL 5.6 feature preview trees
Identified all test cases in the MySQL file subquery_mat.inc that are
not present in MariaDB. In total found 8 test cases for the following
MySQL bugs:
* BUG#49630 - not a bug in MariaDB, added test case
* BUG#52538 - not a bug in MariaDB, added test case (checked with VG)
* BUG#53103 - not a bug in MariaDB, added test case
* BUG#54511 - not a bug in MariaDB, added test case
* BUG#56367 - not a bug in MariaDB, added test case
* BUG#59833 - not a bug in MariaDB, added test case
* BUG#11852644 - not a bug in MariaDB, added test case
* BUG#12668294 - not a bug in MariaDB, added test case

All of these MySQL bugs are not present in MariaDB 5.3.

The comparison was based on the following version of
mysql-trunk:

revno: 3350 [merge]
committer: Marko Mäkelä <marko.makela@oracle.com>
branch nick: mysql-trunk
timestamp: Mon 2011-08-08 12:42:09 +0300
message:
  Merge mysql-5.5 to mysql-trunk.
2011-08-09 18:34:26 +03:00
unknown
a6037394e3 Fix bug lp:817384
This bug is a special case of lp:813447.

Analysis:
Constant optimization finds that the condition t2.a = 1
can be used to access the primary key of table 't2'. As
a result both outer table t1,t2 are considered as constant
when we reach the execution phase. At the same time, during
constant optimization, the IN predicate is not evaluated
because it is expensive.

When execution of the outer query reaches do_select(),
control flow enter the branch:
if (join->table_count == join->const_tables)
{ ... }
This branch checks only the WHERE and HAVING clauses,
but doesn't check the ON clauses of the query. Since the
IN predicate was not evaluated during optimization, it is
not evaluated at all, thus execution doesn't detect that
the ON clause is FALSE.

Solution:
Similar to the patch for bug lp:813447, exclude system
tables from constant substitution based on unique key
lookups if there is an expensive ON condition on the
inner table.
2011-08-09 10:28:57 +03:00
Igor Babaev
b7e9713ee3 Fixed LP bug #819716.
Do not optimize derived table for the second time ever.
2011-08-08 22:02:10 -07:00
Sergey Petrunya
0c459a016c Update test results for previous cset 2011-08-08 22:37:53 +04: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
unknown
21bfae660a Automerge 5.2->5.3 2011-08-01 11:05:30 +02:00
unknown
51c7723eb2 After-merge fix of result file (MARIA <-> Aria) 2011-08-01 10:56:24 +02:00
unknown
efcb48f23e Automerge 5.2->5.3 2011-07-31 22:59:55 +02:00
unknown
0b56ae29bf Automerge 5.1->5.2 2011-07-31 22:46:19 +02:00
unknown
47c23a1128 Speed up mysql-test-run.pl.
Problem was the parsing of test suite files for various tags and options.
This was done inefficiently, and include files were re-parsed for every
place they were included. This caused a delay of 20 seconds or so before
the first test started to run.

By parsing more efficiently and re-using first parse for subsequent
inclusion of the same file, time spent parsing is reduced to less than
1 second, and start appears instantaneous.

(With this patch, full ./mtr runs in 3 minutes on my laptop (release
build.)

mysql-test/suite/innodb_plugin/t/innodb_bug52663.test:
  Test is fairly slow, so try to avoid getting stuck with it at the end
  while other workers are idle.
2011-07-31 22:25:37 +02:00
Igor Babaev
103c4461ca Fixed LP bug #817360.
This problem could be observed for queries with nested outer joins
for which the not_exist optimization were applicable. 
The problem was caused by the code of the patch for bug #49322
that erroneously forced the return to the previous nested loop
level when the join algorithm successfully builds a partial record
for an embedded outer to which the not_exist optimization could be
applied.
Actually the immediate return to the previous nested loops level
is correct only if this partial record is rejected by a predicate
pushed down to one of the inner tables of this outer join. Otherwise
attempts to find extensions of this record must be made.
2011-07-29 17:09:16 -07:00
Michael Widenius
1d61f71384 Merge with 5.1
Fixed lp:814237: Wrong mutex usage in Aria


storage/maria/ma_bitmap.c:
  Added call to _ma_bitmap_mark_file_changed() when flushing bitmap. This fixes lp:814237
2011-07-25 21:52:15 -07:00
Michael Widenius
10065404ea Fixes lp:805930 Sysbench breaks on multiple table test with MariaDB 5.2.7 + Aria
The bug happens when one uses MAX_ROWS=# with Aria & row_format=page and one insert more than # rows.


mysql-test/mysql-test-run.pl:
  Ignore table is full error messages
mysql-test/suite/maria/r/max_length.result:
  Test case for 'Table is full'
mysql-test/suite/maria/t/max_length.test:
  Test case for 'Table is full'
storage/maria/ma_bitmap.c:
  Ensure that we don't allocate bits outside of max_data_file_size.
  Adjust max_data_file_size based on bitmap alignments.
  Backport fix to adjust wrong first_bitmap_with_space.
storage/maria/ma_blockrec.c:
  Calculate value of max_data_file_length
storage/maria/ma_blockrec.h:
  Updated prototype for _ma_bitmap_init()
storage/maria/ma_check.c:
  Give warnings if file sizes are above max file sizes.
  Give more warnings in case of errors.
  Have maria_chk write if table is recreated.
storage/maria/ma_create.c:
  Better calculation of max_data_file_length and thus data pointer length.
  Fixes some wrong pointer lengths when using MAX_ROWS=#
storage/maria/ma_open.c:
  Removed duplicate assigment.
  Use block size from file instead of global variable.
storage/maria/maria_chk.c:
  Remove -1 from printed file length
storage/maria/maria_def.h:
  Update struct st_maria_file_bitmap
2011-07-24 01:25:28 -07:00
Igor Babaev
668eb2b55e Removed settings of 'derived_merge' to 'on' in ps tests. 2011-07-22 23:47:28 -07:00
Igor Babaev
d117f51901 Fixed a crash with pbxt.subselect when 'derived_merge' is set off in
the optimizer switch.
2011-07-22 21:39:55 -07:00
Igor Babaev
2092436457 Merge. 2011-07-21 15:55:08 -07:00
Igor Babaev
63abf00a62 Made the optimizer switches 'derived_merge' and 'derived_with_keys'
off by default.
2011-07-21 14:23:08 -07:00
unknown
813aaac51d Fix for LP BUG#806071
In case of two views with subqueries it is dificult to decide about order of injected ORDER BY clauses.
A simple solution is just prohibit ORDER BY injection if there is other order by.

mysql-test/r/view.result:
  New test added, old test changed.
mysql-test/t/view.test:
  New test aded.
sql/share/errmsg.txt:
  new warning added.
sql/sql_view.cc:
  Inject ORDER BY only if there is no other one.
  
  Warning about ignoring ORDER BY in this case for EXPLAIN EXTENDED.
2011-07-21 23:37:40 +03:00
unknown
3c97c9c9cc test fix. 2011-07-21 18:32:44 +03:00
Sergey Petrunya
c86ffc23ee BUG#803457: Wrong result with semijoin + view + outer join in maria-5.3-subqueries-mwl90
- Correct handling of outer joins + DuplicateWeedout (docs pending)
2011-07-21 19:14:34 +04:00
unknown
ef2b4b14e1 Merge from 5.2 2011-07-21 15:50:25 +03:00
unknown
678f4b2de1 Test fix merge. 2011-07-21 15:21:22 +03:00
unknown
a11a2b242f Fixed PBXT test. 2011-07-21 15:14:16 +03:00
unknown
f675536aa4 Merge 5.1->5.2 2011-07-21 13:15:09 +03:00
unknown
ee06e4d65e Removed incorrect fix and its test suite (the test suit is duplicate).
Fixed explains of previous patch.

mysql-test/r/explain.result:
  Fixed explains of previous patch.
mysql-test/r/join_outer.result:
  Fixed explains of previous patch.
mysql-test/r/negation_elimination.result:
  Fixed explains of previous patch.
mysql-test/r/view.result:
  Fixed explains of previous patch.
mysql-test/suite/innodb/r/innodb_mysql.result:
  Removed duplicate test suite.
mysql-test/suite/innodb/t/innodb_mysql.test:
  Removed duplicate test suite.
mysql-test/suite/innodb_plugin/r/innodb_mysql.result:
  Removed duplicate test suite.
mysql-test/suite/innodb_plugin/t/innodb_mysql.test:
  Removed duplicate test suite.
sql/opt_range.h:
  Removed incorrect fix.
sql/records.cc:
  Removed incorrect fix.
2011-07-21 12:29:00 +03:00
unknown
20a2e1d0ac Fix of LP BUG#777809
There are 2 volatile condition constructions AND/OR constructions and fields(references) when first
good supported to be top elements of conditions because it is normal practice
(see copy_andor_structure for example) fields without any expression in the condition is really rare
and mostly useless case however it could lead to problems when optimiser changes/moves them unaware
of other variables referring to them. An easy solution of this problem is just to replace single field
in a condition with equivalent expression well supported by the server (<field> -> <field> != 0).

mysql-test/r/view.result:
  New test added.
mysql-test/t/view.test:
  New test added.
sql/sql_parse.cc:
  <field> -> <field> != 0
sql/sql_yacc.yy:
  <field> -> <field> != 0
2011-07-21 11:20:55 +03:00
Igor Babaev
4a03a1d777 Fixed LP bug #813447.
Do not make substitution of a single-row table if it is an inner
table of an outer join with on expression containing an expensive
subquery.
2011-07-21 00:43:37 -07:00
Igor Babaev
2e8542f462 Fixed LP bug #791761.
An aggregating query over an empty set of a join of two tables
with a rejecting HAVING clause erroneously could return a row.
It could happen in the cases when the optimizer made a conclusion
that the aggregating set was empty.
Wrong results were produced because the server missed initial
setting for aggregation functions in the mentioned cases.
2011-07-20 21:55:55 -07:00
Igor Babaev
6dc1cdc205 Merge. 2011-07-20 16:49:36 -07:00
Igor Babaev
57f4965f36 Fixed LP bug #702301.
The function matching_cond should take into account that
there may be always false constant conjunctive conditions
that has not been evaluated yet,for example, conjunctive
conditions with non-correlated subqueries.
2011-07-20 16:09:28 -07:00
Igor Babaev
5ab7adfcaf Adjusted the results of the pbxt.subselect test after the push
of the patch for bug 780386.
2011-07-20 16:02:26 -07:00
unknown
2b6a23447b Fix of LP BUG#780386.
ALL subquery should return TRUE if subquery rowa set is empty independently
of left part.  The problem was that Item_func_(eq,ne,gt,ge,lt,le) do not
call execution of second argument if first is NULL no in this case subquery
will not be executed and when Item_func_not_all calls any_value() of the
subquery or aggregation function which report that there was rows. So for
NULL < ALL (SELECT...) result was FALSE instead of TRUE.

Fix is just swapping of arguments of Item_func_(eq,ne,gt,ge,lt,le) (with
changing the operation if it is needed) so that result will be the same
(for examole a < b is equal to b > a). This fix exploit the fact that
first argument will be executed in any case.

mysql-test/r/subselect.result:
  The test suite added.
mysql-test/r/subselect_no_mat.result:
  The test suite added.
mysql-test/r/subselect_no_opts.result:
  The test suite added.
mysql-test/r/subselect_no_semijoin.result:
  The test suite added.
mysql-test/r/subselect_scache.result:
  The test suite added.
mysql-test/t/subselect.test:
  The test suite added.
sql/item_cmpfunc.cc:
  Swap arguments creation methods added.
sql/item_cmpfunc.h:
  Swap arguments creation methods added.
sql/item_subselect.cc:
  Swap arguments of the comparison.
2011-07-20 21:48:41 +03:00
Sergey Petrunya
837c6722ed Merge fix for BUG##806524 2011-07-20 11:21:30 +04:00
Sergey Petrunya
b11eff4025 BUG##806524: Assertion `join->best_read < 1.7976931348623157e+308 with table_elimination=on and derived_merge=on
reset_nj_counters() used to rely on the fact that join nests have 
table->table==NULL. This ceased to be true wit new derived table
optimizations. Use test for table->nested_join!=NULL instead.
2011-07-20 01:31:40 +04:00
unknown
99cce18955 Fixed LP BUG#800696.
The problem was that optimizer removes some outer references (it they are
constant for example) and the list of outer items built during prepare phase is
not actual during execution phase when we need it as the cache parameters.
First solution was use pointer on pointer on outer reference Item and
initialize temporary table on demand. This solved most problem except case
when optimiser also reduce Item which contains outer references ('OR' in
this bug test suite).

The solution is to build the list of outer reference items on execution
phase (after optimization) on demand (just before temporary table creation)
by walking Item tree and finding outer references among Item_ident
(Item_field/Item_ref) and Item_sum items.

Removed depends_on list (because it is not neede any mnore for the cache, in the place where it was used it replaced with upper_refs).

Added processor (collect_outer_ref_processor) and get_cache_parameters() methods to collect outer references (or other expression parameters in future).

mysql-test/r/subselect_cache.result:
  A new test added.
mysql-test/r/subselect_scache.result:
  Changes in creating the cache and its paremeters order or adding arguments of aggregate function (which is a parameter also, but this has no influence on the result).
mysql-test/t/subselect_cache.test:
  Added a new test.
sql/item.cc:
  depends_on removed.
  
  Added processor (collect_outer_ref_processor) and get_cache_parameters() methods to collect outer references.
  
  Item_cache_wrapper collect parameters befor initialization of its cache.
sql/item.h:
  depends_on removed.
  
  Added processor (collect_outer_ref_processor) and get_cache_parameters() methods to collect outer references.
sql/item_cmpfunc.cc:
  depends_on removed.
  
  Added processor (collect_outer_ref_processor) to collect outer references.
sql/item_cmpfunc.h:
  Added processor (collect_outer_ref_processor) to collect outer references.
sql/item_subselect.cc:
  depends_on removed.
  Added processor get_cache_parameters() method to collect outer references.
sql/item_subselect.h:
  depends_on removed.
  Added processor get_cache_parameters() method to collect outer references.
sql/item_sum.cc:
  Added processor (collect_outer_ref_processor) method to collect outer references.
sql/item_sum.h:
  Added processor (collect_outer_ref_processor) and get_cache_parameters() methods to collect outer references.
sql/opt_range.cc:
  depends_on removed.
sql/sql_base.cc:
  depends_on removed.
sql/sql_class.h:
  New iterator added.
sql/sql_expression_cache.cc:
  Build of list of items resolved in outer query done just before creating expression cache on the first execution of the subquery which removes influence of optimizer removing items (all optimization already done).
sql/sql_expression_cache.h:
  Build of list of items resolved in outer query done just before creating expression cache on the first execution of the subquery which removes influence of optimizer removing items (all optimization already done).
sql/sql_lex.cc:
  depends_on removed.
sql/sql_lex.h:
  depends_on removed.
sql/sql_list.h:
  Added add_unique method to add only unique elements to the list.
sql/sql_select.cc:
  Support of new Item list added.
sql/sql_select.h:
  Support of new Item list added.
2011-07-19 23:19:10 +03:00
Sergey Petrunya
5df875b02b BUG#803303: Wrong result with semijoin=on, outer join in maria-5.3-subqueries-mwl90
- Add testcase.
2011-07-19 22:22:40 +04:00
Sergey Petrunya
775ac38dcd Buildbot fixes: add --sorted-result 2011-07-19 13:48:16 +04:00
Sergey Petrunya
265b51df73 Merge 2011-07-19 11:45:46 +04:00
Igor Babaev
cfc7896461 Merge. 2011-07-18 23:21:48 -07:00
unknown
c9e236828e Fix bug lp:782305
Analysis:
Both the wrong result and the valgrind warning were a result
of incomplete cleanup of the MIN/MAX subquery rewrite. At the
first execution of the query, the non-aggregate subquery is
transformed into an aggregate MIN/MAX subquery. During the
fix_fields phase of the MIN/MAX function, it sets the property
st_select_lex::with_sum_func to true.

The second execution of the query finds this flag to be ON.
When optimization reaches the same MIN/MAX subquery
transformation, it tests if the subquery is an aggregate or not.
Since select_lex->with_sum_func == true from the previous
execution, the transformation executes the second branch that
handles aggregate subqueries. This substitutes the subquery
Item into a Item_maxmin_subselect. At the same time elsewhere
it is assumed that the subquery Item is of type
Item_allany_subselect. Ultimately this results in casting the
actual object to the wrong class, and calling the wrong
any_value() method from empty_underlying_subquery().

Solution:
Cleanup the st_select_lex::with_sum_func property in the case
when the MIN/MAX transformation was performed for a non-aggregate
subquery, so that the transformation can be repeated.
2011-07-18 23:45:38 +03:00
Igor Babaev
a7287d9ae1 Fixed LP bug #793448.
This bug could lead to wrong result sets for a query over a
materialized derived table or view accessed by a multi-component
key.
It happened because the function get_next_field_for_derived_key
was supposed to update its argument, and it did not do it.
2011-07-17 23:12:31 -07:00
Igor Babaev
cc0195d6a1 Merge with the latest 5.3 code. 2011-07-17 00:52:07 -07:00
Igor Babaev
d37465a9cc Fixed LP bug #794901.
Also:
1. simplified the code of the function mysql_derived_merge_for_insert.
2. moved merge of views/dt for multi-update/delete to the prepare stage.
3. the list of the references to the candidates for semi-join now is
   allocated in the statement memory.
2011-07-16 23:57:43 -07:00
unknown
c1b6eb1490 Merge of subquery cache off by default. 2011-07-15 12:16:46 +03:00
unknown
af284b55f0 Make subquery cache off by default.
mysql-test/r/subselect_scache.result:
  Test with subquery cache on.
mysql-test/t/subselect_scache.test:
  Test with subquery cache on.
2011-07-15 11:36:36 +03:00
unknown
06fb641c0b Automatic merge. 2011-07-15 09:17:22 +03:00
Igor Babaev
03081bc1fd Changed the default setting of the optimizer switch 'optimize_join_buffer_size'.
Made it 'off' by default.
2011-07-14 22:24:59 -07:00