-
Couldn't load subscription status.
- Fork 25.6k
ES|QL: Fix wrong pruning of plans with no output columns #133405
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 9 commits
ad961ae
21dc299
de95b79
42d364f
544d6dd
c2f01d6
ba01afe
764cace
642b50a
3ae2314
e09cabd
a1aaa5b
0421de5
34b995a
2e35ab3
be75856
657c94e
a3cccde
dd74c0b
afd0350
b45fc9a
b42b09a
3a388a7
076db41
b0a9d02
130fa2e
c0ac934
710fdcc
edc3890
d2a5631
921ecb8
59207cb
bb45498
d059447
f8ca703
e9ebf8b
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,5 @@ | ||
| pr: 133405 | ||
| summary: Fix wrong pruning of plans with no output columns | ||
| area: ES|QL | ||
| type: bug | ||
| issues: [] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ | |
| import org.elasticsearch.common.lucene.BytesRefs; | ||
| import org.elasticsearch.compute.data.AggregateMetricDoubleBlockBuilder; | ||
| import org.elasticsearch.compute.data.Block; | ||
| import org.elasticsearch.compute.data.Page; | ||
| import org.elasticsearch.core.Strings; | ||
| import org.elasticsearch.index.IndexMode; | ||
| import org.elasticsearch.logging.Logger; | ||
|
|
@@ -458,7 +459,7 @@ private LocalRelation tableMapAsRelation(Source source, Map<String, Column> mapT | |
| // prepare the block for the supplier | ||
| blocks[i++] = column.values(); | ||
| } | ||
| LocalSupplier supplier = LocalSupplier.of(blocks); | ||
| LocalSupplier supplier = LocalSupplier.of(blocks.length > 0 ? new Page(blocks) : new Page(0)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am wondering if we could integrate the logic "if the blocks size is 0 then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want this in general, in some cases we want no blocks but |
||
| return new LocalRelation(source, attributes, supplier); | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,7 @@ | |
| import org.elasticsearch.xpack.esql.optimizer.rules.logical.PropagateNullable; | ||
| import org.elasticsearch.xpack.esql.optimizer.rules.logical.PropgateUnmappedFields; | ||
| import org.elasticsearch.xpack.esql.optimizer.rules.logical.PruneColumns; | ||
| import org.elasticsearch.xpack.esql.optimizer.rules.logical.PruneEmptyPlans; | ||
| import org.elasticsearch.xpack.esql.optimizer.rules.logical.PruneEmptyAggregates; | ||
| import org.elasticsearch.xpack.esql.optimizer.rules.logical.PruneFilters; | ||
| import org.elasticsearch.xpack.esql.optimizer.rules.logical.PruneLiteralsInOrderBy; | ||
| import org.elasticsearch.xpack.esql.optimizer.rules.logical.PruneRedundantOrderBy; | ||
|
|
@@ -166,7 +166,6 @@ protected static Batch<LogicalPlan> operators(boolean local) { | |
| "Operator Optimization", | ||
| new CombineProjections(local), | ||
| new CombineEvals(), | ||
| new PruneEmptyPlans(), | ||
| new PropagateEmptyRelation(), | ||
| new FoldNull(), | ||
| new SplitInWithFoldableValue(), | ||
|
|
@@ -203,7 +202,8 @@ protected static Batch<LogicalPlan> operators(boolean local) { | |
| new PushDownAndCombineOrderBy(), | ||
| new PruneRedundantOrderBy(), | ||
| new PruneRedundantSortClauses(), | ||
| new PruneLeftJoinOnNullMatchingField() | ||
| new PruneLeftJoinOnNullMatchingField(), | ||
| new PruneEmptyAggregates() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need this because our aggs don't know how to deal with no grouping and no aggs at the same time. |
||
| ); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| /* | ||
| * 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.xpack.esql.optimizer.rules.logical; | ||
|
|
||
| import org.elasticsearch.compute.data.Page; | ||
| import org.elasticsearch.xpack.esql.plan.logical.Aggregate; | ||
| import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan; | ||
| import org.elasticsearch.xpack.esql.plan.logical.local.LocalRelation; | ||
| import org.elasticsearch.xpack.esql.plan.logical.local.LocalSupplier; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public final class PruneEmptyAggregates extends OptimizerRules.OptimizerRule<Aggregate> { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would help to have a javadoc on this rule. I mean, it is obvious what it does, but it would be helpful to read about the situations that lead to an Aggregate with no aggregates and no groupings. |
||
| @Override | ||
| protected LogicalPlan rule(Aggregate agg) { | ||
| if (agg.aggregates().isEmpty() && agg.groupings().isEmpty()) { | ||
| return new LocalRelation(agg.source(), List.of(), LocalSupplier.of(new Page(1))); | ||
| } | ||
| return agg; | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
| package org.elasticsearch.xpack.esql.optimizer.rules.logical; | ||
|
|
||
| import org.elasticsearch.compute.data.BlockUtils; | ||
| import org.elasticsearch.compute.data.Page; | ||
| import org.elasticsearch.xpack.esql.optimizer.LogicalOptimizerContext; | ||
| import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan; | ||
| import org.elasticsearch.xpack.esql.plan.logical.Row; | ||
|
|
@@ -29,6 +30,6 @@ protected LogicalPlan rule(Row row, LogicalOptimizerContext context) { | |
| List<Object> values = new ArrayList<>(fields.size()); | ||
| fields.forEach(f -> values.add(f.child().fold(context.foldCtx()))); | ||
| var blocks = BlockUtils.fromListRow(PlannerUtils.NON_BREAKING_BLOCK_FACTORY, values); | ||
| return new LocalRelation(row.source(), row.output(), new CopyingLocalSupplier(blocks)); | ||
| return new LocalRelation(row.source(), row.output(), new CopyingLocalSupplier(blocks.length == 0 ? new Page(0) : new Page(blocks))); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here about this common logic where a Page is built this way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above |
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.