Skip to content

Commit

Permalink
rename helper function and make it complete
Browse files Browse the repository at this point in the history
  • Loading branch information
zorancv committed Jan 31, 2025
1 parent 6a28007 commit 522d7f7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 17 deletions.
8 changes: 6 additions & 2 deletions graph/src/schema/entity_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,12 @@ impl EntityType {
self.schema.is_object_type(self.atom)
}

pub fn new_vid_form(&self) -> bool {
self.schema.new_vid_form()
// Changes the way the VID field is generated. It used to be autoincrement. Now its
// based on block number and the order of the entities in a block. The latter
// represents the write order across all entity types in the subgraph.
pub fn strict_vid_order(&self) -> bool {
// Currently the agregations entities don't have VIDs in insertion order
self.schema.strict_vid_order() && self.is_object_type()
}
}

Expand Down
2 changes: 1 addition & 1 deletion graph/src/schema/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1589,7 +1589,7 @@ impl InputSchema {
Some(EntityType::new(self.cheap_clone(), obj_type.name))
}

pub fn new_vid_form(&self) -> bool {
pub fn strict_vid_order(&self) -> bool {
self.inner.spec_version >= SPEC_VERSION_1_3_0
}
}
Expand Down
8 changes: 5 additions & 3 deletions store/postgres/src/relational/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ impl Table {
Ok(cols)
}

// Currently the agregations entities don't have VIDs in insertion order
let new_vid_form = self.object.new_vid_form() && self.object.is_object_type();
let vid_type = if new_vid_form { "bigint" } else { "bigserial" };
let vid_type = if self.object.strict_vid_order() {
"bigint"
} else {
"bigserial"
};

if self.immutable {
writeln!(
Expand Down
8 changes: 3 additions & 5 deletions store/postgres/src/relational/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ impl TablePair {

let vid_seq = format!("{}_{VID_COLUMN}_seq", self.src.name);

let old_vid_form = !(self.src.object.new_vid_form() && self.src.object.is_object_type());

let mut query = String::new();

// What we are about to do would get blocked by autovacuum on our
Expand All @@ -254,9 +252,9 @@ impl TablePair {
"src" => src_nsp.as_str(), "error" => e.to_string());
}

// Make sure the vid sequence
// continues from where it was
if old_vid_form {
// Make sure the vid sequence continues from where it was in case
// that we use autoincrementing order of the DB
if !self.src.object.strict_vid_order() {
writeln!(
query,
"select setval('{dst_nsp}.{vid_seq}', nextval('{src_nsp}.{vid_seq}'));"
Expand Down
12 changes: 6 additions & 6 deletions store/postgres/src/relational_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2548,7 +2548,7 @@ impl<'a> QueryFragment<Pg> for InsertQuery<'a> {
let out = &mut out;
out.unsafe_to_cache_prepared();

let new_vid_form = self.table.object.new_vid_form() && self.table.object.is_object_type();
let strict_vid_order = self.table.object.strict_vid_order();

// Construct a query
// insert into schema.table(column, ...)
Expand All @@ -2575,7 +2575,7 @@ impl<'a> QueryFragment<Pg> for InsertQuery<'a> {
out.push_sql(CAUSALITY_REGION_COLUMN);
};

if new_vid_form {
if strict_vid_order {
out.push_sql(", vid");
}
out.push_sql(") values\n");
Expand All @@ -2595,7 +2595,7 @@ impl<'a> QueryFragment<Pg> for InsertQuery<'a> {
out.push_sql(", ");
out.push_bind_param::<Integer, _>(&row.causality_region)?;
};
if new_vid_form {
if strict_vid_order {
out.push_sql(", ");
out.push_bind_param::<BigInt, _>(&row.vid)?;
}
Expand Down Expand Up @@ -5096,7 +5096,7 @@ impl<'a> QueryFragment<Pg> for CopyEntityBatchQuery<'a> {
fn walk_ast<'b>(&'b self, mut out: AstPass<'_, 'b, Pg>) -> QueryResult<()> {
out.unsafe_to_cache_prepared();

let new_vid_form = self.src.object.new_vid_form() && self.src.object.is_object_type();
let strict_vid_order = self.src.object.strict_vid_order();

// Construct a query
// insert into {dst}({columns})
Expand All @@ -5118,7 +5118,7 @@ impl<'a> QueryFragment<Pg> for CopyEntityBatchQuery<'a> {
out.push_sql(", ");
out.push_sql(CAUSALITY_REGION_COLUMN);
};
if new_vid_form {
if strict_vid_order {
out.push_sql(", vid");
}

Expand Down Expand Up @@ -5186,7 +5186,7 @@ impl<'a> QueryFragment<Pg> for CopyEntityBatchQuery<'a> {
));
}
}
if new_vid_form {
if strict_vid_order {
out.push_sql(", vid");
}

Expand Down

0 comments on commit 522d7f7

Please sign in to comment.