[Optimize] optimize some session variable and profile (#6920)

1. optimize error message when using batch delete
2. rename session variable is_report_success to enable_profile
3. add table name to OlapScanner profile
This commit is contained in:
Zhengguo Yang
2021-10-27 18:03:12 +08:00
committed by GitHub
parent a4a7e642b4
commit 4170aabf83
22 changed files with 70 additions and 44 deletions

View File

@ -810,7 +810,13 @@ public class SchemaChangeHandler extends AlterHandler {
}
}
if (found) {
throw new DdlException("Can not add column which already exists in base table: " + newColName);
if (newColName.equalsIgnoreCase(Column.DELETE_SIGN)) {
throw new DdlException("Can not enable batch delete support, already supported batch delete.");
} else if (newColName.equalsIgnoreCase(Column.SEQUENCE_COL)) {
throw new DdlException("Can not enable sequence column support, already supported sequence column.");
} else {
throw new DdlException("Can not add column which already exists in base table: " + newColName);
}
}
/*

View File

@ -129,23 +129,26 @@ public class SetVar {
}
}
if (getVariable().toLowerCase().equals("prefer_join_method")) {
if (getVariable().equalsIgnoreCase(SessionVariable.PREFER_JOIN_METHOD)) {
String value = getValue().getStringValue();
if (!value.toLowerCase().equals("broadcast") && !value.toLowerCase().equals("shuffle")) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_WRONG_VALUE_FOR_VAR, "prefer_join_method", value);
if (!value.equalsIgnoreCase("broadcast") && !value.equalsIgnoreCase("shuffle")) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_WRONG_VALUE_FOR_VAR, SessionVariable.PREFER_JOIN_METHOD, value);
}
}
// Check variable time_zone value is valid
if (getVariable().toLowerCase().equals("time_zone")) {
if (getVariable().equalsIgnoreCase(SessionVariable.TIME_ZONE)) {
this.value = new StringLiteral(TimeUtils.checkTimeZoneValidAndStandardize(getValue().getStringValue()));
this.result = (LiteralExpr) this.value;
}
if (getVariable().toLowerCase().equals("exec_mem_limit")) {
if (getVariable().equalsIgnoreCase(SessionVariable.EXEC_MEM_LIMIT)) {
this.value = new StringLiteral(Long.toString(ParseUtil.analyzeDataVolumn(getValue().getStringValue())));
this.result = (LiteralExpr) this.value;
}
if (getVariable().equalsIgnoreCase("is_report_success")) {
variable = SessionVariable.ENABLE_PROFILE;
}
}
public String toSql() {

View File

@ -1065,8 +1065,14 @@ public class Load {
for (SlotRef slot : slots) {
SlotDescriptor slotDesc = slotDescByName.get(slot.getColumnName());
if (slotDesc == null) {
throw new UserException("unknown reference column, column=" + entry.getKey()
+ ", reference=" + slot.getColumnName());
if (entry.getKey().equalsIgnoreCase(Column.DELETE_SIGN)) {
throw new UserException("unknown reference column in DELETE ON clause:" + slot.getColumnName());
} else if (entry.getKey().equalsIgnoreCase(Column.SEQUENCE_COL)) {
throw new UserException("unknown reference column in ORDER BY clause:" + slot.getColumnName());
} else {
throw new UserException("unknown reference column, column=" + entry.getKey()
+ ", reference=" + slot.getColumnName());
}
}
smap.getLhs().add(slot);
smap.getRhs().add(new SlotRef(slotDesc));
@ -1099,8 +1105,14 @@ public class Load {
smap.getRhs().add(new CastExpr(tbl.getColumn(slot.getColumnName()).getType(),
exprsByName.get(slot.getColumnName())));
} else {
throw new UserException("unknown reference column, column=" + entry.getKey()
+ ", reference=" + slot.getColumnName());
if (entry.getKey().equalsIgnoreCase(Column.DELETE_SIGN)) {
throw new UserException("unknown reference column in DELETE ON clause:" + slot.getColumnName());
} else if (entry.getKey().equalsIgnoreCase(Column.SEQUENCE_COL)) {
throw new UserException("unknown reference column in ORDER BY clause:" + slot.getColumnName());
} else {
throw new UserException("unknown reference column, column=" + entry.getKey()
+ ", reference=" + slot.getColumnName());
}
}
}
Expr expr = entry.getValue().clone(smap);

View File

@ -75,7 +75,7 @@ public class BrokerLoadJob extends BulkLoadJob {
// Profile of this load job, including all tasks' profiles
private RuntimeProfile jobProfile;
// If set to true, the profile of load job with be pushed to ProfileManager
private boolean isReportSuccess = false;
private boolean enableProfile = false;
// for log replay and unit test
public BrokerLoadJob() {
@ -87,8 +87,8 @@ public class BrokerLoadJob extends BulkLoadJob {
throws MetaNotFoundException {
super(EtlJobType.BROKER, dbId, label, originStmt, userInfo);
this.brokerDesc = brokerDesc;
if (ConnectContext.get() != null && ConnectContext.get().getSessionVariable().isReportSucc()) {
isReportSuccess = true;
if (ConnectContext.get() != null && ConnectContext.get().getSessionVariable().enableProfile()) {
enableProfile = true;
}
}
@ -199,7 +199,7 @@ public class BrokerLoadJob extends BulkLoadJob {
LoadLoadingTask task = new LoadLoadingTask(db, table, brokerDesc,
brokerFileGroups, getDeadlineMs(), getExecMemLimit(),
isStrictMode(), transactionId, this, getTimeZone(), getTimeout(),
getLoadParallelism(), getSendBatchParallelism(), isReportSuccess ? jobProfile : null);
getLoadParallelism(), getSendBatchParallelism(), enableProfile ? jobProfile : null);
UUID uuid = UUID.randomUUID();
TUniqueId loadId = new TUniqueId(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits());
task.init(loadId, attachment.getFileStatusByTable(aggKey),
@ -306,7 +306,7 @@ public class BrokerLoadJob extends BulkLoadJob {
}
private void writeProfile() {
if (!isReportSuccess) {
if (!enableProfile) {
return;
}

View File

@ -759,6 +759,7 @@ public class OlapScanNode extends ScanNode {
msg.olap_scan_node.setSortColumn(sortColumn);
}
msg.olap_scan_node.setKeyType(olapTable.getKeysType().toThrift());
msg.olap_scan_node.setTableName(olapTable.getName());
}
// export some tablets

View File

@ -239,7 +239,7 @@ public class Coordinator {
}
this.tResourceInfo = new TResourceInfo(context.getQualifiedUser(),
context.getSessionVariable().getResourceGroup());
this.needReport = context.getSessionVariable().isReportSucc();
this.needReport = context.getSessionVariable().enableProfile();
this.nextInstanceId = new TUniqueId();
nextInstanceId.setHi(queryId.hi);
nextInstanceId.setLo(queryId.lo + 1);

View File

@ -82,7 +82,6 @@ public final class GlobalVariable {
// Don't allow create instance.
private GlobalVariable() {
}
public static List<String> getPersistentGlobalVarNames() {

View File

@ -162,7 +162,7 @@ public final class QeProcessorImpl implements QeProcessor {
.db(context.getDatabase())
.fragmentInstanceInfos(info.getCoord().getFragmentInstanceInfos())
.profile(info.getCoord().getQueryProfile())
.isReportSucc(context.getSessionVariable().isReportSucc()).build();
.isReportSucc(context.getSessionVariable().enableProfile()).build();
querySet.put(queryIdStr, item);
}
return querySet;

View File

@ -45,7 +45,7 @@ public class SessionVariable implements Serializable, Writable {
public static final String EXEC_MEM_LIMIT = "exec_mem_limit";
public static final String QUERY_TIMEOUT = "query_timeout";
public static final String IS_REPORT_SUCCESS = "is_report_success";
public static final String ENABLE_PROFILE = "enable_profile";
public static final String SQL_MODE = "sql_mode";
public static final String RESOURCE_VARIABLE = "resource_group";
public static final String AUTO_COMMIT = "autocommit";
@ -186,8 +186,8 @@ public class SessionVariable implements Serializable, Writable {
public int queryTimeoutS = 300;
// if true, need report to coordinator when plan fragment execute successfully.
@VariableMgr.VarAttr(name = IS_REPORT_SUCCESS, needForward = true)
public boolean isReportSucc = false;
@VariableMgr.VarAttr(name = ENABLE_PROFILE, needForward = true)
public boolean enableProfile = false;
// Set sqlMode to empty string
@VariableMgr.VarAttr(name = SQL_MODE, needForward = true)
@ -396,8 +396,8 @@ public class SessionVariable implements Serializable, Writable {
return queryTimeoutS;
}
public boolean isReportSucc() {
return isReportSucc;
public boolean enableProfile() {
return enableProfile;
}
public int getWaitTimeoutS() {
@ -813,7 +813,7 @@ public class SessionVariable implements Serializable, Writable {
tResult.setBufferPoolLimit(maxExecMemByte);
tResult.setQueryTimeout(queryTimeoutS);
tResult.setIsReportSuccess(isReportSucc);
tResult.setIsReportSuccess(enableProfile);
tResult.setCodegenLevel(codegenLevel);
tResult.setEnableVectorizedEngine(enableVectorizedEngine);
@ -913,7 +913,7 @@ public class SessionVariable implements Serializable, Writable {
Text.readString(in);
sqlMode = 0L;
}
isReportSucc = in.readBoolean();
enableProfile = in.readBoolean();
queryTimeoutS = in.readInt();
maxExecMemByte = in.readLong();
if (Catalog.getCurrentCatalogJournalVersion() >= FeMetaVersion.VERSION_37) {

View File

@ -465,7 +465,7 @@ public class StmtExecutor implements ProfileWriter {
@Override
public void writeProfile(boolean isLastWriteProfile) {
if (!context.getSessionVariable().isReportSucc()) {
if (!context.getSessionVariable().enableProfile()) {
return;
}
synchronized (writeProfileLock) {

View File

@ -51,9 +51,9 @@ public class SessionVariablesTest {
Assert.assertTrue(numOfForwardVars >= 6);
Assert.assertEquals(numOfForwardVars, vars.size());
vars.put(SessionVariable.IS_REPORT_SUCCESS, "true");
vars.put(SessionVariable.ENABLE_PROFILE, "true");
sessionVariable.setForwardedSessionVariables(vars);
Assert.assertEquals(true, sessionVariable.isReportSucc);
Assert.assertEquals(true, sessionVariable.enableProfile);
}
@Test

View File

@ -85,7 +85,7 @@ public class VariableMgrTest {
SessionVariable var = VariableMgr.newSessionVariable();
Assert.assertEquals(2147483648L, var.getMaxExecMemByte());
Assert.assertEquals(300, var.getQueryTimeoutS());
Assert.assertEquals(false, var.isReportSucc());
Assert.assertEquals(false, var.enableProfile());
Assert.assertEquals(0L, var.getSqlMode());
List<List<String>> rows = VariableMgr.dump(SetType.SESSION, var, null);