Skip to content

[BUG] PIT/Scroll request incorrectly triggered for aggregation queries when size limit exceeds max_result_window #3607

@noCharger

Description

@noCharger

What is the bug?
When executing aggregation queries with plugins.query.size_limit set higher than max_result_window (default 10,000), the query planner incorrectly triggers a PIT/scroll request. This results in unpredictable results for aggregation queries.

Root Cause: The size limit check in the query planner doesn't distinguish between aggregation and non-aggregation queries, contrary to the pagination design doc (https://github.com/opensearch-project/sql/blob/main/docs/dev/Pagination-v2.md#scope).

Code Reference: #1666

      if (startFrom + size >= maxResultWindow) {
        sourceBuilder.size(maxResultWindow - startFrom);
        return new OpenSearchScrollRequest(
            indexName, cursorKeepAlive, sourceBuilder, exprValueFactory, includes);

Impact: Unpredictable results for aggregation queries when plugins.query.size_limit exceeds max_result_window.

How can one reproduce the bug?

Set plugins.query.size_limit to 20,000:

{
    "persistent": {
        "plugins.query.size_limit": "20000"
    }
}

Execute an aggregation query:

source=fluentd.services | where attrs.SERVICE_NAME='ratelimit' | stats count() as cnt

What is the expected behavior?

  • PIT/Scroll request should not be triggered for aggregation queries
  • Accurate number of datarows with the correct count should be returned

Do you have any screenshots?

Scroll query returns infinite loop of nulls
Image

PIT query returns infinite loop of counts
Image

Do you have any additional context?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions