Request processing method and request processing system
By creating a global temporary table in the database and rewriting the query request, the problem of the inability to share temporary tables in PostgreSQL and MySQL databases is solved. This enables the sharing of global temporary tables and centralized maintenance of DDL statements, improving the efficiency and consistency of database processing.
Patent Information
- Application Number
- CN202411361053.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-27
- Publication Date
- 2024-11-01
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In PostgreSQL and MySQL databases, temporary tables cannot be shared between sessions or transactions, causing DDL statements to be scattered throughout the business, making centralized maintenance difficult and resulting in problems with logical concurrency and logical inconsistency.
A global temporary table is created in the database, and the kernel processor receives and parses the query request to determine whether it contains the global temporary table. If it does, it is rewritten as the target query request and the target query transaction is executed, thus realizing the sharing of the global temporary table within the database and the centralized maintenance of DDL statements.
It enables the sharing of global temporary tables within the database, resolving the issues of logical concurrency and inconsistency caused by scattered DDL statements, and improving maintenance efficiency and consistency.
Smart Images

Figure CN118885487A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a request processing method and a request processing system. Background Art
[0002] In the batch processing business of the database, a lot of complex processing logic is usually run. These processing logics cannot be completed by a SQL (Structured Query Language) statement, or need to be shared among multiple steps of the whole process, so they are usually processed by middleware.
[0003] In Oracle database, global temporary tables are often used in middleware scenarios. Global temporary tables have the characteristics of table structure and physical properties shared between sessions or transactions. In PostgreSQL and MySQL databases, although the use of temporary tables is supported, it is private between each session or transaction, independent within the database, and cannot be shared. Using temporary tables as middleware in PostgreSQL or MySQL databases requires developers to write different data definition language (DDL) statements according to different businesses. Since these DDL statements are scattered throughout the business, it is not easy to maintain them centrally. Therefore, a method is continued to solve the technical problems that the above-mentioned temporary tables cannot be shared within the database and the DDL statements are difficult to maintain centrally. Summary of the invention
[0004] In view of this, an embodiment of this specification provides a request processing method. One or more embodiments of this specification also relate to a request processing device, a computing device, a computer-readable storage medium and a computer program product to solve the technical defects existing in the prior art.
[0005] According to a first aspect of an embodiment of this specification, a request processing method is provided, which is applied to a core processor, including: In response to a global temporary table creation request submitted to a database, create a global temporary table of the database; receiving an initial query request of a data operation type submitted to the database, and determining at least one query target table corresponding to the initial query request; In a case where the at least one query target table includes the global temporary table, rewriting the initial query request into a target query request based on the global temporary table; A target query transaction corresponding to the target query request is executed on the database.
[0006] According to a second aspect of an embodiment of this specification, there is provided a request processing system, including a client and a core processor; The client is configured to send a global temporary table creation request for a database to the kernel processor; The kernel processor is configured to create a global temporary table of the database in response to the global temporary table creation request; The client is further configured to send an initial query request for a data operation type submitted to the database to the core processor; The core processor is further configured to receive the initial query request and determine at least one query target table corresponding to the initial query request; when the at least one query target table includes the global temporary table, rewrite the initial query request into a target query request based on the global temporary table; and execute a target query transaction corresponding to the target query request on the database.
[0007] According to a third aspect of an embodiment of this specification, a request processing device is provided, which is applied to a core processor, including: A creation module, configured to create a global temporary table of the database in response to a global temporary table creation request submitted to the database; a determination module, configured to receive an initial query request of a data operation type submitted to the database, and determine at least one query target table corresponding to the initial query request; A rewriting module, configured to rewrite the initial query request into a target query request based on the global temporary table when the at least one query target table includes the global temporary table; The execution module is configured to execute the target query transaction corresponding to the target query request on the database.
[0008] According to a fourth aspect of an embodiment of this specification, a computing device is provided, including: Memory and processor; The memory is used to store computer programs or instructions, and the processor is used to execute the computer programs or instructions. When the computer programs or instructions are executed by the processor, the steps of the above-mentioned request processing method are implemented.
[0009] According to a fifth aspect of the embodiments of this specification, a computer-readable storage medium is provided, which stores a computer program or instructions, and when the computer program or instructions are executed by a processor, the steps of the above-mentioned request processing method are implemented.
[0010] According to a sixth aspect of the embodiments of this specification, a computer program product is provided, including a computer program or instructions, which implement the steps of the above-mentioned request processing method when executed by a processor.
[0011] An embodiment of the present specification realizes that a global temporary table is created in a database, so that the initial query request submitted for creating the global temporary table can use the created global temporary table as middleware for request processing. In this process, temporary table sharing within the database can be realized based on the global temporary table, and due to the characteristics of the global temporary table itself, the definition of the global temporary table created at this time is visible to the current session of the target query transaction and any other session, thereby realizing centralized maintenance of DDL statements. The initial query request is rewritten based on the global temporary table, and a target query request is generated. The corresponding target query transaction is executed based on the rewritten target query request, which can solve the problems of logical concurrency and logical inconsistency caused by DDL statements scattered everywhere. BRIEF DESCRIPTION OF THE DRAWINGS
[0012] Figure 1 is a schematic diagram of a request processing method provided by an embodiment of this specification; Figure 2 is a flowchart of a request processing method provided by an embodiment of this specification; Figure 3 is a processing flow chart of a request processing method provided by an embodiment of this specification; Figure 4 It is a schematic diagram of a processing flow chart of a request processing system provided by an embodiment of this specification; Figure 5 is a schematic diagram of the structure of a request processing device provided by an embodiment of this specification; Figure 6 It is a structural block diagram of a computing device provided by an embodiment of this specification. DETAILED DESCRIPTION
[0013] Many specific details are described in the following description to facilitate a full understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar generalizations without violating the connotation of this specification, so this specification is not limited to the specific implementation disclosed below.
[0014] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.
[0015] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of this specification, this information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0016] In addition, it should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in one or more embodiments of this specification are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0017] First, the terms involved in one or more embodiments of this specification are explained.
[0018] sql: Structured Query Language, structured query language.
[0019] Data Query Language (DQL): Mainly used to retrieve data.
[0020] Data Manipulation Language (DML): used to add, delete or modify data.
[0021] Data Definition Language (DDL): used to create, modify or delete database objects such as tables, indexes, etc.
[0022] Global Temporary Table: Global Temporary Table (gtt) is a special type of table that behaves between permanent tables and session-level temporary tables. The life cycle of a global temporary table is associated with a session or a transaction, rather than being visible only in one client session like a normal temporary table.
[0023] In Oracle database, global temporary tables are often used in middleware scenarios. Global temporary tables have the characteristics of table structure and physical properties shared between sessions or transactions. In PostgreSQL and MySQL databases, although temporary tables are supported, they are private between each session or transaction, independent within the database, and cannot be shared. Using temporary tables as middleware in PostgreSQL or MySQL databases requires developers to write different data definition language (DDL) statements according to different businesses. Since these DDL statements are scattered throughout the business, it is not easy to centrally maintain them.
[0024] In this specification, a request processing method and a request processing system are provided. This specification also relates to a request processing apparatus, a computing device, a computer-readable storage medium and a computer program product, which are described in detail one by one in the following embodiments.
[0025] See also Figure 1 , Figure 1 FIG. 1 is a schematic diagram of a request processing method provided according to an embodiment of the present specification. Figure 1 As shown in the figure, in the batch processing business of the database, a large amount of complex processing logic is often required. Before executing any session or transaction, a global temporary table can be created in the database and used as an intermediate table. The kernel processor can receive a global temporary table creation request submitted by the client, and create a global temporary table in the database according to the global temporary table creation request. After the global temporary table is successfully created, the global temporary table can be used as an intermediate table for request processing.
[0026] After receiving the initial query request submitted by the client to the database, if the kernel processor determines that the initial query request is specifically a DML statement, the kernel processor parses the initial query request to determine at least one query target table corresponding to the initial query request. After determining at least one query target table corresponding to the initial query request, the kernel processor traverses each query target table to determine whether each query target table contains a global temporary table. If each query target table contains a global temporary table, the initial query request can be rewritten based on the global temporary table to generate a target query request, and in the subsequent process, the target query transaction corresponding to the target query request is executed on the database until the target query transaction is submitted. If each query target table does not contain a global temporary table, it means that the execution process corresponding to the ordinary temporary table can be executed on the initial query request, and the initial query request does not need to be rewritten according to the global temporary table. At this time, the target query transaction corresponding to the initial query request can be executed on the database until the target query transaction is submitted. Further, if it is determined that the initial query request is specifically a DDL statement, it means that the execution process corresponding to the ordinary temporary table can be executed on the initial query request, and the initial query request does not need to be rewritten according to the global temporary table. Specifically, the target query transaction corresponding to the initial query request is executed on the database until the target query transaction is submitted.
[0027] In actual applications, the database may specifically be a database that supports a partitioning mechanism, such as a postgresql database and a mysql database. The specific form of the database may be determined according to actual application conditions, and this specification does not limit this.
[0028] The request processing method provided in this specification can be specifically applied to a kernel processor, and a global temporary table of a database is created by creating a request for a global temporary table submitted to a database, and the created global temporary table is used as an intermediate table of multiple sessions or transactions in the subsequent process. According to the specific request type of the initial query request, it is determined whether the multiple query target tables corresponding to the initial query request contain a global temporary table. If so, the initial query request is rewritten based on the global temporary table to generate a target query request, and the target query transaction corresponding to the target query request is executed on the database to realize the temporary table structure sharing and physical attribute sharing of data query in the database, as well as the centralized maintenance of DDL statements.
[0029] See also Figure 2 , Figure 2 A flowchart of a request processing method provided according to an embodiment of this specification is shown, which specifically includes the following steps: Step 202: In response to a global temporary table creation request submitted to a database, a global temporary table of the database is created.
[0030] Specifically, the database may be a database that supports a partitioning mechanism, such as a postgresql database, a mysql database, etc. A global temporary table creation request refers to a request submitted by a client to create a global temporary table in a database. For example, a global temporary table creation request may be "create global temporary table gtt...", through which a statement is used to declare the creation of a global temporary table.
[0031] Based on this, the request processing method provided in this specification can be applied to the kernel processor. Before creating a global temporary table of a database that supports a partitioning mechanism, the developer can submit a global temporary table creation request for the database to the kernel processor through the client to declare that the global temporary table of the database needs to be created. After receiving the global temporary table creation request, the kernel processor can respond to the global temporary table creation request and create a global temporary table in the database.
[0032] In practical applications, taking the postgresql database as an example, in one or more embodiments of this specification, the definition of the parent table of the inheritance table in the postgresql database, including fields, primary keys, indexes, comments, unique constraints, etc., is specifically used as the definition of the global temporary table, and a global temporary table of the postgresql database is created based on this.
[0033] Furthermore, since the numerous processing requests received by the kernel processor include various processing requests with various functions and corresponding statements, the kernel processor needs to parse the global temporary table after receiving the global temporary table creation request. Therefore, in response to the global temporary table creation request submitted to the database, the global temporary table of the database is created, which is specifically implemented as follows: The global temporary table creation request is parsed to obtain a global keyword in the global temporary table creation request; and a global temporary table of the database is created according to the global keyword.
[0034] Specifically, since the requests for data processing in the database are different, which are specifically reflected in different statement contents, the global temporary table of the database can be created by parsing the global temporary table creation request and further analyzing the statement contents of the global temporary table creation request. The global keyword refers to the keyword used to create the global temporary table contained in the global temporary table creation request, for example, the global keyword can be "global temporary".
[0035] Based on this, after receiving the global temporary table creation request submitted to the database, the kernel processor parses the global temporary table creation request and obtains the global keyword in the global temporary table creation request, so as to determine that a global temporary table needs to be created, and then creates the global temporary table of the database based on the global keyword.
[0036] For example, the request to create a global temporary table is "create global temporary table gtt ...". After parsing the request, we can find that the global keyword in the request is "global temporary", which means that we need to create a global temporary table for the database and create it. To facilitate the use of global temporary tables by various sessions or transactions, we can mark the global temporary table to indicate that it is a global temporary table. Specifically, the type of the global temporary table (gtt) can be marked as "g". At this time, the definition of the gtt global temporary table is visible to subsequent transactions of this session and any other sessions.
[0037] In summary, by parsing the global temporary table creation request, the global keyword contained in the global temporary table creation request is obtained, and the global temporary table of the database is created according to the global keyword.
[0038] Step 204: Receive an initial query request of a data operation type submitted to the database, and determine at least one query target table corresponding to the initial query request.
[0039] Specifically, after the global temporary table of the database is created in response to the global temporary table creation request, an initial query request submitted to the database can be received, and the type of the initial query request is a data operation type (dml). The data operation type refers to the request type of the initial query request; the initial query request of the data operation type can be used to operate on the data in the database, including adding, deleting and modifying data. The query target table refers to the table that needs to be operated by the initial query request.
[0040] Based on this, after the global temporary table of the database is created, the processing request for the database can be processed based on the global temporary table. When receiving the initial query request submitted to the database, if the request type of the initial query request is a data operation type, the initial query request is parsed to determine multiple query target tables corresponding to the initial query request.
[0041] In actual applications, the SQL compiler will perform syntax analysis on the SQL statement to obtain the query target table that the SQL statement needs to operate on.
[0042] Step 206: When the at least one query target table includes the global temporary table, rewrite the initial query request into a target query request based on the global temporary table.
[0043] Specifically, after determining at least one query target table corresponding to the initial query request, multiple query target tables corresponding to the initial query request can be traversed to determine whether the query target table corresponding to the initial query request contains the created global temporary table. If the global temporary table is contained, it means that the initial query request needs to use the created global temporary table as an intermediate table, and then the initial query request is rewritten based on the global temporary table to generate a target query request. The target query request refers to the query request after the initial query request is rewritten based on the global temporary table.
[0044] Based on this, after determining at least one query target table corresponding to the initial query request, each query target table can be traversed to determine whether each query target table contains the created global temporary table. In the process of traversing the query target table, it can be determined whether the determined query target table is a global temporary table by determining whether each query target table has a global temporary table mark. In the case of determining that each query target table contains a global temporary table, the initial query request is rewritten into a target query request based on the global temporary table.
[0045] In actual applications, after obtaining the query target table that the SQL statement needs to operate, multiple query target tables of the SQL statement are traversed, and by judging whether each query target table has the "g" mark (ie, relkind="g"), it is determined whether the query target table is a global temporary table, thereby determining whether the query target table of the SQL statement contains the created global temporary table. If it does, the initial query request is rewritten based on the global temporary table, and the target query request is obtained.
[0046] Furthermore, since each query target table corresponding to the initial query request includes a global temporary table, that is, the global temporary table is referenced in the initial query request, in order to ensure the data privatization of the target query transaction corresponding to the initial query request, a privatized temporary table can be created for the target query transaction based on the global temporary table, and the initial query request can be rewritten into a target query request based on the privatized temporary table. Therefore, the initial query request is rewritten into a target query request based on the global temporary table, and the specific implementation is as follows: Determine a target replacement temporary table corresponding to the global temporary table in the target query transaction; and rewrite the initial query request into a target query request according to the global temporary table and the target replacement temporary table.
[0047] Specifically, the target query transaction refers to the query transaction corresponding to the initial query request. The target replacement temporary table refers to the temporary table used to rewrite the initial query request into the target query request. The target replacement temporary table is created based on the global temporary table. The table structure and physical properties of the target replacement temporary table are the same as those of the global temporary table. The target replacement temporary table is specifically a common temporary table.
[0048] Based on this, after determining that the multiple query target tables corresponding to the initial query request include the global temporary table, the initial query request needs to be rewritten into a target query request based on the global temporary table. Since the target replacement temporary table is the basis for rewriting the initial query request into the target query request, before rewriting the initial query request, it is necessary to determine the target replacement temporary table corresponding to the global temporary table in the target query transaction, and then rewrite the initial query request into the target query request based on the global temporary table and the target replacement temporary table.
[0049] Furthermore, in order to ensure the data privatization of the target query transaction, when the query request in the target query transaction accesses the global temporary table for the first time, a corresponding target replacement temporary table can be created for it, and the initial query request can be rewritten based on the global temporary table and the target replacement temporary table. Therefore, the target replacement temporary table corresponding to the global temporary table in the target query transaction is determined, and the specific implementation is as follows: Obtain a local relational table of the target query transaction, and search the local relational table for a cache entry corresponding to the global temporary table; when a cache entry corresponding to the global temporary table is found, determine a target replacement temporary table corresponding to the global temporary table according to a global table identifier of the global temporary table; when a cache entry corresponding to the global temporary table is not found, create a target replacement temporary table corresponding to the global temporary table for the target query transaction based on the table structure of the global temporary table.
[0050] Specifically, the local relational table is used to cache cache entries accessed by the target query transaction to the global temporary table. The global table identifier refers to the identifier of the global temporary table.
[0051] Based on this, by judging whether the initial query request is the first access to the global temporary table, it is determined whether the kernel processor has created a target replacement temporary table for the target query transaction. The local relationship table of the target query transaction is obtained, and the cache entry corresponding to the global temporary table is searched in the local relationship table. If the cache entry corresponding to the global temporary table can be found in the local relationship table, it means that the initial query request is not the first query request to access the global temporary table in the target query transaction, and the kernel processor has created a corresponding target replacement temporary table for the target query transaction. In the request processing method provided in this specification, the target replacement temporary table is created and obtained through the table structure and global table identifier of the global temporary table. Specifically, the definition statement of the global temporary table will be copied, but the physical properties of the global temporary table, such as the table space, fill factor, etc., will not be copied. At this time, the replacement table identifier of the target replacement temporary table can be determined according to the global table identifier of the global temporary table, and then the target replacement temporary table corresponding to the global temporary table can be determined based on the replacement table identifier. In actual applications, the global table identifier of the global temporary table is similar to but not identical to the replacement table identifier of the target replacement temporary table. For example, if the global table identifier of the global temporary table is gtt_my_table, then the replacement table identifier of the target replacement temporary table is gtt_my_table_pid. If the cache entry corresponding to the global temporary table is not found in the local relationship table, it means that the initial query request is the first query request to access the global temporary table in the target query transaction. At this time, the kernel processor has not yet created a target replacement temporary table corresponding to the global temporary table for the target query transaction. Based on this, based on the table structure of the global temporary table, a target replacement temporary table corresponding to the global temporary table can be created for the target query transaction by copying the implementation method of the global temporary table.
[0052] As described above, rewriting the initial query request into the target query request through the target replacement temporary table is to realize the data privatization of the target query transaction. Therefore, the replacement table type of the target replacement temporary table cannot be a global temporary table.
[0053] Furthermore, since the replacement table type of the target replacement temporary table cannot be a global temporary table, after determining the target replacement temporary table corresponding to the global temporary table, the replacement table type of the target replacement temporary table needs to be set, which is specifically implemented as follows: The replacement table type of the target replacement temporary table is set to a common temporary table.
[0054] Specifically, the replacement table type is the table type of the target replacement temporary table.
[0055] Based on this, after determining the target replacement temporary table corresponding to the global temporary table, the replacement table type of the target replacement temporary table can be set to a common temporary table, so that the target replacement temporary table is private to the target query transaction and is not shared within the database.
[0056] For example, determine the target replacement temporary table gtt_my_table_pid corresponding to the global temporary table gtt_my_table in query transaction 1, set the replacement table type of the target replacement temporary table gtt_my_table_pid to a common temporary table, and specifically mark the replacement table type as "t", that is, relkind="t".
[0057] In summary, by searching the cache entry corresponding to the global temporary table in the local relational table, it is determined whether the initial query request is the first query request to access the global temporary table in the target query transaction. If so, a corresponding target replacement temporary table is created for the target query transaction based on the global temporary table. If not, the target replacement temporary table corresponding to the target query transaction can be determined based on the global table identifier of the global temporary table.
[0058] Further, in order to improve the accuracy of rewriting the initial query request, the initial query request can be rewritten into a target query request in combination with the structure attributes of the initial query request. Therefore, according to the global temporary table and the target replacement temporary table, the initial query request is rewritten into a target query request, which is specifically implemented as follows: Determine the structural attributes of the initial query request; when the structural attributes of the initial query request are preset attributes, rewrite the reference relationship of the initial query request to the global temporary table into a reference relationship to the target replacement temporary table to generate a target query request.
[0059] Specifically, the structure attributes include the hasGtt attribute of the structure; the preset attributes refer to the pre-set structure attributes, which may include true.
[0060] Based on this, after determining the target replacement temporary table corresponding to the global temporary table in the target query transaction, determine the structure attributes of the initial query request, and judge whether the structure attributes of the initial query request are preset attributes. If so, rewrite the reference relationship to the global temporary table in the initial query request into a reference relationship to the target replacement temporary table, and determine the replaced query request as the target query request.
[0061] Continuing with the above example, after determining the target replacement temporary table gtt_my_table_pid corresponding to the global temporary table gtt_my_table in query transaction 1, determine the hasGtt attribute of the structure of the initial query request. When the hasGtt attribute of the structure of the initial query request is true, rewrite the reference relationship to the global temporary table gtt_my_table in the initial query request into a reference relationship to the target replacement temporary table gtt_my_table_pid, and determine the rewritten query request as the target query request.
[0062] In actual applications, after the initial query request is rewritten into a target query request, the kernel processor will call the SQL compiler to recompile and parse the target query request, and generate a parse tree corresponding to the target query request. Then, the parse tree corresponding to the target query request is used to replace the parse tree corresponding to the initial query request for subsequent processing and application.
[0063] In summary, by determining the target replacement temporary table corresponding to the global temporary table in the target query transaction, and after judging the structural properties of the initial query request, rewriting the reference relationship to the global temporary table in the initial query request into a reference relationship to the target replacement temporary table, the target query request is generated. On the basis of realizing the use of global temporary tables for internal sharing in the database, the data privatization between each session or transaction is ensured.
[0064] Furthermore, in actual applications, there may be a situation where the global temporary table is not included in the multiple query target tables corresponding to the initial query request. Therefore, when the multiple query target tables corresponding to the initial query request do not include the global temporary table, the initial query request still needs to be processed. The specific implementation is as follows: In a case where the at least one query target table does not include the global temporary table, a target query transaction corresponding to the initial query request is executed on the database.
[0065] Based on this, if the request type of the initial query request is still a data operation type, but the multiple query target tables corresponding to the initial query request do not include a global temporary table, then the initial query request does not need to use a global temporary table, and there is no need to rewrite the initial query request to generate a target query request. At this time, the target query transaction corresponding to the initial query request can be directly executed on the database, that is, the target query transaction continues to be executed based on the initial query request.
[0066] In summary, based on the usage of the global temporary table by the initial query request, it is determined whether the initial query request needs to be rewritten into a target query request based on the global temporary table, thereby improving the accuracy and practicality of rewriting the initial query request into a target query request.
[0067] Step 208: Execute the target query transaction corresponding to the target query request on the database.
[0068] Specifically, after the initial query request is rewritten into the target query request, the target query transaction corresponding to the target query request can be executed on the database. Based on this, after the initial query request is rewritten into the target query request, the kernel processor calls the SQL engine to continue to execute the target query request until the target query transaction is committed.
[0069] Furthermore, the initial query request submitted by the developer to the database on the client is not necessarily of the data operation type, but may be of other types. Therefore, the processing process of the initial query request of the non-data operation type is specifically implemented as follows: An initial query request of a data definition type submitted to the database is received; and a target query transaction corresponding to the initial query request is executed on the database.
[0070] Specifically, the data definition type refers to the request type of the initial query request; the initial query request of the data definition type can be used to define data structures and objects, including creating, modifying and deleting objects. After the global temporary table of the database is created in response to the global temporary table creation request, the initial query request submitted to the database can be received. If the request type of the received initial query request is the data definition type, it means that the initial query request does not need to use the global temporary table, and there is no need to rewrite the initial query request to generate the target query request. At this time, the target query transaction corresponding to the initial query request can be directly executed on the database, that is, the target query transaction continues to be executed based on the initial query request.
[0071] Furthermore, after the target query transaction is executed, each temporary table corresponding to the target query transaction needs to be processed, which is specifically implemented as follows: When the target query transaction is executed, each temporary table associated with the target query transaction is traversed; when a transaction-level temporary table exists in each temporary table, the transaction-level temporary table is deleted.
[0072] Specifically, whether the target query transaction is executed on the database based on the initial query request or the target query transaction is executed based on the target query request, after the target query transaction is committed, that is, after the target query transaction is executed, it is necessary to process the temporary tables corresponding to the target query transaction. The kernel processor traverses the temporary tables associated with the target query transaction. If the traversed temporary table is a transaction-level temporary table, the transaction-level temporary table is deleted. When the target query transaction ends, the associated temporary tables are automatically deleted.
[0073] In actual applications, when a transaction-level temporary table is created as a global temporary table, it carries the "on commit deleterows" clause. Based on this, when the kernel processor traverses each temporary table of the target query transaction, it can determine whether the traversed temporary table is a transaction-level temporary table according to the "oncommit delete rows" clause. If so, it performs the delete operation.
[0074] Furthermore, if the client is disconnected from the kernel processor, the target query transaction executed in the database will end. At this time, it is also necessary to process the temporary tables corresponding to the target query transaction. The specific implementation is as follows: When the client is disconnected from the core processor, each temporary table associated with the target query transaction is traversed and each temporary table is deleted.
[0075] Specifically, if the client is disconnected from the kernel processor, all transactions executed in the database will end. At this time, the kernel processor traverses all temporary tables associated with the target query transaction and deletes all temporary tables obtained through the traversal. This allows automatic deletion of local temporary tables after the client is disconnected from the kernel processor, without the need for additional computation to determine whether all transactions executed in the database have ended, thus saving computational resources and improving the efficiency of deleting local temporary tables.
[0076] The request processing method provided in this specification is applied to a kernel processor, and includes: in response to a global temporary table creation request submitted to a database, creating a global temporary table of the database; receiving an initial query request of a data operation type submitted to the database, and determining at least one query target table corresponding to the initial query request; when the global temporary table is included in the at least one query target table, rewriting the initial query request into a target query request based on the global temporary table; and executing a target query transaction corresponding to the target query request on the database.
[0077] One or more embodiments of the present specification realize that a global temporary table is created in a database so that the initial query request submitted for creating the global temporary table can use the created global temporary table as middleware for request processing. In this process, the temporary table sharing within the database can be realized based on the global temporary table, and due to the characteristics of the global temporary table itself, the definition of the global temporary table created at this time is visible to the current session of the target query transaction and any other session, thereby realizing the centralized maintenance of the DDL statement. By searching the cache entry corresponding to the global temporary table in the local relationship table to determine whether the initial query request is the first query request to access the global temporary table in the target query transaction, if so, a corresponding target replacement temporary table is created for the target query transaction according to the global temporary table, if not, the target replacement temporary table corresponding to the target query transaction can be determined according to the global table identifier of the global temporary table. The initial query request is rewritten based on the global temporary table and the target replacement temporary table to generate a target query request, and the corresponding target query transaction is executed based on the rewritten target query request, so that the data privatization of the target query transaction can be realized.
[0078] The following combination Figure 3, taking the application of the request processing method provided in this specification in data query as an example, the request processing method is further explained. Among them, Figure 3 A flowchart of a request processing method provided by an embodiment of this specification is shown, which specifically includes the following steps: Step 302: receiving a global temporary table creation request submitted to a database, parsing the global temporary table creation request, obtaining a global keyword in the global temporary table creation request, and creating a global temporary table of the database according to the global keyword.
[0079] Step 304: Receive an initial query request of a data operation type submitted to a database, and determine at least one query target table corresponding to the initial query request.
[0080] Step 306: When each query target table includes a global temporary table, obtain the local relationship table of the target query transaction corresponding to the initial query request, and search the local relationship table for a cache entry corresponding to the global temporary table.
[0081] Step 308: When a cache entry corresponding to the global temporary table is found, a target replacement temporary table corresponding to the global temporary table is determined according to the global table identifier of the global temporary table.
[0082] Step 310: If no cache entry corresponding to the global temporary table is found, a target replacement temporary table corresponding to the global temporary table is created for the target query transaction based on the table structure of the global temporary table, and the replacement table type of the target replacement temporary table is set to a common temporary table.
[0083] It should be noted that step 308 and step 310 are two different situations for determining the target replacement temporary table corresponding to the global temporary table, and there is no sequential execution relationship between the two.
[0084] Step 312: When the hasGtt property of the structure of the initial query request is true, the reference relationship to the global temporary table in the initial query request is rewritten into a reference relationship to the target replacement temporary table, and a target query request is generated.
[0085] Step 314: Execute the target query transaction corresponding to the target query request on the database.
[0086] Step 316: When each query target table does not contain a global temporary table, execute the target query transaction corresponding to the initial query request on the database.
[0087] It should be noted that step 306 and step 316 are two different situations of whether each query target table contains a global temporary table, and there is no sequential execution relationship between the two.
[0088] Step 318: Receive an initial query request of a data definition type submitted to a database, and execute a target query transaction corresponding to the initial query request on the database.
[0089] It should be noted that step 304 and step 318 are two different situations where the initial query request is of a data operation type and a data definition type, respectively, and there is no sequential execution relationship between the two.
[0090] Step 320: When the target query transaction is executed, traverse the temporary tables associated with the target query transaction, and if a transaction-level temporary table exists in each temporary table, delete the transaction-level temporary table.
[0091] Step 322: When the client is disconnected from the kernel processor, traverse each temporary table associated with the target query transaction and delete each temporary table.
[0092] An embodiment of the present specification realizes that a global temporary table is created in a database so that the initial query request submitted for the creation of the global temporary table can use the created global temporary table as middleware for request processing. In this process, the temporary table sharing within the database can be realized based on the global temporary table, and due to the characteristics of the global temporary table itself, the definition of the global temporary table created at this time is visible to the current session of the target query transaction and any other session, thereby realizing the centralized maintenance of the DDL statement. By searching the cache entry corresponding to the global temporary table in the local relationship table, it is determined whether the initial query request is the first query request to access the global temporary table in the target query transaction. If so, a corresponding target replacement temporary table is created for the target query transaction according to the global temporary table. If not, the target replacement temporary table corresponding to the target query transaction can be determined according to the global table identifier of the global temporary table. The initial query request is rewritten based on the global temporary table and the target replacement temporary table to generate a target query request, and the corresponding target query transaction is executed based on the rewritten target query request, retaining the performance and privatization advantages of the temporary table.
[0093] See also Figure 4 , Figure 4 A schematic diagram of a processing flow chart of a request processing system provided according to an embodiment of this specification is shown. The embodiment of the request processing system provided in this specification is as follows: The request processing system includes a client and a core processor; The client is configured to send a global temporary table creation request for a database to the kernel processor; The kernel processor is configured to create a global temporary table of the database in response to the global temporary table creation request; The client is further configured to send an initial query request for a data operation type submitted to the database to the core processor; The core processor is further configured to receive the initial query request and determine at least one query target table corresponding to the initial query request; when the at least one query target table includes the global temporary table, rewrite the initial query request into a target query request based on the global temporary table; and execute a target query transaction corresponding to the target query request on the database.
[0094] Specifically, the request processing system provided in this specification includes a client and a kernel processor. The client can be used to send a global temporary table creation request for a database to the kernel processor. After receiving the global temporary table creation request, the kernel processor responds to the global temporary table creation request and creates a global temporary table (gtt) of the database. After the global temporary table is successfully created, the client can send an initial query request submitted to the database to the kernel processor. If the request type of the initial query request is a data operation type (dml), the initial query request is parsed, and at least one query target table corresponding to the initial query request is determined, and each query target table is traversed to determine whether each query target table contains a global temporary table. If each query target table contains a global temporary table, then when the hasGtt attribute of the structure of the initial query request is true, it is determined according to the local relationship table whether the initial query request is the first query request to access the global temporary table in the target query transaction (the specific implementation process can be found in the above-mentioned request processing method). If so, the target replacement temporary table corresponding to the global temporary table in the target query transaction is created. If not, the corresponding target replacement temporary table ( Figure 4 ). The reference relationship of the global temporary table in the initial query request is rewritten as a reference relationship of the target replacement temporary table to generate a target query request. Then, the SQL compiler is called to recompile the target query request, generate a new parse tree, and continue to execute the target query transaction based on the target query request. If each query target table does not contain a global temporary table, there is no need to rewrite the initial query request, and the target query transaction is continued to be executed according to the initial query request.
[0095] If the request type of the initial query request is a data definition type (ddl), there is no need to rewrite the initial query request, and the target query transaction continues to be executed according to the initial query request.
[0096] After the target query transaction is committed, the kernel processor traverses each temporary table. If it is determined to be a transaction-level temporary table, the transaction-level temporary table is deleted; after the client is disconnected from the kernel processor, the kernel processor traverses each temporary table and deletes the traversed temporary table.
[0097] It should be noted that the core processor deployed in the request processing system is used to execute the above request processing method. The specific execution process of the core processor of the request processing system can be found in the above request processing method, which will not be repeated in this specification.
[0098] The request processing system provided in this specification realizes the creation of a global temporary table in the database through the interaction between the client and the kernel processor, so that the initial query request submitted for the creation of the global temporary table can use the created global temporary table as the middleware for request processing. In this process, the temporary table sharing within the database can be realized based on the global temporary table, and due to the characteristics of the global temporary table itself, the definition of the global temporary table created at this time is visible to the current session of the target query transaction and any other session, thereby realizing the centralized maintenance of the DDL statement. The initial query request is rewritten based on the global temporary table, and a target query request is generated. The corresponding target query transaction is executed based on the rewritten target query request, which can solve the problems of logical concurrency and logical inconsistency caused by the scattered DDL statements.
[0099] Corresponding to the above method embodiment, this specification also provides a request processing device embodiment, Figure 5 FIG. 1 shows a schematic diagram of a request processing device provided by an embodiment of the present specification. Figure 5 As shown, the device is applied to a core processor and includes: A creation module 502 is configured to create a global temporary table of the database in response to a global temporary table creation request submitted to the database; The determination module 504 is configured to receive an initial query request of a data operation type submitted to the database, and determine at least one query target table corresponding to the initial query request; A rewriting module 506 is configured to rewrite the initial query request into a target query request based on the global temporary table when the at least one query target table includes the global temporary table; The execution module 508 is configured to execute the target query transaction corresponding to the target query request on the database.
[0100] Optionally, the creation module 502 is further configured to: Parsing the global temporary table creation request to obtain a global keyword in the global temporary table creation request; A global temporary table of the database is created according to the global keyword.
[0101] Optionally, the rewriting module 506 is further configured to: Determine a target replacement temporary table corresponding to the global temporary table in the target query transaction; The initial query request is rewritten into a target query request according to the global temporary table and the target replacement temporary table.
[0102] Optionally, the rewriting module 506 is further configured to: Obtaining a local relation table of the target query transaction, and searching the local relation table for a cache entry corresponding to the global temporary table; In the case where a cache entry corresponding to the global temporary table is found, determining a target replacement temporary table corresponding to the global temporary table according to a global table identifier of the global temporary table; In the case that no cache entry corresponding to the global temporary table is found, a target replacement temporary table corresponding to the global temporary table is created for the target query transaction based on the table structure of the global temporary table.
[0103] Optionally, the device further includes a setting module configured to: The replacement table type of the target replacement temporary table is set to a common temporary table.
[0104] Optionally, the rewriting module 506 is further configured to: Determining the structure attributes of the initial query request; In the case where the structure attribute of the initial query request is a preset attribute, the reference relationship to the global temporary table in the initial query request is rewritten as a reference relationship to the target replacement temporary table to generate a target query request.
[0105] Optionally, the device further includes a first initial execution module, configured to: In a case where the at least one query target table does not include the global temporary table, a target query transaction corresponding to the initial query request is executed on the database.
[0106] Optionally, the device further includes a second initial execution module, configured to: Receiving an initial query request of a data definition type submitted to the database; A target query transaction corresponding to the initial query request is executed on the database.
[0107] Optionally, the device further includes a first deleting module configured to: When the target query transaction is executed, traverse each temporary table associated with the target query transaction; If a transaction-level temporary table exists in each temporary table, the transaction-level temporary table is deleted.
[0108] Optionally, the device further includes a second deleting module configured to: When the client is disconnected from the core processor, each temporary table associated with the target query transaction is traversed and each temporary table is deleted.
[0109] The request processing device provided in this specification is applied to a kernel processor, including: a creation module, configured to create a global temporary table of the database in response to a global temporary table creation request submitted to the database; a determination module, configured to receive an initial query request of a data operation type submitted to the database, and determine at least one query target table corresponding to the initial query request; a rewrite module, configured to rewrite the initial query request into a target query request based on the global temporary table when the global temporary table is included in the at least one query target table; and an execution module, configured to execute a target query transaction corresponding to the target query request on the database.
[0110] An embodiment of the present specification realizes that a global temporary table is created in a database, so that the initial query request submitted for creating the global temporary table can use the created global temporary table as middleware for request processing. In this process, temporary table sharing within the database can be realized based on the global temporary table, and due to the characteristics of the global temporary table itself, the definition of the global temporary table created at this time is visible to the current session of the target query transaction and any other session, thereby realizing centralized maintenance of DDL statements. The initial query request is rewritten based on the global temporary table, and a target query request is generated. The corresponding target query transaction is executed based on the rewritten target query request, which can solve the problems of logical concurrency and logical inconsistency caused by DDL statements scattered everywhere.
[0111] The above is a schematic scheme of a request processing device of this embodiment. It should be noted that the technical scheme of the request processing device and the technical scheme of the request processing method described above are of the same concept, and the details not described in detail in the technical scheme of the request processing device can be found in the description of the technical scheme of the request processing method described above.
[0112] Figure 6 The structure block diagram of a computing device 600 provided according to an embodiment of the present specification is shown. The components of the computing device 600 include but are not limited to a memory 610 and a processor 620. The processor 620 is connected to the memory 610 via a bus 630, and the database 650 is used to store data.
[0113] The computing device 600 also includes an access device 640 that enables the computing device 600 to communicate via one or more networks 660. Examples of these networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet. The access device 640 may include one or more of any type of network interface (e.g., a network interface card (NIC)) that is wired or wireless, such as an IEEE 802.11 wireless local area network (WLAN) wireless interface, a world-wide interoperability for microwave access (Wi-MAX) interface, an Ethernet interface, a universal serial bus (USB) interface, a cellular network interface, a Bluetooth interface, a near field communication (NFC) interface, and the like.
[0114] In one embodiment of the present specification, the above components of the computing device 600 and Figure 6 Other components not shown in the figure may also be connected to each other, for example, via a bus. It should be understood that Figure 6 The computing device structure block diagram shown is only for the purpose of illustration, and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.
[0115] The computing device 600 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., a tablet computer, a personal digital assistant, a laptop computer, a notebook computer, a netbook, etc.), a mobile phone (e.g., a smart phone), a wearable computing device (e.g., a smart watch, smart glasses, etc.), or other types of mobile devices, or a stationary computing device such as a desktop computer or a personal computer (PC). The computing device 600 may also be a mobile or stationary server.
[0116] The processor 620 implements the steps of the request processing method when executing the computer program or instruction.
[0117] The above is a schematic scheme of a computing device of this embodiment. It should be noted that the technical scheme of the computing device and the technical scheme of the request processing method described above are of the same concept, and the details not described in detail in the technical scheme of the computing device can be found in the description of the technical scheme of the request processing method described above.
[0118] An embodiment of the present specification also provides a computer-readable storage medium storing a computer program or instruction. When the computer program or instruction is executed by a processor, the steps of the request processing method described above are implemented.
[0119] The above is a schematic scheme of a computer-readable storage medium of this embodiment. It should be noted that the technical scheme of the storage medium and the technical scheme of the request processing method described above are of the same concept, and the details not described in detail in the technical scheme of the storage medium can be found in the description of the technical scheme of the request processing method described above.
[0120] An embodiment of the present specification also provides a computer program product, including a computer program or instructions, which implement the steps of the above request processing method when executed by a processor.
[0121] The above is a schematic scheme of a computer program product of this embodiment. It should be noted that the technical scheme of the computer program product and the technical scheme of the request processing method described above are of the same concept, and the details not described in detail in the technical scheme of the computer program product can be found in the description of the technical scheme of the request processing method described above.
[0122] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0123] The computer program or instruction includes a computer program code, which may be in source code form, object code form, executable file or some intermediate form, etc. The computer readable medium may include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electric carrier signal, telecommunication signal and software distribution medium, etc.
[0124] It should be noted that, for the convenience of description, the aforementioned method embodiments are all described as a series of action combinations, but those skilled in the art should be aware that this specification is not limited by the order of the actions described, because according to this specification, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by this specification.
[0125] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0126] The preferred embodiments of this specification disclosed above are only used to help explain this specification. The optional embodiments do not describe all the details in detail, nor do they limit the invention to only the specific implementation methods described. Obviously, many modifications and changes can be made according to the content of this specification. This specification selects and specifically describes these embodiments in order to better explain the principles and practical applications of this specification, so that technicians in the relevant technical field can well understand and use this specification. This specification is limited only by the claims and their full scope and equivalents.
Claims
1. A request processing method, characterized in that: Applicable to core processors, including: In response to a global temporary table creation request submitted to a database, create a global temporary table of the database; receiving an initial query request of a data operation type submitted to the database, and determining at least one query target table corresponding to the initial query request; In a case where the at least one query target table includes the global temporary table, rewriting the initial query request into a target query request based on the global temporary table; A target query transaction corresponding to the target query request is executed on the database.
2. The request processing method according to claim 1, characterized in that: In response to a global temporary table creation request submitted to a database, a global temporary table of the database is created, including: Parsing the global temporary table creation request to obtain a global keyword in the global temporary table creation request; A global temporary table of the database is created according to the global keyword.
3. The request processing method according to claim 1, characterized in that: Rewriting the initial query request into a target query request based on the global temporary table includes: Determine a target replacement temporary table corresponding to the global temporary table in the target query transaction; The initial query request is rewritten into a target query request according to the global temporary table and the target replacement temporary table.
4. The request processing method according to claim 3, characterized in that: Determining a target replacement temporary table corresponding to the global temporary table in the target query transaction includes: Obtaining a local relation table of the target query transaction, and searching the local relation table for a cache entry corresponding to the global temporary table; In the case where a cache entry corresponding to the global temporary table is found, determining a target replacement temporary table corresponding to the global temporary table according to a global table identifier of the global temporary table; In the case that no cache entry corresponding to the global temporary table is found, a target replacement temporary table corresponding to the global temporary table is created for the target query transaction based on the table structure of the global temporary table.
5. The request processing method according to claim 4, characterized in that: After creating the target replacement temporary table corresponding to the global temporary table for the target query transaction, the method further includes: The replacement table type of the target replacement temporary table is set to a common temporary table.
6. The request processing method according to claim 3, characterized in that: According to the global temporary table and the target replacement temporary table, rewriting the initial query request into a target query request includes: Determining the structure attributes of the initial query request; In the case where the structure attribute of the initial query request is a preset attribute, the reference relationship to the global temporary table in the initial query request is rewritten as a reference relationship to the target replacement temporary table to generate a target query request.
7. The request processing method according to claim 1, characterized in that: After determining at least one query target table corresponding to the initial query request, the method further includes: In a case where the at least one query target table does not include the global temporary table, a target query transaction corresponding to the initial query request is executed on the database.
8. The request processing method according to claim 1, characterized in that: The method further comprises: Receiving an initial query request of a data definition type submitted to the database; A target query transaction corresponding to the initial query request is executed on the database.
9. The request processing method according to claim 1, 7 or 8, characterized in that: The method further comprises: When the target query transaction is executed, traverse each temporary table associated with the target query transaction; If a transaction-level temporary table exists in each temporary table, the transaction-level temporary table is deleted.
10. The request processing method according to claim 1, 7 or 8, characterized in that: The method further comprises: When the client is disconnected from the core processor, each temporary table associated with the target query transaction is traversed and each temporary table is deleted.
11. A request processing system, characterized in that: Includes client and core processors; The client is configured to send a global temporary table creation request for a database to the kernel processor; The kernel processor is configured to create a global temporary table of the database in response to the global temporary table creation request; The client is further configured to send an initial query request for a data operation type submitted to the database to the core processor; The core processor is further configured to receive the initial query request and determine at least one query target table corresponding to the initial query request; In a case where the at least one query target table includes the global temporary table, rewriting the initial query request into a target query request based on the global temporary table; A target query transaction corresponding to the target query request is executed on the database.
12. A computing device comprising: Memory and processor; The memory is used to store computer programs or instructions, and the processor is used to execute the computer programs or instructions. It is characterized in that when the computer program or instructions are executed by the processor, the steps of the request processing method described in any one of claims 1-10 are implemented.
13. A computer-readable storage medium storing a computer program or instruction, characterized in that: When the computer program or instruction is executed by a processor, the steps of the request processing method described in any one of claims 1 to 10 are implemented.
14. A computer program product comprising a computer program or instructions, characterized in that When the computer program or instruction is executed by a processor, the steps of the request processing method described in any one of claims 1 to 10 are implemented.
Citation Information
Patent Citations
Database object processing method, device and equipment and storage medium
CN111858645A
Data query method and device, equipment and storage medium
CN116541438A
Data query method and device, equipment and medium
CN116955394A
Database adapter
US20140032608A1
Dynamic and predictive global temporary tables
US20180113921A1
