Unverified 提交 0c1e2a39 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1357 from katzyn/misc

Simplify execution flow in some places
......@@ -21,6 +21,66 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>PR #1357: Simplify execution flow in some places
</li>
<li>PR #1356: Fix NPE in Query.initExpression()
</li>
<li>PR #1355: Assorted changes in MetaTable
</li>
<li>Issue #1352: TestCrashAPI: Prepared.getObjectId() was called before
</li>
<li>PR #1349: Changes is conversion and comparison methods of Value
</li>
<li>Issue #1346: Exception when using IN condition for enums
</li>
<li>PR #1345: Replace some init methods with constructors
</li>
<li>PR #1344: Streamline last chunk verification on startup
</li>
<li>PR #1341: Optimize MVSecondaryIndex.convertToKey()
</li>
<li>PR #1340: NoSuchElementException instead of returning null
</li>
<li>PR #1339: Add support of TIMESTAMP WITH TIME ZONE to addition and subtraction operators
</li>
<li>PR #1337: Streamline Value comparison
</li>
<li>PR #1336: Minor refactorings
</li>
<li>Issue #1332: Constraint name not set correctly
</li>
<li>Rename fields to reflect actual type
</li>
<li>Issue #1331: Regression in Database.updateMeta()
</li>
<li>Issue #1323: Slow update after altering table in 1.4.197
</li>
<li>PR #1326: Add support of PERCENT in FETCH and TOP clauses
</li>
<li>PR #1325: Optimize WITH TIES in some queries and specify data types for KEY_COLUMN_USAGE
</li>
<li>PR #1321: Do not add rows before OFFSET to result if possible
</li>
<li>PR #1319: Treat NEXTVAL as an auto-generated key
</li>
<li>PR #1318: Mode append fo MVPlainTempResult
</li>
<li>PR #1314: Add ALTER VIEW RENAME command
</li>
<li>PR #1313, issue #1315: Bugfix - using default locale encoding issue in conversion between varchar and varbinary value, and checking javac output text issue in SourceCompiler
</li>
<li>PR #1312: Add Java 9+ support to NIO_CLEANER_HACK
</li>
<li>PR #1311: Fix minor issues with ResultSet.getObject(..., Class) and WITH TIES
</li>
<li>Issue #1298: TestKillRestartMulti: A map named undoLog.2 already exists
</li>
<li>Issue #1307: Invalid value "null" for parameter "calendar" [90008-193]
</li>
<li>PR #1306: Add initial implementation of WITH TIES clause
</li>
<li>PR #1304: Update changelog and fix building of documentation
</li>
<li>PR #1302: Use OpenJDK instead of OracleJDK 10 in Travis builds due to Travis problem
</li>
<li>Issue #1032: Error when executing "SELECT DISTINCT ON"
......
......@@ -43,20 +43,15 @@ public abstract class CommandWithColumns extends SchemaCommand {
* the statement to add
*/
public void addConstraintCommand(DefineCommand command) {
if (command instanceof CreateIndex) {
getConstraintCommands().add(command);
} else {
if (!(command instanceof CreateIndex)) {
AlterTableAddConstraint con = (AlterTableAddConstraint) command;
boolean alreadySet;
if (con.getType() == CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_PRIMARY_KEY) {
alreadySet = setPrimaryKey(con);
} else {
alreadySet = false;
}
if (!alreadySet) {
getConstraintCommands().add(command);
if (setPrimaryKey(con)) {
return;
}
}
}
getConstraintCommands().add(command);
}
/**
......
......@@ -451,83 +451,67 @@ public abstract class Query extends Prepared {
// (oracle supports it, but only in order by, not in group by and
// not in having):
// SELECT 1 AS A FROM DUAL ORDER BY -A
boolean isAlias = false;
int idx = expressions.size();
if (e instanceof ExpressionColumn) {
// order by expression
ExpressionColumn exprCol = (ExpressionColumn) e;
String tableAlias = exprCol.getOriginalTableAliasName();
String col = exprCol.getOriginalColumnName();
for (int j = 0; j < visible; j++) {
boolean found = false;
Expression ec = expressions.get(j);
if (ec instanceof ExpressionColumn) {
// select expression
ExpressionColumn c = (ExpressionColumn) ec;
found = db.equalsIdentifiers(col, c.getColumnName());
if (found && tableAlias != null) {
String ca = c.getOriginalTableAliasName();
if (ca == null) {
found = false;
if (filters != null) {
// select id from test order by test.id
for (TableFilter f : filters) {
if (db.equalsIdentifiers(f.getTableAlias(), tableAlias)) {
found = true;
break;
}
}
if (!db.equalsIdentifiers(col, c.getColumnName())) {
continue;
}
if (tableAlias == null) {
return j;
}
String ca = c.getOriginalTableAliasName();
if (ca != null) {
if (db.equalsIdentifiers(ca, tableAlias)) {
return j;
}
} else if (filters != null) {
// select id from test order by test.id
for (TableFilter f : filters) {
if (db.equalsIdentifiers(f.getTableAlias(), tableAlias)) {
return j;
}
} else {
found = db.equalsIdentifiers(ca, tableAlias);
}
}
} else if (!(ec instanceof Alias)) {
continue;
} else if (tableAlias == null && db.equalsIdentifiers(col, ec.getAlias())) {
found = true;
} else {
} else if (ec instanceof Alias) {
if (tableAlias == null && db.equalsIdentifiers(col, ec.getAlias())) {
return j;
}
Expression ec2 = ec.getNonAliasExpression();
if (ec2 instanceof ExpressionColumn) {
ExpressionColumn c2 = (ExpressionColumn) ec2;
String ta = exprCol.getSQL();
String tb = c2.getSQL();
String s2 = c2.getColumnName();
found = db.equalsIdentifiers(col, s2);
if (!db.equalsIdentifiers(ta, tb)) {
found = false;
if (db.equalsIdentifiers(col, s2) && db.equalsIdentifiers(ta, tb)) {
return j;
}
}
}
if (found) {
idx = j;
isAlias = true;
break;
}
}
} else {
} else if (expressionSQL != null) {
String s = e.getSQL();
if (expressionSQL != null) {
for (int j = 0, size = expressionSQL.size(); j < size; j++) {
String s2 = expressionSQL.get(j);
if (db.equalsIdentifiers(s2, s)) {
idx = j;
isAlias = true;
break;
}
for (int j = 0, size = expressionSQL.size(); j < size; j++) {
if (db.equalsIdentifiers(expressionSQL.get(j), s)) {
return j;
}
}
}
if (!isAlias) {
if (expressionSQL == null
|| mustBeInResult && session.getDatabase().getMode().getEnum() != ModeEnum.MySQL
&& !checkOrderOther(session, e, expressionSQL)) {
throw DbException.get(ErrorCode.ORDER_BY_NOT_IN_RESULT, e.getSQL());
}
expressions.add(e);
String sql = e.getSQL();
expressionSQL.add(sql);
if (expressionSQL == null
|| mustBeInResult && session.getDatabase().getMode().getEnum() != ModeEnum.MySQL
&& !checkOrderOther(session, e, expressionSQL)) {
throw DbException.get(ErrorCode.ORDER_BY_NOT_IN_RESULT, e.getSQL());
}
int idx = expressions.size();
expressions.add(e);
expressionSQL.add(e.getSQL());
return idx;
}
......
......@@ -514,11 +514,11 @@ public abstract class Value {
* @return the result
*/
public Value add(@SuppressWarnings("unused") Value v) {
throw throwUnsupportedExceptionForType("+");
throw getUnsupportedExceptionForOperation("+");
}
public int getSignum() {
throw throwUnsupportedExceptionForType("SIGNUM");
throw getUnsupportedExceptionForOperation("SIGNUM");
}
/**
......@@ -527,7 +527,7 @@ public abstract class Value {
* @return the negative
*/
public Value negate() {
throw throwUnsupportedExceptionForType("NEG");
throw getUnsupportedExceptionForOperation("NEG");
}
/**
......@@ -537,7 +537,7 @@ public abstract class Value {
* @return the result
*/
public Value subtract(@SuppressWarnings("unused") Value v) {
throw throwUnsupportedExceptionForType("-");
throw getUnsupportedExceptionForOperation("-");
}
/**
......@@ -547,7 +547,7 @@ public abstract class Value {
* @return the result
*/
public Value divide(@SuppressWarnings("unused") Value v) {
throw throwUnsupportedExceptionForType("/");
throw getUnsupportedExceptionForOperation("/");
}
/**
......@@ -557,7 +557,7 @@ public abstract class Value {
* @return the result
*/
public Value multiply(@SuppressWarnings("unused") Value v) {
throw throwUnsupportedExceptionForType("*");
throw getUnsupportedExceptionForOperation("*");
}
/**
......@@ -567,7 +567,7 @@ public abstract class Value {
* @return the result
*/
public Value modulus(@SuppressWarnings("unused") Value v) {
throw throwUnsupportedExceptionForType("%");
throw getUnsupportedExceptionForOperation("%");
}
/**
......@@ -754,7 +754,7 @@ public abstract class Value {
case DECIMAL: {
switch (getType()) {
case BOOLEAN:
return ValueDecimal.get(BigDecimal.valueOf(getBoolean() ? 1 : 0));
return (ValueDecimal) (getBoolean() ? ValueDecimal.ONE : ValueDecimal.ZERO);
case BYTE:
case SHORT:
case ENUM:
......@@ -1320,15 +1320,14 @@ public abstract class Value {
}
/**
* Throw the exception that the feature is not support for the given data
* type.
* Create an exception meaning the specified operation is not supported for
* this data type.
*
* @param op the operation
* @return never returns normally
* @throws DbException the exception
* @return the exception
*/
protected DbException throwUnsupportedExceptionForType(String op) {
throw DbException.getUnsupportedException(
protected final DbException getUnsupportedExceptionForOperation(String op) {
return DbException.getUnsupportedException(
DataType.getDataType(getType()).name + " " + op);
}
......
......@@ -142,7 +142,7 @@ public class ValueResultSet extends Value {
@Override
public void set(PreparedStatement prep, int parameterIndex) {
throw throwUnsupportedExceptionForType("PreparedStatement.set");
throw getUnsupportedExceptionForOperation("PreparedStatement.set");
}
@Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论