korlov42 commented on code in PR #4221: URL: https://github.com/apache/ignite-3/pull/4221#discussion_r1729002580
########## modules/sql-engine/src/integrationTest/java/org/apache/ignite/internal/sql/engine/ItSqlUsesSelectCountOptimizedTest.java: ########## @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.sql.engine; + +import org.apache.ignite.internal.sql.BaseSqlIntegrationTest; +import org.apache.ignite.internal.sql.engine.util.QueryChecker; +import org.apache.ignite.internal.testframework.SystemPropertiesExtension; +import org.apache.ignite.internal.testframework.WithSystemProperty; +import org.apache.ignite.internal.tx.InternalTransaction; +import org.apache.ignite.tx.Transaction; +import org.apache.ignite.tx.TransactionOptions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * Tests for SELECT COUNT(*) optimization. + */ +@ExtendWith(SystemPropertiesExtension.class) +public class ItSqlUsesSelectCountOptimizedTest extends BaseSqlIntegrationTest { + + @BeforeAll + @SuppressWarnings("ConcatenationWithEmptyString") + static void initSchema() { + CLUSTER.aliveNode().sql().executeScript("" + + "CREATE TABLE test (id INT PRIMARY KEY, val INT);" + + "INSERT INTO test SELECT x, x FROM TABLE(system_range(1, 10));"); + } + + @Test + public void countOpt() { Review Comment: let's also add a few cases to check metadata (name of the columns returned, to be more precise). It would be nice to make sure name of the columns are the same with or without explicit aliasing comparing to execution path with disabled optimization ########## modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/PrepareServiceImpl.java: ########## @@ -248,16 +252,20 @@ public CompletableFuture<QueryPlan> prepareAsync( ); } - private CompletableFuture<QueryPlan> prepareAsync0(ParsedResult parsedResult, PlanningContext planningContext) { + private CompletableFuture<QueryPlan> prepareAsync0( + ParsedResult parsedResult, + PlanningContext planningContext, + @Nullable QueryTransactionContext txContext Review Comment: to avoid such an avalanche changes with every new param, there is `PlanningContext`. Let's just add `explicitTx` flag to planning context ########## modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/prepare/PlannerHelper.java: ########## @@ -343,4 +357,228 @@ static boolean hasSubQuery(SqlNode node) { return super.visit(call); } } + + /** + * Whether we can optimize a query that looks like {@code SELECT count(*)} or not. + * If this method returns {@code true}, then {@link #tryOptimizeSelectCount(IgnitePlanner, QueryTransactionContext, SqlNode)} Review Comment: ```suggestion * * <p>If this method returns {@code true}, then {@link #tryOptimizeSelectCount(IgnitePlanner, QueryTransactionContext, SqlNode)} ``` -- 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]
