Exploring run-time reduction in programming codes via query optimization and caching