Skip to content

Commit

Permalink
indexer-alt: use NULL, instead of DEFAULT VALUE
Browse files Browse the repository at this point in the history
## Description

Add `#[diesel(treat_none_as_default_value = false)]` to model types that
include optional fields. This affects how those fields are written out
to SQL when they contain `None`. Previously (and by default), those
fields would be represented by the keyword `DEFAULT VALUE`, and after
this change, they will be represented by a parameter binding, which will
be bound to `NULL`.

This is semantically identical in our case, because we don't set default
values, but it also results in less variety in prepared statements
(because regardless of the content of fields, they will now all be
represented by a binding), which will improve grouping of statistics
per-statement, and could also improve performance, if those prepared
statements can be cached and re-used.

## Test plan

Re-run indexer on first 100000 checkpoints.
  • Loading branch information
amnn committed Dec 12, 2024
1 parent 58dca7e commit 465401b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 2 additions & 0 deletions crates/sui-indexer-alt-schema/src/epochs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::schema::{kv_epoch_ends, kv_epoch_starts, kv_feature_flags, kv_protoco

#[derive(Insertable, Debug, Clone, FieldCount)]
#[diesel(table_name = kv_epoch_ends)]
#[diesel(treat_none_as_default_value = false)]
pub struct StoredEpochEnd {
pub epoch: i64,
pub cp_hi: i64,
Expand Down Expand Up @@ -47,6 +48,7 @@ pub struct StoredFeatureFlag {

#[derive(Insertable, Debug, Clone, FieldCount)]
#[diesel(table_name = kv_protocol_configs)]
#[diesel(treat_none_as_default_value = false)]
pub struct StoredProtocolConfig {
pub protocol_version: i64,
pub config_name: String,
Expand Down
4 changes: 3 additions & 1 deletion crates/sui-indexer-alt-schema/src/objects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::schema::{

#[derive(Insertable, Debug, Clone, FieldCount)]
#[diesel(table_name = kv_objects, primary_key(object_id, object_version))]
#[diesel(treat_none_as_default_value = false)]
pub struct StoredObject {
pub object_id: Vec<u8>,
pub object_version: i64,
Expand Down Expand Up @@ -70,7 +71,6 @@ pub enum StoredCoinOwnerKind {

#[derive(Insertable, Debug, Clone, FieldCount)]
#[diesel(table_name = sum_coin_balances, primary_key(object_id))]
#[diesel(treat_none_as_default_value = false)]
pub struct StoredSumCoinBalance {
pub object_id: Vec<u8>,
pub object_version: i64,
Expand All @@ -95,6 +95,7 @@ pub struct StoredSumObjType {

#[derive(Insertable, Debug, Clone)]
#[diesel(table_name = wal_coin_balances, primary_key(object_id, object_version))]
#[diesel(treat_none_as_default_value = false)]
pub struct StoredWalCoinBalance {
pub object_id: Vec<u8>,
pub object_version: i64,
Expand All @@ -106,6 +107,7 @@ pub struct StoredWalCoinBalance {

#[derive(Insertable, Debug, Clone)]
#[diesel(table_name = wal_obj_types, primary_key(object_id, object_version))]
#[diesel(treat_none_as_default_value = false)]
pub struct StoredWalObjType {
pub object_id: Vec<u8>,
pub object_version: i64,
Expand Down

0 comments on commit 465401b

Please sign in to comment.