Indexing the context
The history page in my context also allows the user to filter by actor (user), ip (remote_addr) and possible future other entries in the Context.
I wonder what this means for performance? Do you have experience/advice here?
Should I create some indices to improve performance?
operations = [
# Add GIN index on the entire metadata JSON field for general JSON queries
migrations.RunSQL(
"CREATE INDEX IF NOT EXISTS pghistory_context_metadata_gin_idx ON pghistory_context USING GIN (metadata);",
reverse_sql="DROP INDEX IF EXISTS pghistory_context_metadata_gin_idx;"
),
# Add specific indexes for commonly queried JSON keys
migrations.RunSQL(
"CREATE INDEX IF NOT EXISTS pghistory_context_user_idx ON pghistory_context ((metadata->>'user'));",
reverse_sql="DROP INDEX IF EXISTS pghistory_context_user_idx;"
),
migrations.RunSQL(
"CREATE INDEX IF NOT EXISTS pghistory_context_remote_addr_idx ON pghistory_context ((metadata->>'remote_addr'));",
reverse_sql="DROP INDEX IF EXISTS pghistory_context_remote_addr_idx;"
),
# Composite index for user + remote_addr queries
migrations.RunSQL(
"CREATE INDEX IF NOT EXISTS pghistory_context_user_remote_idx ON pghistory_context ((metadata->>'user'), (metadata->>'remote_addr'));",
reverse_sql="DROP INDEX IF EXISTS pghistory_context_user_remote_idx;"
),
]
I can do some experiments/performance tests, but I'd rather build on knowledge already present here :-)
Indexing the context
The history page in my context also allows the user to filter by actor (user), ip (remote_addr) and possible future other entries in the Context.
I wonder what this means for performance? Do you have experience/advice here?
Should I create some indices to improve performance?
I can do some experiments/performance tests, but I'd rather build on knowledge already present here :-)