From 6d323b85996fabd8950d206a3c1ed64d236cbd01 Mon Sep 17 00:00:00 2001 From: englefly Date: Tue, 17 Oct 2023 23:51:45 +0800 Subject: [PATCH] make enable_stats session var --- .../src/main/java/org/apache/doris/common/Config.java | 6 ------ .../org/apache/doris/analysis/AlterColumnStatsStmt.java | 3 +-- .../org/apache/doris/analysis/AlterTableStatsStmt.java | 3 +-- .../java/org/apache/doris/analysis/AnalyzeTblStmt.java | 3 +-- .../main/java/org/apache/doris/analysis/DropStatsStmt.java | 3 +-- .../java/org/apache/doris/analysis/ShowAnalyzeStmt.java | 3 +-- .../org/apache/doris/analysis/ShowAnalyzeTaskStatus.java | 4 ++-- .../org/apache/doris/nereids/minidump/MinidumpUtils.java | 4 ++-- .../org/apache/doris/nereids/stats/StatsCalculator.java | 5 +++-- .../src/main/java/org/apache/doris/qe/SessionVariable.java | 7 +++++++ 10 files changed, 19 insertions(+), 22 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 8e1c8761de3380..75c6f3e679b2f5 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 @@ -2016,12 +2016,6 @@ public class Config extends ConfigBase { @ConfField(mutable = true) public static boolean enable_round_robin_create_tablet = false; - /** - * If set false, user couldn't submit analyze SQL and FE won't allocate any related resources. - */ - @ConfField - public static boolean enable_stats = true; - /** * To prevent different types (V1, V2, V3) of behavioral inconsistencies, * we may delete the DecimalV2 and DateV1 types in the future. diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterColumnStatsStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterColumnStatsStmt.java index 58b81212671fa3..085724b6c9ffc1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterColumnStatsStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterColumnStatsStmt.java @@ -24,7 +24,6 @@ import org.apache.doris.catalog.PartitionType; import org.apache.doris.catalog.TableIf; import org.apache.doris.common.AnalysisException; -import org.apache.doris.common.Config; import org.apache.doris.common.ErrorCode; import org.apache.doris.common.ErrorReport; import org.apache.doris.common.FeNameFormat; @@ -107,7 +106,7 @@ public Map getStatsTypeToValue() { @Override public void analyze(Analyzer analyzer) throws UserException { - if (!Config.enable_stats) { + if (!ConnectContext.get().getSessionVariable().enableStats) { throw new UserException("Analyze function is forbidden, you should add `enable_stats=true`" + "in your FE conf file"); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStatsStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStatsStmt.java index d17b934fadfb0d..b56140ee099884 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStatsStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AlterTableStatsStmt.java @@ -21,7 +21,6 @@ import org.apache.doris.catalog.Env; import org.apache.doris.catalog.Table; import org.apache.doris.common.AnalysisException; -import org.apache.doris.common.Config; import org.apache.doris.common.ErrorCode; import org.apache.doris.common.ErrorReport; import org.apache.doris.common.UserException; @@ -71,7 +70,7 @@ public TableName getTableName() { @Override public void analyze(Analyzer analyzer) throws UserException { - if (!Config.enable_stats) { + if (!ConnectContext.get().getSessionVariable().enableStats) { throw new UserException("Analyze function is forbidden, you should add `enable_stats=true`" + "in your FE conf file"); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyzeTblStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyzeTblStmt.java index 8329d2c451ab8b..2c9abe94c782c1 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyzeTblStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyzeTblStmt.java @@ -26,7 +26,6 @@ import org.apache.doris.catalog.external.ExternalTable; import org.apache.doris.catalog.external.HMSExternalTable; import org.apache.doris.common.AnalysisException; -import org.apache.doris.common.Config; import org.apache.doris.common.ErrorCode; import org.apache.doris.common.ErrorReport; import org.apache.doris.common.FeNameFormat; @@ -118,7 +117,7 @@ public AnalyzeTblStmt(AnalyzeProperties analyzeProperties, TableName tableName, @Override @SuppressWarnings({"rawtypes"}) public void analyze(Analyzer analyzer) throws UserException { - if (!Config.enable_stats) { + if (!ConnectContext.get().getSessionVariable().enableStats) { throw new UserException("Analyze function is forbidden, you should add `enable_stats=true`" + "in your FE conf file"); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/DropStatsStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/DropStatsStmt.java index aa80f664dc32ec..ac08f01f31e70e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DropStatsStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DropStatsStmt.java @@ -22,7 +22,6 @@ import org.apache.doris.catalog.Env; import org.apache.doris.catalog.TableIf; import org.apache.doris.common.AnalysisException; -import org.apache.doris.common.Config; import org.apache.doris.common.ErrorCode; import org.apache.doris.common.ErrorReport; import org.apache.doris.common.UserException; @@ -80,7 +79,7 @@ public DropStatsStmt(TableName tableName, @Override public void analyze(Analyzer analyzer) throws UserException { - if (!Config.enable_stats) { + if (!ConnectContext.get().getSessionVariable().enableStats) { throw new UserException("Analyze function is forbidden, you should add `enable_stats=true`" + "in your FE conf file"); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowAnalyzeStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowAnalyzeStmt.java index 07c3029ee04df6..5e3622ff6c04bb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowAnalyzeStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowAnalyzeStmt.java @@ -21,7 +21,6 @@ import org.apache.doris.catalog.Env; import org.apache.doris.catalog.ScalarType; import org.apache.doris.common.AnalysisException; -import org.apache.doris.common.Config; import org.apache.doris.common.ErrorCode; import org.apache.doris.common.ErrorReport; import org.apache.doris.common.UserException; @@ -109,7 +108,7 @@ public Expr getWhereClause() { @Override public void analyze(Analyzer analyzer) throws UserException { - if (!Config.enable_stats) { + if (!ConnectContext.get().getSessionVariable().enableStats) { throw new UserException("Analyze function is forbidden, you should add `enable_stats=true`" + "in your FE conf file"); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowAnalyzeTaskStatus.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowAnalyzeTaskStatus.java index 7c6c5cf17feb2d..e5e5cde7344635 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowAnalyzeTaskStatus.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowAnalyzeTaskStatus.java @@ -19,8 +19,8 @@ import org.apache.doris.catalog.Column; import org.apache.doris.catalog.ScalarType; -import org.apache.doris.common.Config; import org.apache.doris.common.UserException; +import org.apache.doris.qe.ConnectContext; import org.apache.doris.qe.ShowResultSetMetaData; /** @@ -45,7 +45,7 @@ public ShowAnalyzeTaskStatus(long jobId) { @Override public void analyze(Analyzer analyzer) throws UserException { - if (!Config.enable_stats) { + if (!ConnectContext.get().getSessionVariable().enableStats) { throw new UserException("Analyze function is forbidden, you should add `enable_stats=true`" + "in your FE conf file"); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/minidump/MinidumpUtils.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/minidump/MinidumpUtils.java index aaef4df13347eb..44e14b4c8cdde4 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/minidump/MinidumpUtils.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/minidump/MinidumpUtils.java @@ -23,7 +23,6 @@ import org.apache.doris.catalog.OlapTable; import org.apache.doris.catalog.SchemaTable; import org.apache.doris.catalog.TableIf; -import org.apache.doris.common.Config; import org.apache.doris.common.util.DebugUtil; import org.apache.doris.nereids.NereidsPlanner; import org.apache.doris.nereids.StatementContext; @@ -262,7 +261,8 @@ private static void serializeStatsUsed(JSONObject jsonObj, List tables) for (Column column : columns) { String colName = column.getName(); ColumnStatistic cache = - Config.enable_stats ? getColumnStatistic(table, colName) : ColumnStatistic.UNKNOWN; + ConnectContext.get().getSessionVariable().enableStats + ? getColumnStatistic(table, colName) : ColumnStatistic.UNKNOWN; if (cache.avgSizeByte <= 0) { cache = new ColumnStatisticBuilder(cache) .setAvgSizeByte(column.getType().getSlotSize()) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java index 4aeba03eba31cb..a219cdb1c6bdf9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/stats/StatsCalculator.java @@ -22,7 +22,6 @@ import org.apache.doris.catalog.OlapTable; import org.apache.doris.catalog.PartitionType; import org.apache.doris.catalog.TableIf; -import org.apache.doris.common.Config; import org.apache.doris.common.FeConstants; import org.apache.doris.common.Pair; import org.apache.doris.nereids.CascadesContext; @@ -116,6 +115,7 @@ import org.apache.doris.nereids.trees.plans.physical.PhysicalWindow; import org.apache.doris.nereids.trees.plans.visitor.DefaultPlanVisitor; import org.apache.doris.nereids.types.DataType; +import org.apache.doris.qe.ConnectContext; import org.apache.doris.statistics.ColumnStatistic; import org.apache.doris.statistics.ColumnStatisticBuilder; import org.apache.doris.statistics.Histogram; @@ -631,7 +631,8 @@ private Statistics computeCatalogRelation(CatalogRelation catalogRelation) { if (colName == null) { throw new RuntimeException(String.format("Invalid slot: %s", slotReference.getExprId())); } - ColumnStatistic cache = Config.enable_stats && FeConstants.enableInternalSchemaDb + ColumnStatistic cache = ConnectContext.get().getSessionVariable().enableStats + && FeConstants.enableInternalSchemaDb ? shouldIgnoreThisCol ? ColumnStatistic.UNKNOWN : getColumnStatistic(table, colName) : ColumnStatistic.UNKNOWN; if (cache.avgSizeByte <= 0) { 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 4f0390799726f2..e5047953ab054e 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 @@ -431,6 +431,13 @@ public class SessionVariable implements Serializable, Writable { SHOW_HIDDEN_COLUMNS ); + public static final String ENABLE_STATS = "enable_stats"; + /** + * If set false, user couldn't submit analyze SQL and FE won't allocate any related resources. + */ + @VariableMgr.VarAttr(name = ENABLE_STATS) + public boolean enableStats = true; + // session origin value public Map sessionOriginValue = new HashMap(); // check stmt is or not [select /*+ SET_VAR(...)*/ ...]