oleg-vlsk commented on code in PR #11425: URL: https://github.com/apache/ignite/pull/11425#discussion_r1833672245
########## modules/core/src/main/java/org/apache/ignite/internal/processors/query/running/SqlPlanHistoryTracker.java: ########## @@ -0,0 +1,74 @@ +/* + * 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.running; + +import java.util.Collections; +import java.util.Map; +import org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashMap; +import org.apache.ignite.internal.util.typedef.internal.U; + +/** Class that manages recording and storing SQL plans. */ +public class SqlPlanHistoryTracker { + /** SQL plan history. */ + private GridBoundedConcurrentLinkedHashMap<SqlPlan, Long> sqlPlanHistory; + + /** SQL plan history size. */ + private int historySize; + + /** + * @param historySize SQL plan history size. + */ + public SqlPlanHistoryTracker(int historySize) { + this.historySize = historySize; + + sqlPlanHistory = (historySize > 0) ? new GridBoundedConcurrentLinkedHashMap<>(historySize) : null; + } + + /** + * @param plan SQL plan. + * @param qry Query. + * @param schema Schema name. + * @param loc Local query flag. + * @param engine SQL engine. + */ + public void addPlan(String plan, String qry, String schema, boolean loc, String engine) { + if (historySize <= 0) Review Comment: Done. ########## modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/SqlPlanHistoryIntegrationTest.java: ########## @@ -0,0 +1,718 @@ +/* + * 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.integration; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.stream.Collectors; +import org.apache.ignite.IgniteCache; +import org.apache.ignite.cache.query.Query; +import org.apache.ignite.cache.query.ScanQuery; +import org.apache.ignite.cache.query.SqlFieldsQuery; +import org.apache.ignite.cache.query.SqlQuery; +import org.apache.ignite.cache.query.TextQuery; +import org.apache.ignite.cache.query.annotations.QuerySqlField; +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.configuration.SqlConfiguration; +import org.apache.ignite.indexing.IndexingQueryEngineConfiguration; +import org.apache.ignite.internal.IgniteEx; +import org.apache.ignite.internal.IgniteInterruptedCheckedException; +import org.apache.ignite.internal.processors.query.IgniteSQLException; +import org.apache.ignite.internal.processors.query.QueryEngineConfigurationEx; +import org.apache.ignite.internal.processors.query.running.SqlPlan; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteBiTuple; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.junit.AssumptionViolatedException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import static org.junit.Assume.assumeFalse; + +/** Tests for SQL plan history. */ +@RunWith(Parameterized.class) +public class SqlPlanHistoryIntegrationTest extends GridCommonAbstractTest { + /** SQL plan history size. */ + private static final int PLAN_HISTORY_SIZE = 10; + + /** SQL plan history size excess. */ + private static final int PLAN_HISTORY_EXCESS = 2; + + /** Simple SQL query. */ + private static final String SQL = "SELECT * FROM A.String"; + + /** Failed SQL query. */ + private static final String SQL_FAILED = "select * from A.String where A.fail()=1"; + + /** Cross-cache SQL query. */ + private static final String SQL_CROSS_CACHE = "SELECT * FROM B.String"; + + /** Failed cross-cache SQL query. */ + private static final String SQL_CROSS_CACHE_FAILED = "select * from B.String where B.fail()=1"; + + /** SQL query with reduce phase. */ + private static final String SQL_WITH_REDUCE_PHASE = "select o.name n1, p.name n2 from \"pers\".Person p, " + + "\"org\".Organization o where p.orgId=o._key and o._key=101" + + " union select o.name n1, p.name n2 from \"pers\".Person p, \"org\".Organization o" + + " where p.orgId=o._key and o._key=102"; + + /** List of simple DML commands and the simple queries flag. */ + private final IgniteBiTuple<List<String>, Boolean> dmlCmds = new IgniteBiTuple<>( + Arrays.asList( + "insert into A.String (_key, _val) values(101, '101')", + "update A.String set _val='111' where _key=101", + "delete from A.String where _key=101" + ), true + ); + + /** List of DML commands with joins and the simple queries flag. */ + private final IgniteBiTuple<List<String>, Boolean> dmlCmdsWithJoins = new IgniteBiTuple<>( + Arrays.asList( + "insert into A.String (_key, _val) select o._key, p.name " + + "from \"pers\".Person p, \"org\".Organization o where p.orgId=o._key", + "update A.String set _val = 'updated' where _key in " + + "(select o._key from \"pers\".Person p, \"org\".Organization o where p.orgId=o._key)", + "delete from A.String where _key in (select orgId from \"pers\".Person)" + ), false + ); + + /** Successful SqlFieldsQuery. */ + private final SqlFieldsQuery sqlFieldsQry = new SqlFieldsQuery(SQL); + + /** Failed SqlFieldsQuery. */ + private final SqlFieldsQuery sqlFieldsQryFailed = new SqlFieldsQuery(SQL_FAILED); + + /** Successful cross-cache SqlFieldsQuery. */ + private final SqlFieldsQuery sqlFieldsQryCrossCache = new SqlFieldsQuery(SQL_CROSS_CACHE); + + /** Failed cross-cache SqlFieldsQuery. */ + private final SqlFieldsQuery sqlFieldsQryCrossCacheFailed = new SqlFieldsQuery(SQL_CROSS_CACHE_FAILED); + + /** Successful SqlFieldsQuery with reduce phase. */ + private final SqlFieldsQuery sqlFieldsQryWithReducePhase = new SqlFieldsQuery(SQL_WITH_REDUCE_PHASE) + .setDistributedJoins(true); + + /** Failed SqlFieldsQuery with reduce phase. */ + private final SqlFieldsQuery sqlFieldsQryWithReducePhaseFailed = + new SqlFieldsQuery(SQL_WITH_REDUCE_PHASE.replace("o._key=101", "fail()")); + + /** Successful SqlQuery. */ + private final SqlQuery sqlQry = new SqlQuery<>("String", "from String"); + + /** Failed SqlQuery. */ + private final SqlQuery sqlQryFailed = new SqlQuery<>("String", "from String where fail()=1"); + + /** ScanQuery. */ + private final ScanQuery<Integer, String> scanQry = new ScanQuery<>(); + + /** TextQuery. */ + private final TextQuery<Integer, String> textQry = new TextQuery<>("String", "2"); + + /** Flag for queries with map-reduce phases. */ + private boolean isReducePhase; + + /** SQL engine. */ + @Parameterized.Parameter + public String sqlEngine; + + /** Client mode flag. */ + @Parameterized.Parameter(1) + public boolean isClient; + + /** Local query flag. */ + @Parameterized.Parameter(2) + public boolean loc; + + /** Fully-fetched query flag. */ + @Parameterized.Parameter(3) + public boolean isFullyFetched; + + /** */ + @Parameterized.Parameters(name = "sqlEngine={0}, isClient={1} loc={2}, isFullyFetched={3}") + public static Collection<Object[]> params() { + return Arrays.stream(new Object[][]{ + {CalciteQueryEngineConfiguration.ENGINE_NAME}, + {IndexingQueryEngineConfiguration.ENGINE_NAME} + }).flatMap(sqlEngine -> Arrays.stream(new Boolean[]{true, false}) + .flatMap(isClient -> Arrays.stream(new Boolean[]{true, false}) + .flatMap(loc -> Arrays.stream(new Boolean[]{true, false}) + .map(isFullyFetched -> new Object[]{sqlEngine[0], isClient, loc, isFullyFetched}))) + ).collect(Collectors.toList()); + } + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName); + + QueryEngineConfigurationEx engCfg = configureSqlEngine(); + + cfg.setSqlConfiguration(new SqlConfiguration() + .setSqlPlanHistorySize(PLAN_HISTORY_SIZE) + .setQueryEnginesConfiguration(engCfg) + ); + + return cfg.setCacheConfiguration( + configureCache("A", Integer.class, String.class), + configureCache("B", Integer.class, String.class), + configureCache("pers", Integer.class, Person.class), + configureCache("org", Integer.class, Organization.class) + ); + } + + /** */ + protected QueryEngineConfigurationEx configureSqlEngine() { + if (sqlEngine.equals(CalciteQueryEngineConfiguration.ENGINE_NAME)) + return new CalciteQueryEngineConfiguration(); + else + return new IndexingQueryEngineConfiguration(); + } + + /** + * @param name Name. + * @param idxTypes Index types. + * @return Cache configuration. + */ + @SuppressWarnings("unchecked") Review Comment: Done. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org