Query optimizers in current database management systems (DBMS) often face problems such as intolerably long optimization time and/or poor optimization results when optimizing complex queries. To tackle this challenge, we present a new similarity-based optimization technique in this paper. The key idea is to identify groups of similar subqueries that often appear in a complex query and share the optimization result within each group in the query. An efficient algorithm to identify similar queries in a given query and optimize the query based on similarity is presented. Our experimental results demonstrate that the proposed technique is quite promising in optimizing complex queries in a DBMS.