Skip to content

Instantly share code, notes, and snippets.

@sorra
Last active March 17, 2022 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sorra/48bf97796cefa89f3b2124b822fb2705 to your computer and use it in GitHub Desktop.
Save sorra/48bf97796cefa89f3b2124b822fb2705 to your computer and use it in GitHub Desktop.
The slow query on messages table
SELECT messages.* FROM messages
WHERE messages.deleted_at IS NULL AND messages.namespace = ?
AND (
jsonb_extract_path_text(context, 'topic') IN (?, ?)
OR jsonb_extract_path_text(context, 'topic') LIKE ?
)
AND ( context @> '{"involved_parties":[{"id":1,"type":1}]}'::jsonb )
ORDER BY messages.created_at ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment