Certain database server programs (“database servers”) provide functionality for registering a database query for a change notification (also referred to herein as a “query notification”). A change notification is an asynchronous notification that is provided by the database server when the data underlying a registered database query changes.
Through the use of change notifications and a database query result cache for storing previous database queries, unnecessary database queries can be avoided for data that does not change or that only changes infrequently. Certain types of complex database queries, however, are ineligible for change notifications. As a consequence, query results from this type of database query, which is referred to herein as a “complex database query”, cannot typically be cached. This can affect the performance of certain types of application programs that utilize complex queries.
It is with respect to these and other considerations that the disclosure presented herein has been made.
Concepts and technologies are described herein for notification-based cache invalidation for complex database queries. According to embodiments presented herein, change notifications can be provided for complex database queries that are otherwise ineligible for a change notification provided by a database server. Through the use of such a mechanism, it can be determined whether the data underlying a complex database query has changed without polling a database server to determine if the data has changed.
According to one embodiment presented herein, a database query result cache is provided for caching database query results. The database query result cache includes entries storing query results that can be indexed based upon the corresponding query. When a database query is to be performed, a search is made of the database query result cache to determine whether it includes an entry corresponding to the database query. If so, the database query results stored in the database query result cache are returned. In this way, it is not necessary to perform database queries for those database queries that have been previously cached.
Change notifications provided by a database server may be utilized to invalidate entries in the database query result cache. For instance, if a database query is eligible for a change notification, a request may be made to the database server to register the database query for a change notification. If the set of data returned by the database query changes, the database server will provide a change notification. In response to receiving the change notification, the entry in the database query result cache for the corresponding database query is invalidated. For instance, in one embodiment, the entry in the database query result cache for the corresponding database query is deleted.
A mechanism is also provided herein for invalidating database query result cache entries for database queries that are ineligible for a change notification from the database server. This type of database query is referred to herein as a “complex database query.” In order to invalidate a database query result cache entry corresponding to a complex database query, a secondary database query is registered for a change notification with the database server. In one implementation, the secondary database query is a database query that is eligible for a change notification from the database server and that is configured to return a superset of the data returned by the corresponding complex database query.
If a change notification is received from the database server for a secondary database query, the entry in the database query result cache corresponding to the complex database query is invalidated. In this way, an entry in a database query result cache corresponding to a complex database query can be invalidated even though the complex database query is ineligible for a change notification from the database server.
It should be appreciated that the above-described subject matter may also be implemented as a computer-controlled apparatus, a computer process, a computing system, as an article of manufacture such as a computer readable storage medium, or in another manner. These and various other features will be apparent from a reading of the following Detailed Description and a review of the associated drawings.
This Summary is provided to introduce a selection of concepts in a simplified form that are further described below in the Detailed Description. This Summary is not intended to identify key features or essential features of the claimed subject matter, nor is it intended that this Summary be used to limit the scope of the claimed subject matter. Furthermore, the claimed subject matter is not limited to implementations that solve any or all disadvantages noted in any part of this disclosure.
The following detailed description is directed to technologies for notification-based cache invalidation for complex database queries. While the subject matter described herein is presented in the general context of program modules that execute in conjunction with the execution of an operating system and application programs on a computer system, those skilled in the art will recognize that other implementations may be performed in combination with other types of program modules. Generally, program modules include routines, programs, components, data structures, and other types of structures that perform particular tasks or implement particular abstract data types. Moreover, those skilled in the art will appreciate that the subject matter described herein may be practiced with other computer system configurations, including hand-held devices, multiprocessor systems, microprocessor-based or programmable consumer electronics, minicomputers, mainframe computers, and the like.
In the following detailed description, references are made to the accompanying drawings that form a part hereof, and which are shown by way of illustration specific embodiments or examples. Referring now to the drawings, in which like numerals represent like elements throughout the several figures, concepts and technologies for notification-based cache invalidation for complex database queries will be described.
Turning now to
In one embodiment presented herein, the database server 104 comprises a structured query language (“SQL”) database server that is configured to receive a database query 106 formatted using SQL. It should be appreciated, however, that the embodiments presented herein may be utilized with any type of database server 104 configured for processing database queries structured utilizing other types of database query languages. It should also be appreciated that the application 102 may generate the database query 106 in one embodiment. In other embodiments, the application 102 receives a database query 106 from another software component executing within the application 102 or external to the application 102, and passes the database query 106 to the database server 104 for processing.
According to implementations, the application 102 is configured to maintain a database query result cache 112. As shown in
The routine 200 begins at operation 202, where the application 102 receives or generates a database query 106. As discussed above, the application 102 may generate the database query 106 or may receive the database query 106 from another software component. In response to receiving or generating the database query 106, the routine 200 proceeds to operation 204, where the application 102 determines whether the query result cache 112 contains an entry 114 for the database query 106. If an entry 114 in the query result cache 112 corresponding to the database query 106 is found, the routine 200 proceeds from operation 204 to operation 206. At operation 206, the application 102 utilizes the database query result 108 from the query result cache 112 rather than submitting the database query 106 to the database server 104. From operation 206, the routine 200 proceeds to operation 216, where it ends.
If, at operation 204, the application 102 determines that the query result cache 112 does not contain an entry 114 for the database query 106, the routine 200 proceeds from operation 204 to operation 208. At operation 208, the application 102 submits the database query 106 to the database server 104 for processing. In response thereto, the database server 104 executes the database query 106 against the database 110 and returns the database query result 108 to the application 102. The application 102 receives the database query result 108 from the database server 104 at operation 210.
In response to receiving the database query result 108, the application 102 creates an entry 114 in the query result cache 112 for the database query 106 and stores the database query result 108 in the created entry 114. The routine 200 then proceeds to operation 214, where the database query result 108 received from the database server 104 is utilized by the application 102 in the desired manner. From operation 214, the routine 200 proceeds to operation 216, where it ends.
Referring now to
In order to utilize the change notifications provided by the database server 104, the application 102 submits a database query to the database server 104. The application 102 also submits a notification request 302 with the database server 104. The notification request 302 is a request on behalf of the application 102 for a change notification 304 from the database server 104 in the event that the data underlying the database 106 changes.
In response to receiving the database query 106, the database server 104 executes the database query 106 against the database 110 and returns the database query result 108 to the application 102. As discussed above, an entry may be created in the query result cache 112 that includes the database query result 108. Subsequently, the database server 104 may detect a change to the data underlying the database query 106. In response thereto, the database server 104 is configured to provide a change notification 304 to the application 102. The change notification 304 may be provided asynchronously.
In response to receiving the change notification 304, the application 102 is configured to invalidate the entry in the query result cache 112 corresponding to the database query 106 for which change notification was requested. As discussed above, an entry in the query result cache 112 can be invalidated by deleting the entry from the query result cache 112.
In response to the submission of the database query 106 to the database server 104, the application 102 receives the database query result 108. As discussed above, an entry may be created in the database query result cache 112 for the database query 106 and the database query result 108. Subsequent requests to perform the database query 106 may be satisfied from the database query result cache 112 until the entry corresponding to the database query 106 has been invalidated. From operation 406, the routine 400 proceeds to operation 408, where it ends.
As discussed briefly above, certain types of database queries are ineligible for change notifications provided by the database server 104. For instance, database queries that include aggregates, multiple queries, that include unions, or that write back to the database 110 may be ineligible for a change notification. In order to address this difficulty, embodiments presented herein provide a mechanism by which change notifications can be provided for database queries that are ineligible for change notifications provided by the database server 104. Through the use of this mechanism, the application 102 can determine whether the data underlying a database query that is ineligible for a change notification has changed without polling the database server 104 to determine if the data has changed. The results of this determination can then be utilized to invalidate entries in the query result cache 112.
The system 500 illustrated in
In order to determine whether the data underlying the complex database query 106A has changed and therefore that the entry in the query result cache 112 is no longer valid, the application 102 submits a secondary query 106B to the database server 104 along with a change notification 302 for the secondary query 106B. In this way, the database server 104 is configured to provide a notification 304 to the application 102 in the event that the data underlying the secondary query 106B changes.
According to one implementation, the secondary query 106B is configured to return a superset of the set of data returned by the complex database query 106A. In one particular implementation, the secondary query 106B is configured to return a minimal superset of the set of data returned by the complex database query 106A. Additionally, the secondary query 106B is configured in a manner that permits it to remain eligible for a change notification 304 from the database server 104.
In response to processing the secondary query 106B, the database server 104 executes the secondary query 106B against the database 110 and returns the database query results 108B to the application 102. In response to receiving the database query result 108B, the application 102 creates an entry in the query result cache 112. Subsequently, if the database server 104 determines that the data underlying the secondary query 106B has changed, the database server 104 will issue the change notification 304 to the application 102.
In response to receiving the change notification 304, the application 102 invalidates the entry in the query result cache 112 for the complex database query 106A. In this manner, the change notification 304 for the secondary query 106B is utilized to invalidate an entry in the query result cache 112 for the complex database query 106A. Additional details regarding this process are described below with reference to
From operation 604, the routine 600 proceeds to operation 606 where the application 102 submits the secondary query 106B to the database server 104. As discussed above, the secondary query 106B is configured to return a superset of the set of data returned by the complex database query 106A. Additionally, the application 102 submits a notification request 302 for the secondary query 106B to the database server 104 at operation 608. In response to the submission of the secondary query 106B, the application 102 receives the database query result 108B from the database server 104 at operation 610. The database query result 108B for the secondary query 106B are not utilized. The routine 600 then proceeds to operation 612, where it ends.
If the received or generated query is not a complex query, the routine 700 proceeds from operation 704 to operation 706. At operation 706, the database query is registered for a change notification in the manner discussed above with reference to
If, at operation 704, the application 102 determines that the received or generated database query is a complex database query, the routine 700 proceeds from operation 704 to operation 708. At operation 708, the application 102 registers the database query for a change notification in the manner described above with reference to
If, at operation 754, the application 102 determines that the received change notification 304 corresponds to a secondary query 106B, the routine 750 proceeds to operation 758. At operation 758, the application 102 invalidates the entry in the query result cache 112 corresponding to the complex database query 106A associated with the secondary query 106B. From operation 758, the routine 750 proceeds to operation 760, where it ends.
It should be appreciated that, according to one implementation, the notification mechanism described herein may be utilized to control the caching of output by a World Wide Web (“Web”) server application program. According to this implementation, a change notification 304 for a secondary query 106B may be utilized by the application 102 to instruct a Web server application program not to regenerate output until such time as the entry in the query result cache 112 corresponding to the secondary query 106B has been invalidated. In this way, the Web server can be instructed not to reprocess an output Web page until the database data underlying the Web page has been modified. In this manner, the Web server will cache its generated output until the underlying data stored in the database 110 changes.
The computer architecture shown in
The mass storage device 810 is connected to the CPU 802 through a mass storage controller (not shown) connected to the bus 804. The mass storage device 810 and its associated computer readable storage media provide non-volatile storage for the computer 800. Although the description of computer readable storage media contained herein refers to a mass storage device, such as a hard disk or CD-ROM drive, it should be appreciated by those skilled in the art that computer storage media can be any available computer storage media that can be accessed by the computer 800.
By way of example, and not limitation, computer readable storage media may include volatile and non-volatile, removable and non-removable media implemented in any method or technology for storage of information such as computer readable and executable instructions, data structures, program modules or other data. For example, computer storage media includes, but is not limited to, RAM, ROM, EPROM, EEPROM, flash memory or other solid state memory technology, CD-ROM, digital versatile disks (“DVD”), HD-DVD, BLU-RAY, or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other medium which can be used to store the desired information and which can be accessed by the computer 800.
According to various embodiments, the computer 800 may operate in a networked environment using logical connections to remote computers through a network such as the network 820. The computer 800 may connect to the network 820 through a network interface unit 806 connected to the bus 804. It should be appreciated that the network interface unit 806 may also be utilized to connect to other types of networks and remote computer systems. The computer 800 may also include an input/output controller 812 for receiving and processing input from a number of other devices, including a keyboard, mouse, or electronic stylus (not shown in
As mentioned briefly above, a number of program modules and data files may be stored in the mass storage device 810 and RAM 814 of the computer 800, including an operating system 818 suitable for controlling the operation of a networked desktop, laptop, or server computer. The mass storage device 810 and RAM 814 may also store one or more program modules. In particular, the mass storage device 810 and the RAM 814 may store the application 102 and the database server 104, each of which was described in detail above with respect to
It should be appreciated that the software components described herein may, when loaded into the CPU 802 and executed, transform the CPU 802 and the overall computer 800 from a general-purpose computing system into a special-purpose computing system customized to facilitate the functionality presented herein. The CPU 802 may be constructed from any number of transistors or other discrete circuit elements, which may individually or collectively assume any number of states. More specifically, the CPU 802 may operate as a finite-state machine in response to executable instructions contained within the software modules disclosed herein. These computer-executable instructions may transform the CPU 802 by specifying how the CPU 802 transitions between states, thereby transforming the transistors or other discrete hardware elements constituting the CPU 802.
Encoding the software modules and data presented herein might also transform the physical structure of the computer storage media presented herein. The specific transformation of physical structure may depend on various factors, in different implementations of this description. Examples of such factors may include, but are not limited to: the technology used to implement the computer storage media, whether the computer storage media is characterized as primary or secondary storage, and the like. For example, if the computer storage media is implemented as semiconductor-based memory, the software disclosed herein may be encoded on the computer readable storage media by transforming the physical state of the semiconductor memory. For example, the software may transform the state of transistors, capacitors, or other discrete circuit elements constituting the semiconductor memory. The software may also transform the physical state of such components in order to store data thereupon.
As another example, the computer storage media disclosed herein may be implemented using magnetic or optical technology. In such implementations, the software presented herein may transform the physical state of magnetic or optical media, when the software is encoded therein. These transformations may include altering the magnetic characteristics of particular locations within given magnetic media. These transformations may also include altering the physical features or characteristics of particular locations within given optical media, to change the optical characteristics of those locations. Other transformations of physical media are possible without departing from the scope and spirit of the present description, with the foregoing examples provided only to facilitate this discussion.
In light of the above, it should be appreciated that many types of physical transformations take place in the computer 800 in order to store and execute the software components presented herein. It also should be appreciated that the computer 800 may comprise other types of computing devices, including hand-held computers, embedded computer systems, personal digital assistants, and other types of computing devices known to those skilled in the art. It is also contemplated that the computer 800 may not include all of the components shown in
Based on the foregoing, it should be appreciated that technologies for notification-based cache invalidation for complex database queries have been disclosed herein. Although the subject matter presented herein has been described in language specific to computer structural features, methodological and transformative acts, specific computing machinery, and computer storage media, it is to be understood that the invention defined in the appended claims is not necessarily limited to the specific features, acts, or media described herein. Rather, the specific features, acts and mediums are disclosed as example forms of implementing the claims.
The subject matter described above is provided by way of illustration only and should not be construed as limiting. Various modifications and changes may be made to the subject matter described herein without following the example embodiments and applications illustrated and described, and without departing from the true spirit and scope of the present invention, which is set forth in the following claims.