Skip to content

Commit

Permalink
Merge pull request #3885 from katzyn/merge
Browse files Browse the repository at this point in the history
Don't throw incorrect CONCURRENT_UPDATE_1 exceptions from MERGE INTO
  • Loading branch information
katzyn committed Sep 2, 2023
2 parents 53854b1 + daa0d4a commit 4daeb2b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 2 additions & 0 deletions h2/src/docsrc/html/changelog.html
Expand Up @@ -21,6 +21,8 @@ <h1>Change Log</h1>

<h2>Next Version (unreleased)</h2>
<ul>
<li>Issue #2834: MERGE INTO fails with an error "Timeout trying to lock table"
</li>
<li>Issue #3883: Performance regression in 2.2.222
</li>
<li>PR #3879: Require Java 11
Expand Down
19 changes: 18 additions & 1 deletion h2/src/main/org/h2/command/dml/Merge.java
Expand Up @@ -29,6 +29,8 @@
import org.h2.table.DataChangeDeltaTable.ResultOption;
import org.h2.table.Table;
import org.h2.util.HasSQL;
import org.h2.value.DataType;
import org.h2.value.TypeInfo;
import org.h2.value.Value;
import org.h2.value.ValueNull;

Expand Down Expand Up @@ -170,7 +172,22 @@ private int merge(Row row, Expression[] expressions, ResultTarget deltaChangeCol
if (v == null) {
throw DbException.get(ErrorCode.COLUMN_CONTAINS_NULL_VALUES_1, col.getTraceSQL());
}
k.get(j++).setValue(v);
TypeInfo colType = col.getType();
check: {
TypeInfo rightType = v.getType();
if (session.getMode().numericWithBooleanComparison) {
int lValueType = colType.getValueType();
if (lValueType == Value.BOOLEAN) {
if (DataType.isNumericType(rightType.getValueType())) {
break check;
}
} else if (DataType.isNumericType(lValueType) && rightType.getValueType() == Value.BOOLEAN) {
break check;
}
}
TypeInfo.checkComparable(colType, rightType);
}
k.get(j++).setValue(v.convertForAssignTo(colType, session, col));
}
count = update.update(deltaChangeCollector, deltaChangeCollectionMode);
}
Expand Down
21 changes: 21 additions & 0 deletions h2/src/test/org/h2/test/scripts/dml/merge.sql
Expand Up @@ -159,3 +159,24 @@ MERGE INTO TEST(G) KEY(ID) VALUES (1);

DROP TABLE TEST;
> ok

CREATE TABLE T(ID BOOLEAN PRIMARY KEY);
> ok

INSERT INTO T(ID) VALUES (TRUE);
> update count: 1

MERGE INTO T(ID) VALUES 2;
> exception TYPES_ARE_NOT_COMPARABLE_2

SET MODE MySQL;
> ok

MERGE INTO T(ID) VALUES 2;
> update count: 1

SET MODE Regular;
> ok

DROP TABLE T;
> ok

0 comments on commit 4daeb2b

Please sign in to comment.