diff --git a/graph/src/schema/entity_type.rs b/graph/src/schema/entity_type.rs index 90f65a360fe..f9fe93cc90e 100644 --- a/graph/src/schema/entity_type.rs +++ b/graph/src/schema/entity_type.rs @@ -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() } } diff --git a/graph/src/schema/input/mod.rs b/graph/src/schema/input/mod.rs index 93147874b8b..9ca31592c11 100644 --- a/graph/src/schema/input/mod.rs +++ b/graph/src/schema/input/mod.rs @@ -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 } } diff --git a/store/postgres/src/relational/ddl.rs b/store/postgres/src/relational/ddl.rs index dfa8ea5119b..a19972ea268 100644 --- a/store/postgres/src/relational/ddl.rs +++ b/store/postgres/src/relational/ddl.rs @@ -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!( diff --git a/store/postgres/src/relational/prune.rs b/store/postgres/src/relational/prune.rs index a209a72c9cd..10a9cff1626 100644 --- a/store/postgres/src/relational/prune.rs +++ b/store/postgres/src/relational/prune.rs @@ -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 @@ -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}'));" diff --git a/store/postgres/src/relational_queries.rs b/store/postgres/src/relational_queries.rs index 44df113713d..add24a98155 100644 --- a/store/postgres/src/relational_queries.rs +++ b/store/postgres/src/relational_queries.rs @@ -2548,7 +2548,7 @@ impl<'a> QueryFragment 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, ...) @@ -2575,7 +2575,7 @@ impl<'a> QueryFragment 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"); @@ -2595,7 +2595,7 @@ impl<'a> QueryFragment for InsertQuery<'a> { out.push_sql(", "); out.push_bind_param::(&row.causality_region)?; }; - if new_vid_form { + if strict_vid_order { out.push_sql(", "); out.push_bind_param::(&row.vid)?; } @@ -5096,7 +5096,7 @@ impl<'a> QueryFragment 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}) @@ -5118,7 +5118,7 @@ impl<'a> QueryFragment for CopyEntityBatchQuery<'a> { out.push_sql(", "); out.push_sql(CAUSALITY_REGION_COLUMN); }; - if new_vid_form { + if strict_vid_order { out.push_sql(", vid"); } @@ -5186,7 +5186,7 @@ impl<'a> QueryFragment for CopyEntityBatchQuery<'a> { )); } } - if new_vid_form { + if strict_vid_order { out.push_sql(", vid"); }