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

CLICKHOUSE-3211 add TOP m, and OFFSET k #2840

Merged
merged 10 commits into from
Aug 14, 2018

Conversation

VadimPlh
Copy link
Contributor

I hereby agree to the terms of the CLA available at: https://yandex.ru/legal/cla/?lang=en

@zhang2014
Copy link
Contributor

What does this do? It looks like it's the same as the limit

@VadimPlh
Copy link
Contributor Author

VadimPlh commented Aug 10, 2018

@zhang2014 You are right) It seems like a LIMIT. It's the new syntax

@zhang2014
Copy link
Contributor

zhang2014 commented Aug 10, 2018

So why do we need it? I'm just curious : )

@VadimPlh
Copy link
Contributor Author

image

@VadimPlh
Copy link
Contributor Author

@zhang2014
For TOP ... WITH TIES

@derekperkins
Copy link
Contributor

Does this solve this issue in #2198?

@alexey-milovidov
Copy link
Member

Does this solve this issue in #2198?

No. The task #2198 is still unassigned.

@alexey-milovidov
Copy link
Member

alexey-milovidov commented Aug 10, 2018

So why do we need it? I'm just curious : )

LIMIT OFFSET is required for compatibility.
This syntax exists in PostgreSQL and was standardized in SQL 2008.
Some tools will generate queries using this syntax (instead of LIMIT n, m).
It also was added in MySQL with the same motivation.

And SELECT TOP is a bonus (compatibility with MS SQL + allows the implementation WITH TIES. We could add WITH TIES also after LIMIT but it's more known in MS SQL TOP syntax).

Copy link
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.

We should throw an exception if offset is specified in both forms LIMIT 10, 20 OFFSET 30 or if both LIMIT and TOP are specified.

Test should check that exceptions are thrown.

INSERT INTO test.test VALUES (8);
INSERT INTO test.test VALUES (9);

SELECT TOP 2 * FROM test.test;
Copy link
Member

Choose a reason for hiding this comment

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

The test is non-deterministic due to lack of ORDER BY.

SELECT TOP 2 * FROM test.test;
SELECT TOP (2) * FROM test.test;
SELECT * FROM test.test LIMIT 2 OFFSET 2;
SELECT TOP 2 * FROM test.test LIMIT 2; -- { clientError 406 }
Copy link
Member

Choose a reason for hiding this comment

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

Negative test for LIMIT n, m OFFSET k is pending.

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.

4 participants