Skip to content

Instantly share code, notes, and snippets.

@antoniosmgatto
Last active September 28, 2020 14:12
Show Gist options
  • Save antoniosmgatto/c17ba4eb6e9ea6efc783a416bfd43d0d to your computer and use it in GitHub Desktop.
Save antoniosmgatto/c17ba4eb6e9ea6efc783a416bfd43d0d to your computer and use it in GitHub Desktop.

SQL tips

An index is a copy

Rules

  1. Any columns involved in queries should be covered by an index
    • but avoid redundant and unused index.
    • sometimes an index prefix is nedeed and sufficient.
  2. Use an OR to return records satisfying one or more of several conditions
    • but a union might be necessary to exploit the indexesa
  3. Is there's an index over all the fields in your query, you're all set
    • if the Mysql is making the wrong choice, help it make the right one.
  4. Avoid redundant data across tables
    • except when reads are slow, read/write ratio is high you can denormalize.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment