Claims1. A method comprising performing a machine-executed operation involving instructions, wherein the machine-executed operation is at least one of: A) sending said instructions over transmission media; B) receiving said instructions over transmission media; C) storing said instructions onto a machine-readable storage medium; and D) executing the instructions; wherein said instructions are instructions which, when executed by one or more processors, cause the one or more processors to perform the steps of: evaluating a first database query that requests fields from one or more XML documents stored in a database, wherein the evaluating includes: identifying as correlated fields a first plurality of fields that have a value contained in a XML fragment; determining whether one or more rewrite criteria are satisfied based on the correlated fields; and if said one or more rewrite criteria are satisfied, then rewriting said first database query to generate a rewritten query that includes a new data source that contains field values from said XML fragment, including certain values for said first plurality of fields and at least one field not requested by said database query. 2. The method of claim 1, wherein the new data source includes name-value pairs that represent said certain values. 3. The method of claim 1, wherein the first database query conforms to a standard of SQL. 4. The method of claim 1, wherein the first database query includes a select-list that references said correlated fields but not said at least one field. 5. The method of claim 1, wherein: the first database query requests another field as part of the results to compute for the first database query; and wherein the rewritten query specifies a second data source, different than said new data source, for said another field. 6. The method of claim 1, wherein: said database includes an index that indexes nodes of a collection of XML documents; and wherein execution of the rewritten query uses said index to access said XML documents. 7. The method of claim 1, wherein rewriting said first database query includes rewriting said first database query to access base tables in the database that store XML documents. 8. The method of claim 1, wherein determining whether one or more rewrite criteria is satisfied is based on statistics generated about XML documents stored in the database. 9. The method of claim 1, wherein determining whether one or more rewrite criteria is satisfied is based on the number of correlated fields and a number of fields contained in said XML fragment. 10. A method comprising performing a machine-executed operation involving instructions, wherein the machine-executed operation is at least one of: A) sending said instructions over transmission media; B) receiving said instructions over transmission media; C) storing said instructions onto a machine-readable storage medium; and D) executing the instructions; wherein said instructions are instructions which, when executed by one or more processors, cause the one or more processors to perform the steps of: evaluating a first database query that requests fields from one or more XML documents stored in a database, wherein the evaluating includes: identifying one or more XML fragments as a common data source for a plurality of fields requested by said first database query; for each of the one or more XML fragments identified, establishing as a group of correlated fields the respective plurality of fields; for each group of correlated fields established: determining whether one or more rewrite criteria are satisfied based on the group of correlated fields; and if said one or more rewrite criteria are satisfied, then rewriting said first database query to generate a rewritten query that specifies a new data source for said group of correlated fields, said new data source including certain values for the group's respective XML fragment, said certain values including values for the group of correlated fields and at least one field not requested by said database query. 11. The method of claim 10, wherein: the first database query includes a select-list and a from-list; the rewriting comprises, for each group of correlated fields established, generating in the from-list a subquery whose results include said certain values; and rewriting the select-list to obtain the correlated field values from the results. 12. The method of claim 10, wherein determining whether one or more rewrite criteria is satisfied is based on statistics generated about XML documents stored in the database. 13. The method of claim 10, wherein each new data source established for each group includes name-value pairs that represent said certain values. 14. A machine-readable medium carrying one or more sequences of instructions which, when executed by one or more processors, causes the one or more processors to perform the following steps: evaluating a first database query that requests fields from one or more XML documents stored in a database, wherein the evaluating includes: identifying as correlated fields a first plurality of fields that have a value contained in a XML fragment; determining whether one or more rewrite criteria are satisfied based on the correlated fields; and if said one or more rewrite criteria are satisfied, then rewriting said first database query to generate a rewritten query that includes a new data source that contains field values from said XML fragment, including certain values for said first plurality of fields and at least one field not requested by said database query. 15. The machine-readable medium of claim 14, wherein the new data source includes name-value pairs that represent said certain values. 16. The machine-readable medium of claim 14, wherein the first database query conforms to a standard of SQL. 17. The machine-readable medium of claim 14, wherein the first database query includes a select-list that references said correlated fields but not said at least one field. 18. The machine-readable medium of claim 14, wherein: the first database query requests another field as part of the results to compute for the first database query; and wherein the rewritten query specifies a second data source, different than said new data source, for said another field. 19. The machine-readable medium of claim 14, wherein: said database includes an index that indexes nodes of a collection of XML documents; and wherein execution of the rewritten query uses said index to access said XML documents. 20. The machine-readable medium of claim 14, wherein rewriting said first database query includes rewriting said first database query to access base tables in the database that store XML documents. 21. The machine-readable medium of claim 14, wherein determining whether one or more rewrite criteria is satisfied is based on statistics generated about XML documents stored in the database. 22. The machine-readable medium of claim 14, wherein determining whether one or more rewrite criteria is satisfied is based on the number of correlated fields and a number of fields contained in said XML fragment. 23. A machine-readable medium carrying one or more sequences of instructions which, when executed by one or more processors, causes the one or more processors to perform the following steps: evaluating a first database query that requests fields from one or more XML documents stored in a database, wherein the evaluating includes: identifying one or more XML fragments as a common data source for a plurality of fields requested by said first database query; for each of the one or more XML fragments identified, establishing as a group of correlated fields the respective plurality of fields; for each group of correlated fields established: determining whether one or more rewrite criteria are satisfied based on the group of correlated fields; and if said one or more rewrite criteria are satisfied, then rewriting said first database query to generate a rewritten query that specifies a new data source for said group of correlated fields, said new data source including certain values for the group's respective XML fragment, said certain values including values for the group of correlated fields and at least one field not requested by said database query. 24. The machine-readable medium of claim 23, wherein: the first database query includes a select-list and a from-list; the rewriting comprises, for each group of correlated fields established, generating in the from-list a subquery whose results include said certain values; and rewriting the select-list to obtain the correlated field values from the results. 25. The machine-readable medium of claim 23, wherein determining whether one or more rewrite criteria is satisfied is based on statistics generated about XML documents stored in the database. 26. The machine-readable medium of claim 23, wherein each new data source established for each group includes name-value pairs that represent said certain values. |
| ||||||||||||||