Skip to content

Commit c743f41

Browse files
oleg-vlskalex-plekhanov
authored andcommitted
IGNITE-24800 SQL: Fix SQL plan logging failure for EXPLAIN queries - Fixes #11946.
Signed-off-by: Aleksey Plekhanov <plehanov.alex@gmail.com>
1 parent e76e768 commit c743f41

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/SqlPlanHistoryIntegrationTest.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.junit.runners.Parameterized;
5959

6060
import static org.apache.ignite.configuration.SqlConfiguration.DFLT_SQL_PLAN_HISTORY_SIZE;
61+
import static org.apache.ignite.internal.processors.performancestatistics.AbstractPerformanceStatisticsTest.startCollectStatistics;
6162
import static org.apache.ignite.internal.processors.query.running.RunningQueryManager.SQL_PLAN_HIST_VIEW;
6263
import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
6364
import static org.junit.Assert.assertNotEquals;
@@ -133,19 +134,24 @@ public class SqlPlanHistoryIntegrationTest extends GridCommonAbstractTest {
133134
@Parameterized.Parameter(3)
134135
public boolean isFullyFetched;
135136

137+
/** Flag indicating whether the collection of performance statistics is enabled. */
138+
@Parameterized.Parameter(4)
139+
public boolean isPerfStatsEnabled;
140+
136141
/**
137142
* @return Test parameters.
138143
*/
139-
@Parameterized.Parameters(name = "sqlEngine={0}, isClient={1} loc={2}, isFullyFetched={3}")
144+
@Parameterized.Parameters(name = "sqlEngine={0}, isClient={1} loc={2}, isFullyFetched={3}, isPerfStatsEnabled={4}")
140145
public static Collection<Object[]> params() {
141146
return Arrays.stream(new Object[][]{
142147
{CalciteQueryEngineConfiguration.ENGINE_NAME},
143148
{IndexingQueryEngineConfiguration.ENGINE_NAME}
144149
}).flatMap(sqlEngine -> Arrays.stream(sqlEngine[0].equals(IndexingQueryEngineConfiguration.ENGINE_NAME) ?
145-
new Boolean[]{false} : new Boolean[]{true, false})
146-
.flatMap(isClient -> Arrays.stream(isClient ? new Boolean[]{false} : new Boolean[]{true, false})
147-
.flatMap(loc -> Arrays.stream(new Boolean[]{true, false})
148-
.map(isFullyFetched -> new Object[]{sqlEngine[0], isClient, loc, isFullyFetched})))
150+
new Boolean[]{false} : new Boolean[]{true, false})
151+
.flatMap(isClient -> Arrays.stream(isClient ? new Boolean[]{false} : new Boolean[]{true, false})
152+
.flatMap(loc -> Arrays.stream(new Boolean[]{true, false})
153+
.flatMap(isFullyFetched -> Arrays.stream(new Boolean[]{true, false})
154+
.map(isPerfStatsEnabled -> new Object[]{sqlEngine[0], isClient, loc, isFullyFetched, isPerfStatsEnabled}))))
149155
).collect(Collectors.toList());
150156
}
151157

@@ -214,6 +220,9 @@ protected void startTestGrid() throws Exception {
214220
if (isClient)
215221
startClientGrid(1);
216222

223+
if (isPerfStatsEnabled)
224+
startCollectStatistics();
225+
217226
IgniteCache<Integer, String> cacheA = queryNode().cache("A");
218227
IgniteCache<Integer, String> cacheB = queryNode().cache("B");
219228

@@ -331,6 +340,12 @@ public void testSqlQueryFailed() throws Exception {
331340
runFailedQuery(new SqlQuery<>("String", "from String where fail()=1"));
332341
}
333342

343+
/** Checks that EXPLAIN queries execute successfully and are not added to the SQL plan history. */
344+
@Test
345+
public void testExplainQuery() throws Exception {
346+
runQueryWithoutPlan(new SqlFieldsQuery("explain plan for " + SQL));
347+
}
348+
334349
/** Checks ScanQuery. */
335350
@Test
336351
public void testScanQuery() throws Exception {
@@ -370,6 +385,8 @@ public void testSqlFieldsDmlWithJoins() throws Exception {
370385
/** Checks that older plan entries are evicted when maximum history size is reached. */
371386
@Test
372387
public void testPlanHistoryEviction() throws Exception {
388+
assumeFalse(isPerfStatsEnabled);
389+
373390
startTestGrid();
374391

375392
IgniteCache<Integer, String> cache = queryNode().cache("A");
@@ -402,6 +419,8 @@ public void testPlanHistoryEviction() throws Exception {
402419
*/
403420
@Test
404421
public void testEntryReplacement() throws Exception {
422+
assumeFalse(isPerfStatsEnabled);
423+
405424
startTestGrid();
406425

407426
long firstTs;
@@ -494,6 +513,8 @@ public void testNoScanCountSuffix() throws Exception {
494513
assumeTrue("ScanCount suffix can only be present in H2 local query plans",
495514
sqlEngine == IndexingQueryEngineConfiguration.ENGINE_NAME && loc);
496515

516+
assumeFalse(isPerfStatsEnabled);
517+
497518
startTestGrid();
498519

499520
final int iterations = 5;
@@ -729,6 +750,8 @@ public void checkMetrics(List<SqlPlanHistoryView> sqlPlans) {
729750
* @param reset Reset event.
730751
*/
731752
public void checkReset(Runnable reset) throws Exception {
753+
assumeFalse(isPerfStatsEnabled);
754+
732755
startTestGrid();
733756

734757
IgniteCache<Integer, String> cache = queryNode().cache("A");
@@ -756,6 +779,8 @@ public void checkReset(Runnable reset) throws Exception {
756779
* @param startGridFirst Flag indicating whether to start the grid before the setup.
757780
*/
758781
public void checkEmptyHistory(Runnable setup, boolean startGridFirst) throws Exception {
782+
assumeFalse(isPerfStatsEnabled);
783+
759784
if (startGridFirst)
760785
startTestGrid();
761786

@@ -784,7 +809,7 @@ public void checkDefaultHistorySize(
784809
if (isSingleEngineCheck)
785810
assumeFalse(sqlEngine == CalciteQueryEngineConfiguration.ENGINE_NAME);
786811

787-
assumeFalse(isClient || loc || isFullyFetched);
812+
assumeFalse(isClient || loc || isFullyFetched || isPerfStatsEnabled);
788813

789814
startTestGrid();
790815

modules/core/src/main/java/org/apache/ignite/internal/processors/query/running/SqlPlanHistoryTracker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public SqlPlanHistoryTracker(int histSize) {
4545
* @param engine SQL engine.
4646
*/
4747
public void addPlan(String plan, String qry, String schema, boolean loc, String engine) {
48-
if (sqlPlanHistory == EMPTY_MAP)
48+
if (sqlPlanHistory == EMPTY_MAP || plan.isEmpty())
4949
return;
5050

5151
SqlPlan sqlPlan = new SqlPlan(plan, qry, schema, loc, engine);

modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/H2QueryInfo.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,11 @@ public long queryId() {
121121

122122
/** */
123123
public synchronized String plan() {
124-
if (plan == null)
125-
plan = planWithoutScanCount(stmt.getPlanSQL());
124+
if (plan == null) {
125+
String plan0 = stmt.getPlanSQL();
126+
127+
plan = (plan0 != null) ? planWithoutScanCount(plan0) : "";
128+
}
126129

127130
return plan;
128131
}

0 commit comments

Comments
 (0)