pages.clear();
LookupSource lookupSource = outputPagesIndex.createLookupSource(indexChannels);
// Build a page containing the keys that produced no output rows, so in future requests can skip these keys
PageBuilder missingKeysPageBuilder = new PageBuilder(missingKeysIndex.getTypes());
UnloadedIndexKeyRecordCursor unloadedKeyRecordCursor = unloadedKeysRecordSet.cursor();
while (unloadedKeyRecordCursor.advanceNextPosition()) {
Block[] blocks = unloadedKeyRecordCursor.getBlocks();
int position = unloadedKeyRecordCursor.getPosition();
if (lookupSource.getJoinPosition(position, blocks) < 0) {
for (int i = 0; i < blocks.length; i++) {
Block block = blocks[i];
Type type = unloadedKeyRecordCursor.getType(i);
type.appendTo(block, position, missingKeysPageBuilder.getBlockBuilder(i));
}
}
}
Page missingKeysPage = missingKeysPageBuilder.build();
memoryInBytes += missingKeysPage.getDataSize().toBytes();
if (isMemoryExceeded()) {
return null;
}
// only update missing keys if we have new missing keys
if (!missingKeysPageBuilder.isEmpty()) {
missingKeysIndex.addPage(missingKeysPage);
missingKeys = missingKeysIndex.createLookupSource(missingKeysChannels);
}
return new IndexSnapshot(lookupSource, missingKeys);