Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
6bca6ae1
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6bca6ae1
编写于
6月 05, 2019
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
for #2441, remove index for LimitValue
上级
18dec77a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
21 addition
and
32 deletion
+21
-32
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/rewriter/parameter/ShardingParameterRewriter.java
...rewrite/rewriter/parameter/ShardingParameterRewriter.java
+1
-1
sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/limit/Limit.java
...ava/org/apache/shardingsphere/core/route/limit/Limit.java
+16
-21
sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/limit/LimitValue.java
...rg/apache/shardingsphere/core/route/limit/LimitValue.java
+4
-10
未找到文件。
sharding-core/sharding-core-rewrite/src/main/java/org/apache/shardingsphere/core/rewrite/rewriter/parameter/ShardingParameterRewriter.java
浏览文件 @
6bca6ae1
...
...
@@ -44,6 +44,6 @@ public final class ShardingParameterRewriter implements ParameterRewriter {
private
void
rewriteLimit
(
final
SelectStatement
selectStatement
,
final
ParameterBuilder
parameterBuilder
)
{
boolean
isNeedFetchAll
=
(!
selectStatement
.
getGroupByItems
().
isEmpty
()
||
!
selectStatement
.
getAggregationSelectItems
().
isEmpty
())
&&
!
selectStatement
.
isSameGroupByAndOrderByItems
();
parameterBuilder
.
getReplacedIndexAndParameters
().
putAll
(
sqlRouteResult
.
getLimit
().
getRevised
IndexAnd
Parameters
(
isNeedFetchAll
,
databaseType
.
name
()));
parameterBuilder
.
getReplacedIndexAndParameters
().
putAll
(
sqlRouteResult
.
getLimit
().
getRevisedParameters
(
isNeedFetchAll
,
databaseType
.
name
()));
}
}
sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/limit/Limit.java
浏览文件 @
6bca6ae1
...
...
@@ -18,7 +18,6 @@
package
org.apache.shardingsphere.core.route.limit
;
import
lombok.Getter
;
import
lombok.ToString
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.NumberLiteralLimitValueSegment
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.ParameterMarkerLimitValueSegment
;
...
...
@@ -28,14 +27,13 @@ import java.util.List;
import
java.util.Map
;
/**
* Limit
object
.
* Limit.
*
* @author zhangliang
* @author caohao
* @author zhangyonglun
*/
@Getter
@ToString
public
final
class
Limit
{
private
final
LimitValue
offset
;
...
...
@@ -50,8 +48,7 @@ public final class Limit {
private
LimitValue
createLimitValue
(
final
LimitValueSegment
limitValueSegment
,
final
List
<
Object
>
parameters
)
{
int
segmentValue
=
limitValueSegment
instanceof
ParameterMarkerLimitValueSegment
?
(
int
)
parameters
.
get
(((
ParameterMarkerLimitValueSegment
)
limitValueSegment
).
getParameterIndex
())
:
((
NumberLiteralLimitValueSegment
)
limitValueSegment
).
getValue
();
int
index
=
limitValueSegment
instanceof
ParameterMarkerLimitValueSegment
?
((
ParameterMarkerLimitValueSegment
)
limitValueSegment
).
getParameterIndex
()
:
-
1
;
return
new
LimitValue
(
segmentValue
,
index
,
limitValueSegment
);
return
new
LimitValue
(
limitValueSegment
,
segmentValue
);
}
/**
...
...
@@ -73,32 +70,30 @@ public final class Limit {
}
/**
*
R
evise parameters.
*
Get r
evise parameters.
*
* @param isFetchAll is fetch all data or not
* @param databaseType database type
* @return revised
indexes and parameter
s
* @return revised
parameters and parameters' indexe
s
*/
public
Map
<
Integer
,
Object
>
getRevised
IndexAnd
Parameters
(
final
boolean
isFetchAll
,
final
String
databaseType
)
{
public
Map
<
Integer
,
Object
>
getRevisedParameters
(
final
boolean
isFetchAll
,
final
String
databaseType
)
{
Map
<
Integer
,
Object
>
result
=
new
HashMap
<>(
2
,
1
);
int
rewriteOffset
=
0
;
int
rewriteRowCount
;
if
(
isFetchAll
)
{
rewriteRowCount
=
Integer
.
MAX_VALUE
;
}
else
if
(
isNeedRewriteRowCount
(
databaseType
))
{
rewriteRowCount
=
null
==
rowCount
?
-
1
:
getOffsetValue
()
+
rowCount
.
getValue
();
}
else
{
rewriteRowCount
=
rowCount
.
getValue
();
}
if
(
null
!=
offset
&&
offset
.
getIndex
()
>
-
1
)
{
result
.
put
(
offset
.
getIndex
(),
rewriteOffset
);
if
(
null
!=
offset
&&
offset
.
getLimitValueSegment
()
instanceof
ParameterMarkerLimitValueSegment
)
{
result
.
put
(((
ParameterMarkerLimitValueSegment
)
offset
.
getLimitValueSegment
()).
getParameterIndex
(),
0
);
}
if
(
null
!=
rowCount
&&
rowCount
.
get
Index
()
>
-
1
)
{
result
.
put
(
rowCount
.
getIndex
(),
rewriteRowCount
);
if
(
null
!=
rowCount
&&
rowCount
.
get
LimitValueSegment
()
instanceof
ParameterMarkerLimitValueSegment
)
{
result
.
put
(
((
ParameterMarkerLimitValueSegment
)
rowCount
.
getLimitValueSegment
()).
getParameterIndex
(),
getRewriteRowCount
(
isFetchAll
,
databaseType
)
);
}
return
result
;
}
private
int
getRewriteRowCount
(
final
boolean
isFetchAll
,
final
String
databaseType
)
{
if
(
isFetchAll
)
{
return
Integer
.
MAX_VALUE
;
}
return
isNeedRewriteRowCount
(
databaseType
)
?
getOffsetValue
()
+
rowCount
.
getValue
()
:
rowCount
.
getValue
();
}
/**
* Judge is need rewrite row count or not.
*
...
...
sharding-core/sharding-core-route/src/main/java/org/apache/shardingsphere/core/route/limit/LimitValue.java
浏览文件 @
6bca6ae1
...
...
@@ -17,10 +17,8 @@
package
org.apache.shardingsphere.core.route.limit
;
import
lombok.AllArgsConstructor
;
import
lombok.Getter
;
import
lombok.Setter
;
import
lombok.ToString
;
import
lombok.RequiredArgsConstructor
;
import
org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitValueSegment
;
/**
...
...
@@ -28,15 +26,11 @@ import org.apache.shardingsphere.core.parse.sql.segment.dml.limit.LimitValueSegm
*
* @author zhangliang
*/
@
All
ArgsConstructor
@
Required
ArgsConstructor
@Getter
@Setter
@ToString
public
final
class
LimitValue
{
private
int
value
;
private
final
LimitValueSegment
limitValueSegment
;
private
int
index
;
private
LimitValueSegment
limitValueSegment
;
private
final
int
value
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录