Skip to content

Commit

Permalink
docs(iota-indexer): update ERD diagram and README (#4028)
Browse files Browse the repository at this point in the history
* docs(iota-indexer): update ERD diagram and README

* fixup! docs(iota-indexer): update ERD diagram and README
  • Loading branch information
sergiupopescu199 authored Nov 14, 2024
1 parent 4265d92 commit ac01bde
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 41 deletions.
2 changes: 1 addition & 1 deletion crates/iota-indexer/database_schema.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
167 changes: 127 additions & 40 deletions crates/iota-indexer/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 from the `checkpoints` table) it goes from `0` to `MAXVALUE`
> - The table `transactions` has partitions, each partition is created based on `tx_sequence_number` (related from the `transactions` table) it goes from `0` to `MAXVALUE`
> - `__diesel_schema_migrations` table is managed by `diesel` cli when applying migrations
## Indexes
Expand All @@ -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`

Expand All @@ -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_input_objects_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`

Expand All @@ -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 |
Expand All @@ -111,10 +179,29 @@ 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 `objects_version`

| Keys | Condition |
| --------- | ------------------------------------------------------------- |
| object_id | custom function, create a partition for each first byte value |

### Tables `transactions` & `events`

| Keys | Condition |
| ------------------ | --------------------------------- |
| tx_sequence_number | FOR VALUES FROM (0) TO (MAXVALUE) |

0 comments on commit ac01bde

Please sign in to comment.