Btree index #115
@ -47,6 +47,8 @@ CREATE INDEX state_mh_index ON eth.state_cids USING btree (mh_key);
|
||||
|
||||
CREATE INDEX state_path_index ON eth.state_cids USING btree (state_path);
|
||||
|
||||
CREATE INDEX state_node_type_index ON eth.state_cids USING btree (node_type);
|
||||
|
||||
-- storage node indexes
|
||||
CREATE INDEX storage_state_id_index ON eth.storage_cids USING btree (state_id);
|
||||
|
||||
@ -58,6 +60,8 @@ CREATE INDEX storage_mh_index ON eth.storage_cids USING btree (mh_key);
|
||||
|
||||
CREATE INDEX storage_path_index ON eth.storage_cids USING btree (storage_path);
|
||||
|
||||
CREATE INDEX storage_node_type_index ON eth.storage_cids USING btree (node_type);
|
||||
|
||||
-- state accounts indexes
|
||||
CREATE INDEX account_state_id_index ON eth.state_accounts USING btree (state_id);
|
||||
|
||||
@ -69,6 +73,7 @@ DROP INDEX eth.storage_root_index;
|
||||
DROP INDEX eth.account_state_id_index;
|
||||
|
||||
-- storage node indexes
|
||||
DROP INDEX eth.storage_node_type_index;
|
||||
DROP INDEX eth.storage_path_index;
|
||||
DROP INDEX eth.storage_mh_index;
|
||||
DROP INDEX eth.storage_cid_index;
|
||||
@ -76,6 +81,7 @@ DROP INDEX eth.storage_leaf_key_index;
|
||||
DROP INDEX eth.storage_state_id_index;
|
||||
|
||||
-- state node indexes
|
||||
DROP INDEX eth.state_node_type_index;
|
||||
DROP INDEX eth.state_path_index;
|
||||
DROP INDEX eth.state_mh_index;
|
||||
DROP INDEX eth.state_cid_index;
|
||||
|
@ -2,8 +2,8 @@
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
-- Dumped from database version 12.4
|
||||
-- Dumped by pg_dump version 12.4
|
||||
-- Dumped from database version 14beta3
|
||||
-- Dumped by pg_dump version 14beta3
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
@ -47,7 +47,8 @@ CREATE TABLE eth.header_cids (
|
||||
uncle_root character varying(66) NOT NULL,
|
||||
bloom bytea NOT NULL,
|
||||
"timestamp" numeric NOT NULL,
|
||||
times_validated integer DEFAULT 1 NOT NULL
|
||||
times_validated integer DEFAULT 1 NOT NULL,
|
||||
base_fee bigint
|
||||
);
|
||||
|
||||
|
||||
@ -103,33 +104,6 @@ end;
|
||||
$_$;
|
||||
|
||||
|
||||
--
|
||||
-- Name: canonical_header(bigint); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.canonical_header(height bigint) RETURNS integer
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
DECLARE
|
||||
current_weight INT;
|
||||
heaviest_weight INT DEFAULT 0;
|
||||
heaviest_id INT;
|
||||
r eth.header_cids%ROWTYPE;
|
||||
BEGIN
|
||||
FOR r IN SELECT * FROM eth.header_cids
|
||||
WHERE block_number = height
|
||||
LOOP
|
||||
SELECT INTO current_weight * FROM header_weight(r.block_hash);
|
||||
IF current_weight > heaviest_weight THEN
|
||||
heaviest_weight := current_weight;
|
||||
heaviest_id := r.id;
|
||||
END IF;
|
||||
END LOOP;
|
||||
RETURN heaviest_id;
|
||||
END
|
||||
$$;
|
||||
|
||||
|
||||
--
|
||||
-- Name: canonical_header_from_array(eth.header_cids[]); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
@ -216,17 +190,6 @@ END;
|
||||
$$;
|
||||
|
||||
|
||||
--
|
||||
-- Name: ethHeaderCidByBlockNumber(bigint); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE FUNCTION public."ethHeaderCidByBlockNumber"(n bigint) RETURNS SETOF eth.header_cids
|
||||
LANGUAGE sql STABLE
|
||||
AS $_$
|
||||
SELECT * FROM eth.header_cids WHERE block_number=$1 ORDER BY id
|
||||
$_$;
|
||||
|
||||
|
||||
--
|
||||
-- Name: has_child(character varying, bigint); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
@ -255,33 +218,11 @@ BEGIN
|
||||
new_child_result.children = array_append(new_child_result.children, temp_child);
|
||||
END LOOP;
|
||||
END IF;
|
||||
RETURN new_child_result;
|
||||
RETURN new_child_result;
|
||||
END
|
||||
$$;
|
||||
|
||||
|
||||
--
|
||||
-- Name: header_weight(character varying); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE FUNCTION public.header_weight(hash character varying) RETURNS bigint
|
||||
LANGUAGE sql
|
||||
AS $$
|
||||
WITH RECURSIVE validator AS (
|
||||
SELECT block_hash, parent_hash, block_number
|
||||
FROM eth.header_cids
|
||||
WHERE block_hash = hash
|
||||
UNION
|
||||
SELECT eth.header_cids.block_hash, eth.header_cids.parent_hash, eth.header_cids.block_number
|
||||
FROM eth.header_cids
|
||||
INNER JOIN validator
|
||||
ON eth.header_cids.parent_hash = validator.block_hash
|
||||
AND eth.header_cids.block_number = validator.block_number + 1
|
||||
)
|
||||
SELECT COUNT(*) FROM validator;
|
||||
$$;
|
||||
|
||||
|
||||
--
|
||||
-- Name: was_state_removed(bytea, bigint, character varying); Type: FUNCTION; Schema: public; Owner: -
|
||||
--
|
||||
@ -324,23 +265,23 @@ $$;
|
||||
|
||||
|
||||
--
|
||||
-- Name: access_list_entry; Type: TABLE; Schema: eth; Owner: -
|
||||
-- Name: access_list_element; Type: TABLE; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE eth.access_list_entry (
|
||||
CREATE TABLE eth.access_list_element (
|
||||
id integer NOT NULL,
|
||||
index integer NOT NULL,
|
||||
tx_id integer NOT NULL,
|
||||
index integer NOT NULL,
|
||||
address character varying(66),
|
||||
storage_keys character varying(66)[]
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: access_list_entry_id_seq; Type: SEQUENCE; Schema: eth; Owner: -
|
||||
-- Name: access_list_element_id_seq; Type: SEQUENCE; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE eth.access_list_entry_id_seq
|
||||
CREATE SEQUENCE eth.access_list_element_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
@ -350,10 +291,10 @@ CREATE SEQUENCE eth.access_list_entry_id_seq
|
||||
|
||||
|
||||
--
|
||||
-- Name: access_list_entry_id_seq; Type: SEQUENCE OWNED BY; Schema: eth; Owner: -
|
||||
-- Name: access_list_element_id_seq; Type: SEQUENCE OWNED BY; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE eth.access_list_entry_id_seq OWNED BY eth.access_list_entry.id;
|
||||
ALTER SEQUENCE eth.access_list_element_id_seq OWNED BY eth.access_list_element.id;
|
||||
|
||||
|
||||
--
|
||||
@ -376,6 +317,45 @@ CREATE SEQUENCE eth.header_cids_id_seq
|
||||
ALTER SEQUENCE eth.header_cids_id_seq OWNED BY eth.header_cids.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_cids; Type: TABLE; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
CREATE TABLE eth.log_cids (
|
||||
id integer NOT NULL,
|
||||
leaf_cid text NOT NULL,
|
||||
leaf_mh_key text NOT NULL,
|
||||
receipt_id integer NOT NULL,
|
||||
address character varying(66),
|
||||
log_data bytea,
|
||||
index integer NOT NULL,
|
||||
topic0 character varying(66),
|
||||
topic1 character varying(66),
|
||||
topic2 character varying(66),
|
||||
topic3 character varying(66)
|
||||
);
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_cids_id_seq; Type: SEQUENCE; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
CREATE SEQUENCE eth.log_cids_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_cids_id_seq; Type: SEQUENCE OWNED BY; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
ALTER SEQUENCE eth.log_cids_id_seq OWNED BY eth.log_cids.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: receipt_cids; Type: TABLE; Schema: eth; Owner: -
|
||||
--
|
||||
@ -387,13 +367,9 @@ CREATE TABLE eth.receipt_cids (
|
||||
mh_key text NOT NULL,
|
||||
contract character varying(66),
|
||||
contract_hash character varying(66),
|
||||
topic0s character varying(66)[],
|
||||
topic1s character varying(66)[],
|
||||
topic2s character varying(66)[],
|
||||
topic3s character varying(66)[],
|
||||
log_contracts character varying(66)[],
|
||||
post_state character varying(66),
|
||||
post_status integer
|
||||
post_status integer,
|
||||
log_root character varying(66)
|
||||
);
|
||||
|
||||
|
||||
@ -692,10 +668,10 @@ ALTER SEQUENCE public.nodes_id_seq OWNED BY public.nodes.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: access_list_entry id; Type: DEFAULT; Schema: eth; Owner: -
|
||||
-- Name: access_list_element id; Type: DEFAULT; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY eth.access_list_entry ALTER COLUMN id SET DEFAULT nextval('eth.access_list_entry_id_seq'::regclass);
|
||||
ALTER TABLE ONLY eth.access_list_element ALTER COLUMN id SET DEFAULT nextval('eth.access_list_element_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
@ -705,6 +681,13 @@ ALTER TABLE ONLY eth.access_list_entry ALTER COLUMN id SET DEFAULT nextval('eth.
|
||||
ALTER TABLE ONLY eth.header_cids ALTER COLUMN id SET DEFAULT nextval('eth.header_cids_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_cids id; Type: DEFAULT; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY eth.log_cids ALTER COLUMN id SET DEFAULT nextval('eth.log_cids_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: receipt_cids id; Type: DEFAULT; Schema: eth; Owner: -
|
||||
--
|
||||
@ -762,19 +745,19 @@ ALTER TABLE ONLY public.nodes ALTER COLUMN id SET DEFAULT nextval('public.nodes_
|
||||
|
||||
|
||||
--
|
||||
-- Name: access_list_entry access_list_entry_pkey; Type: CONSTRAINT; Schema: eth; Owner: -
|
||||
-- Name: access_list_element access_list_element_pkey; Type: CONSTRAINT; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY eth.access_list_entry
|
||||
ADD CONSTRAINT access_list_entry_pkey PRIMARY KEY (id);
|
||||
ALTER TABLE ONLY eth.access_list_element
|
||||
ADD CONSTRAINT access_list_element_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: access_list_entry access_list_entry_tx_id_index_key; Type: CONSTRAINT; Schema: eth; Owner: -
|
||||
-- Name: access_list_element access_list_element_tx_id_index_key; Type: CONSTRAINT; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY eth.access_list_entry
|
||||
ADD CONSTRAINT access_list_entry_tx_id_index_key UNIQUE (tx_id, index);
|
||||
ALTER TABLE ONLY eth.access_list_element
|
||||
ADD CONSTRAINT access_list_element_tx_id_index_key UNIQUE (tx_id, index);
|
||||
|
||||
|
||||
--
|
||||
@ -793,6 +776,22 @@ ALTER TABLE ONLY eth.header_cids
|
||||
ADD CONSTRAINT header_cids_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_cids log_cids_pkey; Type: CONSTRAINT; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY eth.log_cids
|
||||
ADD CONSTRAINT log_cids_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_cids log_cids_receipt_id_index_key; Type: CONSTRAINT; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY eth.log_cids
|
||||
ADD CONSTRAINT log_cids_receipt_id_index_key UNIQUE (receipt_id, index);
|
||||
|
||||
|
||||
--
|
||||
-- Name: receipt_cids receipt_cids_pkey; Type: CONSTRAINT; Schema: eth; Owner: -
|
||||
--
|
||||
@ -922,10 +921,10 @@ ALTER TABLE ONLY public.nodes
|
||||
|
||||
|
||||
--
|
||||
-- Name: accesss_list_address_index; Type: INDEX; Schema: eth; Owner: -
|
||||
-- Name: accesss_list_element_address_index; Type: INDEX; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX accesss_list_address_index ON eth.access_list_entry USING btree (address);
|
||||
CREATE INDEX accesss_list_element_address_index ON eth.access_list_element USING btree (address);
|
||||
|
||||
|
||||
--
|
||||
@ -963,6 +962,55 @@ CREATE INDEX header_cid_index ON eth.header_cids USING btree (cid);
|
||||
CREATE INDEX header_mh_index ON eth.header_cids USING btree (mh_key);
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_cid_index; Type: INDEX; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX log_cid_index ON eth.log_cids USING btree (leaf_cid);
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_mh_index; Type: INDEX; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX log_mh_index ON eth.log_cids USING btree (leaf_mh_key);
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_rct_id_index; Type: INDEX; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX log_rct_id_index ON eth.log_cids USING btree (receipt_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_topic0_index; Type: INDEX; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX log_topic0_index ON eth.log_cids USING btree (topic0);
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_topic1_index; Type: INDEX; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX log_topic1_index ON eth.log_cids USING btree (topic1);
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_topic2_index; Type: INDEX; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX log_topic2_index ON eth.log_cids USING btree (topic2);
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_topic3_index; Type: INDEX; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX log_topic3_index ON eth.log_cids USING btree (topic3);
|
||||
|
||||
|
||||
--
|
||||
-- Name: rct_cid_index; Type: INDEX; Schema: eth; Owner: -
|
||||
--
|
||||
@ -984,13 +1032,6 @@ CREATE INDEX rct_contract_hash_index ON eth.receipt_cids USING btree (contract_h
|
||||
CREATE INDEX rct_contract_index ON eth.receipt_cids USING btree (contract);
|
||||
|
||||
|
||||
--
|
||||
-- Name: rct_log_contract_index; Type: INDEX; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX rct_log_contract_index ON eth.receipt_cids USING gin (log_contracts);
|
||||
|
||||
|
||||
--
|
||||
-- Name: rct_mh_index; Type: INDEX; Schema: eth; Owner: -
|
||||
--
|
||||
@ -1033,6 +1074,13 @@ CREATE INDEX state_leaf_key_index ON eth.state_cids USING btree (state_leaf_key)
|
||||
CREATE INDEX state_mh_index ON eth.state_cids USING btree (mh_key);
|
||||
|
||||
|
||||
--
|
||||
-- Name: state_node_type_index; Type: INDEX; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX state_node_type_index ON eth.state_cids USING btree (node_type);
|
||||
|
||||
|
||||
--
|
||||
-- Name: state_path_index; Type: INDEX; Schema: eth; Owner: -
|
||||
--
|
||||
@ -1068,6 +1116,13 @@ CREATE INDEX storage_leaf_key_index ON eth.storage_cids USING btree (storage_lea
|
||||
CREATE INDEX storage_mh_index ON eth.storage_cids USING btree (mh_key);
|
||||
|
||||
|
||||
--
|
||||
-- Name: storage_node_type_index; Type: INDEX; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX storage_node_type_index ON eth.storage_cids USING btree (node_type);
|
||||
|
||||
|
||||
--
|
||||
-- Name: storage_path_index; Type: INDEX; Schema: eth; Owner: -
|
||||
--
|
||||
@ -1188,11 +1243,11 @@ CREATE TRIGGER uncle_cids_ai AFTER INSERT ON eth.uncle_cids FOR EACH ROW EXECUTE
|
||||
|
||||
|
||||
--
|
||||
-- Name: access_list_entry access_list_entry_tx_id_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
|
||||
-- Name: access_list_element access_list_element_tx_id_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY eth.access_list_entry
|
||||
ADD CONSTRAINT access_list_entry_tx_id_fkey FOREIGN KEY (tx_id) REFERENCES eth.transaction_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
|
||||
ALTER TABLE ONLY eth.access_list_element
|
||||
ADD CONSTRAINT access_list_element_tx_id_fkey FOREIGN KEY (tx_id) REFERENCES eth.transaction_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
|
||||
|
||||
|
||||
--
|
||||
@ -1211,6 +1266,22 @@ ALTER TABLE ONLY eth.header_cids
|
||||
ADD CONSTRAINT header_cids_node_id_fkey FOREIGN KEY (node_id) REFERENCES public.nodes(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_cids log_cids_leaf_mh_key_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY eth.log_cids
|
||||
ADD CONSTRAINT log_cids_leaf_mh_key_fkey FOREIGN KEY (leaf_mh_key) REFERENCES public.blocks(key) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
|
||||
|
||||
|
||||
--
|
||||
-- Name: log_cids log_cids_receipt_id_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY eth.log_cids
|
||||
ADD CONSTRAINT log_cids_receipt_id_fkey FOREIGN KEY (receipt_id) REFERENCES eth.receipt_cids(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED;
|
||||
|
||||
|
||||
--
|
||||
-- Name: receipt_cids receipt_cids_mh_key_fkey; Type: FK CONSTRAINT; Schema: eth; Owner: -
|
||||
--
|
||||
@ -1302,3 +1373,4 @@ ALTER TABLE ONLY eth.uncle_cids
|
||||
--
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user