提交 8e8bc2bc authored 作者: Noel Grandin's avatar Noel Grandin

issue#1787: Non-standard MERGE throws LOCK_TIMEOUT_1

the match-index-to-key logic was wrong when there are more key columns than index columns
上级 6801c1e5
...@@ -182,14 +182,17 @@ public class Merge extends CommandWithValues { ...@@ -182,14 +182,17 @@ public class Merge extends CommandWithValues {
if (index != null) { if (index != null) {
// verify the index columns match the key // verify the index columns match the key
Column[] indexColumns = index.getColumns(); Column[] indexColumns = index.getColumns();
boolean indexMatchesKeys = true; boolean indexMatchesKeys;
if (indexColumns.length <= keys.length) { if (indexColumns.length <= keys.length) {
indexMatchesKeys = true;
for (int i = 0; i < indexColumns.length; i++) { for (int i = 0; i < indexColumns.length; i++) {
if (indexColumns[i] != keys[i]) { if (indexColumns[i] != keys[i]) {
indexMatchesKeys = false; indexMatchesKeys = false;
break; break;
} }
} }
} else {
indexMatchesKeys = false;
} }
if (indexMatchesKeys) { if (indexMatchesKeys) {
throw DbException.get(ErrorCode.CONCURRENT_UPDATE_1, targetTable.getName()); throw DbException.get(ErrorCode.CONCURRENT_UPDATE_1, targetTable.getName());
......
...@@ -46,13 +46,13 @@ EXPLAIN MERGE INTO TEST(ID, NAME) KEY(ID) VALUES(3, 'How do you do'); ...@@ -46,13 +46,13 @@ EXPLAIN MERGE INTO TEST(ID, NAME) KEY(ID) VALUES(3, 'How do you do');
>> MERGE INTO PUBLIC.TEST(ID, NAME) KEY(ID) VALUES (3, 'How do you do') >> MERGE INTO PUBLIC.TEST(ID, NAME) KEY(ID) VALUES (3, 'How do you do')
MERGE INTO TEST(ID, NAME) KEY(NAME) VALUES(3, 'Fine'); MERGE INTO TEST(ID, NAME) KEY(NAME) VALUES(3, 'Fine');
> exception LOCK_TIMEOUT_1 > exception DUPLICATE_KEY_1
MERGE INTO TEST(ID, NAME) KEY(NAME) VALUES(4, 'Fine!'); MERGE INTO TEST(ID, NAME) KEY(NAME) VALUES(4, 'Fine!');
> update count: 1 > update count: 1
MERGE INTO TEST(ID, NAME) KEY(NAME) VALUES(4, 'Fine! And you'); MERGE INTO TEST(ID, NAME) KEY(NAME) VALUES(4, 'Fine! And you');
> exception LOCK_TIMEOUT_1 > exception DUPLICATE_KEY_1
MERGE INTO TEST(ID, NAME) KEY(NAME, ID) VALUES(5, 'I''m ok'); MERGE INTO TEST(ID, NAME) KEY(NAME, ID) VALUES(5, 'I''m ok');
> update count: 1 > update count: 1
...@@ -94,3 +94,14 @@ SELECT * FROM TEST; ...@@ -94,3 +94,14 @@ SELECT * FROM TEST;
DROP TABLE TEST; DROP TABLE TEST;
> ok > ok
-- Test for the index matching logic in org.h2.command.dml.Merge
CREATE TABLE TEST(ID INT PRIMARY KEY, VALUE1 INT, VALUE2 INT, UNIQUE(VALUE1, VALUE2));
> ok
MERGE INTO TEST KEY (ID) VALUES (1, 2, 3), (2, 2, 3);
> exception DUPLICATE_KEY_1
DROP TABLE TEST;
> ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论