[BUGFIX] Missing relations command: optimize SQL