diff --git a/crates/iota-indexer/database_schema.svg b/crates/iota-indexer/database_schema.svg index 86997161b05..4b785446071 100644 --- a/crates/iota-indexer/database_schema.svg +++ b/crates/iota-indexer/database_schema.svg @@ -1,4 +1,4 @@ -displayPKobject_type text NNbcs bytea NNid bytea NNversion int2 NNobjectsPKobject_id bytea NNcheckpoint_sequence_number ref(checkpoints) int8 NNcoin_balance int8coint_type textdf_kind int2df_name byteadf_object_id byteadf_object_type textobject_digest bytea NNobject_type textobject_version in8 NNowner_id byteaowner_type int2 NNserialized_object bytea NNobjects_snapshotPKobject_id ref(objects_history) bytea NNcheckpoint_sequence_number int8 NNcoin_balance int8coint_type textdf_kind int2df_name byteadf_object_id byteadf_object_type textobject_digest byteaobject_status int2 NNobject_type textobject_version in8 NNowner_id byteaowner_type int2serialized_object byteaobjects_historyPKcheckpoint_sequence_number ref(checkpoints) int8 NNPKobject_id ref(objects) bytea NNPKobject_version int8 NNcoin_balance int8coint_type textdf_kind int2df_name byteadf_object_id byteadf_object_type textobject_digest byteaobject_status int2 NNobject_type textowner_id byteaowner_type int2serialized_object byteaepochsPKepoch int8 NNburn_leftover_amount int8burn_tokens_amount int8epoch_commitments byteaepoch_end_timestamp int8epoch_start_timestamp int8 NNepoch_total_transactions int8first_checkpoint_id ref(checkpoints) int8 NNlast_checkpoint_id ref(checkpoints) int8minted_tokens_amount int8protocol_version int8 NNreference_gas_price int8 NNstake_subsidy_amount int8storage_charge int8storage_fund_balance int8 NNstorage_rebate int8system_state bytea NNtotal_gas_fees int8total_stake int8 NNtotal_stake_reward_distributed int8checkpointsPKsequence_number int8 NNcheckpoint_digest bytea NNepoch int8 NNnetwork_total_transactions int8 NNprevious_checkpoint_digest byteaend_of_epoch bool NNend_of_epoch_data byteatx_digests bytea[] NNtimestamp_ms int8 NNtotal_gas_cost int8 NNcomputation_cost int8 NNstorage_cost int8 NNstorage_rebate int8 NNnon_refundable_storage_fee int8 NNcheckpoint_commitments bytea NNvalidator_signature bytea NNend_of_epoch_data byteatransactionsPKcheckpoint_sequence_number ref(checkpoints) int8 NNPKtx_sequence_number int8 NNbalance_changes bytea[] NNevents bytea[] NNobject_changes bytea[] NNraw_effects bytea NNraw_transaction bytea NNsuccess_command_count int2 NNtimestamp_ms ref(checkpoints) int8 NNtransaction_digest ref(checkpoints) bytea NNtransaction_kind int2 NNeventsPKevent_ sequence_number int8 NNPKtx_sequence_number ref(transactions) int8 NNbcs bytea NNcheckpoint_sequence_number ref(checkpoints) int8 NNevent_type text NNmodule text NNpackage bytea NNsenders bytea[] NNtimestamp_ms ref(checkpoints) int8 NNtransaction_digest ref(transactions) bytea NNtx_sendersPKsender bytea NNPKtx_sequence_number ref(transactions). int8 NNtx_recipientsPKrecipient bytea NNPKtx_sequence_number ref(transactions). int8 NNtx_callsPKpackage ref(packages) bytea NNPKtx_sequence_number ref(transactions) int8 NNbcs bytea NNid bytea NNversion int2 NNtx_input_objectsPKobject_id bytea NNPKtx_sequence_number ref(transactions) int8 NNtx_changed_objectsPKobject_id bytea NNPKtx_sequence_number ref(transactions) int8 NNpackagesPKpackage_id bytea NNmove_package bytea NN__diesel_schema_migrationsPKversion varchar(50) NNrun_on timestamp NNLegendDatabase schemaref(< table-name >) Possible Foreign Key linktx_count_metricsPKcheckpoint_sequence_number ref(checkpoints) int8 NNepoch ref(epochs) int8 NNtimestamp_ms int8 NNtotal_transaction_blocks int8 NNtotal_successful_transaction_blocks int8 NNtotal_successful_transactions int8 NNmove_callsPKtransactions_sequence_number ref(transactions) int8 NNPKmove_package bytea NNPKmove_module text NNPKmove_function text NNcheckpoint_sequence_number ref(checkpoints) int8 NNepoch ref(epochs) int8 NNmove_call_metricsPKid bigserial NNcount int8 NNday int8 NNepoch ref(epochs) int8 NNmove_function text NNmove_module text NNmove_package text NNaddressesPKaddress bytea NNfirst_appearance_time int8 NNfirst_appearance_tx int8 NNlast_appearance_time int8 NNlast_appearance_tx int8 NNactive_addressesPKaddress bytea NNfirst_appearance_time int8 NNfirst_appearance_tx int8 NNlast_appearance_time int8 NNlast_appearance_tx int8 NNaddress_metricsPKcheckpoint ref(checkpoints) int8 NNcumulative_active_addresses int8 NNcumulative_addresses int8 NNdaily_active_addresses int8 NNepoch ref(epochs) int8 NNtimestamp_ms int8 NNepoch_peak_tpsPKepoch ref(epochs) int8 NNpeak_tps float8 NNpeak_tps_30d float8 NN \ No newline at end of file +displayPKobject_type text NNbcs bytea NNid bytea NNversion int2 NNobjectsPKobject_id bytea NNcheckpoint_sequence_number ref(checkpoints) int8 NNcoin_balance int8coint_type textdf_kind int2df_name byteadf_object_id byteadf_object_type textobject_digest bytea NNobject_type textobject_type_module textobject_type_name textobject_type_package byteaobject_version in8 NNowner_id byteaowner_type int2 NNserialized_object bytea NNobjects_snapshotPKobject_id ref(objects_history) bytea NNcheckpoint_sequence_number ref(checkpoints) int8 NNcoin_balance int8coint_type textdf_kind int2df_name byteadf_object_id byteadf_object_type textobject_digest byteaobject_status int2 NNobject_type textobject_type_module textobject_type_name textobject_type_package byteaobject_version in8 NNowner_id byteaowner_type int2serialized_object byteaobjects_historyPKcheckpoint_sequence_number ref(checkpoints) int8 NNPKobject_id ref(objects) bytea NNPKobject_version int8 NNcoin_balance int8coint_type textdf_kind int2df_name byteadf_object_id byteadf_object_type textobject_digest byteaobject_status int2 NNobject_type textobject_type_module textobject_type_name textobject_type_package byteaowner_id byteaowner_type int2serialized_object byteaepochsPKepoch int8 NNburn_tokens_amount int8epoch_commitments byteaepoch_end_timestamp int8epoch_start_timestamp int8 NNepoch_total_transactions int8first_checkpoint_id ref(checkpoints) int8 NNlast_checkpoint_id ref(checkpoints) int8minted_tokens_amount int8protocol_version int8 NNreference_gas_price int8 NNstorage_charge int8storage_fund_balance int8 NNstorage_rebate int8system_state bytea NNtotal_gas_fees int8total_stake int8 NNtotal_stake_reward_distributed int8checkpointsPKsequence_number int8 NNcheckpoint_commitments bytea NNcheckpoint_digest bytea NNcomputation_cost int8 NNend_of_epoch bool NNend_of_epoch_data byteaepoch int8 NNmax_tx_sequence_number int8min_tx_sequence_number int8network_total_transactions int8 NNnon_refundable_storage_fee int8 NNprevious_checkpoint_digest byteastorage_cost int8 NNstorage_rebate int8 NNtimestamp_ms int8 NNtotal_gas_cost int8 NNtx_digests bytea[] NNvalidator_signature bytea NNtransactionsPKtx_sequence_number int8 NNbalance_changes bytea[] NNcheckpoint_sequence_number ref(checkpoints) int8 NNevents bytea[] NNobject_changes bytea[] NNraw_effects bytea NNraw_transaction bytea NNsuccess_command_count int2 NNtimestamp_ms ref(checkpoints) int8 NNtransaction_digest ref(checkpoints) bytea NNtransaction_kind int2 NNeventsPKevent_ sequence_number int8 NNPKtx_sequence_number ref(transactions) int8 NNbcs bytea NNevent_type text NNmodule text NNpackage bytea NNsenders bytea[] NNtimestamp_ms ref(checkpoints) int8 NNtransaction_digest ref(transactions) bytea NNtx_sendersPKsender bytea NNPKtx_sequence_number ref(transactions) int8 NNtx_recipientsPKrecipient bytea NNPKtx_sequence_number ref(transactions) int8 NNsender bytea NNpackagesPKoriginal_id bytea NNPKpackage_id bytea NNPKpackage_version int8 NNcheckpoint_sequence_number ref(checkpoints) int8 NNmove_package bytea NN__diesel_schema_migrationsPKversion varchar(50) NNrun_on timestamp NNLegendDatabase schemaref(< table-name >) Possible Foreign Key linkDatabase Viewtx_count_metricsPKcheckpoint_sequence_number ref(checkpoints) int8 NNepoch ref(epochs) int8 NNtimestamp_ms int8 NNtotal_successful_transaction_blocks int8 NNtotal_successful_transactions int8 NNtotal_transaction_blocks int8 NNmove_callsPKmove_function text NNPKmove_module text NNPKmove_package bytea NNPKtransactions_sequence_number ref(transactions) int8 NNcheckpoint_sequence_number ref(checkpoints) int8 NNepoch ref(epochs) int8 NNmove_call_metricsPKid bigserial NNcount int8 NNday int8 NNepoch ref(epochs) int8 NNmove_function text NNmove_module text NNmove_package text NNaddressesPKaddress bytea NNfirst_appearance_time int8 NNfirst_appearance_tx int8 NNlast_appearance_time int8 NNlast_appearance_tx int8 NNactive_addressesPKaddress bytea NNfirst_appearance_time int8 NNfirst_appearance_tx int8 NNlast_appearance_time int8 NNlast_appearance_tx int8 NNaddress_metricsPKcheckpoint ref(checkpoints) int8 NNcumulative_active_addresses int8 NNcumulative_addresses int8 NNdaily_active_addresses int8 NNepoch ref(epochs) int8 NNtimestamp_ms int8 NNepoch_peak_tpsPKepoch ref(epochs) int8 NNpeak_tps float8 NNpeak_tps_30d float8 NNchain_identifierPKcheckpoint_digest ref(checkpoints) bytea NNreal_time_tpsrecent_tps float8tx_digestsPKtx_digest bytea NNtx_sequence_number ref(transactions) int8 NNtx_kindsPKtx_kind int2 NNPKtx_sequence_number ref(transactions) int8 NNevent_sendersPKevent_sequence_number ref(events) int8 NNPKsender bytea NNPKtx_sequence_number ref(transactions) int8 NNfeature_flagsPKflag_name text NNPKprotocol_version int8 NNflag_value bool NNprotocol_configsPKconfig_name text NNPKprotocol_version int8 NNconfig_value textobjects_versionPKobject_id ref(objects) bytea NNPKobject_version ref(objects) int8 NNcp_sequence_number ref(checkpoints) int8 NNpruner_cp_watermarkPKcheckpoint_sequence_number ref(checkpoints) int8 NNPKmax_tx_sequence_number int8 NNmin_tx_sequence_number int8 NNtx_changed_objectsPKobject_id ref(objects) bytea NNPKtx_sequence_number ref(transactions) int8 NNsender bytea NNtx_input_objectsPKobject_id ref(objects) bytea NNPKtx_sequence_number ref(transactions) int8 NNsender bytea NNevent_emit_packagePKevent_sequence_number ref(events) int8 NNPKpackage ref(packages) bytea NNPKtx_sequence_number ref(transactions) int8 NNsender bytea NNevent_struct_packagePKevent_sequence_number ref(events) int8 NNPKpackage ref(packages) bytea NNPKtx_sequence_number ref(transactions) int8 NNsender bytea NNevent_emit_modulePKevent_sequence_number ref(events) int8 NNPKmodule text NNPKpackage ref(packages) bytea NNPKtx_sequence_number ref(transactions) int8 NNsender bytea NNnetwork_metricscurrent_checkpoint int8current_epoch int8current_tps float8total_addresses int8total_objects int8total_packages int8tps_30_days float8event_struct_instantiationPKevent_sequence_number ref(events) int8 NNPKmodule text NNPKpackage ref(packages) bytea NNPKtx_sequence_number ref(transactions) int8 NNPKtype_instantiation text NNsender bytea NNevent_struct_namePKevent_sequence_number ref(events) int8 NNPKmodule text NNPKpackage ref(packages) bytea NNPKtx_sequence_number ref(transactions) int8 NNPKtype_name text NNsender bytea NNtx_calls_funPKfunc text NNPKmodule text NNPKpackage ref(packages) bytea NNPKtx_sequence_number ref(transactions) int8 NNsender bytea NNtx_calls_modPKmodule text NNPKpackage ref(packages) bytea NNPKtx_sequence_number ref(transactions) int8 NNsender bytea NNtx_calls_pkgPKpackage ref(packages) bytea NNPKtx_sequence_number ref(transactions) int8 NNsender bytea NNevent_struct_modulePKevent_sequence_number ref(events) int8 NNPKmodule text NNPKpackage ref(packages) bytea NNPKtx_sequence_number ref(transactions) int8 NNsender bytea NN \ No newline at end of file diff --git a/crates/iota-indexer/schema.md b/crates/iota-indexer/schema.md index 39b99baf6b2..a6dcb43689d 100644 --- a/crates/iota-indexer/schema.md +++ b/crates/iota-indexer/schema.md @@ -11,7 +11,8 @@ The Indexer pulls checkpoint data from the full node and populates the tables sh > Migrations are generated by diesel cli, the basic schema can be found [schema.rs](src/schema.rs). > For more in depth understanding of the database tables, go to [migrations](migrations) folder, in the contained `SQL` the indexes, partitions & constraints are declared. > -> - Tables `objects_history` & `transactions` have partitions, each partition is created based on `checkpoint_sequence_number` (related form the `checkpoints` table) it goes from `0` to `MAXVALUE` +> - The table `objects_history` has partitions, each partition is created based on `checkpoint_sequence_number` (related form the `checkpoints` table) it goes from `0` to `MAXVALUE` +> - The table `transactions` has partitions, each partition is created based on `tx_sequence_number` (related form the `transactions` table) it goes from `0` to `MAXVALUE` > - `__diesel_schema_migrations` table is managed by `diesel` cli when applying migrations ## Indexes @@ -23,40 +24,83 @@ The Indexer pulls checkpoint data from the full node and populates the tables sh | checkpoints_epoch | epoch, sequence_number | | checkpoints_digest | checkpoint_digest | +### Table `event_emit_package` + +| Index name | Keys | +| ------------------------- | ---------------------------------------------------------- | +| event_emit_package_sender | sender, package, tx_sequence_number, event_sequence_number | + +### Table `event_emit_module` + +| Index name | Keys | +| ------------------------ | ------------------------------------------------------------------ | +| event_emit_module_sender | sender, package, module, tx_sequence_number, event_sequence_number | + +### Table `event_struct_package` + +| Index name | Keys | +| --------------------------- | ---------------------------------------------------------- | +| event_struct_package_sender | sender, package, tx_sequence_number, event_sequence_number | + +### Table `event_struct_module` + +| Index name | Keys | +| -------------------------- | ------------------------------------------------------------------ | +| event_struct_module_sender | sender, package, module, tx_sequence_number, event_sequence_number | + +### Table `event_struct_name` + +| Index name | Keys | +| ------------------------ | ----------------------------------------------------------------------------- | +| event_struct_name_sender | sender, package, module, type_name, tx_sequence_number, event_sequence_number | + +### Table `event_struct_instantiation` + +| Index name | Keys | +| --------------------------------- | -------------------------------------------------------------------------------------- | +| event_struct_instantiation_sender | sender, package, module, type_instantiation, tx_sequence_number, event_sequence_number | + ### Table `events` -| Index name | Keys | -| --------------------------------- | ----------------------------------------------------------------------- | -| events_package | package, tx_sequence_number, event_sequence_number | -| events_package_module | package, module, tx_sequence_number, event_sequence_number | -| events_event_type | event_type, text_pattern_ops, tx_sequence_number, event_sequence_number | -| events_checkpoint_sequence_number | checkpoint_sequence_number | +| Index name | Keys | +| --------------------- | ----------------------------------------------------------------------- | +| events_package | package, tx_sequence_number, event_sequence_number | +| events_package_module | package, module, tx_sequence_number, event_sequence_number | +| events_event_type | event_type, text_pattern_ops, tx_sequence_number, event_sequence_number | ### Table `objects` -| Index name | Keys | Condition | -| ---------------------------------- | -------------------------- | --------------------------------------------------------- | -| objects_owner | owner_type, owner_id | WHERE owner_type BETWEEN 1 AND 2 AND owner_id IS NOT NULL | -| objects_coin | owner_id, coin_type | WHERE coin_type IS NOT NULL AND owner_type = 1 | -| objects_checkpoint_sequence_number | checkpoint_sequence_number | | -| objects_type | object_type | | +| Index name | Keys | Condition | +| ------------------------------------------- | -------------------------------------------------------------------------------- | --------------------------------------------------------- | +| objects_owner | owner_type, owner_id | WHERE owner_type BETWEEN 1 AND 2 AND owner_id IS NOT NULL | +| objects_coin | owner_id, coin_type | WHERE coin_type IS NOT NULL AND owner_type = 1 | +| objects_checkpoint_sequence_number | checkpoint_sequence_number | | +| objects_package_module_name_full_type | object_type_package, object_type_module, object_type_name, object_type | | +| objects_owner_package_module_name_full_type | owner_id, object_type_package, object_type_module, object_type_name, object_type | | ### Table `objects_snapshot` -| Index name | Keys | Condition | -| ------------------------------------------- | ------------------------------- | --------------------------------------------------------- | -| objects_snapshot_checkpoint_sequence_number | checkpoint_sequence_number | | -| objects_snapshot_coin | owner_id, coin_type, object_id | WHERE coin_type IS NOT NULL AND owner_type = 1 | -| objects_snapshot_type | object_type, object_id | | -| objects_snapshot_owner | owner_type, owner_id, object_id | WHERE owner_type BETWEEN 1 AND 2 AND owner_id IS NOT NULL | +| Index name | Keys | Condition | +| ---------------------------------------------------- | --------------------------------------------------------------------------------- | --------------------------------------------------------- | +| objects_snapshot_checkpoint_sequence_number | checkpoint_sequence_number | | +| objects_snapshot_owner | owner_type, owner_id, object_id | WHERE owner_type BETWEEN 1 AND 2 AND owner_id IS NOT NULL | +| objects_snapshot_coin_owner | owner_id, coin_type, object_id | WHERE coin_type IS NOT NULL AND owner_type = 1 | +| objects_snapshot_coin_only | coin_type, object_id | WHERE coin_type IS NOT NULL | +| objects_snapshot_type_id | object_type_package, object_type_module, object_type_name, object_type, object_id | | +| objects_snapshot_id_type | object_id, object_type_package, object_type_module, object_type_name, object_type | | +| objects_snapshot_owner_package_module_name_full_type | owner_id, object_type_package, object_type_module, object_type_name, object_type | | ### Table `objects_history` -| Index name | Keys | Condition | -| --------------------- | ------------------------------------------------ | --------------------------------------------------------- | -| objects_history_owner | checkpoint_sequence_number, owner_type, owner_id | WHERE owner_type BETWEEN 1 AND 2 AND owner_id IS NOT NULL | -| objects_history_coin | checkpoint_sequence_number, owner_id, coin_type | WHERE coin_type IS NOT NULL AND owner_type = 1 | -| objects_history_type | checkpoint_sequence_number, object_type | | +| Index name | Keys | Condition | +| --------------------------------------------------- | ------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------- | +| objects_history_id_version | object_id, object_version, checkpoint_sequence_number | | +| objects_history_owner | checkpoint_sequence_number, owner_type, owner_id | WHERE owner_type BETWEEN 1 AND 2 AND owner_id IS NOT NULL | +| objects_history_coin_owner | checkpoint_sequence_number, owner_id, coin_type, object_id | WHERE coin_type IS NOT NULL AND owner_type = 1 | +| objects_history_coin_only | checkpoint_sequence_number, coin_type, object_id | WHERE coin_type IS NOT NULL | +| objects_history_type | checkpoint_sequence_number, object_type | | +| objects_history_package_module_name_full_type | checkpoint_sequence_number, object_type_package, object_type_module, object_type_name, object_type | | +| objects_history_owner_package_module_name_full_type | checkpoint_sequence_number, owner_id, object_type_package, object_type_module, object_type_name, object_type | | ### Table `transactions` @@ -66,25 +110,18 @@ The Indexer pulls checkpoint data from the full node and populates the tables sh | transactions_checkpoint_sequence_number | checkpoint_sequence_number | | | transactions_transaction_kind | transaction_kind | WHERE transaction_kind = 1 | -### Table `tx_calls` +### Table `tx_input_objects` -| Index name | Keys | -| --------------------------- | ----------------------------------------- | -| tx_calls_module | package, module, tx_sequence_number | -| tx_calls_func | package, module, func, tx_sequence_number | -| tx_calls_tx_sequence_number | tx_sequence_number | - -### Table `tx_senders` - -| Index name | Keys | Condition | -| ----------------------------------- | ------------------ | --------- | -| tx_senders_tx_sequence_number_index | tx_sequence_number | ASC | +| Index name | Keys | Condition | +| ----------------------------------- | ------------------------------------- | --------- | +| tx_senders_tx_sequence_number_index | tx_sequence_number | | +| tx_input_objects_sender | sender, object_id, tx_sequence_number | | ### Tables `tx_recipients` -| Index name | Keys | Condition | -| -------------------------------------- | ------------------ | --------- | -| tx_recipients_tx_sequence_number_index | tx_sequence_number | ASC | +| Index name | Keys | Condition | +| -------------------- | ------------------------------------- | --------- | +| tx_recipients_sender | sender, recipient, tx_sequence_number | | ### Table `tx_count_metrics` @@ -93,6 +130,37 @@ The Indexer pulls checkpoint data from the full node and populates the tables sh | tx_count_metrics_epoch | epoch | | tx_count_metrics_timestamp_ms | timestamp_ms | +### Table `tx_changed_objects` + +| Index name | Keys | +| ------------------------------------------- | ------------------------------------- | +| tx_changed_objects_tx_sequence_number_index | tx_sequence_number | +| tx_changed_objects_sender | sender, object_id, tx_sequence_number | + +### Table `tx_calls_pkg` + +| Index name | Keys | +| ------------------- | ----------------------------------- | +| tx_calls_pkg_sender | sender, package, tx_sequence_number | + +### Table `tx_calls_mod` + +| Index name | Keys | +| ------------------- | ------------------------------------------- | +| tx_calls_mod_sender | sender, package, module, tx_sequence_number | + +### Table `tx_calls_fun` + +| Index name | Keys | +| ------------------- | ------------------------------------------------- | +| tx_calls_fun_sender | sender, package, module, func, tx_sequence_number | + +### Table `tx_digests` + +| Index name | Keys | +| ----------------------------- | ------------------ | +| tx_digests_tx_sequence_number | tx_sequence_number | + ### Table `move_calls` | Index name | Keys | @@ -111,10 +179,23 @@ The Indexer pulls checkpoint data from the full node and populates the tables sh | ------------------------- | ----- | | address_metrics_epoch_idx | epoch | +### Table `packages` + +| Index name | Keys | +| ---------------------- | -------------------------------------------------------- | +| packages_cp_id_version | checkpoint_sequence_number, original_id, package_version | +| packages_id_version_cp | original_id, package_version, checkpoint_sequence_number | + ## Partitions -### Tables `transactions`, `objects_history` +### Table `objects_history` | Keys | Condition | | -------------------------- | --------------------------------- | | checkpoint_sequence_number | FOR VALUES FROM (0) TO (MAXVALUE) | + +### Table `transactions` + +| Keys | Condition | +| ------------------ | --------------------------------- | +| tx_sequence_number | FOR VALUES FROM (0) TO (MAXVALUE) |