feat: extract metadata to compiled_contracts_metadata - #2929
feat: extract metadata to compiled_contracts_metadata#2929peterlodri-sec wants to merge 7 commits into
Conversation
|
Why: Storing massive I've also written an in-depth retrospective blog post on this optimization: Solving Database Bloat in Sourcify with Metadata Deduplication |
|
It might look like there are no explicit In PostgreSQL, declaring a column as a CREATE TABLE compiled_contracts_metadata (
compilation_id uuid PRIMARY KEY REFERENCES compiled_contracts(id) ON DELETE CASCADE,
metadata json NOT NULL
);That implicit index on compilation_id perfectly covers the only two ways the database interacts with this side-table:
I intentionally didn't add a GIN or BTREE index on the metadata JSON blob itself because Sourcify's architecture never queries inside that payload (e.g., we never run WHERE metadata->>'language' = 'Solidity').
|
Fix for
|
…OUP BY when metadata or std_json_output is selected
|
Thanks for the work on this! Superseded by #2941, which keeps the same table shape and first-wins semantics but restructures the rollout (backfill moved out of the migration into a batched script, no COALESCE read path, based on staging). See the discussion there for details. |
Fixes #2924 by deduplicating JSON metadata into a separate
compiled_contracts_metadataside table. This dramatically reduces table bloat insourcify_matchescaused by multiple networks sharing identical compiled contract JSON structures. The reads are gracefully degraded via COALESCE, allowing zero-downtime database migration.