-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
planner,executor,parser: support the plan cache for prepared insert/delete/update statements #8107
planner,executor,parser: support the plan cache for prepared insert/delete/update statements #8107
Conversation
Hi contributor, thanks for your PR. This patch needs to be approved by someone of admins. They should reply with "/ok-to-test" to accept this PR for running test automatically. |
/run-all-tests |
@dbjoa Thanks! |
/run-common-test |
node, ok := n.Table.Accept(v) | ||
if !ok { | ||
return n, false | ||
if n.Table != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please give an example where n.Table
is nil in INSERT
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know a real example. The code is to pass the test case below .
https://github.com/pingcap/tidb/blob/6fbb42d22bdfdbe4822174c44430b64f7946b73f/planner/core/cacheable_checker_test.go#L41-L42
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, then this code change is unreasonable IMHO. By the way, I learned that since we have moved parser to a separate repository, we need to file a PR in https://github.com/pingcap/parser if we want to make changes, and then make update
in tidb repo.
The failed common-test can be simplified to this test case: import java.sql.*;
class TiDBTestConnector {
public static void main(String args[]){
try{
ResultSet rs;
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:4000/test?useServerPrepStmts=true","root","");
//createTable("testExecuteLargeBatch", "(id BIGINT AUTO_INCREMENT PRIMARY KEY, n INT)");
PreparedStatement stmt = con.prepareStatement("INSERT INTO testExecuteLargeBatch (n) VALUES (?)", Statement.RETURN_GENERATED_KEYS);
stmt.setInt(1, 1);
stmt.addBatch();
stmt.setInt(1, 2);
stmt.addBatch();
stmt.setInt(1, 3);
stmt.addBatch();
stmt.setInt(1, 4);
stmt.addBatch();
stmt.addBatch("INSERT INTO testExecuteLargeBatch (n) VALUES (5), (6), (7)");
stmt.setString(1, "eight");
stmt.addBatch();
stmt.addBatch("INSERT INTO testExecuteLargeBatch (n) VALUES (9), (10)");
try {
stmt.executeLargeBatch();
System.out.println("error, should raise exception");
} catch (BatchUpdateException e) {
String err = "Incorrect int value: 'eight' for column 'n' at row 1";
if (!err.equals(e.getMessage())) {
System.out.println("wrong error message: " + e.getMessage());
}
}
System.out.println("finished");
con.close();
}catch(Exception e) { System.out.println(e); }
}
} when plan cache is enabled, the error message returned is wrong: |
@eurekaka, Thank you for the test case. I'll come back after fixing the failure. |
@eurekaka, The updated PR should fix the test failure. |
/run-all-tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
planner/core/common_plans.go
Outdated
@@ -192,6 +193,7 @@ func (e *Execute) getPhysicalPlan(ctx sessionctx.Context, is infoschema.InfoSche | |||
if err != nil { | |||
return nil, errors.Trace(err) | |||
} | |||
log.Errorf("hit: %+v", ToString(plan)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why here use the level of “Error”?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the comment. The PR should remove the debugging code. I'll delete the line from the updated PR.
planner/core/cacheable_checker.go
Outdated
@@ -21,7 +21,12 @@ import ( | |||
|
|||
// Cacheable checks whether the input ast is cacheable. | |||
func Cacheable(node ast.Node) bool { | |||
if _, isSelect := node.(*ast.SelectStmt); !isSelect { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we remove this blank line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the comment. I'll delete the line from the updated PR.
…elete/update statements
/run-all-tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really great work! Rest LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What problem does this PR solve?
Support the plan cache for the prepared insert/delete/update statements
What is changed and how it works?
Check List
Tests
Code changes
Side effects
Related changes