Skip to content

fix(ui): Avoid auto-applying LIMIT to non-SELECT statements#26987

Merged
tdcmeehan merged 2 commits intoprestodb:masterfrom
prabhushankar-ps:fix-ui-limit-non-select
Jan 20, 2026
Merged

fix(ui): Avoid auto-applying LIMIT to non-SELECT statements#26987
tdcmeehan merged 2 commits intoprestodb:masterfrom
prabhushankar-ps:fix-ui-limit-non-select

Conversation

@prabhushankar-ps
Copy link
Copy Markdown
Contributor

Description

This change fixes how the Presto Web UI applies its default row limit. Previously, the UI added a LIMIT 100 to any statement that contained a SELECT clause, even when the statement itself was not a SELECT.

Because statements like CREATE TABLE AS SELECT and INSERT INTO … SELECT includes a SELECT as part of their syntax, they were incorrectly treated as interactive queries and could be silently truncated when run from the Web UI. This update ensures the default limit is applied only to top-level SELECT statements.

Motivation and Context

The Web UI applies a default row limit to help prevent users from accidentally returning very large result sets. The existing logic only checked for the presence of a SELECT clause, which caused non-SELECT statements that embed a SELECT to be handled incorrectly.

This change refines the SQL detection logic so that only plain SELECT statements are subject to the automatic limit.

Fixes #26975.

Impact

Interactive SELECT queries in the Web UI behave the same as before. CREATE TABLE AS SELECT, INSERT, and other non-SELECT statements are no longer modified by the UI. There are no changes to public APIs, server-side behavior, or performance.

Test Plan

Tested manually using the Presto Web UI.

Ran a SELECT without an explicit LIMIT and confirmed the default limit is applied. Ran a SELECT with an explicit LIMIT and confirmed it is preserved. Ran CREATE TABLE AS SELECT and INSERT INTO … SELECT statements and confirmed no LIMIT was appended.

Automated tests were not added because this change affects UI-side SQL preprocessing and there is no existing test coverage in this area.

Contributor checklist

Follows the Presto contributing guide and code style
PR description clearly explains the problem and why the change is needed
Linked to the relevant GitHub issue
No new public APIs, SQL syntax, or configuration changes
Manual testing completed; automated tests not applicable
CI passed (pending)
No new dependencies added

@prabhushankar-ps prabhushankar-ps requested review from a team and yhwang as code owners January 20, 2026 00:21
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Jan 20, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Jan 20, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refines the SQL detection logic in the Presto Web UI so that the automatic LIMIT is only applied to top-level SELECT statements, avoiding modification of CTAS, INSERT, and other non-SELECT queries that embed SELECTs.

Sequence diagram for applying default LIMIT only to top level SELECT

sequenceDiagram
    actor User
    participant WebUI
    participant SQLInputModule
    participant SelectListener

    User->>WebUI: submit SQL text
    WebUI->>SQLInputModule: sqlCleaning(sql, errorHandler)
    SQLInputModule->>SelectListener: new SelectListener()
    SQLInputModule->>SelectListener: walk parse tree
    SelectListener->>SelectListener: enterStatement(ctx)
    SelectListener->>SelectListener: set isTopLevelSelect based on ctx.query()
    SQLInputModule->>SQLInputModule: inspect isTopLevelSelect, limit, fetchFirstNRows
    alt isTopLevelSelect is true and limit exceeds 100
        SQLInputModule->>SQLInputModule: replace LIMIT with limit 100
    else isTopLevelSelect is false
        SQLInputModule->>SQLInputModule: do not modify SQL
    end
    SQLInputModule-->>WebUI: cleaned SQL
    WebUI-->>User: execute query and show results
Loading

Class diagram for updated SQLInput SelectListener limit detection

classDiagram
    class SelectListener {
        +number limit
        +number fetchFirstNRows
        +boolean isSelect
        +boolean isTopLevelSelect
        +SelectListener()
        +enterStatement(ctx)
    }

    class SQLInputModule {
        +sqlCleaning(sql, errorHandler)
    }

    SQLInputModule --> SelectListener : uses
Loading

File-Level Changes

Change Details Files
Only apply default LIMIT handling when the parsed SQL is a top-level SELECT statement.
  • Extend the SQL parse listener with an isTopLevelSelect flag initialized to false.
  • Set isTopLevelSelect to true in enterStatement when the parsed statement context represents a query (i.e., has ctx.query()).
  • Update sqlCleaning logic to gate LIMIT rewriting on isTopLevelSelect instead of the previous isSelect flag.
presto-ui/src/components/SQLInput.tsx

Assessment against linked issues

Issue Objective Addressed Explanation
#26975 Ensure the UI only auto-inserts a default LIMIT for top-level SELECT queries, and does not add LIMIT to non-SELECT statements such as CREATE TABLE AS SELECT or INSERT ... SELECT.
#26975 Add a configuration mechanism (e.g., a dropdown in the UI) to control the default LIMIT behavior/value. The PR only refines SQL parsing to distinguish top-level SELECT statements via isTopLevelSelect and uses that to decide when to apply the LIMIT. It does not add any UI elements (such as a dropdown) or configuration options to control the LIMIT value or behavior.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The new isTopLevelSelect flag makes isSelect appear redundant in this listener; consider removing isSelect (and any associated logic) if it is no longer used to keep the state and detection logic simple and easier to reason about.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `isTopLevelSelect` flag makes `isSelect` appear redundant in this listener; consider removing `isSelect` (and any associated logic) if it is no longer used to keep the state and detection logic simple and easier to reason about.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@tdcmeehan tdcmeehan self-assigned this Jan 20, 2026
@prabhushankar-ps
Copy link
Copy Markdown
Contributor Author

I’ve cleaned up the listener based on the feedback and removed the isSelect flag along with the related logic. Now that LIMIT enforcement is driven entirely by isTopLevelSelect, keeping isSelect didn’t add any value and made the state harder to follow.

On the CI side, the failure is in prestocpp-linux-build-for-test appears to come from presto-native-execution (an HTTP invocation error in the native client). Since this PR only touches Web UI SQL preprocessing and doesn’t affect native execution, the failure looks unrelated. A re-run of the failed job should help confirm.

@steveburnett
Copy link
Copy Markdown
Contributor

Please add a release note entry, even if the appropriate is only

== NO RELEASE NOTE ==

Copy link
Copy Markdown
Member

@yhwang yhwang left a comment

Choose a reason for hiding this comment

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

Nice change and thanks for the clean up.

/LGTM

@tdcmeehan
Copy link
Copy Markdown
Contributor

Thank you @prabhushankar-ps!

@tdcmeehan tdcmeehan merged commit acc0f20 into prestodb:master Jan 20, 2026
111 of 112 checks passed
@prabhushankar-ps
Copy link
Copy Markdown
Contributor Author

Thanks for the review and for re-running CI.

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.

UI: LIMIT should only be inserted for SELECT queries, should be configurable

4 participants