korlov42 commented on code in PR #2965:
URL: https://github.com/apache/ignite-3/pull/2965#discussion_r1434114962
##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/SqlQueryProcessor.java:
##########
@@ -835,7 +851,42 @@ CompletableFuture<AsyncSqlCursor<InternalSqlRow>>
processNext() {
// Try to rollback script managed transaction, if any.
txCtx.rollbackUncommitted();
} else {
- taskExecutor.execute(this::processNext);
+ CompletableFuture<Void> triggerFuture;
+ ScriptStatement nextStatement = statements.peek();
+
+ if (txWrapper == null) {
+ // tx is started already, no need to wait
+ triggerFuture = nullCompletedFuture();
+ } else if (txWrapper.implicit()) {
+ if (cursor.queryType() != SqlQueryType.QUERY) {
+ // any query apart from type of QUERY returns
at most a single row, so
+ // it should be safe to commit transaction
prematurely after receiving
+ // `firstPageReady` signal, since all sources
have been processed
+ triggerFuture =
cursor.onFirstPageReady().thenCompose(none -> txWrapper.commitImplicit());
+ } else if (nextStatement != null
+ &&
readOnlyQuery(nextStatement.parsedResult.queryType())) {
+ // if next statement only reads data, no need
to wait
+ triggerFuture = nullCompletedFuture();
+ } else {
+ triggerFuture = cursor.onFirstPageReady();
+ }
+ } else {
+ if (readOnlyQuery(cursor.queryType())
+ && nextStatement != null
+ &&
readOnlyQuery(nextStatement.parsedResult.queryType())) {
Review Comment:
> why we need to wait for the prefetch of the last SELECT?
with explicit tx things a bit trickier here: we have no isolation within the
same transaction, meaning you can even see results from operation itself (for
instance, a query `INSERT INTO t SELECT * FROM t may insert more rows then it
was prior to statement execution).With that said, we have to make sure that DML
is started not earlier than first pages of SELECT statements prior to that DML
become ready.
I've added tracking of such in-flight selects
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]