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

[SQL lab] Fixed limit issue #5281

Closed
wants to merge 1 commit into from

Conversation

conglei
Copy link
Contributor

@conglei conglei commented Jun 25, 2018

This PR is to fix the issue #5272

The original Regular Expression cannot catch the LIMIT statement when there are extra statements after LIMIT.

Note, the proposed solution is not perfect either.. Currently all the corner case I can think of:

  • 'LIMIT' inside quotes, which causes the false setting of query.limit
    SELECT "LIMIT 100" as C, id from aTable

  • LIMIT number is set larger than SQL_MAX_ROW, which causes the additional limit clause added
    SELECT * FROM atable LIMIT 10000001 OFFSET 1

  • get_query_without_limit function is broken too for the cases shown above.

@mistercrunch
Copy link
Member

Can you add a unit test preventing regression on this specific issue?

@@ -127,8 +126,7 @@ def get_query_without_limit(cls, sql):
(?ix) # case insensitive, verbose
\s+ # whitespace
LIMIT\s+\d+ # LIMIT $ROWS
;? # optional semi-colon
(\s|;)*$ # remove trailing spaces tabs or semicolons
(\s|;|.)*$ # remove the reset of the chars
Copy link
Contributor

@timifasubaa timifasubaa Jun 25, 2018

Choose a reason for hiding this comment

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

How about we selected everything after the number after the limit and also passed that remaining text along to the caller so the caller can do something lie "{before_limit} {new_limit} {after_limit}" That should fix problem 3 (adding the things after the limit). And to do that, we will just change this line to to (.*$) and pass the whole regex results tuple.

Copy link
Member

Choose a reason for hiding this comment

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

@conglei conglei closed this Jun 27, 2018
@conglei conglei deleted the conglei_sql_limit_fix branch June 27, 2018 18:41
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.

None yet

4 participants