提交 8cbe0522 编写于 作者: N Nikita Akilov

#11289 do not trigger transaction start in smart commit mode on explain statement

上级 21edbefe
......@@ -875,4 +875,12 @@ public class CommonUtils {
return radix > ch - 'A' + 10;
return false;
}
@NotNull
@SafeVarargs
public static <T> Set<T> unmodifiableSet(@NotNull T... vararg) {
Set<T> set = new HashSet<>(vararg.length * 4 / 3 + 1); //Adjusting to account for the default load factor
set.addAll(Arrays.asList(vararg));
return Collections.unmodifiableSet(set);
}
}
......@@ -36,6 +36,7 @@ import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCUtils;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLConstants;
import org.jkiss.dbeaver.model.sql.format.SQLFormatUtils;
import org.jkiss.utils.CommonUtils;
......@@ -250,7 +251,7 @@ public class DB2Utils {
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Verify EXPLAIN tables")) {
// First Check with given schema
try (JDBCCallableStatement stmtSP = session.prepareCall(CALL_INST_OBJ)) {
stmtSP.setString(1, "EXPLAIN"); // EXPLAIN
stmtSP.setString(1, SQLConstants.KEYWORD_EXPLAIN); // EXPLAIN
stmtSP.setString(2, "V"); // Verify
stmtSP.setString(3, ""); // Tablespace
stmtSP.setString(4, explainTableSchemaName); // Schema
......@@ -280,7 +281,7 @@ public class DB2Utils {
try (JDBCSession session = DBUtils.openMetaSession(monitor, dataSource, "Create EXPLAIN tables")) {
try (JDBCCallableStatement stmtSP = session.prepareCall(CALL_INST_OBJ)) {
stmtSP.setString(1, "EXPLAIN"); // EXPLAIN
stmtSP.setString(1, SQLConstants.KEYWORD_EXPLAIN); // EXPLAIN
stmtSP.setString(2, "C"); // Create
stmtSP.setString(3, tablespaceName); // Tablespace
stmtSP.setString(4, explainTableSchemaName); // Schema
......
......@@ -24,6 +24,7 @@ import org.jkiss.dbeaver.model.exec.jdbc.JDBCSession;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCDataSource;
import org.jkiss.dbeaver.model.impl.jdbc.JDBCSQLDialect;
import org.jkiss.dbeaver.model.impl.sql.BasicSQLDialect;
import org.jkiss.dbeaver.model.sql.SQLConstants;
import org.jkiss.dbeaver.model.sql.SQLDialect;
import org.jkiss.dbeaver.model.struct.DBSAttributeBase;
import org.jkiss.utils.ArrayUtils;
......@@ -41,7 +42,7 @@ class MySQLDialect extends JDBCSQLDialect {
new String[]{
"USE", "SHOW",
"CREATE", "ALTER", "DROP",
"EXPLAIN", "DESCRIBE", "DESC" }
SQLConstants.KEYWORD_EXPLAIN, "DESCRIBE", "DESC" }
);
private static final String[] ADVANCED_KEYWORDS = {
......@@ -120,7 +121,7 @@ class MySQLDialect extends JDBCSQLDialect {
this.setSupportsUnquotedMixedCase(lowerCaseTableNames != 2);
//addSQLKeyword("STATISTICS");
Collections.addAll(tableQueryWords, "EXPLAIN", "DESCRIBE", "DESC");
Collections.addAll(tableQueryWords, SQLConstants.KEYWORD_EXPLAIN, "DESCRIBE", "DESC");
addFunctions(Arrays.asList("SLEEP"));
for (String kw : ADVANCED_KEYWORDS) {
......
......@@ -48,6 +48,8 @@ public abstract class AbstractSQLDialect implements SQLDialect {
private static final String[] QUERY_KEYWORDS = new String[] { SQLConstants.KEYWORD_SELECT };
private static final String[] EXEC_KEYWORDS = new String[0];
private static final String[] DDL_KEYWORDS = new String[0];
private static final Collection<String> TRANSACTION_NON_MODIFYING_KEYWORDS =
CommonUtils.unmodifiableSet(SQLConstants.KEYWORD_SELECT, "SHOW", "USE", "SET", SQLConstants.KEYWORD_EXPLAIN);
public static final String[][] DEFAULT_IDENTIFIER_QUOTES = {{"\"", "\""}};
public static final String[][] DEFAULT_STRING_QUOTES = {{"'", "'"}};
......@@ -598,14 +600,7 @@ public abstract class AbstractSQLDialect implements SQLDialect {
if (getKeywordType(firstKeyword) != DBPKeywordType.KEYWORD) {
return false;
}
if (SQLConstants.KEYWORD_SELECT.equals(firstKeyword) ||
"SHOW".equals(firstKeyword) ||
"USE".equals(firstKeyword) ||
"SET".equals(firstKeyword))
{
return false;
}
return true;
return !TRANSACTION_NON_MODIFYING_KEYWORDS.contains(firstKeyword);
}
private static boolean containsKeyword(String[] keywords, String keyword) {
......
......@@ -52,9 +52,18 @@ public class BasicSQLDialect extends AbstractSQLDialect implements RelationalSQL
SQLConstants.BLOCK_END
}
};
protected static final String[] NON_TRANSACTIONAL_KEYWORDS = new String[]{
protected static final String[] NON_TRANSACTIONAL_KEYWORDS = {
SQLConstants.KEYWORD_SELECT,
"EXPLAIN", "DESCRIBE", "DESC", "USE", "SET", "COMMIT", "ROLLBACK"};
SQLConstants.KEYWORD_EXPLAIN,
"DESCRIBE",
"DESC",
"USE",
"SET",
SQLConstants.KEYWORD_COMMIT,
SQLConstants.KEYWORD_ROLLBACK
};
private static final String[] CORE_NON_TRANSACTIONAL_KEYWORDS = new String[]{
SQLConstants.KEYWORD_SELECT,
};
......
......@@ -65,6 +65,8 @@ public class SQLConstants {
public static final String KEYWORD_COMMIT = "COMMIT";
public static final String KEYWORD_ROLLBACK = "ROLLBACK";
public static final String KEYWORD_EXPLAIN = "EXPLAIN";
public static final String[] TABLE_KEYWORDS = {
KEYWORD_FROM,
KEYWORD_UPDATE,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册