提交 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; ...@@ -12,13 +12,12 @@ import org.h2.command.Command;
import org.h2.command.CommandInterface; import org.h2.command.CommandInterface;
import org.h2.command.Prepared; import org.h2.command.Prepared;
import org.h2.constant.ErrorCode; import org.h2.constant.ErrorCode;
import org.h2.engine.Database;
import org.h2.engine.Right; import org.h2.engine.Right;
import org.h2.engine.Session; import org.h2.engine.Session;
import org.h2.engine.UndoLogRecord; import org.h2.engine.UndoLogRecord;
import org.h2.expression.Expression; import org.h2.expression.Expression;
import org.h2.expression.Parameter; import org.h2.expression.Parameter;
import org.h2.index.PageIndex; import org.h2.index.Index;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.result.ResultInterface; import org.h2.result.ResultInterface;
import org.h2.result.ResultTarget; import org.h2.result.ResultTarget;
...@@ -76,10 +75,9 @@ public class Insert extends Prepared implements ResultTarget { ...@@ -76,10 +75,9 @@ public class Insert extends Prepared implements ResultTarget {
} }
public int update() { public int update() {
Database db = session.getDatabase(); Index index = null;
PageIndex index = null; if (sortedInsertMode) {
if (sortedInsertMode && db.isPersistent()) { index = table.getScanIndex(session);
index = (PageIndex) table.getScanIndex(session);
index.setSortedInsertMode(true); index.setSortedInsertMode(true);
} }
try { try {
......
...@@ -332,4 +332,8 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -332,4 +332,8 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
return true; return true;
} }
public void setSortedInsertMode(boolean sortedInsertMode) {
// ignore
}
} }
...@@ -233,4 +233,13 @@ public interface Index extends SchemaObject { ...@@ -233,4 +233,13 @@ public interface Index extends SchemaObject {
*/ */
boolean canScan(); 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 { ...@@ -322,4 +322,9 @@ public class MultiVersionIndex implements Index {
return base.canScan(); return base.canScan();
} }
public void setSortedInsertMode(boolean sortedInsertMode) {
base.setSortedInsertMode(sortedInsertMode);
delta.setSortedInsertMode(sortedInsertMode);
}
} }
...@@ -36,6 +36,7 @@ public class TestCases extends TestBase { ...@@ -36,6 +36,7 @@ public class TestCases extends TestBase {
} }
public void test() throws Exception { public void test() throws Exception {
testSortedSelect();
testMaxMemoryRowsDistinct(); testMaxMemoryRowsDistinct();
testDeleteTop(); testDeleteTop();
testUnicode(); testUnicode();
...@@ -89,6 +90,16 @@ public class TestCases extends TestBase { ...@@ -89,6 +90,16 @@ public class TestCases extends TestBase {
deleteDb("cases"); 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 { private void testMaxMemoryRowsDistinct() throws SQLException {
deleteDb("cases"); deleteDb("cases");
Connection conn = getConnection("cases;max_memory_rows_distinct=1"); Connection conn = getConnection("cases;max_memory_rows_distinct=1");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论