Commit graph

55 commits

Author SHA1 Message Date
Sergey Petrunya
997445bc8e Make EXPLAIN better at displaying MRR/BKA:
- "Using MRR" is no longer shown with range access.
- Instead, both range and BKA accesses will show one of the following:
  = "Rowid-ordered scan"
  = "Key-ordered scan"
  = "Key-ordered Rowid-ordered scan"
depending on whether DS-MRR implementation will do scan keys in order, rowids in order,
or both.
- The patch also introduces a way for other storage engines/MRR implementations to
  pass information to EXPLAIN output about the properties of employed MRR scans.
2011-04-02 14:04:45 +04:00
Sergey Petrunya
e6bd643c75 MRR interface: change range_info's type from char* to range_id_t typedef. The goals are:
- cleaner code
- ability to change from using pointers to offsets at some point
2011-03-04 12:06:03 +03:00
Sergey Petrunya
db984067eb Fix buildbot failure in fix of BUG#723822 2011-02-26 23:09:58 +03:00
Vladislav Vaintroub
70a7e97e3c Fixed high-impact Windows 64bit warnings (at least 4000 of them) 2011-02-19 13:43:01 +01:00
Vladislav Vaintroub
019256c9fc Fix numerous warnings introduced in the last pushes on Windows 2011-02-18 23:31:01 +01:00
Igor Babaev
4b24105df8 Introduced optimizer switch flag 'optimize_join_buffer_size'.
When this flag is 'off' the size of the used join buffer 
is taken directly from the system variable 'join_buffer_size'.
When this flag is 'on' then the size of the buffer depends
on the estimated number of rows in the partial join whose
records are to be stored in the buffer.
By default this flag is set 'on'.
2011-02-04 19:06:35 -08:00
Igor Babaev
ec368ab9fa Merge 2011-01-21 22:48:28 -08:00
Igor Babaev
92f2392eb5 Merge 2011-01-14 23:53:27 -08:00
Igor Babaev
0aebdc115f Ported the fix for LP bug #702310 / bug #59493.
An assertion failure was triggered for a 6-way join query that used two
join buffers.
The failure happened because every call of JOIN_CACHE::join_matching_records
saved and restored status of all tables that were accessed before the table
join_tab. It must do it only for those of them that follow the last table 
using a join buffer.
2011-01-14 22:55:56 -08:00
Sergey Petrunya
7fd3c9e2ff Merge backported subquery bugfixes/testcases into MariaDB 5.3 2011-01-14 13:07:50 +03:00
Sergey Petrunya
d2cbb10443 Backport of (see below) + temporary measures to make SJ-Materialization work with join buffering.
Date: Mon, 01 Nov 2010 15:15:25 -0000
3272 Roy Lyseng        2010-11-01
Bug#52068: Optimizer generates invalid semijoin materialization plan

When MaterializeScan semijoin strategy was used and there were one
or more outer dependent tables before the semijoin tables, the scan
over the materialized table was not properly reset for each row of
the prefix outer tables.

Example: suppose we have a join order:

  ot1 SJ-Mat-Scan(it2 it3)  ot4

Notice that this is called a MaterializeScan, even though there is an
outer table ahead of the materialized tables. Usually a MaterializeScan
has the outer tables after the materialized table, but this is
a special (but legal) case with outer dependent tables both before and
after the materialized table.

For each qualifying row from ot1, a new scan over the materialized
table must be set up. The code failed to do that, so all scans after
the first one returned zero rows from the materialized table.
2011-01-13 19:25:31 +03: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
Igor Babaev
18dc64eca2 Fixed LP bug #694443.
One of the hash functions employed by the BNLH join algorithm
calculates the the value of hash index for key value utilizing
every byte of the key buffer. To make this calculation valid
one has to ensure that for any key value unused bytes of the 
buffer are filled with with a certain filler. We choose 0 as
a filler for these bytes.

Added an optional boolean parameter with_zerofill to the function
key_copy. If the value of the parameter is TRUE all unused bytes
of the key buffer is filled with 0.
2010-12-26 16:31:03 -08:00
Igor Babaev
1eb5e0e603 Merge 2010-12-24 16:24:20 -08:00
Igor Babaev
a095346a9d Fixed LP bug #670380.
Lifted the limitation that hash join could not be used over 
varchar fields with non-binary collation.
2010-12-22 00:37:35 -08:00
Sergey Petrunya
eafc4bef33 MWL#121-125 DS-MRR improvements
- Address review feedback: change return type of RANGE_SEQ_IF::next()
2010-12-13 20:01:32 +03:00
Sergey Petrunya
58b646001a Merge DS-MRR/CPK improvements into 5.3-main 2010-12-13 13:42:40 +03:00
Igor Babaev
419d524ff9 Fixed compiler warnings. 2010-12-11 12:50:39 -08:00
Sergey Petrunya
44be131cd3 MWL#121-125 DS-MRR improvements
- Address Monty's review feedback, part 5
2010-12-02 14:10:52 +03:00
Sergey Petrunya
d1afc20e13 Merge maria-5.3-mwl128 -> maria-5.2-mwl128-dsmrr-cpk 2010-11-29 19:00:32 +03:00
Sergey Petrunya
a6c1d56e08 MWL#121-125 DS-MRR improvements
- Address Monty's review feedback, part 1
- Fix buildbot failure
2010-11-22 19:34:03 +03:00
Igor Babaev
ae4b5a32a6 Fixed LP bug #675922.
The bug happened when BKA join algorithm used an incremental buffer
and some of the fields over which access keys were constructed
- were allocated in the previous join buffers
- were non-nullable
- belonged to inner tables of outer joins.
For such fields an offset to the field value in the record is saved
in the postfix of the record, and a zero offset indicates that the value 
is null. Before the key using the field value is constructed the
value is read into the corresponding field of the record buffer and
the null bit is set for the field if the offset is 0. However if
the field is non-nullable the table->null_row must be set to 1
for null values and to 0 for non-null values  to ensure proper reading
of the value from the record buffer.
2010-11-19 07:38:02 -08:00
Sergey Petrunya
9ab54acbf0 Merge MWL#121-125 DS-MRR improvements into MWL#128 Classic hash join tree 2010-11-15 04:45:49 +03:00
Igor Babaev
9441a9cc28 Fixed LP bug #674423.
The patch that introduced the new enumeration type Match_flag
for the values of match flags in the records put into join buffers
missed the necessary modifications in JOIN_CACHE::set_match_flag_if_none.
This could cause wrong results for outer joins with on expressions
only over outer tables.
2010-11-13 07:47:43 -08:00
Igor Babaev
92772d6d46 Fixed LP bug#672497.
Miscalculation of the minimum possible buffer size could trigger
an assert in JOIN_CACHE_HASHED::put_record when if join_buffer_size
was set to the values that is less than the length of one record to
stored in the join buffer.
It happened due to the following mistakes:
- underestimation of space needed for a key in the hash table
  (we have to take into account that hash table can have more
  buckets than the expected number of records).
- the value of maximum total length of all records stored in
  the join buffer was not saved in the field max_used_fieldlength
  by the function calc_used_field_length.
2010-11-11 15:35:11 -08: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
7f059782d0 Merge MWL#121-124 DS-MRR support for key-ordered reads + MWL#128 BNL-Hash join 2010-11-01 20:43:02 +03:00
Sergey Petrunya
6c15806b68 MWL#121-124 DS-MRR support for key-ordered retrieval, etc
- Merge into 5.3-main
2010-11-01 18:49:59 +03:00
Igor Babaev
4f75a8254a Merge 5.3-mwl128 -> 5.3 2010-10-27 16:31:22 -07: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
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
51294f5948 Remove garbage comments 2010-10-10 22:43:19 +03:00
Sergey Petrunya
a285ce3e58 Post-merge fixes part 1 2010-10-10 17:38:17 +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
f1d42ec940 Applied the fix for bug #54235 taken from one of the mysql trees.
The fix aligns join_null_complements() with join_matching_records()
making both call generate_full_extensions().
There should not be any difference between how the WHERE clause
is applied to NULL-complemented records from a partial join and how
it is applied to other partially joined records:the latter happens in
join_matching_records(), precisely in generate_full_extensions().
2010-10-03 18:45:46 -07:00
Igor Babaev
f4503f39ee Fixed bug #52394 / LP bug #623209.
When an incremental join cache is used to join a table whose
fields are not referenced anywhere in the query the association
pointer to the last record in the such cache can be the same
as the pointer to the end of the buffer. 
The function JOIN_CACHE_BKA::get_next_key must take into 
consideration this when iterating over the keys of the records
from the join buffer. 
The assertion in JOIN_TAB_SCAN_MRR::next also must take this
into consideration.
Borrowed a slightly changed test case from a patch attached to the
bug #52394.
2010-09-21 16:41:53 -07:00
Igor Babaev
61e96a75a6 Fixed a typo bug in JOIN_CACHE::shrink_join_buffer_in_ratio. 2010-09-02 17:16:03 -07:00
Igor Babaev
4a9696a451 Made sure that JOIN_CACHE::max_records is not less than 10. 2010-09-02 07:42:47 -07:00
Igor Babaev
f83cc50793 Fixed an incorrect calculation of JOIN_CACHE::max_buff_size. 2010-09-01 23:11:14 -07:00
Igor Babaev
e268f224fb Fixes in function specs. 2010-08-31 22:30:54 -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
Sergey Petrunya
e0999cdf7c DS-MRR support improvements (MWL#123, MWL#124, MWL#125)
- Lots of TODO comments
- add mrr_sort_keys flag to @@optimizer_switch
- [from Igor] SQL layer part passes HA_MRR_MATERIALIZED_KEYS flag
- Don't call rnd_pos() many times in a row if sorted rowid buffer
  has the same rowid value for multiple consequive (rowid, range_id) pairs.
2010-07-17 18:03:50 +04:00
Sergey Petrunya
e1006e9e1f MWL#121: DS-MRR support for clustered primary keys
- Merge with current 5.3
2010-07-16 13:38:23 +04:00
Igor Babaev
0d734037cc Added missing calls of update_virtual_fields() in the
join cache module.
Without these calls SELECTs over tables with virtual columns
that used join cache could return wrong results. This could
be seen with the test case added into vcol_misc.test
2010-07-01 22:13:19 -07:00
Sergey Petrunya
27f9fc063c MariaDB 5.2 -> MariaDB 5.3 merge 2010-06-26 14:05:41 +04:00
Sergey Petrunya
488d352a66 MWL#121: DS-MRR support for clustered primary keys
- Remove back key_parts from multi_range_read_init() parameters
- Related code simplification/cleanup
2010-06-22 23:26:11 +04:00
Sergey Petrunya
925e508a2e MWL#121: DS-MRR support for clustered primary keys
- First code (will need code cleanup)
2010-06-19 15:40:19 +04:00
Sergey Petrunya
c2924e155e BUG#49129: Wrong result with IN-subquery with join_cache_level=6 and firstmatch=off
- The problem was that DuplicateWeedout strategy setup code wasn't aware of the 
  fact that join buffering will be used and applied optimization that doesn't work
  together with join buffering. Fixed by making DuplicateWeedout setup code to have 
  a pessimistic check about whether there is a chance that join buffering will be 
  used.
- Make JOIN_CACHE_BKA::init() correctly process Copy_field elements that denote saving
  current rowids in the join buffer.

mysql-test/r/subselect_sj2.result:
  Update test results
mysql-test/r/subselect_sj2_jcl6.result:
  Update test results
mysql-test/r/subselect_sj_jcl6.result:
  Testcase
mysql-test/t/subselect_sj2.test:
  Update test results
mysql-test/t/subselect_sj_jcl6.test:
  Testcase
sql/opt_subselect.cc:
  - The problem was that DuplicateWeedout strategy setup code wasn't aware of the 
    fact that join buffering will be used and applied optimization that doesn't work
    together with join buffering. Fixed by making DuplicateWeedout setup code to have 
    a pessimistic check about whether there is a chance that join buffering will be 
    used.
sql/sql_join_cache.cc:
  Make JOIN_CACHE_BKA::init() correctly process Copy_field elements that denote saving current rowids in the join buffer.
sql/sql_select.cc:
  Added a question note
2010-03-07 18:41:45 +03:00