Skip to content

Commit ce86935

Browse files
authored
[fix](regression) topn-filter unstable case (#47797)
### What problem does this PR solve? regression-test/suites/query_p0/test_array_orderby_limit.groovy is unstable when case failed, plan shows that the table row count is 0. Issue Number: close #xxx Related PR: #xxx Problem Summary: ### Release note None ### Check List (For Author) - Test <!-- At least one of them must be included. --> - [ ] Regression test - [ ] Unit Test - [ ] Manual test (add detailed scripts or steps below) - [ ] No need to test or manual test. Explain why: - [ ] This is a refactor/code format and no logic has been changed. - [ ] Previous test can cover this change. - [ ] No code files have been changed. - [ ] Other reason <!-- Add your reason? --> - Behavior changed: - [ ] No. - [ ] Yes. <!-- Explain the behavior change --> - Does this need documentation? - [ ] No. - [ ] Yes. <!-- Add document PR link here. eg: apache/doris-website#1214 --> ### Check List (For Reviewer who merge this PR) - [ ] Confirm the release note - [ ] Confirm test cases - [ ] Confirm document - [ ] Add branch pick label <!-- Add branch pick label that this PR should merge into -->
1 parent fb74ef2 commit ce86935

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

fe/fe-core/src/main/java/org/apache/doris/nereids/processor/post/TopnFilterPushDownVisitor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ public Boolean visitPhysicalRelation(PhysicalRelation relation, PushDownContext
221221
// in ut, relation.getStats() may return null
222222
if (relation.getStats() == null || ConnectContext.get() == null
223223
|| ConnectContext.get().getSessionVariable() == null
224-
|| relation.getStats().getRowCount()
224+
|| Math.max(relation.getStats().getRowCount(), 1)
225225
* ConnectContext.get().getSessionVariable().topnFilterRatio > ctx.topn.getLimit()
226226
+ ctx.topn.getOffset()) {
227227
topnFilterContext.addTopnFilter(ctx.topn, relation, ctx.probeExpr);

regression-test/suites/query_p0/test_array_orderby_limit.groovy

+8-3
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
suite("test_array_char_orderby", "query") {
18+
suite("test_array_orderby_limit", "query") {
1919
// define a sql table
2020
def testTable = "test_array_char_orderby"
2121

2222
sql """
23+
drop table if exists test_array_char_orderby;
2324
CREATE TABLE IF NOT EXISTS test_array_char_orderby (
2425
`k1` INT(11) NULL,
2526
`k2` array<array<char(50)>> NULL
@@ -32,14 +33,18 @@ suite("test_array_char_orderby", "query") {
3233
"in_memory" = "false",
3334
"storage_format" = "V2",
3435
"disable_auto_compaction" = "false"
35-
)
36+
);
3637
"""
3738
// prepare data
3839
sql """ INSERT INTO test_array_char_orderby VALUES (100, [['abc']]), (200, [['xyz']]) """
3940
sql "analyze table test_array_char_orderby with sync"
4041
// set topn_opt_limit_threshold = 1024 to make sure _internal_service to be request with proto request
4142
sql """ set topn_opt_limit_threshold = 1024 """
42-
sql """ set topn_filter_ratio = 1 """
43+
sql """ set topn_filter_ratio = 2 """
44+
def table_stats = sql("show table stats test_array_char_orderby")
45+
log.info(table_stats.join("\n"))
46+
def memo = sql ("explain memo plan select * from test_array_char_orderby order by k1 limit 1")
47+
log.info(memo.join("\n"))
4348
explain{
4449
sql("select * from test_array_char_orderby order by k1 limit 1")
4550
contains "TOPN"

0 commit comments

Comments
 (0)