Calendar module SQL optimizations