Skip to content

Commit

Permalink
make enable_stats session var
Browse files Browse the repository at this point in the history
  • Loading branch information
englefly committed Oct 17, 2023
1 parent 18c2a13 commit 6d323b8
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -107,7 +106,7 @@ public Map<StatsType, String> 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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -262,7 +261,8 @@ private static void serializeStatsUsed(JSONObject jsonObj, List<TableIf> 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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Field, String> sessionOriginValue = new HashMap<Field, String>();
// check stmt is or not [select /*+ SET_VAR(...)*/ ...]
Expand Down

0 comments on commit 6d323b8

Please sign in to comment.