lowka commented on code in PR #4221: URL: https://github.com/apache/ignite-3/pull/4221#discussion_r1719591615
########## modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/SelectCountPlannerTest.java: ########## @@ -0,0 +1,366 @@ +/* + * 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.planner; + +import static java.util.stream.Collectors.toList; +import static org.apache.ignite.internal.testframework.IgniteTestUtils.await; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.ArrayList; +import java.util.List; +import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.rex.RexNode; +import org.apache.ignite.internal.catalog.CatalogCommand; +import org.apache.ignite.internal.catalog.commands.DropTableCommand; +import org.apache.ignite.internal.catalog.descriptors.CatalogTableDescriptor; +import org.apache.ignite.internal.sql.SqlCommon; +import org.apache.ignite.internal.sql.engine.framework.TestBuilders; +import org.apache.ignite.internal.sql.engine.framework.TestCluster; +import org.apache.ignite.internal.sql.engine.framework.TestNode; +import org.apache.ignite.internal.sql.engine.prepare.QueryPlan; +import org.apache.ignite.internal.sql.engine.prepare.SelectCountPlan; +import org.apache.ignite.internal.testframework.SystemPropertiesExtension; +import org.apache.ignite.internal.testframework.WithSystemProperty; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * Tests to verify SELECT COUNT(*) optimized plans. + */ +@ExtendWith(SystemPropertiesExtension.class) +public class SelectCountPlannerTest extends AbstractPlannerTest { + + private static final String NODE_NAME = "N1"; + + private static final TestCluster CLUSTER = TestBuilders.cluster() + .nodes(NODE_NAME) + .build(); + + private final TestNode node = CLUSTER.node(NODE_NAME); + + @BeforeAll + static void start() { + CLUSTER.start(); + } + + @AfterAll + static void stop() throws Exception { + CLUSTER.stop(); + } + + @AfterEach + void clearCatalog() { + int version = CLUSTER.catalogManager().latestCatalogVersion(); + + List<CatalogCommand> commands = new ArrayList<>(); + for (CatalogTableDescriptor table : CLUSTER.catalogManager().tables(version)) { + commands.add( + DropTableCommand.builder() + .schemaName(SqlCommon.DEFAULT_SCHEMA_NAME) + .tableName(table.name()) + .build() + ); + } + + await(CLUSTER.catalogManager().execute(commands)); + } + + @Test + public void optimizeCountStar() { + node.initSchema("CREATE TABLE test (id INT PRIMARY KEY, val INT)"); + + QueryPlan plan = node.prepare("SELECT count(*) FROM test"); + + assertThat(plan, instanceOf(SelectCountPlan.class)); + assertExpressions((SelectCountPlan) plan, "$0"); Review Comment: An optimised plan for `SELECT count(*) FROM t` looks like this: > Input: [col_estimated_table_size] ( a column contains a result of estimateSize) > ...Projection expressions=[single_col] (we do not have a projection node, but we have an expression list, that compiles to a projection). I can build an expression list that looks exactly the same as expressions in a select list, if you like. -- 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]
