oliver-zehentleitner / maity

hub: index chat_verdict.set_seq (redaction scans the table on PostgreSQL/SQLite); drop ix_placement_credential_id, covered by the new unique key

Sign in to report

tsk-fscx0prcg7pj Open

Audit round 3b (tsk-hgnbapyw7hnh), read at 80fef076. Kind: slow path / redundant index (migrations).

What is wrong

  • chat_verdict.set_seq has no index: hub/src/maity_hub/migrations/versions/20261114200000_chat_verdict.py:46 (column), :58-60 (FK to event.seq), hub/src/maity_hub/tables.py:2175; the only key is (message_seq, human_id) (tables.py:2177). chat_verdicts.redact_sentence (hub/src/maity_hub/chat_verdicts.py:99-104, called from routes/events.py:1108) runs UPDATE chat_verdict ... WHERE set_seq = :seq on every redaction of a chat_verdict event, so on PostgreSQL and SQLite it scans every verdict on the instance; the table only grows (kept with a deleted account). MariaDB indexes the FK by itself, so the three databases differ.
  • 20261117130000_plc_per_instance.py:32-34 adds the unique key (credential_id, active) (tables.py:1490), which starts with credential_id; the old single-column ix_placement_credential_id (tables.py:1470 index=True, created in 0008_placements.py:123) now only adds write cost. Lookups by credential (placements.py:712, 957, 1487, 1509) and MariaDB's FK are served by the unique key.

Proposal

  • New migration on head: create ix_chat_verdict_set_seq (plus Index(...) in tables.py); drop ix_placement_credential_id (drop index=True at tables.py:1470), downgrade recreates it. Check the drop on the hub-mariadb run.

Effort / risk: S. Low risk; test_schema.py keeps model and migration in step.