提交 851e0b85 authored 作者: christian.peter.io's avatar christian.peter.io

New experimental feature "SHUTDOWN DEFRAG". This option optimizes the page layout so

    that a full table scan is faster.
上级 4f3a6422
...@@ -509,17 +509,8 @@ public class PageStore implements CacheWriter { ...@@ -509,17 +509,8 @@ public class PageStore implements CacheWriter {
recordPageReads = true; recordPageReads = true;
for (int i = 0; i < tables.size(); i++) { for (int i = 0; i < tables.size(); i++) {
Table table = tables.get(i); Table table = tables.get(i);
Column[] columns = table.getColumns(); org.h2.command.Prepared pref = database.getSystemSession().prepare("select * from " +
String columnNames = ""; table.getName() + " where -1=abs(rand())");
for (Column column : columns) {
if (column.getType() != Value.BLOB) {
if (!columnNames.equals("")) {
columnNames += ",";
}
columnNames += column.getName();
}
}
org.h2.command.Prepared pref = database.getSystemSession().prepare("select " + columnNames + " from " + table.getName());
ResultInterface ri = pref.query(Integer.MAX_VALUE); ResultInterface ri = pref.query(Integer.MAX_VALUE);
ri.close(); ri.close();
} }
...@@ -528,11 +519,10 @@ public class PageStore implements CacheWriter { ...@@ -528,11 +519,10 @@ public class PageStore implements CacheWriter {
if (free == -1) { if (free == -1) {
DbException.throwInternalError("no free page for defrag"); DbException.throwInternalError("no free page for defrag");
} else { } else {
int currentSeqPosInDb = MIN_PAGE_COUNT;
for (int i = 0; i < recordedPagesList.size(); i++) { for (int i = 0; i < recordedPagesList.size(); i++) {
writeBack(); writeBack();
cache.clear(); cache.clear();
int a = currentSeqPosInDb; int a = MIN_PAGE_COUNT + i;
int b = recordedPagesList.get(i); int b = recordedPagesList.get(i);
if (a == b) { if (a == b) {
...@@ -548,21 +538,6 @@ public class PageStore implements CacheWriter { ...@@ -548,21 +538,6 @@ public class PageStore implements CacheWriter {
recordedPagesList.set(index, b); recordedPagesList.set(index, b);
} }
recordedPagesList.set(i, a); recordedPagesList.set(i, a);
while (true) {
currentSeqPosInDb++;
if (currentSeqPosInDb >= pageCount) {
currentSeqPosInDb = -1;
break;
}
Page currentPage = getPage(currentSeqPosInDb);
if (currentPage == null) {
continue;
}
if (currentPage instanceof PageDataLeaf) {
break;
}
}
} }
} }
...@@ -638,12 +613,13 @@ public class PageStore implements CacheWriter { ...@@ -638,12 +613,13 @@ public class PageStore implements CacheWriter {
trace.debug("swap " + a + " with " + b + " via " + free); trace.debug("swap " + a + " with " + b + " via " + free);
try { try {
pageA.moveTo(systemSession, free); pageA.moveTo(systemSession, free);
freePage(a); free(a);
pageB = getPage(b);
pageB.moveTo(systemSession, a); pageB.moveTo(systemSession, a);
freePage(b); free(b);
f = getPage(free); f = getPage(free);
f.moveTo(systemSession, b); f.moveTo(systemSession, b);
freePage(free); free(free);
} finally { } finally {
changeCount++; changeCount++;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论