Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
a1ee79dc
提交
a1ee79dc
authored
10月 04, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove dead and useless code from MERGE USING
上级
25b98d52
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
4 行增加
和
58 行删除
+4
-58
MergeUsing.java
h2/src/main/org/h2/command/dml/MergeUsing.java
+3
-57
mergeUsing.sql
h2/src/test/org/h2/test/scripts/dml/mergeUsing.sql
+1
-1
没有找到文件。
h2/src/main/org/h2/command/dml/MergeUsing.java
浏览文件 @
a1ee79dc
...
@@ -23,7 +23,6 @@ import org.h2.message.DbException;
...
@@ -23,7 +23,6 @@ import org.h2.message.DbException;
import
org.h2.result.ResultInterface
;
import
org.h2.result.ResultInterface
;
import
org.h2.result.Row
;
import
org.h2.result.Row
;
import
org.h2.result.RowImpl
;
import
org.h2.result.RowImpl
;
import
org.h2.table.Column
;
import
org.h2.table.Table
;
import
org.h2.table.Table
;
import
org.h2.table.TableFilter
;
import
org.h2.table.TableFilter
;
import
org.h2.util.StatementBuilder
;
import
org.h2.util.StatementBuilder
;
...
@@ -207,8 +206,6 @@ public class MergeUsing extends Prepared {
...
@@ -207,8 +206,6 @@ public class MergeUsing extends Prepared {
// Merge fields
// Merge fields
Table
targetTable
;
Table
targetTable
;
private
TableFilter
targetTableFilter
;
private
TableFilter
targetTableFilter
;
private
Column
[]
columns
;
private
final
ArrayList
<
Expression
[]>
valuesExpressionList
=
Utils
.
newSmallArrayList
();
private
Query
query
;
private
Query
query
;
// MergeUsing fields
// MergeUsing fields
...
@@ -327,38 +324,11 @@ public class MergeUsing extends Prepared {
...
@@ -327,38 +324,11 @@ public class MergeUsing extends Prepared {
return
matched
;
return
matched
;
}
}
// Use the regular merge syntax as our plan SQL
@Override
@Override
public
String
getPlanSQL
()
{
public
String
getPlanSQL
()
{
StatementBuilder
buff
=
new
StatementBuilder
(
"MERGE INTO "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"MERGE INTO "
);
buff
.
append
(
targetTable
.
getSQL
()).
append
(
'('
);
buff
.
append
(
targetTable
.
getSQL
()).
append
(
'\n'
).
append
(
"USING "
).
append
(
query
.
getPlanSQL
());
for
(
Column
c
:
columns
)
{
// TODO add aliases and WHEN clauses to make plan SQL more like original SQL
buff
.
appendExceptFirst
(
", "
);
buff
.
append
(
c
.
getSQL
());
}
buff
.
append
(
')'
).
append
(
'\n'
);
if
(!
valuesExpressionList
.
isEmpty
())
{
buff
.
append
(
"VALUES "
);
int
row
=
0
;
for
(
Expression
[]
expr
:
valuesExpressionList
)
{
if
(
row
++
>
0
)
{
buff
.
append
(
", "
);
}
buff
.
append
(
'('
);
buff
.
resetCount
();
for
(
Expression
e
:
expr
)
{
buff
.
appendExceptFirst
(
", "
);
if
(
e
==
null
)
{
buff
.
append
(
"DEFAULT"
);
}
else
{
buff
.
append
(
e
.
getSQL
());
}
}
buff
.
append
(
')'
);
}
}
else
{
buff
.
append
(
query
.
getPlanSQL
());
}
return
buff
.
toString
();
return
buff
.
toString
();
}
}
...
@@ -376,31 +346,7 @@ public class MergeUsing extends Prepared {
...
@@ -376,31 +346,7 @@ public class MergeUsing extends Prepared {
onCondition
.
createIndexConditions
(
session
,
sourceTableFilter
);
onCondition
.
createIndexConditions
(
session
,
sourceTableFilter
);
onCondition
.
createIndexConditions
(
session
,
targetTableFilter
);
onCondition
.
createIndexConditions
(
session
,
targetTableFilter
);
if
(
columns
==
null
)
{
query
.
prepare
();
if
(!
valuesExpressionList
.
isEmpty
()
&&
valuesExpressionList
.
get
(
0
).
length
==
0
)
{
// special case where table is used as a sequence
columns
=
new
Column
[
0
];
}
else
{
columns
=
targetTable
.
getColumns
();
}
}
if
(!
valuesExpressionList
.
isEmpty
())
{
for
(
Expression
[]
expr
:
valuesExpressionList
)
{
if
(
expr
.
length
!=
columns
.
length
)
{
throw
DbException
.
get
(
ErrorCode
.
COLUMN_COUNT_DOES_NOT_MATCH
);
}
for
(
int
i
=
0
;
i
<
expr
.
length
;
i
++)
{
Expression
e
=
expr
[
i
];
if
(
e
!=
null
)
{
expr
[
i
]
=
e
.
optimize
(
session
);
}
}
}
}
else
{
query
.
prepare
();
}
// Prepare each of the sub-commands ready to aid in the MERGE
// Prepare each of the sub-commands ready to aid in the MERGE
// collaboration
// collaboration
...
...
h2/src/test/org/h2/test/scripts/dml/mergeUsing.sql
浏览文件 @
a1ee79dc
...
@@ -29,7 +29,7 @@ EXPLAIN PLAN
...
@@ -29,7 +29,7 @@ EXPLAIN PLAN
UPDATE
SET
P
.
NAME
=
S
.
NAME
WHERE
2
=
2
WHEN
NOT
UPDATE
SET
P
.
NAME
=
S
.
NAME
WHERE
2
=
2
WHEN
NOT
MATCHED
THEN
MATCHED
THEN
INSERT
(
ID
,
NAME
)
VALUES
(
S
.
ID
,
S
.
NAME
);
INSERT
(
ID
,
NAME
)
VALUES
(
S
.
ID
,
S
.
NAME
);
>>
MERGE
INTO
PUBLIC
.
PARENT
(
ID
,
NAME
)
SELECT
X
AS
ID
,
(
'Coco'
||
X
)
AS
NAME
FROM
SYSTEM_RANGE
(
1
,
2
)
/* PUBLIC.RANGE_INDEX */
>>
MERGE
INTO
PUBLIC
.
PARENT
USING
SELECT
X
AS
ID
,
(
'Coco'
||
X
)
AS
NAME
FROM
SYSTEM_RANGE
(
1
,
2
)
/* PUBLIC.RANGE_INDEX */
DROP
TABLE
PARENT
;
DROP
TABLE
PARENT
;
>
ok
>
ok
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论