The present invention relates in general to databases, and in particular to various embodiments of query operations associated with database systems.
Extensible Markup Language (XML) is a restricted form of SGML, the Standard Generalized Markup Language defined in ISO 8879, and represents one form of structuring data. XML is more fully described in “Extensible Markup Language (XML) 1.0 (Second Edition),” W3C Recommendation (6 Oct. 2000), which is incorporated herein by reference for all purposes [and available at http://www.w3.org/TR/2000/REC-xml-20001006] (hereinafter “XML Recommendation”). XML is a useful form of structuring data because it is an open format that is human-readable and machine-interpretable. Other structured languages without these features or with similar features might be used instead of XML, but XML is currently a popular structured language used to encapsulate (obtain, store, process, etc.) data in a structured manner.
An XML document has two parts: 1) a markup document and 2) a document schema. The markup document and the schema are made up of storage units called “elements,” which can be nested to form a hierarchical structure. An example of an XML markup document 10 is shown in
Elements can contain either parsed or unparsed data. Only parsed data is shown for document 10. Unparsed data is made up of arbitrary character sequences. Parsed data is made up of characters, some of which form character data and some of which form markup. The markup encodes a description of the document's storage layout and logical structure. XML elements can have associated attributes, in the form of name-value pairs, such as the publication date attribute of the “citation” element. The name-value pairs appear within the angle brackets of an XML tag, following the tag name.
XML schemas specify constraints on the structures and types of elements and attribute values in an XML document. The basic schema for XML is the XML Schema, described in “XML Schema Part 1: Structures,” W3C Working Draft (24 Sep. 1999), which is incorporated herein by reference for all purposes [and available at http://www.w3.org/TR/1999/WD-xmlschema-1-19990924]. A previous and very widely used schema format is the DTD (Document Type Definition), which is described in the XML Recommendation.
Since XML documents are typically in text format, they can be searched using conventional text search tools. However, such tools may ignore the information content provided by the structure of the document, which is one of the key benefits of XML. Several query languages have been proposed for searching and reformatting XML documents that do consider the XML documents as structured documents. One such language is XQuery, described in “XQuery 1.0: An XML Query Language,” W3C Working Draft (23 Jan. 2007), which is incorporated herein by reference for all purposes [and available at http://www.w3.org/TR/XQuery]. An example of a general form for an XQuery query is shown in
XQuery is derived from an XML query language called Quilt [described at http://www.almaden.ibm.com/cs/people/chamberlin/quilt.html], which in turn borrowed features from several other languages, including XPath 1.0 [described at http://www.w3.org/TR/XPath.html], XQL [described at http://www.w3.org/TandS/QL/QL98/pp/xql.html], XML-QL [described at http://www.research.att.com/˜mff/files/final.html], and OQL.
Query languages predated the development of XML and many relational databases use a standardized query language called SQL, as described in ISO/IEC 9075-1:1999. The SQL language has established itself as the lingua franca for relational database management and provides the basis for systems interoperability, application portability, client/server operation, and distributed databases. XQuery is proposed to fulfill a similar role with respect to XML database systems. As XML becomes the standard for information exchange between peer data stores, and between client visualization tools and data servers, XQuery may become the standard method for storing and retrieving data from XML databases.
With SQL query systems, much work has been done on the issue of efficiency, such as how to process a query, retrieve a matching result set, and present the result set to the human or computer query issuer quickly and with efficient use of resources. As XQuery and other tools are relied on more and more for querying XML documents, query efficiency will be more essential.
One type of query that is not efficiently handled by current XML database systems is determining the position of a word, phrase, or element relative to another element in an XML document. This type of query is referred to herein as an “element query.” For instance, an exemplary element query might be whether a particular word (e.g., “cat”) is contained within (i.e., is a descendant of) a particular element (e.g., “<b>”) in a document. Another exemplary element query might be whether the word “cat” is contained within a nested element of (i.e., is an indirect descendant of) the element “<b>.”
One approach to processing element queries such as those described above involves searching a database of XML documents based on a keyword index to find a result set of documents containing the word “cat,” and then linearly scanning each document in the result set for instances of “cat” within the element “<b>.” However this approach is both time consuming and resource-intensive, particularly if the database contains many documents, and/or if each document is large.
Another prior art approach is known as “fielded search.” With fielded search, a limited number of elements or “fields” of an XML document are identified prior to being ingested into the database, and special purpose indexes are built at ingestion time to facilitate searching of words within those specific elements. While this approach addresses the performance problems of linear searching, it has at least three significant limitations. First, the fields of an XML document to be indexed must be determined prior to ingestion. Thus, the database administrator (or other party responsible for ingestion) must anticipate what fields will likely be searched by users. Second, for pragmatic reasons, the number of such predetermined fields will likely be limited. Finally, the content of each field is indexed as completely “flat” content. Thus, information about elements nested within other elements will be lost. For example, consider the XML construct “<title>My<b>Big</b>Discovery</title>.” If the element “<title>” is chosen to be indexed under fielded search then (depending on the implementation) either (1) only the words “My” and “Discovery” will be indexed against “<title>,” meaning that the word “Big” is completely lost, or (2) “My,” “Big,” and “Discovery” will all be indexed against “<title>,” meaning that the context of the word “Big” within the nested element “<b>” is lost. As can be seen, with fielded search some aspect of content or context is lost.
Embodiments of the present invention address the foregoing and other such problems by providing methods, systems, and computer-readable media for representing and querying positional information about hierarchical documents. Specifically, embodiments of the present invention provide representational schemes and techniques for processing element queries efficiently and without prior knowledge about which fields of a document to index. Various embodiments also enable the processing of element queries that require knowledge about the hierarchical structure of elements within a document.
According to one embodiment of the present invention, a computer-implemented method for representing word positions in a hierarchical document comprises receiving a hierarchical document comprising a plurality of words and a plurality of elements, at least one word in the plurality of words being a descendant of at least one element in the plurality of elements. The method further comprises associating at least one word in the plurality of words with one or more word positions, the word positions indicating positions of the word relative to other words within the hierarchical document, and associating at least one element in the plurality of elements with one or more word position ranges, each word position within the one or more word position ranges corresponding to a word in the plurality of words that is a descendant of the element.
In various embodiments, at least one element in the plurality of elements has zero descendants, and is associated with a word position range indicating a range of zero word positions. In further embodiments, a first element in the plurality of elements is a descendant of a second element in the plurality of elements, and one or more word position ranges associated with the second element indicate a range of word positions subsumed by the first element.
According to another embodiment of the present invention, a computer-implemented method for determining whether one or more words are descendants of an element in a hierarchical document comprises retrieving word positions for the one or more words, retrieving one or more word position ranges for the element, and processing the word positions for the one or more words and the one or more word position ranges for the element to determine whether the one or more words are descendants of the element. In various embodiments, the processing may comprise determining whether the one or more words are direct descendants of the element, and/or determining whether the one or more words are indirect descendants of the element.
In one set of embodiments, the word positions for the one or more words may be indexed in a first database index, and the word position ranges for the element may be indexed in a second database index. In these embodiments, the first and second indexes may be intersected to determine whether the one or more words are descendants of the element.
According to another embodiment of the present invention, the word position ranges for an element in a hierarchical document are encoded using a space-efficient format, such as delta encoding.
According to yet another embodiment of the present invention, a database system is disclosed. The database system comprises a database configured to store a plurality of hierarchical documents, where a first hierarchical document in the plurality of hierarchical documents comprises a plurality of words and a plurality of elements, at least one word in the plurality of words being a descendant of at least one element in the plurality of elements. At least one word in the plurality of words is associated with one or more word positions, the word positions indicating positions of the word relative to other words within the first hierarchical document, and at least one element in the plurality of elements is associated with one or more word position ranges, each word position within the one or more word position ranges corresponding to a word in the plurality of words that is a descendant of the element.
In various embodiments, the database system further comprises a query engine configured to receive a query, and to return a result responsive to the query by analyzing one or more of the word positions and one or more of the word position ranges. In one embodiment, the query is whether one or more words in the first hierarchical document are direct descendants of a particular element in the first hierarchical document. In an alternative embodiment, the query is whether one or more words in the first hierarchical document are indirect descendants of a particular element in the first hierarchical document.
According to yet another embodiment of the present invention, a computer program product embedded in a computer readable medium comprises program code for receiving a hierarchical document comprising a plurality of words and a plurality of elements, at least one word in the plurality of words being a descendant of at least one element in the plurality of elements. The computer program product further comprises program code for associating at least one word in the plurality of words with one or more word positions, the word positions indicating positions of the word relative to other words within the hierarchical document, and program code for associating at least one element in the plurality of elements with one or more word position ranges, each word position within the one or more word position ranges corresponding to a word in the plurality of words that is a descendant of the element.
A further understanding of the nature and the advantages of the embodiments disclosed herein may be realized by reference to the remaining portions of the specification and the attached drawings.
Various embodiments in accordance with the present invention will be described with reference to the drawings, in which:
In the following description, for the purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the present invention. It will be apparent, however, to one skilled in the art that the present invention may be practiced without some of these specific details. In other instances, well-known structures and devices are shown in block diagram form.
Subtree Decomposition
In an embodiment of the present invention, an XML document (or other structured document) is parsed into “subtrees” for efficient handling. An example of an XML document and its decomposition is described in this section, with following sections describing apparatus, methods, structures and the like that might create and store subtrees. Subtree decomposition is explained with reference to a simple example, but it should be understood that such techniques are equally applicable to more complex examples.
In a convention used for the figures of the present application, directed edges are oriented from an initial node that is higher on the page than the edge's terminal node, unless otherwise indicated. Nodes are represented by their labels, often with their delimiters. Thus, the root node in
As used herein, “subtree” refers to a set of nodes with a property that one of the nodes is a root node and all of the other nodes of the set can be reached by following edges in the orientation direction from the root node through zero or more non-root nodes to reach that other node. A subtree might contain one or more overlapping nodes that are also members of other “inner” or “lower” subtrees; nodes beyond a subtree's overlapping nodes are not generally considered to be part of that subtree. The tree of
To simplify the following description and figures, single letter labels will be used, as in
Some nodes may contain one or more attributes, which can be expressed as (name, value) pairs associated with nodes. In graph theory terms, the directed edges come in two flavors, one for a parent-child relationship between two tags or between a tag and its data node, and one for linking a tag with an attribute node representing an attribute of that tag. The latter is referred to herein as an “attribute edge”. Thus, adding an attribute (key, value) pair to an XML file would map to adding an attribute edge and an attribute node, followed by an attribute value node to a tree representing that XML file. A tag node can have more than one attribute edge (or zero attribute edges). Attribute nodes have exactly one descendant node, a value node, which is a leaf node and a data node, the value of which is the value from the attribute pair.
In the tree diagrams used herein, attribute edges sometimes are distinguished from other edges in that the attribute name is indicated with a preceding “@”.
Note from
The pointer in a link node advantageously does not reference the other link node specifically; instead the pointer advantageously references the subtree in which the other link node can be found.
Navigation from lower link node 106 to upper link node 104 (and vice versa) is nevertheless possible. For instance, the target location of lower link node 106 can be used to obtain a data structure for subtree 100 (an example of such a data structure is described below). The data structure for subtree 100 includes all seven of the nodes shown for subtree 100 in
Using a reference scheme that connects a link node to a target subtree (rather than to a particular node within the target subtree) makes lower link node 106 insensitive to changes in subtree 100. For instance, a new node may be added to subtree 100, causing the storage location of upper link node 104 to change. Lower link node 106 need not be modified; it can still reference subtree 100 and be able to locate upper link node 104. Likewise, upper link node 104 is insensitive to changes in subtree 102 that might affect the location of lower link node 106. This increases the modularity of the subtree structure. Subtree 100 can be modified without affecting link node 106 as long as link node 104 is not deleted. (If link node 104 is deleted, then subtree 102 is likely to be deleted as well.) Similarly, subtree 102 can be modified without affecting link node 104; if subtree 102 is deleted, then link node 104 will likely be deleted as well. Handling subtree updates that affect other subtrees is described in detail in Lindblad IIIA.
It should be noted that this indirect indexing approach is reliable as long as cyclic connections between subtrees are not allowed, i.e., as long as subtree 100 has only one node that connects to subtree 102 and vice versa. Those of ordinary skill in the art will appreciate that non-circularity is an inherent feature of XML and numerous other structured document formats.
Subtree Data Structure
Each subtree can be stored as a data structure in a storage area (e.g., in memory or on disk), preferably in a contiguous region of the storage area.
In
As shown in
It should be noted that each link node (such as described above with reference to
In the case where link node block 1212(1) corresponds to link node 106 of
As shown in
Atom data block 1214 is shown in detail in
It will be appreciated that the data structure described herein for storing subtree data is illustrative and that variations and modifications are possible. Different fields and/or field names may be used, and not all of the data shown herein is required. The particular coding schemes (e.g., unary coding, atom coding) described herein need not be used; different coding schemes or unencoded data may be stored. The arrangement of data into blocks may also be modified without restriction, provided that it is possible to determine which nodes are associated with a particular subtree and to navigate hierarchically between subtrees. Further, as described below, subtree data can be found in scratch space, in memory and on disk, and implementation details of the subtree data structure, including the atom data substructure, may vary within the same embodiment, depending on whether an in-scratch, in-memory, or on-disk subtree is being provided.
Database Management System
System Overview
According to one embodiment of the invention, a computer database management system is provided that parses XML documents into subtree data structures (e.g., similar to the data structure described above), and updates the subtree data structures as document data is updated. The subtree data structures may also be used to respond to queries.
A typical XML handling system according to one embodiment of the present invention is illustrated in
System 1300 also includes parameter storage 1312 that maintains parameters usable to control operation of elements of system 1300 as described below. Parameter storage 1312 can include permanent memory and/or changeable memory; it can also be configured to gather parameters via calls to remote data structures. A user interface 1314 might also be provided so that a human or machine user can access and/or modify parameters stored in parameter storage 1312.
Data loader 1304 includes an XML parser 1316, a stand builder 1318, a scratch storage unit 1320, and interfaces as shown. Scratch storage 1320 is used to hold a “scratch” stand 1321 (also referred to as an “in-scratch stand”) while it is in the process of being built by stand builder 1318. Building of a stand is described below. After scratch stand 1321 is completed (e.g., when scratch storage 1320 is full), it is transferred to database 1308, where it becomes stand 1321′.
System 1300 might comprise dedicated hardware such as a personal computer, a workstation, a server, a mainframe, or similar hardware, or might be implemented in software running on a general purpose computer, either alone or in conjunction with other related or unrelated processes, or some combination thereof. In one example described herein, database 1308 is stored as part of a storage subsystem designed to handle a high level of traffic in documents, queries and retrievals. System 1300 might also include a database manager 1332 to manage database 1308 according to parameters available in parameter storage 1312.
System 1300 reads and stores XML schema data type definitions and maintains a mapping from document elements to their declared types at various points in the processing. System 1300 can also read, parse and print the results of XML XQuery expressions evaluated across the XML database and XML schema store.
Forests, Stands, and Subtrees
In the architecture described herein, XML database 1308 includes one or more “forests” 1322, where a forest is a data structure against which a query is made. In one embodiment, a forest 1322 encompasses the data of one or more XML input documents. Forest 1322 is a collection of one or more “stands” 1306, wherein each stand is a collection of one or more subtrees (as described above) that is treated as a unit of the database. The contents of a stand in one embodiment are described below. In some embodiments, physical delimitations (e.g., delimiter data) are present to delimit subtrees, stands and forests, while in other embodiments, the delimitations are only logical, such as by having a table of memory addresses and forest/stand/subtree identifiers, and in yet other embodiments, a combination of those approaches might be used.
In one implementation, a forest 1322 contains some number of stands 1306, and all but one of these stands resides in a persistent on-disk data store (shown as database 1308) as compressed read-only data structures. The last stand is an “in-memory” stand (not shown) that is used to re-present subtrees from on-disk stands to system 1300 when appropriate (e.g., during query processing or subtree updates). System 1300 continues to add subtrees to the in-memory stand as long as it remains less than a certain (tunable) size. Once the size limit is reached, system 1300 automatically flushes the in-memory stand out to disk as a new persistent (“on-disk”) stand.
Data Flow
Two main data flows into database 1308 are shown. The flow on the right shows XML documents 1302 streaming into the system through a pipeline comprising an XML parser 1316 and a stand builder 1318. These components identify and act upon each subtree as it appears in the input document stream, as described below. The pipeline generates scratch data structures (e.g., a stand 1320) until a size threshold is exceeded, at which point the system automatically flushes the in-memory data structures to disk as a new persistent on-disk stand 1306.
The flow on the left shows processing of queries. A query processor 1310 receives a query (e.g., XQuery query 1340), parses the query, optimizes it to minimize the amount of computation required to evaluate the query, and evaluates it by accessing database 1308. For instance, query processor 1310 advantageously applies a query to a forest 1322 by retrieving a stand 1306 from disk into memory, apply the query to the stand in memory, and aggregate results across the constituent stands of forest 1322; some implementations allow multiple stands to be processed in parallel. Results 1342 are returned to the user. One such query system could be the system described in Lindblad IIA.
Queries to query processor 1310 can come from human users, such as through an interactive query system, or from computer users, such as through a remote call instruction from a running computer program that uses the query results. In one embodiment, queries can be received and responded to using a hypertext transfer protocol (HTTP). It is to be understood that a wide variety of query processors can be used with the subtree-based database described herein, and a detailed description of a particular query processor is omitted as not being crucial to understanding the present invention.
Processing of input documents will now be described.
Parser 1316 also includes a subtree finder 1406 that allocates nodes identified in the tokenized document to subtrees according to subtree rules 1408 stored in parameter storage 1312. In one embodiment, subtree finder 1406 allocates nodes to subtrees based on a subtree root element indicated by the subtree rules 1408 Thus, an XML document is divided into subtrees from matching subtree nodes down. For example, if an XML document including citations was processed and the subtree root element was set to “citation”, the XML document would be divided into subtrees each having a root node of “citation”. In other cases, the division of subtrees is not strictly by elements, but can be by subtree size or tree depth constraints, or a combination thereof or other criteria.
Each subtree identified by subtree finder 1406 are provided to stand builder 1318, which includes a subtree analyzer 1410, a posting list generator 1412, and a key generator 1414. Subtree analyzer 1410 generates a subtree data structure (e.g., data structure 1200 of
As stand builder 1318 generates the various data structures associated with subtrees, it places them into scratch stand 1320, which acts as a scratch storage unit for building a stand. The scratch storage unit is flushed to disk when it exceed a certain size threshold, which can be set by a database administrator (e.g., by setting a parameter in parameter storage 1312). In some implementations of data loader 1304, multiple parsers 1316 and/or stand builders 1318 are operated in parallel (e.g., as parallel processes or threads), but preferably each scratch storage unit is only accessible by one thread at a time.
Stand Structure
One example of a structure of an XML database used with the present invention is shown in
Forest structure 1504 includes one or more stand structures 1506, each of which contains data related to a number of subtrees, as shown in detail for stand 1506. For example, stand 1506 may be a directory in a disk-based file system, and each of the blocks may be a file. Other implementations are also possible, and the description of “files” herein should be understood as illustrative and not limiting of the invention.
TreeData file 1510 includes the data structure (e.g., data structure 1200 of
ListData file 1514 contains information about the text or other data contained in the subtrees that is useful in processing queries. For example, in one embodiment, ListData file 1514 stores “posting lists” of subtree identifiers for subtrees containing a particular term (e.g., an atom), and ListIndex file 1516 is used to provide more efficient access to particular terms in ListData file 1514. Examples of posting lists and their creation are described in detail in Lindblad IIA, and a detailed description is omitted herein as not being critical to understanding the present invention.
Qualities file 1518 provides a fixed-width array indexed by subtree identifier that encodes one or more numeric quality values for each subtree; these quality values can be used for classifying subtrees or XML documents. Numeric quality values are optional features that may be defined by a particular application. For example, if the subtree store contained Internet web pages as XHTML, with the subtree units specified as the <HTML> elements, then the qualities block could encode some combination of the semantic coherence and inbound hyper link density of each page. Further examples of quality values that could be implemented are described in Lindblad IVA, and a detailed description is omitted herein as not being critical to understanding the present invention.
Timestamps file 1520 provides a fixed-width array indexed by subtree identifier that stores two 64-bit timestamps indicating a creation and deletion time for the subtree. For subtrees that are current, the deletion timestamp may be set to a value (e.g., zero) indicating that the subtree is current. As described below, Timestamps file 1520 can be used to support modification of individual subtrees, as well as storing of archival information.
The next three files provide selected information from the data structure 1200 for each subtree in a readily-accessible format. More specifically, Ordinals file 1522 provides a fixed-width array indexed by subtree identifier that stores the initial ordinal for each subtree, i.e., the ordinal value stored in block 1202 of the data structure 1200 for that subtree; because the ordinal increments as every node is processed, the ordinals for different subtrees reflects the ordering of the nodes within the original XML document. URI-Keys file 1524 provides a fixed-width array indexed by subtree identifier that stores the URI key for each subtree, i.e., the uri-key value stored in block 1202 of the data structure 1200. Unique-Keys file 1526 provides a fixed-width array indexed by subtree identifier that stores the unique key for each subtree, i.e., the unique-key value stored in block 1202 of the data structure 1200. It should be noted that any of the information in the Ordinals, URI-Keys, and Unique-Keys files could also be obtained, albeit less efficiently, by locating the subtree in the TreeData file 1510 and reading its subtree data structure 1200. Thus, these files are to be understood as auxiliary files for facilitating access to selected, frequently used information about the subtrees. Different files and different combinations of data could also be stored in this manner.
Frequencies file 1528 stores a number of entries related to the frequency of occurrence of selected tokens, which might include all of the tokens in any subtrees in the stand or a subset thereof. In one embodiment, for each selected token, frequency file 1528 holds a count of the number of subtrees in which the token occurs.
It will be appreciated that the stand structure described herein is illustrative and that variations and modifications are possible. Implementation as files in a directory is not required; a single structured file or other arrangement might also be used. The particular data described herein is not required, and any other data that can be maintained on a per-subtree basis may also be included. Use of subtree data structure 1200 is not required; as described above, different subtree data structures may also be implemented.
Creation, Updating, and Deletion of Subtrees
As the stands of a forest are generated, processed and stored, they can be “log-structured”, i.e., each stand can be saved to a file system as a unit that is never edited (other than the timestamps file). To update a subtree, the old subtree is marked as deleted (e.g., by setting its deletion timestamp in Timestamps file 1520) and a new subtree is created. The new subtree with the updated information is constructed in a memory cache as part of an in-memory stand and eventually flushed to disk, so that in general, the new subtree may be in a different stand from the old subtree it replaces. Thus, any insertions, deletions and updates to the forest are processed by writing new or revised subtrees to a new stand. This feature localizes updates, rather than requiring entire documents to be replaced.
It should be noted that in some instances, updates to a subtree will also affect other subtrees; for instance, if a lower subtree is deleted, the link node in the upper subtree is preferably be removed, which would require modifying the upper subtree. Transactional updating procedures that might be implemented to handle such changes while maintaining consistency are described in detail in Lindblad IIIA.
It is to be understood that marking a subtree as deleted does not require that the subtree immediately be removed from the data store. Rather than removing any data, the current time can be entered as a deletion timestamp for the subtree in Timestamps file 1520 of
Merging of Stands
Stand size is advantageously controlled to provide efficient I/O, e.g., by keeping the TreeData file size of a stand close to the maximum amount of data that can be retrieved in a single I/O operation. As stands are updated, stand size may fluctuate. In some embodiments of the invention, merging of stands is provided to keep stand size optimized. For example, in system 1300 of
In one embodiment, the background merge process can be tuned by two parameters: Merge-min-ratio and Merge-min-size, which can be provided by parameter storage 1312. Merge-min-ratio specifies the minimum allowed ratio between any two on-disk stands; once the ratio is exceeded, system 1300 automatically schedules stands for merging to reduce the maximum size ratio between any two on-disk stands. Merge-min-size limits the minimum size of any single on-disk stand. Stands below this size limit will be automatically scheduled for merging into some larger on-disk stand.
In the embodiment of a stand shown in
System Parameters
As described above, parameters can be provided using parameter storage 1312 to control various aspects of system operation. Parameters that can be provided include rules for identifying tokens and subtrees, rules establishing minimum and/or maximum sizes for on-disk and in-memory stands, parameters for determining whether to merge on-disk stands, and so on.
In one embodiment, some or all of these parameters can be provided using a forest configuration file, which can be defined in accordance with a preestablished XML schema. For example, the forest configuration file can allow a user to designate one or more ‘subtree root’ element labels, with the effect that the data loader, when it encounters an element with a matching label, loads the portion of the document appearing at or below the matching element subdivision as a subtree. The configuration file might also allow for the definition of ‘subtree parent’ element names, with the effect that any elements which are found as immediate children of a subtree parent will be treated as the roots of contiguous subtrees.
More complex rules for identifying subtree root nodes may also be provided via parameter storage 1312, for example, conditional rules that identify subtree root nodes based on a sequence of element labels or tag names. Subtree identification rules need not be specific to tag names, but can specify breaks upon occurrence of other conditions, such as reaching a certain size of subtree or subtree content. Some decomposition rules might be parameterized where parameters are supplied by users and/or administrators (e.g., “break whenever a tag is encountered that matches a label the user specifies,” or more generally, when a user-specified regular expression or other condition occurs). In general, subtree decomposition rules are defined so as to optimize tradeoffs between storage space and processing time, but the particular set of optimum rules for a given implementation will generally depend on the structure, size, and content of the input document(s), as well as on parameters of the system on which the database is to be installed, such as memory limits, file-system configurations, and the like.
Element Queries
As described previously, element queries are used to determine the position of words, phrases, or elements relative to a particular element in a hierarchical (e.g., XML) document. For example, a typical element query is whether a given word is contained within (i.e., is a descendant of) a given element. Current solutions to processing element queries are inefficient, cannot be applied generically to all elements in a document, and fail to take into account the hierarchical structure of the elements. Embodiments of the present invention provide techniques for representing and querying positional information in hierarchical documents that overcome these problems.
At step 1602, a hierarchical document such as an XML document is received. As is well known in the art, an XML document comprises a plurality of words which define the content of the document, and a plurality of elements which define the structure of the document. At step 1604, at least one word in the plurality of words is associated with one or more word positions. In an exemplary embodiment, every word in the plurality of words is associated with a word position. In alternative embodiments, a subset of words is associated with a word position. A word position indicates the position of the word relative to other words in the document. For example, consider the following sample XML document (referred to herein as “sample document 1”):
Note that the positional subscripts above are included to illustrate the order of the words in the document; they are not a part of the XML document. The words in sample document 1 may be associated with word positions as follows:
brown: 3, 8
dog: 10
fox: 4
jumped: 5
over: 6
striped: 2, 9
the: 1, 7
In this embodiment, the word positions for each word correspond to the ascending, sequential order of the word in sample document 1. Thus, the word “the” is the first word in the document and is therefore associated with the word position “1.” Similarly, the word “fox” is the fourth word in the document is and therefore associated with the word position “4.” In alternative embodiments, other possible word positions that maintain the relative positions of the words may be used. Words that appear multiple times in the document may be associated with multiple word positions. Thus, the word “striped” is associated with the positions 2 and 9, indicating that the word appears at both the second and ninth word positions in the document.
In various embodiments, the word positions for a document may be stored in a data structure that is separate from the document. In these cases, the word positions may be associated with an identifier that identifies the document. This identifier may be, for example, a subtree identifier of a subtree contained within the document, or a document identifier. Alternatively, the word positions may be stored with the document. In further embodiments, the word positions may be indexed in a word position index to allow fast retrieval of a word based upon a word position, or vice versa. As will be described in greater detail below, such an index may be used to facilitate the processing of element queries.
At step 1606, at least one element in the plurality of elements is associated with one or more word position ranges. In an exemplary embodiment, every element in the plurality of elements is associated with a word position range. In alternative embodiments, a subset of elements is associated with a word position range. A word position range describes a range of zero or more word positions, and is used to identify the words that are contained within an element. Referring back to sample document 1, the word position ranges for elements “<b>” and “<i>” may be represented as:
element <b>: (3, 4), (7, 10)
element <i>: (9, 10)
As shown, each word position range is represented using a “starting” word position and an “ending” word position. For example, element “<b>” has a range (3, 4) with a starting word position 3 and an ending word position 4. The word positions that fall within the starting and ending positions of a range represent the words that are descendants of the corresponding element.
According to one embodiment, the word position ranges for element “<b>” above may be interpreted as:
Using the two types of positional information described above (word positions and word position ranges), element queries may be processed in an efficient manner. For example, by intersecting the word positions and word position ranges for sample document 1, we can determine that:
Like word positions, word position ranges may be indexed in a range index to allow fast retrieval of a range based upon an element, or vice versa. In various embodiments, the range index may be intersected with the word position index described earlier to quickly identify whether a given word is a descendant of a given element.
Word position ranges for a document may be stored in a data structure that is separate from the document. In this case, the word position ranges may be associated with an identifier that identifies the document. This identifier may be, for example, a subtree identifier of a subtree contained within the document, or a document identifier. In one embodiment, each word position and word position range may be associated with a separate identifier. In other embodiments, all of the positional information for a document may be associated with a single identifier.
In various embodiments, the word position ranges of a document may be augmented to support elements that have zero descendants (i.e., are empty). For example, consider the following XML document (identical to sample document 1 except for the addition of an empty “<br>” element):
In this case, the word position ranges would be augmented as follows:
element <b>: (3, 4), (7, 10)
element <br>: (9, 9)
element <i>: (9, 10)
Note that the representation of the word position range for element “<br>” is (9,9)—this denotes that element “<br>” is an empty element, as there are no positions which satisfy the constraint (9<=position<9).
In further embodiments, the word position ranges for a document may be augmented to support elements that contain nested elements. Specifically, word position range information may be modified to indicate what part of a range is subsumed by a descendant (i.e., nested) element. This representation allows us to determine, for example, whether a word or phrase is an indirect descendant (i.e., is contained within a nested element) of a particular element. For example, consider the following second sample XML document:
To identify whether an element contains another element, the beginning or end of a descendant element is marked within a word position range with an identifier, such as an asterisk. This produces the following representation:
element <b>: (3, 4), (7, 9*), (12*, 16)
element <i>: (9, 10*), (12*, 12)
element <u>: (10, 12)
In the above example, when an asterisk appears at the ending position of a word position range, the asterisk indicates that a descendant element begins at that position. When the asterisk appears at a starting position of a word position range, the asterisk indicates that a descendant element is closed at that position. This representation is sufficient to identify whether a word is a direct descendant of (i.e., contained directly under) an element, or an indirect descendant of (i.e., contained within a nested element of) the element. For example, the word position ranges for element “<b>” as shown above may be interpreted as follows:
In various embodiments, the above described representation for word position ranges may be used to indicate any level of nesting within an element, and may be used to indicate descendant elements that have the same element name as their parent elements. For example, consider the following third sample document and corresponding word position ranges:
element <b>: (3,4), (7,9*), (10, 12)(12*,16)
element <i>: (9,10*), (12*,12)
Note that element “<b>” is nested within itself. Based on the above, the word position ranges for element <b> may be interpreted as follows:
As another example, consider the following fourth sample document and corresponding word position ranges (hereinafter “sample document 4”):
element <b>: 3,4), (7,9*),(9,10*),(10,12),(12*,12),(12*,16)
In this example, the word position ranges for element “<b>” may be interpreted as follows:
At step 1608 of
element <b>: (3, 4), (7, 9*), (9, 10*), (10, 12), (12*, 12), (12*, 16)
The word position ranges above are represented using absolute values for the word positions. Using delta values, the word position ranges may be encoded as:
element <b>: (3, 1), (3, 2*), (0, 1*), (0, 2), (0*, 0), (0*, 4)
As shown, the starting and ending word positions for each word position range are encoded as the difference (i.e., delta) between the position and a previous position. Such an encoding reduces the absolute magnitude of the numbers that need to be stored, thereby reducing storage space requirements. Note that the absolute word positions may be recovered from the delta encoded positions by adding together all of the numbers in the range information up to the desired position.
In one set of embodiments, the delta encoding scheme for word position ranges may be modified to encode a stream of pure numbers without any non-numeric identifiers such as asterisks. This may be desirable because number streams are easily compressible using known compression techniques. According to one embodiment, each asterisk is changed to a zero value that precedes the starting or ending position the asterisk is associated to. Thus, the representation for certain word position ranges may be changed from a pair of numbers to a tuple of numbers. Consider the following delta-encoded word position ranges for element “<b>”:
element <b>: (3, 1), (3, 2*), (0, 1*), (0, 2), (0*, 0), (0*, 4)
By replacing each asterisk with a preceding zero, the word position ranges are modified to:
element <b>: (3, 1), (3, 0, 2), (0, 0, 1), (0, 2), (0, 0, 0), (0, 0, 4)
One problem with the above representation is that the delta-encoded starting and ending positions for a range may have a value of zero, making it difficult to differentiate position data from an asterisk. To avoid this, each starting and ending position can be incremented by 1 so that no position data item can be equal to 0. This allows the word position range data for an element to be encoded as a pure stream of numbers, without any notion of “parentheses.” For example, the stream encoding for element “<b>” is:
element <b>: 4, 2, 4, 0, 3, 1, 0, 2, 1, 3, 0, 1, 1, 0, 1, 5
Note that the original delta encoding can be recovered by decrementing each position datum by 1 prior to use, and by recognizing that any position datum preceded by a zero should be regarded as modified by an asterisk. This stream encoding lends itself to extremely efficient storage through well-understood techniques for delta compression.
It should be appreciated that the specific steps illustrated in
Using the above-described representations for word positions and word position ranges, element queries can be processed efficiently against any hierarchical document.
At step 1702, an element query is received. In various embodiments, the element query contains a word or phrase and an element. At steps 1704 and 1706, the word positions for the word or phrase and the word position ranges for the element are retrieved. According to one set of embodiments, the word positions for the word or phrase may be retrieved via a word position index. Similarly, the word position ranges for the element may be retrieved via a range index. In various embodiments, an efficient on-disk stream encoding for the word positions and word position ranges may be retrieved and converted into an array of 32-bit numbers in memory, where the high-bit of each number indicates whether or not an asterisk is present. The high-bit is masked out for numeric position comparison operations.
At step 1708, the word positions and word position ranges are processed to determine, for example, whether the word or phrase is a descendant of the element provided in the query. Other types of queries are also contemplated, such as queries that check for indirect descendant relationships, both direct and indirect descendant relationships, a direct descendant relationship at the exclusion of an indirect descendant relationship, and the like. In one set of embodiments, the processing comprises comparing the word position data to the word position range data. Since both sets of position data may be arranged in non-descending order, algorithms that perform non-linear comparisons (e.g. a binary search) may be used, in addition to other algorithms (linear merges, etc.). One of ordinary skill in the art would recognize many variations, modifications, and alternatives. Depending on the relative sizes and densities of the word position data and word position range data, different algorithms may be executed.
At step 1710, the result set of the query is return to the query initiator.
In an alternative embodiment, an element position may be associated with each element of a document, and a similar approach as described herein may be used as a general solution to determining what elements are contained within other elements.
It should be appreciated that the specific steps illustrated in
This detailed description illustrates some embodiments of the present invention and variations thereof, but should not be taken as a limitation on the scope of the invention. In this description, structured documents are described, along with their processing, storage and use, with XML being the primary example. However, it should be understood that the invention might find applicability in systems other than XML systems, whether they are later-developed evolutions of XML or entirely different approaches to structuring data. It should also be understood that “XML” is not limited to the current version or versions of XML. An XML file (or XML document) as used herein can be serialized XML or more generally an “infoset.” Generally, XML files are text, but they might be in a highly compressed binary form.
The specification and drawings are, accordingly, to be regarded in an illustrative rather than a restrictive sense. Many variations of the invention will become apparent to those skilled in the art upon review of the disclosure. The scope of the invention should, therefore, be determined not with reference to the above description, but instead should be determined with reference to the pending claims along with their full scope or equivalents.
This application claims the benefit of U.S. Provisional Application No. 60/811,626, filed Jun. 5, 2006 by Lindblad et al. and entitled “ELEMENT QUERY METHOD AND SYSTEM,” the disclosure of which is incorporated herein by reference for all purposes. The present disclosure is related to the following commonly assigned, co-pending U.S. patent applications: Ser. No. 10/462,100 (Attorney Docket No. 021512-00011US), entitled “SUBTREE-STRUCTURED XML DATABASE” (hereinafter “Lindblad I-A”); Ser. No. 10/462,019 (Attorney Docket No. 021512-000210US), entitled “PARENT-CHILD QUERY INDEXING FOR XML DATABASES” (hereinafter “Lindblad III-A”); Ser. No. 10/462,023 (Attorney Docket No. 021512-000310US), entitled “XML DB TRANSACTIONAL UPDATE SYSTEM” (hereinafter “Lindblad III-A”); and Ser. No. 10/461,935 (Attorney Docket No. 021512 000410US), entitled “XML DATABASE MIXED STRUCTURAL-TEXTUAL CLASSIFICATION SYSTEM” (hereinafter “Lindblad IV-A”). The respective disclosures of these applications are incorporated herein by reference for all purposes.
Number | Date | Country | |
---|---|---|---|
60811626 | Jun 2006 | US |