SMS versenden: Query Rewriting and Optimization for Ontological Databases