Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e9a303fb
提交
e9a303fb
authored
10月 03, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove target row match on insert restriction from MERGE USING
上级
7aa0e49a
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
25 行增加
和
41 行删除
+25
-41
changelog.html
h2/src/docsrc/html/changelog.html
+2
-0
MergeUsing.java
h2/src/main/org/h2/command/dml/MergeUsing.java
+1
-10
TestMergeUsing.java
h2/src/test/org/h2/test/db/TestMergeUsing.java
+0
-31
mergeUsing.sql
h2/src/test/org/h2/test/scripts/dml/mergeUsing.sql
+22
-0
没有找到文件。
h2/src/docsrc/html/changelog.html
浏览文件 @
e9a303fb
...
...
@@ -21,6 +21,8 @@ Change Log
<h2>
Next Version (unreleased)
</h2>
<ul>
<li>
Issue #1491: Unnecessary restriction on MERGE USING statement when ON predicate doesn't match inserted row
</li>
<li>
Issue #1490: NullPointerException when running invalid MERGE statement
</li>
<li>
Issue #1488: Improve documentation of window and some other functions
...
...
h2/src/main/org/h2/command/dml/MergeUsing.java
浏览文件 @
e9a303fb
...
...
@@ -6,7 +6,6 @@
package
org
.
h2
.
command
.
dml
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.HashMap
;
import
java.util.HashSet
;
...
...
@@ -214,15 +213,7 @@ public class MergeUsing extends Prepared {
}
}
else
{
if
(
insertCommand
!=
null
)
{
int
count
=
insertCommand
.
update
();
if
(!
isTargetRowFound
())
{
throw
DbException
.
get
(
ErrorCode
.
GENERAL_ERROR_1
,
"Expected to find key after row inserted, but none found. "
+
"Insert does not match ON condition.:"
+
targetTable
.
getSQL
()
+
":source row="
+
Arrays
.
asList
(
sourceRow
.
getValueList
()));
}
countUpdatedRows
+=
count
;
countUpdatedRows
+=
insertCommand
.
update
();
}
}
}
...
...
h2/src/test/org/h2/test/db/TestMergeUsing.java
浏览文件 @
e9a303fb
...
...
@@ -196,25 +196,6 @@ public class TestMergeUsing extends TestDb implements Trigger {
"SELECT 1 AS ID, 'Marcy'||X||X UNION ALL SELECT 1 AS ID, 'Marcy2'"
,
2
);
// Multiple update on same row: SQL standard says duplicate or repeated
// updates in same statement should cause errors -but because first row
// is updated, delete then insert it's considered different
// One insert, one update one delete happens (on same row, which is
// okay), then another update (which is illegal)target table missing PK,
// no source or target alias
testMergeUsingException
(
"CREATE TABLE PARENT AS (SELECT X AS ID, 'Marcy'||X AS NAME FROM SYSTEM_RANGE(1,1) );"
+
"CREATE TABLE SOURCE AS (SELECT 1 AS ID, 'Marcy'||X AS NAME FROM SYSTEM_RANGE(1,3) );"
,
"MERGE INTO PARENT USING SOURCE ON (PARENT.ID = SOURCE.ID) WHEN MATCHED THEN "
+
"UPDATE SET PARENT.NAME = SOURCE.NAME||SOURCE.ID WHERE PARENT.ID = 2 "
+
"DELETE WHERE PARENT.ID = 1 WHEN NOT MATCHED THEN "
+
"INSERT (ID, NAME) VALUES (SOURCE.ID, SOURCE.NAME)"
,
GATHER_ORDERED_RESULTS_SQL
,
"SELECT 1 AS ID, 'Marcy'||X||X UNION ALL SELECT 1 AS ID, 'Marcy2'"
,
3
,
"Unique index or primary key violation: \"Merge using "
+
"ON column expression, duplicate _ROWID_ target record "
+
"already updated, deleted or inserted:_ROWID_=2:in:PUBLIC.PARENT:conflicting source row number:2"
);
// Duplicate key updated 3 rows at once, only 1 expected
testMergeUsingException
(
"CREATE TABLE PARENT AS (SELECT 1 AS ID, 'Marcy'||X AS NAME FROM SYSTEM_RANGE(1,3) );"
...
...
@@ -251,18 +232,6 @@ public class TestMergeUsing extends TestDb implements Trigger {
"SELECT X AS ID, 'Marcy'||X||X AS NAME FROM SYSTEM_RANGE(2,2) UNION ALL "
+
"SELECT X AS ID, 'Marcy'||X AS NAME FROM SYSTEM_RANGE(3,3)"
,
3
,
"Duplicate key updated 3 rows at once, only 1 expected"
);
// Insert does not insert correct values with respect to ON condition
// (inserts ID value above 100, instead)
testMergeUsingException
(
"CREATE TABLE PARENT AS (SELECT 1 AS ID, 'Marcy'||X AS NAME FROM SYSTEM_RANGE(4,4) );"
+
"CREATE TABLE SOURCE AS (SELECT X AS ID, 'Marcy'||X AS NAME FROM SYSTEM_RANGE(1,3) );"
,
"MERGE INTO PARENT USING SOURCE ON (PARENT.ID = SOURCE.ID) WHEN MATCHED THEN "
+
"UPDATE SET PARENT.NAME = SOURCE.NAME||SOURCE.ID WHERE PARENT.ID = 2 "
+
"DELETE WHERE PARENT.ID = 1 WHEN NOT MATCHED THEN "
+
"INSERT (ID, NAME) VALUES (SOURCE.ID+100, SOURCE.NAME)"
,
GATHER_ORDERED_RESULTS_SQL
,
"SELECT X AS ID, 'Marcy'||X AS NAME FROM SYSTEM_RANGE(4,4)"
,
1
,
"Expected to find key after row inserted, but none found. Insert does not match ON condition."
);
// One insert, one update one delete happens, target table missing PK,
// triggers update all NAME fields
triggerTestingUpdateCount
=
0
;
...
...
h2/src/test/org/h2/test/scripts/dml/mergeUsing.sql
浏览文件 @
e9a303fb
...
...
@@ -213,3 +213,25 @@ MERGE INTO TEST USING (SELECT 40) ON UNKNOWN_COLUMN = 1 WHEN NOT MATCHED THEN IN
DROP
TABLE
TEST
;
>
ok
CREATE
TABLE
TEST
(
ID
INT
PRIMARY
KEY
,
VALUE
INT
);
>
ok
INSERT
INTO
TEST
VALUES
(
1
,
10
),
(
2
,
20
);
>
update
count
:
2
MERGE
INTO
TEST
USING
(
SELECT
1
)
ON
(
ID
<
0
)
WHEN
MATCHED
THEN
UPDATE
SET
VALUE
=
30
WHEN
NOT
MATCHED
THEN
INSERT
VALUES
(
3
,
30
);
>
update
count
:
1
SELECT
*
FROM
TEST
;
>
ID
VALUE
>
-- -----
>
1
10
>
2
20
>
3
30
>
rows
:
3
DROP
TABLE
TEST
;
>
ok
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论