提交 26000a01 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix WITH TIES for data types without total ordering

上级 b5737548
...@@ -405,15 +405,8 @@ public class LocalResult implements ResultInterface, ResultTarget { ...@@ -405,15 +405,8 @@ public class LocalResult implements ResultInterface, ResultTarget {
} }
int to = offset + limit; int to = offset + limit;
if (withTies && sort != null) { if (withTies && sort != null) {
int[] indexes = sort.getQueryColumnIndexes();
Value[] expected = rows.get(to - 1); Value[] expected = rows.get(to - 1);
loop: while (to < rows.size()) { while (to < rows.size() && sort.compare(expected, rows.get(to)) == 0) {
Value[] current = rows.get(to);
for (int idx : indexes) {
if (!expected[idx].equals(current[idx])) {
break loop;
}
}
to++; to++;
rowCount++; rowCount++;
} }
...@@ -446,14 +439,8 @@ public class LocalResult implements ResultInterface, ResultTarget { ...@@ -446,14 +439,8 @@ public class LocalResult implements ResultInterface, ResultTarget {
} }
} }
if (withTies && sort != null && row != null) { if (withTies && sort != null && row != null) {
int[] indexes = sort.getQueryColumnIndexes();
Value[] expected = row; Value[] expected = row;
loop: while ((row = temp.next()) != null) { while ((row = temp.next()) != null && sort.compare(expected, row) == 0) {
for (int idx : indexes) {
if (!expected[idx].equals(row[idx])) {
break loop;
}
}
rows.add(row); rows.add(row);
rowCount++; rowCount++;
if (rows.size() > maxMemoryRows) { if (rows.size() > maxMemoryRows) {
......
...@@ -131,3 +131,20 @@ EXPLAIN SELECT * FROM TEST ORDER BY A, B OFFSET 3 ROWS FETCH NEXT 1 ROW WITH TIE ...@@ -131,3 +131,20 @@ EXPLAIN SELECT * FROM TEST ORDER BY A, B OFFSET 3 ROWS FETCH NEXT 1 ROW WITH TIE
DROP TABLE TEST; DROP TABLE TEST;
> ok > ok
CREATE TABLE TEST(A NUMERIC, B NUMERIC);
> ok
INSERT INTO TEST VALUES (0, 1), (0.0, 2), (0, 3), (1, 4);
> update count: 4
SELECT A, B FROM TEST ORDER BY A FETCH FIRST 1 ROW WITH TIES;
> A B
> --- -
> 0 1
> 0 3
> 0.0 2
> rows: 3
DROP TABLE TEST;
> ok
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论