Skip to content

Commit

Permalink
feat(torii-core): add indices to speed up queries (#2824)
Browse files Browse the repository at this point in the history
* feat(torii-core): add indices to speed up queries

* fmt
  • Loading branch information
Larkooo authored Dec 20, 2024
1 parent d67a5fd commit c0b8033
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions crates/torii/core/src/sql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,15 @@ impl Sql {
TEXT, "
);

indices.push(format!(
"CREATE INDEX IF NOT EXISTS [idx_{table_id}_internal_entity_id] ON [{table_id}] \
([internal_entity_id]);"
));
indices.push(format!(
"CREATE INDEX IF NOT EXISTS [idx_{table_id}_internal_event_message_id] ON \
[{table_id}] ([internal_event_message_id]);"
));

// Recursively add columns for all nested type
add_columns_recursive(
&path,
Expand Down
9 changes: 9 additions & 0 deletions crates/torii/migrations/20241219104134_indices.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Add index on the updated_at column of the entities table. As we are now allowing querying entities by their updated_at
-- we need to ensure that the updated_at column is indexed.
CREATE INDEX idx_entities_updated_at ON entities (updated_at);

-- Add indices on the event_messages_historical table.
CREATE INDEX idx_event_messages_historical_id ON event_messages_historical (id);
CREATE INDEX idx_event_messages_historical_keys ON event_messages_historical (keys);
CREATE INDEX idx_event_messages_historical_event_id ON event_messages_historical (event_id);
CREATE INDEX idx_event_messages_historical_executed_at ON event_messages_historical (executed_at);

0 comments on commit c0b8033

Please sign in to comment.