korlov42 commented on code in PR #2965:
URL: https://github.com/apache/ignite-3/pull/2965#discussion_r1434107511


##########
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())) {

Review Comment:
   I gave it a second thought, and indeed looks like we don't need this check. 
For implicit transaction we may wait nothing, because with implicit tx we 
always read a consistent snapshot
   
   thanks for noticing! fixed 



-- 
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]

Reply via email to