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

Prepare Statement Improvement #3140

Merged
merged 2 commits into from
Mar 28, 2024
Merged

Prepare Statement Improvement #3140

merged 2 commits into from
Mar 28, 2024

Conversation

hououou
Copy link
Collaborator

@hououou hououou commented Mar 26, 2024

see #3065

A little different implementation: for a query statement, we always need to prepare, and we will start a transaction.

  • we will commit the transaction opened in prepare if prepare() is a standalone call. (requiredNewTx=true)
  • we will not commit the transaction opened in prepare() called in query(). In query() , execute() is always followed with prepare(), we will close the transaction in execute(). (requiredNewTx=false)

Similar logic is used in execute().

src/main/connection.cpp Outdated Show resolved Hide resolved
src/main/connection.cpp Show resolved Hide resolved
src/include/binder/expression/parameter_expression.h Outdated Show resolved Hide resolved
src/common/types/value/value.cpp Outdated Show resolved Hide resolved
src/include/main/client_context.h Outdated Show resolved Hide resolved
src/main/client_context.cpp Outdated Show resolved Hide resolved
src/main/client_context.cpp Outdated Show resolved Hide resolved
test/main/prepare_test.cpp Outdated Show resolved Hide resolved
src/main/client_context.cpp Outdated Show resolved Hide resolved
src/main/client_context.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@andyfengHKU andyfengHKU left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me. You can merge if the CI passes.

@@ -323,6 +345,9 @@ std::unique_ptr<PreparedStatement> ClientContext::prepareNoLock(
} else {
preparedStatement->logicalPlans = std::move(plans);
}
if (transactionContext->isAutoTransaction() && requireNewTx) {
this->transactionContext->commit();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we have a similar check when rollback?

if (!preparedStatement->isSuccess()) {
return queryResultWithError(preparedStatement->errMsg);
}
if (preparedStatement->preparedSummary.statementType != common::StatementType::TRANSACTION &&
this->getTx() == nullptr) {
if (preparedStatement->parsedStatement->requireTx() && requiredNexTx && getTx() == nullptr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can u branch out from this branch and try commit after prepare and we open a new transaction during execute. In this design, we should no longer need to pass requiredNexTx

Copy link

codecov bot commented Mar 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.07%. Comparing base (73ed1ea) to head (d45ac3d).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3140      +/-   ##
==========================================
- Coverage   92.08%   92.07%   -0.01%     
==========================================
  Files        1168     1168              
  Lines       44065    44091      +26     
==========================================
+ Hits        40577    40597      +20     
- Misses       3488     3494       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@hououou hououou marked this pull request as ready for review March 28, 2024 02:41
@hououou hououou merged commit 015bf23 into master Mar 28, 2024
17 checks passed
@hououou hououou deleted the prepare_statement branch March 28, 2024 03:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants