Skip to content

[Feature Request]: explain prepared statement #14533

Closed

Description

@fengttt

Is there an existing issue for the same feature request?

  • I have checked the existing issues.

Is your feature request related to a problem?

prepare st from 'select * from t where i = ?';
set @a = 42;
execute st using @a; // runs fine

mysql> explain execute  st using @a;
ERROR 1064 (HY000): SQL parser error: You have an error in your SQL syntax; check the manual that corresponds to your MatrixOne server version for the right syntax to use. syntax error at line 1 column 25 near " using @a";
mysql>

Describe the feature you'd like

explain execute st using @A;
should print explain plan

Describe implementation you've considered

No response

Documentation, Adoption, Use Case, Migration Strategy

No response

Additional information

No response

Activity

  1. added this to the 1.2.0 milestone on Feb 4, 2024
  2. changed the title [-][Feature Request]: explain an prepared statement[/-] [+][Feature Request]: explain prepared statement[/+] on Feb 4, 2024
  3. daviszhen commented on Feb 19, 2024

    @daviszhen
    Contributor

    explain 能看 execute 的plan。之前没有。
    explain碰到execute的plan时,会将plan替换为prepare生成的plan 并替换其中的参数,最后显示出来。

    语法:

    explain force execute ...;
    explain verbose force execute ...;
    explain analyze force execute ...;
    explain analyze verbose force execute ...;

    加force关键字,是因为要与mysql兼容。mysql是不支持对execute进行explain的。
    在实现过程中,碰到explain execute 语法冲突的问题。

    • 一种解决冲突的办法是将execute 改为保留关键字。

    • 一种是在execute前面区分用的保留关键字force。

    为了与mysql保持兼容,execute没有改为保留关键字。最终选择了方案2。

    支持下面的形式:

    prepare st1 from 'select * from test.t2 where a = ? and b = ?';
    
    set @a = 1, @b=1;
    
    execute st1 using @a,@b;
    
    explain force execute st1 using @a,@b;
    
    explain verbose force execute st1 using @a,@b;
    
    explain analyze force execute st1 using @a,@b;
    
    explain analyze verbose force execute st1 using @a,@b;
    
    
    //.  === 
    
    
    prepare st2 from 'select * from test.t2 where a = 1 and b = 1';
    
    execute st2;
    
    explain force execute st2;
    
    explain verbose force execute st2;
    
    explain analyze force execute st2;
    
    explain analyze verbose force execute st2;
    
  4. Ariznawlll commented on Mar 12, 2024

    @Ariznawlll
    Collaborator

    test done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions