Skip to content

Add support for negative LIMIT and negative OFFSET#88411

Merged
alexey-milovidov merged 49 commits intoClickHouse:masterfrom
nihalzp:negative-limit
Oct 16, 2025
Merged

Add support for negative LIMIT and negative OFFSET#88411
alexey-milovidov merged 49 commits intoClickHouse:masterfrom
nihalzp:negative-limit

Conversation

@nihalzp
Copy link
Copy Markdown
Member

@nihalzp nihalzp commented Oct 12, 2025

Supports both new and old analyzers.

Some optimizations are not yet supported with negative LIMIT. Additionally, LIMIT BY and WITH TIES are not supported for now. I will add the support eventually in future PRs.

Examples:

SELECT number
FROM numbers(10)
LIMIT -3 OFFSET -2

   ┌─number─┐
1. │      52. │      63. │      7 │
   └────────┘
SELECT number
FROM numbers(10)
OFFSET -8

   ┌─number─┐
1. │      02. │      1 │
   └────────┘

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Add support for negative LIMIT and negative OFFSET. Closes #28913

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 12, 2025
@clickhouse-gh
Copy link
Copy Markdown
Contributor

clickhouse-gh bot commented Oct 12, 2025

Workflow [PR], commit [b4b46dd]

Summary:

job_name test_name status info comment
Integration tests (amd_binary, 1/5) failure
test_storage_s3_queue/test_4.py::test_alter_settings FAIL cidb
Performance Comparison (amd_release, master_head, 3/3) failure
Start failure

@clickhouse-gh clickhouse-gh bot added the pr-feature Pull request with new product feature label Oct 12, 2025
@nihalzp nihalzp mentioned this pull request Oct 15, 2025
@nihalzp
Copy link
Copy Markdown
Member Author

nihalzp commented Oct 15, 2025

@alexey-milovidov The PR is ready for review.

Copy link
Copy Markdown
Member

@alexey-milovidov alexey-milovidov left a comment

Choose a reason for hiding this comment

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

Looks really great - an example of high-quality code, well tested, good documentation!

@alexey-milovidov alexey-milovidov self-assigned this Oct 16, 2025
@alexey-milovidov
Copy link
Copy Markdown
Member

alexey-milovidov commented Oct 16, 2025

SELECT number
FROM numbers(10)
OFFSET -8

   ┌─number─┐
1. │      0 │
2. │      1 │
   └────────┘

This looks interesting. So, negative offset also implies negative "limit direction". Yes, that's reasonable.

@alexey-milovidov alexey-milovidov merged commit c8d2df3 into ClickHouse:master Oct 16, 2025
119 of 123 checks passed
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors pr-feature Pull request with new product feature pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Negative LIMIT specification.

3 participants