-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add query plans to profile output #128828
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
Changes from 8 commits
14eecf4
d2f5e34
dc24b62
966fac3
9d2072d
f0ff488
41a31ed
f7fc208
191bcb9
a55d399
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.compute.operator; | ||
|
|
||
| import org.elasticsearch.common.io.stream.StreamInput; | ||
| import org.elasticsearch.common.io.stream.StreamOutput; | ||
| import org.elasticsearch.common.io.stream.Writeable; | ||
| import org.elasticsearch.xcontent.ToXContentObject; | ||
| import org.elasticsearch.xcontent.XContentBuilder; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| public record PlanProfile(String description, String clusterName, String nodeName, String planTree) implements Writeable, ToXContentObject { | ||
|
|
||
| public static PlanProfile readFrom(StreamInput in) throws IOException { | ||
| return new PlanProfile(in.readString(), in.readString(), in.readString(), in.readString()); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| out.writeString(description); | ||
| out.writeString(clusterName); | ||
| out.writeString(nodeName); | ||
| out.writeString(planTree); | ||
| } | ||
|
|
||
| @Override | ||
| public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
| return builder.startObject() | ||
| .field("description", description) | ||
| .field("cluster_name", clusterName) | ||
| .field("node_name", nodeName) | ||
| .field("plan", planTree) | ||
| .endObject(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import org.elasticsearch.compute.data.BlockStreamInput; | ||
| import org.elasticsearch.compute.data.Page; | ||
| import org.elasticsearch.compute.operator.DriverProfile; | ||
| import org.elasticsearch.compute.operator.PlanProfile; | ||
| import org.elasticsearch.core.AbstractRefCounted; | ||
| import org.elasticsearch.core.Nullable; | ||
| import org.elasticsearch.core.Releasable; | ||
|
|
@@ -122,7 +123,7 @@ static EsqlQueryResponse deserialize(BlockStreamInput in) throws IOException { | |
| long documentsFound = in.getTransportVersion().onOrAfter(ESQL_DOCUMENTS_FOUND_AND_VALUES_LOADED) ? in.readVLong() : 0; | ||
| long valuesLoaded = in.getTransportVersion().onOrAfter(ESQL_DOCUMENTS_FOUND_AND_VALUES_LOADED) ? in.readVLong() : 0; | ||
| if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_12_0)) { | ||
| profile = in.readOptionalWriteable(Profile::new); | ||
| profile = in.readOptionalWriteable(Profile::readFrom); | ||
| } | ||
| boolean columnar = in.readBoolean(); | ||
| EsqlExecutionInfo executionInfo = null; | ||
|
|
@@ -286,13 +287,19 @@ private Iterator<ToXContent> profileRenderer(ToXContent.Params params) { | |
| if (profile == null) { | ||
| return Collections.emptyIterator(); | ||
| } | ||
| return Iterators.concat(ChunkedToXContentHelper.startObject("profile"), ChunkedToXContentHelper.chunk((b, p) -> { | ||
|
||
| if (executionInfo != null) { | ||
| b.field("query", executionInfo.overallTimeSpan()); | ||
| b.field("planning", executionInfo.planningTimeSpan()); | ||
| } | ||
| return b; | ||
| }), ChunkedToXContentHelper.array("drivers", profile.drivers.iterator(), params), ChunkedToXContentHelper.endObject()); | ||
| return Iterators.concat( | ||
| ChunkedToXContentHelper.startObject("profile"), // | ||
| ChunkedToXContentHelper.chunk((b, p) -> { | ||
| if (executionInfo != null) { | ||
| b.field("query", executionInfo.overallTimeSpan()); | ||
| b.field("planning", executionInfo.planningTimeSpan()); | ||
| } | ||
| return b; | ||
| }), | ||
| ChunkedToXContentHelper.array("drivers", profile.drivers.iterator(), params), | ||
| ChunkedToXContentHelper.array("plans", profile.plans.iterator()), | ||
|
||
| ChunkedToXContentHelper.endObject() | ||
| ); | ||
| } | ||
|
|
||
| public boolean[] nullColumns() { | ||
|
|
@@ -396,41 +403,23 @@ public EsqlResponse responseInternal() { | |
| return esqlResponse; | ||
| } | ||
|
|
||
| public static class Profile implements Writeable { | ||
| private final List<DriverProfile> drivers; | ||
| public record Profile(List<DriverProfile> drivers, List<PlanProfile> plans) implements Writeable { | ||
|
|
||
| public Profile(List<DriverProfile> drivers) { | ||
| this.drivers = drivers; | ||
| } | ||
|
|
||
| public Profile(StreamInput in) throws IOException { | ||
| this.drivers = in.readCollectionAsImmutableList(DriverProfile::readFrom); | ||
| public static Profile readFrom(StreamInput in) throws IOException { | ||
| return new Profile( | ||
| in.readCollectionAsImmutableList(DriverProfile::readFrom), | ||
| in.getTransportVersion().onOrAfter(TransportVersions.ESQL_PROFILE_INCLUDE_PLAN) | ||
| ? in.readCollectionAsImmutableList(PlanProfile::readFrom) | ||
| : List.of() | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public void writeTo(StreamOutput out) throws IOException { | ||
| out.writeCollection(drivers); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| if (out.getTransportVersion().onOrAfter(TransportVersions.ESQL_PROFILE_INCLUDE_PLAN)) { | ||
| out.writeCollection(plans); | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| Profile profile = (Profile) o; | ||
| return Objects.equals(drivers, profile.drivers); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(drivers); | ||
| } | ||
|
|
||
| List<DriverProfile> drivers() { | ||
| return drivers; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had said to auto-backport this. but it needs a transport version change. I should have know it does.
I think it's still worth it. Imagine someone giving us an 8.19 profile a year from now - we'll be happy that you added the plan....