Skip to content

Commit

Permalink
refactor(store): Add more database indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Jan 18, 2025
1 parent cac4523 commit 3a81ed6
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ CREATE INDEX IF NOT EXISTS idx_transactions_tx_id ON transactions (tx_id);
CREATE INDEX IF NOT EXISTS idx_transactions_tx_index ON transactions (tx_index);
CREATE INDEX IF NOT EXISTS idx_transactions_tx_status ON transactions (tx_status);
CREATE INDEX IF NOT EXISTS idx_transactions_kind ON transactions (kind);

-- Composite indexes for filtering with "WHERE block_height >= <value>"
CREATE INDEX IF NOT EXISTS idx_transactions_tx_status_block_height ON transactions (tx_status, block_height);
CREATE INDEX IF NOT EXISTS idx_transactions_tx_kind_block_height ON transactions (kind, block_height);

-- Composite index for ordering by (block_height, tx_index)
CREATE INDEX IF NOT EXISTS idx_transactions_ordering ON transactions (block_height, tx_index);
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,14 @@ CREATE INDEX IF NOT EXISTS idx_inputs_asset_id ON inputs (asset_id);
CREATE INDEX IF NOT EXISTS idx_inputs_contract_id ON inputs (contract_id);
CREATE INDEX IF NOT EXISTS idx_inputs_sender_address ON inputs (sender_address);
CREATE INDEX IF NOT EXISTS idx_inputs_recipient_address ON inputs (recipient_address);

-- Composite indexes for filtering with "WHERE block_height >= <value>"
CREATE INDEX IF NOT EXISTS idx_inputs_input_type_block_height ON inputs (input_type, block_height);
CREATE INDEX IF NOT EXISTS idx_inputs_owner_id_block_height ON inputs (owner_id, block_height);
CREATE INDEX IF NOT EXISTS idx_inputs_asset_id_block_height ON inputs (asset_id, block_height);
CREATE INDEX IF NOT EXISTS idx_inputs_contract_id_block_height ON inputs (contract_id, block_height);
CREATE INDEX IF NOT EXISTS idx_inputs_sender_address_block_height ON inputs (sender_address, block_height);
CREATE INDEX IF NOT EXISTS idx_inputs_recipient_address_block_height ON inputs (recipient_address, block_height);

-- Composite index for ordering by (block_height, tx_index, input_index)
CREATE INDEX IF NOT EXISTS idx_inputs_ordering ON inputs (block_height, tx_index, input_index);
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,12 @@ CREATE INDEX IF NOT EXISTS idx_outputs_output_type ON outputs (output_type);
CREATE INDEX IF NOT EXISTS idx_outputs_to_address ON outputs (to_address);
CREATE INDEX IF NOT EXISTS idx_outputs_asset_id ON outputs (asset_id);
CREATE INDEX IF NOT EXISTS idx_outputs_contract_id ON outputs (contract_id);

-- Composite indexes for filtering with "WHERE block_height >= <value>"
CREATE INDEX IF NOT EXISTS idx_outputs_output_type_block_height ON outputs (output_type, block_height);
CREATE INDEX IF NOT EXISTS idx_outputs_to_address_block_height ON outputs (to_address, block_height);
CREATE INDEX IF NOT EXISTS idx_outputs_asset_id_block_height ON outputs (asset_id, block_height);
CREATE INDEX IF NOT EXISTS idx_outputs_contract_id_block_height ON outputs (contract_id, block_height);

-- Composite index for ordering by (block_height, tx_index, output_index)
CREATE INDEX IF NOT EXISTS idx_outputs_ordering ON outputs (block_height, tx_index, output_index);
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ CREATE INDEX IF NOT EXISTS idx_utxos_tx_index ON utxos (tx_index);
CREATE INDEX IF NOT EXISTS idx_utxos_input_index ON utxos (input_index);
CREATE INDEX IF NOT EXISTS idx_utxos_utxo_type ON utxos (utxo_type);
CREATE INDEX IF NOT EXISTS idx_utxos_utxo_id ON utxos (utxo_id);

-- Composite indexes for filtering with "WHERE block_height >= <value>"
CREATE INDEX IF NOT EXISTS idx_utxos_utxo_type_block_height ON utxos (utxo_type, block_height);
CREATE INDEX IF NOT EXISTS idx_utxos_utxo_id_block_height ON utxos (utxo_id, block_height);

-- Composite index for ordering by (block_height, tx_index, input_index)
CREATE INDEX IF NOT EXISTS idx_utxos_ordering ON utxos (block_height, tx_index, input_index);
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,17 @@ CREATE INDEX IF NOT EXISTS idx_receipts_contract_id ON receipts (contract_id);
CREATE INDEX IF NOT EXISTS idx_receipts_sub_id ON receipts (sub_id);
CREATE INDEX IF NOT EXISTS idx_receipts_sender_address ON receipts (sender_address);
CREATE INDEX IF NOT EXISTS idx_receipts_recipient_address ON receipts (recipient_address);

-- Composite indexes for filtering with "WHERE block_height >= <value>"
CREATE INDEX IF NOT EXISTS idx_receipts_receipt_type_block_height ON receipts (receipt_type, block_height);
CREATE INDEX IF NOT EXISTS idx_receipts_from_contract_id_block_height ON receipts (from_contract_id, block_height);
CREATE INDEX IF NOT EXISTS idx_receipts_to_contract_id_block_height ON receipts (to_contract_id, block_height);
CREATE INDEX IF NOT EXISTS idx_receipts_to_address_block_height ON receipts (to_address, block_height);
CREATE INDEX IF NOT EXISTS idx_receipts_asset_id_block_height ON receipts (asset_id, block_height);
CREATE INDEX IF NOT EXISTS idx_receipts_contract_id_block_height ON receipts (contract_id, block_height);
CREATE INDEX IF NOT EXISTS idx_receipts_sub_id_block_height ON receipts (sub_id, block_height);
CREATE INDEX IF NOT EXISTS idx_receipts_sender_address_block_height ON receipts (sender_address, block_height);
CREATE INDEX IF NOT EXISTS idx_receipts_recipient_address_block_height ON receipts (recipient_address, block_height);

-- Composite index for ordering by (block_height, tx_index, receipt_index)
CREATE INDEX IF NOT EXISTS idx_receipts_ordering ON receipts (block_height, tx_index, receipt_index);

0 comments on commit 3a81ed6

Please sign in to comment.