50-blocks.sql 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. -- Copyright (C) 2025 The Syncthing Authors.
  2. --
  3. -- This Source Code Form is subject to the terms of the Mozilla Public
  4. -- License, v. 2.0. If a copy of the MPL was not distributed with this file,
  5. -- You can obtain one at https://mozilla.org/MPL/2.0/.
  6. -- Block lists
  7. --
  8. -- The block lists are extracted from FileInfos and stored separately. This
  9. -- reduces the database size by reusing the same block list entry for all
  10. -- devices announcing the same file. Doing it for all block lists instead of
  11. -- using a size cutoff simplifies queries. Block lists are garbage collected
  12. -- "manually", not using a trigger as that was too performance impacting.
  13. CREATE TABLE IF NOT EXISTS blocklists (
  14. blocklist_hash BLOB NOT NULL PRIMARY KEY,
  15. blprotobuf BLOB NOT NULL
  16. ) STRICT, WITHOUT ROWID
  17. ;
  18. -- Blocks
  19. --
  20. -- For all local files we store the blocks individually for quick lookup. A
  21. -- given block can exist in multiple blocklists and at multiple offsets in a
  22. -- blocklist. We eschew most indexes here as inserting millions of blocks is
  23. -- common and performance is critical.
  24. CREATE TABLE IF NOT EXISTS blocks (
  25. hash BLOB NOT NULL,
  26. blocklist_hash BLOB NOT NULL,
  27. idx INTEGER NOT NULL,
  28. offset INTEGER NOT NULL,
  29. size INTEGER NOT NULL,
  30. PRIMARY KEY(hash, blocklist_hash, idx)
  31. ) STRICT, WITHOUT ROWID
  32. ;