Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make explain return planner metrics as separate column #3064

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

normen662
Copy link
Contributor

 RelationalStructMetaData(
  FieldDescription.primitive("TASK_COUNT", Types.BIGINT, DatabaseMetaData.columnNoNulls),
  FieldDescription.primitive("TASK_TOTAL_TIME_NS", Types.BIGINT, DatabaseMetaData.columnNoNulls),
  FieldDescription.primitive("TRANSFORM_COUNT", Types.BIGINT, DatabaseMetaData.columnNoNulls),
  FieldDescription.primitive("TRANSFORM_TIME_NS", Types.BIGINT, DatabaseMetaData.columnNoNulls),
  FieldDescription.primitive("TRANSFORM_YIELD_COUNT", Types.BIGINT, DatabaseMetaData.columnNoNulls),
  FieldDescription.primitive("INSERT_TIME_NS", Types.BIGINT, DatabaseMetaData.columnNoNulls),
  FieldDescription.primitive("INSERT_NEW_COUNT", Types.BIGINT, DatabaseMetaData.columnNoNulls),
  FieldDescription.primitive("INSERT_REUSED_COUNT", Types.BIGINT, DatabaseMetaData.columnNoNulls), ...)

Most of the PR is just making sure that the Debugger stats structures become accessible to the code that prepares and packages the result that is sent to the client. For that purpose I extracted Stats from the respective Debugger implementations and make it is own first-class citizen. Similar goes for StatsMaps. One thing I wanted to make sure is that once the StatsMaps are accessed outside of the installed Debugger, the StatsMaps become immutable. For that purpose we make a copy, as usual, however, we only want to make that copy when the client of the planner (i.e. QueryPlan) needs the stats (when responding to an EXPLAIN).

@foundationdb-ci
Copy link
Contributor

Result of fdb-record-layer-pr on Linux CentOS 7

  • Commit ID: 41fa34a
  • Duration 0:56:18
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@normen662 normen662 requested a review from alecgrieser January 27, 2025 11:35
@@ -318,6 +318,9 @@ public QueryPlanResult planQuery(@Nonnull final RecordQuery query, @Nonnull Para
.put(QueryPlanInfoKeys.TOTAL_TASK_COUNT, taskCount)
.put(QueryPlanInfoKeys.MAX_TASK_QUEUE_SIZE, maxQueueSize)
.put(QueryPlanInfoKeys.CONSTRAINTS, constraints)
.put(QueryPlanInfoKeys.STATS_MAPS,
Debugger.getDebuggerMaybe().flatMap(Debugger::getStatsMaps)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it that the query plan result won't be returned if the STATS_MAP is empty if the debugger isn't present? Maybe that's fine, as this information is a little internal. It does potentially limit the ability to get these stats through the relational server, but maybe we don't care about that (at least for the moment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right.

@@ -273,12 +282,23 @@ private RelationalResultSet executeExplain(@Nonnull ContinuationImpl parsedConti
FieldDescription.primitive("VERSION", Types.INTEGER, DatabaseMetaData.columnNoNulls),
FieldDescription.primitive("PLAN_HASH_MODE", Types.VARCHAR, DatabaseMetaData.columnNoNulls)
);
StructMetaData plannerMetricsMetadata = new RelationalStructMetaData(
FieldDescription.primitive("TASK_COUNT", Types.BIGINT, DatabaseMetaData.columnNoNulls),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know if we have coverage of what happens if there isn't a debugger set (e.g., making sure that we don't return a null column here)? This looks right to me, but I just wanted to see if it's covered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are plenty of tests where we don't have a Debugger installed (all that's not EXPLAIN) and this is null

final var expectedLabels = List.of("PLAN", "PLAN_HASH", "PLAN_DOT", "PLAN_GML", "PLAN_CONTINUATION");
final var expectedTypes = List.of(Types.VARCHAR, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.STRUCT);
final var expectedLabels = List.of("PLAN", "PLAN_HASH", "PLAN_DOT", "PLAN_GML", "PLAN_CONTINUATION", "PLANNER_METRICS");
final var expectedTypes = List.of(Types.VARCHAR, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.STRUCT, Types.STRUCT);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it needs to be here, but it would be nice to have a test somewhere that asserted on the values of the planner stats struct, even if it was just making sure the values weren't null or zero. Getting a more sophisticated test set of assertions is probably for another time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a few verifys to the planGraph API in record-layer-core and I added some verifys in relational-core in QueryConfig. There is more code coming in that uses these metrics.

Comment on lines +239 to +240
final var plannerMetrics = resultSet.getStruct(6);
if (plannerMetrics != null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the plannerMetrics ever be null? I'd think that it should always be non-null except maybe for mixed mode tests where the column wouldn't be defined (and I guess must not be running here because it's happening in the explain step)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's null if the server does not have a Debugger installed.

@foundationdb-ci
Copy link
Contributor

Result of fdb-record-layer-pr on Linux CentOS 7

  • Commit ID: 2f565f5
  • Duration 0:56:34
  • Result: ✅ SUCCEEDED
  • Error: N/A
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@alecgrieser alecgrieser merged commit ee8f327 into FoundationDB:main Jan 28, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants