← Back to team overview

maria-developers team mailing list archive

Re: MDEV-17399: JSON_TABLE's dependency check is incomplete


On Mon, Feb 08, 2021 at 08:34:15PM +0300, Sergey Petrunia wrote:
> I see that for other tables, TABLE_LIST::dep_tables is computed in
> simplify_joins(). simplify_joins() can remove table dependencies if it
> converts an outer join into inner.
> Can it somehow remove a dependency of JSON_TABLE(...) on its argument?
> I haven't been able to construct such case.
> (An obvious reason one cannot easily do this is that JSON_TABLE() doesn't
> allow to declare NOT NULL columns. I'm not sure if this a fundamental 
> limitation or something random).
> I think the very least that should be done is to make a comment about 
> this in simplify_joins().

Debugging further, I see that TABLE_LIST::dep_tables only includes
"direct" dependencies. 
That is, for 

   t1 left join (t2, t3 ) ON ...

t2->dep_tables=0 and t1->dep_tables=0, both before and after simplify_joins().
After simplify_joins, t2->embedding->dep_tables={t1}, same for t3.

Well, this means the check for dependencies is incomplete.

Trying to construct a testcase for this:

create table t2 (a int not null, b int not null);
create table t3 (a int not null, b int not null);
create table t4 (a int not null, js json);

select * 
  json_table(t4.js, '$[*]' columns (o for ordinality)) as jt  
  left join (t4, t3) on js.o=t4.a ;

this crashes, the stack tace is below.

Please wait with fixing this. I think the fix here should be to adjust the name
resolution so that this query doesn't pass the name resolution phase.

  Thread 17 "mysqld" received signal SIGSEGV, Segmentation fault.
  0x0000555555e41206 in TABLE_LIST::get_map (this=0x7ffe9c017e00) at sql/table.h:2286
(gdb) wher
  #0  0x0000555555e41206 in TABLE_LIST::get_map (this=0x7ffe9c017e00) at sql/table.h:2286
  #1  0x00005555560f26f5 in Table_function_json_table::setup (this=0x7ffe9c015918, thd=0x7ffe9c000d78, sql_table=0x7ffe9c0168f8) at sql/table_function.cc:1088
  #2  0x0000555555ea7e16 in JOIN::prepare (this=0x7ffe9c01a2f0, tables_init=0x7ffe9c0168f8, conds_init=0x0, og_num=0, order_init=0x0, skip_order_by=false, group_init=0x0, having_init=0x0, proc_param_init=0x0, select_lex_arg=0x7ffe9c015210, unit_arg=0x7ffe9c004f18) at sql/sql_select.cc:1263
  #3  0x0000555555eb4a2a in mysql_select (thd=0x7ffe9c000d78, tables=0x7ffe9c0168f8, fields=..., conds=0x0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748612, result=0x7ffe9c019bd0, unit=0x7ffe9c004f18, select_lex=0x7ffe9c015210) at sql/sql_select.cc:4643
  #4  0x0000555555ef34e8 in mysql_explain_union (thd=0x7ffe9c000d78, unit=0x7ffe9c004f18, result=0x7ffe9c019bd0) at sql/sql_select.cc:27235
  #5  0x0000555555e6775e in execute_sqlcom_select (thd=0x7ffe9c000d78, all_tables=0x7ffe9c0168f8) at sql/sql_parse.cc:6211
  #6  0x0000555555e5eb75 in mysql_execute_command (thd=0x7ffe9c000d78) at sql/sql_parse.cc:3968

Sergei Petrunia, Software Developer
MariaDB Corporation | Skype: sergefp | Blog: http://petrunia.net