Skip to content

Optimize async cursor cleanup by skipping task reduction instead of executing tasks #6665

@puzpuzpuz

Description

@puzpuzpuz

Problem

When closing async record cursors (e.g., AsyncWindowJoinRecordCursor, AsyncFilteredRecordCursor, AsyncGroupByRecordCursor), the current implementation reduces/executes all published tasks before completing the cleanup. This is wasteful because these task results will be discarded anyway.

Current behavior

  • On close(), the cursor calls collectCursor(true) and frameSequence.await()
  • This causes remaining tasks in the frame sequence to be reduced (executed) by workers
  • The results are then discarded since the cursor is closing

Suggested enhancement

When closing a cursor, skip all tasks that belong to the frame sequence being closed instead of reducing them. This would:

  • Avoid wasting CPU cycles on work that will be discarded
  • Reduce query latency, especially for queries with LIMIT n that close early

Additional context

The SIGSEGV bug in #6662 manifested reliably with LIMIT n clauses because the query owner thread (when not a worker thread) was guaranteed to reduce remaining tasks during close, which accelerated the race condition between task reduction and resource cleanup.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementEnhance existing functionalityPerformancePerformance improvementsSQLIssues or changes relating to SQL execution

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions