diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/AbstractTpcQueryPlannerTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/AbstractTpcQueryPlannerTest.java new file mode 100644 index 0000000000000..cda55b8ca0d2f --- /dev/null +++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/AbstractTpcQueryPlannerTest.java @@ -0,0 +1,182 @@ +/* + * 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.processors.query.calcite.planner.tpc; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.apache.calcite.plan.RelOptUtil; +import org.apache.calcite.sql.SqlExplainLevel; +import org.apache.ignite.cache.query.annotations.QuerySqlFunction; +import org.apache.ignite.calcite.CalciteQueryEngineConfiguration; +import org.apache.ignite.configuration.CacheConfiguration; +import org.apache.ignite.configuration.IgniteConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgnitionEx; +import org.apache.ignite.internal.processors.query.calcite.CalciteQueryProcessor; +import org.apache.ignite.internal.processors.query.calcite.planner.AbstractPlannerTest; +import org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.AfterPlansTest; +import org.apache.ignite.internal.processors.query.calcite.planner.tpc.PlanChecker.BeforePlansTest; +import org.apache.ignite.internal.processors.query.calcite.schema.IgniteSchema; +import org.apache.ignite.testframework.GridTestUtils; +import org.junit.Test; +import org.junit.runners.Parameterized; + +import static org.apache.ignite.internal.processors.query.calcite.planner.tpc.TpchHelper.loadFromResource; +import static org.apache.ignite.internal.processors.query.calcite.planner.tpc.TpchHelper.scriptToQueries; +import static org.apache.ignite.internal.processors.query.calcite.planner.tpc.TpchHelper.sql; +import static org.apache.ignite.internal.processors.query.calcite.planner.tpc.TpchHelper.sqlTestName; + +/** + * Abstract test class to ensure a planner generates expected plan for TPC queries. + */ +public class AbstractTpcQueryPlannerTest extends AbstractPlannerTest { + /** Set to {@code true} to write plan files, instead of checking. */ + private static final boolean UPDATE_PLAN = false; + + /** Server node to run queries on. */ + private static IgniteEx srv; + + /** Query id. Set by {@link PlanChecker}. */ + @Parameterized.Parameter + public String queryId; + + /** Run once, before all queries check. */ + @BeforePlansTest + public static void startAll(Class testClass) throws Exception { + AbstractTpcQueryPlannerTest mock = new AbstractTpcQueryPlannerTest(); + + mock.beforeFirstTest(); + + IgniteConfiguration cfg = mock.getConfiguration("server"); + + cfg.getSqlConfiguration() + .setQueryEnginesConfiguration(new CalciteQueryEngineConfiguration().setDefault(true)); + + srv = (IgniteEx)IgnitionEx.start(cfg); + + srv.getOrCreateCache(new CacheConfiguration<>("mock") + .setSqlFunctionClasses(AbstractTpcQueryPlannerTest.TpchUDF.class) + .setSqlSchema("PUBLIC")); + + TpchHelper.testFiles(testClass, "ddl") + .filter(p -> p.toString().endsWith(".sql")) + .map(p -> loadFromResource(p.toString())) + .forEach(ddl -> scriptToQueries(ddl).forEach(q -> sql(srv, q))); + } + + /** Run once, after all queries check. */ + @AfterPlansTest + public static void stopAll(Class testClass) { + if (srv != null) { + srv.close(); + + srv = null; + } + } + + /** Test single query. */ + @Test + public void testQuery() { + String actualPlan = queryPlan(); + + if (UPDATE_PLAN) { + updatePlan(actualPlan); + + return; + } + + boolean match = false; + + String expPlan = TpchHelper.replaceIdAndHash(loadFromResource(String.format("%s/%s.plan", sqlTestName(getClass()), queryId))); + + for (String possiblePlan : TpchHelper.expandTemplates(expPlan)) { + if (possiblePlan.equals(actualPlan)) { + match = true; + + break; + } + } + + if (!match) { + // This assertion will print nice diff in IDE that will help to investigate. + // Test will fail anyway. + assertEquals(expPlan, actualPlan); + + assert false : "Should not happen"; + } + } + + /** {@inheritDoc} */ + @Override protected boolean isSafeTopology() { + return false; + } + + /** */ + private String queryPlan() { + CalciteQueryProcessor engine = (CalciteQueryProcessor)srv.context().query().defaultQueryEngine(); + + Map schemas = GridTestUtils.getFieldValue(engine.schemaHolder(), "igniteSchemas"); + + List res = scriptToQueries(loadFromResource(sqlTestName(getClass()) + "/" + queryId + ".sql")).stream().map(qry -> { + try { + return RelOptUtil.toString(physicalPlan(plannerCtx(qry, schemas.values(), null)), SqlExplainLevel.ALL_ATTRIBUTES); + } + catch (Exception e) { + throw new RuntimeException(e); + } + }) + .map(TpchHelper::replaceIdAndHash) + .collect(Collectors.toList()); + + assertEquals(1, res.size()); + + return res.get(0); + } + + /** */ + private void updatePlan(String newPlan) { + Path targetDir = Path.of("./src/test/resources/" + sqlTestName(getClass())); + + // A targetDirectory must be specified by hand when expected plans are generated. + if (targetDir == null) { + throw new RuntimeException("Please provide target directory to where save generated plans." + + " Usually plans are kept in resource folder of tests within the same module."); + } + + try { + Files.createDirectories(targetDir); + + Files.writeString(targetDir.resolve(String.format("%s.plan", queryId)), newPlan); + } + catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** */ + public static class TpchUDF { + /** */ + @QuerySqlFunction(alias = "SUBSTR") + public static String substr(String str, int from, int cnt) { + return str.substring(from, from + cnt); + } + } +} diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/PlanChecker.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/PlanChecker.java new file mode 100644 index 0000000000000..9ed63bc401cf2 --- /dev/null +++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/PlanChecker.java @@ -0,0 +1,122 @@ +/* + * 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.processors.query.calcite.planner.tpc; + +import java.io.IOException; +import java.lang.annotation.Annotation; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.junit.runner.Runner; +import org.junit.runner.notification.RunNotifier; +import org.junit.runners.Suite; +import org.junit.runners.model.InitializationError; +import org.junit.runners.model.TestClass; +import org.junit.runners.parameterized.BlockJUnit4ClassRunnerWithParameters; +import org.junit.runners.parameterized.TestWithParameters; + +/** + * Suite to check queries plans. + * Makes pretty test names to simplify CI tracking. + */ +public class PlanChecker extends Suite { + /** + * Only called reflectively. Do not use programmatically. + */ + public PlanChecker(Class klass) throws Throwable { + super(klass, createRunnersForParameters(new TestClass(klass)).collect(Collectors.toList())); + } + + /** */ + private static Stream createRunnersForParameters(TestClass testClass) throws IOException { + Stream queries = TpchHelper.testFiles(testClass.getJavaClass()) + .filter(p -> p.toString().endsWith(".sql")) + .sorted() + .map(p -> p.getFileName().toString().replace(".sql", "")); + + return queries + .map(qryId -> new TestWithParameters("[queryId=" + qryId + "]", testClass, Collections.singletonList(qryId))) + .map(test -> { + try { + return new BlockJUnit4ClassRunnerWithParameters(test); + } + catch (InitializationError e) { + throw new RuntimeException(e); + } + }); + } + + /** {@inheritDoc} */ + @Override public void run(RunNotifier notifier) { + runAnnotated(BeforePlansTest.class); + + try { + super.run(notifier); + } + finally { + runAnnotated(AfterPlansTest.class); + } + } + + /** Runs static void method of test class annotated with the specific annotation. */ + private void runAnnotated(Class annotation) { + getTestClass().getAnnotatedMethods(annotation).forEach(m -> { + List errors = new ArrayList<>(); + + m.validatePublicVoid(true, errors); + + try { + if (!errors.isEmpty()) + throw errors.get(0); + + m.invokeExplosively(getTestClass().getJavaClass(), getTestClass().getJavaClass()); + } + catch (Throwable e) { + throw new RuntimeException(e); + } + }); + } + + /** */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.TYPE) + public @interface PlansTest { + /** @return Test name. */ + String name() default ""; + } + + /** */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + public @interface BeforePlansTest { + // No-op. + } + + /** */ + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + public @interface AfterPlansTest { + // No-op. + } +} diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/TpchHelper.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/TpchHelper.java new file mode 100644 index 0000000000000..be23cd08d0a16 --- /dev/null +++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/TpchHelper.java @@ -0,0 +1,265 @@ +/* + * 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.processors.query.calcite.planner.tpc; + +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UncheckedIOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Scanner; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import com.google.common.io.CharStreams; +import org.apache.ignite.Ignite; +import org.apache.ignite.cache.query.FieldsQueryCursor; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.internal.IgniteEx; + +/** + * Provides utility methods to work with queries defined by the TPC-H benchmark. + */ +public final class TpchHelper { + /** */ + private static final Pattern ID_PATTERN = Pattern.compile(", id = \\d+"); + + /** */ + private static final Pattern HASH_PATTERN = Pattern.compile(", hash=-?\\d+]"); + + /** */ + private static final String RSRC_DIR = "./src/test/resources"; + + /** */ + private TpchHelper() { + } + + /** */ + public static Stream testFiles(Class klass) throws IOException { + return testFiles(klass, ""); + } + + /** */ + public static Stream testFiles(Class klass, String exdDir) throws IOException { + return Files.list(Path.of(RSRC_DIR, sqlTestName(klass), exdDir)); + } + + /** + * Loads resource with given name as string. + * + * @param resource Name of the resource to load. + * @return Resource as string. + */ + public static String loadFromResource(String resource) { + if (resource.startsWith(RSRC_DIR)) + resource = resource.substring(RSRC_DIR.length() + 1); + + try (InputStream is = TpchHelper.class.getClassLoader().getResourceAsStream(resource)) { + if (is == null) + throw new IllegalArgumentException("Resource does not exist: " + resource); + + try (InputStreamReader reader = new InputStreamReader(is, StandardCharsets.UTF_8)) { + return CharStreams.toString(reader); + } + } + catch (IOException e) { + throw new UncheckedIOException("I/O operation failed: " + resource, e); + } + } + + /** @return SQL test name. */ + public static String sqlTestName(Class klass) { + PlanChecker.PlansTest desc = plansTest(klass); + + if (desc.name().isEmpty()) + throw new IllegalStateException("Please, set test name with the @PlanTest(name=\"XXX\")"); + + return desc.name(); + } + + /** @return Test description annotation. */ + private static PlanChecker.PlansTest plansTest(Class klass) { + PlanChecker.PlansTest desc = klass.getAnnotation(PlanChecker.PlansTest.class); + + if (desc == null) + throw new IllegalStateException("Test class must be annotated with @" + PlanChecker.PlansTest.class.getSimpleName()); + + return desc; + } + + /** + * Execute SQL query. + * + * @param ignite Ignite. + * @param sql SQL query. + * @param params Query parameters. + */ + public static List> sql(Ignite ignite, String sql, Object... params) { + SqlFieldsQuery qry = new SqlFieldsQuery(sql).setArgs(params); + + try (FieldsQueryCursor> cur = ((IgniteEx)ignite).context().query().querySqlFields(qry, false)) { + return cur.getAll(); + } + } + + /** + * Supported templates: + *
    + *
  • {@code ", id = 123} replaced with the {@code ", id = {id}}
  • + *
  • {@code ", hash=123} replaced with the {@code ", hash={hash}}
  • + *
  • {@code "{INDEX_CASE:IDX1,IDX2}} expands to the plans where {INDEX_CASE....} replaced with each of the index from list.
  • + *
  • {@code "{ONEOF}} start and finish with the {@code {ONEOF}} tag. Cases separated with the line "=====". + * Creates as many plans as there are cases. + *
  • + *
+ * + * @param plan Plan with templates + * @return Expanded (templates replaced with the possible values). One of the plan must be equal to the one created by Ignite node. + */ + public static List expandTemplates(String plan) { + return expandOneof(plan).stream() + .flatMap(TpchHelper::expandIndexCase) + .collect(Collectors.toList()); + } + + /** Expands plans. Replace {INDEX_CASE} tag with the possible indexes. */ + private static Stream expandIndexCase(String plan) { + List res = new ArrayList<>(); + + res.add(plan); + + while (true) { + String idxCaseStart = "{INDEX_CASE:"; + + if (res.get(0).contains(idxCaseStart)) { + res = res.stream().flatMap(p -> { + int start = p.indexOf(idxCaseStart); + int end = p.indexOf('}', start); + + assert start != -1 && end != -1; + + String[] idxs = p.substring(start + idxCaseStart.length(), end).split(","); + + return Arrays.stream(idxs).map(idx -> p.substring(0, start) + idx + p.substring(end + 1)); + }).collect(Collectors.toList()); + } + else + break; + } + + return res.stream(); + } + + /** Expands plans. Replace {ONEOF} tag with the possible cases. */ + private static List expandOneof(String plan) { + String oneOf = "{ONEOF}"; + + if (!plan.contains(oneOf)) + return Collections.singletonList(plan); + + List res = new ArrayList<>(); + + Scanner sc = new Scanner(plan); + + StringBuilder beforeOneof = new StringBuilder(); + + while (sc.hasNextLine()) { + String line = sc.nextLine(); + + if (line.trim().startsWith(oneOf)) + break; + + beforeOneof.append(line).append('\n'); + } + + boolean oneOfEnd = false; + + // Expanding first found oneof + while (sc.hasNextLine() && !oneOfEnd) { + StringBuilder oneofCase = new StringBuilder(); + + while (sc.hasNextLine()) { + String line = sc.nextLine(); + + oneOfEnd = line.trim().equals(oneOf); + + if (line.trim().matches("^=+$") || oneOfEnd) + break; + + oneofCase.append(line).append('\n'); + } + + res.add(new StringBuffer(beforeOneof).append(oneofCase)); + } + + if (!oneOfEnd) + throw new IllegalStateException(oneOf + " not closed"); + + while (sc.hasNextLine()) { + String line = sc.nextLine(); + + for (StringBuffer expanded : res) { + expanded.append(line).append('\n'); + } + } + + // Recursively expanding next ONEOF. + return res.stream().flatMap(p -> expandOneof(p.toString()).stream()).collect(Collectors.toList()); + } + + /** Replaces id and hash patterns. */ + public static String replaceIdAndHash(String plan) { + plan = ID_PATTERN.matcher(plan).replaceAll(", id = {id}"); + return HASH_PATTERN.matcher(plan).replaceAll(", hash={hash}"); + } + + /** @return List of SQL queries from the script file. Comments are skipped. */ + public static List scriptToQueries(String sqlScript) { + List queries = new ArrayList<>(); + + Scanner sc = new Scanner(sqlScript); + + StringBuilder cur = new StringBuilder(); + + while (sc.hasNextLine()) { + String line = sc.nextLine().trim(); + + if (line.startsWith("--") || line.isEmpty()) + continue; + + cur.append(line).append('\n'); + + if (line.endsWith(";")) { + queries.add(cur.toString()); + + cur = new StringBuilder(); + } + } + + if (cur.length() > 0) + queries.add(cur.toString()); + + return queries; + } +} diff --git a/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/TpchQueryPlannerTest.java b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/TpchQueryPlannerTest.java new file mode 100644 index 0000000000000..e0aa8734929d6 --- /dev/null +++ b/modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/tpc/TpchQueryPlannerTest.java @@ -0,0 +1,31 @@ +/* + * 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.processors.query.calcite.planner.tpc; + +import org.junit.runner.RunWith; + +/** + * Tests ensures a planner generates optimal plan for TPC-H queries. + * + * @code org.apache.ignite.internal.sql.engine.benchmarks.TpchParseBenchmark + */ +@RunWith(PlanChecker.class) +@PlanChecker.PlansTest(name = "tpch") +public class TpchQueryPlannerTest extends AbstractTpcQueryPlannerTest { + // No-op +} diff --git a/modules/calcite/src/test/java/org/apache/ignite/testsuites/PlannerTestSuite.java b/modules/calcite/src/test/java/org/apache/ignite/testsuites/PlannerTestSuite.java index 30415c303720e..c1c24761bdb32 100644 --- a/modules/calcite/src/test/java/org/apache/ignite/testsuites/PlannerTestSuite.java +++ b/modules/calcite/src/test/java/org/apache/ignite/testsuites/PlannerTestSuite.java @@ -50,6 +50,7 @@ import org.apache.ignite.internal.processors.query.calcite.planner.UnionPlannerTest; import org.apache.ignite.internal.processors.query.calcite.planner.UserDefinedViewsPlannerTest; import org.apache.ignite.internal.processors.query.calcite.planner.hints.HintsTestSuite; +import org.apache.ignite.internal.processors.query.calcite.planner.tpc.TpchQueryPlannerTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; @@ -92,6 +93,7 @@ UncollectPlannerTest.class, HintsTestSuite.class, + TpchQueryPlannerTest.class }) public class PlannerTestSuite { } diff --git a/modules/calcite/src/test/resources/tpch/ddl/customer_ddl.sql b/modules/calcite/src/test/resources/tpch/ddl/customer_ddl.sql new file mode 100644 index 0000000000000..1bba80dda97ed --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/ddl/customer_ddl.sql @@ -0,0 +1,19 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- Size: SF*150,000 + +DROP TABLE IF EXISTS customer; + +CREATE TABLE customer ( + c_custkey integer NOT NULL, + c_name varchar(25) NOT NULL, + c_address varchar(40) NOT NULL, + c_nationkey integer NOT NULL, + c_phone varchar(15) NOT NULL, + c_acctbal decimal(15, 2) NOT NULL, + c_mktsegment varchar(10) NOT NULL, + c_comment varchar(117) NOT NULL, + PRIMARY KEY (c_custkey) +); + +CREATE INDEX c_nk ON customer (c_nationkey ASC); diff --git a/modules/calcite/src/test/resources/tpch/ddl/lineitem_ddl.sql b/modules/calcite/src/test/resources/tpch/ddl/lineitem_ddl.sql new file mode 100644 index 0000000000000..07d937fa2ce41 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/ddl/lineitem_ddl.sql @@ -0,0 +1,32 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- Size: SF*6,000,000 + +DROP TABLE IF EXISTS lineitem; + +CREATE TABLE lineitem ( + l_orderkey integer NOT NULL, + l_partkey integer NOT NULL, + l_suppkey integer NOT NULL, + l_linenumber integer NOT NULL, + l_quantity decimal(15, 2) NOT NULL, + l_extendedprice decimal(15, 2) NOT NULL, + l_discount decimal(15, 2) NOT NULL, + l_tax decimal(15, 2) NOT NULL, + l_returnflag varchar(1) NOT NULL, + l_linestatus varchar(1) NOT NULL, + l_shipdate date NOT NULL, + l_commitdate date NOT NULL, + l_receiptdate date NOT NULL, + l_shipinstruct varchar(25) NOT NULL, + l_shipmode varchar(10) NOT NULL, + l_comment varchar(44) NOT NULL, + PRIMARY KEY (l_orderkey, l_linenumber) +); + +CREATE INDEX l_sd ON lineitem (l_shipdate ASC); +CREATE INDEX l_cd ON lineitem (l_commitdate ASC); +CREATE INDEX l_rd ON lineitem (l_receiptdate ASC); +CREATE INDEX l_ok ON lineitem (l_orderkey ASC); +CREATE INDEX l_pk_sk ON lineitem (l_partkey ASC, l_suppkey ASC); +CREATE INDEX l_sk_pk ON lineitem (l_suppkey ASC, l_partkey ASC); diff --git a/modules/calcite/src/test/resources/tpch/ddl/nation_ddl.sql b/modules/calcite/src/test/resources/tpch/ddl/nation_ddl.sql new file mode 100644 index 0000000000000..c24517333c88b --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/ddl/nation_ddl.sql @@ -0,0 +1,15 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- Size: 25 + +DROP TABLE IF EXISTS nation; + +CREATE TABLE nation ( + n_nationkey integer NOT NULL, + n_name varchar(25) NOT NULL, + n_regionkey integer NOT NULL, + n_comment varchar(152), + PRIMARY KEY (n_nationkey) +); + +CREATE INDEX n_rk ON nation (n_regionkey ASC); diff --git a/modules/calcite/src/test/resources/tpch/ddl/orders_ddl.sql b/modules/calcite/src/test/resources/tpch/ddl/orders_ddl.sql new file mode 100644 index 0000000000000..c5a855c670ab3 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/ddl/orders_ddl.sql @@ -0,0 +1,21 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- Size: SF*1,500,000 + +DROP TABLE IF EXISTS orders; + +CREATE TABLE orders ( + o_orderkey integer NOT NULL, + o_custkey integer NOT NULL, + o_orderstatus varchar(1) NOT NULL, + o_totalprice decimal(15, 2) NOT NULL, + o_orderdate date NOT NULL, + o_orderpriority varchar(15) NOT NULL, + o_clerk varchar(15) NOT NULL, + o_shippriority integer NOT NULL, + o_comment varchar(79) NOT NULL, + PRIMARY KEY (o_orderkey) +); + +CREATE INDEX o_ck ON orders (o_custkey ASC); +CREATE INDEX o_od ON orders (o_orderdate ASC); diff --git a/modules/calcite/src/test/resources/tpch/ddl/part_ddl.sql b/modules/calcite/src/test/resources/tpch/ddl/part_ddl.sql new file mode 100644 index 0000000000000..e0b79be7fb71f --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/ddl/part_ddl.sql @@ -0,0 +1,18 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- Size: SF*200,000 + +DROP TABLE IF EXISTS part; + +CREATE TABLE part ( + p_partkey integer NOT NULL, + p_name varchar(55) NOT NULL, + p_mfgr varchar(25) NOT NULL, + p_brand varchar(10) NOT NULL, + p_type varchar(25) NOT NULL, + p_size integer NOT NULL, + p_container varchar(10) NOT NULL, + p_retailprice decimal(15, 2) NOT NULL, + p_comment varchar(23) NOT NULL, + PRIMARY KEY (p_partkey) +); diff --git a/modules/calcite/src/test/resources/tpch/ddl/partsupp_ddl.sql b/modules/calcite/src/test/resources/tpch/ddl/partsupp_ddl.sql new file mode 100644 index 0000000000000..b93210e667323 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/ddl/partsupp_ddl.sql @@ -0,0 +1,17 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- Size: SF*800,000 + +DROP TABLE IF EXISTS partsupp; + +CREATE TABLE partsupp ( + ps_partkey integer NOT NULL, + ps_suppkey integer NOT NULL, + ps_availqty integer NOT NULL, + ps_supplycost decimal(15, 2) NOT NULL, + ps_comment varchar(199) NOT NULL, + PRIMARY KEY (ps_partkey, ps_suppkey) +); + +CREATE INDEX ps_pk ON partsupp (ps_partkey ASC); +CREATE INDEX ps_sk_pk ON partsupp (ps_suppkey ASC, ps_partkey ASC); diff --git a/modules/calcite/src/test/resources/tpch/ddl/region_ddl.sql b/modules/calcite/src/test/resources/tpch/ddl/region_ddl.sql new file mode 100644 index 0000000000000..f224ae412da7c --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/ddl/region_ddl.sql @@ -0,0 +1,12 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- Size: 5 + +DROP TABLE IF EXISTS region; + +CREATE TABLE region ( + r_regionkey integer NOT NULL, + r_name varchar(25) NOT NULL, + r_comment varchar(152), + PRIMARY KEY (r_regionkey) +); diff --git a/modules/calcite/src/test/resources/tpch/ddl/supplier_ddl.sql b/modules/calcite/src/test/resources/tpch/ddl/supplier_ddl.sql new file mode 100644 index 0000000000000..e50ab1fe94a85 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/ddl/supplier_ddl.sql @@ -0,0 +1,18 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile +-- Size: SF*10,000 + +DROP TABLE IF EXISTS supplier; + +CREATE TABLE supplier ( + s_suppkey integer NOT NULL, + s_name varchar(25) NOT NULL, + s_address varchar(40) NOT NULL, + s_nationkey integer NOT NULL, + s_phone varchar(15) NOT NULL, + s_acctbal decimal(15, 2) NOT NULL, + s_comment varchar(101) NOT NULL, + PRIMARY KEY (s_suppkey) +); + +CREATE INDEX s_nk ON supplier (s_nationkey ASC); diff --git a/modules/calcite/src/test/resources/tpch/q1.plan b/modules/calcite/src/test/resources/tpch/q1.plan new file mode 100644 index 0000000000000..7096aeb1e4eb3 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q1.plan @@ -0,0 +1,5 @@ +IgniteReduceSortAggregate(rowType=[RecordType(VARCHAR L_RETURNFLAG, VARCHAR L_LINESTATUS, DECIMAL(32767, 0) SUM_QTY, DECIMAL(32767, 0) SUM_BASE_PRICE, DECIMAL(32767, 0) SUM_DISC_PRICE, DECIMAL(32767, 0) SUM_CHARGE, DECIMAL(15, 2) AVG_QTY, DECIMAL(15, 2) AVG_PRICE, DECIMAL(15, 2) AVG_DISC, BIGINT COUNT_ORDER)], group=[{0, 1}], SUM_QTY=[SUM($2)], SUM_BASE_PRICE=[SUM($3)], SUM_DISC_PRICE=[SUM($4)], SUM_CHARGE=[SUM($5)], AVG_QTY=[AVG($2)], AVG_PRICE=[AVG($3)], AVG_DISC=[AVG($6)], COUNT_ORDER=[COUNT()], collation=[[0 ASC-nulls-first, 1 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.0, cpu=8.0, memory=77.0, io=1.0, network=13.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=7.0, memory=77.0, io=1.0, network=13.0], id = {id} + IgniteMapSortAggregate(group=[{0, 1}], SUM_QTY=[SUM($2)], SUM_BASE_PRICE=[SUM($3)], SUM_DISC_PRICE=[SUM($4)], SUM_CHARGE=[SUM($5)], AVG_QTY=[AVG($2)], AVG_PRICE=[AVG($3)], AVG_DISC=[AVG($6)], COUNT_ORDER=[COUNT()], collation=[[0 ASC-nulls-first, 1 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=77.0, io=1.0, network=1.0], id = {id} + IgniteSort(sort0=[$0], sort1=[$1], dir0=[ASC-nulls-first], dir1=[ASC-nulls-first]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=29.0, io=1.0, network=1.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[L_SD], filters=[<=($t6, 1998-09-02)], rowType=[RecordType(VARCHAR L_RETURNFLAG, VARCHAR L_LINESTATUS, DECIMAL(15, 2) L_QUANTITY, DECIMAL(15, 2) L_EXTENDEDPRICE, DECIMAL(31, 4) $f4, DECIMAL(47, 6) $f5, DECIMAL(15, 2) L_DISCOUNT)], projects=[[$t4, $t5, $t0, $t1, *($t1, -(1, $t2)), *(*($t1, -(1, $t2)), +(1, $t3)), $t2]], requiredColumns=[{6, 7, 8, 9, 10, 11, 12}], searchBounds=[[null, null, null, null, null, null, null, null, null, null, null, null, RangeBounds [lowerBound=$NULL_BOUND(), upperBound=1998-09-02, lowerInclude=false, upperInclude=true], null, null, null, null, null]], inlineScan=[false], collation=[[12 ASC-nulls-first, 2 ASC-nulls-first, 5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q1.sql b/modules/calcite/src/test/resources/tpch/q1.sql new file mode 100644 index 0000000000000..938f33eddc566 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q1.sql @@ -0,0 +1,29 @@ +-- using default substitutions +-- $ID$ +-- TPC-H/TPC-R Pricing Summary Report Query (Q1) +-- Functional Query Definition +-- Approved February 1998 +-- TODO: actual SQL query differs from Ignite3 version. Why? + + +select + l_returnflag, + l_linestatus, + sum(l_quantity) as sum_qty, + sum(l_extendedprice) as sum_base_price, + sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, + sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, + avg(l_quantity) as avg_qty, + avg(l_extendedprice) as avg_price, + avg(l_discount) as avg_disc, + count(*) as count_order +from + lineitem +where + l_shipdate <= TIMESTAMPADD(DAY, -90, date '1998-12-01') +group by + l_returnflag, + l_linestatus +order by + l_returnflag, + l_linestatus; diff --git a/modules/calcite/src/test/resources/tpch/q10.plan b/modules/calcite/src/test/resources/tpch/q10.plan new file mode 100644 index 0000000000000..1786907541975 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q10.plan @@ -0,0 +1,18 @@ +IgniteLimit(fetch=[20]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=18.45, cpu=38.3, memory=97.0921875, io=3.15, network=52.35], id = {id} + IgniteSort(sort0=[$2], dir0=[DESC-nulls-last]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=17.45, cpu=37.3, memory=97.0921875, io=3.15, network=52.35], id = {id} + IgniteProject(C_CUSTKEY=[$0], C_NAME=[$1], REVENUE=[$7], C_ACCTBAL=[$2], N_NAME=[$4], C_ADDRESS=[$5], C_PHONE=[$3], C_COMMENT=[$6]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=16.45, cpu=33.3, memory=65.0921875, io=3.15, network=52.35], id = {id} + IgniteColocatedHashAggregate(group=[{0, 1, 2, 3, 4, 5, 6}], REVENUE=[SUM($7)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=15.45, cpu=32.3, memory=65.0921875, io=3.15, network=52.35], id = {id} + IgniteProject(C_CUSTKEY=[$5], C_NAME=[$6], C_ACCTBAL=[$10], C_PHONE=[$9], N_NAME=[$13], C_ADDRESS=[$7], C_COMMENT=[$11], $f7=[*($1, -(1, $2))]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=14.45, cpu=31.3, memory=32.35, io=3.15, network=52.35], id = {id} + IgniteMergeJoin(condition=[=($0, $3)], joinType=[inner], variablesSet=[[]], leftCollation=[[0 ASC-nulls-first]], rightCollation=[[0 ASC-nulls-first]], allowNulls=[{}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=13.45, cpu=30.3, memory=32.35, io=3.15, network=52.35], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=13.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[=($t3, _UTF-8'R')], rowType=[RecordType(INTEGER L_ORDERKEY, DECIMAL(15, 2) L_EXTENDEDPRICE, DECIMAL(15, 2) L_DISCOUNT)], projects=[[$t0, $t1, $t2]], requiredColumns=[{2, 7, 8, 10}], inlineScan=[false], collation=[[2 ASC-nulls-first, 5 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($2, $1)], joinType=[inner], variablesSet=[[$cor1]], variablesSet=[[1]], correlationVariables=[[$cor1]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=8.45, cpu=16.3, memory=31.35, io=2.15, network=39.35], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, ORDERS]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[AND(>=($t2, 1993-10-01), <($t2, 1994-01-01))], rowType=[RecordType(INTEGER O_ORDERKEY, INTEGER O_CUSTKEY)], projects=[[$t0, $t1]], requiredColumns=[{2, 3, 6}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($3, $7)], joinType=[inner], variablesSet=[[$cor2]], variablesSet=[[2]], correlationVariables=[[$cor2]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.45, cpu=6.3, memory=30.35, io=1.15, network=30.35], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($0, $cor1.O_CUSTKEY)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor1.O_CUSTKEY], null, null, null, null, null, null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=29.0, io=1.0, network=29.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=29.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, CUSTOMER]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 3, 4, 5, 6, 7, 9}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor2.C_NATIONKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor2.C_NATIONKEY], null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, NATION]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 3}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q10.sql b/modules/calcite/src/test/resources/tpch/q10.sql new file mode 100644 index 0000000000000..0ba0bb540a131 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q10.sql @@ -0,0 +1,35 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT + c_custkey, + c_name, + sum(l_extendedprice * (1 - l_discount)) AS revenue, + c_acctbal, + n_name, + c_address, + c_phone, + c_comment +FROM + customer, + orders, + lineitem, + nation +WHERE + c_custkey = o_custkey + AND l_orderkey = o_orderkey + AND o_orderdate >= DATE '1993-10-01' + AND o_orderdate < DATE '1993-10-01' + INTERVAL '3' MONTH + AND l_returnflag = 'R' + AND c_nationkey = n_nationkey +GROUP BY + c_custkey, + c_name, + c_acctbal, + c_phone, + n_name, + c_address, + c_comment +ORDER BY + revenue DESC + LIMIT 20 diff --git a/modules/calcite/src/test/resources/tpch/q11.plan b/modules/calcite/src/test/resources/tpch/q11.plan new file mode 100644 index 0000000000000..a38dea6787312 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q11.plan @@ -0,0 +1,24 @@ +IgniteProject(PS_PARTKEY=[$0], VAL=[$1]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=26.0, cpu=50.0, memory=35.5, io=6.0, network=58.0], id = {id} + IgniteNestedLoopJoin(condition=[>($1, CAST($2):DECIMAL(32767, 0))], joinType=[inner], variablesSet=[[]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=25.0, cpu=49.0, memory=35.5, io=6.0, network=58.0], id = {id} + IgniteSort(sort0=[$1], dir0=[DESC-nulls-last]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=12.0, cpu=24.0, memory=19.5, io=3.0, network=31.0], id = {id} + IgniteColocatedHashAggregate(group=[{0}], VAL=[SUM($1)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=11.0, cpu=20.0, memory=11.5, io=3.0, network=31.0], id = {id} + IgniteProject(PS_PARTKEY=[$0], $f1=[*($3, $2)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=10.0, cpu=19.0, memory=7.0, io=3.0, network=31.0], id = {id} + IgniteMergeJoin(condition=[=($1, $4)], joinType=[inner], variablesSet=[[]], leftCollation=[[1 ASC-nulls-first, 0 ASC-nulls-first]], rightCollation=[[0 ASC-nulls-first]], allowNulls=[{}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=9.0, cpu=18.0, memory=7.0, io=3.0, network=31.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=17.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, PARTSUPP]], index=[PS_SK_PK], requiredColumns=[{2, 3, 4, 5}], inlineScan=[false], collation=[[3 ASC-nulls-first, 2 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteNestedLoopJoin(condition=[=($1, $2)], joinType=[inner], variablesSet=[[]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.0, cpu=8.0, memory=6.0, io=2.0, network=14.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, SUPPLIER]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 5}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteTableScan(table=[[PUBLIC, NATION]], filters=[=($t1, _UTF-8'GERMANY')], rowType=[RecordType(INTEGER N_NATIONKEY)], projects=[[$t0]], requiredColumns=[{2, 3}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteProject(EXPR$0=[*($0, 0.0001:DECIMAL(5, 4))]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=12.0, cpu=21.0, memory=12.0, io=3.0, network=27.0], id = {id} + IgniteColocatedHashAggregate(group=[{}], agg#0=[SUM($0)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=11.0, cpu=20.0, memory=12.0, io=3.0, network=27.0], id = {id} + IgniteProject($f0=[*($2, $1)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=10.0, cpu=19.0, memory=7.0, io=3.0, network=27.0], id = {id} + IgniteMergeJoin(condition=[=($0, $3)], joinType=[inner], variablesSet=[[]], leftCollation=[[0 ASC-nulls-first]], rightCollation=[[0 ASC-nulls-first]], allowNulls=[{}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=9.0, cpu=18.0, memory=7.0, io=3.0, network=27.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=13.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, PARTSUPP]], index=[PS_SK_PK], requiredColumns=[{3, 4, 5}], inlineScan=[false], collation=[[3 ASC-nulls-first, 2 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteNestedLoopJoin(condition=[=($1, $2)], joinType=[inner], variablesSet=[[]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.0, cpu=8.0, memory=6.0, io=2.0, network=14.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, SUPPLIER]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 5}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteTableScan(table=[[PUBLIC, NATION]], filters=[=($t1, _UTF-8'GERMANY')], rowType=[RecordType(INTEGER N_NATIONKEY)], projects=[[$t0]], requiredColumns=[{2, 3}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q11.sql b/modules/calcite/src/test/resources/tpch/q11.sql new file mode 100644 index 0000000000000..d304415b2734b --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q11.sql @@ -0,0 +1,30 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT + ps_partkey, + sum(ps_supplycost * ps_availqty) AS val +FROM + partsupp, + supplier, + nation +WHERE + ps_suppkey = s_suppkey + AND s_nationkey = n_nationkey + AND n_name = 'GERMANY' +GROUP BY + ps_partkey +HAVING + sum(ps_supplycost * ps_availqty) > ( + SELECT sum(ps_supplycost * ps_availqty) * 0.0001 + FROM + partsupp, + supplier, + nation + WHERE + ps_suppkey = s_suppkey + AND s_nationkey = n_nationkey + AND n_name = 'GERMANY' + ) +ORDER BY + val DESC diff --git a/modules/calcite/src/test/resources/tpch/q12.plan b/modules/calcite/src/test/resources/tpch/q12.plan new file mode 100644 index 0000000000000..2153b4def0009 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q12.plan @@ -0,0 +1,9 @@ +IgniteReduceSortAggregate(rowType=[RecordType(VARCHAR L_SHIPMODE, BIGINT HIGH_LINE_COUNT, BIGINT LOW_LINE_COUNT)], group=[{0}], HIGH_LINE_COUNT=[SUM($1)], LOW_LINE_COUNT=[SUM($2)], collation=[[0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=9.0, cpu=15.0, memory=24.0, io=2.0, network=18.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=8.0, cpu=14.0, memory=24.0, io=2.0, network=18.0], id = {id} + IgniteMapSortAggregate(group=[{0}], HIGH_LINE_COUNT=[SUM($1)], LOW_LINE_COUNT=[SUM($2)], collation=[[0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=7.0, cpu=13.0, memory=24.0, io=2.0, network=10.0], id = {id} + IgniteProject(L_SHIPMODE=[$1], $f1=[CASE(SEARCH($3, Sarg[_UTF-8'1-URGENT':VARCHAR CHARACTER SET "UTF-8", _UTF-8'2-HIGH':VARCHAR CHARACTER SET "UTF-8"]:VARCHAR CHARACTER SET "UTF-8"), 1, 0)], $f2=[CASE(SEARCH($3, Sarg[(-∞.._UTF-8'1-URGENT':VARCHAR CHARACTER SET "UTF-8"), (_UTF-8'1-URGENT':VARCHAR CHARACTER SET "UTF-8".._UTF-8'2-HIGH':VARCHAR CHARACTER SET "UTF-8"), (_UTF-8'2-HIGH':VARCHAR CHARACTER SET "UTF-8"..+∞)]:VARCHAR CHARACTER SET "UTF-8"), 1, 0)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=6.0, cpu=12.0, memory=10.0, io=2.0, network=10.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($2, $0)], joinType=[inner], variablesSet=[[$cor0]], variablesSet=[[0]], correlationVariables=[[$cor0]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.0, cpu=11.0, memory=10.0, io=2.0, network=10.0], id = {id} + IgniteExchange(distribution=[affinity[identity=AffinityIdentity [affFuncCls=class org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction, backups=0, partsCnt=1024, filterCls=class org.apache.ignite.configuration.CacheConfiguration$IgniteAllNodesPredicate, hash={hash}, cacheId=-1464737622][0]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteSort(sort0=[$1], dir0=[ASC-nulls-first]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=9.0, io=1.0, network=1.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[L_RD], filters=[AND(OR(=($t4, _UTF-8'MAIL'), =($t4, _UTF-8'SHIP')), <($t2, $t3), <($t1, $t2), AND(>=($t3, 1994-01-01), <($t3, 1995-01-01)))], rowType=[RecordType(INTEGER L_ORDERKEY, VARCHAR L_SHIPMODE)], projects=[[$t0, $t4]], requiredColumns=[{2, 12, 13, 14, 16}], searchBounds=[[null, null, null, null, null, null, null, null, null, null, null, null, null, null, RangeBounds [lowerBound=1994-01-01, upperBound=1995-01-01, lowerInclude=true, upperInclude=false], null, null, null]], inlineScan=[false], collation=[[14 ASC-nulls-first, 2 ASC-nulls-first, 5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, ORDERS]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[=($t0, $cor0.L_ORDERKEY)], requiredColumns=[{2, 7}], searchBounds=[[null, null, ExactBounds [bound=$cor0.L_ORDERKEY], null, null, null, null, null, null, null, null]], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q12.sql b/modules/calcite/src/test/resources/tpch/q12.sql new file mode 100644 index 0000000000000..31a40ce58908d --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q12.sql @@ -0,0 +1,31 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT + l_shipmode, + sum(CASE + WHEN o_orderpriority = '1-URGENT' + OR o_orderpriority = '2-HIGH' + THEN 1 + ELSE 0 + END) AS high_line_count, + sum(CASE + WHEN o_orderpriority <> '1-URGENT' + AND o_orderpriority <> '2-HIGH' + THEN 1 + ELSE 0 + END) AS low_line_count +FROM + orders, + lineitem +WHERE + o_orderkey = l_orderkey + AND l_shipmode IN ('MAIL', 'SHIP') + AND l_commitdate < l_receiptdate + AND l_shipdate < l_commitdate + AND l_receiptdate >= DATE '1994-01-01' + AND l_receiptdate < DATE '1994-01-01' + INTERVAL '1' YEAR +GROUP BY + l_shipmode +ORDER BY + l_shipmode diff --git a/modules/calcite/src/test/resources/tpch/q13.plan b/modules/calcite/src/test/resources/tpch/q13.plan new file mode 100644 index 0000000000000..4f87e7b626837 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q13.plan @@ -0,0 +1,10 @@ +IgniteSort(sort0=[$1], sort1=[$0], dir0=[DESC-nulls-last], dir1=[DESC-nulls-last]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=10.3, cpu=16.3, memory=23.675, io=2.0, network=14.0], id = {id} + IgniteColocatedHashAggregate(group=[{0}], CUSTDIST=[COUNT()]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=9.3, cpu=12.3, memory=15.675, io=2.0, network=14.0], id = {id} + IgniteProject(C_COUNT=[$1]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=8.3, cpu=11.3, memory=11.175, io=2.0, network=14.0], id = {id} + IgniteColocatedHashAggregate(group=[{0}], EXPR$1=[COUNT($1)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=7.300000000000001, cpu=10.3, memory=11.175, io=2.0, network=14.0], id = {id} + IgniteProject(C_CUSTKEY=[$2], O_ORDERKEY=[$0]): rowcount = 1.15, cumulative cost = IgniteCost [rowCount=6.15, cpu=9.15, memory=6.0, io=2.0, network=14.0], id = {id} + IgniteNestedLoopJoin(condition=[=($2, $1)], joinType=[right], variablesSet=[[]]): rowcount = 1.15, cumulative cost = IgniteCost [rowCount=5.0, cpu=8.0, memory=6.0, io=2.0, network=14.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteTableScan(table=[[PUBLIC, ORDERS]], filters=[NOT(LIKE($t2, _UTF-8'%special%requests%'))], rowType=[RecordType(INTEGER O_ORDERKEY, INTEGER O_CUSTKEY)], projects=[[$t0, $t1]], requiredColumns=[{2, 3, 10}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, CUSTOMER]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2}], inlineScan=[true], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q13.sql b/modules/calcite/src/test/resources/tpch/q13.sql new file mode 100644 index 0000000000000..c3ab108c66d4d --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q13.sql @@ -0,0 +1,23 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT + c_count, + count(*) AS custdist +FROM ( + SELECT + c_custkey, + count(o_orderkey) + FROM + customer + LEFT OUTER JOIN orders ON + c_custkey = o_custkey + AND o_comment NOT LIKE '%special%requests%' + GROUP BY + c_custkey + ) AS c_orders (c_custkey, c_count) +GROUP BY + c_count +ORDER BY + custdist DESC, + c_count DESC diff --git a/modules/calcite/src/test/resources/tpch/q14.plan b/modules/calcite/src/test/resources/tpch/q14.plan new file mode 100644 index 0000000000000..0a554b92928a1 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q14.plan @@ -0,0 +1,8 @@ +IgniteProject(PROMO_REVENUE=[/(*(100.00:DECIMAL(5, 2), $0), $1)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=10.0, cpu=19.0, memory=12.0, io=2.0, network=22.0], id = {id} + IgniteColocatedHashAggregate(group=[{}], agg#0=[SUM($0)], agg#1=[SUM($1)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=9.0, cpu=18.0, memory=12.0, io=2.0, network=22.0], id = {id} + IgniteProject($f0=[CASE(LIKE($1, _UTF-8'PROMO%'), *($3, -(1, $4)), 0.0000:DECIMAL(31, 4))], $f1=[*($3, -(1, $4))]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=8.0, cpu=17.0, memory=2.0, io=2.0, network=22.0], id = {id} + IgniteMergeJoin(condition=[=($2, $0)], joinType=[inner], variablesSet=[[]], leftCollation=[[0 ASC-nulls-first]], rightCollation=[[0 ASC-nulls-first]], allowNulls=[{}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=7.0, cpu=16.0, memory=2.0, io=2.0, network=22.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, PART]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 6}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=13.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[L_PK_SK], filters=[AND(>=($t3, 1995-09-01), <($t3, 1995-10-01))], rowType=[RecordType(INTEGER L_PARTKEY, DECIMAL(15, 2) L_EXTENDEDPRICE, DECIMAL(15, 2) L_DISCOUNT)], projects=[[$t0, $t1, $t2]], requiredColumns=[{3, 7, 8, 12}], inlineScan=[false], collation=[[3 ASC-nulls-first, 4 ASC-nulls-first, 2 ASC-nulls-first, 5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q14.sql b/modules/calcite/src/test/resources/tpch/q14.sql new file mode 100644 index 0000000000000..4971ae7c7df02 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q14.sql @@ -0,0 +1,15 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT 100.00 * sum(CASE + WHEN p_type LIKE 'PROMO%' + THEN l_extendedprice * (1 - l_discount) + ELSE 0 + END) / sum(l_extendedprice * (1 - l_discount)) AS promo_revenue +FROM + lineitem, + part +WHERE + l_partkey = p_partkey + AND l_shipdate >= DATE '1995-09-01' + AND l_shipdate < DATE '1995-09-01' + INTERVAL '1' MONTH diff --git a/modules/calcite/src/test/resources/tpch/q15.plan b/modules/calcite/src/test/resources/tpch/q15.plan new file mode 100644 index 0000000000000..b2a58b029b105 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q15.plan @@ -0,0 +1,14 @@ +IgniteProject(S_SUPPKEY=[$0], S_NAME=[$1], S_ADDRESS=[$2], S_PHONE=[$3], TOTAL_REVENUE=[$6]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=16.0, cpu=28.0, memory=25.5, io=3.0, network=35.0], id = {id} + IgniteMergeJoin(condition=[=($0, $5)], joinType=[inner], variablesSet=[[]], leftCollation=[[0 ASC-nulls-first]], rightCollation=[[1 ASC-nulls-first]], allowNulls=[{}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=15.0, cpu=27.0, memory=25.5, io=3.0, network=35.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=17.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, SUPPLIER]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 3, 4, 6}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteProject(EXPR$0=[$2], L_SUPPKEY=[$0], EXPR$1=[$1]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=11.0, cpu=17.0, memory=24.5, io=2.0, network=18.0], id = {id} + IgniteNestedLoopJoin(condition=[=($1, $2)], joinType=[inner], variablesSet=[[]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=10.0, cpu=16.0, memory=24.5, io=2.0, network=18.0], id = {id} + IgniteColocatedSortAggregate(group=[{0}], EXPR$1=[SUM($1)], collation=[[0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=7.0, memory=10.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[L_SK_PK], filters=[AND(>=($t3, 1996-01-01), <($t3, 1996-04-01))], rowType=[RecordType(INTEGER L_SUPPKEY, DECIMAL(31, 4) $f1)], projects=[[$t0, *($t1, -(1, $t2))]], requiredColumns=[{4, 7, 8, 12}], inlineScan=[false], collation=[[4 ASC-nulls-first, 3 ASC-nulls-first, 2 ASC-nulls-first, 5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteColocatedHashAggregate(group=[{}], EXPR$0=[MAX($0)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.0, cpu=5.0, memory=10.5, io=1.0, network=9.0], id = {id} + IgniteProject(EXPR$1=[$1]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=4.0, memory=5.5, io=1.0, network=9.0], id = {id} + IgniteColocatedHashAggregate(group=[{0}], EXPR$1=[SUM($1)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=3.0, memory=5.5, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[L_SD], filters=[AND(>=($t3, 1996-01-01), <($t3, 1996-04-01))], rowType=[RecordType(INTEGER L_SUPPKEY, DECIMAL(31, 4) $f1)], projects=[[$t0, *($t1, -(1, $t2))]], requiredColumns=[{4, 7, 8, 12}], searchBounds=[[null, null, null, null, null, null, null, null, null, null, null, null, RangeBounds [lowerBound=1996-01-01, upperBound=1996-04-01, lowerInclude=true, upperInclude=false], null, null, null, null, null]], inlineScan=[false], collation=[[12 ASC-nulls-first, 2 ASC-nulls-first, 5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q15.sql b/modules/calcite/src/test/resources/tpch/q15.sql new file mode 100644 index 0000000000000..0bc233adf7b4d --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q15.sql @@ -0,0 +1,34 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +WITH revenue (supplier_no, total_revenue) as ( + SELECT + l_suppkey, + sum(l_extendedprice * (1-l_discount)) + FROM + lineitem + WHERE + l_shipdate >= DATE '1996-01-01' + AND l_shipdate < DATE '1996-01-01' + INTERVAL '3' MONTH + GROUP BY + l_suppkey +) +SELECT + s_suppkey, + s_name, + s_address, + s_phone, + total_revenue +FROM + supplier, + revenue +WHERE + s_suppkey = supplier_no + AND total_revenue = ( + SELECT + max(total_revenue) + FROM + revenue +) +ORDER BY + s_suppkey diff --git a/modules/calcite/src/test/resources/tpch/q16.plan b/modules/calcite/src/test/resources/tpch/q16.plan new file mode 100644 index 0000000000000..5f74a965c60e5 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q16.plan @@ -0,0 +1,20 @@ +IgniteSort(sort0=[$3], sort1=[$0], sort2=[$1], sort3=[$2], dir0=[DESC-nulls-last], dir1=[ASC-nulls-first], dir2=[ASC-nulls-first], dir3=[ASC-nulls-first]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=22.15, cpu=43.6, memory=58.5, io=4.0, network=52.0], id = {id} + IgniteColocatedHashAggregate(group=[{0, 1, 2}], SUPPLIER_CNT=[COUNT(DISTINCT $3)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=21.15, cpu=39.6, memory=42.5, io=4.0, network=52.0], id = {id} + IgniteProject(P_BRAND=[$5], P_TYPE=[$6], P_SIZE=[$7], PS_SUPPKEY=[$3]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=20.15, cpu=38.6, memory=27.0, io=4.0, network=52.0], id = {id} + IgniteFilter(condition=[OR(=($8, 0), AND(IS NULL($1), >=($9, $8)))]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=19.15, cpu=37.6, memory=27.0, io=4.0, network=52.0], id = {id} + IgniteMergeJoin(condition=[=($3, $0)], joinType=[right], variablesSet=[[]], leftCollation=[[0 ASC-nulls-first]], rightCollation=[[1 ASC-nulls-first]], allowNulls=[{}]): rowcount = 1.15, cumulative cost = IgniteCost [rowCount=18.0, cpu=33.0, memory=27.0, io=4.0, network=52.0], id = {id} + IgniteColocatedSortAggregate(group=[{0}], i=[LITERAL_AGG(true)], collation=[[0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=7.0, memory=10.0, io=1.0, network=5.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, SUPPLIER]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[LIKE($t1, _UTF-8'%Customer%Complaints%')], rowType=[RecordType(INTEGER S_SUPPKEY)], projects=[[$t0]], requiredColumns=[{2, 8}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[true], joinType=[inner], variablesSet=[[$cor0]], variablesSet=[[0]], correlationVariables=[[$cor0]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=12.0, cpu=18.0, memory=17.0, io=3.0, network=47.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.0, cpu=8.0, memory=2.0, io=2.0, network=34.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($2, $0)], joinType=[inner], variablesSet=[[$cor1]], variablesSet=[[1]], correlationVariables=[[$cor1]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=7.0, memory=2.0, io=2.0, network=10.0], id = {id} + IgniteExchange(distribution=[affinity[identity=AffinityIdentity [affFuncCls=class org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction, backups=0, partsCnt=1024, filterCls=class org.apache.ignite.configuration.CacheConfiguration$IgniteAllNodesPredicate, hash={hash}, cacheId=-2066312456][0]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, PARTSUPP]], index=[PS_SK_PK], requiredColumns=[{2, 3}], inlineScan=[false], collation=[[3 ASC-nulls-first, 2 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, PART]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[AND(<>($t1, _UTF-8'Brand#45'), OR(=($t3, 3), =($t3, 9), =($t3, 14), =($t3, 19), =($t3, 23), =($t3, 36), =($t3, 45), =($t3, 49)), =($t0, $cor1.PS_PARTKEY), NOT(LIKE($t2, _UTF-8'MEDIUM POLISHED%')))], requiredColumns=[{2, 5, 6, 7}], searchBounds=[[null, null, ExactBounds [bound=$cor1.PS_PARTKEY], null, null, null, null, null, null, null, null]], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteProject(c=[$0], ck=[$0]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=6.0, cpu=6.0, memory=15.0, io=1.0, network=13.0], id = {id} + IgniteTableSpool(readType=[LAZY], writeType=[EAGER]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.0, cpu=5.0, memory=15.0, io=1.0, network=13.0], id = {id} + IgniteReduceHashAggregate(rowType=[RecordType(BIGINT c)], group=[{}], c=[COUNT()]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=4.0, memory=11.0, io=1.0, network=13.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=3.0, memory=6.0, io=1.0, network=13.0], id = {id} + IgniteMapHashAggregate(group=[{}], c=[COUNT()]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=6.0, io=1.0, network=1.0], id = {id} + IgniteTableScan(table=[[PUBLIC, SUPPLIER]], filters=[LIKE($t8, _UTF-8'%Customer%Complaints%')]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q16.sql b/modules/calcite/src/test/resources/tpch/q16.sql new file mode 100644 index 0000000000000..9598a8c683cc6 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q16.sql @@ -0,0 +1,32 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT + p_brand, + p_type, + p_size, + count(DISTINCT ps_suppkey) AS supplier_cnt +FROM + partsupp, + part +WHERE + p_partkey = ps_partkey + AND p_brand <> 'Brand#45' + AND p_type NOT LIKE 'MEDIUM POLISHED%' + AND p_size IN (49, 14, 23, 45, 19, 3, 36, 9) + AND ps_suppkey NOT IN ( + SELECT s_suppkey + FROM + supplier + WHERE + s_comment LIKE '%Customer%Complaints%' +) +GROUP BY + p_brand, + p_type, + p_size +ORDER BY + supplier_cnt DESC, + p_brand, + p_type, + p_size diff --git a/modules/calcite/src/test/resources/tpch/q17.plan b/modules/calcite/src/test/resources/tpch/q17.plan new file mode 100644 index 0000000000000..14f65d5193825 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q17.plan @@ -0,0 +1,16 @@ +IgniteProject(AVG_YEARLY=[/($0, 7.0:DECIMAL(2, 1))]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=10.9, cpu=19.75, memory=13.1, io=2.15, network=19.35], id = {id} + IgniteColocatedHashAggregate(group=[{}], agg#0=[SUM($0)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=9.9, cpu=18.75, memory=13.1, io=2.15, network=19.35], id = {id} + IgniteProject(L_EXTENDEDPRICE=[$2]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=8.9, cpu=17.75, memory=8.1, io=2.15, network=19.35], id = {id} + IgniteFilter(condition=[<(CAST($1):DECIMAL(17, 3) NOT NULL, $4)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=7.9, cpu=16.75, memory=8.1, io=2.15, network=19.35], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[true], joinType=[left], variablesSet=[[$cor0]], variablesSet=[[0]], correlationVariables=[[$cor0]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=6.9, cpu=12.75, memory=8.1, io=2.15, network=19.35], id = {id} + IgniteNestedLoopJoin(condition=[=($3, $0)], joinType=[inner], variablesSet=[[]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.0, cpu=8.0, memory=6.0, io=2.0, network=18.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=13.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[L_PK_SK], requiredColumns=[{3, 6, 7}], inlineScan=[false], collation=[[3 ASC-nulls-first, 4 ASC-nulls-first, 2 ASC-nulls-first, 5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteTableScan(table=[[PUBLIC, PART]], filters=[AND(=($t1, _UTF-8'Brand#23'), =($t2, _UTF-8'MED BOX'))], rowType=[RecordType(INTEGER P_PARTKEY)], projects=[[$t0]], requiredColumns=[{2, 5, 8}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteProject(EXPR$0=[*(0.2:DECIMAL(2, 1), $0)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=6.0, cpu=5.0, memory=14.0, io=1.0, network=9.0], id = {id} + IgniteColocatedHashAggregate(group=[{}], agg#0=[AVG($0)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.0, cpu=4.0, memory=14.0, io=1.0, network=9.0], id = {id} + IgniteProject(L_QUANTITY=[$1]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=3.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($0, $cor0.P_PARTKEY)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor0.P_PARTKEY], null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[L_PK_SK], requiredColumns=[{3, 6}], inlineScan=[false], collation=[[3 ASC-nulls-first, 4 ASC-nulls-first, 2 ASC-nulls-first, 5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q17.sql b/modules/calcite/src/test/resources/tpch/q17.sql new file mode 100644 index 0000000000000..cd594a917843c --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q17.sql @@ -0,0 +1,18 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT sum(l_extendedprice) / 7.0 AS avg_yearly +FROM + lineitem, + part +WHERE + p_partkey = l_partkey + AND p_brand = 'Brand#23' + AND p_container = 'MED BOX' + AND l_quantity < ( + SELECT 0.2 * avg(l_quantity) + FROM + lineitem + WHERE + l_partkey = p_partkey +) diff --git a/modules/calcite/src/test/resources/tpch/q18.plan b/modules/calcite/src/test/resources/tpch/q18.plan new file mode 100644 index 0000000000000..4ef548d8cb848 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q18.plan @@ -0,0 +1,34 @@ +IgniteLimit(fetch=[100]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=15.1125, cpu=26.09, memory=75.62375, io=3.0225, network=35.2025], id = {id} + IgniteSort(sort0=[$4], sort1=[$3], dir0=[DESC-nulls-last], dir1=[ASC-nulls-first], fetch=[100]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=14.1125, cpu=25.09, memory=75.62375, io=3.0225, network=35.2025], id = {id} + IgniteColocatedHashAggregate(group=[{0, 1, 2, 3, 4}], EXPR$5=[SUM($5)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=13.1125, cpu=21.09, memory=51.62375, io=3.0225, network=35.2025], id = {id} + IgniteProject(C_NAME=[$1], C_CUSTKEY=[$0], O_ORDERKEY=[$4], O_ORDERDATE=[$7], O_TOTALPRICE=[$6], L_QUANTITY=[$3]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=12.1125, cpu=20.09, memory=27.405, io=3.0225, network=35.2025], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($0, $5)], joinType=[inner], variablesSet=[[$cor3]], variablesSet=[[3]], correlationVariables=[[$cor3]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=11.1125, cpu=19.09, memory=27.405, io=3.0225, network=35.2025], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, CUSTOMER]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 3}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($2, $0)], joinType=[inner], variablesSet=[[$cor5]], variablesSet=[[5]], correlationVariables=[[$cor5]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=8.1125, cpu=13.09, memory=26.405, io=2.0225, network=26.2025], id = {id} + IgniteTableSpool(readType=[LAZY], writeType=[EAGER]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=3.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 6}], inlineScan=[false], collation=[[2 ASC-nulls-first, 5 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($0, $4)], joinType=[inner], variablesSet=[[$cor6]], variablesSet=[[6]], correlationVariables=[[$cor6]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.1125, cpu=6.09, memory=17.405, io=1.0225, network=17.2025], id = {id} +{ONEOF} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[AND(=($cor3.C_CUSTKEY, $1), =($0, $cor5.L_ORDERKEY))], collation=[[1 ASC-nulls-first]], searchBounds=[[null, ExactBounds [bound=$cor3.C_CUSTKEY], null, null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=17.0, io=1.0, network=17.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=17.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, ORDERS]], index=[_key_PK], requiredColumns=[{2, 3, 5, 6}], inlineScan=[false], collation=[[3 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +====== + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[AND(=($cor3.C_CUSTKEY, $1), =($0, $cor5.L_ORDERKEY))], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor5.L_ORDERKEY], null, null, null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=17.0, io=1.0, network=17.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=17.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, ORDERS]], index=[_key_PK_proxy], requiredColumns=[{2, 3, 5, 6}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +====== + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[AND(=($cor3.C_CUSTKEY, $1), =($0, $cor5.L_ORDERKEY))], collation=[[1 ASC-nulls-first, 0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor5.L_ORDERKEY], ExactBounds [bound=$cor3.C_CUSTKEY], null, null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=17.0, io=1.0, network=17.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=17.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, ORDERS]], index=[{INDEX_CASE:O_CK,O_CK_proxy}], requiredColumns=[{2, 3, 5, 6}], inlineScan=[false], collation=[[3 ASC-nulls-first, 2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +====== + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[AND(=($cor3.C_CUSTKEY, $1), =($0, $cor5.L_ORDERKEY))], collation=[[1 ASC-nulls-first]], searchBounds=[[null, ExactBounds [bound=$cor3.C_CUSTKEY], null, null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=17.0, io=1.0, network=17.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=17.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, ORDERS]], index=[{INDEX_CASE:O_CK,O_CK_proxy}], requiredColumns=[{2, 3, 5, 6}], inlineScan=[false], collation=[[3 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +{ONEOF} + IgniteProject(L_ORDERKEY=[$0]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.0, cpu=4.0, memory=18.0, io=1.0, network=9.0], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[AND(>($1, 300), =($cor6.O_ORDERKEY, $0))], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor6.O_ORDERKEY], null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=3.0, memory=18.0, io=1.0, network=9.0], id = {id} + IgniteColocatedSortAggregate(group=[{0}], agg#0=[SUM($1)], collation=[[0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=3.0, memory=10.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 6}], inlineScan=[false], collation=[[2 ASC-nulls-first, 5 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q18.sql b/modules/calcite/src/test/resources/tpch/q18.sql new file mode 100644 index 0000000000000..5b0d0d4f44561 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q18.sql @@ -0,0 +1,36 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice, + sum(l_quantity) +FROM + customer, + orders, + lineitem +WHERE + o_orderkey IN ( + SELECT l_orderkey + FROM + lineitem + GROUP BY + l_orderkey + HAVING + sum(l_quantity) > 300 + ) + AND c_custkey = o_custkey + AND o_orderkey = l_orderkey +GROUP BY + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice +ORDER BY + o_totalprice DESC, + o_orderdate + LIMIT 100 diff --git a/modules/calcite/src/test/resources/tpch/q19.plan b/modules/calcite/src/test/resources/tpch/q19.plan new file mode 100644 index 0000000000000..922dbf6acbe1e --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q19.plan @@ -0,0 +1,11 @@ +IgniteColocatedHashAggregate(group=[{}], REVENUE=[SUM($0)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=8.0, cpu=14.0, memory=7.0, io=2.0, network=22.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=7.0, cpu=13.0, memory=2.0, io=2.0, network=22.0], id = {id} + IgniteProject($f0=[*($2, -(1, $3))]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=6.0, cpu=12.0, memory=2.0, io=2.0, network=18.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[AND(=($4, $0), OR(AND(=($5, _UTF-8'Brand#12'), SEARCH($7, Sarg[_UTF-8'SM BOX':VARCHAR CHARACTER SET "UTF-8", _UTF-8'SM CASE':VARCHAR CHARACTER SET "UTF-8", _UTF-8'SM PACK':VARCHAR CHARACTER SET "UTF-8", _UTF-8'SM PKG':VARCHAR CHARACTER SET "UTF-8"]:VARCHAR CHARACTER SET "UTF-8"), SEARCH($1, Sarg[[1.00:DECIMAL(15, 2)..11.00:DECIMAL(15, 2)]]:DECIMAL(15, 2)), <=($6, 5)), AND(=($5, _UTF-8'Brand#23'), SEARCH($7, Sarg[_UTF-8'MED BAG':VARCHAR CHARACTER SET "UTF-8", _UTF-8'MED BOX':VARCHAR CHARACTER SET "UTF-8", _UTF-8'MED PACK':VARCHAR CHARACTER SET "UTF-8", _UTF-8'MED PKG':VARCHAR CHARACTER SET "UTF-8"]:VARCHAR CHARACTER SET "UTF-8"), SEARCH($1, Sarg[[10.00:DECIMAL(15, 2)..20.00:DECIMAL(15, 2)]]:DECIMAL(15, 2)), <=($6, 10)), AND(=($5, _UTF-8'Brand#34'), SEARCH($7, Sarg[_UTF-8'LG BOX':VARCHAR CHARACTER SET "UTF-8", _UTF-8'LG CASE':VARCHAR CHARACTER SET "UTF-8", _UTF-8'LG PACK':VARCHAR CHARACTER SET "UTF-8", _UTF-8'LG PKG':VARCHAR CHARACTER SET "UTF-8"]:VARCHAR CHARACTER SET "UTF-8"), SEARCH($1, Sarg[[20.00:DECIMAL(15, 2)..30.00:DECIMAL(15, 2)]]:DECIMAL(15, 2)), <=($6, 15))), OR(AND(<=($6, 5), SEARCH($7, Sarg[_UTF-8'SM BOX':VARCHAR CHARACTER SET "UTF-8", _UTF-8'SM CASE':VARCHAR CHARACTER SET "UTF-8", _UTF-8'SM PACK':VARCHAR CHARACTER SET "UTF-8", _UTF-8'SM PKG':VARCHAR CHARACTER SET "UTF-8"]:VARCHAR CHARACTER SET "UTF-8"), =($5, _UTF-8'Brand#12')), AND(<=($6, 10), SEARCH($7, Sarg[_UTF-8'MED BAG':VARCHAR CHARACTER SET "UTF-8", _UTF-8'MED BOX':VARCHAR CHARACTER SET "UTF-8", _UTF-8'MED PACK':VARCHAR CHARACTER SET "UTF-8", _UTF-8'MED PKG':VARCHAR CHARACTER SET "UTF-8"]:VARCHAR CHARACTER SET "UTF-8"), =($5, _UTF-8'Brand#23')), AND(<=($6, 15), SEARCH($7, Sarg[_UTF-8'LG BOX':VARCHAR CHARACTER SET "UTF-8", _UTF-8'LG CASE':VARCHAR CHARACTER SET "UTF-8", _UTF-8'LG PACK':VARCHAR CHARACTER SET "UTF-8", _UTF-8'LG PKG':VARCHAR CHARACTER SET "UTF-8"]:VARCHAR CHARACTER SET "UTF-8"), =($5, _UTF-8'Brand#34'))), OR(SEARCH($1, Sarg[[1.00:DECIMAL(15, 2)..11.00:DECIMAL(15, 2)]]:DECIMAL(15, 2)), SEARCH($1, Sarg[[10.00:DECIMAL(15, 2)..20.00:DECIMAL(15, 2)]]:DECIMAL(15, 2)), SEARCH($1, Sarg[[20.00:DECIMAL(15, 2)..30.00:DECIMAL(15, 2)]]:DECIMAL(15, 2))))], joinType=[inner], variablesSet=[[$cor0]], variablesSet=[[0]], correlationVariables=[[$cor0]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.0, cpu=11.0, memory=2.0, io=2.0, network=18.0], id = {id} + IgniteExchange(distribution=[affinity[identity=AffinityIdentity [affFuncCls=class org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction, backups=0, partsCnt=1024, filterCls=class org.apache.ignite.configuration.CacheConfiguration$IgniteAllNodesPredicate, hash={hash}, cacheId=-2066312456][0]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=17.0], id = {id} +{ONEOF} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[L_PK_SK], filters=[AND(=($t4, _UTF-8'DELIVER IN PERSON'), OR(=($t5, _UTF-8'AIR'), =($t5, _UTF-8'AIR REG')), AND(>=($t1, 1.00), <=($t1, 30.00)))], rowType=[RecordType(INTEGER L_PARTKEY, DECIMAL(15, 2) L_QUANTITY, DECIMAL(15, 2) L_EXTENDEDPRICE, DECIMAL(15, 2) L_DISCOUNT)], projects=[[$t0, $t1, $t2, $t3]], requiredColumns=[{3, 6, 7, 8, 15, 16}], inlineScan=[false], collation=[[3 ASC-nulls-first, 4 ASC-nulls-first, 2 ASC-nulls-first, 5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} +===== + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[L_PK_SK], filters=[AND(OR(=($t5, _UTF-8'AIR'), =($t5, _UTF-8'AIR REG')), =($t4, _UTF-8'DELIVER IN PERSON'), AND(>=($t1, 1.00), <=($t1, 30.00)))], rowType=[RecordType(INTEGER L_PARTKEY, DECIMAL(15, 2) L_QUANTITY, DECIMAL(15, 2) L_EXTENDEDPRICE, DECIMAL(15, 2) L_DISCOUNT)], projects=[[$t0, $t1, $t2, $t3]], requiredColumns=[{3, 6, 7, 8, 15, 16}], inlineScan=[false], collation=[[3 ASC-nulls-first, 4 ASC-nulls-first, 2 ASC-nulls-first, 5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} +{ONEOF} + IgniteIndexScan(table=[[PUBLIC, PART]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[AND(>=($t2, 1), OR(AND(<=($t2, 5), OR(=($t3, _UTF-8'SM BOX'), =($t3, _UTF-8'SM CASE'), =($t3, _UTF-8'SM PACK'), =($t3, _UTF-8'SM PKG')), =($t1, _UTF-8'Brand#12')), AND(<=($t2, 10), OR(=($t3, _UTF-8'MED BAG'), =($t3, _UTF-8'MED BOX'), =($t3, _UTF-8'MED PACK'), =($t3, _UTF-8'MED PKG')), =($t1, _UTF-8'Brand#23')), AND(<=($t2, 15), OR(=($t3, _UTF-8'LG BOX'), =($t3, _UTF-8'LG CASE'), =($t3, _UTF-8'LG PACK'), =($t3, _UTF-8'LG PKG')), =($t1, _UTF-8'Brand#34'))), =($t0, $cor0.L_PARTKEY), OR(AND(=($t1, _UTF-8'Brand#12'), OR(=($t3, _UTF-8'SM BOX'), =($t3, _UTF-8'SM CASE'), =($t3, _UTF-8'SM PACK'), =($t3, _UTF-8'SM PKG')), AND(>=($cor0.L_QUANTITY, 1.00), <=($cor0.L_QUANTITY, 11.00)), <=($t2, 5)), AND(=($t1, _UTF-8'Brand#23'), OR(=($t3, _UTF-8'MED BAG'), =($t3, _UTF-8'MED BOX'), =($t3, _UTF-8'MED PACK'), =($t3, _UTF-8'MED PKG')), AND(>=($cor0.L_QUANTITY, 10.00), <=($cor0.L_QUANTITY, 20.00)), <=($t2, 10)), AND(=($t1, _UTF-8'Brand#34'), OR(=($t3, _UTF-8'LG BOX'), =($t3, _UTF-8'LG CASE'), =($t3, _UTF-8'LG PACK'), =($t3, _UTF-8'LG PKG')), AND(>=($cor0.L_QUANTITY, 20.00), <=($cor0.L_QUANTITY, 30.00)), <=($t2, 15))), AND(>=($cor0.L_QUANTITY, 1.00), <=($cor0.L_QUANTITY, 30.00)))], requiredColumns=[{2, 5, 7, 8}], searchBounds=[[null, null, ExactBounds [bound=$cor0.L_PARTKEY], null, null, null, null, null, null, null, null]], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q19.sql b/modules/calcite/src/test/resources/tpch/q19.sql new file mode 100644 index 0000000000000..5945c5f7cd7e7 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q19.sql @@ -0,0 +1,37 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT sum(l_extendedprice * (1 - l_discount)) AS revenue +FROM + lineitem, + part +WHERE + ( + p_partkey = l_partkey + AND p_brand = 'Brand#12' + AND p_container IN ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') + AND l_quantity >= 1 AND l_quantity <= 1 + 10 + AND p_size BETWEEN 1 AND 5 + AND l_shipmode IN ('AIR', 'AIR REG') + AND l_shipinstruct = 'DELIVER IN PERSON' + ) + OR + ( + p_partkey = l_partkey + AND p_brand = 'Brand#23' + AND p_container IN ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') + AND l_quantity >= 10 AND l_quantity <= 10 + 10 + AND p_size BETWEEN 1 AND 10 + AND l_shipmode IN ('AIR', 'AIR REG') + AND l_shipinstruct = 'DELIVER IN PERSON' + ) + OR + ( + p_partkey = l_partkey + AND p_brand = 'Brand#34' + AND p_container IN ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') + AND l_quantity >= 20 AND l_quantity <= 20 + 10 + AND p_size BETWEEN 1 AND 15 + AND l_shipmode IN ('AIR', 'AIR REG') + AND l_shipinstruct = 'DELIVER IN PERSON' + ) diff --git a/modules/calcite/src/test/resources/tpch/q2.plan b/modules/calcite/src/test/resources/tpch/q2.plan new file mode 100644 index 0000000000000..c584fc03dd254 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q2.plan @@ -0,0 +1,48 @@ +IgniteLimit(fetch=[100]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=25.3935, cpu=51.09025, memory=84.63187500000001, io=4.348375, network=67.63187500000001], id = {id} + IgniteSort(sort0=[$0], sort1=[$2], sort2=[$1], sort3=[$3], dir0=[DESC-nulls-last], dir1=[ASC-nulls-first], dir2=[ASC-nulls-first], dir3=[ASC-nulls-first], fetch=[100]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=24.3935, cpu=50.09025, memory=84.63187500000001, io=4.348375, network=67.63187500000001], id = {id} + IgniteProject(S_ACCTBAL=[$7], S_NAME=[$3], N_NAME=[$13], P_PARTKEY=[$0], P_MFGR=[$1], S_ADDRESS=[$4], S_PHONE=[$6], S_COMMENT=[$8]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=23.3935, cpu=46.09025, memory=52.631875, io=4.348375, network=67.63187500000001], id = {id} + IgniteFilter(condition=[=($11, $16)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=22.3935, cpu=45.09025, memory=52.631875, io=4.348375, network=67.63187500000001], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[true], joinType=[left], variablesSet=[[$cor0]], variablesSet=[[0]], correlationVariables=[[$cor0]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=21.3935, cpu=41.09025, memory=52.631875, io=4.348375, network=67.63187500000001], id = {id} + IgniteProject(P_PARTKEY=[$0], P_MFGR=[$1], S_SUPPKEY=[$5], S_NAME=[$6], S_ADDRESS=[$7], S_NATIONKEY=[$8], S_PHONE=[$9], S_ACCTBAL=[$10], S_COMMENT=[$11], PS_PARTKEY=[$2], PS_SUPPKEY=[$3], PS_SUPPLYCOST=[$4], N_NATIONKEY=[$12], N_NAME=[$13], N_REGIONKEY=[$14], R_REGIONKEY=[$15]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=13.69, cpu=28.035, memory=33.0625, io=3.1725, network=53.0625], id = {id} + IgniteMergeJoin(condition=[=($0, $2)], joinType=[inner], variablesSet=[[]], leftCollation=[[0 ASC-nulls-first]], rightCollation=[[0 ASC-nulls-first]], allowNulls=[{}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=12.69, cpu=27.035, memory=33.0625, io=3.1725, network=53.0625], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, PART]], index=[{INDEX_CASE:_key_PK_proxy,_key_PK}], filters=[AND(=($t3, 15), LIKE($t2, _UTF-8'%BRASS'))], rowType=[RecordType(INTEGER P_PARTKEY, VARCHAR P_MFGR)], projects=[[$t0, $t1]], requiredColumns=[{2, 4, 6, 7}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($3, $1)], joinType=[inner], variablesSet=[[$cor4]], variablesSet=[[4]], correlationVariables=[[$cor4]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=7.6899999999999995, cpu=13.035, memory=32.0625, io=2.1725, network=44.0625], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=13.0], id = {id} +{ONEOF} + IgniteIndexScan(table=[[PUBLIC, PARTSUPP]], index=[PS_PK], requiredColumns=[{2, 3, 5}], inlineScan=[false], collation=[[2 ASC-nulls-first, 3 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +===== + IgniteIndexScan(table=[[PUBLIC, PARTSUPP]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 3, 5}], inlineScan=[false], collation=[[2 ASC-nulls-first, 3 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +{ONEOF} + IgniteCorrelatedNestedLoopJoin(condition=[=($3, $7)], joinType=[inner], variablesSet=[[$cor5]], variablesSet=[[5]], correlationVariables=[[$cor5]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.6899999999999995, cpu=7.035, memory=31.0625, io=1.1724999999999999, network=31.0625], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($0, $cor4.PS_SUPPKEY)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor4.PS_SUPPKEY], null, null, null, null, null, null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=29.0, io=1.0, network=29.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=29.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, SUPPLIER]], index=[{INDEX_CASE:_key_PK_proxy,_key_PK}], requiredColumns=[{2, 3, 4, 5, 6, 7, 8}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($2, $3)], joinType=[inner], variablesSet=[[$cor6]], variablesSet=[[6]], correlationVariables=[[$cor6]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.6, cpu=6.9, memory=13.75, io=1.15, network=13.75], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor5.S_NATIONKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor5.S_NATIONKEY], null, null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=13.0, io=1.0, network=13.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=13.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, NATION]], index=[{INDEX_CASE:_key_PK_proxy,_key_PK}], requiredColumns=[{2, 3, 4}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor6.N_REGIONKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor6.N_REGIONKEY]]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=6.0, memory=5.0, io=1.0, network=5.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, REGION]], index=[{INDEX_CASE:_key_PK_proxy,_key_PK}], filters=[=($t1, _UTF-8'EUROPE')], rowType=[RecordType(INTEGER R_REGIONKEY)], projects=[[$t0]], requiredColumns=[{2, 3}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteColocatedHashAggregate(group=[{}], EXPR$0=[MIN($0)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=6.7035, cpu=9.055250000000001, memory=19.569375, io=1.175875, network=14.569375], id = {id} + IgniteProject(PS_SUPPLYCOST=[$2]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.7035, cpu=8.055250000000001, memory=14.569375, io=1.175875, network=14.569375], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($3, $1)], joinType=[inner], variablesSet=[[$cor14]], variablesSet=[[14]], correlationVariables=[[$cor14]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.7035, cpu=7.05525, memory=14.569375, io=1.175875, network=14.569375], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor0.P_PARTKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor0.P_PARTKEY], null, null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=13.0, io=1.0, network=13.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=13.0], id = {id} +{ONEOF} + IgniteIndexScan(table=[[PUBLIC, PARTSUPP]], index=[PS_PK], requiredColumns=[{2, 3, 5}], inlineScan=[false], collation=[[2 ASC-nulls-first, 3 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +====== + IgniteIndexScan(table=[[PUBLIC, PARTSUPP]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 3, 5}], inlineScan=[false], collation=[[2 ASC-nulls-first, 3 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +{ONEOF} + IgniteCorrelatedNestedLoopJoin(condition=[=($1, $2)], joinType=[inner], variablesSet=[[$cor15]], variablesSet=[[15]], correlationVariables=[[$cor15]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.6899999999999995, cpu=7.035, memory=10.4625, io=1.1724999999999999, network=10.4625], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($0, $cor14.PS_SUPPKEY)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor14.PS_SUPPKEY], null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, SUPPLIER]], index=[{INDEX_CASE:_key_PK_proxy,_key_PK}], requiredColumns=[{2, 5}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($1, $2)], joinType=[inner], variablesSet=[[$cor16]], variablesSet=[[16]], correlationVariables=[[$cor16]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.6, cpu=6.9, memory=9.75, io=1.15, network=9.75], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor15.S_NATIONKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor15.S_NATIONKEY], null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, NATION]], index=[{INDEX_CASE:_key_PK_proxy,_key_PK}], requiredColumns=[{2, 4}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor16.N_REGIONKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor16.N_REGIONKEY]]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=6.0, memory=5.0, io=1.0, network=5.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, REGION]], index=[{INDEX_CASE:_key_PK_proxy,_key_PK}], filters=[=($t1, _UTF-8'EUROPE')], rowType=[RecordType(INTEGER R_REGIONKEY)], projects=[[$t0]], requiredColumns=[{2, 3}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q2.sql b/modules/calcite/src/test/resources/tpch/q2.sql new file mode 100644 index 0000000000000..c6981c62636ca --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q2.sql @@ -0,0 +1,46 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT + s_acctbal, + s_name, + n_name, + p_partkey, + p_mfgr, + s_address, + s_phone, + s_comment +FROM + part, + supplier, + partsupp, + nation, + region +WHERE + p_partkey = ps_partkey + AND s_suppkey = ps_suppkey + AND p_size = 15 + AND p_type LIKE '%BRASS' + AND s_nationkey = n_nationkey + AND n_regionkey = r_regionkey + AND r_name = 'EUROPE' + AND ps_supplycost = ( + SELECT min(ps_supplycost) + FROM + partsupp, + supplier, + nation, + region + WHERE + p_partkey = ps_partkey + AND s_suppkey = ps_suppkey + AND s_nationkey = n_nationkey + AND n_regionkey = r_regionkey + AND r_name = 'EUROPE' +) +ORDER BY + s_acctbal DESC, + n_name, + s_name, + p_partkey + LIMIT 100 diff --git a/modules/calcite/src/test/resources/tpch/q20.plan b/modules/calcite/src/test/resources/tpch/q20.plan new file mode 100644 index 0000000000000..c26bff5639b9f --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q20.plan @@ -0,0 +1,29 @@ +IgniteSort(sort0=[$0], dir0=[ASC-nulls-first]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=22.05, cpu=45.35, memory=28.7, io=4.15, network=41.95], id = {id} + IgniteProject(S_NAME=[$2], S_ADDRESS=[$3]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=21.05, cpu=41.35, memory=20.7, io=4.15, network=41.95], id = {id} + IgniteMergeJoin(condition=[=($4, $0)], joinType=[inner], variablesSet=[[]], leftCollation=[[0 ASC-nulls-first]], rightCollation=[[3 ASC-nulls-first]], allowNulls=[{}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=20.05, cpu=40.35, memory=20.7, io=4.15, network=41.95], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, NATION]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[=($t1, _UTF-8'CANADA')], rowType=[RecordType(INTEGER N_NATIONKEY)], projects=[[$t0]], requiredColumns=[{2, 3}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($0, $4)], joinType=[inner], variablesSet=[[$cor3]], variablesSet=[[3]], correlationVariables=[[$cor3]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=15.05, cpu=26.35, memory=19.7, io=3.15, network=36.95], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=17.0], id = {id} +{ONEOF} + IgniteIndexScan(table=[[PUBLIC, SUPPLIER]], index=[S_NK], requiredColumns=[{2, 3, 4, 5}], inlineScan=[false], collation=[[5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +===== + IgniteIndexScan(table=[[PUBLIC, SUPPLIER]], index=[S_NK_proxy], requiredColumns=[{2, 3, 4, 5}], inlineScan=[false], collation=[[5 ASC-nulls-first, 2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +{ONEOF} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor3.S_SUPPKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor3.S_SUPPKEY]]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=12.05, cpu=20.35, memory=18.7, io=2.15, network=19.95], id = {id} + IgniteColocatedSortAggregate(group=[{0}], collation=[[0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=11.05, cpu=20.35, memory=14.7, io=2.15, network=19.95], id = {id} + IgniteProject(PS_SUPPKEY=[$1]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=10.05, cpu=19.35, memory=10.7, io=2.15, network=19.95], id = {id} + IgniteFilter(condition=[>(CAST($2):DECIMAL(32767, 1) NOT NULL, $4)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=9.05, cpu=18.35, memory=10.7, io=2.15, network=19.95], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[true], joinType=[left], variablesSet=[[$cor0]], variablesSet=[[0]], correlationVariables=[[$cor0]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=8.05, cpu=14.35, memory=10.7, io=2.15, network=19.95], id = {id} + IgniteNestedLoopJoin(condition=[=($0, $3)], joinType=[inner], variablesSet=[[]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=6.0, cpu=9.0, memory=8.0, io=2.0, network=18.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=13.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, PARTSUPP]], index=[PS_SK_PK], requiredColumns=[{2, 3, 4}], inlineScan=[false], collation=[[3 ASC-nulls-first, 2 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteColocatedHashAggregate(group=[{0}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=3.0, memory=3.0, io=1.0, network=5.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteTableScan(table=[[PUBLIC, PART]], filters=[LIKE($t1, _UTF-8'forest%')], rowType=[RecordType(INTEGER P_PARTKEY)], projects=[[$t0]], requiredColumns=[{2, 3}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteProject(EXPR$0=[*(0.5:DECIMAL(2, 1), $0)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=7.0, cpu=9.0, memory=18.0, io=1.0, network=13.0], id = {id} + IgniteColocatedHashAggregate(group=[{}], agg#0=[SUM($0)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=6.0, cpu=8.0, memory=18.0, io=1.0, network=13.0], id = {id} + IgniteProject(L_QUANTITY=[$2]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.0, cpu=7.0, memory=13.0, io=1.0, network=13.0], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[AND(=($0, $cor0.PS_PARTKEY), =($1, $cor0.PS_SUPPKEY))], collation=[[0 ASC-nulls-first, 1 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor0.PS_PARTKEY], ExactBounds [bound=$cor0.PS_SUPPKEY], null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=6.0, memory=13.0, io=1.0, network=13.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=13.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[L_PK_SK], filters=[AND(>=($t3, 1994-01-01), <($t3, 1995-01-01))], rowType=[RecordType(INTEGER L_PARTKEY, INTEGER L_SUPPKEY, DECIMAL(15, 2) L_QUANTITY)], projects=[[$t0, $t1, $t2]], requiredColumns=[{3, 4, 6, 12}], inlineScan=[false], collation=[[3 ASC-nulls-first, 4 ASC-nulls-first, 2 ASC-nulls-first, 5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q20.sql b/modules/calcite/src/test/resources/tpch/q20.sql new file mode 100644 index 0000000000000..41ce83f04d8db --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q20.sql @@ -0,0 +1,35 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT + s_name, + s_address +FROM + supplier, nation +WHERE + s_suppkey IN ( + SELECT ps_suppkey + FROM + partsupp + WHERE + ps_partkey IN ( + SELECT p_partkey + FROM + part + WHERE + p_name LIKE 'forest%' + ) + AND ps_availqty > ( + SELECT 0.5 * sum(l_quantity) + FROM + lineitem + WHERE + l_partkey = ps_partkey + AND l_suppkey = ps_suppkey + AND l_shipdate >= date('1994-01-01') + AND l_shipdate < date('1994-01-01') + interval '1' YEAR + ) + ) + AND s_nationkey = n_nationkey + AND n_name = 'CANADA' +ORDER BY s_name diff --git a/modules/calcite/src/test/resources/tpch/q21.plan b/modules/calcite/src/test/resources/tpch/q21.plan new file mode 100644 index 0000000000000..35c5591cb0978 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q21.plan @@ -0,0 +1,31 @@ +IgniteLimit(fetch=[100]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=32.6, cpu=62.9, memory=54.25, io=5.15, network=45.75], id = {id} + IgniteSort(sort0=[$1], sort1=[$0], dir0=[DESC-nulls-last], dir1=[ASC-nulls-first], fetch=[100]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=31.6, cpu=61.9, memory=54.25, io=5.15, network=45.75], id = {id} + IgniteColocatedHashAggregate(group=[{0}], NUMWAIT=[COUNT()]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=30.6, cpu=57.9, memory=46.25, io=5.15, network=45.75], id = {id} + IgniteProject(S_NAME=[$1]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=29.6, cpu=56.9, memory=41.75, io=5.15, network=45.75], id = {id} + IgniteFilter(condition=[IS NULL($8)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=28.6, cpu=55.9, memory=41.75, io=5.15, network=45.75], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[true], joinType=[left], variablesSet=[[$cor0]], variablesSet=[[0]], correlationVariables=[[$cor0]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=27.6, cpu=51.9, memory=41.75, io=5.15, network=45.75], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[true], joinType=[inner], variablesSet=[[$cor4]], variablesSet=[[4]], correlationVariables=[[$cor4]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=20.6, cpu=39.9, memory=28.75, io=4.15, network=36.75], id = {id} + IgniteProject(S_SUPPKEY=[$3], S_NAME=[$4], S_NATIONKEY=[$5], L_ORDERKEY=[$1], L_SUPPKEY=[$2], O_ORDERKEY=[$0], N_NATIONKEY=[$6]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=14.6, cpu=31.9, memory=15.75, io=3.15, network=27.75], id = {id} + IgniteMergeJoin(condition=[=($0, $1)], joinType=[inner], variablesSet=[[]], leftCollation=[[0 ASC-nulls-first]], rightCollation=[[0 ASC-nulls-first]], allowNulls=[{}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=13.6, cpu=30.9, memory=15.75, io=3.15, network=27.75], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, ORDERS]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[=($t1, _UTF-8'F')], rowType=[RecordType(INTEGER O_ORDERKEY)], projects=[[$t0]], requiredColumns=[{2, 4}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($2, $1)], joinType=[inner], variablesSet=[[$cor6]], variablesSet=[[6]], correlationVariables=[[$cor6]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=8.6, cpu=16.9, memory=14.75, io=2.15, network=22.75], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[>($t3, $t2)], rowType=[RecordType(INTEGER L_ORDERKEY, INTEGER L_SUPPKEY)], projects=[[$t0, $t1]], requiredColumns=[{2, 4, 13, 14}], inlineScan=[false], collation=[[2 ASC-nulls-first, 5 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($2, $3)], joinType=[inner], variablesSet=[[$cor7]], variablesSet=[[7]], correlationVariables=[[$cor7]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.6, cpu=6.9, memory=13.75, io=1.15, network=13.75], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($0, $cor6.L_SUPPKEY)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor6.L_SUPPKEY], null, null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=13.0, io=1.0, network=13.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=13.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, SUPPLIER]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 3, 5}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor7.S_NATIONKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor7.S_NATIONKEY]]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=6.0, memory=5.0, io=1.0, network=5.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, NATION]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[=($t1, _UTF-8'SAUDI ARABIA')], rowType=[RecordType(INTEGER N_NATIONKEY)], projects=[[$t0]], requiredColumns=[{2, 3}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteColocatedHashAggregate(group=[{0}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.0, cpu=4.0, memory=13.0, io=1.0, network=9.0], id = {id} + IgniteProject(i=[true]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=3.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[AND(=($0, $cor4.L_ORDERKEY), <>($1, $cor4.L_SUPPKEY))], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor4.L_ORDERKEY], null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 4}], inlineScan=[false], collation=[[2 ASC-nulls-first, 5 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteColocatedHashAggregate(group=[{0}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=6.0, cpu=8.0, memory=13.0, io=1.0, network=9.0], id = {id} + IgniteProject(i=[true]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.0, cpu=7.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[AND(=($0, $cor0.L_ORDERKEY), <>($1, $cor0.L_SUPPKEY))], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor0.L_ORDERKEY], null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=6.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[>($t3, $t2)], rowType=[RecordType(INTEGER L_ORDERKEY, INTEGER L_SUPPKEY)], projects=[[$t0, $t1]], requiredColumns=[{2, 4, 13, 14}], inlineScan=[false], collation=[[2 ASC-nulls-first, 5 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q21.sql b/modules/calcite/src/test/resources/tpch/q21.sql new file mode 100644 index 0000000000000..0373124f1a6e6 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q21.sql @@ -0,0 +1,41 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT + s_name, + count(*) AS numwait +FROM + supplier, + lineitem l1, + orders, + nation +WHERE + s_suppkey = l1.l_suppkey + AND o_orderkey = l1.l_orderkey + AND o_orderstatus = 'F' + AND l1.l_receiptdate > l1.l_commitdate + AND exists( + SELECT * + FROM + lineitem l2 + WHERE + l2.l_orderkey = l1.l_orderkey + AND l2.l_suppkey <> l1.l_suppkey + ) + AND NOT exists( + SELECT * + FROM + lineitem l3 + WHERE + l3.l_orderkey = l1.l_orderkey + AND l3.l_suppkey <> l1.l_suppkey + AND l3.l_receiptdate > l3.l_commitdate + ) + AND s_nationkey = n_nationkey + AND n_name = 'SAUDI ARABIA' +GROUP BY + s_name +ORDER BY + numwait DESC, + s_name + LIMIT 100 diff --git a/modules/calcite/src/test/resources/tpch/q22.plan b/modules/calcite/src/test/resources/tpch/q22.plan new file mode 100644 index 0000000000000..2b64be7a62f10 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q22.plan @@ -0,0 +1,20 @@ +IgniteColocatedSortAggregate(group=[{0}], NUMCUST=[COUNT()], TOTACCTBAL=[SUM($1)], collation=[[0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=13.5, cpu=25.0, memory=37.5, io=2.5, network=20.5], id = {id} + IgniteSort(sort0=[$0], dir0=[ASC-nulls-first]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=12.5, cpu=24.0, memory=23.5, io=2.5, network=20.5], id = {id} + IgniteProject(CNTRYCODE=[SUBSTR($1, 1, 2)], C_ACCTBAL=[$2]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=11.5, cpu=20.0, memory=15.5, io=2.5, network=20.5], id = {id} + IgniteFilter(condition=[IS NULL($4)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=10.5, cpu=19.0, memory=15.5, io=2.5, network=20.5], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[true], joinType=[left], variablesSet=[[$cor0]], variablesSet=[[0]], correlationVariables=[[$cor0]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=9.5, cpu=15.0, memory=15.5, io=2.5, network=20.5], id = {id} + IgniteNestedLoopJoin(condition=[>($2, $3)], joinType=[inner], variablesSet=[[]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=6.0, cpu=9.0, memory=11.0, io=2.0, network=18.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=13.0], id = {id} + IgniteTableScan(table=[[PUBLIC, CUSTOMER]], filters=[OR(=(SUBSTR($t1, 1, 2), _UTF-8'13'), =(SUBSTR($t1, 1, 2), _UTF-8'31'), =(SUBSTR($t1, 1, 2), _UTF-8'23'), =(SUBSTR($t1, 1, 2), _UTF-8'29'), =(SUBSTR($t1, 1, 2), _UTF-8'30'), =(SUBSTR($t1, 1, 2), _UTF-8'18'), =(SUBSTR($t1, 1, 2), _UTF-8'17'))], requiredColumns=[{2, 6, 7}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteColocatedHashAggregate(group=[{}], EXPR$0=[AVG($0)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=3.0, memory=6.0, io=1.0, network=5.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteTableScan(table=[[PUBLIC, CUSTOMER]], filters=[AND(>($t1, 0.00), OR(=(SUBSTR($t0, 1, 2), _UTF-8'13'), =(SUBSTR($t0, 1, 2), _UTF-8'31'), =(SUBSTR($t0, 1, 2), _UTF-8'23'), =(SUBSTR($t0, 1, 2), _UTF-8'29'), =(SUBSTR($t0, 1, 2), _UTF-8'30'), =(SUBSTR($t0, 1, 2), _UTF-8'18'), =(SUBSTR($t0, 1, 2), _UTF-8'17')))], rowType=[RecordType(DECIMAL(15, 2) C_ACCTBAL)], projects=[[$t1]], requiredColumns=[{6, 7}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteColocatedHashAggregate(group=[{0}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.0, cpu=4.0, memory=9.0, io=1.0, network=5.0], id = {id} + IgniteProject(i=[true]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=3.0, memory=5.0, io=1.0, network=5.0], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($0, $cor0.C_CUSTKEY)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor0.C_CUSTKEY]]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=5.0, io=1.0, network=5.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=5.0], id = {id} +{ONEOF} + IgniteIndexScan(table=[[PUBLIC, ORDERS]], index=[O_CK], requiredColumns=[{3}], inlineScan=[true], collation=[[3 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +===== + IgniteIndexScan(table=[[PUBLIC, ORDERS]], index=[O_CK_proxy], requiredColumns=[{3}], inlineScan=[true], collation=[[3 ASC-nulls-first, 2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +{ONEOF} diff --git a/modules/calcite/src/test/resources/tpch/q22.sql b/modules/calcite/src/test/resources/tpch/q22.sql new file mode 100644 index 0000000000000..d24b936bd4218 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q22.sql @@ -0,0 +1,37 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT + cntrycode, + count(*) AS numcust, + sum(c_acctbal) AS totacctbal +FROM ( + SELECT + substr(c_phone, 1, 2) AS cntrycode, + c_acctbal + FROM + customer + WHERE + substr(c_phone, 1, 2) IN + ('13', '31', '23', '29', '30', '18', '17') + AND c_acctbal > ( + SELECT avg(c_acctbal) + FROM + customer + WHERE + c_acctbal > 0.00 + AND substr(c_phone, 1, 2) IN + ('13', '31', '23', '29', '30', '18', '17') + ) + AND NOT exists( + SELECT * + FROM + orders + WHERE + o_custkey = c_custkey + ) + ) AS custsale +GROUP BY + cntrycode +ORDER BY + cntrycode diff --git a/modules/calcite/src/test/resources/tpch/q3.plan b/modules/calcite/src/test/resources/tpch/q3.plan new file mode 100644 index 0000000000000..d5eda79e2a7b3 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q3.plan @@ -0,0 +1,18 @@ +IgniteLimit(fetch=[10]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=17.0, cpu=35.0, memory=37.875, io=3.0, network=35.0], id = {id} +{ONEOF} + IgniteSort(sort0=[$1], sort1=[$2], dir0=[DESC-nulls-last], dir1=[ASC-nulls-first], fetch=[10]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=16.0, cpu=34.0, memory=37.875, io=3.0, network=35.0], id = {id} +===== + IgniteSort(sort0=[$1], sort1=[$2], dir0=[DESC-nulls-last], dir1=[ASC-nulls-first]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=16.0, cpu=34.0, memory=37.875, io=3.0, network=35.0], id = {id} +{ONEOF} + IgniteProject(L_ORDERKEY=[$0], REVENUE=[$3], O_ORDERDATE=[$1], O_SHIPPRIORITY=[$2]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=15.0, cpu=30.0, memory=21.875, io=3.0, network=35.0], id = {id} + IgniteColocatedHashAggregate(group=[{0, 1, 2}], REVENUE=[SUM($3)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=14.0, cpu=29.0, memory=21.875, io=3.0, network=35.0], id = {id} + IgniteProject(L_ORDERKEY=[$0], O_ORDERDATE=[$6], O_SHIPPRIORITY=[$7], $f3=[*($1, -(1, $2))]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=13.0, cpu=28.0, memory=7.0, io=3.0, network=35.0], id = {id} + IgniteMergeJoin(condition=[=($0, $4)], joinType=[inner], variablesSet=[[]], leftCollation=[[0 ASC-nulls-first]], rightCollation=[[1 ASC-nulls-first]], allowNulls=[{}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=12.0, cpu=27.0, memory=7.0, io=3.0, network=35.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=13.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[>($t3, 1995-03-15)], rowType=[RecordType(INTEGER L_ORDERKEY, DECIMAL(15, 2) L_EXTENDEDPRICE, DECIMAL(15, 2) L_DISCOUNT)], projects=[[$t0, $t1, $t2]], requiredColumns=[{2, 7, 8, 12}], inlineScan=[false], collation=[[2 ASC-nulls-first, 5 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteProject(C_CUSTKEY=[$4], O_ORDERKEY=[$0], O_CUSTKEY=[$1], O_ORDERDATE=[$2], O_SHIPPRIORITY=[$3]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=7.0, cpu=13.0, memory=6.0, io=2.0, network=22.0], id = {id} + IgniteNestedLoopJoin(condition=[=($4, $1)], joinType=[inner], variablesSet=[[]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=6.0, cpu=12.0, memory=6.0, io=2.0, network=22.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=17.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, ORDERS]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[<($t2, 1995-03-15)], requiredColumns=[{2, 3, 6, 9}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteTableScan(table=[[PUBLIC, CUSTOMER]], filters=[=($t1, _UTF-8'BUILDING')], rowType=[RecordType(INTEGER C_CUSTKEY)], projects=[[$t0]], requiredColumns=[{2, 8}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q3.sql b/modules/calcite/src/test/resources/tpch/q3.sql new file mode 100644 index 0000000000000..8a6eab5ce987f --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q3.sql @@ -0,0 +1,26 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT + l_orderkey, + sum(l_extendedprice * (1 - l_discount)) AS revenue, + o_orderdate, + o_shippriority +FROM + customer, + orders, + lineitem +WHERE + c_mktsegment = 'BUILDING' + AND c_custkey = o_custkey + AND l_orderkey = o_orderkey + AND o_orderdate < DATE '1995-03-15' + AND l_shipdate > DATE '1995-03-15' +GROUP BY + l_orderkey, + o_orderdate, + o_shippriority +ORDER BY + revenue DESC, + o_orderdate + LIMIT 10 diff --git a/modules/calcite/src/test/resources/tpch/q4.plan b/modules/calcite/src/test/resources/tpch/q4.plan new file mode 100644 index 0000000000000..0fc032fbf18aa --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q4.plan @@ -0,0 +1,11 @@ +IgniteColocatedSortAggregate(group=[{0}], ORDER_COUNT=[COUNT()], collation=[[0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=12.0, cpu=20.0, memory=23.0, io=2.0, network=14.0], id = {id} + IgniteSort(sort0=[$0], dir0=[ASC-nulls-first]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=11.0, cpu=19.0, memory=14.0, io=2.0, network=14.0], id = {id} + IgniteProject(O_ORDERPRIORITY=[$1]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=10.0, cpu=15.0, memory=10.0, io=2.0, network=14.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[true], joinType=[inner], variablesSet=[[$cor0]], variablesSet=[[0]], correlationVariables=[[$cor0]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=9.0, cpu=14.0, memory=10.0, io=2.0, network=14.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, ORDERS]], index=[O_OD], filters=[AND(>=($t1, 1993-07-01), <($t1, 1993-10-01))], rowType=[RecordType(INTEGER O_ORDERKEY, VARCHAR O_ORDERPRIORITY)], projects=[[$t0, $t2]], requiredColumns=[{2, 6, 7}], searchBounds=[[null, null, null, null, null, null, RangeBounds [lowerBound=1993-07-01, upperBound=1993-10-01, lowerInclude=true, upperInclude=false], null, null, null, null]], inlineScan=[false], collation=[[6 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteColocatedHashAggregate(group=[{0}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=6.0, cpu=8.0, memory=9.0, io=1.0, network=5.0], id = {id} + IgniteProject(i=[true]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.0, cpu=7.0, memory=5.0, io=1.0, network=5.0], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($0, $cor0.O_ORDERKEY)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor0.O_ORDERKEY]]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=6.0, memory=5.0, io=1.0, network=5.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[<($t1, $t2)], rowType=[RecordType(INTEGER L_ORDERKEY)], projects=[[$t0]], requiredColumns=[{2, 13, 14}], inlineScan=[false], collation=[[2 ASC-nulls-first, 5 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q4.sql b/modules/calcite/src/test/resources/tpch/q4.sql new file mode 100644 index 0000000000000..18ca1817e0bb5 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q4.sql @@ -0,0 +1,21 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT + o_orderpriority, + count(*) AS order_count +FROM orders +WHERE + o_orderdate >= DATE '1993-07-01' + AND o_orderdate < DATE '1993-07-01' + INTERVAL '3' MONTH + AND EXISTS ( + SELECT * + FROM lineitem + WHERE + l_orderkey = o_orderkey + AND l_commitdate < l_receiptdate + ) +GROUP BY + o_orderpriority +ORDER BY + o_orderpriority diff --git a/modules/calcite/src/test/resources/tpch/q5.plan b/modules/calcite/src/test/resources/tpch/q5.plan new file mode 100644 index 0000000000000..9e63eb8699872 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q5.plan @@ -0,0 +1,26 @@ +IgniteSort(sort0=[$1], dir0=[DESC-nulls-last]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=15.7035, cpu=30.05525, memory=41.159375, io=3.175875, network=36.659375], id = {id} + IgniteColocatedHashAggregate(group=[{0}], REVENUE=[SUM($1)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=14.7035, cpu=26.05525, memory=33.159375, io=3.175875, network=36.659375], id = {id} + IgniteProject(N_NAME=[$11], $f1=[*($6, -(1, $7))]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=13.7035, cpu=25.05525, memory=28.659375, io=3.175875, network=36.659375], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[AND(=($1, $9), =($0, $3))], joinType=[inner], variablesSet=[[$cor10]], variablesSet=[[10]], correlationVariables=[[$cor10]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=12.7035, cpu=24.05525, memory=28.659375, io=3.175875, network=36.659375], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, CUSTOMER]], index=[C_NK_proxy], requiredColumns=[{2, 5}], inlineScan=[true], collation=[[5 ASC-nulls-first, 2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteFilter(condition=[AND(=($cor10.C_NATIONKEY, $7), =($cor10.C_CUSTKEY, $1))]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=9.7035, cpu=18.05525, memory=27.659375, io=2.175875, network=27.659375], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($2, $0)], joinType=[inner], variablesSet=[[$cor6]], variablesSet=[[6]], correlationVariables=[[$cor6]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=8.7035, cpu=14.055250000000001, memory=27.659375, io=2.175875, network=27.659375], id = {id} + IgniteTableSpool(readType=[LAZY], writeType=[EAGER]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=3.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, ORDERS]], index=[O_OD], filters=[AND(>=($t2, 1994-01-01), <($t2, 1995-01-01))], rowType=[RecordType(INTEGER O_ORDERKEY, INTEGER O_CUSTKEY)], projects=[[$t0, $t1]], requiredColumns=[{2, 3, 6}], searchBounds=[[null, null, null, null, null, null, RangeBounds [lowerBound=1994-01-01, upperBound=1995-01-01, lowerInclude=true, upperInclude=false], null, null, null, null]], inlineScan=[false], collation=[[6 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($1, $4)], joinType=[inner], variablesSet=[[$cor7]], variablesSet=[[7]], correlationVariables=[[$cor7]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.7035, cpu=7.05525, memory=18.659375, io=1.175875, network=18.659375], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($0, $cor6.O_ORDERKEY)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor6.O_ORDERKEY], null, null, null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=17.0, io=1.0, network=17.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=17.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 4, 7, 8}], inlineScan=[false], collation=[[2 ASC-nulls-first, 5 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($1, $2)], joinType=[inner], variablesSet=[[$cor8]], variablesSet=[[8]], correlationVariables=[[$cor8]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.6899999999999995, cpu=7.035, memory=11.0625, io=1.1724999999999999, network=11.0625], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor7.L_SUPPKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor7.L_SUPPKEY], null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, SUPPLIER]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 5}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($2, $3)], joinType=[inner], variablesSet=[[$cor9]], variablesSet=[[9]], correlationVariables=[[$cor9]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.6, cpu=6.9, memory=13.75, io=1.15, network=13.75], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor8.S_NATIONKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor8.S_NATIONKEY], null, null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=13.0, io=1.0, network=13.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=13.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, NATION]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 3, 4}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor9.N_REGIONKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor9.N_REGIONKEY]]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=6.0, memory=5.0, io=1.0, network=5.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, REGION]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[=($t1, _UTF-8'ASIA')], rowType=[RecordType(INTEGER R_REGIONKEY)], projects=[[$t0]], requiredColumns=[{2, 3}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q5.sql b/modules/calcite/src/test/resources/tpch/q5.sql new file mode 100644 index 0000000000000..2a07e3a5de52b --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q5.sql @@ -0,0 +1,27 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT + n_name, + sum(l_extendedprice * (1 - l_discount)) AS revenue +FROM + customer, + orders, + lineitem, + supplier, + nation, + region +WHERE + c_custkey = o_custkey + AND l_orderkey = o_orderkey + AND l_suppkey = s_suppkey + AND c_nationkey = s_nationkey + AND s_nationkey = n_nationkey + AND n_regionkey = r_regionkey + AND r_name = 'ASIA' + AND o_orderdate >= DATE '1994-01-01' + AND o_orderdate < DATE '1994-01-01' + INTERVAL '1' YEAR +GROUP BY + n_name +ORDER BY + revenue DESC diff --git a/modules/calcite/src/test/resources/tpch/q6.plan b/modules/calcite/src/test/resources/tpch/q6.plan new file mode 100644 index 0000000000000..68b06ae548564 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q6.plan @@ -0,0 +1,3 @@ +IgniteColocatedHashAggregate(group=[{}], REVENUE=[SUM($0)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=3.0, memory=6.0, io=1.0, network=5.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[L_SD], filters=[AND(AND(>=($t3, 1994-01-01), <($t3, 1995-01-01)), AND(>=($t2, 0.05:DECIMAL(4, 2)), <=($t2, 0.07:DECIMAL(4, 2))), <($t0, 24.00))], rowType=[RecordType(DECIMAL(30, 4) $f0)], projects=[[*($t1, $t2)]], requiredColumns=[{6, 7, 8, 12}], searchBounds=[[null, null, null, null, null, null, null, null, null, null, null, null, RangeBounds [lowerBound=1994-01-01, upperBound=1995-01-01, lowerInclude=true, upperInclude=false], null, null, null, null, null]], inlineScan=[false], collation=[[12 ASC-nulls-first, 2 ASC-nulls-first, 5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q6.sql b/modules/calcite/src/test/resources/tpch/q6.sql new file mode 100644 index 0000000000000..075cf6bd1b5f6 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q6.sql @@ -0,0 +1,11 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT sum(l_extendedprice * l_discount) AS revenue +FROM + lineitem +WHERE + l_shipdate >= DATE '1994-01-01' + AND l_shipdate < DATE '1994-01-01' + INTERVAL '1' YEAR + AND l_discount BETWEEN decimal '0.06' - decimal '0.01' AND decimal '0.06' + decimal '0.01' + AND l_quantity < 24 diff --git a/modules/calcite/src/test/resources/tpch/q7.plan b/modules/calcite/src/test/resources/tpch/q7.plan new file mode 100644 index 0000000000000..6ccc81d091248 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q7.plan @@ -0,0 +1,29 @@ +IgniteSort(sort0=[$0], sort1=[$1], sort2=[$2], dir0=[ASC-nulls-first], dir1=[ASC-nulls-first], dir2=[ASC-nulls-first]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=16.700125, cpu=37.04175, memory=55.457875, io=3.175875, network=40.582875], id = {id} + IgniteColocatedHashAggregate(group=[{0, 1, 2}], REVENUE=[SUM($3)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=15.700125, cpu=33.04175, memory=39.457875, io=3.175875, network=40.582875], id = {id} + IgniteProject(SUPP_NATION=[$1], CUST_NATION=[$14], L_YEAR=[EXTRACT(FLAG(YEAR), $8)], VOLUME=[*($6, -(1, $7))]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=14.700125, cpu=32.04175, memory=24.582875, io=3.175875, network=40.582875], id = {id} + IgniteFilter(condition=[AND(OR(AND(=($1, _UTF-8'FRANCE'), =($14, _UTF-8'GERMANY')), AND(=($1, _UTF-8'GERMANY'), =($14, _UTF-8'FRANCE'))), SEARCH($1, Sarg[_UTF-8'FRANCE':VARCHAR CHARACTER SET "UTF-8", _UTF-8'GERMANY':VARCHAR CHARACTER SET "UTF-8"]:VARCHAR CHARACTER SET "UTF-8"), SEARCH($14, Sarg[_UTF-8'FRANCE':VARCHAR CHARACTER SET "UTF-8", _UTF-8'GERMANY':VARCHAR CHARACTER SET "UTF-8"]:VARCHAR CHARACTER SET "UTF-8"), OR(=($1, _UTF-8'FRANCE'), =($1, _UTF-8'GERMANY')), OR(=($14, _UTF-8'GERMANY'), =($14, _UTF-8'FRANCE')))]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=13.700125, cpu=31.04175, memory=24.582875, io=3.175875, network=40.582875], id = {id} + IgniteMergeJoin(condition=[=($3, $0)], joinType=[inner], variablesSet=[[]], leftCollation=[[0 ASC-nulls-first]], rightCollation=[[1 ASC-nulls-first]], allowNulls=[{}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=12.700125, cpu=27.04175, memory=24.582875, io=3.175875, network=40.582875], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, NATION]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 3}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($0, $3)], joinType=[inner], variablesSet=[[$cor6]], variablesSet=[[6]], correlationVariables=[[$cor6]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=8.700125, cpu=17.04175, memory=23.582875, io=2.175875, network=31.582875], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} +{ONEOF} + IgniteIndexScan(table=[[PUBLIC, SUPPLIER]], index=[S_NK_proxy], requiredColumns=[{2, 5}], inlineScan=[true], collation=[[5 ASC-nulls-first, 2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +===== + IgniteIndexScan(table=[[PUBLIC, SUPPLIER]], index=[S_NK], requiredColumns=[{2, 5}], inlineScan=[false], collation=[[5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +{ONEOF} + IgniteCorrelatedNestedLoopJoin(condition=[=($5, $0)], joinType=[inner], variablesSet=[[$cor7]], variablesSet=[[7]], correlationVariables=[[$cor7]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.700125, cpu=11.04175, memory=22.582875, io=1.175875, network=22.582875], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor6.S_SUPPKEY, $1)], collation=[[1 ASC-nulls-first]], searchBounds=[[null, ExactBounds [bound=$cor6.S_SUPPKEY], null, null, null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=6.0, memory=21.0, io=1.0, network=21.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=21.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[L_SK_PK], filters=[AND(>=($t4, 1995-01-01), <=($t4, 1996-12-31))], requiredColumns=[{2, 4, 7, 8, 12}], inlineScan=[false], collation=[[4 ASC-nulls-first, 3 ASC-nulls-first, 2 ASC-nulls-first, 5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($2, $1)], joinType=[inner], variablesSet=[[$cor8]], variablesSet=[[8]], correlationVariables=[[$cor8]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.6675, cpu=6.945, memory=10.5525, io=1.1724999999999999, network=10.5525], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($0, $cor7.L_ORDERKEY)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor7.L_ORDERKEY], null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, ORDERS]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 3}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($1, $2)], joinType=[inner], variablesSet=[[$cor9]], variablesSet=[[9]], correlationVariables=[[$cor9]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.45, cpu=6.3, memory=10.35, io=1.15, network=10.35], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($0, $cor8.O_CUSTKEY)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor8.O_CUSTKEY], null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, CUSTOMER]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 5}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor9.C_NATIONKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor9.C_NATIONKEY], null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, NATION]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 3}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q7.sql b/modules/calcite/src/test/resources/tpch/q7.sql new file mode 100644 index 0000000000000..a98318a1f3654 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q7.sql @@ -0,0 +1,41 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT + supp_nation, + cust_nation, + l_year, + sum(volume) AS revenue +FROM ( + SELECT + n1.n_name AS supp_nation, + n2.n_name AS cust_nation, + extract(YEAR FROM l_shipdate) AS l_year, + l_extendedprice * (1 - l_discount) AS volume + FROM + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2 + WHERE + s_suppkey = l_suppkey + AND o_orderkey = l_orderkey + AND c_custkey = o_custkey + AND s_nationkey = n1.n_nationkey + AND c_nationkey = n2.n_nationkey + AND ( + (n1.n_name = 'FRANCE' AND n2.n_name = 'GERMANY') + OR (n1.n_name = 'GERMANY' AND n2.n_name = 'FRANCE') + ) + AND l_shipdate BETWEEN DATE '1995-01-01' AND DATE '1996-12-31' + ) AS shipping +GROUP BY + supp_nation, + cust_nation, + l_year +ORDER BY + supp_nation, + cust_nation, + l_year diff --git a/modules/calcite/src/test/resources/tpch/q8.plan b/modules/calcite/src/test/resources/tpch/q8.plan new file mode 100644 index 0000000000000..36dc762e828a6 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q8.plan @@ -0,0 +1,39 @@ +IgniteSort(sort0=[$0], dir0=[ASC-nulls-first]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=16.72832875, cpu=31.148743125, memory=44.477810937499996, io=3.1764571875, network=26.4778109375], id = {id} + IgniteProject(O_YEAR=[$0], MKT_SHARE=[/($1, $2)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=15.72832875, cpu=27.148743125, memory=36.477810937499996, io=3.1764571875, network=26.4778109375], id = {id} + IgniteColocatedHashAggregate(group=[{0}], agg#0=[SUM($1)], agg#1=[SUM($2)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=14.72832875, cpu=26.148743125, memory=36.477810937499996, io=3.1764571875, network=26.4778109375], id = {id} + IgniteProject(O_YEAR=[EXTRACT(FLAG(YEAR), $12)], $f1=[CASE(=($2, _UTF-8'BRAZIL'), *($8, -(1, $9)), 0.0000:DECIMAL(31, 4))], VOLUME=[*($8, -(1, $9))]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=13.72832875, cpu=25.148743125, memory=22.4778109375, io=3.1764571875, network=26.4778109375], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($0, $6)], joinType=[inner], variablesSet=[[$cor21]], variablesSet=[[21]], correlationVariables=[[$cor21]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=12.72832875, cpu=24.148743125, memory=22.4778109375, io=3.1764571875, network=26.4778109375], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteTableScan(table=[[PUBLIC, PART]], filters=[=($t1, _UTF-8'ECONOMY ANODIZED STEEL')], rowType=[RecordType(INTEGER P_PARTKEY)], projects=[[$t0]], requiredColumns=[{2, 6}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteFilter(condition=[=($cor21.P_PARTKEY, $5)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=9.72832875, cpu=18.148743125, memory=21.4778109375, io=2.1764571875, network=21.4778109375], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($3, $0)], joinType=[inner], variablesSet=[[$cor15]], variablesSet=[[15]], correlationVariables=[[$cor15]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=8.72832875, cpu=14.148743125, memory=21.4778109375, io=2.1764571875, network=21.4778109375], id = {id} + IgniteTableSpool(readType=[LAZY], writeType=[EAGER]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=3.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, NATION]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 3}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($0, $4)], joinType=[inner], variablesSet=[[$cor16]], variablesSet=[[16]], correlationVariables=[[$cor16]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.72832875, cpu=7.148743125, memory=12.4778109375, io=1.1764571875, network=12.4778109375], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($1, $cor15.N_NATIONKEY)], collation=[[1 ASC-nulls-first]], searchBounds=[[null, ExactBounds [bound=$cor15.N_NATIONKEY]]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} +{ONEOF} + IgniteIndexScan(table=[[PUBLIC, SUPPLIER]], index=[S_NK_proxy], requiredColumns=[{2, 5}], inlineScan=[true], collation=[[5 ASC-nulls-first, 2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +===== + IgniteIndexScan(table=[[PUBLIC, SUPPLIER]], index=[S_NK], requiredColumns=[{2, 5}], inlineScan=[false], collation=[[5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +{ONEOF} + IgniteCorrelatedNestedLoopJoin(condition=[=($0, $5)], joinType=[inner], variablesSet=[[$cor17]], variablesSet=[[17]], correlationVariables=[[$cor17]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.855525, cpu=7.6582875, memory=23.18540625, io=1.17638125, network=23.18540625], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor16.S_SUPPKEY, $2)], collation=[[2 ASC-nulls-first]], searchBounds=[[null, null, ExactBounds [bound=$cor16.S_SUPPKEY], null, null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=21.0, io=1.0, network=21.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=21.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[L_SK_PK], requiredColumns=[{2, 3, 4, 7, 8}], inlineScan=[false], collation=[[4 ASC-nulls-first, 3 ASC-nulls-first, 2 ASC-nulls-first, 5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($1, $3)], joinType=[inner], variablesSet=[[$cor18]], variablesSet=[[18]], correlationVariables=[[$cor18]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.7035, cpu=11.055250000000001, memory=14.569375, io=1.175875, network=14.569375], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor17.L_ORDERKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor17.L_ORDERKEY], null, null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=6.0, memory=13.0, io=1.0, network=13.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=13.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, ORDERS]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[AND(>=($t2, 1995-01-01), <=($t2, 1996-12-31))], requiredColumns=[{2, 3, 6}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($1, $2)], joinType=[inner], variablesSet=[[$cor19]], variablesSet=[[19]], correlationVariables=[[$cor19]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.6899999999999995, cpu=7.035, memory=10.4625, io=1.1724999999999999, network=10.4625], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor18.O_CUSTKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor18.O_CUSTKEY], null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, CUSTOMER]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 5}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($1, $2)], joinType=[inner], variablesSet=[[$cor20]], variablesSet=[[20]], correlationVariables=[[$cor20]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.6, cpu=6.9, memory=9.75, io=1.15, network=9.75], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor19.C_NATIONKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor19.C_NATIONKEY], null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, NATION]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 4}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor20.N_REGIONKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor20.N_REGIONKEY]]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=6.0, memory=5.0, io=1.0, network=5.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, REGION]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[=($t1, _UTF-8'AMERICA')], rowType=[RecordType(INTEGER R_REGIONKEY)], projects=[[$t0]], requiredColumns=[{2, 3}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q8.sql b/modules/calcite/src/test/resources/tpch/q8.sql new file mode 100644 index 0000000000000..617d098c1ab1b --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q8.sql @@ -0,0 +1,40 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT + o_year, + sum(CASE + WHEN nation = 'BRAZIL' + THEN volume + ELSE 0 + END) / sum(volume) AS mkt_share +FROM ( + SELECT + extract(YEAR FROM o_orderdate) AS o_year, + l_extendedprice * (1 - l_discount) AS volume, + n2.n_name AS nation + FROM + part, + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2, + region + WHERE + p_partkey = l_partkey + AND s_suppkey = l_suppkey + AND l_orderkey = o_orderkey + AND o_custkey = c_custkey + AND c_nationkey = n1.n_nationkey + AND n1.n_regionkey = r_regionkey + AND r_name = 'AMERICA' + AND s_nationkey = n2.n_nationkey + AND o_orderdate BETWEEN DATE '1995-01-01' AND DATE '1996-12-31' + AND p_type = 'ECONOMY ANODIZED STEEL' + ) AS all_nations +GROUP BY + o_year +ORDER BY + o_year diff --git a/modules/calcite/src/test/resources/tpch/q9.plan b/modules/calcite/src/test/resources/tpch/q9.plan new file mode 100644 index 0000000000000..ba87001467449 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q9.plan @@ -0,0 +1,32 @@ +IgniteSort(sort0=[$0], sort1=[$1], dir0=[ASC-nulls-first], dir1=[DESC-nulls-last]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=19.01501875, cpu=36.0212625, memory=69.78493125, io=4.00388125, network=52.03493125], id = {id} + IgniteColocatedHashAggregate(group=[{0, 1}], SUM_PROFIT=[SUM($2)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=18.01501875, cpu=32.0212625, memory=57.78493125, io=4.00388125, network=52.03493125], id = {id} + IgniteProject(NATION=[$15], O_YEAR=[EXTRACT(FLAG(YEAR), $5)], AMOUNT=[-(*($10, -(1, $11)), *($3, $9))]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=17.01501875, cpu=31.0212625, memory=48.03493125, io=4.00388125, network=52.03493125], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($0, $7)], joinType=[inner], variablesSet=[[$cor12]], variablesSet=[[12]], correlationVariables=[[$cor12]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=16.01501875, cpu=30.0212625, memory=48.03493125, io=4.00388125, network=52.03493125], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteTableScan(table=[[PUBLIC, PART]], filters=[LIKE($t1, _UTF-8'%green%')], rowType=[RecordType(INTEGER P_PARTKEY)], projects=[[$t0]], requiredColumns=[{2, 3}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteFilter(condition=[=($cor12.P_PARTKEY, $6)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=13.01501875, cpu=24.0212625, memory=47.03493125, io=3.00388125, network=47.03493125], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[AND(=($1, $7), =($0, $6))], joinType=[inner], variablesSet=[[$cor6]], variablesSet=[[6]], correlationVariables=[[$cor6]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=12.01501875, cpu=20.0212625, memory=47.03493125, io=3.00388125, network=47.03493125], id = {id} + IgniteTableSpool(readType=[LAZY], writeType=[EAGER]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=3.0, memory=13.0, io=1.0, network=13.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=13.0], id = {id} +{ONEOF} + IgniteIndexScan(table=[[PUBLIC, PARTSUPP]], index=[PS_SK_PK], requiredColumns=[{2, 3, 5}], inlineScan=[false], collation=[[3 ASC-nulls-first, 2 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +===== + IgniteIndexScan(table=[[PUBLIC, PARTSUPP]], index=[PS_PK], requiredColumns=[{2, 3, 5}], inlineScan=[false], collation=[[2 ASC-nulls-first, 3 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +===== + IgniteIndexScan(table=[[PUBLIC, PARTSUPP]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 3, 5}], inlineScan=[false], collation=[[2 ASC-nulls-first, 3 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +{ONEOF} + IgniteCorrelatedNestedLoopJoin(condition=[=($0, $2)], joinType=[inner], variablesSet=[[$cor9]], variablesSet=[[9]], correlationVariables=[[$cor9]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=8.01501875, cpu=13.021262499999999, memory=34.03493125, io=2.00388125, network=34.03493125], id = {id} + IgniteTableSpool(readType=[LAZY], writeType=[EAGER]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=3.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, ORDERS]], index=[O_OD_proxy], requiredColumns=[{2, 6}], inlineScan=[true], collation=[[6 ASC-nulls-first, 2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($6, $2)], joinType=[inner], variablesSet=[[$cor10]], variablesSet=[[10]], correlationVariables=[[$cor10]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.01501875, cpu=6.0212625, memory=25.03493125, io=1.00388125, network=25.03493125], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[AND(=($cor6.PS_SUPPKEY, $2), =($cor6.PS_PARTKEY, $1), =($cor9.O_ORDERKEY, $0))], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor9.O_ORDERKEY], null, null, null, null, null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=25.0, io=1.0, network=25.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=25.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 3, 4, 6, 7, 8}], inlineScan=[false], collation=[[2 ASC-nulls-first, 5 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($1, $2)], joinType=[inner], variablesSet=[[$cor11]], variablesSet=[[11]], correlationVariables=[[$cor11]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.45, cpu=6.3, memory=10.35, io=1.15, network=10.35], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($0, $cor10.L_SUPPKEY)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor10.L_SUPPKEY], null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, SUPPLIER]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 5}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor11.S_NATIONKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor11.S_NATIONKEY], null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, NATION]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 3}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/q9.sql b/modules/calcite/src/test/resources/tpch/q9.sql new file mode 100644 index 0000000000000..0fdc07f1bf437 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/q9.sql @@ -0,0 +1,34 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +SELECT + nation, + o_year, + sum(amount) AS sum_profit +FROM ( + SELECT + n_name AS nation, + extract(YEAR FROM o_orderdate) AS o_year, + l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity AS amount + FROM + part, + supplier, + lineitem, + partsupp, + orders, + nation + WHERE + s_suppkey = l_suppkey + AND ps_suppkey = l_suppkey + AND ps_partkey = l_partkey + AND p_partkey = l_partkey + AND o_orderkey = l_orderkey + AND s_nationkey = n_nationkey + AND p_name LIKE '%green%' + ) AS profit +GROUP BY + nation, + o_year +ORDER BY + nation, + o_year DESC diff --git a/modules/calcite/src/test/resources/tpch/variant_q12.plan b/modules/calcite/src/test/resources/tpch/variant_q12.plan new file mode 100644 index 0000000000000..8f5835e1086c8 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/variant_q12.plan @@ -0,0 +1,9 @@ +IgniteReduceSortAggregate(rowType=[RecordType(VARCHAR L_SHIPMODE, BIGINT HIGH_LINE_COUNT, BIGINT LOW_LINE_COUNT)], group=[{0}], HIGH_LINE_COUNT=[SUM($1)], LOW_LINE_COUNT=[SUM($2)], collation=[[0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=9.0, cpu=15.0, memory=24.0, io=2.0, network=18.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=8.0, cpu=14.0, memory=24.0, io=2.0, network=18.0], id = {id} + IgniteMapSortAggregate(group=[{0}], HIGH_LINE_COUNT=[SUM($1)], LOW_LINE_COUNT=[SUM($2)], collation=[[0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=7.0, cpu=13.0, memory=24.0, io=2.0, network=10.0], id = {id} + IgniteProject(L_SHIPMODE=[$1], $f1=[CASE(SEARCH($3, Sarg[_UTF-8'1-URGENT':VARCHAR(8) CHARACTER SET "UTF-8", _UTF-8'2-HIGH':VARCHAR(8) CHARACTER SET "UTF-8"]:VARCHAR(8) CHARACTER SET "UTF-8"), 1, 0)], $f2=[CASE(SEARCH($3, Sarg[_UTF-8'1-URGENT':VARCHAR(8) CHARACTER SET "UTF-8", _UTF-8'2-HIGH':VARCHAR(8) CHARACTER SET "UTF-8"]:VARCHAR(8) CHARACTER SET "UTF-8"), 0, 1)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=6.0, cpu=12.0, memory=10.0, io=2.0, network=10.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($2, $0)], joinType=[inner], variablesSet=[[$cor0]], variablesSet=[[0]], correlationVariables=[[$cor0]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.0, cpu=11.0, memory=10.0, io=2.0, network=10.0], id = {id} + IgniteExchange(distribution=[affinity[identity=AffinityIdentity [affFuncCls=class org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction, backups=0, partsCnt=1024, filterCls=class org.apache.ignite.configuration.CacheConfiguration$IgniteAllNodesPredicate, hash={hash}, cacheId=-1464737622][0]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteSort(sort0=[$1], dir0=[ASC-nulls-first]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=9.0, io=1.0, network=1.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[L_RD], filters=[AND(OR(=($t4, _UTF-8'MAIL'), =($t4, _UTF-8'SHIP')), <($t2, $t3), <($t1, $t2), AND(>=($t3, 1994-01-01), <($t3, 1995-01-01)))], rowType=[RecordType(INTEGER L_ORDERKEY, VARCHAR L_SHIPMODE)], projects=[[$t0, $t4]], requiredColumns=[{2, 12, 13, 14, 16}], searchBounds=[[null, null, null, null, null, null, null, null, null, null, null, null, null, null, RangeBounds [lowerBound=1994-01-01, upperBound=1995-01-01, lowerInclude=true, upperInclude=false], null, null, null]], inlineScan=[false], collation=[[14 ASC-nulls-first, 2 ASC-nulls-first, 5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, ORDERS]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[=($t0, $cor0.L_ORDERKEY)], requiredColumns=[{2, 7}], searchBounds=[[null, null, ExactBounds [bound=$cor0.L_ORDERKEY], null, null, null, null, null, null, null, null]], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/variant_q12.sql b/modules/calcite/src/test/resources/tpch/variant_q12.sql new file mode 100644 index 0000000000000..02bd28364b5be --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/variant_q12.sql @@ -0,0 +1,25 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +-- This variant replaces the CASE statement from the Functional Query Definition with equivalent DECODE() syntax + +SELECT + l_shipmode, + sum(decode(o_orderpriority, '1-URGENT', 1, '2-HIGH', 1, 0)) as + high_line_count, + sum(decode(o_orderpriority, '1-URGENT', 0, '2-HIGH', 0, 1)) as + low_line_count +FROM + orders, + lineitem +WHERE + o_orderkey = l_orderkey + AND l_shipmode IN ('MAIL', 'SHIP') + AND l_commitdate < l_receiptdate + AND l_shipdate < l_commitdate + AND l_receiptdate >= DATE '1994-01-01' + AND l_receiptdate < DATE '1994-01-01' + INTERVAL '1' YEAR +GROUP BY + l_shipmode +ORDER BY + l_shipmode diff --git a/modules/calcite/src/test/resources/tpch/variant_q14.plan b/modules/calcite/src/test/resources/tpch/variant_q14.plan new file mode 100644 index 0000000000000..68e4728c8a870 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/variant_q14.plan @@ -0,0 +1,8 @@ +IgniteProject(PROMO_REVENUE=[/(*(100.00:DECIMAL(5, 2), $0), $1)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=10.0, cpu=19.0, memory=12.0, io=2.0, network=22.0], id = {id} + IgniteColocatedHashAggregate(group=[{}], agg#0=[SUM($0)], agg#1=[SUM($1)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=9.0, cpu=18.0, memory=12.0, io=2.0, network=22.0], id = {id} + IgniteProject($f0=[CASE(=(SUBSTRING($1, 1, 5), _UTF-8'PROMO'), *($3, -(1, $4)), 0.0000:DECIMAL(31, 4))], $f1=[*($3, -(1, $4))]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=8.0, cpu=17.0, memory=2.0, io=2.0, network=22.0], id = {id} + IgniteMergeJoin(condition=[=($2, $0)], joinType=[inner], variablesSet=[[]], leftCollation=[[0 ASC-nulls-first]], rightCollation=[[0 ASC-nulls-first]], allowNulls=[{}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=7.0, cpu=16.0, memory=2.0, io=2.0, network=22.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, PART]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 6}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=13.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[L_PK_SK], filters=[AND(>=($t3, 1995-09-01), <($t3, 1995-10-01))], rowType=[RecordType(INTEGER L_PARTKEY, DECIMAL(15, 2) L_EXTENDEDPRICE, DECIMAL(15, 2) L_DISCOUNT)], projects=[[$t0, $t1, $t2]], requiredColumns=[{3, 7, 8, 12}], inlineScan=[false], collation=[[3 ASC-nulls-first, 4 ASC-nulls-first, 2 ASC-nulls-first, 5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/variant_q14.sql b/modules/calcite/src/test/resources/tpch/variant_q14.sql new file mode 100644 index 0000000000000..4738c3b13b9d3 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/variant_q14.sql @@ -0,0 +1,16 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +-- -- This variant replaces the CASE statement from the Functional Query Definition with equivalent DECODE() syntax + +SELECT + 100.00 * sum(decode(substring(p_type from 1 for 5), 'PROMO', + l_extendedprice * (1-l_discount), 0)) / + sum(l_extendedprice * (1-l_discount)) as promo_revenue +FROM + lineitem, + part +WHERE + l_partkey = p_partkey + AND l_shipdate >= DATE '1995-09-01' + AND l_shipdate < DATE '1995-09-01' + INTERVAL '1' MONTH diff --git a/modules/calcite/src/test/resources/tpch/variant_q8.plan b/modules/calcite/src/test/resources/tpch/variant_q8.plan new file mode 100644 index 0000000000000..36dc762e828a6 --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/variant_q8.plan @@ -0,0 +1,39 @@ +IgniteSort(sort0=[$0], dir0=[ASC-nulls-first]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=16.72832875, cpu=31.148743125, memory=44.477810937499996, io=3.1764571875, network=26.4778109375], id = {id} + IgniteProject(O_YEAR=[$0], MKT_SHARE=[/($1, $2)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=15.72832875, cpu=27.148743125, memory=36.477810937499996, io=3.1764571875, network=26.4778109375], id = {id} + IgniteColocatedHashAggregate(group=[{0}], agg#0=[SUM($1)], agg#1=[SUM($2)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=14.72832875, cpu=26.148743125, memory=36.477810937499996, io=3.1764571875, network=26.4778109375], id = {id} + IgniteProject(O_YEAR=[EXTRACT(FLAG(YEAR), $12)], $f1=[CASE(=($2, _UTF-8'BRAZIL'), *($8, -(1, $9)), 0.0000:DECIMAL(31, 4))], VOLUME=[*($8, -(1, $9))]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=13.72832875, cpu=25.148743125, memory=22.4778109375, io=3.1764571875, network=26.4778109375], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($0, $6)], joinType=[inner], variablesSet=[[$cor21]], variablesSet=[[21]], correlationVariables=[[$cor21]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=12.72832875, cpu=24.148743125, memory=22.4778109375, io=3.1764571875, network=26.4778109375], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteTableScan(table=[[PUBLIC, PART]], filters=[=($t1, _UTF-8'ECONOMY ANODIZED STEEL')], rowType=[RecordType(INTEGER P_PARTKEY)], projects=[[$t0]], requiredColumns=[{2, 6}]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteFilter(condition=[=($cor21.P_PARTKEY, $5)]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=9.72832875, cpu=18.148743125, memory=21.4778109375, io=2.1764571875, network=21.4778109375], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($3, $0)], joinType=[inner], variablesSet=[[$cor15]], variablesSet=[[15]], correlationVariables=[[$cor15]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=8.72832875, cpu=14.148743125, memory=21.4778109375, io=2.1764571875, network=21.4778109375], id = {id} + IgniteTableSpool(readType=[LAZY], writeType=[EAGER]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=3.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, NATION]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 3}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($0, $4)], joinType=[inner], variablesSet=[[$cor16]], variablesSet=[[16]], correlationVariables=[[$cor16]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.72832875, cpu=7.148743125, memory=12.4778109375, io=1.1764571875, network=12.4778109375], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($1, $cor15.N_NATIONKEY)], collation=[[1 ASC-nulls-first]], searchBounds=[[null, ExactBounds [bound=$cor15.N_NATIONKEY]]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} +{ONEOF} + IgniteIndexScan(table=[[PUBLIC, SUPPLIER]], index=[S_NK_proxy], requiredColumns=[{2, 5}], inlineScan=[true], collation=[[5 ASC-nulls-first, 2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +===== + IgniteIndexScan(table=[[PUBLIC, SUPPLIER]], index=[S_NK], requiredColumns=[{2, 5}], inlineScan=[false], collation=[[5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} +{ONEOF} + IgniteCorrelatedNestedLoopJoin(condition=[=($0, $5)], joinType=[inner], variablesSet=[[$cor17]], variablesSet=[[17]], correlationVariables=[[$cor17]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.855525, cpu=7.6582875, memory=23.18540625, io=1.17638125, network=23.18540625], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor16.S_SUPPKEY, $2)], collation=[[2 ASC-nulls-first]], searchBounds=[[null, null, ExactBounds [bound=$cor16.S_SUPPKEY], null, null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=21.0, io=1.0, network=21.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=21.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, LINEITEM]], index=[L_SK_PK], requiredColumns=[{2, 3, 4, 7, 8}], inlineScan=[false], collation=[[4 ASC-nulls-first, 3 ASC-nulls-first, 2 ASC-nulls-first, 5 ASC-nulls-first, 0 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($1, $3)], joinType=[inner], variablesSet=[[$cor18]], variablesSet=[[18]], correlationVariables=[[$cor18]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=5.7035, cpu=11.055250000000001, memory=14.569375, io=1.175875, network=14.569375], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor17.L_ORDERKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor17.L_ORDERKEY], null, null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=6.0, memory=13.0, io=1.0, network=13.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=13.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, ORDERS]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[AND(>=($t2, 1995-01-01), <=($t2, 1996-12-31))], requiredColumns=[{2, 3, 6}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($1, $2)], joinType=[inner], variablesSet=[[$cor19]], variablesSet=[[19]], correlationVariables=[[$cor19]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.6899999999999995, cpu=7.035, memory=10.4625, io=1.1724999999999999, network=10.4625], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor18.O_CUSTKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor18.O_CUSTKEY], null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, CUSTOMER]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 5}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteCorrelatedNestedLoopJoin(condition=[=($1, $2)], joinType=[inner], variablesSet=[[$cor20]], variablesSet=[[20]], correlationVariables=[[$cor20]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.6, cpu=6.9, memory=9.75, io=1.15, network=9.75], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor19.C_NATIONKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor19.C_NATIONKEY], null]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=2.0, memory=9.0, io=1.0, network=9.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=2.0, memory=1.0, io=1.0, network=9.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, NATION]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], requiredColumns=[{2, 4}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=1.0, cpu=1.0, memory=1.0, io=1.0, network=1.0], id = {id} + IgniteSortedIndexSpool(readType=[LAZY], writeType=[EAGER], condition=[=($cor20.N_REGIONKEY, $0)], collation=[[0 ASC-nulls-first]], searchBounds=[[ExactBounds [bound=$cor20.N_REGIONKEY]]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=4.0, cpu=6.0, memory=5.0, io=1.0, network=5.0], id = {id} + IgniteExchange(distribution=[single]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=3.0, cpu=6.0, memory=1.0, io=1.0, network=5.0], id = {id} + IgniteIndexScan(table=[[PUBLIC, REGION]], index=[{INDEX_CASE:_key_PK,_key_PK_proxy}], filters=[=($t1, _UTF-8'AMERICA')], rowType=[RecordType(INTEGER R_REGIONKEY)], projects=[[$t0]], requiredColumns=[{2, 3}], inlineScan=[false], collation=[[2 ASC-nulls-first]]): rowcount = 1.0, cumulative cost = IgniteCost [rowCount=2.0, cpu=5.0, memory=1.0, io=1.0, network=1.0], id = {id} diff --git a/modules/calcite/src/test/resources/tpch/variant_q8.sql b/modules/calcite/src/test/resources/tpch/variant_q8.sql new file mode 100644 index 0000000000000..a93f0b73d095a --- /dev/null +++ b/modules/calcite/src/test/resources/tpch/variant_q8.sql @@ -0,0 +1,38 @@ +-- noinspection SqlDialectInspectionForFile +-- noinspection SqlNoDataSourceInspectionForFile + +-- This variant replaces the CASE statement from the Functional Query Definition with equivalent DECODE() syntax + +SELECT + o_year, + sum(decode(nation, 'BRAZIL', volume, 0)) / sum(volume) as mkt_share +FROM ( + SELECT + extract(YEAR FROM o_orderdate) AS o_year, + l_extendedprice * (1 - l_discount) AS volume, + n2.n_name AS nation + FROM + part, + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2, + region + WHERE + p_partkey = l_partkey + AND s_suppkey = l_suppkey + AND l_orderkey = o_orderkey + AND o_custkey = c_custkey + AND c_nationkey = n1.n_nationkey + AND n1.n_regionkey = r_regionkey + AND r_name = 'AMERICA' + AND s_nationkey = n2.n_nationkey + AND o_orderdate BETWEEN DATE '1995-01-01' AND DATE '1996-12-31' + AND p_type = 'ECONOMY ANODIZED STEEL' + ) AS all_nations +GROUP BY + o_year +ORDER BY + o_year