[Improvement](statistics)Improve statistics user experience (#24414)
Two improvements: 1. Move the `Job_id` column for the return info of `Analyze table` command to the first column. To keep consistent with `show analyze`. ``` mysql> analyze table hive.tpch100.region; +--------+--------------+-------------------------+------------+--------------------------------+ | Job_Id | Catalog_Name | DB_Name | Table_Name | Columns | +--------+--------------+-------------------------+------------+--------------------------------+ | 14403 | hive | default_cluster:tpch100 | region | [r_regionkey,r_comment,r_name] | +--------+--------------+-------------------------+------------+--------------------------------+ 1 row in set (0.03 sec) ``` 2. Add `analyze_timeout` session variable, to control `analyze table/database with sync` timeout.
This commit is contained in:
@ -742,6 +742,8 @@ public class ConnectContext {
|
||||
if (executor != null && executor.isInsertStmt()) {
|
||||
// particular for insert stmt, we can expand other type of timeout in the same way
|
||||
return Math.max(sessionVariable.getInsertTimeoutS(), sessionVariable.getQueryTimeoutS());
|
||||
} else if (executor != null && executor.isAnalyzeStmt()) {
|
||||
return sessionVariable.getAnalyzeTimeoutS();
|
||||
} else {
|
||||
// normal query stmt
|
||||
return sessionVariable.getQueryTimeoutS();
|
||||
|
||||
@ -68,6 +68,7 @@ public class SessionVariable implements Serializable, Writable {
|
||||
public static final String EXEC_MEM_LIMIT = "exec_mem_limit";
|
||||
public static final String SCAN_QUEUE_MEM_LIMIT = "scan_queue_mem_limit";
|
||||
public static final String QUERY_TIMEOUT = "query_timeout";
|
||||
public static final String ANALYZE_TIMEOUT = "analyze_timeout";
|
||||
|
||||
public static final String MAX_EXECUTION_TIME = "max_execution_time";
|
||||
public static final String INSERT_TIMEOUT = "insert_timeout";
|
||||
@ -453,6 +454,10 @@ public class SessionVariable implements Serializable, Writable {
|
||||
@VariableMgr.VarAttr(name = QUERY_TIMEOUT)
|
||||
public int queryTimeoutS = 900;
|
||||
|
||||
// query timeout in second.
|
||||
@VariableMgr.VarAttr(name = ANALYZE_TIMEOUT, needForward = true)
|
||||
public int analyzeTimeoutS = 43200;
|
||||
|
||||
// The global max_execution_time value provides the default for the session value for new connections.
|
||||
// The session value applies to SELECT executions executed within the session that include
|
||||
// no MAX_EXECUTION_TIME(N) optimizer hint or for which N is 0.
|
||||
@ -1373,6 +1378,10 @@ public class SessionVariable implements Serializable, Writable {
|
||||
return queryTimeoutS;
|
||||
}
|
||||
|
||||
public int getAnalyzeTimeoutS() {
|
||||
return analyzeTimeoutS;
|
||||
}
|
||||
|
||||
public void setEnableTwoPhaseReadOpt(boolean enable) {
|
||||
enableTwoPhaseReadOpt = enable;
|
||||
}
|
||||
@ -1552,6 +1561,10 @@ public class SessionVariable implements Serializable, Writable {
|
||||
this.queryTimeoutS = queryTimeoutS;
|
||||
}
|
||||
|
||||
public void setAnalyzeTimeoutS(int analyzeTimeoutS) {
|
||||
this.analyzeTimeoutS = analyzeTimeoutS;
|
||||
}
|
||||
|
||||
public void setMaxExecutionTimeMS(int maxExecutionTimeMS) {
|
||||
this.maxExecutionTimeMS = maxExecutionTimeMS;
|
||||
this.queryTimeoutS = this.maxExecutionTimeMS / 1000;
|
||||
@ -2486,6 +2499,9 @@ public class SessionVariable implements Serializable, Writable {
|
||||
if (queryOptions.isSetInsertTimeout()) {
|
||||
setInsertTimeoutS(queryOptions.getInsertTimeout());
|
||||
}
|
||||
if (queryOptions.isSetAnalyzeTimeout()) {
|
||||
setAnalyzeTimeoutS(queryOptions.getAnalyzeTimeout());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2497,6 +2513,7 @@ public class SessionVariable implements Serializable, Writable {
|
||||
queryOptions.setScanQueueMemLimit(Math.min(maxScanQueueMemByte, maxExecMemByte / 20));
|
||||
queryOptions.setQueryTimeout(queryTimeoutS);
|
||||
queryOptions.setInsertTimeout(insertTimeoutS);
|
||||
queryOptions.setAnalyzeTimeout(analyzeTimeoutS);
|
||||
return queryOptions;
|
||||
}
|
||||
|
||||
|
||||
@ -405,6 +405,13 @@ public class StmtExecutor {
|
||||
return parsedStmt instanceof InsertStmt;
|
||||
}
|
||||
|
||||
public boolean isAnalyzeStmt() {
|
||||
if (parsedStmt == null) {
|
||||
return false;
|
||||
}
|
||||
return parsedStmt instanceof AnalyzeStmt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used for audit in ConnectProcessor.
|
||||
* <p>
|
||||
|
||||
@ -384,11 +384,11 @@ public class AnalysisManager extends Daemon implements Writable {
|
||||
|
||||
private void sendJobId(List<AnalysisInfo> analysisInfos, boolean proxy) {
|
||||
List<Column> columns = new ArrayList<>();
|
||||
columns.add(new Column("Job_Id", ScalarType.createVarchar(19)));
|
||||
columns.add(new Column("Catalog_Name", ScalarType.createVarchar(1024)));
|
||||
columns.add(new Column("DB_Name", ScalarType.createVarchar(1024)));
|
||||
columns.add(new Column("Table_Name", ScalarType.createVarchar(1024)));
|
||||
columns.add(new Column("Columns", ScalarType.createVarchar(1024)));
|
||||
columns.add(new Column("Job_Id", ScalarType.createVarchar(19)));
|
||||
ShowResultSetMetaData commonResultSetMetaData = new ShowResultSetMetaData(columns);
|
||||
List<List<String>> resultRows = new ArrayList<>();
|
||||
for (AnalysisInfo analysisInfo : analysisInfos) {
|
||||
@ -396,11 +396,11 @@ public class AnalysisManager extends Daemon implements Writable {
|
||||
continue;
|
||||
}
|
||||
List<String> row = new ArrayList<>();
|
||||
row.add(String.valueOf(analysisInfo.jobId));
|
||||
row.add(analysisInfo.catalogName);
|
||||
row.add(analysisInfo.dbName);
|
||||
row.add(analysisInfo.tblName);
|
||||
row.add(analysisInfo.colName);
|
||||
row.add(String.valueOf(analysisInfo.jobId));
|
||||
resultRows.add(row);
|
||||
}
|
||||
ShowResultSet commonResultSet = new ShowResultSet(commonResultSetMetaData, resultRows);
|
||||
|
||||
Reference in New Issue
Block a user