Skip to content

Conversation

@morningman
Copy link
Contributor

cherry-pick #44338

Problem Summary:
When there is a `limit` cluse in SQL, if FE has obtained data with more
than the `limit` number of rows,
it should send a cancel command to BE to cancel the query to prevent BE
from reading more data.
However, this function has problems in the current code and does not
work.
Especially in external table query, this may result in lots of
unnecessary network io read.

1. `isBlockQuery`

In the old optimizer, if a query statement contains a `sort` or `agg`
node,
    `isBlockQuery` will be marked as true, otherwise it will be false.
    In the new optimizer, this value is always true.

    Regardless of the old or new optimizer, this logic is wrong.
But only when `isBlockQuery = false` will the reach limit logic be
triggered.

2. Calling problem of reach limit logic

The reach limit logic judgment will only be performed when `eos = true`
in the rowBatch returned by BE.
    This is wrong.
Because for `limit N` queries, each BE's own `limit` is N. But for FE,
as long as the total number of rows
returned by all BEs exceeds N, the reach limit logic can be triggered.
    So it should not be processed only when `eos = true`.

The PR mainly changes:

1. Remove `isBlockQuery`

`isBlockQuery` is only used in the reach limit logic. And it is not
needed. Remove it completely.

2. Modify the judgment position of reach limit.

    When the number of rows obtained by FE is greater than the limit,
    it will check the reach limit logic.

3. fix wrong `limitRows` in `QueryProcessor`

    the limitRows should be got from the first fragment, not last.

4. In scanner scheduler on BE side, if scanner has limit, ignore the
scan bytes threshold per round.

[fix](planner) query should be cancelled if limit reached
@doris-robot
Copy link

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@morningman
Copy link
Contributor Author

run buildall

@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

1 similar comment
@github-actions
Copy link
Contributor

clang-tidy review says "All clean, LGTM! 👍"

@doris-robot
Copy link

TeamCity be ut coverage result:
Function Coverage: 36.51% (9565/26201)
Line Coverage: 27.93% (78561/281305)
Region Coverage: 26.59% (40319/151630)
Branch Coverage: 23.35% (20429/87482)
Coverage Report: http://coverage.selectdb-in.cc/coverage/7bf03dc6d88168423397024d1eebfbecab50addf_7bf03dc6d88168423397024d1eebfbecab50addf/report/index.html

@github-actions github-actions bot added the approved Indicates a PR has been approved by one committer. label Dec 10, 2024
@github-actions
Copy link
Contributor

PR approved by at least one committer and no changes requested.

@github-actions
Copy link
Contributor

PR approved by anyone and no changes requested.

@morningman morningman merged commit e29d125 into apache:branch-2.1 Dec 10, 2024
21 of 23 checks passed
@yiguolei yiguolei mentioned this pull request Jan 19, 2025
GoGoWen pushed a commit to GoGoWen/incubator-doris that referenced this pull request Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by one committer. reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants