The equivalence rules of relational algebra are exploited, in other words, different query structures and orderings can be mathematically proven to yield the same result.
Query rewriting can also involve materialization of views and other subqueries; operations that may or may not be available to the API user.
The query rewriting transformation can be aided by creating indices from which the optimizer can choose (some database systems create their own indexes if deemed useful), mandating the use of specific indices, creating materialized and/or denormalized views, or helping a database system gather statistics on the data and query use, as the optimality depends on patterns in data and typical query usage.
Some sources discuss query rewriting as a distinct step prior to optimization, operating at the level of the user accessible algebra API (e.g.
[citation needed] There are other, largely unrelated concepts also named similarly, for example, query rewriting by search engines.