summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2022-06-09 11:53:46 +0300
committerMarko Mäkelä <marko.makela@mariadb.com>2022-06-09 11:53:46 +0300
commitc89e3b70a740f486db2c60270892ba2893bb5610 (patch)
tree946650c0e5e1f84ebb6aa19234c665393a963abd /sql
parent5efadf8d8c6076bbee73e45afe050ab62c517f3c (diff)
parent98293130c34cfd39bf2e8c904923abe3942d23be (diff)
downloadmariadb-git-c89e3b70a740f486db2c60270892ba2893bb5610.tar.gz
Merge 10.3 into 10.4
Diffstat (limited to 'sql')
-rw-r--r--sql/opt_subselect.cc103
-rw-r--r--sql/opt_subselect.h8
-rw-r--r--sql/share/errmsg-utf8.txt2
-rw-r--r--sql/sql_select.cc18
-rw-r--r--sql/sql_select.h8
-rw-r--r--sql/tztime.cc30
6 files changed, 122 insertions, 47 deletions
diff --git a/sql/opt_subselect.cc b/sql/opt_subselect.cc
index bff0f3d7ef6..23829a7c075 100644
--- a/sql/opt_subselect.cc
+++ b/sql/opt_subselect.cc
@@ -180,7 +180,7 @@
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- optimize_semijoin_nests() does pre-optimization
- during join optimization, the join has one JOIN_TAB (or is it POSITION?)
- array, and suffix-based detection is used, see advance_sj_state()
+ array, and suffix-based detection is used, see optimize_semi_joins()
- after join optimization is done, get_best_combination() switches
the data-structure to prefix-based, multiple JOIN_TAB ranges format.
@@ -2735,7 +2735,7 @@ bool find_eq_ref_candidate(TABLE *table, table_map sj_inner_tables)
Do semi-join optimization step after we've added a new tab to join prefix
SYNOPSIS
- advance_sj_state()
+ optimize_semi_joins()
join The join we're optimizing
remaining_tables Tables not in the join prefix
new_join_tab Join tab we've just added to the join prefix
@@ -2795,9 +2795,9 @@ bool is_multiple_semi_joins(JOIN *join, POSITION *prefix, uint idx, table_map in
}
-void advance_sj_state(JOIN *join, table_map remaining_tables, uint idx,
- double *current_record_count, double *current_read_time,
- POSITION *loose_scan_pos)
+void optimize_semi_joins(JOIN *join, table_map remaining_tables, uint idx,
+ double *current_record_count,
+ double *current_read_time, POSITION *loose_scan_pos)
{
POSITION *pos= join->positions + idx;
const JOIN_TAB *new_join_tab= pos->table;
@@ -2988,19 +2988,36 @@ void advance_sj_state(JOIN *join, table_map remaining_tables, uint idx,
}
}
- if ((emb_sj_nest= new_join_tab->emb_sj_nest))
+ update_sj_state(join, new_join_tab, idx, remaining_tables);
+
+ pos->prefix_cost.convert_from_cost(*current_read_time);
+ pos->prefix_record_count= *current_record_count;
+ pos->dups_producing_tables= dups_producing_tables;
+}
+
+
+/*
+ Update JOIN's semi-join optimization state after the join tab new_tab
+ has been added into the join prefix.
+
+ @seealso restore_prev_sj_state() does the reverse actoion
+*/
+
+void update_sj_state(JOIN *join, const JOIN_TAB *new_tab,
+ uint idx, table_map remaining_tables)
+{
+ if (TABLE_LIST *emb_sj_nest= new_tab->emb_sj_nest)
{
join->cur_sj_inner_tables |= emb_sj_nest->sj_inner_tables;
/* Remove the sj_nest if all of its SJ-inner tables are in cur_table_map */
if (!(remaining_tables &
- emb_sj_nest->sj_inner_tables & ~new_join_tab->table->map))
+ emb_sj_nest->sj_inner_tables & ~new_tab->table->map))
join->cur_sj_inner_tables &= ~emb_sj_nest->sj_inner_tables;
}
-
- pos->prefix_cost.convert_from_cost(*current_read_time);
- pos->prefix_record_count= *current_record_count;
- pos->dups_producing_tables= dups_producing_tables;
+#ifndef DBUG_OFF
+ join->dbug_verify_sj_inner_tables(idx + 1);
+#endif
}
@@ -3553,10 +3570,45 @@ bool Duplicate_weedout_picker::check_qep(JOIN *join,
return FALSE;
}
+#ifndef DBUG_OFF
+/*
+ Verify the value of JOIN::cur_sj_inner_tables by recomputing it
+*/
+void JOIN::dbug_verify_sj_inner_tables(uint prefix_size) const
+{
+ table_map cur_map= const_table_map;
+ table_map nests_entered= 0;
+ if (emb_sjm_nest)
+ {
+ DBUG_ASSERT(cur_sj_inner_tables == 0);
+ return;
+ }
+
+ for (uint i= const_tables; i < prefix_size; i++)
+ {
+ JOIN_TAB *tab= positions[i].table;
+ cur_map |= tab->table->map;
+ if (TABLE_LIST *sj_nest= tab->emb_sj_nest)
+ {
+ nests_entered |= sj_nest->sj_inner_tables;
+ if (!(sj_nest->sj_inner_tables & ~cur_map))
+ {
+ // all nest tables are in the prefix already
+ nests_entered &= ~sj_nest->sj_inner_tables;
+ }
+ }
+ }
+ DBUG_ASSERT(nests_entered == cur_sj_inner_tables);
+}
+#endif
/*
Remove the last join tab from from join->cur_sj_inner_tables bitmap
- we assume remaining_tables doesnt contain @tab.
+
+ @note
+ remaining_tables contains @tab.
+
+ @seealso update_sj_state() does the reverse
*/
void restore_prev_sj_state(const table_map remaining_tables,
@@ -3570,15 +3622,30 @@ void restore_prev_sj_state(const table_map remaining_tables,
tab->join->sjm_lookup_tables &= ~subq_tables;
}
- if ((emb_sj_nest= tab->emb_sj_nest))
+ if (!tab->join->emb_sjm_nest && (emb_sj_nest= tab->emb_sj_nest))
{
+ table_map subq_tables= emb_sj_nest->sj_inner_tables &
+ ~tab->join->const_table_map;
/* If we're removing the last SJ-inner table, remove the sj-nest */
- if ((remaining_tables & emb_sj_nest->sj_inner_tables) ==
- (emb_sj_nest->sj_inner_tables & ~tab->table->map))
+ if ((remaining_tables & subq_tables) == subq_tables)
{
+ // All non-const tables of the SJ nest are in the remaining_tables.
+ // we are not in the nest anymore.
tab->join->cur_sj_inner_tables &= ~emb_sj_nest->sj_inner_tables;
}
+ else
+ {
+ // Semi-join nest has:
+ // - a table being removed (not in the prefix)
+ // - some tables in the prefix.
+ tab->join->cur_sj_inner_tables |= emb_sj_nest->sj_inner_tables;
+ }
}
+
+#ifndef DBUG_OFF
+ /* positions[idx] has been removed. Verify the state for [0...idx-1] */
+ tab->join->dbug_verify_sj_inner_tables(idx);
+#endif
}
@@ -3805,8 +3872,8 @@ void fix_semijoin_strategies_for_picked_join_order(JOIN *join)
join->best_positions[first].sj_strategy= SJ_OPT_MATERIALIZE_SCAN;
join->best_positions[first].n_sj_tables= sjm->tables;
/*
- Do what advance_sj_state did: re-run best_access_path for every table
- in the [last_inner_table + 1; pos..) range
+ Do what optimize_semi_joins did: re-run best_access_path for every
+ table in the [last_inner_table + 1; pos..) range
*/
double prefix_rec_count;
/* Get the prefix record count */
@@ -5032,7 +5099,7 @@ int setup_semijoin_loosescan(JOIN *join)
The choice between the strategies is made by the join optimizer (see
- advance_sj_state() and fix_semijoin_strategies_for_picked_join_order()).
+ optimize_semi_joins() and fix_semijoin_strategies_for_picked_join_order()).
This function sets up all fields/structures/etc needed for execution except
for setup/initialization of semi-join materialization which is done in
setup_sj_materialization() (todo: can't we move that to here also?)
diff --git a/sql/opt_subselect.h b/sql/opt_subselect.h
index d7978e9ef73..a6b26be3bb6 100644
--- a/sql/opt_subselect.h
+++ b/sql/opt_subselect.h
@@ -314,9 +314,11 @@ public:
};
-void advance_sj_state(JOIN *join, table_map remaining_tables, uint idx,
- double *current_record_count, double *current_read_time,
- POSITION *loose_scan_pos);
+void optimize_semi_joins(JOIN *join, table_map remaining_tables, uint idx,
+ double *current_record_count,
+ double *current_read_time, POSITION *loose_scan_pos);
+void update_sj_state(JOIN *join, const JOIN_TAB *new_tab,
+ uint idx, table_map remaining_tables);
void restore_prev_sj_state(const table_map remaining_tables,
const JOIN_TAB *tab, uint idx);
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index ebebb4824cd..d8154255851 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -8671,7 +8671,7 @@ ER_JSON_ESCAPING
eng "Incorrect escaping in JSON text in argument %d to function '%s' at position %d"
ER_JSON_DEPTH
chi "超过JSON嵌套深度的%d限制 参数%d 函数'%s' 位置%d的"
- eng "Limit of %d on JSON nested strucures depth is reached in argument %d to function '%s' at position %d"
+ eng "Limit of %d on JSON nested structures depth is reached in argument %d to function '%s' at position %d"
ER_JSON_PATH_EOS
chi "JSON文本路径错误 参数%d 函数'%s'"
eng "Unexpected end of JSON path in argument %d to function '%s'"
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index c3b87a13fcd..f3d853ccc06 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -8335,6 +8335,10 @@ choose_plan(JOIN *join, table_map join_tables)
{
choose_initial_table_order(join);
}
+ /*
+ Note: constant tables are already in the join prefix. We don't
+ put them into the cur_sj_inner_tables, though.
+ */
join->cur_sj_inner_tables= 0;
if (straight_join)
@@ -8648,8 +8652,8 @@ optimize_straight_join(JOIN *join, table_map join_tables)
read_time+= COST_ADD(read_time - filter_cmp_gain,
COST_ADD(position->read_time,
record_count / (double) TIME_FOR_COMPARE));
- advance_sj_state(join, join_tables, idx, &record_count, &read_time,
- &loose_scan_pos);
+ optimize_semi_joins(join, join_tables, idx, &record_count, &read_time,
+ &loose_scan_pos);
join_tables&= ~(s->table->map);
double pushdown_cond_selectivity= 1.0;
@@ -8826,6 +8830,12 @@ greedy_search(JOIN *join,
/* This has been already checked by best_extension_by_limited_search */
DBUG_ASSERT(!is_interleave_error);
+ /*
+ Also, update the semi-join optimization state. Information about the
+ picked semi-join operation is in best_pos->...picker, but we need to
+ update the global state in the JOIN object, too.
+ */
+ update_sj_state(join, best_table, idx, remaining_tables);
/* find the position of 'best_table' in 'join->best_ref' */
best_idx= idx;
@@ -9624,8 +9634,8 @@ best_extension_by_limited_search(JOIN *join,
trace_one_table.add("rows_for_plan", current_record_count);
trace_one_table.add("cost_for_plan", current_read_time);
}
- advance_sj_state(join, remaining_tables, idx, &current_record_count,
- &current_read_time, &loose_scan_pos);
+ optimize_semi_joins(join, remaining_tables, idx, &current_record_count,
+ &current_read_time, &loose_scan_pos);
/* Expand only partial plans with lower cost than the best QEP so far */
if (current_read_time >= join->best_read)
diff --git a/sql/sql_select.h b/sql/sql_select.h
index 9a6237f00a6..4de8005444c 100644
--- a/sql/sql_select.h
+++ b/sql/sql_select.h
@@ -1283,9 +1283,15 @@ public:
Bitmap of inner tables of semi-join nests that have a proper subset of
their tables in the current join prefix. That is, of those semi-join
nests that have their tables both in and outside of the join prefix.
+ (Note: tables that are constants but have not been pulled out of semi-join
+ nests are not considered part of semi-join nests)
*/
table_map cur_sj_inner_tables;
-
+
+#ifndef DBUG_OFF
+ void dbug_verify_sj_inner_tables(uint n_positions) const;
+#endif
+
/* We also maintain a stack of join optimization states in * join->positions[] */
/******* Join optimization state members end *******/
diff --git a/sql/tztime.cc b/sql/tztime.cc
index 7319084c28b..3db97ad97d6 100644
--- a/sql/tztime.cc
+++ b/sql/tztime.cc
@@ -2470,15 +2470,6 @@ MEM_ROOT tz_storage;
char fullname[FN_REFLEN + 1];
char *root_name_end;
-/*
- known file types that exist in the zoneinfo directory that are safe to
- silently skip
-*/
-const char *known_extensions[]= {
- ".tab",
- NullS
-};
-
/*
Recursively scan zoneinfo directory and print all found time zone
@@ -2575,20 +2566,19 @@ scan_tz_dir(char * name_end, uint symlink_recursion_level, uint verbose)
else
{
/*
- Some systems (like debian, opensuse etc) have description
- files (.tab). We skip these silently if verbose is > 0
+ Some systems (like Debian, openSUSE, etc) have non-timezone files:
+ * iso3166.tab
+ * leap-seconds.list
+ * leapseconds
+ * tzdata.zi
+ * zone.tab
+ * zone1970.tab
+ We skip these silently unless verbose > 0.
*/
const char *current_ext= fn_ext(fullname);
- my_bool known_ext= 0;
+ my_bool known_ext= strlen(current_ext) ||
+ !strcmp(my_basename(fullname), "leapseconds");
- for (const char **ext= known_extensions ; *ext ; ext++)
- {
- if (!strcmp(*ext, current_ext))
- {
- known_ext= 1;
- break;
- }
- }
if (verbose > 0 || !known_ext)
{
fflush(stdout);