zstan commented on code in PR #5211: URL: https://github.com/apache/ignite-3/pull/5211#discussion_r1961022672
########## modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/SelectRowCountEstimationTest.java: ########## @@ -0,0 +1,195 @@ +/* + * 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 org.apache.ignite.internal.sql.engine.framework.DataProvider.fromCollection; +import static org.apache.ignite.internal.sql.engine.framework.TestBuilders.tableScan; +import static org.apache.ignite.internal.sql.engine.metadata.IgniteMdSelectivity.COMPARISON_SELECTIVITY; +import static org.apache.ignite.internal.sql.engine.metadata.IgniteMdSelectivity.EQ_SELECTIVITY; +import static org.apache.ignite.internal.sql.engine.metadata.IgniteMdSelectivity.IS_NOT_NULL_SELECTIVITY; +import static org.apache.ignite.internal.sql.engine.util.QueryChecker.nodeRowCount; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import org.apache.ignite.internal.lang.IgniteStringBuilder; +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.util.TpcTable; +import org.apache.ignite.internal.sql.engine.util.tpcds.TpcdsTables; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Tests to check row count estimation for select relation. + */ +public class SelectRowCountEstimationTest extends BaseRowsProcessedEstimationTest { + private static final int TABLE_REAL_SIZE = 73_049; + + private static final TestCluster CLUSTER = TestBuilders.cluster() + .nodes("N1") + .defaultAssignmentsProvider(tableName -> (partNum, includeBackups) -> IntStream.range(0, partNum) + .mapToObj(part -> List.of("N1")) + .collect(Collectors.toList()) + ) + .defaultDataProvider(tableName -> tableScan(fromCollection(List.of()))) + .build(); + + private static final TestNode NODE = CLUSTER.node("N1"); + + @BeforeAll + static void startCluster() { + CLUSTER.start(); + + for (TpcTable table : List.of(TpcdsTables.CATALOG_SALES)) { + NODE.initSchema(table.ddlScript()); + } + + CLUSTER.setTableSize("CATALOG_SALES", TABLE_REAL_SIZE); + } + + @AfterAll + static void stopCluster() throws Exception { + CLUSTER.stop(); + } + + @Test + void testConditionWithPk() { + // partial pk Review Comment: you right, done ########## modules/sql-engine/src/test/java/org/apache/ignite/internal/sql/engine/planner/SelectRowCountEstimationTest.java: ########## @@ -0,0 +1,195 @@ +/* + * 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 org.apache.ignite.internal.sql.engine.framework.DataProvider.fromCollection; +import static org.apache.ignite.internal.sql.engine.framework.TestBuilders.tableScan; +import static org.apache.ignite.internal.sql.engine.metadata.IgniteMdSelectivity.COMPARISON_SELECTIVITY; +import static org.apache.ignite.internal.sql.engine.metadata.IgniteMdSelectivity.EQ_SELECTIVITY; +import static org.apache.ignite.internal.sql.engine.metadata.IgniteMdSelectivity.IS_NOT_NULL_SELECTIVITY; +import static org.apache.ignite.internal.sql.engine.util.QueryChecker.nodeRowCount; + +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; +import org.apache.ignite.internal.lang.IgniteStringBuilder; +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.util.TpcTable; +import org.apache.ignite.internal.sql.engine.util.tpcds.TpcdsTables; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +/** + * Tests to check row count estimation for select relation. + */ +public class SelectRowCountEstimationTest extends BaseRowsProcessedEstimationTest { + private static final int TABLE_REAL_SIZE = 73_049; + + private static final TestCluster CLUSTER = TestBuilders.cluster() + .nodes("N1") + .defaultAssignmentsProvider(tableName -> (partNum, includeBackups) -> IntStream.range(0, partNum) + .mapToObj(part -> List.of("N1")) + .collect(Collectors.toList()) + ) + .defaultDataProvider(tableName -> tableScan(fromCollection(List.of()))) + .build(); + + private static final TestNode NODE = CLUSTER.node("N1"); + + @BeforeAll + static void startCluster() { + CLUSTER.start(); + + for (TpcTable table : List.of(TpcdsTables.CATALOG_SALES)) { + NODE.initSchema(table.ddlScript()); + } + + CLUSTER.setTableSize("CATALOG_SALES", TABLE_REAL_SIZE); + } + + @AfterAll + static void stopCluster() throws Exception { + CLUSTER.stop(); + } + + @Test + void testConditionWithPk() { + // partial pk + double selectivityFactor = EQ_SELECTIVITY; + assertQuery(NODE, "SELECT * FROM CATALOG_SALES WHERE CS_ITEM_SK = 1") + .matches(nodeRowCount("TableScan", approximatelyEqual(TABLE_REAL_SIZE * selectivityFactor))) + .check(); + + // full pk, eq operations + selectivityFactor = 1.0 / TABLE_REAL_SIZE; + assertQuery(NODE, "SELECT * FROM CATALOG_SALES WHERE CS_ITEM_SK = 1 AND CS_ORDER_NUMBER = 1") + .disableRules("TableScanToKeyValueGetRule", "LogicalIndexScanConverterRule") + .matches(nodeRowCount("TableScan", approximatelyEqual(TABLE_REAL_SIZE * selectivityFactor))) + .check(); + + // full pk, comp operations + selectivityFactor = EQ_SELECTIVITY * COMPARISON_SELECTIVITY; + assertQuery(NODE, "SELECT * FROM CATALOG_SALES WHERE CS_ITEM_SK = 1 AND CS_ORDER_NUMBER > 1") + .disableRules("TableScanToKeyValueGetRule", "LogicalIndexScanConverterRule") + .matches(nodeRowCount("TableScan", approximatelyEqual(TABLE_REAL_SIZE * selectivityFactor))) + .check(); + + // full pk with OR + selectivityFactor = EQ_SELECTIVITY; + assertQuery(NODE, "SELECT * FROM CATALOG_SALES WHERE (CS_ITEM_SK = 1 AND CS_ORDER_NUMBER = 1) OR CS_ORDER_NUMBER = 2") + .disableRules("TableScanToKeyValueGetRule", "LogicalIndexScanConverterRule") + .matches(nodeRowCount("TableScan", approximatelyEqual(TABLE_REAL_SIZE * selectivityFactor))) + .check(); + + // full pk or full pk + selectivityFactor = 1.0 / TABLE_REAL_SIZE; + assertQuery(NODE, "SELECT * FROM CATALOG_SALES WHERE (CS_ITEM_SK = 1 AND CS_ORDER_NUMBER = 1) " + + "OR (CS_ITEM_SK = 3 AND CS_ORDER_NUMBER = 3)") + .disableRules("TableScanToKeyValueGetRule", "LogicalIndexScanConverterRule") + .matches(nodeRowCount("TableScan", approximatelyEqual(TABLE_REAL_SIZE * selectivityFactor))) + .check(); + + // full pk with computation, not covered by now + selectivityFactor = EQ_SELECTIVITY; + assertQuery(NODE, "SELECT * FROM CATALOG_SALES WHERE CS_ORDER_NUMBER + CS_ITEM_SK = 1") + .matches(nodeRowCount("TableScan", approximatelyEqual(TABLE_REAL_SIZE * selectivityFactor))) + .check(); + } + + @Test + void testPredicatesSelectivity() { Review Comment: done -- 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: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org