Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ace8433a
提交
ace8433a
authored
6 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Pass StringBuilder to TableFilter.getPlanSQL()
上级
e619227f
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
49 行增加
和
49 行删除
+49
-49
Delete.java
h2/src/main/org/h2/command/dml/Delete.java
+2
-2
Select.java
h2/src/main/org/h2/command/dml/Select.java
+2
-2
Update.java
h2/src/main/org/h2/command/dml/Update.java
+14
-13
Aggregate.java
h2/src/main/org/h2/expression/aggregate/Aggregate.java
+0
-1
TableFilter.java
h2/src/main/org/h2/table/TableFilter.java
+31
-31
没有找到文件。
h2/src/main/org/h2/command/dml/Delete.java
浏览文件 @
ace8433a
...
@@ -136,8 +136,8 @@ public class Delete extends Prepared {
...
@@ -136,8 +136,8 @@ public class Delete extends Prepared {
@Override
@Override
public
String
getPlanSQL
()
{
public
String
getPlanSQL
()
{
StringBuilder
buff
=
new
StringBuilder
();
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
"DELETE "
);
buff
.
append
(
"DELETE
FROM
"
);
buff
.
append
(
"FROM "
).
append
(
targetTableFilter
.
getPlanSQL
(
false
)
);
targetTableFilter
.
getPlanSQL
(
buff
,
false
);
if
(
condition
!=
null
)
{
if
(
condition
!=
null
)
{
buff
.
append
(
"\nWHERE "
);
buff
.
append
(
"\nWHERE "
);
condition
.
getUnenclosedSQL
(
buff
);
condition
.
getUnenclosedSQL
(
buff
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
ace8433a
...
@@ -1345,7 +1345,7 @@ public class Select extends Query {
...
@@ -1345,7 +1345,7 @@ public class Select extends Query {
int
i
=
0
;
int
i
=
0
;
do
{
do
{
buff
.
appendExceptFirst
(
"\n"
);
buff
.
appendExceptFirst
(
"\n"
);
buff
.
append
(
filter
.
getPlanSQL
(
i
++
>
0
)
);
filter
.
getPlanSQL
(
buff
.
builder
(),
i
++
>
0
);
filter
=
filter
.
getJoin
();
filter
=
filter
.
getJoin
();
}
while
(
filter
!=
null
);
}
while
(
filter
!=
null
);
}
else
{
}
else
{
...
@@ -1354,7 +1354,7 @@ public class Select extends Query {
...
@@ -1354,7 +1354,7 @@ public class Select extends Query {
for
(
TableFilter
f
:
topFilters
)
{
for
(
TableFilter
f
:
topFilters
)
{
do
{
do
{
buff
.
appendExceptFirst
(
"\n"
);
buff
.
appendExceptFirst
(
"\n"
);
buff
.
append
(
f
.
getPlanSQL
(
i
++
>
0
)
);
f
.
getPlanSQL
(
buff
.
builder
(),
i
++
>
0
);
f
=
f
.
getJoin
();
f
=
f
.
getJoin
();
}
while
(
f
!=
null
);
}
while
(
f
!=
null
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/dml/Update.java
浏览文件 @
ace8433a
...
@@ -27,7 +27,6 @@ import org.h2.table.Column;
...
@@ -27,7 +27,6 @@ import org.h2.table.Column;
import
org.h2.table.PlanItem
;
import
org.h2.table.PlanItem
;
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.Utils
;
import
org.h2.util.Utils
;
import
org.h2.value.Value
;
import
org.h2.value.Value
;
import
org.h2.value.ValueNull
;
import
org.h2.value.ValueNull
;
...
@@ -216,23 +215,25 @@ public class Update extends Prepared {
...
@@ -216,23 +215,25 @@ public class Update extends Prepared {
@Override
@Override
public
String
getPlanSQL
()
{
public
String
getPlanSQL
()
{
StatementBuilder
buff
=
new
StatementBuilder
(
"UPDATE "
);
StringBuilder
builder
=
new
StringBuilder
(
"UPDATE "
);
buff
.
append
(
targetTableFilter
.
getPlanSQL
(
false
)).
append
(
"\nSET\n "
);
targetTableFilter
.
getPlanSQL
(
builder
,
false
).
append
(
"\nSET\n "
);
for
(
Column
c
:
columns
)
{
for
(
int
i
=
0
,
size
=
columns
.
size
();
i
<
size
;
i
++)
{
Expression
e
=
expressionMap
.
get
(
c
);
if
(
i
>
0
)
{
buff
.
appendExceptFirst
(
",\n "
);
builder
.
append
(
",\n "
);
buff
.
append
(
c
.
getName
()).
append
(
" = "
);
}
e
.
getSQL
(
buff
.
builder
());
Column
c
=
columns
.
get
(
i
);
builder
.
append
(
c
.
getName
()).
append
(
" = "
);
expressionMap
.
get
(
c
).
getSQL
(
builder
);
}
}
if
(
condition
!=
null
)
{
if
(
condition
!=
null
)
{
bu
ff
.
append
(
"\nWHERE "
);
bu
ilder
.
append
(
"\nWHERE "
);
condition
.
getUnenclosedSQL
(
bu
ff
.
builder
()
);
condition
.
getUnenclosedSQL
(
bu
ilder
);
}
}
if
(
limitExpr
!=
null
)
{
if
(
limitExpr
!=
null
)
{
bu
ff
.
append
(
"\nLIMIT "
);
bu
ilder
.
append
(
"\nLIMIT "
);
limitExpr
.
getUnenclosedSQL
(
bu
ff
.
builder
()
);
limitExpr
.
getUnenclosedSQL
(
bu
ilder
);
}
}
return
bu
ff
.
toString
();
return
bu
ilder
.
toString
();
}
}
@Override
@Override
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/aggregate/Aggregate.java
浏览文件 @
ace8433a
...
@@ -30,7 +30,6 @@ import org.h2.table.ColumnResolver;
...
@@ -30,7 +30,6 @@ import org.h2.table.ColumnResolver;
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
;
import
org.h2.util.StringUtils
;
import
org.h2.util.ValueHashMap
;
import
org.h2.util.ValueHashMap
;
import
org.h2.value.CompareMode
;
import
org.h2.value.CompareMode
;
import
org.h2.value.DataType
;
import
org.h2.value.DataType
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/table/TableFilter.java
浏览文件 @
ace8433a
...
@@ -747,75 +747,75 @@ public class TableFilter implements ColumnResolver {
...
@@ -747,75 +747,75 @@ public class TableFilter implements ColumnResolver {
}
}
/**
/**
* Get the query execution plan text to use for this table filter.
* Get the query execution plan text to use for this table filter and append
* it to the specified builder.
*
*
* @param builder string builder to append to
* @param isJoin if this is a joined table
* @param isJoin if this is a joined table
* @return the
SQL statement snippet
* @return the
specified builder
*/
*/
public
String
getPlanSQL
(
boolean
isJoin
)
{
public
StringBuilder
getPlanSQL
(
StringBuilder
builder
,
boolean
isJoin
)
{
StringBuilder
buff
=
new
StringBuilder
();
if
(
isJoin
)
{
if
(
isJoin
)
{
if
(
joinOuter
)
{
if
(
joinOuter
)
{
bu
ff
.
append
(
"LEFT OUTER JOIN "
);
bu
ilder
.
append
(
"LEFT OUTER JOIN "
);
}
else
{
}
else
{
bu
ff
.
append
(
"INNER JOIN "
);
bu
ilder
.
append
(
"INNER JOIN "
);
}
}
}
}
if
(
nestedJoin
!=
null
)
{
if
(
nestedJoin
!=
null
)
{
StringBuilder
buffNested
=
new
StringBuilder
();
StringBuilder
buffNested
=
new
StringBuilder
();
TableFilter
n
=
nestedJoin
;
TableFilter
n
=
nestedJoin
;
do
{
do
{
buffNested
.
append
(
n
.
getPlanSQL
(
n
!=
nestedJoin
));
n
.
getPlanSQL
(
buffNested
,
n
!=
nestedJoin
).
append
(
'\n'
);
buffNested
.
append
(
'\n'
);
n
=
n
.
getJoin
();
n
=
n
.
getJoin
();
}
while
(
n
!=
null
);
}
while
(
n
!=
null
);
String
nested
=
buffNested
.
toString
();
String
nested
=
buffNested
.
toString
();
boolean
enclose
=
!
nested
.
startsWith
(
"("
);
boolean
enclose
=
!
nested
.
startsWith
(
"("
);
if
(
enclose
)
{
if
(
enclose
)
{
bu
ff
.
append
(
"(\n"
);
bu
ilder
.
append
(
"(\n"
);
}
}
StringUtils
.
indent
(
bu
ff
,
nested
,
4
,
false
);
StringUtils
.
indent
(
bu
ilder
,
nested
,
4
,
false
);
if
(
enclose
)
{
if
(
enclose
)
{
bu
ff
.
append
(
')'
);
bu
ilder
.
append
(
')'
);
}
}
if
(
isJoin
)
{
if
(
isJoin
)
{
bu
ff
.
append
(
" ON "
);
bu
ilder
.
append
(
" ON "
);
if
(
joinCondition
==
null
)
{
if
(
joinCondition
==
null
)
{
// need to have a ON expression,
// need to have a ON expression,
// otherwise the nesting is unclear
// otherwise the nesting is unclear
bu
ff
.
append
(
"1=1"
);
bu
ilder
.
append
(
"1=1"
);
}
else
{
}
else
{
joinCondition
.
getUnenclosedSQL
(
bu
ff
);
joinCondition
.
getUnenclosedSQL
(
bu
ilder
);
}
}
}
}
return
bu
ff
.
toString
()
;
return
bu
ilder
;
}
}
if
(
table
.
isView
()
&&
((
TableView
)
table
).
isRecursive
())
{
if
(
table
.
isView
()
&&
((
TableView
)
table
).
isRecursive
())
{
bu
ff
.
append
(
table
.
getSchema
().
getSQL
()).
append
(
'.'
).
append
(
Parser
.
quoteIdentifier
(
table
.
getName
()));
bu
ilder
.
append
(
table
.
getSchema
().
getSQL
()).
append
(
'.'
).
append
(
Parser
.
quoteIdentifier
(
table
.
getName
()));
}
else
{
}
else
{
bu
ff
.
append
(
table
.
getSQL
());
bu
ilder
.
append
(
table
.
getSQL
());
}
}
if
(
table
.
isView
()
&&
((
TableView
)
table
).
isInvalid
())
{
if
(
table
.
isView
()
&&
((
TableView
)
table
).
isInvalid
())
{
throw
DbException
.
get
(
ErrorCode
.
VIEW_IS_INVALID_2
,
table
.
getName
(),
"not compiled"
);
throw
DbException
.
get
(
ErrorCode
.
VIEW_IS_INVALID_2
,
table
.
getName
(),
"not compiled"
);
}
}
if
(
alias
!=
null
)
{
if
(
alias
!=
null
)
{
bu
ff
.
append
(
' '
).
append
(
Parser
.
quoteIdentifier
(
alias
));
bu
ilder
.
append
(
' '
).
append
(
Parser
.
quoteIdentifier
(
alias
));
}
}
if
(
indexHints
!=
null
)
{
if
(
indexHints
!=
null
)
{
bu
ff
.
append
(
" USE INDEX ("
);
bu
ilder
.
append
(
" USE INDEX ("
);
boolean
first
=
true
;
boolean
first
=
true
;
for
(
String
index
:
indexHints
.
getAllowedIndexes
())
{
for
(
String
index
:
indexHints
.
getAllowedIndexes
())
{
if
(!
first
)
{
if
(!
first
)
{
bu
ff
.
append
(
", "
);
bu
ilder
.
append
(
", "
);
}
else
{
}
else
{
first
=
false
;
first
=
false
;
}
}
bu
ff
.
append
(
Parser
.
quoteIdentifier
(
index
));
bu
ilder
.
append
(
Parser
.
quoteIdentifier
(
index
));
}
}
bu
ff
.
append
(
")"
);
bu
ilder
.
append
(
")"
);
}
}
if
(
index
!=
null
)
{
if
(
index
!=
null
)
{
bu
ff
.
append
(
'\n'
);
bu
ilder
.
append
(
'\n'
);
StatementBuilder
planBuff
=
new
StatementBuilder
();
StatementBuilder
planBuff
=
new
StatementBuilder
();
if
(
joinBatch
!=
null
)
{
if
(
joinBatch
!=
null
)
{
IndexLookupBatch
lookupBatch
=
joinBatch
.
getLookupBatch
(
joinFilterId
);
IndexLookupBatch
lookupBatch
=
joinBatch
.
getLookupBatch
(
joinFilterId
);
...
@@ -842,28 +842,28 @@ public class TableFilter implements ColumnResolver {
...
@@ -842,28 +842,28 @@ public class TableFilter implements ColumnResolver {
if
(
plan
.
indexOf
(
'\n'
)
>=
0
)
{
if
(
plan
.
indexOf
(
'\n'
)
>=
0
)
{
plan
+=
"\n"
;
plan
+=
"\n"
;
}
}
StringUtils
.
indent
(
bu
ff
,
"/* "
+
plan
+
" */"
,
4
,
false
);
StringUtils
.
indent
(
bu
ilder
,
"/* "
+
plan
+
" */"
,
4
,
false
);
}
}
if
(
isJoin
)
{
if
(
isJoin
)
{
bu
ff
.
append
(
"\n ON "
);
bu
ilder
.
append
(
"\n ON "
);
if
(
joinCondition
==
null
)
{
if
(
joinCondition
==
null
)
{
// need to have a ON expression, otherwise the nesting is
// need to have a ON expression, otherwise the nesting is
// unclear
// unclear
bu
ff
.
append
(
"1=1"
);
bu
ilder
.
append
(
"1=1"
);
}
else
{
}
else
{
joinCondition
.
getUnenclosedSQL
(
bu
ff
);
joinCondition
.
getUnenclosedSQL
(
bu
ilder
);
}
}
}
}
if
(
filterCondition
!=
null
)
{
if
(
filterCondition
!=
null
)
{
bu
ff
.
append
(
'\n'
);
bu
ilder
.
append
(
'\n'
);
String
condition
=
StringUtils
.
unEnclose
(
filterCondition
.
getSQL
());
String
condition
=
StringUtils
.
unEnclose
(
filterCondition
.
getSQL
());
condition
=
"/* WHERE "
+
StringUtils
.
quoteRemarkSQL
(
condition
)
+
"\n*/"
;
condition
=
"/* WHERE "
+
StringUtils
.
quoteRemarkSQL
(
condition
)
+
"\n*/"
;
StringUtils
.
indent
(
bu
ff
,
condition
,
4
,
false
);
StringUtils
.
indent
(
bu
ilder
,
condition
,
4
,
false
);
}
}
if
(
scanCount
>
0
)
{
if
(
scanCount
>
0
)
{
bu
ff
.
append
(
"\n /* scanCount: "
).
append
(
scanCount
).
append
(
" */"
);
bu
ilder
.
append
(
"\n /* scanCount: "
).
append
(
scanCount
).
append
(
" */"
);
}
}
return
bu
ff
.
toString
()
;
return
bu
ilder
;
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论