1
0

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
  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.
  23. CREATE TABLE IF NOT EXISTS blocks (
  24. hash BLOB NOT NULL,
  25. blocklist_hash BLOB NOT NULL,
  26. idx INTEGER NOT NULL,
  27. offset INTEGER NOT NULL,
  28. size INTEGER NOT NULL,
  29. PRIMARY KEY (hash, blocklist_hash, idx),
  30. FOREIGN KEY(blocklist_hash) REFERENCES blocklists(blocklist_hash) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
  31. ) STRICT
  32. ;