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 ...@@ -21,6 +21,66 @@ Change Log
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul> <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>PR #1302: Use OpenJDK instead of OracleJDK 10 in Travis builds due to Travis problem
</li> </li>
<li>Issue #1032: Error when executing "SELECT DISTINCT ON" <li>Issue #1032: Error when executing "SELECT DISTINCT ON"
......
...@@ -43,20 +43,15 @@ public abstract class CommandWithColumns extends SchemaCommand { ...@@ -43,20 +43,15 @@ public abstract class CommandWithColumns extends SchemaCommand {
* the statement to add * the statement to add
*/ */
public void addConstraintCommand(DefineCommand command) { public void addConstraintCommand(DefineCommand command) {
if (command instanceof CreateIndex) { if (!(command instanceof CreateIndex)) {
getConstraintCommands().add(command);
} else {
AlterTableAddConstraint con = (AlterTableAddConstraint) command; AlterTableAddConstraint con = (AlterTableAddConstraint) command;
boolean alreadySet;
if (con.getType() == CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_PRIMARY_KEY) { if (con.getType() == CommandInterface.ALTER_TABLE_ADD_CONSTRAINT_PRIMARY_KEY) {
alreadySet = setPrimaryKey(con); if (setPrimaryKey(con)) {
} else { return;
alreadySet = false; }
}
if (!alreadySet) {
getConstraintCommands().add(command);
} }
} }
getConstraintCommands().add(command);
} }
/** /**
......
...@@ -451,83 +451,67 @@ public abstract class Query extends Prepared { ...@@ -451,83 +451,67 @@ public abstract class Query extends Prepared {
// (oracle supports it, but only in order by, not in group by and // (oracle supports it, but only in order by, not in group by and
// not in having): // not in having):
// SELECT 1 AS A FROM DUAL ORDER BY -A // SELECT 1 AS A FROM DUAL ORDER BY -A
boolean isAlias = false;
int idx = expressions.size();
if (e instanceof ExpressionColumn) { if (e instanceof ExpressionColumn) {
// order by expression // order by expression
ExpressionColumn exprCol = (ExpressionColumn) e; ExpressionColumn exprCol = (ExpressionColumn) e;
String tableAlias = exprCol.getOriginalTableAliasName(); String tableAlias = exprCol.getOriginalTableAliasName();
String col = exprCol.getOriginalColumnName(); String col = exprCol.getOriginalColumnName();
for (int j = 0; j < visible; j++) { for (int j = 0; j < visible; j++) {
boolean found = false;
Expression ec = expressions.get(j); Expression ec = expressions.get(j);
if (ec instanceof ExpressionColumn) { if (ec instanceof ExpressionColumn) {
// select expression // select expression
ExpressionColumn c = (ExpressionColumn) ec; ExpressionColumn c = (ExpressionColumn) ec;
found = db.equalsIdentifiers(col, c.getColumnName()); if (!db.equalsIdentifiers(col, c.getColumnName())) {
if (found && tableAlias != null) { continue;
String ca = c.getOriginalTableAliasName(); }
if (ca == null) { if (tableAlias == null) {
found = false; return j;
if (filters != null) { }
// select id from test order by test.id String ca = c.getOriginalTableAliasName();
for (TableFilter f : filters) { if (ca != null) {
if (db.equalsIdentifiers(f.getTableAlias(), tableAlias)) { if (db.equalsIdentifiers(ca, tableAlias)) {
found = true; return j;
break; }
} } 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)) { } else if (ec instanceof Alias) {
continue; if (tableAlias == null && db.equalsIdentifiers(col, ec.getAlias())) {
} else if (tableAlias == null && db.equalsIdentifiers(col, ec.getAlias())) { return j;
found = true; }
} else {
Expression ec2 = ec.getNonAliasExpression(); Expression ec2 = ec.getNonAliasExpression();
if (ec2 instanceof ExpressionColumn) { if (ec2 instanceof ExpressionColumn) {
ExpressionColumn c2 = (ExpressionColumn) ec2; ExpressionColumn c2 = (ExpressionColumn) ec2;
String ta = exprCol.getSQL(); String ta = exprCol.getSQL();
String tb = c2.getSQL(); String tb = c2.getSQL();
String s2 = c2.getColumnName(); String s2 = c2.getColumnName();
found = db.equalsIdentifiers(col, s2); if (db.equalsIdentifiers(col, s2) && db.equalsIdentifiers(ta, tb)) {
if (!db.equalsIdentifiers(ta, tb)) { return j;
found = false;
} }
} }
} }
if (found) {
idx = j;
isAlias = true;
break;
}
} }
} else { } else if (expressionSQL != null) {
String s = e.getSQL(); String s = e.getSQL();
if (expressionSQL != null) { for (int j = 0, size = expressionSQL.size(); j < size; j++) {
for (int j = 0, size = expressionSQL.size(); j < size; j++) { if (db.equalsIdentifiers(expressionSQL.get(j), s)) {
String s2 = expressionSQL.get(j); return j;
if (db.equalsIdentifiers(s2, s)) {
idx = j;
isAlias = true;
break;
}
} }
} }
} }
if (!isAlias) { if (expressionSQL == null
if (expressionSQL == null || mustBeInResult && session.getDatabase().getMode().getEnum() != ModeEnum.MySQL
|| mustBeInResult && session.getDatabase().getMode().getEnum() != ModeEnum.MySQL && !checkOrderOther(session, e, expressionSQL)) {
&& !checkOrderOther(session, e, expressionSQL)) { throw DbException.get(ErrorCode.ORDER_BY_NOT_IN_RESULT, e.getSQL());
throw DbException.get(ErrorCode.ORDER_BY_NOT_IN_RESULT, e.getSQL());
}
expressions.add(e);
String sql = e.getSQL();
expressionSQL.add(sql);
} }
int idx = expressions.size();
expressions.add(e);
expressionSQL.add(e.getSQL());
return idx; return idx;
} }
......
...@@ -514,11 +514,11 @@ public abstract class Value { ...@@ -514,11 +514,11 @@ public abstract class Value {
* @return the result * @return the result
*/ */
public Value add(@SuppressWarnings("unused") Value v) { public Value add(@SuppressWarnings("unused") Value v) {
throw throwUnsupportedExceptionForType("+"); throw getUnsupportedExceptionForOperation("+");
} }
public int getSignum() { public int getSignum() {
throw throwUnsupportedExceptionForType("SIGNUM"); throw getUnsupportedExceptionForOperation("SIGNUM");
} }
/** /**
...@@ -527,7 +527,7 @@ public abstract class Value { ...@@ -527,7 +527,7 @@ public abstract class Value {
* @return the negative * @return the negative
*/ */
public Value negate() { public Value negate() {
throw throwUnsupportedExceptionForType("NEG"); throw getUnsupportedExceptionForOperation("NEG");
} }
/** /**
...@@ -537,7 +537,7 @@ public abstract class Value { ...@@ -537,7 +537,7 @@ public abstract class Value {
* @return the result * @return the result
*/ */
public Value subtract(@SuppressWarnings("unused") Value v) { public Value subtract(@SuppressWarnings("unused") Value v) {
throw throwUnsupportedExceptionForType("-"); throw getUnsupportedExceptionForOperation("-");
} }
/** /**
...@@ -547,7 +547,7 @@ public abstract class Value { ...@@ -547,7 +547,7 @@ public abstract class Value {
* @return the result * @return the result
*/ */
public Value divide(@SuppressWarnings("unused") Value v) { public Value divide(@SuppressWarnings("unused") Value v) {
throw throwUnsupportedExceptionForType("/"); throw getUnsupportedExceptionForOperation("/");
} }
/** /**
...@@ -557,7 +557,7 @@ public abstract class Value { ...@@ -557,7 +557,7 @@ public abstract class Value {
* @return the result * @return the result
*/ */
public Value multiply(@SuppressWarnings("unused") Value v) { public Value multiply(@SuppressWarnings("unused") Value v) {
throw throwUnsupportedExceptionForType("*"); throw getUnsupportedExceptionForOperation("*");
} }
/** /**
...@@ -567,7 +567,7 @@ public abstract class Value { ...@@ -567,7 +567,7 @@ public abstract class Value {
* @return the result * @return the result
*/ */
public Value modulus(@SuppressWarnings("unused") Value v) { public Value modulus(@SuppressWarnings("unused") Value v) {
throw throwUnsupportedExceptionForType("%"); throw getUnsupportedExceptionForOperation("%");
} }
/** /**
...@@ -754,7 +754,7 @@ public abstract class Value { ...@@ -754,7 +754,7 @@ public abstract class Value {
case DECIMAL: { case DECIMAL: {
switch (getType()) { switch (getType()) {
case BOOLEAN: case BOOLEAN:
return ValueDecimal.get(BigDecimal.valueOf(getBoolean() ? 1 : 0)); return (ValueDecimal) (getBoolean() ? ValueDecimal.ONE : ValueDecimal.ZERO);
case BYTE: case BYTE:
case SHORT: case SHORT:
case ENUM: case ENUM:
...@@ -1320,15 +1320,14 @@ public abstract class Value { ...@@ -1320,15 +1320,14 @@ public abstract class Value {
} }
/** /**
* Throw the exception that the feature is not support for the given data * Create an exception meaning the specified operation is not supported for
* type. * this data type.
* *
* @param op the operation * @param op the operation
* @return never returns normally * @return the exception
* @throws DbException the exception
*/ */
protected DbException throwUnsupportedExceptionForType(String op) { protected final DbException getUnsupportedExceptionForOperation(String op) {
throw DbException.getUnsupportedException( return DbException.getUnsupportedException(
DataType.getDataType(getType()).name + " " + op); DataType.getDataType(getType()).name + " " + op);
} }
......
...@@ -142,7 +142,7 @@ public class ValueResultSet extends Value { ...@@ -142,7 +142,7 @@ public class ValueResultSet extends Value {
@Override @Override
public void set(PreparedStatement prep, int parameterIndex) { public void set(PreparedStatement prep, int parameterIndex) {
throw throwUnsupportedExceptionForType("PreparedStatement.set"); throw getUnsupportedExceptionForOperation("PreparedStatement.set");
} }
@Override @Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论