MDEV-17399: JSON_TABLE: cleanup table dependency code

- Don't touch simplify_joins()
- All dependencies caused by JSON_TABLE(...) are now added by
  add_table_function_dependencies().
This commit is contained in:
Sergei Petrunia 2021-03-15 17:03:52 +03:00 committed by Alexey Botchkov
parent 2f650fb955
commit 93daad3a1e
2 changed files with 11 additions and 5 deletions

View File

@ -1153,9 +1153,8 @@ int Table_function_json_table::setup(THD *thd, TABLE_LIST *sql_table,
if (m_dep_tables) if (m_dep_tables)
{ {
sql_table->dep_tables|= m_dep_tables;
t->no_cache= TRUE; t->no_cache= TRUE;
if (unlikely(sql_table->dep_tables & sql_table->get_map())) if (unlikely(m_dep_tables & sql_table->get_map()))
{ {
/* Table itself is used in the argument. */ /* Table itself is used in the argument. */
my_error(ER_WRONG_USAGE, MYF(0), "JSON_TABLE", "argument"); my_error(ER_WRONG_USAGE, MYF(0), "JSON_TABLE", "argument");
@ -1308,8 +1307,9 @@ static void add_extra_deps(List<TABLE_LIST> *join_list, table_map deps)
/* /*
@brief @brief
Add extra dependencies implied by table functions so that the join Add table dependencies that are directly caused by table functions, also
optimizer does not construct "dead-end" join prefixes. add extra dependencies so that the join optimizer does not construct
"dead-end" join prefixes.
@detail @detail
There are two kinds of limitations on join order: There are two kinds of limitations on join order:
@ -1321,6 +1321,9 @@ static void add_extra_deps(List<TABLE_LIST> *join_list, table_map deps)
current table in the query text. The table maybe outside of the current current table in the query text. The table maybe outside of the current
nested join and/or inside another nested join. nested join and/or inside another nested join.
One may think that adding dependency according to #2 would be sufficient,
but this is not the case.
@example @example
select ... select ...
@ -1387,7 +1390,10 @@ table_map add_table_function_dependencies(List<TABLE_LIST> *join_list,
nested_join->used_tables); nested_join->used_tables);
} }
else if (table->table_function) else if (table->table_function)
{
table->dep_tables |= table->table_function->used_tables();
res |= table->dep_tables; res |= table->dep_tables;
}
} }
res= res & ~nest_tables & ~PSEUDO_TABLE_BITS; res= res & ~nest_tables & ~PSEUDO_TABLE_BITS;
// Then, make all "peers" have them: // Then, make all "peers" have them:

View File

@ -16546,7 +16546,7 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top,
if (table->outer_join && !table->embedding && table->table) if (table->outer_join && !table->embedding && table->table)
table->table->maybe_null= FALSE; table->table->maybe_null= FALSE;
table->outer_join= 0; table->outer_join= 0;
if (!(straight_join || table->straight || table->table_function)) if (!(straight_join || table->straight))
{ {
table->dep_tables= 0; table->dep_tables= 0;
TABLE_LIST *embedding= table->embedding; TABLE_LIST *embedding= table->embedding;