Skip to content

Conversation

@idegtiarenko
Copy link
Contributor

This change reuse previously grouped indices during query execution phase.

@idegtiarenko idegtiarenko added >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) :Analytics/ES|QL AKA ESQL v9.3.0 labels Nov 11, 2025
@idegtiarenko idegtiarenko marked this pull request as ready for review November 11, 2025 16:20
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

Map<String, OriginalIndices> clusterToOriginalIndices = transportService.getRemoteClusterService()
.groupIndices(SearchRequest.DEFAULT_INDICES_OPTIONS, PlannerUtils.planOriginalIndices(physicalPlan));
// Gets the original indices specified in the FROM command of the query. We need the original query to resolve alias filters.
Map<String, OriginalIndices> clusterToOriginalIndices = getIndices(execInfo, EsqlExecutionInfo.Cluster::getOriginalIndices);
Copy link
Contributor Author

@idegtiarenko idegtiarenko Nov 12, 2025

Choose a reason for hiding this comment

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

It is not possible to group original expressions in flat/CPS since cluster prefixes are not explicit.
EsqlExecutionInfo contains the necessary information after performing FC, we could take it from there.
Additionally this would avoid the need to traverse plane and group indices again and will make this operation a tiny bit cheaper.

.groupIndices(SearchRequest.DEFAULT_INDICES_OPTIONS, PlannerUtils.planConcreteIndices(physicalPlan).toArray(String[]::new));

// Returns the concrete/resolved indices used in the FROM command of the query.
Map<String, OriginalIndices> clusterToConcreteIndices = getIndices(execInfo, EsqlExecutionInfo.Cluster::getConcreteIndices);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Grouping concrete indices should be possible, but it is preferable to store result in EsqlExecutionInfo instead of traversing plan and grouping indices again (especially if we have a pattern resolved to hundreds of indices).

Copy link
Contributor

@luigidellaquila luigidellaquila left a comment

Choose a reason for hiding this comment

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

LGTM

/**
* This cluster's concrete/resolved indices.
*/
private final String concreteIndices;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I wonder if this should be a String[] instead. Probably it depends on how we'll use it in the future.

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 was considering using array, however I am concerned that it is mutable opposed to plain string

Copy link
Member

Choose a reason for hiding this comment

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

This string can be very long.

# Conflicts:
#	server/src/main/resources/transport/upper_bounds/9.3.csv
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlExecutionInfo.java
# Conflicts:
#	server/src/main/resources/transport/upper_bounds/9.3.csv
Copy link
Member

@dnhatn dnhatn left a comment

Choose a reason for hiding this comment

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

I've left some small comments. Thanks @idegtiarenko.

out.writeString(indexExpression);
out.writeString(originalIndices);
if (out.getTransportVersion().supports(CONCRETE_INDICES_VERSION)) {
out.writeString(concreteIndices);
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to serialize this field? If so, we need to handle nulls from line 526.

return Maps.transformValues(
executionInfo.getClusters(),
cluster -> new OriginalIndices(
Strings.commaDelimitedListToStringArray(getter.apply(cluster)),
Copy link
Member

Choose a reason for hiding this comment

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

This is only called once, but I'm not sure this approach. We concatenate an array of concrete indices into a single string, then split them here. Can we store them as a Set (shared with indexNameWithModes from EsRelation) or as an array, but not as a single string?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants