Skip to content

Commit

Permalink
pick raw SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
zorancv committed May 17, 2024
1 parent e989027 commit 1c4f291
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 39 deletions.
16 changes: 1 addition & 15 deletions store/postgres/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,9 @@ table! {
}
}

// Readonly; not all columns are mapped
table! {
pg_index(indid) {
#[sql_name = "indrelid"]
tabid -> Oid,
#[sql_name = "indexrelid"]
indid -> Oid,
#[sql_name = "indisvalid"]
isvalid -> Bool,
#[sql_name = "indisready"]
isready -> Bool,
}
}

joinable!(pg_class -> pg_namespace(namespace));
joinable!(pg_attribute -> pg_class(relid));
allow_tables_to_appear_in_same_query!(pg_class, pg_namespace, pg_attribute, pg_index);
allow_tables_to_appear_in_same_query!(pg_class, pg_namespace, pg_attribute);

table! {
subgraphs.table_stats {
Expand Down
25 changes: 1 addition & 24 deletions store/postgres/src/deployment_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ use graph::schema::{ApiSchema, EntityKey, EntityType, InputSchema};
use web3::types::Address;

use crate::block_range::{BLOCK_COLUMN, BLOCK_RANGE_COLUMN};
use crate::catalog::{pg_class, pg_index, pg_namespace};
use crate::deployment::{self, OnSync};
use crate::detail::ErrorDetail;
use crate::dynds::DataSourcesTable;
Expand Down Expand Up @@ -1597,27 +1596,6 @@ impl DeploymentStore {
for table in dst.tables.values() {
for (index_name, create_query) in table.create_postponed_indexes() {
let table_name = table.name.clone();
// Version 1 - SQL generated with diesel
use pg_class as c;
use pg_index as x;
use pg_namespace as n;
let ns = diesel::alias!(pg_namespace as ns);
let (ca, ia) = diesel::alias!(pg_class as ca, pg_class as ia);
let q = x::table
.inner_join(ca.on(ca.field(c::oid).eq(x::tabid)))
.inner_join(ia.on(ia.field(c::oid).eq(x::indid)))
.left_join(ns.on(ns.field(n::oid).eq(ca.field(c::namespace))))
.filter(ns.field(n::name).eq(namespace))
.filter(ca.field(c::name).eq(table_name.as_str()))
.filter(ia.field(c::name).eq(index_name.as_str()))
.filter(ca.field(c::kind).eq_any(vec!["r", "m", "p"]))
.filter(ia.field(c::kind).eq_any(vec!["i", "I"]))
.select((x::isvalid, x::isready))
.get_results::<(bool, bool)>(&mut conn)?
.into_iter()
.collect::<Vec<(bool, bool)>>();
println!("SQL: {:?}", q);
// Version 2 - A string SQL:
let query = r#"
SELECT x.indisvalid AS isvalid,
x.indisready AS isready
Expand All @@ -1638,11 +1616,10 @@ impl DeploymentStore {
.into_iter()
.map(|ii| ii.into())
.collect::<Vec<IndexInfo>>();
// TODO: pick one of the above two
assert!(ii_vec.len() <= 1);
// Check if the index is valid. If either isvalid or isready flag of pg_index table
// isn't true, drop it and recreate it.
if ii_vec.len() == 0 || !ii_vec[0].isvalid || !ii_vec[0].isready || true {
if ii_vec.len() == 0 || !ii_vec[0].isvalid || !ii_vec[0].isready {
if ii_vec.len() > 0 {
let drop_query =
sql_query(format!("DROP INDEX {}.{};", namespace, index_name));
Expand Down

0 comments on commit 1c4f291

Please sign in to comment.