提交 e02fad72 authored 作者: Thomas Mueller's avatar Thomas Mueller

The sorted insert mode did not work for not-persisted tables in a persisted…

The sorted insert mode did not work for not-persisted tables in a persisted database. It threw a ClassCastException.
上级 b9733170
......@@ -12,13 +12,12 @@ import org.h2.command.Command;
import org.h2.command.CommandInterface;
import org.h2.command.Prepared;
import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Right;
import org.h2.engine.Session;
import org.h2.engine.UndoLogRecord;
import org.h2.expression.Expression;
import org.h2.expression.Parameter;
import org.h2.index.PageIndex;
import org.h2.index.Index;
import org.h2.message.DbException;
import org.h2.result.ResultInterface;
import org.h2.result.ResultTarget;
......@@ -76,10 +75,9 @@ public class Insert extends Prepared implements ResultTarget {
}
public int update() {
Database db = session.getDatabase();
PageIndex index = null;
if (sortedInsertMode && db.isPersistent()) {
index = (PageIndex) table.getScanIndex(session);
Index index = null;
if (sortedInsertMode) {
index = table.getScanIndex(session);
index.setSortedInsertMode(true);
}
try {
......
......@@ -332,4 +332,8 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
return true;
}
public void setSortedInsertMode(boolean sortedInsertMode) {
// ignore
}
}
......@@ -233,4 +233,13 @@ public interface Index extends SchemaObject {
*/
boolean canScan();
/**
* Enable or disable the 'sorted insert' optimizations (rows are inserted in
* ascending or descending order) if applicable for this index
* implementation.
*
* @param sortedInsertMode the new value
*/
void setSortedInsertMode(boolean sortedInsertMode);
}
......@@ -322,4 +322,9 @@ public class MultiVersionIndex implements Index {
return base.canScan();
}
public void setSortedInsertMode(boolean sortedInsertMode) {
base.setSortedInsertMode(sortedInsertMode);
delta.setSortedInsertMode(sortedInsertMode);
}
}
......@@ -36,6 +36,7 @@ public class TestCases extends TestBase {
}
public void test() throws Exception {
testSortedSelect();
testMaxMemoryRowsDistinct();
testDeleteTop();
testUnicode();
......@@ -89,6 +90,16 @@ public class TestCases extends TestBase {
deleteDb("cases");
}
private void testSortedSelect() throws SQLException {
deleteDb("cases");
Connection conn = getConnection("cases");
Statement stmt = conn.createStatement();
stmt.execute("create memory temporary table test(id int) not persistent");
stmt.execute("insert into test(id) direct sorted select 1");
stmt.execute("drop table test");
conn.close();
}
private void testMaxMemoryRowsDistinct() throws SQLException {
deleteDb("cases");
Connection conn = getConnection("cases;max_memory_rows_distinct=1");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论