A method and apparatus for rewriting a database command containing an
embedded XML expression such that the rewritten database command recites
a text function, in lieu of the embedded XML expression, is provided.
Advantageously, a DBMS may take advantage of the efficiencies in storing
XML data within the database, while avoiding the generation of
unnecessary XML elements in processing the query when the XML elements
contribute nothing to the outcome of the query. Cost-base or rule-based
analysis may be performed to determine how to rewrite a received database
command. The database server may functionally evaluate the text function
or may use an index defined on a column of the database. The text
function may function as a primary filter or may reference a column upon
which an index is defined, wherein the index operates at the same or
higher level than a column being referenced in the embedded XML
expression.