The semantic web represents meta-data as a relation of triples using the RDF data model. We have developed a virtual repository system that enables to process queries to RDF views of large relational databases. This provides very flexible views of wrapped relational databases that can be queried using either the RDF-oriented query language RDQL or SQL. Optimization of queries to such views is challenging because the naïve implementation of such general views become very complex. These complex RDF views make it critical to optimize not only data access time but also the time to perform the query optimization itself. We have developed query optimization techniques based on query rewrites and compile time evaluation of subexpressions to reduce the query size during query processing. This enables execution of real-world queries to RDF views of relational databases.