TRIBS-139 Performance fix for certain queries.