提交 eb2fc137 authored 作者: Noel Grandin's avatar Noel Grandin

Issue #401: NPE in "SELECT DISTINCT * ORDER BY"

上级 e3351bf0
......@@ -21,6 +21,8 @@ Change Log
<h2>Next Version (unreleased)</h2>
<ul>
<li>Issue #401: NPE in "SELECT DISTINCT * ORDER BY"
</li>
<li>Added BITGET function
</li>
<li>Fixed bug in FilePathRetryOnInterrupt that caused infinite loop
......
......@@ -7,7 +7,6 @@ package org.h2.result;
import java.util.ArrayList;
import java.util.Arrays;
import org.h2.command.ddl.CreateTableData;
import org.h2.engine.Constants;
import org.h2.engine.Database;
......@@ -88,7 +87,9 @@ public class ResultTempTable implements ResultExternal {
private void createIndex() {
IndexColumn[] indexCols = null;
if (sort != null) {
// If we need to do distinct, the distinct columns may not match the sort columns
// so we need to disregard the sort. Not ideal.
if (sort != null && !distinct) {
int[] colIndex = sort.getQueryColumnIndexes();
indexCols = new IndexColumn[colIndex.length];
for (int i = 0; i < colIndex.length; i++) {
......
......@@ -74,4 +74,9 @@ public class IndexColumn {
col.column = table.getColumn(col.columnName);
}
}
@Override
public String toString() {
return "IndexColumn " + getSQL();
}
}
......@@ -10,7 +10,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.api.ErrorCode;
import org.h2.engine.Constants;
import org.h2.store.fs.FileUtils;
......@@ -48,6 +47,7 @@ public class TestTempTables extends TestBase {
c1.close();
c2.close();
testLotsOfTables();
testCreateAsSelectDistinct();
deleteDb("tempTables");
}
......@@ -333,4 +333,24 @@ public class TestTempTables extends TestBase {
}
conn.close();
}
/**
* Issue #401: NPE in "SELECT DISTINCT * ORDER BY"
*/
private void testCreateAsSelectDistinct() throws SQLException {
deleteDb("tempTables");
Connection conn = getConnection("tempTables;MAX_MEMORY_ROWS=1000");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE ONE(S1 VARCHAR(255), S2 VARCHAR(255))");
PreparedStatement prep = conn
.prepareStatement("insert into one values(?,?)");
for (int row = 0; row < 10000; row++) {
prep.setString(1, "abc");
prep.setString(2, "def" + row);
prep.execute();
}
stat.execute(
"CREATE TABLE TWO AS SELECT DISTINCT * FROM ONE ORDER BY S1");
conn.close();
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论