Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
14e92665
提交
14e92665
authored
6 年前
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Evaluate offset expression together with limit expression in Select
上级
27a74b26
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
30 行增加
和
22 行删除
+30
-22
Select.java
h2/src/main/org/h2/command/dml/Select.java
+30
-22
没有找到文件。
h2/src/main/org/h2/command/dml/Select.java
浏览文件 @
14e92665
...
@@ -586,14 +586,12 @@ public class Select extends Query {
...
@@ -586,14 +586,12 @@ public class Select extends Query {
return
null
;
return
null
;
}
}
private
void
queryDistinct
(
ResultTarget
result
,
long
limitRows
,
boolean
withTies
)
{
private
void
queryDistinct
(
ResultTarget
result
,
long
offset
,
long
limitRows
,
boolean
withTies
)
{
// limitRows must be long, otherwise we get an int overflow
if
(
limitRows
>
0
&&
offset
>
0
)
{
// if limitRows is at or near Integer.MAX_VALUE
limitRows
+=
offset
;
// limitRows is never 0 here
if
(
limitRows
<
0
)
{
if
(
limitRows
>
0
&&
offsetExpr
!=
null
)
{
// Overflow
int
offset
=
offsetExpr
.
getValue
(
session
).
getInt
();
limitRows
=
Long
.
MAX_VALUE
;
if
(
offset
>
0
)
{
limitRows
+=
offset
;
}
}
}
}
int
rowNumber
=
0
;
int
rowNumber
=
0
;
...
@@ -627,14 +625,12 @@ public class Select extends Query {
...
@@ -627,14 +625,12 @@ public class Select extends Query {
}
}
}
}
private
LazyResult
queryFlat
(
int
columnCount
,
ResultTarget
result
,
long
limitRows
,
boolean
withTies
)
{
private
LazyResult
queryFlat
(
int
columnCount
,
ResultTarget
result
,
long
offset
,
long
limitRows
,
boolean
withTies
)
{
// limitRows must be long, otherwise we get an int overflow
if
(
limitRows
>
0
&&
offset
>
0
)
{
// if limitRows is at or near Integer.MAX_VALUE
limitRows
+=
offset
;
// limitRows is never 0 here
if
(
limitRows
<
0
)
{
if
(
limitRows
>
0
&&
offsetExpr
!=
null
)
{
// Overflow
int
offset
=
offsetExpr
.
getValue
(
session
).
getInt
();
limitRows
=
Long
.
MAX_VALUE
;
if
(
offset
>
0
)
{
limitRows
+=
offset
;
}
}
}
}
ArrayList
<
Row
>
forUpdateRows
=
this
.
isForUpdateMvcc
?
Utils
.<
Row
>
newSmallArrayList
()
:
null
;
ArrayList
<
Row
>
forUpdateRows
=
this
.
isForUpdateMvcc
?
Utils
.<
Row
>
newSmallArrayList
()
:
null
;
...
@@ -688,9 +684,18 @@ public class Select extends Query {
...
@@ -688,9 +684,18 @@ public class Select extends Query {
limitRows
=
Math
.
min
(
l
,
limitRows
);
limitRows
=
Math
.
min
(
l
,
limitRows
);
}
}
}
}
long
offset
;
if
(
offsetExpr
!=
null
)
{
offset
=
offsetExpr
.
getValue
(
session
).
getLong
();
if
(
offset
<
0
)
{
offset
=
0
;
}
}
else
{
offset
=
0
;
}
boolean
lazy
=
session
.
isLazyQueryExecution
()
&&
boolean
lazy
=
session
.
isLazyQueryExecution
()
&&
target
==
null
&&
!
isForUpdate
&&
!
isQuickAggregateQuery
&&
target
==
null
&&
!
isForUpdate
&&
!
isQuickAggregateQuery
&&
limitRows
!=
0
&&
!
withTies
&&
offset
Expr
==
null
&&
isReadOnly
();
limitRows
!=
0
&&
!
withTies
&&
offset
==
0
&&
isReadOnly
();
int
columnCount
=
expressions
.
size
();
int
columnCount
=
expressions
.
size
();
LocalResult
result
=
null
;
LocalResult
result
=
null
;
if
(!
lazy
&&
(
target
==
null
||
if
(!
lazy
&&
(
target
==
null
||
...
@@ -713,7 +718,7 @@ public class Select extends Query {
...
@@ -713,7 +718,7 @@ public class Select extends Query {
if
(
isGroupQuery
&&
!
isGroupSortedQuery
)
{
if
(
isGroupQuery
&&
!
isGroupSortedQuery
)
{
result
=
createLocalResult
(
result
);
result
=
createLocalResult
(
result
);
}
}
if
(!
lazy
&&
(
limitRows
>=
0
||
offset
Expr
!=
null
))
{
if
(!
lazy
&&
(
limitRows
>=
0
||
offset
>
0
))
{
result
=
createLocalResult
(
result
);
result
=
createLocalResult
(
result
);
}
}
topTableFilter
.
startQuery
(
session
);
topTableFilter
.
startQuery
(
session
);
...
@@ -749,9 +754,9 @@ public class Select extends Query {
...
@@ -749,9 +754,9 @@ public class Select extends Query {
queryGroup
(
columnCount
,
result
);
queryGroup
(
columnCount
,
result
);
}
}
}
else
if
(
isDistinctQuery
)
{
}
else
if
(
isDistinctQuery
)
{
queryDistinct
(
to
,
limitRows
,
withTies
);
queryDistinct
(
to
,
offset
,
limitRows
,
withTies
);
}
else
{
}
else
{
lazyResult
=
queryFlat
(
columnCount
,
to
,
limitRows
,
withTies
);
lazyResult
=
queryFlat
(
columnCount
,
to
,
offset
,
limitRows
,
withTies
);
}
}
}
finally
{
}
finally
{
if
(!
lazy
)
{
if
(!
lazy
)
{
...
@@ -770,8 +775,11 @@ public class Select extends Query {
...
@@ -770,8 +775,11 @@ public class Select extends Query {
return
lazyResult
;
return
lazyResult
;
}
}
}
}
if
(
offsetExpr
!=
null
)
{
if
(
offset
!=
0
)
{
result
.
setOffset
(
offsetExpr
.
getValue
(
session
).
getInt
());
if
(
offset
>
Integer
.
MAX_VALUE
)
{
throw
DbException
.
getInvalidValueException
(
"OFFSET"
,
offset
);
}
result
.
setOffset
((
int
)
offset
);
}
}
if
(
limitRows
>=
0
)
{
if
(
limitRows
>=
0
)
{
result
.
setLimit
(
limitRows
);
result
.
setLimit
(
limitRows
);
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论