Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
2f6921ae
提交
2f6921ae
authored
10月 08, 2017
作者:
Owner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Removed debug statements
上级
920722fc
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
10 行增加
和
206 行删除
+10
-206
Parser.java
h2/src/main/org/h2/command/Parser.java
+4
-38
MergeUsing.java
h2/src/main/org/h2/command/dml/MergeUsing.java
+6
-158
Comparison.java
h2/src/main/org/h2/expression/Comparison.java
+0
-2
ExpressionColumn.java
h2/src/main/org/h2/expression/ExpressionColumn.java
+0
-2
Table.java
h2/src/main/org/h2/table/Table.java
+0
-3
TableFilter.java
h2/src/main/org/h2/table/TableFilter.java
+0
-2
TestMergeUsing.java
h2/src/test/org/h2/test/db/TestMergeUsing.java
+0
-1
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
2f6921ae
...
@@ -1094,29 +1094,11 @@ public class Parser {
...
@@ -1094,29 +1094,11 @@ public class Parser {
}
}
return
command
;
return
command
;
}
}
/*
* TODO finish writing this MergeUsing
MERGE INTO targetTableName [[AS] t_alias] USING table_reference [[AS} s_alias] ON ( condition ,...)
WHEN MATCHED THEN
[UPDATE SET column1 = value1 [, column2 = value2 ... WHERE ...]
[DELETE WHERE ...]
WHEN NOT MATCHED THEN
INSERT (column1 [, column2 ...]) VALUES (value1 [, value2 ...]);
table_reference ::= table | view | ( sub-query )
The current implementation (for comparison) uses this syntax:
MERGE INTO tablename [(columnName1,...)]
[KEY (keyColumnName1,...)]
[ VALUES (expression1,...) | SELECT ...]
*/
/* TODO: Finish coding parseMergeUsing */
private
MergeUsing
parseMergeUsing
(
Merge
oldCommand
,
int
start
)
{
private
MergeUsing
parseMergeUsing
(
Merge
oldCommand
,
int
start
)
{
/* TODO: not sure why schema name is reset to null */
if
(
schemaName
==
null
){
if
(
schemaName
==
null
){
schemaName
=
session
.
getCurrentSchemaName
();
schemaName
=
session
.
getCurrentSchemaName
();
System
.
out
.
println
(
"schemaName="
+
schemaName
);
}
}
Schema
schema
=
getSchema
();
Schema
schema
=
getSchema
();
...
@@ -1125,29 +1107,25 @@ public class Parser {
...
@@ -1125,29 +1107,25 @@ public class Parser {
currentPrepared
=
command
;
currentPrepared
=
command
;
if
(
readIf
(
"("
))
{
if
(
readIf
(
"("
))
{
System
.
out
.
println
(
"pre select schema="
+
getSchema
()+
",schemaName="
+
schemaName
);
/* a select query is supplied */
if
(
isSelect
())
{
if
(
isSelect
())
{
command
.
setQuery
(
parseSelect
());
command
.
setQuery
(
parseSelect
());
System
.
out
.
println
(
"post select schema="
+
getSchema
()+
",schemaName="
+
schemaName
);
schemaName
=
savedSchemaName
;
schemaName
=
savedSchemaName
;
System
.
out
.
println
(
"post2 select schema="
+
getSchema
()+
",schemaName="
+
schemaName
);
read
(
")"
);
read
(
")"
);
}
}
command
.
setQueryAlias
(
readFromAlias
(
null
,
Arrays
.
asList
(
"ON"
)));
command
.
setQueryAlias
(
readFromAlias
(
null
,
Arrays
.
asList
(
"ON"
)));
String
[]
querySQLOutput
=
new
String
[]{
null
};
String
[]
querySQLOutput
=
new
String
[]{
null
};
List
<
Column
>
columnTemplateList
=
createQueryColumnTemplateList
(
null
,
command
.
getQuery
(),
querySQLOutput
);
List
<
Column
>
columnTemplateList
=
createQueryColumnTemplateList
(
null
,
command
.
getQuery
(),
querySQLOutput
);
System
.
out
.
println
(
"pre:alias="
+
command
.
getQueryAlias
()+
",sql="
+
querySQLOutput
[
0
]+
",ctlist="
+
columnTemplateList
+
",schema="
+
getSchema
()+
",schemaName="
+
schemaName
);
TableView
temporarySourceTableView
=
createTemporarySessionView
(
command
.
getQueryAlias
(),
querySQLOutput
[
0
],
columnTemplateList
,
false
,
false
);
TableView
temporarySourceTableView
=
createTemporarySessionView
(
command
.
getQueryAlias
(),
querySQLOutput
[
0
],
columnTemplateList
,
false
,
false
);
command
.
setTemporaryTableView
(
temporarySourceTableView
);
command
.
setTemporaryTableView
(
temporarySourceTableView
);
System
.
out
.
println
(
"sourceTableFilter with tableOrView="
+
temporarySourceTableView
);
System
.
out
.
println
(
"sourceTableFilter rightsChecked="
+
rightsChecked
);
TableFilter
sourceTableFilter
=
new
TableFilter
(
session
,
temporarySourceTableView
,
command
.
getQueryAlias
(),
rightsChecked
,
TableFilter
sourceTableFilter
=
new
TableFilter
(
session
,
temporarySourceTableView
,
command
.
getQueryAlias
(),
rightsChecked
,
(
Select
)
command
.
getQuery
(),
0
,
null
);
(
Select
)
command
.
getQuery
(),
0
,
null
);
command
.
setSourceTableFilter
(
sourceTableFilter
);
command
.
setSourceTableFilter
(
sourceTableFilter
);
}
}
else
{
else
{
/* Its a table name, simulate a query by building a select query for the table */
List
<
String
>
excludeIdentifiers
=
Arrays
.
asList
(
"ON"
);
List
<
String
>
excludeIdentifiers
=
Arrays
.
asList
(
"ON"
);
TableFilter
sourceTableFilter
=
readSimpleTableFilterWithAliasExcludes
(
0
,
excludeIdentifiers
);
TableFilter
sourceTableFilter
=
readSimpleTableFilterWithAliasExcludes
(
0
,
excludeIdentifiers
);
command
.
setSourceTableFilter
(
sourceTableFilter
);
command
.
setSourceTableFilter
(
sourceTableFilter
);
...
@@ -1157,9 +1135,7 @@ public class Parser {
...
@@ -1157,9 +1135,7 @@ public class Parser {
if
(
sourceTableFilter
.
getTableAlias
()!=
null
){
if
(
sourceTableFilter
.
getTableAlias
()!=
null
){
buff
.
append
(
" AS "
+
sourceTableFilter
.
getTableAlias
());
buff
.
append
(
" AS "
+
sourceTableFilter
.
getTableAlias
());
}
}
//ArrayList<Value> paramValues = New.arrayList();
Prepared
preparedQuery
=
prepare
(
session
,
buff
.
toString
(),
null
/*paramValues*/
);
Prepared
preparedQuery
=
prepare
(
session
,
buff
.
toString
(),
null
/*paramValues*/
);
System
.
out
.
println
(
"class="
+
preparedQuery
.
getClass
());
command
.
setQuery
((
Select
)
preparedQuery
);
command
.
setQuery
((
Select
)
preparedQuery
);
}
}
...
@@ -1197,14 +1173,6 @@ public class Parser {
...
@@ -1197,14 +1173,6 @@ public class Parser {
}
}
}
}
if
(
command
.
getQueryAlias
()!=
null
){
if
(
schema
==
null
){
System
.
out
.
println
(
"Why oh why is the schema null???"
);
System
.
out
.
println
(
"schemaName="
+
schemaName
);
throw
DbException
.
getUnsupportedException
(
"unexpected null schema"
);
}
}
setSQL
(
command
,
"MERGE"
,
start
);
setSQL
(
command
,
"MERGE"
,
start
);
return
command
;
return
command
;
}
}
...
@@ -5198,7 +5166,6 @@ public class Parser {
...
@@ -5198,7 +5166,6 @@ public class Parser {
withQuery
.
prepare
();
withQuery
.
prepare
();
querySQLOutput
[
0
]
=
StringUtils
.
cache
(
withQuery
.
getPlanSQL
());
querySQLOutput
[
0
]
=
StringUtils
.
cache
(
withQuery
.
getPlanSQL
());
ArrayList
<
Expression
>
withExpressions
=
withQuery
.
getExpressions
();
ArrayList
<
Expression
>
withExpressions
=
withQuery
.
getExpressions
();
System
.
out
.
println
(
"withExpressions="
+
withExpressions
);
for
(
int
i
=
0
;
i
<
withExpressions
.
size
();
++
i
)
{
for
(
int
i
=
0
;
i
<
withExpressions
.
size
();
++
i
)
{
Expression
columnExp
=
withExpressions
.
get
(
i
);
Expression
columnExp
=
withExpressions
.
get
(
i
);
// use the passed in column name if supplied, otherwise use alias (if used) otherwise use column name
// use the passed in column name if supplied, otherwise use alias (if used) otherwise use column name
...
@@ -5225,7 +5192,6 @@ public class Parser {
...
@@ -5225,7 +5192,6 @@ public class Parser {
// No easy way to determine if this is a recursive query up front, so we just compile
// No easy way to determine if this is a recursive query up front, so we just compile
// it twice - once without the flag set, and if we didn't see a recursive term,
// it twice - once without the flag set, and if we didn't see a recursive term,
// then we just compile it again.
// then we just compile it again.
System
.
out
.
println
(
"createTemporarySessionView="
+
tempViewName
);
TableView
view
=
new
TableView
(
schema
,
id
,
tempViewName
,
querySQL
,
TableView
view
=
new
TableView
(
schema
,
id
,
tempViewName
,
querySQL
,
parameters
,
columnTemplateList
.
toArray
(
new
Column
[
0
]),
session
,
parameters
,
columnTemplateList
.
toArray
(
new
Column
[
0
]),
session
,
allowRecursiveQueryDetection
/* recursive */
,
false
);
allowRecursiveQueryDetection
/* recursive */
,
false
);
...
...
h2/src/main/org/h2/command/dml/MergeUsing.java
浏览文件 @
2f6921ae
...
@@ -56,7 +56,6 @@ public class MergeUsing extends Merge {
...
@@ -56,7 +56,6 @@ public class MergeUsing extends Merge {
// bring across only the already parsed data from Merge...
// bring across only the already parsed data from Merge...
this
.
targetTable
=
merge
.
targetTable
;
this
.
targetTable
=
merge
.
targetTable
;
this
.
targetTableFilter
=
merge
.
targetTableFilter
;
this
.
targetTableFilter
=
merge
.
targetTableFilter
;
}
}
...
@@ -64,8 +63,6 @@ public class MergeUsing extends Merge {
...
@@ -64,8 +63,6 @@ public class MergeUsing extends Merge {
public
int
update
()
{
public
int
update
()
{
sourceKeysRemembered
.
clear
();
sourceKeysRemembered
.
clear
();
System
.
out
.
println
(
"update using:"
+
temporarySourceTableView
);
if
(
targetTableFilter
!=
null
){
if
(
targetTableFilter
!=
null
){
targetTableFilter
.
startQuery
(
session
);
targetTableFilter
.
startQuery
(
session
);
targetTableFilter
.
reset
();
targetTableFilter
.
reset
();
...
@@ -89,11 +86,9 @@ public class MergeUsing extends Merge {
...
@@ -89,11 +86,9 @@ public class MergeUsing extends Merge {
countInputRows
++;
countInputRows
++;
Value
[]
sourceRowValues
=
rows
.
currentRow
();
Value
[]
sourceRowValues
=
rows
.
currentRow
();
Row
sourceRow
=
new
RowImpl
(
sourceRowValues
,
0
);
Row
sourceRow
=
new
RowImpl
(
sourceRowValues
,
0
);
System
.
out
.
println
((
"currentRowValues="
+
Arrays
.
toString
(
sourceRowValues
)));
Row
newTargetRow
=
targetTable
.
getTemplateRow
();
Row
newTargetRow
=
targetTable
.
getTemplateRow
();
ArrayList
<
Value
>
sourceKeyValuesList
=
new
ArrayList
<
Value
>();
ArrayList
<
Value
>
sourceKeyValuesList
=
new
ArrayList
<
Value
>();
setCurrentRowNumber
(
countInputRows
);
setCurrentRowNumber
(
countInputRows
);
System
.
out
.
println
(
"columns="
+
Arrays
.
toString
(
columns
));
// isolate the source row key columns values
// isolate the source row key columns values
for
(
int
j
=
0
;
j
<
sourceKeys
.
length
;
j
++)
{
for
(
int
j
=
0
;
j
<
sourceKeys
.
length
;
j
++)
{
...
@@ -168,29 +163,22 @@ public class MergeUsing extends Merge {
...
@@ -168,29 +163,22 @@ public class MergeUsing extends Merge {
// try and perform an update
// try and perform an update
int
rowUpdateCount
=
0
;
int
rowUpdateCount
=
0
;
System
.
out
.
println
(
"onConditions="
+
onCondition
.
toString
());
if
(
updateCommand
!=
null
){
if
(
updateCommand
!=
null
){
System
.
out
.
println
(
"updatePlanSQL="
+
updateCommand
.
getPlanSQL
());
rowUpdateCount
+=
updateCommand
.
update
();
rowUpdateCount
+=
updateCommand
.
update
();
System
.
out
.
println
(
"update.count="
+
rowUpdateCount
);
}
}
if
(
deleteCommand
!=
null
){
if
(
deleteCommand
!=
null
){
System
.
out
.
println
(
"deleteCommand="
+
deleteCommand
.
getPlanSQL
());
rowUpdateCount
+=
deleteCommand
.
update
();
rowUpdateCount
+=
deleteCommand
.
update
();
System
.
out
.
println
(
"delete.count="
+
rowUpdateCount
);
}
}
// if either updates do nothing, try an insert
// if either updates do nothing, try an insert
if
(
rowUpdateCount
==
0
)
{
if
(
rowUpdateCount
==
0
)
{
rowUpdateCount
+=
addRowByCommandInsert
(
session
,
newTargetRow
);
rowUpdateCount
+=
addRowByCommandInsert
(
session
,
newTargetRow
);
//addRowByAPIInsert(session,newTargetRow);
}
else
if
(
rowUpdateCount
!=
1
)
{
}
else
if
(
rowUpdateCount
!=
1
)
{
throw
DbException
.
get
(
ErrorCode
.
DUPLICATE_KEY_1
,
"Duplicate key updated "
+
rowUpdateCount
+
" rows at once, only 1 expected:"
+
targetTable
.
getSQL
());
throw
DbException
.
get
(
ErrorCode
.
DUPLICATE_KEY_1
,
"Duplicate key updated "
+
rowUpdateCount
+
" rows at once, only 1 expected:"
+
targetTable
.
getSQL
());
}
}
countUpdatedRows
+=
rowUpdateCount
;
countUpdatedRows
+=
rowUpdateCount
;
}
}
private
void
configPreparedParameters
(
Row
newTargetRow
,
Prepared
updatePrepared
)
{
private
void
configPreparedParameters
(
Row
newTargetRow
,
Prepared
updatePrepared
)
{
ArrayList
<
Parameter
>
k
=
updatePrepared
.
getParameters
();
ArrayList
<
Parameter
>
k
=
updatePrepared
.
getParameters
();
// set each parameter in the updatePrepared with the real value from the source column
// set each parameter in the updatePrepared with the real value from the source column
...
@@ -216,56 +204,13 @@ public class MergeUsing extends Merge {
...
@@ -216,56 +204,13 @@ public class MergeUsing extends Merge {
private
int
addRowByCommandInsert
(
Session
session
,
Row
newTargetRow
)
{
private
int
addRowByCommandInsert
(
Session
session
,
Row
newTargetRow
)
{
int
localCount
=
0
;
int
localCount
=
0
;
if
(
insertCommand
!=
null
){
if
(
insertCommand
!=
null
){
System
.
out
.
println
(
"insertPlanSQL="
+
insertCommand
.
getPlanSQL
());
localCount
+=
insertCommand
.
update
();
localCount
+=
insertCommand
.
update
();
}
}
System
.
out
.
println
(
"insert.count="
+
localCount
);
return
localCount
;
return
localCount
;
}
}
private
int
addRowByAPIInsert
(
Session
session
,
Row
newTargetRow
)
{
System
.
out
.
println
(
"addRowByInsert=(hashcode)"
+
newTargetRow
.
hashCode
());
try
{
targetTable
.
validateConvertUpdateSequence
(
session
,
newTargetRow
);
boolean
done
=
targetTable
.
fireBeforeRow
(
session
,
null
,
newTargetRow
);
if
(!
done
)
{
targetTable
.
lock
(
session
,
true
,
false
);
targetTable
.
addRow
(
session
,
newTargetRow
);
session
.
log
(
targetTable
,
UndoLogRecord
.
INSERT
,
newTargetRow
);
targetTable
.
fireAfterRow
(
session
,
null
,
newTargetRow
,
false
);
return
1
;
}
return
0
;
}
catch
(
DbException
e
)
{
if
(
e
.
getErrorCode
()
==
ErrorCode
.
DUPLICATE_KEY_1
)
{
// possibly a concurrent merge or insert
Index
index
=
(
Index
)
e
.
getSource
();
if
(
index
!=
null
)
{
// verify the index columns match the key
Column
[]
indexColumns
=
index
.
getColumns
();
boolean
indexMatchesKeys
=
true
;
if
(
indexColumns
.
length
<=
keys
.
length
)
{
for
(
int
i
=
0
;
i
<
indexColumns
.
length
;
i
++)
{
if
(
indexColumns
[
i
]
!=
keys
[
i
])
{
indexMatchesKeys
=
false
;
break
;
}
}
}
if
(
indexMatchesKeys
)
{
throw
DbException
.
get
(
ErrorCode
.
CONCURRENT_UPDATE_1
,
targetTable
.
getName
());
}
}
}
throw
e
;
}
}
@Override
@Override
public
String
getPlanSQL
()
{
public
String
getPlanSQL
()
{
System
.
out
.
println
(
"getPlanSQL"
);
StatementBuilder
buff
=
new
StatementBuilder
(
"MERGE INTO "
);
StatementBuilder
buff
=
new
StatementBuilder
(
"MERGE INTO "
);
buff
.
append
(
targetTable
.
getSQL
()).
append
(
'('
);
buff
.
append
(
targetTable
.
getSQL
()).
append
(
'('
);
for
(
Column
c
:
columns
)
{
for
(
Column
c
:
columns
)
{
...
@@ -307,55 +252,9 @@ public class MergeUsing extends Merge {
...
@@ -307,55 +252,9 @@ public class MergeUsing extends Merge {
}
}
return
buff
.
toString
();
return
buff
.
toString
();
}
}
/*
@Override
public void prepare() {
if (condition != null) {
condition.mapColumns(tableFilter, 0);
condition = condition.optimize(session);
condition.createIndexConditions(session, tableFilter);
}
for (int i = 0, size = columns.size(); i < size; i++) {
Column c = columns.get(i);
Expression e = expressionMap.get(c);
e.mapColumns(tableFilter, 0);
expressionMap.put(c, e.optimize(session));
}
TableFilter[] filters = new TableFilter[] { tableFilter };
PlanItem item = tableFilter.getBestPlanItem(session, filters, 0,
ExpressionVisitor.allColumnsForTableFilters(filters));
tableFilter.setPlanItem(item);
tableFilter.prepare();
}
*/
/*
MERGE INTO targetTableName [[AS] t_alias] USING table_reference [[AS} s_alias] ON ( condition ,...)
WHEN MATCHED THEN
[UPDATE SET column1 = value1 [, column2 = value2 ... WHERE ...]
[DELETE WHERE ...]
WHEN NOT MATCHED THEN
INSERT (column1 [, column2 ...]) VALUES (value1 [, value2 ...]);
table_reference ::= table | view | ( sub-query )
The current implementation (for comparison) uses this syntax:
MERGE INTO tablename [(columnName1,...)]
[KEY (keyColumnName1,...)]
[ VALUES (expression1,...) | SELECT ...]
*/
@Override
@Override
public
void
prepare
()
{
public
void
prepare
()
{
System
.
out
.
println
(
"prepare:targetTableFilterAlias="
+
targetTableFilter
.
getTableAlias
());
System
.
out
.
println
(
"prepare:sourceTableFilterAlias="
+
sourceTableFilter
.
getTableAlias
());
System
.
out
.
println
(
"prepare:onConditions="
+
onCondition
);
//TableFilter[] filters = new TableFilter[] { sourceTableFilter, targetTableFilter };
System
.
out
.
println
(
"onCondition="
+
onCondition
+
":op="
+
onCondition
.
getClass
().
getSimpleName
());
onCondition
.
addFilterConditions
(
sourceTableFilter
,
true
);
onCondition
.
addFilterConditions
(
sourceTableFilter
,
true
);
onCondition
.
addFilterConditions
(
targetTableFilter
,
true
);
onCondition
.
addFilterConditions
(
targetTableFilter
,
true
);
onCondition
.
mapColumns
(
sourceTableFilter
,
2
);
onCondition
.
mapColumns
(
sourceTableFilter
,
2
);
...
@@ -365,24 +264,23 @@ public class MergeUsing extends Merge {
...
@@ -365,24 +264,23 @@ public class MergeUsing extends Merge {
if
(
keys
==
null
)
{
if
(
keys
==
null
)
{
HashSet
<
Column
>
targetColumns
=
buildColumnListFromOnCondition
(
targetTableFilter
);
HashSet
<
Column
>
targetColumns
=
buildColumnListFromOnCondition
(
targetTableFilter
);
keys
=
targetColumns
.
toArray
(
new
Column
[
0
]);
keys
=
targetColumns
.
toArray
(
new
Column
[
0
]);
System
.
out
.
println
(
"keys.length="
+
keys
.
length
);
}
}
if
(
keys
.
length
==
0
){
if
(
keys
.
length
==
0
){
throw
DbException
.
get
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
"No references to target columns found in ON clause:"
+
targetTableFilter
.
toString
());
throw
DbException
.
get
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
"No references to target columns found in ON clause:"
+
targetTableFilter
.
toString
());
}
}
if
(
sourceKeys
==
null
)
{
if
(
sourceKeys
==
null
)
{
HashSet
<
Column
>
sourceColumns
=
buildColumnListFromOnCondition
(
sourceTableFilter
);
HashSet
<
Column
>
sourceColumns
=
buildColumnListFromOnCondition
(
sourceTableFilter
);
sourceKeys
=
sourceColumns
.
toArray
(
new
Column
[
0
]);
sourceKeys
=
sourceColumns
.
toArray
(
new
Column
[
0
]);
System
.
out
.
println
(
"sourceKeys.length="
+
sourceKeys
.
length
);
}
}
if
(
sourceKeys
.
length
==
0
){
if
(
sourceKeys
.
length
==
0
){
throw
DbException
.
get
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
"No references to source columns found in ON clause:"
+
sourceTableFilter
.
toString
());
throw
DbException
.
get
(
ErrorCode
.
COLUMN_NOT_FOUND_1
,
"No references to source columns found in ON clause:"
+
sourceTableFilter
.
toString
());
}
}
// only do the optimi
s
e now - before we have already gathered the unoptimized column data
// only do the optimi
z
e now - before we have already gathered the unoptimized column data
onCondition
=
onCondition
.
optimize
(
session
);
onCondition
=
onCondition
.
optimize
(
session
);
onCondition
.
createIndexConditions
(
session
,
sourceTableFilter
);
onCondition
.
createIndexConditions
(
session
,
sourceTableFilter
);
//optional
onCondition
.
createIndexConditions
(
session
,
targetTableFilter
);
onCondition
.
createIndexConditions
(
session
,
targetTableFilter
);
if
(
columns
==
null
)
{
if
(
columns
==
null
)
{
...
@@ -411,13 +309,6 @@ public class MergeUsing extends Merge {
...
@@ -411,13 +309,6 @@ public class MergeUsing extends Merge {
throw
DbException
.
get
(
ErrorCode
.
COLUMN_COUNT_DOES_NOT_MATCH
);
throw
DbException
.
get
(
ErrorCode
.
COLUMN_COUNT_DOES_NOT_MATCH
);
}
}
}
}
// if (keys == null) {
// Index idx = targetTable.getPrimaryKey();
// if (idx == null) {
// throw DbException.get(ErrorCode.CONSTRAINT_NOT_FOUND_1, "PRIMARY KEY");
// }
// keys = idx.getColumns();
// }
String
sql
=
buildPreparedSQL
();
String
sql
=
buildPreparedSQL
();
update
=
session
.
prepare
(
sql
);
update
=
session
.
prepare
(
sql
);
...
@@ -437,23 +328,18 @@ public class MergeUsing extends Merge {
...
@@ -437,23 +328,18 @@ public class MergeUsing extends Merge {
insertCommand
.
setSourceTableFilter
(
sourceTableFilter
);
insertCommand
.
setSourceTableFilter
(
sourceTableFilter
);
insertCommand
.
prepare
();
insertCommand
.
prepare
();
}
}
}
}
private
HashSet
<
Column
>
buildColumnListFromOnCondition
(
TableFilter
anyTableFilter
)
{
private
HashSet
<
Column
>
buildColumnListFromOnCondition
(
TableFilter
anyTableFilter
)
{
HashSet
<
Column
>
filteredColumns
=
new
HashSet
<
Column
>();
HashSet
<
Column
>
filteredColumns
=
new
HashSet
<
Column
>();
HashSet
<
Column
>
columns
=
new
HashSet
<
Column
>();
HashSet
<
Column
>
columns
=
new
HashSet
<
Column
>();
ExpressionVisitor
visitor
=
ExpressionVisitor
.
getColumnsVisitor
(
columns
);
ExpressionVisitor
visitor
=
ExpressionVisitor
.
getColumnsVisitor
(
columns
);
onCondition
.
isEverything
(
visitor
);
onCondition
.
isEverything
(
visitor
);
for
(
Column
c:
columns
){
for
(
Column
c:
columns
){
System
.
out
.
println
(
"C="
+
c
);
if
(
c
!=
null
&&
c
.
getTable
()==
anyTableFilter
.
getTable
()){
if
(
c
!=
null
&&
c
.
getTable
()==
anyTableFilter
.
getTable
()){
filteredColumns
.
add
(
c
);
filteredColumns
.
add
(
c
);
}
}
}
}
System
.
out
.
println
(
"columnsVisitedForTable"
+
anyTableFilter
.
getTable
()+
"="
+
filteredColumns
);
return
filteredColumns
;
return
filteredColumns
;
}
}
...
@@ -491,44 +377,6 @@ public class MergeUsing extends Merge {
...
@@ -491,44 +377,6 @@ public class MergeUsing extends Merge {
String
sql
=
buff
.
toString
();
String
sql
=
buff
.
toString
();
return
sql
;
return
sql
;
}
}
private
String
buildPreparedSQLForMergeUsing
()
{
StatementBuilder
buff
=
new
StatementBuilder
(
"MERGE INTO "
);
buff
.
append
(
targetTable
.
getSQL
());
if
(
targetTableFilter
.
getTableAlias
()!=
null
){
buff
.
append
(
" AS "
+
targetTableFilter
.
getTableAlias
()+
"\n"
);
}
buff
.
append
(
"USING \n"
);
buff
.
append
(
temporarySourceTableView
.
getSQL
());
buff
.
append
(
"\n"
);
if
(
sourceTableFilter
.
getTableAlias
()!=
null
){
buff
.
append
(
" AS "
+
sourceTableFilter
.
getTableAlias
()+
"\n"
);
}
buff
.
append
(
"ON ("
);
buff
.
append
(
onCondition
.
getSQL
());
buff
.
append
(
" )"
);
if
(
updateCommand
!=
null
||
deleteCommand
!=
null
){
buff
.
append
(
"\nWHEN MATCHED\n"
);
if
(
updateCommand
!=
null
){
buff
.
append
(
updateCommand
.
getPlanSQL
());
}
if
(
deleteCommand
!=
null
){
buff
.
append
(
deleteCommand
.
getPlanSQL
());
}
}
if
(
insertCommand
!=
null
){
buff
.
append
(
"\nWHEN NOT MATCHED\n"
);
if
(
insertCommand
!=
null
){
buff
.
append
(
insertCommand
.
getPlanSQL
());
}
}
// buff.resetCount();
// for (Column c : keys) {
// buff.appendExceptFirst(" AND ");
// buff.append(c.getSQL()).append("=?");
// }
String
sql
=
buff
.
toString
();
return
sql
;
}
public
void
setSourceTableFilter
(
TableFilter
sourceTableFilter
)
{
public
void
setSourceTableFilter
(
TableFilter
sourceTableFilter
)
{
this
.
sourceTableFilter
=
sourceTableFilter
;
this
.
sourceTableFilter
=
sourceTableFilter
;
...
...
h2/src/main/org/h2/expression/Comparison.java
浏览文件 @
2f6921ae
...
@@ -492,10 +492,8 @@ public class Comparison extends Condition {
...
@@ -492,10 +492,8 @@ public class Comparison extends Condition {
@Override
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
System
.
out
.
println
(
"Checking left:"
+
left
+
" against "
+
resolver
);
left
.
mapColumns
(
resolver
,
level
);
left
.
mapColumns
(
resolver
,
level
);
if
(
right
!=
null
)
{
if
(
right
!=
null
)
{
System
.
out
.
println
(
"Checking right:"
+
right
+
" against "
+
resolver
);
right
.
mapColumns
(
resolver
,
level
);
right
.
mapColumns
(
resolver
,
level
);
}
}
}
}
...
...
h2/src/main/org/h2/expression/ExpressionColumn.java
浏览文件 @
2f6921ae
...
@@ -117,11 +117,9 @@ public class ExpressionColumn extends Expression {
...
@@ -117,11 +117,9 @@ public class ExpressionColumn extends Expression {
queryLevel
=
level
;
queryLevel
=
level
;
column
=
col
;
column
=
col
;
this
.
columnResolver
=
resolver
;
this
.
columnResolver
=
resolver
;
System
.
out
.
println
(
"mapColumn: Setting resolver:"
+
col
+
"@"
+
System
.
identityHashCode
(
col
)+
" by resolver "
+
resolver
+
"-"
+
resolver
.
getClass
());
}
else
if
(
queryLevel
==
level
&&
this
.
columnResolver
!=
resolver
)
{
}
else
if
(
queryLevel
==
level
&&
this
.
columnResolver
!=
resolver
)
{
if
(
resolver
instanceof
SelectListColumnResolver
)
{
if
(
resolver
instanceof
SelectListColumnResolver
)
{
// ignore - already mapped, that's ok
// ignore - already mapped, that's ok
System
.
out
.
println
(
"mapColumn: Already mapped:"
+
col
+
"@"
+
System
.
identityHashCode
(
col
)+
" by resolver "
+
resolver
+
"-"
+
resolver
.
getClass
());
}
else
{
}
else
{
throw
DbException
.
get
(
ErrorCode
.
AMBIGUOUS_COLUMN_NAME_1
,
columnName
);
throw
DbException
.
get
(
ErrorCode
.
AMBIGUOUS_COLUMN_NAME_1
,
columnName
);
}
}
...
...
h2/src/main/org/h2/table/Table.java
浏览文件 @
2f6921ae
...
@@ -85,9 +85,6 @@ public abstract class Table extends SchemaObjectBase {
...
@@ -85,9 +85,6 @@ public abstract class Table extends SchemaObjectBase {
public
Table
(
Schema
schema
,
int
id
,
String
name
,
boolean
persistIndexes
,
public
Table
(
Schema
schema
,
int
id
,
String
name
,
boolean
persistIndexes
,
boolean
persistData
)
{
boolean
persistData
)
{
System
.
out
.
println
(
"newTable:schema="
+
schema
);
System
.
out
.
println
(
"newTable:name="
+
name
);
System
.
out
.
println
(
"newTable:schema="
+
schema
+
",database="
+
schema
.
getDatabase
());
columnMap
=
schema
.
getDatabase
().
newStringMap
();
columnMap
=
schema
.
getDatabase
().
newStringMap
();
initSchemaObjectBase
(
schema
,
id
,
name
,
Trace
.
TABLE
);
initSchemaObjectBase
(
schema
,
id
,
name
,
Trace
.
TABLE
);
this
.
persistIndexes
=
persistIndexes
;
this
.
persistIndexes
=
persistIndexes
;
...
...
h2/src/main/org/h2/table/TableFilter.java
浏览文件 @
2f6921ae
...
@@ -567,8 +567,6 @@ public class TableFilter implements ColumnResolver {
...
@@ -567,8 +567,6 @@ public class TableFilter implements ColumnResolver {
private
void
checkTimeout
()
{
private
void
checkTimeout
()
{
session
.
checkCanceled
();
session
.
checkCanceled
();
// System.out.println(this.alias+ " " + table.getName() + ": " +
// scanCount);
}
}
/**
/**
...
...
h2/src/test/org/h2/test/db/TestMergeUsing.java
浏览文件 @
2f6921ae
...
@@ -191,7 +191,6 @@ public class TestMergeUsing extends TestBase {
...
@@ -191,7 +191,6 @@ public class TestMergeUsing extends TestBase {
while
(
rs
.
next
())
{
while
(
rs
.
next
())
{
rowCount
++;
rowCount
++;
diffBuffer
.
append
(
"|"
);
diffBuffer
.
append
(
"|"
);
System
.
out
.
println
(
"rs.getMetaData().getColumnCount()="
+
rs
.
getMetaData
().
getColumnCount
());
for
(
int
ndx
=
1
;
ndx
<=
rs
.
getMetaData
().
getColumnCount
();
ndx
++){
for
(
int
ndx
=
1
;
ndx
<=
rs
.
getMetaData
().
getColumnCount
();
ndx
++){
diffBuffer
.
append
(
rs
.
getObject
(
ndx
));
diffBuffer
.
append
(
rs
.
getObject
(
ndx
));
diffBuffer
.
append
(
"|\n"
);
diffBuffer
.
append
(
"|\n"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论