Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
acd95c24
提交
acd95c24
authored
6 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Convert results to distinct where needed in safe way
上级
edf9f2d7
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
48 行增加
和
18 行删除
+48
-18
Parser.java
h2/src/main/org/h2/command/Parser.java
+1
-1
Query.java
h2/src/main/org/h2/command/dml/Query.java
+8
-4
Select.java
h2/src/main/org/h2/command/dml/Select.java
+27
-4
SelectUnion.java
h2/src/main/org/h2/command/dml/SelectUnion.java
+11
-6
ConditionInSelect.java
h2/src/main/org/h2/expression/ConditionInSelect.java
+1
-3
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
acd95c24
...
...
@@ -2535,7 +2535,7 @@ public class Parser {
}
currentSelect
=
temp
;
if
(
readIf
(
DISTINCT
))
{
command
.
setDistinct
(
true
);
command
.
setDistinct
();
}
else
{
readIf
(
ALL
);
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/dml/Query.java
浏览文件 @
acd95c24
...
...
@@ -255,13 +255,17 @@ public abstract class Query extends Prepared {
/**
* Set the distinct flag.
*
* @param b the new value
*/
public
void
setDistinct
(
boolean
b
)
{
distinct
=
b
;
public
void
setDistinct
()
{
distinct
=
true
;
}
/**
* Set the distinct flag only if it is possible, may be used as a possible
* optimization only.
*/
public
abstract
void
setDistinctIfPossible
();
public
boolean
isDistinct
()
{
return
distinct
;
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
acd95c24
...
...
@@ -247,6 +247,13 @@ public class Select extends Query {
return
orderList
!=
null
||
sort
!=
null
;
}
@Override
public
void
setDistinctIfPossible
()
{
if
(!
distinct
&&
offsetExpr
==
null
&&
limitExpr
==
null
)
{
setDistinct
();
}
}
/**
* Add a condition to the list of conditions.
*
...
...
@@ -667,9 +674,6 @@ public class Select extends Query {
result
=
createLocalResult
(
result
);
result
.
setDistinct
();
}
if
(
randomAccessResult
)
{
result
=
createLocalResult
(
result
);
}
if
(
isGroupQuery
&&
!
isGroupSortedQuery
)
{
result
=
createLocalResult
(
result
);
}
...
...
@@ -724,7 +728,11 @@ public class Select extends Query {
if
(
limitRows
>
0
)
{
lazyResult
.
setLimit
(
limitRows
);
}
return
lazyResult
;
if
(
randomAccessResult
)
{
return
convertToDistinct
(
lazyResult
);
}
else
{
return
lazyResult
;
}
}
if
(
offsetExpr
!=
null
)
{
result
.
setOffset
(
offsetExpr
.
getValue
(
session
).
getInt
());
...
...
@@ -734,6 +742,9 @@ public class Select extends Query {
}
if
(
result
!=
null
)
{
result
.
done
();
if
(
randomAccessResult
&&
!
distinct
)
{
result
=
convertToDistinct
(
result
);
}
if
(
target
!=
null
)
{
while
(
result
.
next
())
{
target
.
addRow
(
result
.
currentRow
());
...
...
@@ -761,6 +772,18 @@ public class Select extends Query {
visibleColumnCount
);
}
private
LocalResult
convertToDistinct
(
ResultInterface
result
)
{
LocalResult
distinctResult
=
new
LocalResult
(
session
,
expressionArray
,
visibleColumnCount
);
distinctResult
.
setDistinct
();
result
.
reset
();
while
(
result
.
next
())
{
distinctResult
.
addRow
(
result
.
currentRow
());
}
result
.
close
();
distinctResult
.
done
();
return
distinctResult
;
}
private
void
expandColumnList
()
{
Database
db
=
session
.
getDatabase
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/command/dml/SelectUnion.java
浏览文件 @
acd95c24
...
...
@@ -125,6 +125,11 @@ public class SelectUnion extends Query {
return
orderList
!=
null
||
sort
!=
null
;
}
@Override
public
void
setDistinctIfPossible
()
{
setDistinct
();
}
private
Value
[]
convert
(
Value
[]
values
,
int
columnCount
)
{
Value
[]
newValues
;
if
(
columnCount
==
values
.
length
)
{
...
...
@@ -210,8 +215,8 @@ public class SelectUnion extends Query {
result
.
setSortOrder
(
sort
);
}
if
(
distinct
)
{
left
.
setDistinct
(
true
);
right
.
setDistinct
(
true
);
left
.
setDistinct
IfPossible
(
);
right
.
setDistinct
IfPossible
(
);
result
.
setDistinct
();
}
if
(
randomAccessResult
)
{
...
...
@@ -220,15 +225,15 @@ public class SelectUnion extends Query {
switch
(
unionType
)
{
case
UNION:
case
EXCEPT:
left
.
setDistinct
(
true
);
right
.
setDistinct
(
true
);
left
.
setDistinct
IfPossible
(
);
right
.
setDistinct
IfPossible
(
);
result
.
setDistinct
();
break
;
case
UNION_ALL:
break
;
case
INTERSECT:
left
.
setDistinct
(
true
);
right
.
setDistinct
(
true
);
left
.
setDistinct
IfPossible
(
);
right
.
setDistinct
IfPossible
(
);
break
;
default
:
DbException
.
throwInternalError
(
"type="
+
unionType
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/expression/ConditionInSelect.java
浏览文件 @
acd95c24
...
...
@@ -43,9 +43,7 @@ public class ConditionInSelect extends Condition {
@Override
public
Value
getValue
(
Session
session
)
{
query
.
setSession
(
session
);
if
(!
query
.
hasOrder
())
{
query
.
setDistinct
(
true
);
}
query
.
setDistinctIfPossible
();
ResultInterface
rows
=
query
.
query
(
0
);
Value
l
=
left
.
getValue
(
session
);
if
(!
rows
.
hasNext
())
{
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论