Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: explain prepared statement #14533

Closed
1 task done
fengttt opened this issue Feb 4, 2024 · 2 comments
Closed
1 task done

[Feature Request]: explain prepared statement #14533

fengttt opened this issue Feb 4, 2024 · 2 comments
Assignees
Milestone

Comments

@fengttt
Copy link
Contributor

fengttt commented Feb 4, 2024

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

@fengttt fengttt added this to the 1.2.0 milestone Feb 4, 2024
@fengttt fengttt changed the title [Feature Request]: explain an prepared statement [Feature Request]: explain prepared statement Feb 4, 2024
@daviszhen daviszhen mentioned this issue Feb 8, 2024
7 tasks
@daviszhen
Copy link
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;

@daviszhen daviszhen assigned fengttt and unassigned daviszhen Feb 19, 2024
@Ariznawlll
Copy link
Contributor

test done.

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

No branches or pull requests

3 participants