Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions internal/cbm/sqlite_writer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1213,9 +1213,16 @@ static uint32_t write_index_btree(FILE *fp, uint32_t *next_page, uint8_t **cells
pb_init(&pb, fp, *next_page, true);

for (int i = 0; i < count; i++) {
if (!pb_cell_fits(&pb, cell_lens[i]) && pb.cell_count > 0) {
if (!pb_promote_and_flush(&pb, cells, cell_lens, i - SKIP_ONE)) {
return 0;
if (!pb_cell_fits(&pb, cell_lens[i])) {
if (pb.cell_count > 0) {
if (!pb_promote_and_flush(&pb, cells, cell_lens, i - SKIP_ONE)) {
return 0;
}
}
// After flush, check if the cell still doesn't fit on an empty page.
// Index cells larger than a full page can never be stored; skip them.
if (!pb_cell_fits(&pb, cell_lens[i])) {
continue;
}
}
pb_add_cell(&pb, cells[i], cell_lens[i]);
Expand Down