← Back to team overview

maria-developers team mailing list archive

Re: MDEV-10000 Add EXPLAIN FOR CONNECTION syntax support

 

Hi Oleg,

> commit 8e6595cff0caa22d2bb81002505e52b5c52f5ab2
> Author: Oleg Smirnov <olernov@xxxxxxxxx>
> Date:   Tue Jan 11 20:25:11 2022 +0300
> 
>     MDEV-10000 Add EXPLAIN FOR CONNECTION syntax support
...

> diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
> index 442644eddd6..74757970411 100644
> --- a/sql/sql_yacc.yy
> +++ b/sql/sql_yacc.yy
> @@ -14121,6 +14122,15 @@ opt_describe_column:
>            }
>          ;
>  
> +explain_for_connection:
> +          describe_command FOR_SYM CONNECTION_SYM expr
> +          {
> +            Lex->sql_command= SQLCOM_SHOW_EXPLAIN;
> +            if (unlikely(prepare_schema_table(thd, Lex, 0, SCH_EXPLAIN)))
> +              MYSQL_YYABORT;
> +            add_value_to_list(thd, $4);
> +          }
> +		;
>  

This fails to intialize the statement properly. For SHOW EXPLAIN, the following
is done at statement start:

show:
          SHOW
          {
            LEX *lex=Lex;
            lex->wild=0;
            lex->ident= null_clex_str;
            if (Lex->main_select_push())
              MYSQL_YYABORT;
            mysql_init_select(lex);
            lex->current_select->parsing_place= SELECT_LIST;
            lex->create_info.init();
          }

If you don't do it, EXPLAIN FOR CONNECTION may produce crashes (e.g. on my
machine it was crash in JOIN::prepare due to
select_lex->inner_sum_func_list=0xa5a5a5a5a5).

The rest of the code looks ok. Let's have another review iteration once the
aboveis fixed.

I've also found one difference with MySQL, which I am not sure if we should fix:

In MariaDB, if the target is not running something that has an query plan, SHOW 
EXPLAIN (and now EXPLAIN FOR CONNECTION) will produce this error:

MariaDB [test]> show explain for 5;
ERROR 1933 (HY000): Target is not running an EXPLAINable command

while in MySQL it can be one of two:

1. Target is idle:
mysql> explain for connection 8;
Query OK, 0 rows affected (0.00 sec)

2. Target is running a command that's not supported:
mysql> explain for connection 8;
ERROR 3012 (HY000): EXPLAIN FOR CONNECTION command is supported only for SELECT/UPDATE/INSERT/DELETE/REPLACE

I'm not sure we should try to imitate this behavior.

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