SQL Query performance optimization

General query speed issues fixed.

Fix for 'Mark all read' issue http://tracker.modx.com/issues/9393