Skip to content

Commit

Permalink
indexer-alt: remove {sum,wal}_{obj_types,coin_balances} (MystenLabs#2…
Browse files Browse the repository at this point in the history
…0659)

## Description

Clean up the previous consistent pipelines (obj_types and coin_balances)
and their schemas.

## Test plan

CI

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
amnn authored Dec 18, 2024
1 parent d4d8d49 commit 3e63476
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 797 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
CREATE TABLE IF NOT EXISTS sum_obj_types
(
object_id BYTEA PRIMARY KEY,
object_version BIGINT NOT NULL,
owner_kind SMALLINT NOT NULL,
owner_id BYTEA,
package BYTEA,
module TEXT,
name TEXT,
instantiation BYTEA
);

CREATE INDEX IF NOT EXISTS sum_obj_types_owner
ON sum_obj_types (owner_kind, owner_id, object_id, object_version);

CREATE INDEX IF NOT EXISTS sum_obj_types_pkg
ON sum_obj_types (package, object_id, object_version);

CREATE INDEX IF NOT EXISTS sum_obj_types_mod
ON sum_obj_types (package, module, object_id, object_version);

CREATE INDEX IF NOT EXISTS sum_obj_types_name
ON sum_obj_types (package, module, name, object_id, object_version);

CREATE INDEX IF NOT EXISTS sum_obj_types_inst
ON sum_obj_types (package, module, name, instantiation, object_id, object_version);

CREATE INDEX IF NOT EXISTS sum_obj_types_owner_pkg
ON sum_obj_types (owner_kind, owner_id, package, object_id, object_version);

CREATE INDEX IF NOT EXISTS sum_obj_types_owner_mod
ON sum_obj_types (owner_kind, owner_id, package, module, object_id, object_version);

CREATE INDEX IF NOT EXISTS sum_obj_types_owner_name
ON sum_obj_types (owner_kind, owner_id, package, module, name, object_id, object_version);

CREATE INDEX IF NOT EXISTS sum_obj_types_owner_inst
ON sum_obj_types (owner_kind, owner_id, package, module, name, instantiation, object_id, object_version);

CREATE TABLE IF NOT EXISTS sum_coin_balances
(
object_id BYTEA PRIMARY KEY,
object_version BIGINT NOT NULL,
owner_id BYTEA NOT NULL,
coin_type BYTEA NOT NULL,
coin_balance BIGINT NOT NULL
);

CREATE INDEX IF NOT EXISTS sum_coin_balances_owner_type
ON sum_coin_balances (owner_id, coin_type, coin_balance, object_id, object_version);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DROP TABLE IF EXISTS sum_obj_types;

DROP TABLE IF EXISTS wal_obj_types;

DROP TABLE IF EXISTS sum_coin_balances;

DROP TABLE IF EXISTS wal_coin_balances;
72 changes: 1 addition & 71 deletions crates/sui-indexer-alt-schema/src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ use diesel::{
sql_types::SmallInt, FromSqlRow,
};
use sui_field_count::FieldCount;
use sui_types::base_types::ObjectID;

use crate::schema::{
coin_balance_buckets, kv_objects, obj_info, obj_versions, sum_coin_balances, sum_obj_types,
wal_coin_balances, wal_obj_types,
};
use crate::schema::{coin_balance_buckets, kv_objects, obj_info, obj_versions};

#[derive(Insertable, Debug, Clone, FieldCount)]
#[diesel(table_name = kv_objects, primary_key(object_id, object_version))]
Expand All @@ -30,17 +26,6 @@ pub struct StoredObjVersion {
pub cp_sequence_number: i64,
}

/// An insert/update or deletion of an object record, keyed on a particular Object ID and version.
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct StoredObjectUpdate<T> {
pub object_id: ObjectID,
pub object_version: u64,
pub cp_sequence_number: u64,
/// `None` means the object was deleted or wrapped at this version, `Some(x)` means it was
/// changed to `x`.
pub update: Option<T>,
}

#[derive(AsExpression, FromSqlRow, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[diesel(sql_type = SmallInt)]
#[repr(i16)]
Expand All @@ -59,54 +44,6 @@ pub enum StoredCoinOwnerKind {
Consensus = 1,
}

#[derive(Insertable, Debug, Clone, FieldCount)]
#[diesel(table_name = sum_coin_balances, primary_key(object_id))]
pub struct StoredSumCoinBalance {
pub object_id: Vec<u8>,
pub object_version: i64,
pub owner_id: Vec<u8>,
pub coin_type: Vec<u8>,
pub coin_balance: i64,
}

#[derive(Insertable, Debug, Clone, FieldCount)]
#[diesel(table_name = sum_obj_types, primary_key(object_id))]
pub struct StoredSumObjType {
pub object_id: Vec<u8>,
pub object_version: i64,
pub owner_kind: StoredOwnerKind,
pub owner_id: Option<Vec<u8>>,
pub package: Option<Vec<u8>>,
pub module: Option<String>,
pub name: Option<String>,
pub instantiation: Option<Vec<u8>>,
}

#[derive(Insertable, Debug, Clone)]
#[diesel(table_name = wal_coin_balances, primary_key(object_id, object_version))]
pub struct StoredWalCoinBalance {
pub object_id: Vec<u8>,
pub object_version: i64,
pub owner_id: Option<Vec<u8>>,
pub coin_type: Option<Vec<u8>>,
pub coin_balance: Option<i64>,
pub cp_sequence_number: i64,
}

#[derive(Insertable, Debug, Clone)]
#[diesel(table_name = wal_obj_types, primary_key(object_id, object_version))]
pub struct StoredWalObjType {
pub object_id: Vec<u8>,
pub object_version: i64,
pub owner_kind: Option<StoredOwnerKind>,
pub owner_id: Option<Vec<u8>>,
pub package: Option<Vec<u8>>,
pub module: Option<String>,
pub name: Option<String>,
pub instantiation: Option<Vec<u8>>,
pub cp_sequence_number: i64,
}

#[derive(Insertable, Debug, Clone, FieldCount)]
#[diesel(table_name = obj_info, primary_key(object_id, cp_sequence_number))]
pub struct StoredObjInfo {
Expand All @@ -131,13 +68,6 @@ pub struct StoredCoinBalanceBucket {
pub coin_balance_bucket: Option<i16>,
}

/// StoredObjectUpdate is a wrapper type, we want to count the fields of the inner type.
impl<T: FieldCount> FieldCount for StoredObjectUpdate<T> {
// Add one here for cp_sequence_number field, because StoredObjectUpdate is used for
// wal_* handlers, where the actual type to commit has an additional field besides fields of T.
const FIELD_COUNT: usize = T::FIELD_COUNT.saturating_add(1);
}

impl<DB: Backend> serialize::ToSql<SmallInt, DB> for StoredOwnerKind
where
i16: serialize::ToSql<SmallInt, DB>,
Expand Down
52 changes: 0 additions & 52 deletions crates/sui-indexer-alt-schema/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,6 @@ diesel::table! {
}
}

diesel::table! {
sum_coin_balances (object_id) {
object_id -> Bytea,
object_version -> Int8,
owner_id -> Bytea,
coin_type -> Bytea,
coin_balance -> Int8,
}
}

diesel::table! {
sum_displays (object_type) {
object_type -> Bytea,
Expand All @@ -155,19 +145,6 @@ diesel::table! {
}
}

diesel::table! {
sum_obj_types (object_id) {
object_id -> Bytea,
object_version -> Int8,
owner_kind -> Int2,
owner_id -> Nullable<Bytea>,
package -> Nullable<Bytea>,
module -> Nullable<Text>,
name -> Nullable<Text>,
instantiation -> Nullable<Bytea>,
}
}

diesel::table! {
sum_packages (package_id) {
package_id -> Bytea,
Expand Down Expand Up @@ -225,31 +202,6 @@ diesel::table! {
}
}

diesel::table! {
wal_coin_balances (object_id, object_version) {
object_id -> Bytea,
object_version -> Int8,
owner_id -> Nullable<Bytea>,
coin_type -> Nullable<Bytea>,
coin_balance -> Nullable<Int8>,
cp_sequence_number -> Int8,
}
}

diesel::table! {
wal_obj_types (object_id, object_version) {
object_id -> Bytea,
object_version -> Int8,
owner_kind -> Nullable<Int2>,
owner_id -> Nullable<Bytea>,
package -> Nullable<Bytea>,
module -> Nullable<Text>,
name -> Nullable<Text>,
instantiation -> Nullable<Bytea>,
cp_sequence_number -> Int8,
}
}

diesel::allow_tables_to_appear_in_same_query!(
coin_balance_buckets,
ev_emit_mod,
Expand All @@ -264,16 +216,12 @@ diesel::allow_tables_to_appear_in_same_query!(
kv_transactions,
obj_info,
obj_versions,
sum_coin_balances,
sum_displays,
sum_obj_types,
sum_packages,
tx_affected_addresses,
tx_affected_objects,
tx_balance_changes,
tx_calls,
tx_digests,
tx_kinds,
wal_coin_balances,
wal_obj_types,
);
Loading

0 comments on commit 3e63476

Please sign in to comment.