state_cids and storage_cids only index leaf nodes and related adjustments
This commit is contained in:
parent
bb57b4a033
commit
241bb281eb
@ -2,13 +2,16 @@
|
||||
CREATE TABLE IF NOT EXISTS eth.state_cids (
|
||||
block_number BIGINT NOT NULL,
|
||||
header_id VARCHAR(66) NOT NULL,
|
||||
state_leaf_key VARCHAR(66),
|
||||
state_leaf_key VARCHAR(66) NOT NULL,
|
||||
cid TEXT NOT NULL,
|
||||
state_path BYTEA NOT NULL,
|
||||
node_type INTEGER NOT NULL,
|
||||
diff BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
mh_key TEXT NOT NULL,
|
||||
PRIMARY KEY (state_path, header_id, block_number)
|
||||
balance NUMERIC NOT NULL,
|
||||
nonce BIGINT NOT NULL,
|
||||
code_hash VARCHAR(66) NOT NULL,
|
||||
storage_root VARCHAR(66) NOT NULL,
|
||||
PRIMARY KEY (state_leaf_key, header_id, block_number)
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
|
@ -2,14 +2,13 @@
|
||||
CREATE TABLE IF NOT EXISTS eth.storage_cids (
|
||||
block_number BIGINT NOT NULL,
|
||||
header_id VARCHAR(66) NOT NULL,
|
||||
state_path BYTEA NOT NULL,
|
||||
storage_leaf_key VARCHAR(66),
|
||||
state_leaf_key VARCHAR(66) NOT NULL,
|
||||
storage_leaf_key VARCHAR(66) NOT NULL,
|
||||
cid TEXT NOT NULL,
|
||||
storage_path BYTEA NOT NULL,
|
||||
node_type INTEGER NOT NULL,
|
||||
diff BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
mh_key TEXT NOT NULL,
|
||||
PRIMARY KEY (storage_path, state_path, header_id, block_number)
|
||||
PRIMARY KEY (storage_leaf_key, state_leaf_key, header_id, block_number)
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
|
@ -1,14 +0,0 @@
|
||||
-- +goose Up
|
||||
CREATE TABLE IF NOT EXISTS eth.state_accounts (
|
||||
block_number BIGINT NOT NULL,
|
||||
header_id VARCHAR(66) NOT NULL,
|
||||
state_path BYTEA NOT NULL,
|
||||
balance NUMERIC NOT NULL,
|
||||
nonce BIGINT NOT NULL,
|
||||
code_hash VARCHAR(66) NOT NULL,
|
||||
storage_root VARCHAR(66) NOT NULL,
|
||||
PRIMARY KEY (state_path, header_id, block_number)
|
||||
);
|
||||
|
||||
-- +goose Down
|
||||
DROP TABLE eth.state_accounts;
|
@ -30,25 +30,18 @@ CREATE INDEX rct_contract_hash_index ON eth.receipt_cids USING btree (contract_h
|
||||
|
||||
-- state node indexes
|
||||
CREATE INDEX state_block_number_index ON eth.state_cids USING brin (block_number);
|
||||
CREATE INDEX state_leaf_key_index ON eth.state_cids USING btree (state_leaf_key);
|
||||
CREATE INDEX state_cid_index ON eth.state_cids USING btree (cid);
|
||||
CREATE INDEX state_mh_block_number_index ON eth.state_cids USING btree (mh_key, block_number);
|
||||
CREATE INDEX state_header_id_index ON eth.state_cids USING btree (header_id);
|
||||
CREATE INDEX state_node_type_index ON eth.state_cids USING btree (node_type);
|
||||
CREATE INDEX state_path_index ON eth.state_cids USING btree (state_path);
|
||||
|
||||
-- storage node indexes
|
||||
CREATE INDEX storage_block_number_index ON eth.storage_cids USING brin (block_number);
|
||||
CREATE INDEX storage_state_path_index ON eth.storage_cids USING btree (state_path);
|
||||
CREATE INDEX storage_leaf_key_index ON eth.storage_cids USING btree (storage_leaf_key);
|
||||
CREATE INDEX storage_state_leaf_key_index ON eth.storage_cids USING btree (state_leaf_key);
|
||||
CREATE INDEX storage_cid_index ON eth.storage_cids USING btree (cid);
|
||||
CREATE INDEX storage_mh_block_number_index ON eth.storage_cids USING btree (mh_key, block_number);
|
||||
CREATE INDEX storage_header_id_index ON eth.storage_cids USING btree (header_id);
|
||||
CREATE INDEX storage_node_type_index ON eth.storage_cids USING btree (node_type);
|
||||
|
||||
-- state accounts indexes
|
||||
CREATE INDEX account_block_number_index ON eth.state_accounts USING brin (block_number);
|
||||
CREATE INDEX account_header_id_index ON eth.state_accounts USING btree (header_id);
|
||||
CREATE INDEX account_storage_root_index ON eth.state_accounts USING btree (storage_root);
|
||||
CREATE INDEX storage_path_index ON eth.storage_cids USING btree (state_path);
|
||||
|
||||
-- access list indexes
|
||||
CREATE INDEX access_list_block_number_index ON eth.access_list_elements USING brin (block_number);
|
||||
@ -85,26 +78,20 @@ DROP INDEX eth.access_list_storage_keys_index;
|
||||
DROP INDEX eth.access_list_element_address_index;
|
||||
DROP INDEX eth.access_list_block_number_index;
|
||||
|
||||
-- state account indexes
|
||||
DROP INDEX eth.account_storage_root_index;
|
||||
DROP index eth.account_header_id_index;
|
||||
DROP INDEX eth.account_block_number_index;
|
||||
|
||||
-- storage node indexes
|
||||
DROP INDEX eth.storage_node_type_index;
|
||||
DROP INDEX eth.storage_path_index;
|
||||
DROP INDEX eth.storage_header_id_index;
|
||||
DROP INDEX eth.storage_mh_block_number_index;
|
||||
DROP INDEX eth.storage_cid_index;
|
||||
DROP INDEX eth.storage_leaf_key_index;
|
||||
DROP INDEX eth.storage_state_path_index;
|
||||
DROP INDEX eth.storage_state_leaf_key_index;
|
||||
DROP INDEX eth.storage_block_number_index;
|
||||
|
||||
-- state node indexes
|
||||
DROP INDEX eth.state_node_type_index;
|
||||
DROP INDEX eth.state_path_index;
|
||||
DROP INDEX eth.state_header_id_index;
|
||||
DROP INDEX eth.state_mh_block_number_index;
|
||||
DROP INDEX eth.state_cid_index;
|
||||
DROP INDEX eth.state_leaf_key_index;
|
||||
DROP INDEX eth.state_block_number_index;
|
||||
|
||||
-- receipt indexes
|
@ -6,7 +6,7 @@ CREATE FUNCTION eth.graphql_subscription() RETURNS TRIGGER AS $$
|
||||
DECLARE
|
||||
obj jsonb;
|
||||
BEGIN
|
||||
IF (TG_TABLE_NAME = 'state_cids') OR (TG_TABLE_NAME = 'state_accounts') THEN
|
||||
IF (TG_TABLE_NAME = 'state_cids') THEN
|
||||
obj := json_build_array(
|
||||
TG_TABLE_NAME,
|
||||
NEW.header_id,
|
||||
@ -116,4 +116,4 @@ DROP TRIGGER trg_eth_header_cids ON eth.header_cids;
|
||||
DROP TRIGGER trg_eth_log_cids ON eth.log_cids;
|
||||
DROP TRIGGER trg_eth_access_list_elements ON eth.access_list_elements;
|
||||
|
||||
DROP FUNCTION eth.graphql_subscription();
|
||||
DROP FUNCTION eth.graphql_subscription();
|
@ -6,7 +6,6 @@ SELECT create_hypertable('eth.transaction_cids', 'block_number', migrate_data =>
|
||||
SELECT create_hypertable('eth.receipt_cids', 'block_number', migrate_data => true, chunk_time_interval => 32768);
|
||||
SELECT create_hypertable('eth.state_cids', 'block_number', migrate_data => true, chunk_time_interval => 32768);
|
||||
SELECT create_hypertable('eth.storage_cids', 'block_number', migrate_data => true, chunk_time_interval => 32768);
|
||||
SELECT create_hypertable('eth.state_accounts', 'block_number', migrate_data => true, chunk_time_interval => 32768);
|
||||
SELECT create_hypertable('eth.access_list_elements', 'block_number', migrate_data => true, chunk_time_interval => 32768);
|
||||
SELECT create_hypertable('eth.log_cids', 'block_number', migrate_data => true, chunk_time_interval => 32768);
|
||||
|
||||
@ -22,7 +21,6 @@ INSERT INTO public.db_version (singleton, version) VALUES (true, 'v4.0.0')
|
||||
-- create new regular tables
|
||||
CREATE TABLE eth.log_cids_i (LIKE eth.log_cids INCLUDING ALL);
|
||||
CREATE TABLE eth.access_list_elements_i (LIKE eth.access_list_elements INCLUDING ALL);
|
||||
CREATE TABLE eth.state_accounts_i (LIKE eth.state_accounts INCLUDING ALL);
|
||||
CREATE TABLE eth.storage_cids_i (LIKE eth.storage_cids INCLUDING ALL);
|
||||
CREATE TABLE eth.state_cids_i (LIKE eth.state_cids INCLUDING ALL);
|
||||
CREATE TABLE eth.receipt_cids_i (LIKE eth.receipt_cids INCLUDING ALL);
|
||||
@ -34,7 +32,6 @@ CREATE TABLE public.blocks_i (LIKE public.blocks INCLUDING ALL);
|
||||
-- migrate data
|
||||
INSERT INTO eth.log_cids_i (SELECT * FROM eth.log_cids);
|
||||
INSERT INTO eth.access_list_elements_i (SELECT * FROM eth.access_list_elements);
|
||||
INSERT INTO eth.state_accounts_i (SELECT * FROM eth.state_accounts);
|
||||
INSERT INTO eth.storage_cids_i (SELECT * FROM eth.storage_cids);
|
||||
INSERT INTO eth.state_cids_i (SELECT * FROM eth.state_cids);
|
||||
INSERT INTO eth.receipt_cids_i (SELECT * FROM eth.receipt_cids);
|
||||
@ -46,7 +43,6 @@ INSERT INTO public.blocks_i (SELECT * FROM public.blocks);
|
||||
-- drop hypertables
|
||||
DROP TABLE eth.log_cids;
|
||||
DROP TABLE eth.access_list_elements;
|
||||
DROP TABLE eth.state_accounts;
|
||||
DROP TABLE eth.storage_cids;
|
||||
DROP TABLE eth.state_cids;
|
||||
DROP TABLE eth.receipt_cids;
|
||||
@ -58,7 +54,6 @@ DROP TABLE public.blocks;
|
||||
-- rename new tables
|
||||
ALTER TABLE eth.log_cids_i RENAME TO log_cids;
|
||||
ALTER TABLE eth.access_list_elements_i RENAME TO access_list_elements;
|
||||
ALTER TABLE eth.state_accounts_i RENAME TO state_accounts;
|
||||
ALTER TABLE eth.storage_cids_i RENAME TO storage_cids;
|
||||
ALTER TABLE eth.state_cids_i RENAME TO state_cids;
|
||||
ALTER TABLE eth.receipt_cids_i RENAME TO receipt_cids;
|
Loading…
Reference in New Issue
Block a user