mirror of
https://github.com/alibaba/druid.git
synced 2023-03-04 19:17:16 +00:00
improved PageUtils.hasUnorderedLimit.
This commit is contained in:
@@ -527,7 +527,22 @@ public class PagerUtils {
|
||||
SQLLimit limit = x.getLimit();
|
||||
|
||||
if (limit != null && (orderBy == null || orderBy.getItems().size() == 0)) {
|
||||
unorderedLimitCount++;
|
||||
boolean subQueryHasOrderBy = false;
|
||||
SQLTableSource from = x.getFrom();
|
||||
if (from instanceof SQLSubqueryTableSource) {
|
||||
SQLSubqueryTableSource subqueryTabSrc = (SQLSubqueryTableSource) from;
|
||||
SQLSelect select = subqueryTabSrc.getSelect();
|
||||
if (select.getQuery() instanceof SQLSelectQueryBlock) {
|
||||
SQLSelectQueryBlock subquery = (SQLSelectQueryBlock) select.getQuery();
|
||||
if (subquery.getOrderBy() != null && subquery.getOrderBy().getItems().size() > 0) {
|
||||
subQueryHasOrderBy = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!subQueryHasOrderBy) {
|
||||
unorderedLimitCount++;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,4 +26,9 @@ public class PagerUtilsTest_hasUnorderedLimit extends TestCase {
|
||||
String sql = "select * from(select * from test t limit 3) x";
|
||||
assertTrue(PagerUtils.hasUnorderedLimit(sql, JdbcConstants.MYSQL));
|
||||
}
|
||||
|
||||
public void test_true_subquery_2() throws Exception {
|
||||
String sql = "select * from (select * from test t order by id desc) z limit 100";
|
||||
assertFalse(PagerUtils.hasUnorderedLimit(sql, JdbcConstants.MYSQL));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user