This is an automated email from the ASF dual-hosted git repository.
yujun777 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 3933c9d672f [improvement](statistics) Configure scanner concurrency
for statistics SQL (#70938)
3933c9d672f is described below
commit 3933c9d672f3dc172c4bf618e6d31ec09c141e31
Author: yujun <[email protected]>
AuthorDate: Fri Nov 27 18:53:36 2026 +0800
[improvement](statistics) Configure scanner concurrency for statistics SQL
(#70938)
### Background
Manual and automatic statistics collection run SQL in a dedicated FE
connection context. This context starts with the global session defaults
and then applies statistics-specific resource settings for SQL memory
and pipeline instances. The BE has separate scanner concurrency settings
for table scans and file scans.
### What problem does this PR solve?
Issue Number: None
Related PR: None
PR Type: Enhancement
Problem Summary:
Operators who need to reduce scanner concurrency for statistics
collection currently have to lower the corresponding global session
defaults, which also affect ordinary queries. Two separate FE settings
let administrators tune statistics SQL at runtime for Doris tables and
file scans. Both default to one scanner per scan instance. Set either to
zero to restore inheritance from the corresponding global session
variable.
---
.../main/java/org/apache/doris/common/Config.java | 34 +++++++++++++
.../java/org/apache/doris/common/ConfigTest.java | 26 ++++++++++
.../src/main/java/org/apache/doris/DorisFE.java | 1 +
.../java/org/apache/doris/qe/SessionVariable.java | 4 +-
.../doris/statistics/util/StatisticsUtil.java | 8 +++
.../doris/statistics/util/StatisticsUtilTest.java | 58 ++++++++++++++++++++++
6 files changed, 129 insertions(+), 2 deletions(-)
diff --git a/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
b/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
index 24fb57f76be..ac9522a1401 100644
--- a/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
+++ b/fe/fe-common/src/main/java/org/apache/doris/common/Config.java
@@ -2709,6 +2709,40 @@ public class Config extends ConfigBase {
@ConfField(mutable = true)
public static long statistics_sql_mem_limit_in_bytes = 2L * 1024 * 1024 *
1024;
+ public static final int MAX_SQL_SCANNER_CONCURRENCY = 256;
+
+ @ConfField(mutable = true, callback =
StatisticsScannerConcurrencyConfHandler.class,
+ description = "Maximum scanner concurrency per scan instance for
internal tables in statistics SQL. "
+ + "0 inherits the global max_scanners_concurrency session
default.")
+ public static volatile int statistics_sql_max_scanners_concurrency = 1;
+
+ @ConfField(mutable = true, callback =
StatisticsScannerConcurrencyConfHandler.class,
+ description = "Maximum scanner concurrency per file scan instance
in statistics SQL. "
+ + "0 inherits the global max_file_scanners_concurrency
session default.")
+ public static volatile int statistics_sql_max_file_scanners_concurrency =
1;
+
+ public static class StatisticsScannerConcurrencyConfHandler implements
ConfHandler {
+ @Override
+ public void handle(Field field, String value) throws Exception {
+ int concurrency = Integer.parseInt(value.trim());
+ validateStatisticsScannerConcurrency(field.getName(), concurrency);
+ field.setInt(null, concurrency);
+ }
+ }
+
+ public static void validateStatisticsScannerConcurrency() throws
ConfigException {
+
validateStatisticsScannerConcurrency("statistics_sql_max_scanners_concurrency",
+ statistics_sql_max_scanners_concurrency);
+
validateStatisticsScannerConcurrency("statistics_sql_max_file_scanners_concurrency",
+ statistics_sql_max_file_scanners_concurrency);
+ }
+
+ private static void validateStatisticsScannerConcurrency(String name, int
concurrency) throws ConfigException {
+ if (concurrency < 0 || concurrency > MAX_SQL_SCANNER_CONCURRENCY) {
+ throw new ConfigException(name + " must be between 0 and " +
MAX_SQL_SCANNER_CONCURRENCY);
+ }
+ }
+
@ConfField(mutable = true, masterOnly = true, description = "Used to force
the number of replicas of internal "
+ "tables. If this config is greater than zero, the " + "number of
replicas specified by the user when "
+ "creating the table will be ignored, and the value " + "set by
this parameter will be used. At the same "
diff --git a/fe/fe-common/src/test/java/org/apache/doris/common/ConfigTest.java
b/fe/fe-common/src/test/java/org/apache/doris/common/ConfigTest.java
index 10c6b453adc..d1c6a30f064 100644
--- a/fe/fe-common/src/test/java/org/apache/doris/common/ConfigTest.java
+++ b/fe/fe-common/src/test/java/org/apache/doris/common/ConfigTest.java
@@ -316,6 +316,32 @@ public class ConfigTest {
}
}
+ @Test
+ public void testStatisticsScannerConcurrencyConfig() throws Exception {
+ for (String key : List.of("statistics_sql_max_scanners_concurrency",
+ "statistics_sql_max_file_scanners_concurrency")) {
+ Field field = Config.getField(key);
+ int previous = field.getInt(null);
+ try {
+ ConfigBase.setMutableConfig(key, "256");
+ Assertions.assertEquals(256, field.getInt(null));
+ for (String invalid : List.of("-1", "257", "unknown")) {
+ Assertions.assertThrows(ConfigException.class, () ->
ConfigBase.setMutableConfig(key, invalid));
+ Assertions.assertEquals(256, field.getInt(null));
+ }
+ ConfigBase.setMutableConfig(key, "0");
+ Assertions.assertEquals(0, field.getInt(null));
+
+ new Config().init(configFile(key + "=257").toString());
+ ConfigException exception =
Assertions.assertThrows(ConfigException.class,
+ Config::validateStatisticsScannerConcurrency);
+ Assertions.assertTrue(exception.getMessage().contains(key));
+ } finally {
+ field.setInt(null, previous);
+ }
+ }
+ }
+
@Test
public void testCloudWarmUpSchedulerIntervalMustBePositive() throws
ConfigException {
int original = Config.cloud_warm_up_job_scheduler_interval_millisecond;
diff --git a/fe/fe-core/src/main/java/org/apache/doris/DorisFE.java
b/fe/fe-core/src/main/java/org/apache/doris/DorisFE.java
index e7f6e788d50..ffc78b807ed 100755
--- a/fe/fe-core/src/main/java/org/apache/doris/DorisFE.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/DorisFE.java
@@ -154,6 +154,7 @@ public class DorisFE {
config.initCustom(Config.custom_config_dir + "/fe_custom.conf");
Config.validateWebSqlConfig();
Config.validateMtmvCacheConfig();
+ Config.validateStatisticsScannerConcurrency();
// inverted_index_storage_format's runtime callback is not invoked
while parsing
// fe.conf/fe_custom.conf, so validate the loaded value here after
both files are loaded
// and merged, to reject a "V1" left over in the config files at
startup.
diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
index 7ed07cf469e..6240dd75a4a 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java
@@ -4489,11 +4489,11 @@ public class SessionVariable implements Serializable,
Writable {
public void checkMaxScannersConcurrency(String value) throws Exception {
// Non-positive scanner concurrency values select the BE defaults.
- checkFieldValue(MAX_SCANNERS_CONCURRENCY, Integer.MIN_VALUE, 256,
value);
+ checkFieldValue(MAX_SCANNERS_CONCURRENCY, Integer.MIN_VALUE,
Config.MAX_SQL_SCANNER_CONCURRENCY, value);
}
public void checkMaxFileScannersConcurrency(String value) throws Exception
{
- checkFieldValue(MAX_FILE_SCANNERS_CONCURRENCY, Integer.MIN_VALUE, 256,
value);
+ checkFieldValue(MAX_FILE_SCANNERS_CONCURRENCY, Integer.MIN_VALUE,
Config.MAX_SQL_SCANNER_CONCURRENCY, value);
}
public void checkMinScannersConcurrency(String value) throws Exception {
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java
b/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java
index e6c4ae3f803..cc91bd9aabc 100644
---
a/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java
+++
b/fe/fe-core/src/main/java/org/apache/doris/statistics/util/StatisticsUtil.java
@@ -224,6 +224,14 @@ public class StatisticsUtil {
sessionVariable.enableProfile = Config.enable_profile_when_analyze;
sessionVariable.parallelExecInstanceNum =
Config.statistics_sql_parallel_exec_instance_num;
sessionVariable.parallelPipelineTaskNum =
Config.statistics_sql_parallel_exec_instance_num;
+ int maxScannersConcurrency =
Config.statistics_sql_max_scanners_concurrency;
+ if (maxScannersConcurrency > 0) {
+ sessionVariable.setMaxScannersConcurrency(maxScannersConcurrency);
+ }
+ int maxFileScannersConcurrency =
Config.statistics_sql_max_file_scanners_concurrency;
+ if (maxFileScannersConcurrency > 0) {
+ sessionVariable.maxFileScannersConcurrency =
maxFileScannersConcurrency;
+ }
sessionVariable.setQueryTimeoutS(StatisticsUtil.getAnalyzeTimeout());
sessionVariable.insertTimeoutS = StatisticsUtil.getAnalyzeTimeout();
sessionVariable.enableFileCache = false;
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/statistics/util/StatisticsUtilTest.java
b/fe/fe-core/src/test/java/org/apache/doris/statistics/util/StatisticsUtilTest.java
index cc0e9b28903..a0ef8d3c6d6 100644
---
a/fe/fe-core/src/test/java/org/apache/doris/statistics/util/StatisticsUtilTest.java
+++
b/fe/fe-core/src/test/java/org/apache/doris/statistics/util/StatisticsUtilTest.java
@@ -33,17 +33,21 @@ import org.apache.doris.common.Config;
import org.apache.doris.common.DdlException;
import org.apache.doris.common.Pair;
import org.apache.doris.common.util.PropertyAnalyzer;
+import org.apache.doris.datasource.CatalogMgr;
import org.apache.doris.datasource.ExternalCatalog;
import org.apache.doris.datasource.InternalCatalog;
import org.apache.doris.datasource.plugin.PluginDrivenExternalCatalog;
import org.apache.doris.datasource.plugin.PluginDrivenExternalDatabase;
import org.apache.doris.datasource.plugin.PluginDrivenExternalTable;
import org.apache.doris.nereids.trees.expressions.literal.Literal;
+import org.apache.doris.qe.AutoCloseConnectContext;
import org.apache.doris.qe.SessionVariable;
+import org.apache.doris.qe.VariableMgr;
import org.apache.doris.rpc.RpcException;
import org.apache.doris.statistics.analysis.AnalysisManager;
import org.apache.doris.statistics.analysis.ColStatsMeta;
import org.apache.doris.statistics.analysis.TableStatsMeta;
+import org.apache.doris.thrift.TQueryOptions;
import org.apache.doris.thrift.TStorageType;
import org.junit.jupiter.api.Assertions;
@@ -59,6 +63,60 @@ import java.util.List;
import java.util.Map;
class StatisticsUtilTest {
+ @Test
+ void testStatisticsScannerConcurrencyQueryOptions() {
+ int previousMaxScanners =
Config.statistics_sql_max_scanners_concurrency;
+ int previousMaxFileScanners =
Config.statistics_sql_max_file_scanners_concurrency;
+ SessionVariable globalDefaults =
VariableMgr.getDefaultSessionVariable();
+ int previousGlobalMaxScanners =
globalDefaults.getMaxScannersConcurrency();
+ int previousGlobalMaxFileScanners =
globalDefaults.maxFileScannersConcurrency;
+
+ Env env = Mockito.mock(Env.class);
+ CatalogMgr catalogMgr = Mockito.mock(CatalogMgr.class);
+ InternalCatalog catalog = Mockito.mock(InternalCatalog.class);
+ Mockito.when(env.getInternalCatalog()).thenReturn(catalog);
+ Mockito.when(env.getCatalogMgr()).thenReturn(catalogMgr);
+
Mockito.when(catalog.getName()).thenReturn(InternalCatalog.INTERNAL_CATALOG_NAME);
+
Mockito.when(catalogMgr.getCatalog(InternalCatalog.INTERNAL_CATALOG_NAME)).thenReturn(catalog);
+ try (MockedStatic<Env> mockedEnv = Mockito.mockStatic(Env.class)) {
+ mockedEnv.when(Env::getCurrentEnv).thenReturn(env);
+ globalDefaults.setMaxScannersConcurrency(6);
+ globalDefaults.maxFileScannersConcurrency = 12;
+
+ try (AutoCloseConnectContext context =
StatisticsUtil.buildConnectContext(false)) {
+ TQueryOptions options =
context.connectContext.getSessionVariable().toThrift();
+ Assertions.assertEquals(1,
options.getMaxScannersConcurrency());
+ Assertions.assertEquals(1,
options.getMaxFileScannersConcurrency());
+ }
+
+ Config.statistics_sql_max_scanners_concurrency = 0;
+ Config.statistics_sql_max_file_scanners_concurrency = 7;
+
+ try (AutoCloseConnectContext context =
StatisticsUtil.buildConnectContext(false)) {
+ TQueryOptions options =
context.connectContext.getSessionVariable().toThrift();
+ Assertions.assertEquals(6,
options.getMaxScannersConcurrency());
+ Assertions.assertEquals(7,
options.getMaxFileScannersConcurrency());
+ }
+
+ Config.statistics_sql_max_scanners_concurrency = 2;
+ Config.statistics_sql_max_file_scanners_concurrency = 0;
+ try (AutoCloseConnectContext context =
StatisticsUtil.buildConnectContext(false)) {
+ TQueryOptions options =
context.connectContext.getSessionVariable().toThrift();
+ Assertions.assertEquals(2,
options.getMaxScannersConcurrency());
+ Assertions.assertEquals(12,
options.getMaxFileScannersConcurrency());
+ }
+
+ SessionVariable ordinaryQueryVariables =
VariableMgr.newSessionVariable();
+ Assertions.assertEquals(6,
ordinaryQueryVariables.getMaxScannersConcurrency());
+ Assertions.assertEquals(12,
ordinaryQueryVariables.maxFileScannersConcurrency);
+ } finally {
+ Config.statistics_sql_max_scanners_concurrency =
previousMaxScanners;
+ Config.statistics_sql_max_file_scanners_concurrency =
previousMaxFileScanners;
+
globalDefaults.setMaxScannersConcurrency(previousGlobalMaxScanners);
+ globalDefaults.maxFileScannersConcurrency =
previousGlobalMaxFileScanners;
+ }
+ }
+
@Test
void testTimestampNsStatisticsValues() throws AnalysisException {
String minValue = "1677-09-21 00:12:43.145224192";
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]