提交 4f3a6422 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.
上级 74827696
......@@ -524,40 +524,44 @@ public class PageStore implements CacheWriter {
ri.close();
}
recordPageReads = false;
int currentSeqPosInDb = MIN_PAGE_COUNT;
for (int i = 0; i < recordedPagesList.size(); i++) {
writeBack();
cache.clear();
int free = getFirstFree();
int a = currentSeqPosInDb;
int b = recordedPagesList.get(i);
if (a == b) {
continue;
}
boolean swapped = swap(a, b, free);
if (!swapped) {
DbException.throwInternalError("swapping not possible: " + a + " with " + b + " via " + free);
}
int index = recordedPagesList.indexOf(a);
if (index != -1) {
recordedPagesList.set(index, b);
}
recordedPagesList.set(i, a);
int free = getFirstFree(); // We swap, so this page is fix
if (free == -1) {
DbException.throwInternalError("no free page for defrag");
} else {
int currentSeqPosInDb = MIN_PAGE_COUNT;
for (int i = 0; i < recordedPagesList.size(); i++) {
writeBack();
cache.clear();
int a = currentSeqPosInDb;
int b = recordedPagesList.get(i);
if (a == b) {
continue;
}
// Find next PageDataLeaf
while (true) {
currentSeqPosInDb++;
if (currentSeqPosInDb >= pageCount) {
currentSeqPosInDb = -1;
boolean swapped = swap(a, b, free);
if (!swapped) {
DbException.throwInternalError("swapping not possible: " + a + " with " + b + " via " + free);
}
Page currentPage = getPage(currentSeqPosInDb);
if (currentPage == null) {
continue;
int index = recordedPagesList.indexOf(a);
if (index != -1) {
recordedPagesList.set(index, b);
}
if (currentPage instanceof PageDataLeaf) {
break;
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;
}
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论