Search code examples
sqliteb-treeb-tree-index

Does SQLite support bulk-loading (sort-then-indexing)?


When constructing indexing tree from existing data, there is a bulk-loading algorithm, like

  1. https://en.wikipedia.org/wiki/B%2B_tree#Bulk-loading
  2. https://www.youtube.com/watch?v=HJgXVxsO5YU

When creating an index for a non-empty table, does SQLite use bulk-loading or create indexing by insertions? From my performance test, it seems that SQLite uses insertion to create indexing because the time costs between inserting table after indexing and creating indexing after insertion are similar.

Do we know why bulk-loading is not used? Does it not work well in practice?


Solution

  • Bulk loading requires that the data is already sorted.

    SQLite implements sorting by inserting the rows into a temporary index, so using it for bulk loading would not be productive.