提交 995ae3c4 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Allow usage of SAMPLE_SIZE together with OFFSET / FETCH

上级 ea6ce813
......@@ -10,10 +10,10 @@ FROM tableExpression [,...] [ WHERE expression ]
[ GROUP BY expression [,...] ] [ HAVING expression ]
[ { UNION [ ALL ] | MINUS | EXCEPT | INTERSECT } select ]
[ ORDER BY order [,...] ]
[ { LIMIT expression [ OFFSET expression ] [ SAMPLE_SIZE rowCountInt ] }
| { [ OFFSET expression { ROW | ROWS } ]
[ { { LIMIT expression [ OFFSET expression ] }
| { [ OFFSET expression { ROW | ROWS } ]
[ FETCH { FIRST | NEXT } [ expression [ PERCENT ] ] { ROW | ROWS }
{ ONLY | WITH TIES } ] } ]
{ ONLY | WITH TIES } ] } } [ SAMPLE_SIZE rowCountInt ] ]
[ FOR UPDATE ]
","
Selects data from a table or multiple tables.
......
......@@ -2361,7 +2361,7 @@ public class Parser {
// make sure aggregate functions will not work here
Select temp = currentSelect;
currentSelect = null;
// http://sqlpro.developpez.com/SQL2008/
// Standard SQL OFFSET / FETCH
if (readIf(OFFSET)) {
command.setOffset(readExpression().optimize(session));
if (!readIf("ROW")) {
......@@ -2391,11 +2391,8 @@ public class Parser {
read("ONLY");
}
}
currentSelect = temp;
// MySQL-style LIMIT / OFFSET
if (readIf(LIMIT)) {
temp = currentSelect;
// make sure aggregate functions will not work here
currentSelect = null;
Expression limit = readExpression().optimize(session);
command.setLimit(limit);
if (readIf(OFFSET)) {
......@@ -2408,12 +2405,12 @@ public class Parser {
command.setOffset(offset);
command.setLimit(limit);
}
}
if (readIf("SAMPLE_SIZE")) {
Expression sampleSize = readExpression().optimize(session);
command.setSampleSize(sampleSize);
}
currentSelect = temp;
}
if (readIf(FOR)) {
if (readIf("UPDATE")) {
if (readIf("OF")) {
......
......@@ -115,14 +115,13 @@ public class Analyze extends DefineCommand {
}
buff.append(" FROM ").append(table.getSQL());
if (sample > 0) {
buff.append(" LIMIT ? SAMPLE_SIZE ? ");
buff.append(" FETCH NEXT ROW ONLY SAMPLE_SIZE ? ");
}
String sql = buff.toString();
Prepared command = session.prepare(sql);
if (sample > 0) {
ArrayList<Parameter> params = command.getParameters();
params.get(0).setValue(ValueInt.get(1));
params.get(1).setValue(ValueInt.get(sample));
params.get(0).setValue(ValueInt.get(sample));
}
ResultInterface result = command.query(0);
result.next();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论