This is an automated email from the ASF dual-hosted git repository.
suxiaogang223 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push:
new 616d018ed68 [fix](fe) Honor scan limits in external SQL block rules
(#71150)
616d018ed68 is described below
commit 616d018ed686e9644889cf373ab909d54ba2dd45
Author: Socrates <[email protected]>
AuthorDate: Tue Dec 1 15:04:34 2026 +0800
[fix](fe) Honor scan limits in external SQL block rules (#71150)
### Background
SQL block rules compare the estimated cardinality of each scan with the
configured threshold. The planner can set a local limit on a file scan
while retaining its original cardinality estimate.
### What problem does this PR solve?
Issue Number: None
Related PR: None
PR Type: Bugfix
Problem Summary:
A preview query on a large external table can hit the cardinality rule
when its file scan already has LIMIT 1. Bound the cardinality used by
SQL Block with the limit on that scan.
### Details
- **Frequency:** File scans with a pushed-down limit at or below the
cardinality threshold and an estimate above it.
- **Root cause:** The SQL Block check reads the scan estimate before
accounting for the file scan's local execution limit.
- **Why existing tests missed it:** The Hive, Iceberg, and Paimon suites
checked oversized scans, including a Hive sort with a larger query
limit. The suites now cover a small limit on the scan and a limit on
aggregate output.
- **Fix:** Use the smaller of the file scan estimate and its local limit
for the cardinality check. Each scan supplies its own limit. A limit
on an aggregate does not affect the file scan's threshold comparison.
- **Other paths and branches:** The shared check covers external
connectors
that plan a `FileScanNode`. The partition and split rules continue to
use
their original estimates.
- **Behavior change:** A preview query can pass the cardinality rule
when
the limit on its file scan is within the configured threshold.
### Testing
- FE build with build.sh on Fedora and FE Checkstyle passed.
- Ran 10 focused FE tests on Fedora, including a temporary validation
of the scan limit, unrestricted scan, and split threshold paths.
- ASAN BE build with build.sh on Fedora passed.
- Both SQL Block regression suites passed end to end on Fedora
(`test_external_sql_block_rule` and `test_iceberg_sql_block_rule`).
The fixture used a single ASAN BE with file cache disabled on Btrfs.
- The Paimon SQL Block regression (`test_paimon_sql_block_rule`) passed
end to end on Fedora with the repository's Spark-generated MinIO
fixture.
A scan with LIMIT 1 passed the rule; a limited aggregate was blocked.
### Release note
SQL Block accounts for limits pushed to external scans when checking
cardinality, so small preview queries can pass the row threshold.
### Check List (For Author)
- Behavior changed: Yes (see Details)
- Does this need documentation: No
- Pre-submission status: Ready
### AI Disclosure
- Tool: OpenAI Codex (GPT-6)
- Generated: code, regression tests, and PR description
- Human review: Not yet performed.
---
fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java | 7 ++++++-
.../external_table_p0/hive/test_external_sql_block_rule.groovy | 7 +++++++
.../external_table_p0/iceberg/test_iceberg_sql_block_rule.groovy | 7 +++++++
.../external_table_p0/paimon/test_paimon_sql_block_rule.groovy | 7 +++++++
4 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
index e5f83d5fbd5..7fd24ad5318 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/StmtExecutor.java
@@ -958,10 +958,15 @@ public class StmtExecutor {
List<ScanNode> scanNodeList = planner.getScanNodes();
for (ScanNode scanNode : scanNodeList) {
if (scanNode instanceof OlapScanNode || scanNode instanceof
FileScanNode) {
+ long cardinality = scanNode.getCardinality();
+ if (scanNode instanceof FileScanNode && scanNode.hasLimit()) {
+ // File scans keep their uncapped estimate, even when the
scan itself enforces a limit.
+ cardinality = Math.min(cardinality, scanNode.getLimit());
+ }
Env.getCurrentEnv().getSqlBlockRuleMgr().checkLimitations(
scanNode.getSelectedPartitionNum(),
scanNode.getSelectedSplitNum(),
- scanNode.getCardinality(),
+ cardinality,
scanNode.isPartitionedTable(),
scanNode.hasPartitionPredicate(),
context.getQualifiedUser());
diff --git
a/regression-test/suites/external_table_p0/hive/test_external_sql_block_rule.groovy
b/regression-test/suites/external_table_p0/hive/test_external_sql_block_rule.groovy
index 69437be7055..4f94d426bf9 100644
---
a/regression-test/suites/external_table_p0/hive/test_external_sql_block_rule.groovy
+++
b/regression-test/suites/external_table_p0/hive/test_external_sql_block_rule.groovy
@@ -152,6 +152,13 @@ suite("test_external_sql_block_rule", "p0,external") {
sql """select * from ${catalog_name}.${db_name}.${table_name}
order by id limit 10;"""
exception """sql hits sql block rule: hive_cardinality_rule, reach
cardinality : 3"""
}
+ // A scan limit below or at the rule threshold should allow the query.
+ sql """select * from ${catalog_name}.${db_name}.${table_name} limit
1"""
+ // The aggregate still needs to scan all input rows. Its LIMIT only
bounds the output.
+ test {
+ sql """select sum(id) from
${catalog_name}.${db_name}.${table_name} limit 1"""
+ exception """sql hits sql block rule: hive_cardinality_rule, reach
cardinality : 3"""
+ }
// Test EXPLAIN should not be blocked
sql """explain select * from ${catalog_name}.${db_name}.${table_name}
order by id limit 10;"""
}
diff --git
a/regression-test/suites/external_table_p0/iceberg/test_iceberg_sql_block_rule.groovy
b/regression-test/suites/external_table_p0/iceberg/test_iceberg_sql_block_rule.groovy
index 1eee5270fc6..b8e3c509a6c 100644
---
a/regression-test/suites/external_table_p0/iceberg/test_iceberg_sql_block_rule.groovy
+++
b/regression-test/suites/external_table_p0/iceberg/test_iceberg_sql_block_rule.groovy
@@ -127,6 +127,13 @@ suite("test_iceberg_sql_block_rule", "p0,external") {
sql """select * from ${catalog_name}.${db_name}.${table_name}"""
exception """sql hits sql block rule: iceberg_cardinality_rule,
reach cardinality : 1"""
}
+ // A scan limit below or at the rule threshold should allow the query.
+ sql """select * from ${catalog_name}.${db_name}.${table_name} limit
1"""
+ // The aggregate still needs to scan all input rows. Its LIMIT only
bounds the output.
+ test {
+ sql """select sum(id) from
${catalog_name}.${db_name}.${table_name} limit 1"""
+ exception """sql hits sql block rule: iceberg_cardinality_rule,
reach cardinality : 1"""
+ }
// Test EXPLAIN should not be blocked
sql """explain select * from
${catalog_name}.${db_name}.${table_name}"""
}
diff --git
a/regression-test/suites/external_table_p0/paimon/test_paimon_sql_block_rule.groovy
b/regression-test/suites/external_table_p0/paimon/test_paimon_sql_block_rule.groovy
index 11cf2ea6cad..89ad588a8ce 100644
---
a/regression-test/suites/external_table_p0/paimon/test_paimon_sql_block_rule.groovy
+++
b/regression-test/suites/external_table_p0/paimon/test_paimon_sql_block_rule.groovy
@@ -114,6 +114,13 @@ suite("test_paimon_sql_block_rule", "p0,external") {
sql """select * from ${catalog_name}.${db_name}.${table_name}"""
exception """sql hits sql block rule: paimon_cardinality_rule,
reach cardinality : 1"""
}
+ // A scan limit below or at the rule threshold should allow the query.
+ sql """select * from ${catalog_name}.${db_name}.${table_name} limit
1"""
+ // The aggregate still needs to scan all input rows. Its LIMIT only
bounds the output.
+ test {
+ sql """select sum(id) from
${catalog_name}.${db_name}.${table_name} limit 1"""
+ exception """sql hits sql block rule: paimon_cardinality_rule,
reach cardinality : 1"""
+ }
// Test EXPLAIN should not be blocked
sql """explain select * from
${catalog_name}.${db_name}.${table_name}"""
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]