提交 6bca6ae1 编写于 作者: T terrymanu

for #2441, remove index for LimitValue

上级 18dec77a
......@@ -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().getRevisedIndexAndParameters(isNeedFetchAll, databaseType.name()));
parameterBuilder.getReplacedIndexAndParameters().putAll(sqlRouteResult.getLimit().getRevisedParameters(isNeedFetchAll, databaseType.name()));
}
}
......@@ -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 {
}
/**
* Revise parameters.
* Get revise parameters.
*
* @param isFetchAll is fetch all data or not
* @param databaseType database type
* @return revised indexes and parameters
* @return revised parameters and parameters' indexes
*/
public Map<Integer, Object> getRevisedIndexAndParameters(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.getIndex() > -1) {
result.put(rowCount.getIndex(), rewriteRowCount);
if (null != rowCount && rowCount.getLimitValueSegment() 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.
*
......
......@@ -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
*/
@AllArgsConstructor
@RequiredArgsConstructor
@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.
先完成此消息的编辑!
想要评论请 注册