Commit graph

28076 commits

Author SHA1 Message Date
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
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
unknown
445fcaa81a MWL#68 efficient partial matching
- Added an initial set of feature-specific test cases
- Handled the special case where the materialized subquery of an
  IN predicates consists of only NULL values.
- Fixed a bug where making Item_in_subselect a constant,
  didn't respect its null_value value.
2011-07-15 00:23:57 +03:00
Sergey Petrunya
932d516656 Merge 2011-07-14 20:06:46 +04:00
Sergey Petrunya
2a9c86be26 BUG#778434 Wrong result with in_to_exists=on in maria-5.3-mwl89
- Make {ha_myisam,ha_maria}::index_read_idx_map check pushed index condition.
- Address review feedback (added comments)
2011-07-14 17:44:37 +04:00
unknown
53681ee5db Fix bug lp:777691
Analysis:

For some of the re-executions of the correlated subquery the
where clause is false. In these cases the execution of the
subquery detects that it must generate a NULL row because of
implicit grouping. In this case the subquery execution reaches
the following code in do_select():

        while ((table= li++))
          mark_as_null_row(table->table);

This code marks all rows in the table as complete NULL rows.
In the example, when evaluating the field t2.f10 for the second
row, all bits of Field::null_ptr[0] are set by the previous call
to mark_as_null_row(). Then the call to Field::is_null()
returns true, resulting in a NULL for the MAX function.

Thus the lines above are not suitable for subquery re-execution
because mark_as_null_row() changes the NULL bits of each table
field, and there is no logic to restore these fields.

Solution:

The call to mark_as_null_row() was added by the fix for bug
lp:613029. Therefore removing the fix for lp:613029 corrects
this wrong result. At the same time the test for lp:613029
behaves correctly because the changes of MWL#89 result in a
different execution path where:
- the constant subquery is evaluated via JOIN::exec_const_cond
- detecting that it has an empty result triggers the branch
  if (zero_result_cause)
    return_zero_rows()
- return_zero_rows() calls mark_as_null_row().
2011-07-14 12:53:00 +03:00
unknown
c4097382ef Automatic merge. 2011-07-14 10:22:18 +03:00
Igor Babaev
b1a177e438 Merge. 2011-07-13 22:19:32 -07:00
Igor Babaev
ff9c406c1d Fixed LP bug #809179.
The attribute not_null_tables could be calculated incorrectly in the
function SELECT_LEX::update_used_tables for queries over views 
with row items in the WHERE clause. It happened because no 
implementation of the virtual callback function eval_not_null_tables
was provided for the class Item_row.
Also slightly optimized the code calculating the value of the maybe_null
flag for tables in the function SELECT_LEX::update_used_tables.
2011-07-13 21:06:28 -07:00
Igor Babaev
70455c517b Corrected the patch for bug 809206 to fix valgrind failures. 2011-07-13 20:00:28 -07:00
Sergey Petrunya
85571ea76c Disable LooseScan and FirstMatch when outer joins are present. 2011-07-14 01:53:05 +04:00
unknown
1e6bd6b4df Fix bug lp:809266
Analysis:
This is a bug in MWL#68, where it was incorrectly assumed
that if there is a match in the only non-null key, then
if there is a covering NULL row on all remaining NULL-able
columns there is a partial match. However, this is not the case,
because even if there is such a null-only sub-row, it is not
guaranteed to be part of the matched sub-row. The matched sub-row
and the NULL-only sub-row may be parts of different rows.

In fact there are two cases:
- there is a complete row with only NULL values, and
- all nullable columns contain only NULL values.

These two cases were incorrectly mixed up in the class member
  subselect_partial_match_engine::covering_null_row_width.


Solution:
The solution is to:
- split covering_null_row_width into two members:
  has_covering_null_row, and has_covering_null_columns, and
- take into account each state during initialization and
  execution.
2011-07-14 00:15:07 +03:00
Igor Babaev
7c46dc525e Merge. 2011-07-13 12:14:35 -07:00
Igor Babaev
102fb4e0b8 Corrected the code of the recent patch that had changed the base
class for Item_func_xor. Added the implementation of the
subst_argument_checker virtual method that the objects of this 
class used to use before the patch.
Reverted the previous result changes in sunselect_sj and
subselect_sj_jcl6.
2011-07-13 11:05:33 -07:00
unknown
61eb3423b4 Merged the fix for bug lp:608744 2011-07-13 17:11:46 +03:00
unknown
990584d73a Fixed bug lp:809245
In addition to the bug fix explained below, the patch performs
few renames, and adds some comments to avoid similar problems.

Analysis:
The failed assert was due to a bug in MWL#68, where it was
incorrectly assumed that the size of the bitmap
subselect_rowid_merge_engine::null_only_columns should be
the same as the size of the array of Ordered_keys.

The bitmap null_only_columns contains bits to mark columns
that contain only NULLs. Therefore the indexes of the bits
to be set in null_only_columns are different from the indexes
of the Ordered_keys. If there is a NULL-only column that appears
in a table after the last partial match column with Ordered_key,
this NULL-only column would require setting a bit with index
bigger than the size of the bitmap null_only_columns.

Accessing such a bit caused the failed assert.

Solution:
Upon analysis, it turns out that null_only_columns is not needed
at all, because we are looking for partial matches, and having
such columns guarantees that there is a partial match for any
corresponding outer value.

Therefore the patch removes
  subselect_rowid_merge_engine::null_only_columns.
2011-07-13 17:09:09 +03:00
Igor Babaev
5819dfcdf6 Fixed LP bug #809206.
The bitmap of used tables must be evaluated for the select list of every
materialized derived table / view and saved in a dedicated field.
This is also applied to materialized subqueries.
2011-07-12 23:47:35 -07:00
Sergey Petrunya
419c20f10a Merge 2011-07-12 13:02:19 +04:00
Igor Babaev
6e5413853e Merge with the latest 5.3 code. 2011-07-11 14:00:44 -07:00
Sergey Petrunya
2c28412e2e Port of code for: (part of testcase is in mysql-test/t/subquery*.test and will be ported separately)
Bug#11766642: crash in Item_field::register_field_in_read_map 
              with view

(Former 59793)

Prior to the refactoring in this patch, Item_cond_xor behaved 
partially as an Item_cond and partially as an Item_func. The
reasoning behind this was that XOR is currently not optimized
(thus should be Item_func instead of Item_cond), but it was 
planned optimize it in the future (thus, made Item_cond anyway 
to ease optimization later). 

Even though Item_cond inherits from Item_func, there are 
differences between these two. One difference is that the 
arguments are stored differently. Item_cond stores them in a 
list while Item_func store them in an args[]. 

BUG no 45221 was caused by Item_cond_xor storing arguments in 
the list while users of the objects would look for them in 
args[]. The fix back then was to store the arguments in both 
locations.

In this bug, Item_cond_xor initially gets two Item_field 
arguments. These are stored in the list inherited from 
Item_cond and in args[] inherited from Item_func. During
resolution, find_field_in_view() replaces the Item_fields 
stored in the list with Item_direct_view_refs, but args[] 
still points to the unresolved Item_fields. This shows that 
the fix for 45221 was incorrect.

The refactoring performed in this patch removes the confusion
by making the XOR item an Item_func period. A neg_transformer() 
is also implemented for Item_func_xor to improve performance 
when negating XOR expressions. An XOR is negated by negating 
one of the operands.
2011-07-11 23:48:35 +04:00
Igor Babaev
47aee19827 Fixed LP bug #793386.
Auto-generated names for view field items must be allocated in
the statement memory, not in the execution memory of the statement.
2011-07-11 10:56:48 -07:00
Sergey Petrunya
62cc4df4d3 Alternate version of MySQL's fix for BUG#49453.
The cause of the crash is sj_nest->sj_subq_pred->unit->first_select()->item_list
contains "stale" items for the second execution. By "stale" I mean that they have
item->fixed==FALSE, and they are Item_field object instead of Item_direct_view_ref.

The solution is to use sj_nest->sj_subq_pred->unit->first_select()->ref_pointer_array.
Surprisingly, that array contains items that are ok.

Oracle team has introduced and is using NESTED_JOIN::sj_inner_exprs, but we go without that
and always copy the ref_pointer_array.
2011-07-11 17:13:16 +04:00
Igor Babaev
f8db35bd15 Fixed LP bug #806504.
Missing initialization of the bitmap not_null_tables_cache to 0 
in the function Item_func::eval_not_null_tables caused this bug.
This function is called indirectly from the function
SELECT_LEX::update_used_tables after merging mergeable views and
derived tables into the main query. The leaf tables of resulting
query may change their bitmap numbers after this merge. That's why
the not_null_tables_cache bitmaps must be updated. Due to the bug 
mentioned above the result of the re-evaluation of the 
not_null_tables_cache turned out to be incorrect in some cases.
This could trigger an invalid conversion of outer joins into 
inner joins leading to invalid query result sets.

Also removed an implicit conversion from int to bool in the function
SELECT_LEX::update_used_tables.
2011-07-10 17:19:45 -07:00
Igor Babaev
a515802c5b Fixed LP bug #806097.
The value of THD::used tables should be re-evaluated after merges
of views and derived tables into the main query. 
Now it's done in the function SELECT_LEX::update_used_tables.
The re-evaluation of the 'used_table' bitmaps for the items
in HAVING, GROUP BY and ORDER BY clauses has been added as well.
2011-07-09 22:34:56 -07:00
Sergey Petrunya
9e7495df83 Semi-join fixes: make COST_VECT objects survive add_io(add_io_cnt=0, add_avg_cost=...) calls without
getting NaN in internal fields.
2011-07-09 16:33:40 +04:00
Sergey Petrunya
0ce603ab5e [No BUG#] Fixes for problems discovered when running mysql-trunk's subquery testsuite 2011-07-09 13:47:41 +04:00
Sergey Petrunya
a4f5e01475 Merge @@optimizer_switch default settings changes into 5.3 2011-07-09 11:20:15 +04:00
Igor Babaev
5ead4083ec Fixed LP bug #806510.
The bug was caused by an incorrect code of the function
Item_direct_view_ref::replace_equal_field introduced in the
patch for bugs 717577, 724942. The function erroneously
returned the wrapped field instead of the Item_direct_view_ref
object itself in the cases when no replacement happened.

The bug masked two other minor bugs that could result in not
quite correct output of the EXPLAIN command for some queries.
They were fixed in the patch as well.
2011-07-08 16:39:28 -07:00
Sergey Petrunya
41c766f30d Make table_elimination=on|off flag to be always present in @@optimizer_switch. 2011-07-08 19:09:30 +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
Igor Babaev
f222a51340 Merge. 2011-07-07 13:06:40 -07:00
Igor Babaev
e55e78eeda Fixed LP bug #806477.
The offending query returns a wrong result set because the optimizer
erroneously eliminated the where condition evaluated it to TRUE.
The cause of this wrong transformation was that the flag maybe_null
for an inner table of the outer join was not set to TRUE after the 
table had replaced the wrapping view.
Now the function SELECT_LEX::update_used_tables resets the value
of the maybe_null flag for each leaf table of the query after all
merges of views have been done.
2011-07-07 13:04:48 -07:00
unknown
4128ec4852 Fix bug lp:806943
Analysis:
This bug is yet another incarnation of the generic problem
where optimization of the outer query triggers evaluation
of a subquery, and this evaluation performs a destructive
change to the subquery plan. Specifically a temp table is
created for the DISTINCT operation that replaces the
original subquery table. Later, select_describe() attempts
to print the table name, however, there is no corresponding
TABLE_LIST object to the internal temp table, so we get a
crash. Execution works fine because it is not interested in
the corresponding TABLE_LIST object (or its name).

Solution:
Similar to other such bugs, block the evaluation of expensive
Items in convert_const_to_int().
2011-07-07 16:28:26 +03:00
Igor Babaev
b79316f583 Fixed LP bug #806431.
The function generate_derived_keys_for_table incorrectly handled
the cases when a materialized view or derived table could be accessed
by different keys on the same fields if these keys depended on the
same tables.
2011-07-06 17:24:42 -07:00
unknown
db36ce1de0 Merge the fix for bug lp:802979 2011-07-06 17:27:38 +03:00
Sergey Petrunya
271d9c21e6 Merge fix for BUG#611704 2011-07-06 10:30:51 +04:00
Sergey Petrunya
a5a8683f70 # BUG#611704: Crash in replace_where_subcondition with nested subquery and semijoin=on
- SELECT_LEX::merge_subquery should not set "(*in_subq)->emb_on_expr_nest= derived" for subqueries that 
  are in the ON expressions of semi-joins.
2011-07-06 10:21:31 +04:00
Vladislav Vaintroub
b792411a7a fix compile warnings 2011-07-05 22:38:38 +02:00
Vladislav Vaintroub
f9cb1467b8 merge Windows performance patches into 5.3 2011-07-05 21:46:53 +02:00
Sergey Petrunya
9e95a54793 Merge fix for BUG#803365 2011-07-05 21:48:50 +04:00
Sergey Petrunya
05d54b121c BUG#803365: Crash in pull_out_semijoin_tables with outer join + semijoin + derived tables in maria-5.3 with WL#106
- Don't perform table pullout out of semi-join nests that have nested outer joins.
2011-07-05 21:22:13 +04:00
Sergey Petrunya
c1de6f8b77 Change the default @@optimizer_switch setting from
semijoin=on,firstmatch=on,loosescan=on
to
  semijoin=off,firstmatch=off,loosescan=off
Adjust the testcases:
- Modify subselect*.test and join_cache.test so that all tests
  use the same execution paths as before (i.e. optimizations that
  are being tested are enabled)
- Let all other test files run with the new default settings (i.e.
  with new optimizations disabled)
- Copy subquery testcases from these files into t/subselect_extra.test
  which will run them with new optimizations enabled.
2011-07-05 01:44:15 +04:00
unknown
59784abead Fix LP bug lp:802979
Analysis:
This bug consists of two related problems that are
result of too early evaluation of single-row subqueries
during the optimization phase of the outer query.

Several optimizer code paths try to evaluate single-row
subqueries in order to produce a constant and use that
constant for further optimzation.

When the execution of the subquery peforms destructive
changes to the representation of the subquery, and these
changes are not anticipated by the subsequent optimization
phases of the outer query, we tipically get a crash or
failed assert.

Specifically, in this bug the inner-most suqbuery with
DISTINCT triggers a substitution of the original JOIN
object by a single-table JOIN object with a temp table
needed to perform the DISTINCT operation (created by
JOIN::make_simple_join).

This substitution breaks EXPLAIN because:
a) in the first example JOIN::cleanup no longer can
reach the original table of the innermost subquery, and
close all indexes, and
b) in this second test query, EXPLAIN attempts to print
the name of the internal temp table, and crashes because
the temp table has no name (NULL pointer instead).

Solution:
a) fully disable subquery evaluation during optimization
in all cases - both for constant propagation and range
optimization, and
b) change JOIN::join_free() to perform cleanup irrespective
of EXPLAIN or not.
2011-07-04 14:51:16 +03:00
Igor Babaev
3f7d51d0d8 Fixed LP bug #804686.
The assert conditions in the functions Item_direct_ref_to_ident::transform
and Item_direct_ref_to_ident::compile could be not valid after constant
propagation when fields and field references may be substituted for constants.
Not only these invalid asserts have been removed, but the functions containing
them have been removed as well because now Item_ref::transform and 
Item_ref::compile can be used instead of them.
2011-07-03 14:59:01 -07:00
Igor Babaev
006dedf537 Fixed LP bug #804515.
If no index is used to access a materialized derived table or view
then the value of TABLE_REF::key for this table must be (-1).
2011-07-01 21:53:47 -07:00