A sentence conversion method and device, electronic equipment, storage medium and program product
Patent Information
- Application Number
- CN202510595666.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-09
- Publication Date
- 2026-09-18
- Estimated Expiration
- 2045-05-09
AI Technical Summary
例如,企图先通过DDL语句删除索引来提高后续DML语句的执行效率,但是删除索引的操作,使数据块中字典对象信息发生了变化,在DML语句已经基于原始字典对象信息构造了执行计划的前提下,字典对象信息变化会导致已构造的DML语句无法执行计划,发生报错
[0019] The technical solution of this invention addresses the issue of converting statements within a block of statements to be analyzed. It involves obtaining the statements to be converted and their corresponding parsing information; converting the statements to be converted into executable statements based on the parsing information; and replacing the statements to be converted within the block of statements to be analyzed with the executable statements to obtain an updated block of statements to be analyzed. By obtaining the statements to be converted and their corresponding parsing information within the block of statements to be analyzed, the invention achieves the conversion of statements to be converted into executable statements based on the parsing information. This converts static statements into dynamic statements, enabling the real-time construction of execution plans during the execution of the block of statements to be analyzed, thus improving the execution efficiency of the block. Replacing the statements to be converted with executable statements in the block of statements to be analyzed solves the problem of static statements failing due to changes in object definitions caused by the execution of data definition languages, thereby ensuring the normal execution of the block of statements to be analyzed in the database.
Smart Images

Figure CN120448412B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of database technology, and in particular to a statement conversion method, apparatus, electronic device, storage medium, and program product. Background Technology
[0002] A statement block refers to a set of statements arranged in a certain logical order. Within a statement block, Data Manipulation Language (DML) statements can be used to perform CRUD operations on data. DML statements are static SQL statements; their execution plans are constructed directly during statement block compilation, and subsequent execution follows this pre-constructed plan. Besides static SQL statements, statement blocks also support dynamic SQL statements. Dynamic SQL is not processed during statement block compilation; it is only analyzed and processed when the statement block encounters a corresponding dynamic SQL instruction, at which point an execution plan is constructed. The execution plan for dynamic SQL statements is constructed in real-time based on the current database environment, making it more accurate than the static SQL statement execution plan, which is based on the database environment at the time of statement block analysis. This difference is particularly noticeable when the statement block contains a large amount of table data modification, insertion, and deletion.
[0003] When executing a statement block, if a DDL (Data Definition Language) statement is executed first, it may cause changes to the dictionary objects, rendering the execution plan of the subsequently constructed DML statement unusable. DDL statements are used to define and manage database objects; they are dynamic SQL statements. For example, attempting to improve the execution efficiency of subsequent DML statements by first deleting an index using a DDL statement will result in changes to the dictionary object information within the data block. Since the DML statement has already constructed its execution plan based on the original dictionary object information, this change will prevent the constructed DML statement from executing its plan, leading to errors. Besides the above issues, other problems exist when executing statement blocks. For instance, if data is inserted into the statement block (the number of rows can be variable, ranging from a few to hundreds, tens of thousands, or even millions), and then a static SQL statement is executed, the static SQL statement, which has already constructed its execution plan based on the data before the insertion, will no longer be compatible with the statement block after the data addition, causing the statement block to fail to execute correctly. Summary of the Invention
[0004] This invention provides a statement conversion method, apparatus, electronic device, storage medium, and program product to ensure the normal execution of statement blocks in a database and to avoid errors during statement block execution.
[0005] According to one aspect of the present invention, a statement conversion method is provided, comprising:
[0006] For the statement to be converted in the statement block to be analyzed, the statement to be converted and the parsing information of the statement to be converted are obtained. The parsing information includes information obtained by semantic parsing the statement to be converted. The statement to be converted includes static statements in the statement block to be analyzed. The static statements include statements with pre-constructed execution plans.
[0007] Based on the parsed information, the statement to be converted is converted into a statement to be executed. The statement to be executed includes dynamic statements that conform to the characteristics of dynamic statements, and the dynamic statements include statements that construct execution plans in real time.
[0008] The statement to be converted in the statement block to be analyzed is replaced with the statement to be executed to obtain the updated statement block to be analyzed.
[0009] According to another aspect of the present invention, a statement conversion apparatus is provided, comprising:
[0010] The acquisition module is used to acquire the statement to be converted and the parsing information of the statement to be converted in the statement block to be analyzed. The parsing information includes information obtained by semantic parsing the statement to be converted. The statement to be converted includes static statements in the statement block to be analyzed. The static statements include statements with pre-constructed execution plans.
[0011] The conversion module is used to convert the statement to be converted into a statement to be executed based on the parsed information. The statement to be executed includes dynamic statements that conform to the characteristics of dynamic statements, and the dynamic statements include statements that construct execution plans in real time.
[0012] The replacement module is used to replace the statement to be converted in the statement block to be analyzed with the statement to be executed, so as to obtain an updated statement block to be analyzed.
[0013] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0014] At least one processor; and
[0015] A memory communicatively connected to the at least one processor; wherein,
[0016] The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the statement conversion method according to any embodiment of the present invention.
[0017] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the statement conversion method described in any embodiment of the present invention.
[0018] According to another aspect of the present invention, a computer program product is provided, the computer program product comprising a computer program that, when executed by a processor, implements the statement conversion method described in any embodiment of the present invention.
[0019] The technical solution of this invention addresses the issue of converting statements within a block of statements to be analyzed. It involves obtaining the statements to be converted and their corresponding parsing information; converting the statements to be converted into executable statements based on the parsing information; and replacing the statements to be converted within the block of statements to be analyzed with the executable statements to obtain an updated block of statements to be analyzed. By obtaining the statements to be converted and their corresponding parsing information within the block of statements to be analyzed, the invention achieves the conversion of statements to be converted into executable statements based on the parsing information. This converts static statements into dynamic statements, enabling the real-time construction of execution plans during the execution of the block of statements to be analyzed, thus improving the execution efficiency of the block. Replacing the statements to be converted with executable statements in the block of statements to be analyzed solves the problem of static statements failing due to changes in object definitions caused by the execution of data definition languages, thereby ensuring the normal execution of the block of statements to be analyzed in the database.
[0020] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 This is a flowchart of a statement conversion method provided in Embodiment 1 of the present invention;
[0023] Figure 2 This is a flowchart of a method for converting a statement to be converted according to Embodiment 2 of the present invention;
[0024] Figure 3 This is a schematic diagram of the structure of a statement conversion device according to Embodiment 3 of the present invention;
[0025] Figure 4 This is a block diagram of an electronic device provided according to Embodiment 4 of the present invention. Detailed Implementation
[0026] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0027] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0028] Example 1
[0029] Figure 1 This document provides a flowchart of a statement conversion method according to Embodiment 1 of the present invention. This embodiment is applicable to the conversion of static statements in a database into dynamic statements. The method can be executed by a statement conversion device, which can be implemented in hardware and / or software. This device can be configured in an electronic device, such as a mobile terminal, a PC, or a server. Figure 1 As shown, the method includes:
[0030] S110. For the statement to be converted in the statement block to be analyzed, obtain the statement to be converted and the parsing information of the statement to be converted.
[0031] The parsed information includes information obtained by semantic parsing the statement to be converted. The statement to be converted includes static statements in the statement block to be analyzed, and the static statements include statements with pre-constructed execution plans.
[0032] In this embodiment, the statement block to be analyzed can be understood as a statement block in the database that supports statement transformation. A statement block refers to a set of statements arranged in sequence. In the database, a statement block can contain multiple statements, which can be executed sequentially or their execution order can be controlled by some logic (such as conditional judgments, loops, etc.). The statement to be transformed can be understood as a statement in the statement block that supports statement transformation. The statement to be transformed is a static statement. The execution plan corresponding to a static statement is pre-constructed, and when the statement is executed, the execution plan is directly obtained from the database. The execution plan can be understood as the execution step scheme specified by the statement in the database. For static statements, their execution plan is determined at compile time and cannot be dynamically generated.
[0033] Parsing information can be understood as the information obtained by semantically parsing the statement to be analyzed. This parsing information can include the static features that make up the statement, as well as its description, structure, and other information. Semantic parsing can be understood as the parsing operation of statements in a database, enabling in-depth examination and understanding of the statements. Static features can be the information obtained by semantically parsing the statement to be transformed, and the statement to be transformed can be composed of static features.
[0034] Specifically, the process first obtains the block of statements to be analyzed that supports statement transformation, as well as the statements within that block that can be transformed. Statement transformation can be considered as stripping the static statements from the statements to be analyzed and adding the corresponding dynamic statements. The block of statements to be analyzed that supports transformation can be a block of statements edited and executed by the user. The statements within the block that can be transformed must be static statements, and semantic parsing of the statements to be transformed must be successfully performed, with the parsing information recorded.
[0035] For example, static statements can include INSERT statements, DELETE statements, UPDATE statements, and SELECT statements. In a statement block, there are the following three statements: INSERT INTO TEST1(X,Y)VALUES(1,1); INSERT INTO TEST1(X,Y)VALUES(2,2); INSERT INTO TEST1(X,Y)VALUES(3,3). These three statements are all static statements. Semantic parsing is performed on these three statements, and the successfully parsed statements are used as the statements to be converted.
[0036] S120. Based on the parsed information, convert the statement to be converted into a statement to be executed.
[0037] The statements to be executed include dynamic statements that conform to the characteristics of dynamic statements, and the dynamic statements include statements that construct execution plans in real time.
[0038] In this embodiment, the statement to be executed can be understood as the statement obtained after the statement to be transformed is transformed. The statement to be executed is a dynamic statement, and the execution plan corresponding to the dynamic statement is constructed in real time. When the statement is executed, the execution plan of the constructed dynamic statement is implemented. The characteristics of dynamic statements can be understood as characteristics that indicate the standard structure, composition method, etc. of dynamic statements.
[0039] Specifically, the static features of the statements to be converted in the parsed information are determined, and each static feature is rewritten into a dynamic feature according to the information indicated by the dynamic statement characteristics. Dynamic features can be understood as the features required to compose a dynamic statement; dynamic features are features that conform to the characteristics of dynamic statements. Finally, the dynamic features corresponding to each static feature are assembled according to the dynamic statement characteristics to obtain the statement to be executed.
[0040] For example, consider the statement to be transformed: `SELECT MAX(X) INTO VAR1 FROM TEST1 WHERE Y = VAR2`. Based on the parsed information of the statement to be transformed, it is converted into the statement to be executed: `EXECUTE IMMEDATE SELECT MAX(SYSDBA.TEST1.X) FROM SYSDBA.TEST1 WHERE SYSDBA.TEST1.Y = :` <1> 'INTO VAR1 USING VAR2.' It can be seen that the parameters and variables in the statement to be converted, such as VAR1 and VAR2, are rewritten as USING and INTO clauses. The dictionary object X is also prefixed with SYSDBA.TEST1.X, which respectively represent the schema name SYSDBA and the table name TEST1 of the table where X is located.
[0041] S130. Replace the statement to be converted in the statement block to be analyzed with the statement to be executed to obtain the updated statement block to be analyzed.
[0042] Specifically, within the block of statements to be analyzed containing the statements to be transformed, each statement to be transformed is attempted to be identified as a corresponding statement to be executed, until all statements to be transformed in the block of statements to be analyzed are replaced with statements to be executed, resulting in an updated block of statements to be analyzed. All statements to be transformed in the block of statements to be analyzed are then replaced with their corresponding statements to be executed, resulting in the final updated block of statements to be analyzed. An execution plan is then generated and executed for the updated block of statements to be analyzed.
[0043] For example, suppose a block of statements to be analyzed can be represented as:
[0044] DECLARE
[0045] VAR1 INT;
[0046] VAR2 INT;
[0047] BEGIN
[0048] SELECT MAX(X)INTO VAR1 FROM TEST1 WHERE Y=VAR2;
[0049] DELETE FROM TEST1 WHERE X=VAR1;
[0050] END;
[0051] The static statement (i.e., static SQL statement) in the statement block to be analyzed, SELECT MAX(X) INTO VAR1 FROM TEST1 WHERE Y = VAR2, is converted into a dynamic statement (i.e., dynamic SQL statement): EXECUTE IMMEDIATE SELECT MAX(SYSDBA.TEST1.X) FROM SYSDBA.TEST1 WHERE SYSDBA.TEST1.Y = : <1> 'INTO VAR1 USING VAR2; converts the static statement DELETE FROM TEST1 WHERE X = VAR1 into the dynamic statement EXECUTEIMMEDIATE' DELETE FROM SYSDBA.TEST1 WHERE SYSDBA.TEST1.X =: <1> If 'USING VAR1' is used, then after replacing all the statements to be transformed in the block to be analyzed with the statements to be executed, the updated block to be analyzed can be represented as follows:
[0052] DECLARE
[0053] VAR1 INT;
[0054] VAR2 INT;
[0055] BEGIN
[0056] EXECUTE IMMEDIATE'SELECT MAX(SYSDBA.TEST1.X)FROM SYSDBA.TEST1 WHERESYSDBA.TEST1.Y=: <1> 'INTO VAR1 USING VAR2;
[0057] EXECUTE IMMEDIATE'DELETE FROM SYSDBA.TEST1 WHERE SYSDBA.TEST1.X=: <1> 'USING VAR1;
[0058] END.
[0059] The technical solution of this invention addresses the issue of converting statements within a block of statements to be analyzed. It involves obtaining the statements to be converted and their corresponding parsing information; converting the statements to be converted into executable statements based on the parsing information; and replacing the statements to be converted within the block of statements to be analyzed with the executable statements to obtain an updated block of statements to be analyzed. By obtaining the statements to be converted and their corresponding parsing information within the block of statements to be analyzed, the invention achieves the conversion of statements to be converted into executable statements based on the parsing information. This converts static statements into dynamic statements, enabling the real-time construction of execution plans during the execution of the block of statements to be analyzed, thus improving the execution efficiency of the block. Replacing the statements to be converted with executable statements in the block of statements to be analyzed solves the problem of static statements failing due to changes in object definitions caused by the execution of data definition languages, thereby ensuring the normal execution of the block of statements to be analyzed in the database.
[0060] Based on the above embodiments, modified embodiments of the above embodiments are proposed. It should be noted that, in order to keep the description brief, only the differences from the above embodiments are described in the modified embodiments.
[0061] In one embodiment, obtaining the statement to be converted includes:
[0062] Determine the statement to be analyzed in the statement block to be analyzed, wherein the statement block to be analyzed consists of at least one statement to be analyzed;
[0063] For each statement to be analyzed, determine whether it is a static statement. If so, perform semantic parsing on the statement. If the parsing is successful, determine the statement to be analyzed as a statement to be converted.
[0064] In this embodiment, the statement to be analyzed can be understood as the statement in the statement block to be analyzed. The statement to be analyzed can be a static statement or a dynamic statement. A statement block to be analyzed can consist of at least one statement to be analyzed.
[0065] Specifically, for a block of statements to be analyzed, all statements comprising that block are identified. For each statement to be analyzed, it is determined whether it is a static statement. If so, semantic parsing is performed. To preserve the semantics of the original static statement as much as possible, optimization is avoided during semantic parsing. Instead, optimization is performed after converting the static statement to a dynamic statement and executing the dynamic statement. If the statement to be analyzed is a static statement, no additional optimization is performed. Instead, semantic parsing is performed directly. If parsing is successful, the statement is considered for conversion; otherwise, additional optimization is performed. If the statement to be analyzed is not a static statement, additional optimization is performed, and semantic parsing is performed using the original method. If parsing is successful, the process continues to determine whether the next statement to be analyzed is a static statement; otherwise, an error is reported.
[0066] For example, additional optimizations could include converting OR expressions in the statement to be analyzed to IN expressions, or converting correlated subqueries to WITH FUNCTION to remove relevance. Before performing semantic parsing on the statement to be analyzed, it's advisable to record the statement in advance; in this case, the statement is a static statement, avoiding significant differences before and after transformation. If the statement to be analyzed does not contain parameters, variables, or requires object prefixes, then statement transformation can be omitted.
[0067] Optionally, determining the statements to be analyzed in the block of statements to be analyzed includes:
[0068] Obtain the original statement block and the statement block characteristics of the original statement block, wherein the original statement block is composed of original statements;
[0069] If the statement block feature indicates that the original statement block meets the set conditions, the original statement block is identified as a statement block to be analyzed. The set conditions include conditions related to the execution subject of the original statement block.
[0070] The original statements that make up the block of statements to be analyzed are identified as the statements to be analyzed.
[0071] In this embodiment, a raw statement block can be understood as a statement block included in the database. A raw statement block can be a code block directly written in SQL language, which can be directly executed in the program. A raw statement block consists of at least one raw statement, which is a statement directly written in SQL language in the database. Statement block characteristics can be understood as characteristics indicating the execution subject of the raw statement block, such as the user or the database system.
[0072] Specifically, the process involves retrieving a block of raw statements from the database, consisting of at least one raw statement, and determining the block's characteristics. It then determines whether the block meets predefined conditions, which can be related to the execution entity of the block. Specifically, if the block's characteristics indicate that it was edited and executed by a user, the block is considered to meet the conditions; if the characteristics indicate that it was executed internally by the database system, the block is considered not to meet the conditions. The block that meets the conditions is then designated as the block to be analyzed, and the raw statements that make up this block are also designated as statements to be analyzed.
[0073] In one embodiment, after replacing the statement to be transformed in the statement block to be analyzed with the statement to be executed to obtain the updated statement block to be analyzed, the method further includes:
[0074] Based on the statement to be executed in the updated statement block to be analyzed, an execution plan for the updated statement block to be analyzed is generated and the execution plan is executed. The execution plan includes the plan for the execution of the statement to be executed in the updated statement block to be analyzed.
[0075] In this embodiment, the execution plan can be used to plan the order, steps, etc. of the execution of the statements to be executed in the updated block of statements to be analyzed.
[0076] For example, based on the statements to be executed in the updated block of statements to be analyzed, an execution plan is generated for the updated block of statements to be analyzed. This execution plan describes how to execute the statements to be executed. Finally, the updated block of statements to be analyzed is executed according to the execution plan. For example, an updated block of statements to be analyzed can be represented as:
[0077] DECLARE
[0078] VAR1 INT;
[0079] VAR2 INT;
[0080] BEGIN
[0081] EXECUTE IMMEDIATE'SELECT MAX(SYSDBA.TEST1.X)FROM SYSDBA.TEST1 WHERESYSDBA.TEST1.Y=: <1> 'INTO VAR1 USING VAR2;
[0082] EXECUTE IMMEDIATE'DELETE FROM SYSDBA.TEST1 WHERE SYSDBA.TEST1.X=: <1> 'USING VAR1;
[0083] END
[0084] An execution plan is generated and executed for the updated statement block to be analyzed.
[0085] Example 2
[0086] Figure 2 This is a flowchart of a method for converting a statement to be converted according to Embodiment 2 of the present invention. This embodiment focuses on the method of converting a statement to be converted into an executable statement as described in the above embodiments. Figure 2 As shown, the method includes:
[0087] S210. For the statement to be converted in the statement block to be analyzed, obtain the statement to be converted and the parsing information of the statement to be converted.
[0088] S220. Determine the static features included in the parsed information.
[0089] The statement to be converted consists of at least one of the static features.
[0090] Specifically, after semantic parsing the statement to be converted, parsing information can be obtained. This parsing information includes the static features of the statement to be converted, as well as information indicating the structure of the statement. The statement to be converted can consist of at least one static feature, which may include the input, output, object name, and expression of the statement.
[0091] S230. For each of the static features, rewrite the static features into dynamic features according to the dynamic statement characteristics.
[0092] Specifically, the type information for each static feature is determined, as different types of static features require different rewriting schemes for dynamic features. Based on the type information of each static feature and the scheme indicated by the dynamic statement characteristics, the static features are rewritten as dynamic features. The type information indicates the type of the static feature, which can include expression type, object type, input type, and output type.
[0093] Optionally, rewriting the static feature into a dynamic feature according to the dynamic statement characteristics includes:
[0094] Determine the type information of the static feature, wherein the type information indicates the type of the static feature;
[0095] Based on the type information, the static features are rewritten as dynamic features according to the dynamic statement characteristics.
[0096] Specifically, static features and type information for each static feature are obtained from the parsed information. Following the scheme indicated by the type information and satisfying the characteristics of dynamic statements, the static features are rewritten as dynamic features. Static features can include expression types, object types, input types, and output types. The static features of expression types can be rewritten as dynamic features first, and then the static features of object types, input types, and output types can be rewritten as their corresponding dynamic features.
[0097] Optionally, the type information includes expression type, object type, input type, and output type. The step of rewriting the static features into dynamic features according to the type information and the dynamic statement characteristics includes:
[0098] When the type information indicates that the static feature is an expression type, the static feature is rewritten as a dynamic feature according to a set scheme. The set scheme includes replacing the expression in the static feature that is related to the statement block to be analyzed with the expression indicated by the dynamic statement feature.
[0099] When the type information indicates that the static feature is an object type, according to the dynamic statement characteristics, the object name is spelled according to the entity object indicated by the static feature, and the object name is used as the dynamic feature;
[0100] When the type information indicates that the static feature is an input type, the static feature is rewritten as a parameter binding clause, and the parameter binding clause is used as a dynamic feature;
[0101] If the type information indicates that the static feature is an output type, the static feature is treated as a dynamic feature.
[0102] In this embodiment, the setting scheme can be understood as a scheme for rewriting the static features of the expression type into dynamic features. Specifically, some information in the static features can be replaced with information that conforms to the characteristics of dynamic statements. The parameter binding clause is a clause used to bind parameters in a dynamic statement.
[0103] For example, when the type information indicates that the static feature is an expression type, rewriting the static feature into a dynamic feature according to the set scheme can skip the parts of the static feature related to the statement block to be analyzed, such as variables and parameters, and only retain the parts related to the dynamic statement features. For example, for the statement to be converted: SELECT MAX(X)INTO VAR1 FROM TEST1 WHERE Y=VAR2. The expression indicated by the rewritten dynamic statement feature can be: EXECUTE IMMEDIATE 'SELECT MAX(X)FROM TEST1 WHERE Y=? '. Here, "?" indicates the parameter binding of the statement to be executed, that is, the parameter binding of the dynamic statement. The dynamic feature skips variables VAR1 and VAR2, that is, skips the variables and parameters in the statement block to be analyzed.
[0104] When the type information indicates that the static feature is an object type, for the static feature of the object type, such as an entity object, the entity object is the semantic parsing result of the object name in the statement to be converted. The object name in the statement to be executed is spelled according to the entity object. For example, the table name is spelled as schema name.table name, and the column name is spelled as schema name.table name.column name. In the above expression, when the column name is X, it is rewritten as SYSDBA.TEST1.X, and when the table name is TEST1, it is rewritten as SYSDBA.TEST1. The rewritten dynamic feature is then filled into the expression indicated by the above dynamic statement feature: EXECUTE IMMEDIATE 'SELECT MAX(SYSDBA.TEST1.X) FROM SYSDBA.TEST1 WHERE SYSDBA.TEST1.Y=? '.
[0105] If the type information indicates that the static feature is the output type, changing the INTO output part of the static feature to the INTO output part of the dynamic feature will produce the statement to be executed: EXECUTE IMMEDIATE 'SELECT MAX(SYSDBA.TEST1.X)FROM SYSDBA.TEST1 WHERE SYSDBA.TEST1.Y=? 'INTO VAR1.
[0106] When the type information indicates that the static feature is an input type, the input part of the static feature (including variables, parameters, etc.) is changed to a parameter binding clause, such as the USING clause. In this case, the expression indicated by the dynamic statement feature is: EXECUTE IMMEDIATE 'SELECT MAX(SYSDBA.TEST1.X) FROM SYSDBA.TEST1 WHERE SYSDBA.TEST1.Y=? 'INTO VAR1 USING VAR2.' Here, "?" represents the parameter binding of the statement to be executed, and "?" can also be replaced with: <1> This indicates that the first variable following USING is used at this position.
[0107] S240. According to the structural information indicated by the parsed information, assemble the dynamic features corresponding to each static feature to obtain the statement to be executed.
[0108] The structural information is the information included in the parsing information that indicates the structure of the static statement.
[0109] In this embodiment, structural information can indicate the structure of static statements, including information such as the position of static features in static statements.
[0110] Specifically, according to the structural information of the static statement indicated by the parsed information, the dynamic features corresponding to the static features are assembled to obtain the statement to be executed. The dynamic features can be primarily rewritten from the static features of the expression type, and the dynamic features corresponding to the static features of the object type, input type, and output type can be filled into the dynamic features of the expression type to obtain the statement to be executed.
[0111] For example, for a statement to be transformed, i.e., a static statement: `SELECT MAX(X) INTO VAR1 FROM TEST1 WHERE Y = VAR2`, we can first rewrite the static features of the expression type to obtain the dynamic features: `EXECUTE IMMEDIATE 'SELECT MAX(X) FROM TEST1 WHERE Y = ?'`. Then, we rewrite the static features of the object type, input type, and output type, and assemble the dynamic features corresponding to the aforementioned static features into the dynamic features corresponding to the static features of the expression type. The assembly order of the dynamic features corresponding to the aforementioned static features is not limited. For example, first assembling the dynamic features corresponding to the static features of the object type yields the statement: `EXECUTE IMMEDIATE 'SELECT MAX(SYSDBA.TEST1.X) FROM SYSDBA.TEST1 WHERE SYSDBA.TEST1.Y = ?'`. Then, the dynamic features corresponding to the static features of the output type are assembled to obtain the statement: EXECUTE IMMEDIATE 'SELECT MAX(SYSDBA.TEST1.X)FROM SYSDBA.TEST1 WHERE SYSDBA.TEST1.Y=? 'INTO VAR1.' Finally, the dynamic features corresponding to the static features of the input type are assembled to obtain the statement to be executed: EXECUTE IMMEDIATE 'SELECT MAX(SYSDBA.TEST1.X)FROM SYSDBA.TEST1 WHERE SYSDBA.TEST1.Y=? 'INTO VAR1 USING VAR2.'
[0112] S250. Replace the statement to be converted in the statement block to be analyzed with the statement to be executed to obtain the updated statement block to be analyzed.
[0113] The technical solution of this invention involves determining the static features included in the parsed information, wherein the statement to be converted is composed of at least one of the static features; for each static feature, rewriting it into a dynamic feature according to the characteristics of the dynamic statement; and assembling the dynamic features corresponding to each static feature according to the structural information indicated by the parsed information to obtain the statement to be executed, wherein the structural information is the information in the parsed information indicating the structure of the static statement. By rewriting the static features in the parsed information into dynamic features, the method of converting the statement to be converted into the statement to be executed is refined. Finally, the dynamic features are assembled to obtain the statement to be executed, thus realizing the removal of static statements from the statement block to be analyzed and ensuring the normal execution of the statement block to be analyzed in the database.
[0114] Example 3
[0115] Figure 3 This is a schematic diagram of the structure of a statement conversion device provided in Embodiment 3 of the present invention. Figure 3 As shown, the device includes:
[0116] The acquisition module 310 is used to acquire the statement to be converted and the parsing information of the statement to be converted in the statement block to be analyzed. The parsing information includes information obtained by semantic parsing the statement to be converted. The statement to be converted includes static statements in the statement block to be analyzed. The static statements include statements with pre-constructed execution plans.
[0117] The conversion module 320 is used to convert the statement to be converted into a statement to be executed based on the parsed information. The statement to be executed includes dynamic statements that conform to the characteristics of dynamic statements, and the dynamic statements include statements that construct execution plans in real time.
[0118] The replacement module 330 is used to replace the statement to be converted in the statement block to be analyzed with the statement to be executed, so as to obtain the updated statement block to be analyzed.
[0119] The task allocation device provided in this embodiment of the invention, for the statement to be converted in the statement block to be analyzed, obtains the statement to be converted and its parsing information through an acquisition module; converts the statement to be converted into an execution statement according to the parsing information through a conversion module; and replaces the statement to be converted in the statement block to be analyzed with the execution statement through a replacement module, resulting in an updated statement block to be analyzed. Through the cooperation between the modules, the device obtains the statement to be converted and its corresponding parsing information for the statement to be converted in the statement block to be analyzed, realizing the conversion of the statement to be converted into an execution statement according to the parsing information, that is, realizing the conversion of static statements into dynamic statements, so that the execution plan can be constructed in real time when the statement block to be analyzed is executed, thereby improving the execution efficiency of the statement block to be analyzed. Replacing the statement to be converted in the statement block to be analyzed with the execution statement solves the problem that the object definition changes due to the execution of the data definition language, resulting in static statement errors, and achieves the beneficial effect of ensuring the normal execution of the statement block to be analyzed in the database.
[0120] In one embodiment, the conversion module 320 includes:
[0121] The first determining unit is used to determine the static features included in the parsed information, wherein the statement to be converted consists of at least one of the static features;
[0122] The rewriting unit is used to rewrite each static feature into a dynamic feature according to the characteristics of the dynamic statement.
[0123] An assembly unit is used to assemble the dynamic features corresponding to each static feature according to the structural information indicated by the parsing information to obtain an executable statement, wherein the structural information is the information in the parsing information that indicates the structure of the static statement.
[0124] In one embodiment, the rewriting unit includes:
[0125] A subunit is defined to determine the type information of the static feature, wherein the type information indicates the type of the static feature;
[0126] The rewrite subunit is used to rewrite the static feature into a dynamic feature according to the type information and the characteristics of the dynamic statement.
[0127] In one embodiment, the type information includes expression type, object type, input type, and output type. The rewrite subunit is specifically used for:
[0128] When the type information indicates that the static feature is an expression type, the static feature is rewritten as a dynamic feature according to a set scheme. The set scheme includes replacing the expression in the static feature that is related to the statement block to be analyzed with the expression indicated by the dynamic statement feature.
[0129] When the type information indicates that the static feature is an object type, according to the dynamic statement characteristics, the object name is spelled according to the entity object indicated by the static feature, and the object name is used as the dynamic feature;
[0130] When the type information indicates that the static feature is an input type, the static feature is rewritten as a parameter binding clause, and the parameter binding clause is used as a dynamic feature;
[0131] If the type information indicates that the static feature is an output type, the static feature is treated as a dynamic feature.
[0132] In one embodiment, the acquisition module 310 includes:
[0133] The second determining unit is used to determine the statement to be analyzed in the statement block to be analyzed, wherein the statement block to be analyzed consists of at least one statement to be analyzed.
[0134] The third determining unit is used to determine whether each statement to be analyzed is a static statement. If so, it performs semantic parsing on the statement to be analyzed. If the parsing is successful, it determines the statement to be analyzed as a statement to be converted.
[0135] In one embodiment, the second determining unit is specifically used for:
[0136] Obtain the original statement block and the statement block characteristics of the original statement block, wherein the original statement block is composed of original statements;
[0137] If the statement block feature indicates that the original statement block meets the set conditions, the original statement block is identified as a statement block to be analyzed. The set conditions include conditions related to the execution subject of the original statement block.
[0138] The original statements that make up the block of statements to be analyzed are identified as the statements to be analyzed.
[0139] In one embodiment, the statement conversion apparatus further includes an execution module, specifically used for:
[0140] Based on the statement to be executed in the updated statement block to be analyzed, an execution plan for the updated statement block to be analyzed is generated and the execution plan is executed. The execution plan includes the plan for the execution of the statement to be executed in the updated statement block to be analyzed.
[0141] The statement conversion device provided in this embodiment of the invention can execute the statement conversion method provided in any embodiment of the invention. Through the cooperation and coordination between the modules, the statement conversion is completed, and it has the corresponding functional modules and beneficial effects of the execution method.
[0142] Example 4
[0143] According to embodiments of the present invention, the present invention also provides an electronic device, a computer-readable storage medium, and a computer program product.
[0144] Figure 4 This is a block diagram of an electronic device according to Embodiment 4 of the present invention, which implements the statement conversion method described in the embodiments of the present invention. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (such as helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0145] like Figure 4As shown, the electronic device 410 includes at least one processor 411 and a memory, such as a read-only memory (ROM) 412 or a random access memory (RAM) 413, communicatively connected to the at least one processor 411. The memory stores computer programs executable by the at least one processor. The processor 411 can perform various appropriate actions and processes based on the computer program stored in the ROM 412 or loaded from storage unit 418 into the RAM 413. The RAM 413 can also store various programs and data required for the operation of the electronic device 410. The processor 411, ROM 412, and RAM 413 are interconnected via a bus 414. An input / output (I / O) interface 415 is also connected to the bus 414.
[0146] Multiple components in the electronic device are connected to the I / O interface 415, including: an input unit 416, such as a keyboard, mouse, etc.; an output unit 417, such as various types of displays, speakers, etc.; a storage unit 418, such as a disk, optical disk, etc.; and a communication unit 419, such as a network card, modem, wireless transceiver, etc. The communication unit 419 allows the electronic device to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0147] Processor 411 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 411 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 411 performs the various methods and processes described above, such as statement translation methods.
[0148] In some embodiments, the statement translation method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 418. In some embodiments, part or all of the computer program may be loaded and / or mounted on electronic device 410 via ROM 412 and / or communication unit 419. When the computer program is loaded into RAM 413 and executed by processor 411, one or more steps of the statement translation method described above may be performed. Alternatively, in other embodiments, processor 411 may be configured to perform the statement translation method by any other suitable means (e.g., by means of firmware).
[0149] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0150] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0151] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0152] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0153] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0154] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0155] In some embodiments, the computer program product includes a computer program that, when executed by a processor, implements the statement conversion method provided in the embodiments of the present invention.
[0156] The technical solution of this invention provides a statement conversion method, apparatus, electronic device, storage medium, and program product. For a statement to be converted within a statement block to be analyzed, the method acquires the statement to be converted and its parsing information; based on the parsing information, the statement to be converted is converted into an executable statement; and the statement to be converted within the statement block to be analyzed is replaced with the executable statement, resulting in an updated statement block to be analyzed. Acquiring the statement to be converted and its corresponding parsing information within the statement block to be analyzed enables the conversion of the statement to be converted into an executable statement based on the parsing information, thus converting static statements into dynamic statements. This allows for real-time construction of execution plans during the execution of the statement block to be analyzed, improving its execution efficiency. Replacing the statement to be converted with the executable statement solves the problem of static statement errors caused by changes in object definitions due to the execution of data definition languages, thereby ensuring the normal execution of the statement block to be analyzed in the database.
[0157] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A statement conversion method, characterized in that, include: For the statement to be converted in the statement block to be analyzed, the statement to be converted and the parsing information of the statement to be converted are obtained. The parsing information includes information obtained by semantic parsing the statement to be converted. The statement to be converted includes static statements in the statement block to be analyzed. The static statements include statements with pre-constructed execution plans. Based on the parsed information, the statement to be converted is converted into an executable statement. The executable statement includes dynamic statements that conform to the characteristics of dynamic statements, and the dynamic statements include statements that construct execution plans in real time. This process includes: determining the static features included in the parsed information, wherein the statement to be converted consists of at least one of the static features; for each static feature, rewriting the static feature into a dynamic feature according to the characteristics of dynamic statements; assembling the dynamic features corresponding to each static feature according to the structural information indicated by the parsed information to obtain the executable statement, wherein the structural information is information included in the parsed information indicating the structure of the static statement; the rewriting of the static feature into a dynamic feature according to the characteristics of dynamic statements includes: determining the type information of the static feature, wherein the type information indicates the type of the static feature; and rewriting the static feature into a dynamic feature according to the type information and the characteristics of dynamic statements. The statement to be converted in the statement block to be analyzed is replaced with the statement to be executed to obtain the updated statement block to be analyzed.
2. The method according to claim 1, characterized in that, The type information includes expression type, object type, input type, and output type. The step of rewriting the static features into dynamic features according to the type information and the dynamic statement characteristics includes: When the type information indicates that the static feature is an expression type, the static feature is rewritten as a dynamic feature according to a set scheme. The set scheme includes replacing the expression in the static feature that is related to the statement block to be analyzed with the expression indicated by the dynamic statement feature. When the type information indicates that the static feature is an object type, according to the dynamic statement characteristics, the object name is spelled according to the entity object indicated by the static feature, and the object name is used as the dynamic feature; When the type information indicates that the static feature is an input type, the static feature is rewritten as a parameter binding clause, and the parameter binding clause is used as a dynamic feature; If the type information indicates that the static feature is an output type, the static feature is treated as a dynamic feature.
3. The method according to claim 1, characterized in that, The process of obtaining the statement to be converted includes: Determine the statement to be analyzed in the statement block to be analyzed, wherein the statement block to be analyzed consists of at least one statement to be analyzed; For each statement to be analyzed, determine whether it is a static statement. If so, perform semantic parsing on the statement. If the parsing is successful, determine the statement to be analyzed as a statement to be converted.
4. The method according to claim 3, characterized in that, The step of determining the statements to be analyzed in the block of statements to be analyzed includes: Obtain the original statement block and the statement block characteristics of the original statement block, wherein the original statement block is composed of original statements; If the statement block feature indicates that the original statement block meets the set conditions, the original statement block is identified as a statement block to be analyzed. The set conditions include conditions related to the execution subject of the original statement block. The original statements that make up the block of statements to be analyzed are identified as the statements to be analyzed.
5. The method according to claim 1, characterized in that, After replacing the statement to be converted in the statement block to be analyzed with the statement to be executed to obtain the updated statement block to be analyzed, the method further includes: Based on the statement to be executed in the updated statement block to be analyzed, an execution plan for the updated statement block to be analyzed is generated and the execution plan is executed. The execution plan includes the plan for the execution of the statement to be executed in the updated statement block to be analyzed.
6. A sentence conversion device, characterized in that, include: The acquisition module is used to acquire the statement to be converted and the parsing information of the statement to be converted in the statement block to be analyzed. The parsing information includes information obtained by semantic parsing the statement to be converted. The statement to be converted includes static statements in the statement block to be analyzed. The static statements include statements with pre-constructed execution plans. The conversion module is used to convert the statement to be converted into a statement to be executed based on the parsed information. The statement to be executed includes dynamic statements that conform to the characteristics of dynamic statements. The dynamic statements include statements that construct execution plans in real time. Specifically, the module is used to: determine the static features included in the parsed information, wherein the statement to be converted consists of at least one of the static features; and rewrite the static features into dynamic features according to the characteristics of dynamic statements for each static feature. According to the structural information indicated by the parsed information, the dynamic features corresponding to each static feature are assembled to obtain the statement to be executed. The structural information is the information in the parsed information that indicates the structure of the static statement. The step of rewriting the static features into dynamic features according to the dynamic statement characteristics is specifically used for: determining the type information of the static feature, the type information indicating the type of the static feature; and rewriting the static features into dynamic features according to the dynamic statement characteristics based on the type information. The replacement module is used to replace the statement to be converted in the statement block to be analyzed with the statement to be executed, so as to obtain an updated statement block to be analyzed.
7. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the statement conversion method according to any one of claims 1-5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the statement conversion method of any one of claims 1-5.
9. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the statement conversion method according to any one of claims 1-5.
Citation Information
Patent Citations
DDL statement processing method and apparatus,, electronic device and medium
CN110083617A
DDL synchronization method and device for PostgreSQL database, equipment and medium
CN112231407A