Commit graph

67330 commits

Author SHA1 Message Date
Sergey Petrunya
419c20f10a Merge 2011-07-12 13:02:19 +04: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
Vladislav Vaintroub
7ff45c1379 merge 2011-07-10 13:41:30 +02:00
Vladislav Vaintroub
46465327e7 merge 2011-07-10 13:39:37 +02:00
Vladislav Vaintroub
03b4c3bcde merge 2011-07-10 13:18:05 +02:00
Vladislav Vaintroub
066fb9d289 merge 2011-07-10 13:01:00 +02:00
Vladislav Vaintroub
3b393c929b Fix LPBUG#808233 - undefined uint in typelib.h 2011-07-10 12:48:13 +02: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
ae7ed5adf2 Merge. 2011-07-08 16:42:59 -07: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
834bdfa1c8 Update test results for previous csets. 2011-07-08 22:01:02 +04: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
2d325b3cc2 Forgot to add these two files when setting semijoin=off by default:
- Scavenged subquery tests from testcases other than t/subselect*.test and put them into single file
2011-07-08 18:49:53 +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
unknown
d43063939c Merge test cases for bugs that were fixed by MWL#89. 2011-07-08 10:56:46 +03:00
unknown
e98aecc2e0 Test for bug lp:611382
The bug itself has been fixed by MWL#89.
2011-07-08 10:51:53 +03:00
unknown
57432d0c64 Test case for bug lp:611396
The bug itself has been fixed by MWL#89.
2011-07-08 08:52:30 +03: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
0f36ab3a52 Test for bug lp:612543
The bug itself has been fixed by MWL#89.
2011-07-07 17:22:28 +03:00
unknown
5f5cbf7684 Test case for bug lp:611690
The bug itself has been fixed by MWL#89.
2011-07-07 17:07:13 +03: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
801a4ebca9 Merge. 2011-07-06 17:26:01 -07: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
4fadcc2bb4 Bug lp:802979
Adjust PBXT test results.
2011-07-06 21:32:07 +03: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
unknown
d93b4c5394 MWL#163 lp:798213: Remove the --innodb-release-locks-early feature.
The bug lp:798213 exposes a design flaw in --innodb-release-locks-early.
It does not work with InnoDB crash recovery, so it breaks transactional
integrety. So remove the feature.
2011-07-05 15:28:15 +02:00
Sergey Petrunya
371d514fdb Update test results for the previous cset. 2011-07-05 10:32:49 +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
Igor Babaev
3984062ba4 Merge. 2011-07-04 11:02:35 -07:00
Michael Widenius
c9e969b62d Automatic merge 2011-07-04 17:27:46 +03: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
Michael Widenius
7199ac5916 Aria fixes:
- Fixed multi-user problem with one thread doing inserts and another doing scans that gave error 175
- Fixed bug that caused assert in move_to_next_bitmap() & _ma_read_bitmap_page()
- Much more DBUG_ASSERT(!maria_assert_if_crashed_table) to detect errors early
- EXTERNAL_LOCKING -> MARIA_EXTERNAL_LOCKING (to use same define everywhere

storage/maria/ma_bitmap.c:
  More secure handling of first_bitmap_with_space (now we also take care of wrong values)
  Don't set page to -1; This fixed unlikely bug that caused assert in move_to_next_bitmap() & _ma_read_bitmap_page()
storage/maria/ma_blockrec.c:
  More DBUG_ASSERT()'s
  Fixed multi-user problem with one thread doing inserts and another doing scans that gave error 175
  (We should use data_file_length from start of scan, not new value as new bitmap page may not yet be in page cache)
storage/maria/ma_check.c:
  EXTERNAL_LOCKING -> MARIA_EXTERNAL_LOCKING (to use same define everywhere)
storage/maria/ma_checkpoint.c:
  Made maria_checkpoint_min_activity static so that one can change it in debugger while testing.
  Fixed long standing performance problem that caused write of state info at checkpoint for any file that was ever changed since open.
storage/maria/ma_create.c:
  EXTERNAL_LOCKING -> MARIA_EXTERNAL_LOCKING (to use same define everywhere
storage/maria/ma_dynrec.c:
  Added missing MARIA_EXTERNAL_LOCKING (minor performance improvement)
storage/maria/ma_locking.c:
  EXTERNAL_LOCKING -> MARIA_EXTERNAL_LOCKING (to use same define everywhere
storage/maria/ma_open.c:
  EXTERNAL_LOCKING -> MARIA_EXTERNAL_LOCKING (to use same define everywhere
storage/maria/ma_pagecache.c:
  Added assert to detect reads outside of data file
storage/maria/maria_def.h:
  Added checkpoint_state to cache state writes in checkpoint
2011-07-04 04:32:53 +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
Michael Widenius
ec3c26a515 Fixed compilation & test issues found by buildbot
include/Makefile.am:
  Added missing \
mysql-test/mysql-test-run.pl:
  Suppress warning when ha_archive is not compiled
mysql-test/r/variables-big.result:
  Updated results
2011-07-02 17:37:59 +03: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
Michael Widenius
8318ef14af Automatic merge 2011-07-01 15:35:34 +03:00
Michael Widenius
e063e3fd60 Merge with 5.2 2011-07-01 15:16:10 +03:00