Tip for debugging complex MySQL queries if you have PhpStorm

  • Start a new scratch file (Mac: shift-cmd-N)
  • choose ‘MySQL’
  • Paste your query in
  • Reformat code (Mac: opt-cmd-L)

It’ll colour code and tidy everything, including lining up all the field names and aliases, neatly arranging the joins and the where clauses, plus you can hover over opening or closing brackets and see the opposite bracket highlighted.

This is useful when previewing raw Drupal view SQL and trying to understand it.