ALM-167 optimize SQL for responses and events