@@ -6662,7 +6662,7 @@ add_key_field(JOIN *join,
6662
6662
{
6663
6663
uint optimize= 0;
6664
6664
if (eq_func &&
6665
- ((join->is_allowed_hash_join_access() &&
6665
+ ((join->is_allowed_hash_join_access(field->table ) &&
6666
6666
field->hash_join_is_possible() &&
6667
6667
!(field->table->pos_in_table_list->is_materialized_derived() &&
6668
6668
field->table->is_created())) ||
@@ -9428,8 +9428,7 @@ best_access_path(JOIN *join,
9428
9428
(2) s is inner table of outer join -> join cache is allowed for outer joins
9429
9429
*/
9430
9430
if (idx > join->const_tables && best.key == 0 &&
9431
- (join->allowed_join_cache_types & JOIN_CACHE_HASHED_BIT) &&
9432
- join->max_allowed_join_cache_level > 2 &&
9431
+ join->is_allowed_hash_join_access(table) &&
9433
9432
!bitmap_is_clear_all(eq_join_set) && !disable_jbuf &&
9434
9433
(!s->emb_sj_nest ||
9435
9434
join->allowed_semijoin_with_cache) && // (1)
@@ -11468,7 +11467,6 @@ get_costs_for_tables(JOIN *join, table_map remaining_tables, uint idx,
11468
11467
JOIN_TAB *s;
11469
11468
table_map found_tables= 0;
11470
11469
bool found_eq_ref= 0;
11471
- bool disable_jbuf= join->thd->variables.join_cache_level == 0;
11472
11470
DBUG_ENTER("get_plans_for_tables");
11473
11471
11474
11472
s= *pos;
@@ -11485,6 +11483,11 @@ get_costs_for_tables(JOIN *join, table_map remaining_tables, uint idx,
11485
11483
sort_end->join_tab= pos;
11486
11484
sort_end->position= sort_position;
11487
11485
11486
+ bool hint_forces_jbuf=
11487
+ hint_table_state(join->thd, s->table, BNL_HINT_ENUM, false);
11488
+
11489
+ bool disable_jbuf=
11490
+ (join->thd->variables.join_cache_level == 0) && !hint_forces_jbuf;
11488
11491
11489
11492
Json_writer_object wrapper(thd);
11490
11493
/* Find the best access method from 's' to the current partial plan */
@@ -14471,11 +14474,17 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
14471
14474
add_cond_and_fix(thd, &tmp, tab->select_cond);
14472
14475
}
14473
14476
14477
+ uint max_jcl= join->max_allowed_join_cache_level;
14478
+ bool is_hash_allowed= join->allowed_join_cache_types &
14479
+ JOIN_CACHE_HASHED_BIT;
14480
+ bool is_bnlh_enabled= ((max_jcl == 3 || max_jcl == 4) &&
14481
+ is_hash_allowed) ||
14482
+ hint_table_state(thd, tab->table, BNL_HINT_ENUM, false);
14483
+ bool is_bkah_enabled= (max_jcl > 4 && is_hash_allowed) ||
14484
+ hint_table_state(thd, tab->table, BKA_HINT_ENUM, false);
14474
14485
is_hj= (tab->type == JT_REF || tab->type == JT_EQ_REF) &&
14475
- (join->allowed_join_cache_types & JOIN_CACHE_HASHED_BIT) &&
14476
- ((join->max_allowed_join_cache_level+1)/2 == 2 ||
14477
- ((join->max_allowed_join_cache_level+1)/2 > 2 &&
14478
- is_hash_join_key_no(tab->ref.key))) &&
14486
+ (is_bnlh_enabled ||
14487
+ (is_bkah_enabled && is_hash_join_key_no(tab->ref.key))) &&
14479
14488
(!tab->emb_sj_nest ||
14480
14489
join->allowed_semijoin_with_cache) &&
14481
14490
(!(tab->table->map & join->outer_join) ||
@@ -15631,17 +15640,14 @@ end_sj_materialize(JOIN *join, JOIN_TAB *join_tab, bool end_of_records)
15631
15640
OPTIMIZER_HINTS
15632
15641
The following hints may influence the choice of join buffering:
15633
15642
BNL(t1,t2,..): enables BNL and BNLH buffers for the specified tables
15634
- when join_cache_level=0. Effectively it increases
15643
+ when join_cache_level < 4. It effectively increases
15635
15644
join_cache_level to 4 for given tables.
15636
15645
NO_BNL(t1,t2,..): disables BNL/BNLH join buffers, which could have been
15637
15646
chosen for the specified tables otherwise. Does not
15638
15647
prevent employing of BKA/BKAH buffers
15639
15648
BKA(t1,t2,..): enables BKA and BKAH buffers for the specified tables
15640
- when optimizer switch join_cache_bka=off. Does not
15641
- increase join_cache_level, i.e., when join_cache_level=4
15642
- and the hint is specified, BKA join buffers will still
15643
- not be employed. The hint effectively overrides only
15644
- optimizer switch join_cache_bka setting.
15649
+ when join_cache_level < 5 and/or
15650
+ optimizer switch join_cache_bka=off.
15645
15651
NO_BKA(t1,t2,..): disables BKA/BKAH join buffers, which could have been
15646
15652
chosen for the specified tables otherwise. However,
15647
15653
does not prevent employing of BNL/BNLH buffers.
@@ -15710,22 +15716,19 @@ uint check_join_cache_usage(JOIN_TAB *tab,
15710
15716
!(join->allowed_join_cache_types & JOIN_CACHE_INCREMENTAL_BIT);
15711
15717
bool no_hashed_cache=
15712
15718
!(join->allowed_join_cache_types & JOIN_CACHE_HASHED_BIT);
15713
- bool no_bnl_cache= !hint_table_state_or_fallback(join->thd,
15714
- tab->tab_list->table, BNL_HINT_ENUM, true);
15715
- bool no_bka_cache= !hint_table_state_or_fallback(join->thd,
15716
- tab->tab_list->table, BKA_HINT_ENUM,
15717
- join->allowed_join_cache_types & JOIN_CACHE_BKA_BIT);
15718
- bool hint_forces_bka= hint_table_state_or_fallback(join->thd,
15719
- tab->tab_list->table,
15720
- BKA_HINT_ENUM, false);
15719
+ bool no_bnl_cache= !hint_table_state(join->thd, tab->tab_list->table,
15720
+ BNL_HINT_ENUM, true);
15721
+ bool no_bka_cache= !hint_table_state(join->thd, tab->tab_list->table,
15722
+ BKA_HINT_ENUM, join->allowed_join_cache_types & JOIN_CACHE_BKA_BIT);
15723
+ bool hint_forces_bka= hint_table_state(join->thd, tab->tab_list->table,
15724
+ BKA_HINT_ENUM, false);
15721
15725
join->return_tab= 0;
15722
15726
15723
15727
if (tab->no_forced_join_cache || (no_bnl_cache && no_bka_cache))
15724
15728
goto no_join_cache;
15725
15729
15726
- if (cache_level < 4 && hint_table_state_or_fallback(join->thd,
15727
- tab->tab_list->table,
15728
- BNL_HINT_ENUM, false))
15730
+ if (cache_level < 4 && hint_table_state(join->thd, tab->tab_list->table,
15731
+ BNL_HINT_ENUM, false))
15729
15732
{
15730
15733
cache_level= 4; // BNL() hint present, raise join_cache_level to BNLH
15731
15734
}
@@ -32445,6 +32448,13 @@ void JOIN::set_allowed_join_cache_types()
32445
32448
max_allowed_join_cache_level= thd->variables.join_cache_level;
32446
32449
}
32447
32450
32451
+ bool JOIN::is_allowed_hash_join_access(const TABLE *table)
32452
+ {
32453
+ return allowed_join_cache_types & JOIN_CACHE_HASHED_BIT &&
32454
+ (max_allowed_join_cache_level > JOIN_CACHE_HASHED_BIT ||
32455
+ hint_table_state(thd, table, BNL_HINT_ENUM, false) ||
32456
+ hint_table_state(thd, table, BKA_HINT_ENUM, false));
32457
+ }
32448
32458
32449
32459
/**
32450
32460
Save a query execution plan so that the caller can revert to it if needed,
0 commit comments