Skip to content

Commit cea95af

Browse files
committed
Add plan hash from contination to EXPLAIN result
1 parent 34c243c commit cea95af

File tree

2 files changed

+14
-7
lines changed
  • fdb-relational-core/src

2 files changed

+14
-7
lines changed

fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/query/QueryPlan.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ private RelationalResultSet executeExplain(@Nonnull ContinuationImpl parsedConti
310310
DataType.StructType.Field.from("EXECUTION_STATE", DataType.Primitives.BYTES.type(), 0),
311311
DataType.StructType.Field.from("VERSION", DataType.Primitives.INTEGER.type(), 1),
312312
DataType.StructType.Field.from("PLAN_HASH_MODE", DataType.Primitives.STRING.type(), 2),
313-
DataType.StructType.Field.from("SERIALIZED_PLAN_COMPLEXITY", DataType.Primitives.INTEGER.type(), 3)),
313+
DataType.StructType.Field.from("PLAN_HASH", DataType.Primitives.INTEGER.type(), 3),
314+
DataType.StructType.Field.from("SERIALIZED_PLAN_COMPLEXITY", DataType.Primitives.INTEGER.type(), 4)),
314315
true);
315316
final var plannerMetricsStructType = DataType.StructType.from(
316317
"PLANNER_METRICS", List.of(
@@ -338,6 +339,7 @@ private RelationalResultSet executeExplain(@Nonnull ContinuationImpl parsedConti
338339
parsedContinuation.getExecutionState(),
339340
parsedContinuation.getVersion(),
340341
parsedContinuation.getCompiledStatement() == null ? null : parsedContinuation.getCompiledStatement().getPlanSerializationMode(),
342+
parsedContinuation.getPlanHash(),
341343
getPlanFromContinuation(parsedContinuation, executionContext).map(RecordQueryPlan::getComplexity).orElse(null)
342344
), RelationalStructMetaData.of(continuationStructType));
343345

@@ -432,7 +434,7 @@ private Continuation enrichContinuation(@Nonnull final Continuation continuation
432434
// 3. query constraints
433435
//
434436

435-
final var serializationContext = new PlanSerializationContext(new DefaultPlanSerializationRegistry(), currentPlanHashMode);
437+
final var serializationContext = new PlanSerializationContext(DefaultPlanSerializationRegistry.INSTANCE, currentPlanHashMode);
436438

437439
final var literals = queryExecutionContext.getLiterals();
438440
final var compiledStatementBuilder = CompiledStatement.newBuilder()

fdb-relational-core/src/test/java/com/apple/foundationdb/relational/recordlayer/query/ExplainTests.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ void explainResultSetMetadataTest() throws Exception {
7373
"EXECUTION_STATE",
7474
"VERSION",
7575
"PLAN_HASH_MODE",
76+
"PLAN_HASH",
7677
"SERIALIZED_PLAN_COMPLEXITY"
7778
);
78-
final var expectedContTypes = List.of(Types.BINARY, Types.INTEGER, Types.VARCHAR, Types.INTEGER);
79+
final var expectedContTypes = List.of(Types.BINARY, Types.INTEGER, Types.VARCHAR, Types.INTEGER, Types.INTEGER);
7980
try (var ddl = Ddl.builder().database(URI.create("/TEST/QT")).relationalExtension(relationalExtension).schemaTemplate(schemaTemplate).build()) {
8081
executeInsert(ddl);
8182
try (RelationalPreparedStatement ps = ddl.setSchemaAndGetConnection().prepareStatement("EXPLAIN SELECT * FROM RestaurantComplexRecord")) {
@@ -108,7 +109,7 @@ void explainWithNoContinuationTest() throws Exception {
108109
final var assertResult = ResultSetAssert.assertThat(resultSet);
109110
assertResult.hasNextRow()
110111
.hasColumn("PLAN", "ISCAN(RECORD_NAME_IDX <,>)")
111-
.hasColumn("PLAN_HASH", -1635569052L)
112+
.hasColumn("PLAN_HASH", -1635569052)
112113
.hasColumn("PLAN_CONTINUATION", null);
113114
assertResult.hasNoNextRow();
114115
}
@@ -132,15 +133,17 @@ void explainWithContinuationNoSerializedPlanTest() throws Exception {
132133
ps.setObject("cont", continuation.serialize());
133134
try (final RelationalResultSet resultSet = ps.executeQuery()) {
134135
final var assertResult = ResultSetAssert.assertThat(resultSet);
136+
135137
assertResult.hasNextRow()
136138
.hasColumn("PLAN", "ISCAN(RECORD_NAME_IDX <,>)")
137-
.hasColumn("PLAN_HASH", -1635569052L);
139+
.hasColumn("PLAN_HASH", -1635569052);
138140
final var continuationInfo = resultSet.getStruct(5);
139141
org.junit.jupiter.api.Assertions.assertNotNull(continuationInfo);
140142
final var assertStruct = RelationalStructAssert.assertThat(continuationInfo);
141143
assertStruct.hasValue("EXECUTION_STATE", new byte[]{0, 21, 1, 21, 11});
142144
assertStruct.hasValue("VERSION", 1);
143145
assertStruct.hasValue("PLAN_HASH_MODE", null);
146+
assertStruct.hasValue("PLAN_HASH", -1635569052);
144147
assertStruct.hasValue("SERIALIZED_PLAN_COMPLEXITY", null);
145148
}
146149
}
@@ -166,13 +169,14 @@ void explainWithContinuationSerializedPlanTest() throws Exception {
166169
final var assertResult = ResultSetAssert.assertThat(resultSet);
167170
assertResult.hasNextRow()
168171
.hasColumn("PLAN", "ISCAN(RECORD_NAME_IDX <,>)")
169-
.hasColumn("PLAN_HASH", -1635569052L);
172+
.hasColumn("PLAN_HASH", -1635569052);
170173
final var continuationInfo = resultSet.getStruct(5);
171174
org.junit.jupiter.api.Assertions.assertNotNull(continuationInfo);
172175
final var assertStruct = RelationalStructAssert.assertThat(continuationInfo);
173176
assertStruct.hasValue("EXECUTION_STATE", new byte[]{0, 21, 1, 21, 11});
174177
assertStruct.hasValue("VERSION", 1);
175178
assertStruct.hasValue("PLAN_HASH_MODE", "VC0");
179+
assertStruct.hasValue("PLAN_HASH", -1635569052);
176180
assertStruct.hasValue("SERIALIZED_PLAN_COMPLEXITY", 1);
177181
}
178182
}
@@ -198,13 +202,14 @@ void explainExecuteStatementTest() throws Exception {
198202
final var assertResult = ResultSetAssert.assertThat(resultSet);
199203
assertResult.hasNextRow()
200204
.hasColumn("PLAN", "ISCAN(RECORD_NAME_IDX <,>)")
201-
.hasColumn("PLAN_HASH", -1635569052L);
205+
.hasColumn("PLAN_HASH", -1635569052);
202206
final var continuationInfo = resultSet.getStruct(5);
203207
org.junit.jupiter.api.Assertions.assertNotNull(continuationInfo);
204208
final var assertStruct = RelationalStructAssert.assertThat(continuationInfo);
205209
assertStruct.hasValue("EXECUTION_STATE", new byte[]{0, 21, 1, 21, 11});
206210
assertStruct.hasValue("VERSION", 1);
207211
assertStruct.hasValue("PLAN_HASH_MODE", "VC0");
212+
assertStruct.hasValue("PLAN_HASH", -1635569052);
208213
assertStruct.hasValue("SERIALIZED_PLAN_COMPLEXITY", 1);
209214
}
210215
}

0 commit comments

Comments
 (0)