Skip to content

[BUG] SQL legacy engine creates PIT unnecessarily and leak context #5002

@dai-chen

Description

@dai-chen

What is the bug?

When no cursor requested (fetch_size is not specified), the SQL Legacy engine creates Point-in-Time (PIT) contexts unnecessarily. Meanwhile, the PIT is also not closed properly, causing PIT contexts to leak and accumulate until they expire after the keep-alive timeout (default: 1 minute). Under repeated or concurrent query workloads, this can exhaust PIT capacity and hit the default limit of 300 open PIT contexts, resulting in query failures.

How can one reproduce the bug?

  1. Create test index:
PUT /test-logs-2025-01-01
{
  "mappings": {
    "properties": {
      "action": {"type": "text", "fields": {"keyword": {"type": "keyword"}}},
      "timestamp": {"type": "date"}
    }
  }
}
  1. Insert test data:
POST /test-logs-2025-01-01/_bulk
{"index":{}}
{"action":"login_success","timestamp":"2025-01-01T10:00:00Z"}
{"index":{}}
{"action":"login_success","timestamp":"2025-01-01T10:01:00Z"}
{"index":{}}
{"action":"login_failed","timestamp":"2025-01-01T10:02:00Z"}
  1. Run SQL query (with backtick for V2 test, e.g., `test-logs-2025-01-01` ):
POST /_plugins/_sql
{
  "query": "SELECT * FROM test-logs-2025-01-01 WHERE action LIKE 'login%' ORDER BY timestamp ASC"
}
  1. Check PIT contexts:
GET /_nodes/stats/indices/search?filter_path=nodes.*.indices.search.point_in_time_current

What is the expected behavior?

For queries that complete in a single page (no cursor requested / no follow-up page needed):

  • Do not create PIT, or;
  • If PIT is created internally, close/delete it before returning the response.

Note: The SQL/PPL V2 engine may also create PIT implicitly, but in that case it can be intentional: V2 may fetch until the last page and then close the PIT to ensure correctness for any required in-memory post-processing.

What is your host/environment?

  • OpenSearch Version: 2.19-dev, main branch
  • Plugin: SQL plugin

Do you have any screenshots?

N/A

Do you have any additional context?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions