Commit graph

370 commits

Author SHA1 Message Date
Igor Babaev
704f97035f Merged the code of MWL#106 into 5.3
Resolved all conflicts, bad merges and fixed a few minor bugs in the code.
Commented out the queries from multi_update, view, subselect_sj, func_str,
derived_view, view_grant that failed either with crashes in ps-protocol or
with wrong results.
The failures are clear indications of some bugs in the code and these bugs
are to be fixed.
2011-05-16 22:39:43 -07:00
Oleksandr Byelkin
7b797fe66d Moving max/min optimization from prepare to optimization phase. MWL#148
mysql-test/r/explain.result:
  fixed results (new item)
mysql-test/r/subselect.result:
  fixed results (new item)
mysql-test/r/subselect_no_mat.result:
  fixed results (new item)
mysql-test/r/subselect_no_opts.result:
  fixed results (new item)
mysql-test/r/subselect_no_semijoin.result:
  Fixed results (new item)
mysql-test/suite/pbxt/r/subselect.result:
  Fixed results (new item)
mysql-test/t/explain.test:
  Fixed results (correct behaviour)
sql/item_cmpfunc.cc:
  Pass through  for max/min
sql/item_subselect.cc:
  moving max/min
sql/item_subselect.h:
  moving max/min
sql/mysql_priv.h:
  new uncacheble flags added
sql/opt_subselect.cc:
  maxmin moved.
sql/opt_subselect.h:
  New function for maxmin.
sql/sql_class.h:
  debug code
sql/sql_lex.cc:
  Fixed flags.
  Limit setting fixed.
sql/sql_lex.h:
  2 new flags.
sql/sql_select.cc:
  Prepare divided on 2 function to be able recollect some info after transformation.
sql/sql_select.h:
  Prepare divided on 2 functions.
2011-05-04 18:08:58 +03:00
unknown
5dc11616b2 MWL#89
Merge with 5.3
2011-05-02 21:59:16 +03:00
Sergey Petrunya
acc161d363 BUG#752992: Wrong results for a subquery with 'semijoin=on'
- Let advance_sj_state() save the value of JOIN::cur_dups_producing_tables
  in POSITION::prefix_dups_producing_tables, and restore_sj_state() restore
  it.
2011-04-08 02:12:03 +04:00
unknown
3d8aa98c71 MWL#89
Merge 5.3 with 5.3-mwl89.
2011-03-30 11:38:57 +03:00
unknown
952556b345 MWL#89
Merge 5.3 with 5.3-mwl89.
2011-03-30 10:10:59 +03:00
unknown
6902770869 Merge the fix for LP BUG#613029. 2011-03-30 00:48:35 +03:00
unknown
7999f40a99 Fix LP BUG#613029
Analysis:
There are two code paths through which JOIN::exec may produce
an all-NULL row for an empty result set. One goes via the
function return_zero_rows(), when query processing detectes
early that the where clause is false, the other one is via
do_select() in the case of join execution.

In the case of do_select(), the problem was that the executioner
didn't set TABLE::null_row to 1. As result when sending the only
result row, the evaluation of each field didn't detect that all
non-aggregated fields are NULL, because Field::is_null returned
true, after checking that field->table->null_row was false.

Given that the each non-aggregated field was not considered NULL,
select_result::send_data sent whatever was in the buffer of each
field. However, since there was no actual data in the field buffer,
send_data() accessed and sent whatever junk was in the field's
data buffer.

Solution:
Similar to the analogous case in return_zero_rows() mark all
tables that their current row is NULL before sending the
artificailly created NULL row.
2011-03-28 12:55:36 +03:00
Sergey Petrunya
201fb06db9 Merge in fix for BUG#727667 2011-03-25 12:47:44 +03:00
Sergey Petrunya
0fe8c972c6 BUG#727667 Wrong result with OR + NOT NULL in maria-5.3
- Address review feedback: introduce NO_REF_PART symbolic name, better comments
2011-03-25 12:43:32 +03:00
Igor Babaev
edc69e3227 Merge 2011-03-13 03:50:14 -07:00
Michael Widenius
139a2b64bf Merge with 5.2 2011-03-09 15:47:59 +02:00
Igor Babaev
3d3d5f1d43 Fixed LP bug #729039.
If join condition is of the form <t2.key>=<t1.no_key> then the server
performs no index look-ups when looking for matching rows of t2 for
the rows from t1 with t1.no_key=NULL. It happens because the function
add_not_null_conds() injects an additional condition of the form 
IS NOT NULL(<t1.no_key>) into the WHERE condition.
However if the join condition was of the form <t.key>=<outer_ref> no
additional null rejecting predicate was generated. This could lead
to extra records in the result set if the value of <outer_ref> happened
to be NULL.
The new code injects null rejecting predicates of the form 
IS NOT NULL(<outer_ref>) and evaluates them before the first row
the subquery is constructed.
2011-03-07 22:09:21 -08:00
Sergey Petrunya
76165dc760 BUG#727667 Wrong result with OR + NOT NULL in maria-5.3
- put the code that sets HA_NULL_PART bit back
- Fix test_if_ref/part_of_refkey() so that 
  = NULL-ability of lookup columns does not prevent the equality 
    from being removed (we now have early/late NULLs filtering which 
    will filter out NULL values)
  = equality is not removed if it is ref_or_null access, and the value 
    of the lookup column can alternate between the lookup value and NULL.
2011-03-05 12:56:22 +03:00
unknown
71e9d94895 MWL#89
Merge 5.3 into 5.3-mwl89.
2011-03-01 15:54:21 +02:00
unknown
7895c35874 MWL#89
Merge MWL#89 with 5.3.
2011-03-01 14:16:28 +02:00
Igor Babaev
272e5e6212 BNLH algorithm always used a full table scan over the joined table
even in the cases when there existed range/index-merge scans that
were cheaper than the full table scan.
This was a defect/bug of the implementation of mwl #128. 
Now hash join can work not only with full table scan of the joined
table, but also with full index scan, range and index-merge scans.
Accordingly, in the cases when hash join is used the column 'type'
in the EXPLAINs can contain now 'hash_ALL', 'hash_index', 'hash_range'
and 'hash_index_merge'. If hash join is coupled with a range/index_merge
scan then the columns 'key' and 'key_len' contain info not only on
the used hash index, but also on the indexes used for the scan.
2011-02-23 22:23:12 -08:00
Michael Widenius
58bb0769bd Merge with MySQL 5.1.55
- Fixed some issues with partitions and connection_string, which also fixed lp:716890 "Pre- and post-recovery crash in Aria"
- Fixed wrong assert in Aria

Now need to merge with latest xtradb before pushing 

sql/ha_partition.cc:
  Ensure that m_ordered_rec_buffer is not freed before close.
sql/mysqld.cc:
  Changed to use opt_stack_trace instead of opt_pstack.
  Removed references to pstack
sql/partition_element.h:
  Ensure that connect_string is initialized
storage/maria/ma_key_recover.c:
  Fixed wrong assert
2011-02-20 18:51:43 +02:00
Igor Babaev
9ea80ac481 Merge 2011-01-28 18:54:30 -08:00
Igor Babaev
a624f99e98 Fixed LP bug #707555.
The bug was in the code of the patch fixing bug 698882.
With improper casting the method store_key_field::change_source_field
was called for the elements of the array TABLE_REF::key_copy that
were either of a different type or not allocated at all. This caused
crashes in some queries.
2011-01-26 11:30:29 -08:00
Igor Babaev
ec368ab9fa Merge 2011-01-21 22:48:28 -08:00
Igor Babaev
0f46efcba6 Post-review fixes for the patch that added the code allowing to use
hash join over equi-join conditions without supporting indexes.
2011-01-21 18:21:55 -08:00
Igor Babaev
84a0c9b2a2 Fixed LP bug #698882.
Made sure that the optimal fields are used by TABLE_REF objects
when building index access keys to joined tables.
Fixed a bug in the template function that sorts the elements of
a list using the bubble sort algorithm. The bug caused poor
performance of the function. Also added an optimization that
skips comparison with the most heavy elements that has been 
already properly placed in the list.
Made the comparison of the fields belonging to the same Item_equal
more granular: fields belonging to the same table are also ordered
according to some rules.
2011-01-15 11:14:36 -08:00
unknown
b0be3e2c68 Merge MWL#89 into 5.3 main. 2011-01-11 14:04:08 +02:00
Igor Babaev
af800fd92f The patch adds the code that allows to use equi-join conditions
for hash join in the cases when there are no suitable indexes
for these conditions.
2011-01-04 21:59:41 -08:00
Kent Boortz
4acfdb9df1 Merge 2010-12-29 00:47:05 +01:00
Kent Boortz
85323eda8a - Added/updated copyright headers
- Removed files specific to compiling on OS/2
- Removed files specific to SCO Unix packaging
- Removed "libmysqld/copyright", text is included in documentation
- Removed LaTeX headers for NDB Doxygen documentation
- Removed obsolete NDB files
- Removed "mkisofs" binaries
- Removed the "cvs2cl.pl" script
- Changed a few GPL texts to use "program" instead of "library"
2010-12-28 19:57:23 +01:00
unknown
2e42948ed3 MWL#89
- Post-review fixes. Intermediate commit to address review point 1.6.
- Fixed valgrind warnings
2010-12-23 17:33:00 +02:00
unknown
0bee625fea MWL#89
Post-review fixes. Intermediate commit to address
review points 1.1, 1.2, 1.3, 1.4, 1.5, and 3.1, 3.2, 3.3.
2010-12-15 12:54:25 +02:00
Igor Babaev
7f52af655a Merge. 2010-12-10 23:23:34 -08:00
unknown
fd24b33b57 Merge the fix for LP BUG#682683. 2010-12-10 13:10:11 +02:00
unknown
be95cde859 Merge 5.3-mwl89 into 5.3. 2010-12-03 15:37:54 +02:00
unknown
620aea4fde Fix LP BUG#682683
Analysis:
The fix for LP BUG#680846 avoids evaluation of constant expressions
with subqueries in the GROUP/ORDER clauses in the procedure
remove_const(). The purpose of remove_const is to remove constant
expressions in the GROUP/ORDER clauses.
  
In order delay until execution the evaluation of such subqueries,
they were not removed in the GROUP/ORDER clause. As a result temp
table creation during execution attempted to create a column in the
temp table for each constant GROUP/ORDER expression. However, the
logic in create_tmp_table is to not create temp table columns for
constant items. The crash was due to a group Item without a
corresponding column in the temp table for GROUP BY.
  
Solution:
The patch adds back removal of constant expressions with subqueries.
In order for such expressions to be evaluated, so that the server can
ensure that such subquries return 1 row, the evaluation of these
expressions is delayed until execution.
2010-12-02 21:54:40 +02:00
Igor Babaev
4e05898f53 Got the declarations related to the class JOIN_CACHE, its derivatives and
companions out of sql_select.h into a separate file sql_join_cache.h.
2010-11-19 11:03:03 -08:00
unknown
bd5c45dc7a Fix for LP BUG#676411 and MySQL BUG#52317
This is a backport of the fix for
MySQL BUG#52317: Assertion failing in Field_varstring::store () at field.cc:6833

The orginal comment by Oystein is:

In order for EXPLAIN to print const-refs, a Store_key_const_item object
is created. This is different for normal execution of subqueries where
a temporary store_key_item object is used instead. The problem is that
EXPLAIN will execute subqueries.  This leads to a scenario where a
store_key_const_item object it told to write to its underlying field.
This results in a failing assert since the write set of the underlying
table does not reflect this.  

The resolution is to do the same trick as for store_key_item::copy_inner().
That is, temporarily change the write set to allow writes to all columns.
This is only necessary in debug version since non-debug version does not
contain asserts on write_set.

sql/sql_select.h:
  Temporarily change write_set in store_key_const_item::copy_inner() to
  allow initialization of underlying field.  This is necessary since 
  subqueries are executed for EXPLAIN.  (For normal execution, 
  store_key_item::copy_inner is used.)
2010-11-19 17:01:48 +02:00
Igor Babaev
0a3922fca8 Fixed LP #bug 660963.
The condition that was supposed to check whether a join table
is an inner table of a nested outer join or semi-join was not
quite correct in the code of the function check_join_cache_usage.
That's why some queries with nested outer joins triggered 
an assertion failure.
Encapsulated this condition in the new method called
JOIN_TAB::is_nested_inner and provided a proper code for it.

Also corrected a bug in the code of check_join_cache_usage()
that caused a downgrade of not first join buffers of the
level 5 and 7 to level 4 and 6 correspondingly.
2010-11-19 06:20:28 -08:00
unknown
de35f1437a Fixed LP BUG#641203: Query returns rows where no result is expected (impossible WHERE)
The cause for the bug was two-fold:
1. Incorrect detection of whether a table is the first one in a query plan -
  "used_table & 1" actually checks if used_table is table with number "1".
2. Missing logic to delay the evaluation of (expensive) constant conditions
  during the execution phase.

The fix adds/changes:
The patch:
- removes incorrect treatment of expensive predicates from make_cond_for_table,
  and lets the caller decide when to evaluate expensive predicates.
- saves expensive constant conditions in JOIN::exec_const_cond,
  which is evaluated once in the beginning of JOIN::exec.
2010-11-19 12:54:15 +02:00
Igor Babaev
4e5911733a Fixed LP bug #674431.
A non-incremental join buffer cannot be used for inner tables of nested
outer joins. That's why when join_cache_level is set to 7 it must
be downgraded to level 6 for the inner tables of nested outer joins.
For the same reason with join_cache_level set to 3 no join buffer is
used for the inner tables of outer joins (we could downgrade it to
level 2, but this level does not support ref access).
2010-11-13 06:13:34 -08:00
Sergey Petrunya
881f52fee7 Merge in LPBUG#602574 2010-11-11 14:35:26 +02:00
Igor Babaev
74d18e93c6 Fixed LP bug #671901.
Currently BNLH join uses a simplified implementation of hash function
when hash function is calculated over the whole key buffer, not only
the significant bytes of it. It means that both building keys and
probing keys both must fill insignificant bytes with the same filler.
Usually 0 is used as such a filler.
Yet the code before patch filled insignificant bytes only for probing
keys.
2010-11-07 15:19:30 -08:00
Igor Babaev
bbbe3ac8fb Merge 2010-11-05 19:20:54 -07:00
Igor Babaev
dba8cfd541 BNL and BNLH algorithms scan the join table and for each its record they
try to find a match in the join buffer. It makes sense to check for a match
only those records satisfying WHERE/ON conditions that can be pushed to
the scanned table. It allows us to discard early some join candidates.

Such pushdown conditions were built when BNL join algorithm was employed,
but for they were not built when BNLH algorithm was used.
The patch removes this shortcoming.
2010-11-05 19:00:53 -07:00
unknown
bc7369b74b MWL#89: Cost-based choice between Materialization and IN->EXISTS transformation
Merge 5.3-mwl89 into 5.3 main.

There is one remaining test failure in this merge:
innodb_mysql_lock2. All other tests have been checked to
deliver the same results/explains as 5.3-mwl89, including
the few remaining wrong results.
2010-11-05 14:42:58 +02:00
Igor Babaev
615d756721 Fixed LP bug #669382.
When probing into the hash table of a hashed join cache is performed
the key value should not constructed in the buffer used to build keys
in the hash tables. The constant parts of these keys copied only once,
so they should not be ever overwritten. Otherwise wrong results
can be produced by queries that employ hashed join buffers.
2010-11-04 21:00:33 -07:00
Igor Babaev
73898792da Fixed LP bug #664594 and other bugs leading to invalid execution
plans or wrong results due to the fact that JOIN_CACHE functions
ignored the possibility of interleaving materialized semijoin 
tables with tables whose records were stored in join buffers.
This fixes would become mostly unnecessary if the new code of
mwl 90 was merged into 5.3 right now.
Yet the fix the code of optimize_wo_join_buffering was needed
in any case.
2010-11-03 12:26:18 -07:00
Sergey Petrunya
5d1c9ce470 LPBUG#602574: RQG: sql_select.cc:5385: bool greedy_search... : Assertion `join->best_read
- Make optimize_wo_join_buffering() handle cases where position->records_read=0 (this
  happens for outer joins that have constant tables inside them). The number of
  0 is not correct (should be 1 because outer join will produce at least a NULL-complemented
  record) but for now we just make it work with incorrect number.
2010-11-02 21:13:53 +03:00
unknown
9f2bddbd80 Fixed LP BUG#652727 and LP BUG#643424.
The fixes for #643424 was part of the fix for #652727, that's why both
fixes are pushed together.

- The cause for #643424 was the improper use of get_partial_join_cost(),
  which assumed that the 'n_tables' parameter was the upper bound for
  query plan node indexes.
  Fixed by generalizing get_partial_join_cost() as a method that computes
  the cost of any partial join.

- The cause of #652727 was that JOIN::choose_subquery_plan() incorrectly
  deleted the contents of the old keyuse array in the cases when an injected
  plan would not provide more key accesses, and reoptimization was not actually
  performed.
2010-11-02 15:27:01 +02:00
Igor Babaev
df32342102 Fixed LP bug #668290.
Prohibited to use hash join algorithm BNLH if join attributes
need non-binary collations. It has to be done because BNLH does
not support join for such attributes yet.
Later this limitations will be lifted.

Changed default collations for the schemes of some test cases
to preserve the old execution plans.
2010-10-30 15:14:36 -07:00
Igor Babaev
0b72fd88a1 Merge. 2010-10-30 06:07:45 -07:00
Sergei Golubchik
8e7ebfbce8 5.2 merge 2010-10-28 19:04:23 +02:00