Commit d1afc20e authored by Sergey Petrunya's avatar Sergey Petrunya

Merge maria-5.3-mwl128 -> maria-5.2-mwl128-dsmrr-cpk

parents cee6e456 4e05898f
This diff is collapsed.
......@@ -2522,5 +2522,183 @@ SET SESSION join_cache_level = DEFAULT;
DROP TABLE t1,t2;
--echo #
--echo # Bug #675095: nested outer join using join buffer
--echo #
CREATE TABLE t1 (pk int, a1 int) ;
INSERT IGNORE INTO t1 VALUES (2,NULL), (8,0);
CREATE TABLE t2 (pk int, a2 int, c2 int, d2 int) ;
INSERT IGNORE INTO t2 VALUES (9,0,0,2), (1,0,0,7);
CREATE TABLE t3 (pk int, a3 int, c3 int, d3 int) ;
INSERT IGNORE INTO t3 VALUES (9,0,0,2), (1,0,0,7);
CREATE TABLE t4 (pk int, a4 int, INDEX idx(a4)) ;
INSERT IGNORE INTO t4 VALUES (2,NULL), (8,0);
CREATE TABLE t5 (pk int, a5 int) ;
INSERT IGNORE INTO t5 VALUES (2,0), (8,0);
SET SESSION optimizer_switch = 'outer_join_with_cache=on';
SET SESSION join_cache_level = 0;
EXPLAIN EXTENDED
SELECT *
FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.c2 = t3.a3) ON t1.pk = t2.d2)
LEFT JOIN t4 ON t1.a1 = t4.a4) LEFT JOIN t5 ON t3.a3 = t5.a5;
SELECT *
FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.c2 = t3.a3) ON t1.pk = t2.d2)
LEFT JOIN t4 ON t1.a1 = t4.a4) LEFT JOIN t5 ON t3.a3 = t5.a5;
SET SESSION join_cache_level = 2;
EXPLAIN EXTENDED
SELECT *
FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.c2 = t3.a3) ON t1.pk = t2.d2)
LEFT JOIN t4 ON t1.a1 = t4.a4) LEFT JOIN t5 ON t3.a3 = t5.a5;
SELECT *
FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.c2 = t3.a3) ON t1.pk = t2.d2)
LEFT JOIN t4 ON t1.a1 = t4.a4) LEFT JOIN t5 ON t3.a3 = t5.a5;
SET SESSION join_cache_level = 1;
EXPLAIN EXTENDED
SELECT *
FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.c2 = t3.a3) ON t1.pk = t2.d2)
LEFT JOIN t4 ON t1.a1 = t4.a4) LEFT JOIN t5 ON t3.a3 = t5.a5;
SELECT *
FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.c2 = t3.a3) ON t1.pk = t2.d2)
LEFT JOIN t4 ON t1.a1 = t4.a4) LEFT JOIN t5 ON t3.a3 = t5.a5;
SET SESSION optimizer_switch = 'outer_join_with_cache=off';
SET SESSION join_cache_level = DEFAULT;
DROP TABLE t1,t2,t3,t4,t5;
--echo #
--echo # Bug #675516: nested outer join with 3 tables in the nest
--echo # using BNL + BNLH
--echo #
CREATE TABLE t1 (a1 int, b1 int, c1 int) ;
INSERT INTO t1 VALUES (7,8,0), (6,4,0);
CREATE TABLE t2 (a2 int) ;
INSERT INTO t2 VALUES (5);
CREATE TABLE t3 (a3 int, b3 int, c3 int, PRIMARY KEY (b3)) ;
INSERT INTO t3 VALUES (2,5,0);
CREATE TABLE t4 (a4 int, b4 int, c4 int) ;
INSERT INTO t4 VALUES (7,8,0);
SET SESSION optimizer_switch = 'outer_join_with_cache=on';
SET SESSION join_cache_level = 4;
EXPLAIN
SELECT * FROM
t1 LEFT JOIN
((t2 JOIN t3 ON t2.a2 = t3.b3) JOIN t4 ON t4.b4 <> 0) ON t1.c1 = t3.c3
WHERE t3.a3 IS NULL;
SELECT * FROM
t1 LEFT JOIN
((t2 JOIN t3 ON t2.a2 = t3.b3) JOIN t4 ON t4.b4 <> 0) ON t1.c1 = t3.c3
WHERE t3.a3 IS NULL;
SET SESSION join_cache_level = 0;
EXPLAIN
SELECT * FROM
t1 LEFT JOIN
((t2 JOIN t3 ON t2.a2 = t3.b3) JOIN t4 ON t4.b4 <> 0) ON t1.c1 = t3.c3
WHERE t3.a3 IS NULL;
SELECT * FROM
t1 LEFT JOIN
((t2 JOIN t3 ON t2.a2 = t3.b3) JOIN t4 ON t4.b4 <> 0) ON t1.c1 = t3.c3
WHERE t3.a3 IS NULL;
SET SESSION optimizer_switch = 'outer_join_with_cache=off';
SET SESSION join_cache_level = DEFAULT;
DROP TABLE t1,t2,t3,t4;
--echo #
--echo # Bug #660963: nested outer join with join_cache_level set to 5
--echo #
CREATE TABLE t1 (a1 int) ;
INSERT INTO t1 VALUES (0),(0);
CREATE TABLE t2 (a2 int, b2 int, PRIMARY KEY (a2)) ;
INSERT INTO t2 VALUES (2,1);
CREATE TABLE t3 (a3 int, b3 int, PRIMARY KEY (a3)) ;
INSERT INTO t3 VALUES (2,1);
SET SESSION optimizer_switch = 'outer_join_with_cache=on';
SET SESSION join_cache_level = 6;
EXPLAIN
SELECT * FROM t1 LEFT JOIN t2 JOIN t3 ON t3.a3 = t2.a2 ON t3.b3 <> 0 ;
SELECT * FROM t1 LEFT JOIN t2 JOIN t3 ON t3.a3 = t2.a2 ON t3.b3 <> 0 ;
SET SESSION join_cache_level = 5;
EXPLAIN
SELECT * FROM t1 LEFT JOIN t2 JOIN t3 ON t3.a3 = t2.a2 ON t3.b3 <> 0 ;
SELECT * FROM t1 LEFT JOIN t2 JOIN t3 ON t3.a3 = t2.a2 ON t3.b3 <> 0 ;
SET SESSION optimizer_switch = 'outer_join_with_cache=off';
SET SESSION join_cache_level = DEFAULT;
DROP TABLE t1,t2,t3;
--echo #
--echo # Bug #675922: incremental buffer for BKA with access from previous
--echo # buffers from non-nullable columns whose values may be null
--echo #
CREATE TABLE t1 (a1 varchar(32)) ;
INSERT INTO t1 VALUES ('s'),('k');
CREATE TABLE t2 (a2 int PRIMARY KEY, b2 varchar(32)) ;
INSERT INTO t2 VALUES (7,'s');
CREATE TABLE t3 (a3 int PRIMARY KEY, b3 varchar(32)) ;
INSERT INTO t3 VALUES (7,'s');
CREATE TABLE t4 (a4 int) ;
INSERT INTO t4 VALUES (9);
CREATE TABLE t5(a5 int PRIMARY KEY, b5 int) ;
INSERT INTO t5 VALUES (7,0);
SET SESSION optimizer_switch = 'outer_join_with_cache=on';
SET SESSION join_cache_level = 0;
EXPLAIN
SELECT t4.a4, t5.b5
FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.a2 = t3.a3) ON t2.b2 = t1.a1)
LEFT JOIN t4 ON t4.a4 <> 0) LEFT JOIN t5 ON t5.a5 = t2.a2;
SELECT t4.a4, t5.b5
FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.a2 = t3.a3) ON t2.b2 = t1.a1)
LEFT JOIN t4 ON t4.a4 <> 0) LEFT JOIN t5 ON t5.a5 = t2.a2;
SET SESSION join_cache_level = 6;
EXPLAIN
SELECT t4.a4, t5.b5
FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.a2 = t3.a3) ON t2.b2 = t1.a1)
LEFT JOIN t4 ON t4.a4 <> 0) LEFT JOIN t5 ON t5.a5 = t2.a2;
SELECT t4.a4, t5.b5
FROM ((t1 LEFT JOIN (t2 JOIN t3 ON t2.a2 = t3.a3) ON t2.b2 = t1.a1)
LEFT JOIN t4 ON t4.a4 <> 0) LEFT JOIN t5 ON t5.a5 = t2.a2;
SET SESSION optimizer_switch = 'outer_join_with_cache=off';
SET SESSION join_cache_level = DEFAULT;
DROP TABLE t1,t2,t3,t4,t5;
# this must be the last command in the file
set @@optimizer_switch=@save_optimizer_switch;
......@@ -64,7 +64,8 @@ SET (SQL_SOURCE
sql_cursor.cc sql_db.cc sql_delete.cc sql_derived.cc sql_do.cc
sql_error.cc sql_handler.cc sql_help.cc sql_insert.cc
sql_lifo_buffer.h
sql_join_cache.cc sql_lex.cc sql_list.cc sql_load.cc sql_manager.cc
sql_join_cache.h sql_join_cache.cc
sql_lex.cc sql_list.cc sql_load.cc sql_manager.cc
sql_map.cc sql_parse.cc sql_partition.cc sql_plugin.cc
sql_prepare.cc sql_rename.cc
debug_sync.cc debug_sync.h
......
......@@ -82,6 +82,7 @@ noinst_HEADERS = item.h item_func.h item_sum.h item_cmpfunc.h \
sql_partition.h partition_info.h partition_element.h \
contributors.h sql_servers.h \
multi_range_read.h \
sql_join_cache.h \
create_options.h \
sql_expression_cache.h
......
......@@ -1776,7 +1776,13 @@ uint JOIN_CACHE::read_record_field(CACHE_FIELD *copy, bool blob_in_rec_buff)
If the value of *len is 0 then the function sets it to the total
length of the record fields including possible trailing offset
values. Otherwise *len is supposed to provide this value that
has been obtained earlier.
has been obtained earlier.
NOTE
If the value of the referenced field is null then the offset
for the value is set to 0. If the value of a field can be null
then the value of flag_fields is always positive. So the offset
for any non-null value cannot be 0 in this case.
RETURN VALUE
TRUE 'copy' points to a data descriptor of this join cache
......@@ -1805,14 +1811,21 @@ bool JOIN_CACHE::read_referenced_field(CACHE_FIELD *copy,
size_of_fld_ofs*
(referenced_fields+1-copy->referenced_field_no));
bool is_null= FALSE;
Field *field= copy->field;
if (offset == 0 && flag_fields)
is_null= TRUE;
if (is_null)
copy->field->set_null();
{
field->set_null();
if (!field->real_maybe_null())
field->table->null_row= 1;
}
else
{
uchar *save_pos= pos;
copy->field->set_notnull();
field->set_notnull();
if (!field->real_maybe_null())
field->table->null_row= 0;
pos= rec_ptr+offset;
read_record_field(copy, blob_data_is_in_rec_buff(rec_ptr));
pos= save_pos;
......
This diff is collapsed.
......@@ -6010,9 +6010,9 @@ bool JOIN_TAB::hash_join_is_possible()
int JOIN_TAB::make_scan_filter()
{
COND *tmp;
DBUG_ENTER("make_join_select");
DBUG_ENTER("make_scan_filter");
Item *cond= is_last_inner_table() ?
Item *cond= is_inner_table_of_outer_join() ?
*get_first_inner_table()->on_expr_ref : join->conds;
if (cond &&
......@@ -7149,7 +7149,8 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
used_tables2|= current_map;
COND *tmp_cond= make_cond_for_table(on_expr, used_tables2,
current_map, FALSE, FALSE);
add_cond_and_fix(&tmp_cond, tab->on_precond);
if (tab == first_inner_tab && tab->on_precond)
add_cond_and_fix(&tmp_cond, tab->on_precond);
if (tmp_cond)
{
JOIN_TAB *cond_tab= tab < first_inner_tab ? first_inner_tab : tab;
......@@ -7634,8 +7635,7 @@ uint check_join_cache_usage(JOIN_TAB *tab,
if (cache_level == 0 || i == join->const_tables || !prev_tab)
return 0;
if (force_unlinked_cache &&
(cache_level & JOIN_CACHE_INCREMENTAL_BIT))
if (force_unlinked_cache && (cache_level%2 == 0))
cache_level--;
if (options & SELECT_NO_JOIN_CACHE)
......@@ -7657,13 +7657,14 @@ uint check_join_cache_usage(JOIN_TAB *tab,
/*
Non-linked join buffers can't guarantee one match
*/
if (force_unlinked_cache &&
((tab->is_inner_table_of_semi_join_with_first_match() &&
!tab->is_single_inner_of_semi_join_with_first_match()) ||
(tab->is_inner_table_of_outer_join() &&
!tab->is_single_inner_of_outer_join())))
goto no_join_cache;
if (tab->is_nested_inner())
{
if (force_unlinked_cache || cache_level == 1)
goto no_join_cache;
if (cache_level & 1)
cache_level--;
}
/*
Don't use join buffering if we're dictated not to by no_jbuf_after (this
...)
......@@ -7756,9 +7757,6 @@ uint check_join_cache_usage(JOIN_TAB *tab,
(cache_level <= 6 || no_hashed_cache))
goto no_join_cache;
if (prev_tab->cache and cache_level==7)
cache_level= 6;
if ((rows != HA_POS_ERROR) && !(flags & HA_MRR_USE_DEFAULT_IMPL))
{
if (cache_level <= 6 || no_hashed_cache)
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment