BotNetwork

Indexing chat and user ids

index text ids used in WHERE clauses; avoid leading-wildcard searches

Guide1 min readUpdated

Why it matters

Index text ids used in WHERE clauses; avoid leading-wildcard searches.

Practical steps

  1. Choose storage for data chat id indexes deliberately (SQLite vs Postgres vs KV); document why.
  2. Implement index text ids used in WHERE clauses; avoid leading-wildcard searches with migrations that are additive and reversible where possible.
  3. Use transactions / idempotency keys so retries of data chat id indexes do not double-write.
  4. Add a fixture DB and migration test covering data chat id indexes.
  5. Document backup/restore touching tables used by data chat id indexes.

Watch out for

  • Copy-pasting outdated snippets for data chat id indexes without re-reading current official docs.
  • Shipping data chat id indexes to production without a staging rehearsal and a documented rollback.

Related comparisons and tools