Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(torii-core): add indices to speed up queries #2824

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Loading