Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kwsantiago
Copy link

Fixes #95

Problem

Slow PostgreSQL queries (>1s) when fetching contract data due to 2MB rows with large BYTEA fields mixed with frequently queried metadata.

Solution

Split the contracts table into separate metadata and data tables to optimize query performance.

Changes

  • Migration 0004: Creates contract_metadata and contract_data tables
  • Index: Added idx_contract_metadata_state for faster state filtering
  • Storage: Updated all PostgreSQL storage methods to use split tables
  • Safety: Preserves existing data and includes rollback migration

Files Modified

  • src/storage/postgres/migrations/0004_split_contract_tables.{up,down}.sql
  • src/storage/sqlx.rs - Added new table structs
  • src/storage/postgres/mod.rs - Updated storage implementation

Expected Performance

Query times should improve from >1s to <100ms by only loading metadata when contract data isn't needed.

@kwsantiago
Copy link
Author

Hey @bennyhodl let me know if I should close this out in case this was already fixed or is an outdated issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize PostgreSQL Storage for Contract Data to Resolve Slow Queries

1 participant