Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f6b2ced2
Unverified
提交
f6b2ced2
authored
2月 25, 2019
作者:
Evgenij Ryazanov
提交者:
GitHub
2月 25, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1756 from katzyn/distinct_on
Fix DISTINCT ON in presence of ORDER BY
上级
f5c5d3a1
31155068
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
75 行增加
和
12 行删除
+75
-12
help.csv
h2/src/docsrc/help/help.csv
+5
-1
cheatSheet.html
h2/src/docsrc/html/cheatSheet.html
+1
-1
release.txt
h2/src/installer/release.txt
+3
-3
Select.java
h2/src/main/org/h2/command/dml/Select.java
+1
-1
MVSortedTempResult.java
h2/src/main/org/h2/mvstore/db/MVSortedTempResult.java
+26
-4
LocalResultImpl.java
h2/src/main/org/h2/result/LocalResultImpl.java
+2
-1
distinct.sql
h2/src/test/org/h2/test/scripts/distinct.sql
+36
-0
dictionary.txt
h2/src/tools/org/h2/build/doc/dictionary.txt
+1
-1
没有找到文件。
h2/src/docsrc/help/help.csv
浏览文件 @
f6b2ced2
...
...
@@ -44,7 +44,11 @@ Non-window aggregate functions are allowed in this clause.
7. QUALIFY filters rows after evaluation of window functions.
Aggregate and window functions are allowed in this clause.
8. DISTINCT removes duplicates. If DISTINCT ON is used only the specified expressions are checked for duplicates.
8. DISTINCT removes duplicates.
If DISTINCT ON is used only the specified expressions are checked for duplicates;
ORDER BY clause, if any, is used to determine preserved rows.
First row is each DISTINCT ON group is preserved.
In absence of ORDER BY preserved rows are not determined, database may choose any row from each DISTINCT ON group.
9. UNION, EXCEPT (MINUS), and INTERSECT combine the result of this query with the results of another query.
Multiple set operators (UNION, INTERSECT, MINUS, EXCEPT) are evaluated from left to right.
...
...
h2/src/docsrc/html/cheatSheet.html
浏览文件 @
f6b2ced2
...
...
@@ -148,7 +148,7 @@ Reference:
<b><a
href=
"features.html#connection_modes"
>
Embedded
</a></b><br
/>
<code>
jdbc:h2:~/test
</code>
'test' in the user home directory
<br
/>
<code>
jdbc:h2:/data/test
</code>
'test' in the directory /data
<br
/>
<code>
jdbc:h2:test
</code>
in the current(!) working directory
<br
/>
<code>
jdbc:h2:
./
test
</code>
in the current(!) working directory
<br
/>
</p><p>
<b><a
href=
"features.html#in_memory_databases"
>
In-Memory
</a></b><br
/>
<code>
jdbc:h2:mem:test
</code>
multiple connections in one process
<br
/>
...
...
h2/src/installer/release.txt
浏览文件 @
f6b2ced2
...
...
@@ -136,15 +136,15 @@ In Build.java, comment "-Xdoclint:none", but don't commit that change.
# http://central.sonatype.org/pages/ossrh-guide.html
# http://central.sonatype.org/pages/manual-staging-bundle-creation-and-deployment.html
# https://oss.sonatype.org/#welcome - Log In "t..."
#
sometimes this doesn't work reliably and you will have to retry
#
sometimes this doesn't work reliably and you will have to retry
# - Staging Upload
# - Upload Mode: Artifact Bundle, Select Bundle to Upload... - /data/h2database/.../h2/.../bundle.jar
# - Upload Bundle
#
- Staging Repositories - Refresh - select comh2database-<...> - Release - Confirm
#
- Staging Repositories - Refresh - select comh2database-<...> - Release - Confirm
# - Staging Upload
# - Upload Mode: Artifact Bundle, Select Bundle to Upload... - /data/h2database/.../h2-mvstore/.../bundle.jar
# - Upload Bundle
#
- Staging Repositories - Refresh - select comh2database-<...> - Release - Confirm
#
- Staging Repositories - Refresh - select comh2database-<...> - Release - Confirm
Update statistics.
...
...
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
f6b2ced2
...
...
@@ -1825,7 +1825,7 @@ public class Select extends Query {
@Override
public
boolean
allowGlobalConditions
()
{
return
offsetExpr
==
null
&&
(
limitExpr
==
null
||
sort
==
null
);
return
offsetExpr
==
null
&&
(
limitExpr
==
null
&&
distinctExpressions
==
null
||
sort
==
null
);
}
public
SortOrder
getSortOrder
()
{
...
...
h2/src/main/org/h2/mvstore/db/MVSortedTempResult.java
浏览文件 @
f6b2ced2
...
...
@@ -56,7 +56,12 @@ class MVSortedTempResult extends MVTempResult {
* {@link #contains(Value[])} method is invoked. Only the root result should
* have an index if required.
*/
private
MVMap
<
ValueRow
,
Boolean
>
index
;
private
MVMap
<
ValueRow
,
Object
>
index
;
/**
* Used for DISTINCT ON in presence of ORDER BY.
*/
private
ValueDataType
orderedDistinctOnType
;
/**
* Cursor for the {@link #next()} method.
...
...
@@ -172,7 +177,11 @@ class MVSortedTempResult extends MVTempResult {
if
(
distinct
&&
length
!=
visibleColumnCount
||
distinctIndexes
!=
null
)
{
int
count
=
distinctIndexes
!=
null
?
distinctIndexes
.
length
:
visibleColumnCount
;
ValueDataType
distinctType
=
new
ValueDataType
(
database
,
new
int
[
count
]);
Builder
<
ValueRow
,
Boolean
>
indexBuilder
=
new
MVMap
.
Builder
<
ValueRow
,
Boolean
>().
keyType
(
distinctType
);
Builder
<
ValueRow
,
Object
>
indexBuilder
=
new
MVMap
.
Builder
<
ValueRow
,
Object
>().
keyType
(
distinctType
);
if
(
distinctIndexes
!=
null
&&
sort
!=
null
)
{
indexBuilder
.
valueType
(
keyType
);
orderedDistinctOnType
=
keyType
;
}
index
=
store
.
openMap
(
"idx"
,
indexBuilder
);
}
}
...
...
@@ -189,8 +198,21 @@ class MVSortedTempResult extends MVTempResult {
newValues
[
i
]
=
values
[
distinctIndexes
[
i
]];
}
ValueRow
distinctRow
=
ValueRow
.
get
(
newValues
);
if
(
index
.
putIfAbsent
(
distinctRow
,
true
)
!=
null
)
{
return
rowCount
;
if
(
orderedDistinctOnType
==
null
)
{
if
(
index
.
putIfAbsent
(
distinctRow
,
true
)
!=
null
)
{
return
rowCount
;
}
}
else
{
ValueRow
previous
=
(
ValueRow
)
index
.
get
(
distinctRow
);
if
(
previous
==
null
)
{
index
.
put
(
distinctRow
,
key
);
}
else
if
(
orderedDistinctOnType
.
compare
(
previous
,
key
)
>
0
)
{
map
.
remove
(
previous
);
rowCount
--;
index
.
put
(
distinctRow
,
key
);
}
else
{
return
rowCount
;
}
}
}
else
if
(
expressions
.
length
!=
visibleColumnCount
)
{
ValueRow
distinctRow
=
ValueRow
.
get
(
Arrays
.
copyOf
(
values
,
visibleColumnCount
));
...
...
h2/src/main/org/h2/result/LocalResultImpl.java
浏览文件 @
f6b2ced2
...
...
@@ -316,7 +316,8 @@ public class LocalResultImpl implements LocalResult {
if
(
isAnyDistinct
())
{
if
(
distinctRows
!=
null
)
{
ValueRow
array
=
getDistinctRow
(
values
);
if
(!
distinctRows
.
containsKey
(
array
))
{
Value
[]
previous
=
distinctRows
.
get
(
array
);
if
(
previous
==
null
||
sort
!=
null
&&
sort
.
compare
(
previous
,
values
)
>
0
)
{
distinctRows
.
put
(
array
,
values
);
}
rowCount
=
distinctRows
.
size
();
...
...
h2/src/test/org/h2/test/scripts/distinct.sql
浏览文件 @
f6b2ced2
...
...
@@ -144,6 +144,42 @@ SELECT DISTINCT ON(C1) C2 FROM TEST ORDER BY C1;
>
4
>
rows
(
ordered
):
3
SELECT
DISTINCT
ON
(
C1
)
C1
,
C4
,
C5
FROM
TEST
ORDER
BY
C1
,
C5
;
>
C1
C4
C5
>
-- -- --
>
1
4
5
>
2
8
9
>
3
1
1
>
rows
(
ordered
):
3
SELECT
DISTINCT
ON
(
C1
)
C1
,
C4
,
C5
FROM
TEST
ORDER
BY
C1
,
C5
DESC
;
>
C1
C4
C5
>
-- -- --
>
1
6
7
>
2
8
9
>
3
1
1
>
rows
(
ordered
):
3
SELECT
T1
.
C1
,
T2
.
C5
FROM
TEST
T1
JOIN
(
SELECT
DISTINCT
ON
(
C1
)
C1
,
C4
,
C5
FROM
TEST
ORDER
BY
C1
,
C5
)
T2
ON
T1
.
C4
=
T2
.
C4
ORDER
BY
T1
.
C1
;
>
C1
C5
>
-- --
>
1
5
>
2
9
>
3
1
>
rows
(
ordered
):
3
SELECT
T1
.
C1
,
T2
.
C5
FROM
TEST
T1
JOIN
(
SELECT
DISTINCT
ON
(
C1
)
C1
,
C4
,
C5
FROM
TEST
ORDER
BY
C1
,
C5
DESC
)
T2
ON
T1
.
C4
=
T2
.
C4
ORDER
BY
T1
.
C1
;
>
C1
C5
>
-- --
>
1
7
>
2
9
>
3
1
>
rows
(
ordered
):
3
EXPLAIN
SELECT
DISTINCT
ON
(
C1
)
C2
FROM
TEST
ORDER
BY
C1
;
>>
SELECT
DISTINCT
ON
(
C1
)
C2
FROM
PUBLIC
.
TEST
/* PUBLIC.TEST.tableScan */
ORDER
BY
=
C1
...
...
h2/src/tools/org/h2/build/doc/dictionary.txt
浏览文件 @
f6b2ced2
...
...
@@ -809,4 +809,4 @@ preserves masking holder unboxing avert iae transformed subtle reevaluate exclus
presorted inclusion contexts aax mwd percentile cont interpolate mwa hypothetical regproc childed listagg foreground
isodow isoyear psql
waiters
\ No newline at end of file
waiters reliably httpsdocs privileged
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论