This book focuses on the optimization of general conjunctive queries (GCQ) using integrity constraints and in the presence of materialized views. A GCQ is a conjunctive query with arbitrary built-in predicates. The integrity constraints we consider are disjunctive constrained tuple- generating dependencies (DCTGDs)which include many traditional integrity constraints such as functional dependencies, inclusion dependencies, and constrained tuple-generating dependencies. We first present an improved method for testing general conjunctive query containment using relevance mappings. We then present a method for testing general conjunctive query containment in the presence of DCTGDs. Our method generalizes and improves previous algorithms for the semantic containment problem of conjunctive queries. When materialized views exist, we study the problem of rewriting a union of general conjunctive queries using the view relations under the open world assumption and present a general approach for such problems. Our approach can rewrite unions of general conjunctive queries when both the query and the views involve built-in predicates.