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

Add setting to disable aggs optimization #73589

Closed
wants to merge 3 commits into from

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Jun 1, 2021

Sometimes our fancy "run this agg as a Query" optimizations end up
slower than running the aggregation in the old way. We know that and use
heuristics to dissable the optimization in that case. But it turns out
that the process of running the heuristics itself can be slow, depending
on the query. Worse, changing the heuristics requires an upgrade, which
means waiting. If the heurisics make a terrible choice folks need a
quick way out. This adds such a way: a cluster level setting that
contains a list of queries that are considered "too expensive" to try
and optimize. If the top level query contains any of those queries we'll
disable the "run as Query" optimization.

The default for this settings is wildcard and term-in-set queries, which
is fairly conservative. There are certainly wildcard and term-in-set
queries that the optimization works well with, but there are other queries
of that type that it works very badly with. So we're being careful.

Better, you can modify this setting in a running cluster to disable the
optimization if we find a new type of query that doesn't work well.

Closes #73426

Sometimes our fancy "run this agg as a Query" optimizations end up
slower than running the aggregation in the old way. We know that and use
heuristics to dissable the optimization in that case. But it turns out
that the process of running the heuristics itself can be slow, depending
on the query. Worse, changing the heuristics requires an upgrade, which
means waiting. If the heurisics make a terrible choice folks need a
quick way out. This adds such a way: a cluster level setting that
contains a list of queries that are considered "too expensive" to try
and optimize. If the top level query contains any of those queries we'll
disable the "run as Query" optimization.

The default for this settings is wildcard and term-in-set queries, which
is fairly conservative. There are certainly wildcard and term-in-set
queries that the optimization works well with, but there are other queries
of that type that it works very badly with. So we're being careful.

Better, you can modify this setting in a running cluster to disable the
optimization if we find a new type of query that doesn't work well.

Closes elastic#73426
@nik9000
Copy link
Member Author

nik9000 commented Jun 1, 2021

I need to reread this again and add a few more tests, but I'd like to get this out there.

@nik9000 nik9000 force-pushed the disable_filters_opt_on_some branch from 0775318 to 810b282 Compare June 1, 2021 12:41
@nik9000
Copy link
Member Author

nik9000 commented Jun 1, 2021

I'd like to add an integration test for this in the terms aggregator - that'd let us make sure the settings works.

import java.util.stream.Collectors;

import static io.github.nik9000.mapmatcher.MapMatcher.assertMap;
import static io.github.nik9000.mapmatcher.MapMatcher.matchesMap;
Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, that should not be here

Copy link
Member Author

Choose a reason for hiding this comment

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

No?

@nik9000
Copy link
Member Author

nik9000 commented Jun 1, 2021

It looks like there is another class of issue around these optimization that comes from the query being very very large. We don't copy the query, but we do make its weight many times. I'd expected that these weights would be cached. But that's not always guaranteed. I think in a follow up change we should skip this optimization also based on the size of the query. We should also do more to reduce the re-preparation of the weights. That's a little more complicated though. Lucene has some hard won heuristics around what to cache when and we'd have to be careful there. I think it's best to do the simplest thing.

@nik9000 nik9000 closed this Jun 1, 2021
@nik9000
Copy link
Member Author

nik9000 commented Jun 1, 2021

After talking with some folks it turns out that the setting is too precise and difficult to use. And might cause issues on upgrade. And who knows what else. It was clever, but not worth it.

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.

Setting to disable rewrite-to-filters optimization
2 participants