Query Processing and Optimization for Logic Programs with Certainty Constraints