Commit graph

330 commits

Author SHA1 Message Date
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
Igor Babaev
7f52af655a Merge. 2010-12-10 23:23:34 -08: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
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
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
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
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
Igor Babaev
4f75a8254a Merge 5.3-mwl128 -> 5.3 2010-10-27 16:31:22 -07:00
unknown
3b11e4f834 Fixed LP bug #609121
Post-review fix - avoid re-evaluation of the having clause
when it evaluates to true.
2010-10-27 12:35:15 +03:00
unknown
db4738a18a Fixed LP bug #609121
The bug was a result of missing logic to handle the case
when there are 'expensive' predicates that are not evaluated
during constant table optimization. Such is the case for
the IN predicate, which is considered expensive if it is
computed via materialization. In general this bug can be
triggered with any expensive predicate instead of IN.

When FALSE constant predicates are not evaluated during constant
optimization, the execution path changes so that instead of
setting JOIN::zero_result_cause after make_join_select, and
exiting JOIN::exec via the call to return_zero_rows(), execution
ends in JOIN::exec in the branch:
if (join->tables == join->const_tables)
{
  ...
  else if (join->send_row_on_empty_set())
     ...
     rc= join->result->send_data(*columns_list);
}
Unlike return_zero_rows(), this branch didn't evaluate the
having clause of the query.

The patch adds a call to evaluate the HAVING clause of a query even
when all tables are constant, because even for an empty result set
some aggregate functions may produce a NULL value.
2010-10-25 23:48:43 +03:00
Igor Babaev
de69dbae0c Fixed LP bug #663818.
After the patch for bug 663840 had been applied the test case for
bug 663818 triggered the assert introduced by this patch.
It happened because the the patch turned out to be incomplete:
the space needed for a key entry must be taken into account
for the record written into the buffer, and, for the next record
as well, when figuring out whether the record being written is
the last for the buffer or not.
2010-10-22 15:30:47 -07:00
Igor Babaev
ca862231f7 Fixed LP bug #663840.
When adding a new record into the join buffer that is employed by
BNLH join algorithm the writing procedure JOIN_CACHE::write_record_data 
checks whether there is enough space for the record in the buffer.
When doing this it must take into account a possible new key entry
added to the buffer. It might happen, as it has been demonstrated by
the bug test case, that there is enough remaining space in the buffer
for the record, but not for the additional key entry for this record.
In this case the key entry overwrites the end of the record that might
cause a crash or wrong results.
Fixed by taking into account a possible addition of new key entry when
estimating the remaining free space in the buffer.
2010-10-22 10:53:29 -07:00
Sergei Golubchik
745cc74c33 5.1.51 merge 2010-10-19 15:58:35 +02:00
Igor Babaev
25f5debdc7 MWL#128: Added into EXPLAIN output info about types of the used join buffers and
about the employed join algorithms.
Refactored constructors of the JOIN_CACHE* classes.
2010-10-18 13:33:05 -07:00
Sergey Petrunya
f75fd03ea9 MariaDB 5.2 -> 5.2 post-merge fixes:
- When building multiple-equalities for HAVING, don't set JOIN::cond_equal, set
  join_having_equal instead. Setting JOIN::cond_equal based on HAVING makes 
  equality propagation data self-inconsistent
2010-10-17 18:05:29 +04:00
Sergey Petrunya
508e75c259 Merge MariaDB 5.2 -> MariaDB 5.3
- post-merge fixes
2010-10-14 01:48:03 +04:00
Sergey Petrunya
a285ce3e58 Post-merge fixes part 1 2010-10-10 17:38:17 +03:00
Sergey Petrunya
72dd7575cd Merge 5.2->5.3
- Re-commit Monty's merge, partially fixed by Igor and SergeyP, 
  but still broken
2010-10-10 17:18:11 +03:00
Igor Babaev
79087c9e07 Ported the fix for bug #57024 (a performance issue for outer joins).
Employed the same kind of optimization as in the fix for the cases
when join buffer is used.
The optimization performs early evaluation of the conditions from 
on expression with table references to only outer tables of
an outer join.
2010-10-06 13:27:12 -07:00
Igor Babaev
1320f6073c Fixed bug #54539.
Added a possibility not to factor out the condition pushed to
the access index out of the condition pushed to a joined table.
This is useful for the condition pushed to the index when a hashed
join buffer for BKA is employed. In this case the index condition
may be false for some, but for all records with the same key.
So the condition must be checked not only after index lookup,
but after fetching row data as well, and it makes sense not to 
factor out the condition from the condition checked after reading
row data,
The bug happened because the condition pushed to an index always
was factor out from the condition pushed to the accessed table.
2010-10-01 10:08:10 -07:00
Igor Babaev
716e84164a Fixed bug #57024.
The condition over the outer tables now are extracted from
the on condition of any outer join. This condition is
saved in a special field of the JOIN_TAB structure for
the first inner table of the outer join. The condition
is checked before the first inner table is accessed. If 
it turns out to be false the table is not accessed at all
and a null complemented row is generated immediately.
2010-09-26 09:12:34 -07:00
unknown
d6a9b52269 Fixed LP BUG#615760: Check on double cache assignment added into the transformation methods.
Cache parameters print added in EXPLAIN EXTENDED output.

mysql-test/r/compare.result:
  Cache parameters print added in EXPLAIN EXTENDED output.
mysql-test/r/group_by.result:
  Cache parameters print added in EXPLAIN EXTENDED output.
mysql-test/r/subselect.result:
  Cache parameters print added in EXPLAIN EXTENDED output.
mysql-test/r/subselect3.result:
  Cache parameters print added in EXPLAIN EXTENDED output.
mysql-test/r/subselect3_jcl6.result:
  Cache parameters print added in EXPLAIN EXTENDED output.
mysql-test/r/subselect4.result:
  Cache parameters print added in EXPLAIN EXTENDED output.
mysql-test/r/subselect_cache.result:
  Added test suite for LP BUG#615760
mysql-test/r/subselect_mat.result:
  Cache parameters print added in EXPLAIN EXTENDED output.
mysql-test/r/subselect_no_mat.result:
  Cache parameters print added in EXPLAIN EXTENDED output.
mysql-test/r/subselect_no_opts.result:
  Cache parameters print added in EXPLAIN EXTENDED output.
mysql-test/r/subselect_no_semijoin.result:
  Cache parameters print added in EXPLAIN EXTENDED output.
mysql-test/r/subselect_sj.result:
  Cache parameters print added in EXPLAIN EXTENDED output.
mysql-test/r/subselect_sj_jcl6.result:
  Cache parameters print added in EXPLAIN EXTENDED output.
mysql-test/suite/pbxt/r/subselect.result:
  Cache parameters print added in EXPLAIN EXTENDED output.
mysql-test/t/subselect_cache.test:
  Cache parameters print added in EXPLAIN EXTENDED output.
sql/item.cc:
  Item::set_expr_cache result fixed according to its description.
  
  Cache parameters print added in EXPLAIN EXTENDED output.
sql/item.h:
  Cache parameters print added in EXPLAIN EXTENDED output.
sql/item_cmpfunc.cc:
  Check on double cache assignment added into the transformation methods.
sql/item_cmpfunc.h:
  Check on double cache assignment added into the transformation methods.
sql/item_subselect.cc:
  Check on double cache assignment added into the transformation methods.
sql/item_subselect.h:
  Check on double cache assignment added into the transformation methods.
sql/sql_expression_cache.cc:
  Cache parameters print added.
sql/sql_expression_cache.h:
  Cache parameters print added.
sql/sql_select.cc:
  Removed unused method (now it is impossible to make double transformation with the cache).
sql/sql_select.h:
  Removed unused method.
2010-09-06 15:34:24 +03:00
Igor Babaev
f83cc50793 Fixed an incorrect calculation of JOIN_CACHE::max_buff_size. 2010-09-01 23:11:14 -07:00
Igor Babaev
94cfcbd9df The main patch for MWL#128: Implement Block Nested Loop Hash Join. 2010-08-31 09:34:21 -07:00
Michael Widenius
ecf95c6e7f Fix of LP#616253 Crash in _ma_bitmap_set_full_page_bits on Aria recovery
The bug was based on wrong undo data in recovery file and not enough checking of bad data.

sql/sql_select.h:
  Added comment
storage/maria/ma_blockrec.c:
  - Removed wrong sanity checks (didn't work for UNDO records)
  - More sanity checks and DBUG_ASSERT
  - More DBUG_ENTER and DBUG_PRINT
  - Removed filler blocks in extent_to_bitmap_blocks() as it caused problems in write_block_record().
    This was the main cause of the bug.
    (This change can make records generated by UNDO slightly smaller than original record, which we have to fix
    by correcting row_pos.length before calling write_block_record())
  - Fixed some problems in write_block_record() while doing UNDO.
  - Store header_length without TRANSID_SIZE into recovery log (as UNDO entires doesn't have TRANSID_SIZE)
  - Mark table crashed if something goes wrong during UNDO
storage/maria/maria_def.h:
  Added header_length
2010-08-24 20:17:17 +03:00
Alexey Kopytov
0012d0d884 Automerge. 2010-08-24 14:44:15 +04:00
Alexey Kopytov
cd4ca4b7a3 Bug #55568: user variable assignments crash server when used
within query

The server could crash after materializing a derived table
which requires a temporary table for grouping.

When destroying the temporary table used to execute a query for
a derived table, JOIN::destroy() did not clean up Item_fields
pointing to fields in the temporary table. This led to
dereferencing a dangling pointer when printing out the items
tree later in the outer SELECT.

The solution is an addendum to the patch for bug37362: in
addition to cleaning up items in tmp_all_fields3, do the same
for items in tmp_all_fields1, since now we have an example
where this is necessary.


mysql-test/r/join.result:
  Added test cases for bug#55568 and a duplicate bug #54468.
mysql-test/t/join.test:
  Added test cases for bug#55568 and a duplicate bug #54468.
sql/field.cc:
  Make sure field->table_name is not set to NULL in
  Field::make_field() to avoid assertion failure in 
  Item_field::make_field() after cleaning up items
  (the assertion fired in udf.test when running
  the test suite with the patch applied).
sql/sql_select.cc:
  In addition to cleaning up items in tmp_all_fields3, do the
  same for items in tmp_all_fields1.
  Introduce a new helper function to avoid code duplication.
sql/sql_select.h:
  Introduce a new helper function to avoid code duplication in
  JOIN::destroy().
2010-08-24 14:35:48 +04:00
Michael Widenius
b6fe4713fe Fix for LP#612894 Some aggregate functions (such as MIN MAX) work incorrectly in subqueries after getting NULL value
mysql-test/r/group_by.result:
  Added test that showed problems that no_rows_in_results() didn't work for expressions
mysql-test/r/subselect4.result:
  Test case for LP#612894
mysql-test/t/group_by.test:
  Added test that showed problems that no_rows_in_results() didn't work for expressions
mysql-test/t/subselect4.test:
  Test case for LP#612894
sql/item.h:
  Added restore_to_before_no_rows_in_result()
  Added function processor for no_rows_in_results() and restore_to_before_no_rows_in_results() to ensure it works with functions
  Fix that above functions are handled by Item_ref()
sql/item_func.h:
  Ensure that no_rows_in_results() and restore_to_before_no_rows_in_result() are called for all function arguments
sql/item_sum.cc:
  Added restore_to_before_no_rows_in_result() to restore settings after Item_sum_hybrid::no_rows_in_result() was called.
  This is needed to handle the case where we have made 'make_const()' on the item in opt_sum(), but the item will be reused again in a sub query.
  Ignore multiple calls to no_rows_in_result() as Item_ref is calling it twice.
sql/item_sum.h:
  Added restore_to_before_no_rows_in_result();
sql/sql_select.cc:
  Added reset of no_rows_in_result() for JOIN::reinit()
sql/sql_select.h:
  Added marker if no_rows_in_result() is called.
2010-08-23 12:46:25 +03:00
Georgi Kodinov
790852c0c9 Bug #55580 : segfault in read_view_sees_trx_id
The server was not checking for errors generated during
the execution of Item::val_xxx() methods when copying
data to the group, order, or distinct temp table's row.
Fixed by extending the copy_funcs() to return an error
code and by checking for that error code on the places
copy_funcs() is called. 
Test case added.
2010-08-13 11:07:39 +03:00
unknown
ceb5468fd8 Subquery cache (MWL#66) added.
libmysqld/Makefile.am:
  The new file added.
mysql-test/r/index_merge_myisam.result:
  subquery_cache optimization option added.
mysql-test/r/myisam_mrr.result:
  subquery_cache optimization option added.
mysql-test/r/subquery_cache.result:
  The subquery cache tests added.
mysql-test/r/subselect3.result:
  Subquery cache switched off to avoid changing read statistics.
mysql-test/r/subselect3_jcl6.result:
  Subquery cache switched off to avoid changing read statistics.
mysql-test/r/subselect_no_mat.result:
  subquery_cache optimization option added.
mysql-test/r/subselect_no_opts.result:
  subquery_cache optimization option added.
mysql-test/r/subselect_no_semijoin.result:
  subquery_cache optimization option added.
mysql-test/r/subselect_sj.result:
  subquery_cache optimization option added.
mysql-test/r/subselect_sj_jcl6.result:
  subquery_cache optimization option added.
mysql-test/t/subquery_cache.test:
  The subquery cache tests added.
mysql-test/t/subselect3.test:
  Subquery cache switched off to avoid changing read statistics.
sql/CMakeLists.txt:
  The new file added.
sql/Makefile.am:
  The new files added.
sql/item.cc:
  Expression cache item (Item_cache_wrapper) added.
  Item_ref and Item_field fixed for correct usage of result field and fast resolwing in SP.
sql/item.h:
  Expression cache item (Item_cache_wrapper) added.
  Item_ref and Item_field fixed for correct usage of result field and fast resolwing in SP.
sql/item_cmpfunc.cc:
  Subquery cache added.
sql/item_cmpfunc.h:
  Subquery cache added.
sql/item_subselect.cc:
  Subquery cache added.
sql/item_subselect.h:
  Subquery cache added.
sql/item_sum.cc:
  Registration of subquery parameters added.
sql/mysql_priv.h:
  subquery_cache optimization option added.
sql/mysqld.cc:
  subquery_cache optimization option added.
sql/opt_range.cc:
  Fix due to subquery cache.
sql/opt_subselect.cc:
  Parameters of the function cahnged.
sql/procedure.h:
  .h file guard added.
sql/sql_base.cc:
  Registration of subquery parameters added.
sql/sql_class.cc:
  Option to allow add indeces to temporary table.
sql/sql_class.h:
  Item iterators added.
  Option to allow add indeces to temporary table.
sql/sql_expression_cache.cc:
  Expression cache for caching subqueries added.
sql/sql_expression_cache.h:
  Expression cache for caching subqueries added.
sql/sql_lex.cc:
  Registration of subquery parameters added.
sql/sql_lex.h:
  Registration of subqueries and subquery parameters added.
sql/sql_select.cc:
  Subquery cache added.
sql/sql_select.h:
  Subquery cache added.
sql/sql_union.cc:
  A new parameter to the function added.
sql/sql_update.cc:
  A new parameter to the function added.
sql/table.cc:
  Procedures to manage temporarty tables index added.
sql/table.h:
  Procedures to manage temporarty tables index added.
storage/maria/ha_maria.cc:
  Fix of handler to allow destoy a table in case of error during the table creation.
storage/maria/ha_maria.h:
  .h file guard added.
storage/myisam/ha_myisam.cc:
  Fix of handler to allow destoy a table in case of error during the table creation.
2010-07-10 13:37:30 +03:00
Sergey Petrunya
27f9fc063c MariaDB 5.2 -> MariaDB 5.3 merge 2010-06-26 14:05:41 +04:00
Sergey Petrunya
7754be7f4c More comments 2010-06-14 15:17:54 +04: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 Petrunya
7df026676b Merge MariaDB-5.2 -> MariaDB 5.3 2010-03-20 15:01:47 +03:00
Sergey Petrunya
02e9fa62e7 BUG#45174: XOR in subqueries produces differing results in 5.1 and 5.4
BUG#50019: Wrong result for IN-subquery with materialization
- Fix equality substitution in presense of semi-join materialization, lookup and scan variants
  (started off from fix by Evgen Potemkin, then modified it to work in all cases)
2010-03-13 23:04:52 +03:00
Igor Babaev
3ccc1d6b1e Corrected Evgen's fix for bug #45191.
Made sure that join buffers could be used for inner tables of
any semi-join when the first match strategy is employed.
2010-03-05 10:54:48 -08:00
unknown
4bf849c23c Merge MySQL 5.1.44 into MariaDB. 2010-03-04 09:03:07 +01:00
Sergey Petrunya
e0bb2f90a2 Subquery optimization backport:
- Factor out subquery code into sql/opt_subselect.{h,cc}
- Stop using the term "confluent" (was used due to misreading the dictionary)
2010-02-16 00:53:06 +03:00
Georgi Kodinov
32058ba9c6 Addendum 2 for bug #46175: NULL read_view and consistent read assertion
Fixed a compilation warning.
2010-02-15 10:54:27 +02:00
Sergey Petrunya
17116d5155 Subquery optimizations: backport: enable disabled subquery code in BKA 2010-02-12 01:31:18 +03:00
Georgi Kodinov
32902dad00 Addendum to bug #46175 : use and check for the correct error values
when converting to a enumerated type.
2010-02-11 19:41:53 +02:00
Sergey Petrunya
f47b2d38f6 Subquery optimizations: non-semijoin materialization
- Backport into Maria DB 5.3, part 1
2010-01-28 16:48:33 +03:00