Statement conversion method and device, electronic equipment, storage medium and program product
By converting static statements in the database into dynamic statements and constructing execution plans in real time, the execution plan failure caused by DDL operations is solved, and the execution efficiency and reliability of statement blocks are improved.
Patent Information
- Application Number
- CN202510595666.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-09
- Publication Date
- 2025-08-08
- Estimated Expiration
- 2045-05-09
AI Technical Summary
When executing statement blocks in the database, the dictionary object changes due to the data definition language (DDL) operation, resulting in the execution plan of the static statement being unused, and an error problem occurs, and the static SQL statement cannot adapt to data changes, resulting in the execution failure.
By obtaining the statements to be converted and their parsing information in the statement block to be analyzed, the static statements are converted into dynamic statements, and the dynamic statements are constructed in real time and replacing the original static statements.
Realize the real-time construction of the execution plan in the database, improve the execution efficiency of the statement block, avoid errors caused by data definition language operations, and ensure normal execution of the statement block.
Smart Images

Figure CN120448412A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database technology, and in particular to a statement conversion method, device, electronic device, storage medium and program product. Background Art
[0002] A statement block refers to a set of statements arranged in a certain logical order. In a statement block, you can directly use data manipulation language (i.e., DML statements) to add / delete / modify / query data. DML statements are static SQL statements, and the corresponding execution plan can be directly constructed when the statement block is compiled. Subsequent execution of DML statements will be directly executed according to the constructed execution plan. In addition to static SQL statements, statement blocks also support dynamic SQL statements. Dynamic SQL is not processed when the statement block is compiled. Only when the statement block executes the corresponding dynamic SQL instruction is the dynamic SQL analyzed and processed to construct an execution plan. The execution plan of dynamic SQL statements is constructed in real time based on the current database environment. Compared with static SQL statements, the execution plan constructed based on the database environment when the statement block is analyzed is more accurate. The difference is particularly obvious when there is a large amount of table data modification, insertion, and deletion in the statement block.
[0003] When executing a statement block, executing a DDL (Data Definition Language) statement first can cause changes to the dictionary objects, rendering the execution plan for the subsequently constructed DML statements inoperable. DDL statements are used to define and manage database objects and are a type of dynamic SQL statement. For example, an attempt to improve the execution efficiency of subsequent DML statements by first deleting an index through a DDL statement can cause changes to the dictionary object information in the data block. If the DML statements have already constructed an execution plan based on the original dictionary object information, this change in dictionary object information can cause the constructed DML statements to fail to execute, resulting in an error. In addition to the aforementioned issues, other problems can arise when executing a statement block. For example, if data is first inserted into a statement block (the number of inserted rows varies, potentially ranging from a few rows to hundreds, tens of thousands, or even millions or more), and then a static SQL statement is executed, the static SQL statement can already construct an execution plan based on the pre-insertion data. However, after the data is added, the execution plan is no longer compatible with the statement block, resulting in the statement block failing to execute properly. Summary of the Invention
[0004] The present invention provides a statement conversion method, device, electronic device, storage medium and program product to ensure the normal execution of statement blocks in a database and avoid the occurrence of errors during the execution of statement blocks.
[0005] According to one aspect of the present invention, a statement conversion method is provided, comprising:
[0006] For a statement to be converted in a statement block to be analyzed, obtaining the statement to be converted and parsing information of the statement to be converted, wherein the parsing information includes information obtained by semantically parsing the statement to be converted, the statement to be converted includes a static statement in the statement block to be analyzed, and the static statement includes a statement for which an execution plan is pre-constructed;
[0007] Converting the to-be-converted statements into to-be-executed statements based on the parsed information, wherein the to-be-executed statements include dynamic statements that conform to dynamic statement characteristics, and the dynamic statements include statements for constructing an execution plan 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 an updated statement block to be analyzed.
[0009] According to another aspect of the present invention, there is provided a sentence conversion device, comprising:
[0010] an acquisition module, configured to acquire, for a statement to be converted in a statement block to be analyzed, the statement to be converted and parsing information of the statement to be converted, wherein the parsing information includes information obtained by semantically parsing the statement to be converted, the statement to be converted includes a static statement in the statement block to be analyzed, and the static statement includes a statement for which an execution plan is pre-constructed;
[0011] a conversion module, configured to convert the to-be-converted statements into to-be-executed statements based on the parsed information, wherein the to-be-executed statements include dynamic statements that conform to dynamic statement characteristics, and the dynamic statements include statements that construct an execution plan 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 to obtain an updated statement block to be analyzed.
[0013] According to another aspect of the present invention, an electronic device is provided, 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 is executed by the at least one processor so that the at least one processor can execute the statement conversion method described in any embodiment of the present invention.
[0017] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the statement conversion method described in any embodiment of the present invention when executed.
[0018] According to another aspect of the present invention, a computer program product is provided. The computer program product includes a computer program. When the computer program is executed by a processor, the statement conversion method according to any embodiment of the present invention is implemented.
[0019] The technical solution of the embodiment of the present invention is to obtain the to-be-converted statement and the parsing information of the to-be-converted statement in the to-be-converted statement block; convert the to-be-converted statement into the to-be-executed statement according to the parsing information; replace the to-be-converted statement in the to-be-converted statement block with the to-be-executed statement to obtain an updated to-be-converted statement block. For the to-be-converted statement in the to-be-converted statement block, the to-be-converted statement and its corresponding parsing information are obtained, and the to-be-converted statement is converted into the to-be-executed statement according to the parsing information, that is, the static statement is converted into a dynamic statement, so that the execution plan can be constructed in real time when the to-be-converted statement block is executed, thereby improving the execution efficiency of the to-be-converted statement block. Replacing the to-be-converted statement in the to-be-converted statement block with the to-be-executed statement solves the problem of static statement error caused by the change of object definition due to the execution of the data definition language in the to-be-converted statement block, and achieves the beneficial effect of ensuring the normal execution of the to-be-converted statement block in the database.
[0020] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present invention, nor is it intended to limit the scope of the present invention. Other features of the present invention will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0022] Figure 1 This is a flowchart of a statement conversion method provided according to the first embodiment of the present invention;
[0023] Figure 2 This is a flowchart of a method for converting a statement to be converted provided in accordance with a second embodiment of the present invention;
[0024] Figure 3 2 is a schematic diagram of the structure of a sentence conversion device provided according to the third embodiment of the present invention;
[0025] Figure 4 This is a block diagram of an electronic device provided according to a fourth embodiment of the present invention. DETAILED DESCRIPTION
[0026] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.
[0027] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0028] Example 1
[0029] Figure 1 A flowchart of a statement conversion method is provided for the first embodiment of the present invention. This embodiment is applicable to the case of converting static statements in a database into dynamic statements. The method can be executed by a statement conversion device, which can be implemented in the form of hardware and / or software. The statement conversion device can be configured in an electronic device, which can be a mobile terminal, PC or server, etc. Figure 1 As shown, the method includes:
[0030] S110 . For a statement to be converted in a statement block to be analyzed, obtain the statement to be converted and parsing information of the statement to be converted.
[0031] The parsing information includes information obtained by semantically parsing the statements to be converted, the statements to be converted include static statements in the statement block to be analyzed, and the static statements include statements for which an execution plan is pre-constructed.
[0032] In this embodiment, the statement block to be analyzed can be understood as a statement block in the database that can support statement conversion. A statement block refers to a set of statements arranged in sequence. In the database, a statement block can contain multiple statements. These statements can be executed sequentially or the execution order can be controlled by some logic (such as conditional judgment, loop, etc.). The statement to be converted can be understood as a statement in the statement block to be analyzed that can support statement conversion. The statement to be converted is a static statement. The execution plan corresponding to the static statement is pre-constructed. When the statement is executed, the execution plan is directly obtained from the database. The execution plan can be understood as the execution step plan specified by the statement in the database. For static statements, its execution plan is determined at compile time and cannot be generated dynamically.
[0033] Parsing information can be understood as the information obtained by semantically parsing the statement to be analyzed. This information can include the static features that make up the statement to be analyzed, as well as information such as its description and structure. Semantic parsing can be understood as the parsing operation on statements in a database. Semantic parsing enables in-depth inspection and understanding of statements. Static features can be information obtained by semantically parsing the statement to be converted, and the statement to be converted can be composed of static features.
[0034] Specifically, first obtain the block of statements to be analyzed that can support statement conversion, as well as the statements to be converted that can be converted in the block of statements to be analyzed. Statement conversion can also be considered as the operation of stripping the statements to be analyzed, that is, static statements, and adding dynamic statements corresponding to the statements to be analyzed. The block of statements to be analyzed that supports statement conversion can be a statement block that can be edited and executed by the user. The statements to be converted that can be converted in the block of statements to be analyzed must meet the requirements that the statements to be converted are static statements, and the semantic parsing of the statements to be converted must be successful, and the parsing information must be recorded at the same time.
[0035] For example, static statements can include insert statements (INSERT statements), delete statements (DELETE statements), update statements (UPDATE statements), and query statements (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: Convert the statement to be converted into a statement to be executed according to the parsing information.
[0037] The statements to be executed include dynamic statements that meet 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 converted is converted. The statement to be executed is a dynamic statement. The execution plan corresponding to the dynamic statement is constructed in real time. When the statement is executed, the constructed execution plan is implemented. Dynamic statement characteristics can be understood as characteristics that indicate the standard structure and composition of the dynamic statement.
[0039] Specifically, the static features of the statement 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 form a dynamic statement; dynamic features are features that conform to the characteristics of a dynamic statement. 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, for a statement to be converted: SELECT MAX(X) INTO VAR1 FROM TEST1 WHERE Y=VAR2. According to the parsing information of the statement to be converted, the statement to be converted is converted into a statement to be executed: EXECUTEIMMEDIATE'SELECT MAX(SYSDBA.TEST1.X) FROM SYSDBA.TEST1 WHERE SYSDBA.TEST1.Y=: <1> 'INTO VAR1 USING VAR2.' As can be seen, the parameters and variables in the statement to be converted, such as VAR1 and VAR2, are rewritten as USING and INTO clauses. The prefix SYSDBA.TEST1.X is also added before the dictionary object X, indicating the schema name SYSDBA and the table name TEST1 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 an updated statement block to be analyzed.
[0042] Specifically, within the block of statements to be analyzed, the program attempts to determine the corresponding executed statements for each statement to be analyzed, one by one, until all statements to be analyzed in the block are replaced with executed statements, resulting in an updated block of statements to be analyzed. All statements to be analyzed in the block are replaced with the corresponding executed statements, resulting in a final updated block of statements to be analyzed. An execution plan is then generated for the updated block of statements to be analyzed and executed.
[0043] For example, assume that a statement block 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; Convert the static statement DELETE FROM TEST1 WHERE X=VAR1 to the dynamic statement EXECUTEIMMEDIATE' DELETE FROM SYSDBA.TEST1 WHERE SYSDBA.TEST1.X=: <1> 'USING VAR1. After all the statements to be converted in the block to be analyzed are replaced with statements to be executed, the updated block to be analyzed can be expressed as:
[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 the embodiment of the present invention is to obtain the to-be-converted statement and the parsing information of the to-be-converted statement in the to-be-converted statement block; convert the to-be-converted statement into the to-be-executed statement according to the parsing information; replace the to-be-converted statement in the to-be-converted statement block with the to-be-executed statement to obtain an updated to-be-converted statement block. For the to-be-converted statement in the to-be-converted statement block, the to-be-converted statement and its corresponding parsing information are obtained, and the to-be-converted statement is converted into the to-be-executed statement according to the parsing information, that is, the static statement is converted into a dynamic statement, so that the execution plan can be constructed in real time when the to-be-converted statement block is executed, thereby improving the execution efficiency of the to-be-converted statement block. Replacing the to-be-converted statement in the to-be-converted statement block with the to-be-executed statement solves the problem of static statement error caused by the change of object definition due to the execution of the data definition language in the to-be-converted statement block, and achieves the beneficial effect of ensuring the normal execution of the to-be-converted statement block in the database.
[0060] Based on the above embodiment, a modified embodiment of the above embodiment is proposed. It should be noted that, in order to simplify the description, only the differences from the above embodiment are described in the modified embodiment.
[0061] In one embodiment, obtaining the statement to be converted includes:
[0062] Determining a statement to be analyzed in the statement block to be analyzed, where the statement block to be analyzed consists of at least one statement to be analyzed;
[0063] For each of the statements to be analyzed, it is determined whether the statement to be analyzed is a static statement. If so, semantic parsing is performed on the statement to be analyzed. If the parsing is successful, the statement to be analyzed is determined as a statement to be converted.
[0064] In this embodiment, the statement to be analyzed can be understood as a statement in a 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 be composed of at least one statement to be analyzed.
[0065] Specifically, for a block of statements to be analyzed, all the statements to be analyzed that constitute the block of statements to be analyzed are determined. For a statement to be analyzed, determine whether the statement to be analyzed is a static statement. If so, perform semantic analysis on the statement to be analyzed. In order to maintain the semantics of the original static statement as much as possible, try not to optimize it during the semantic analysis process. Instead, optimize it when executing the dynamic statement after converting the static statement into a dynamic statement. In the case that the statement to be analyzed is a static statement, no additional optimization is performed on the statement to be analyzed. Instead, semantic analysis is performed directly on the statement to be analyzed. If the analysis is successful, the statement to be analyzed is used as the statement to be converted. Otherwise, additional optimization is performed on the statement to be analyzed. In the case that the statement to be analyzed is not a static statement, additional optimization is performed on the statement to be analyzed, and semantic analysis is performed on the statement to be analyzed using the original method. If the analysis is successful, continue to determine whether the next statement to be analyzed is a static statement. Otherwise, an error is reported.
[0066] For example, additional optimizations can include converting OR expressions in the statement to be analyzed into IN expressions, or converting correlated subqueries into WITH FUNCTION queries to remove correlations. Before semantically parsing the statement to be analyzed, the statement to be analyzed can be recorded. In this case, the statement to be analyzed is static, avoiding significant differences before and after statement conversion. If the statement to be analyzed does not contain parameters or variables and does not require an object prefix, consider not performing statement conversion on the statement to be analyzed.
[0067] Optionally, determining the statement to be analyzed in the statement block to be analyzed includes:
[0068] Obtaining an original sentence block and a sentence block feature of the original sentence block, wherein the original sentence block is composed of an original sentence;
[0069] If the statement block feature indicates that the original statement block meets a set condition, determining the original statement block as a statement block to be analyzed, wherein the set condition includes a condition related to an execution subject of the original statement block;
[0070] The original sentences constituting the sentence block to be analyzed are determined as the sentences 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 the SQL language, which can be directly executed in a program. A raw statement block consists of at least one raw statement, which is a statement directly written in the SQL language in the database. Statement block features can be understood as features that indicate the execution subject of the raw statement block, etc. The execution subject of the raw statement block can be a user or the database system.
[0072] Specifically, an original statement block consisting of at least one original statement is obtained from the database, and the statement block features of the original statement block are determined. A determination is then made as to whether the original statement block satisfies a set condition. The set condition may be a condition related to the execution subject of the original statement block. Specifically, if the statement block features indicate that the original statement block was edited and executed by a user, the original statement block is deemed to satisfy the set condition; if the statement block features indicate that the original statement block was executed within the database system, the original statement block is deemed to not satisfy the set condition. The original statement block that satisfies the set condition is used as the statement block to be analyzed, and the original statements that constitute the original statement block are used as the statements to be analyzed.
[0073] In one embodiment, after replacing the to-be-converted statement in the to-be-analyzed statement block with the to-be-executed statement to obtain an updated to-be-analyzed statement block, the method further includes:
[0074] An execution plan for the updated statement block to be analyzed is generated based on the statement to be executed in the updated statement block to be analyzed, and the execution plan is executed. The execution plan includes a plan for executing the statement to be executed in the updated statement block to be analyzed.
[0075] In this embodiment, the execution plan can be used to update the sequence, steps, and other plans for executing the statements to be executed in the statement block to be analyzed.
[0076] For example, based on the pending statements in the updated block of statements to be analyzed, an execution plan is generated for the updated block of statements to be analyzed. The execution plan can describe how to execute the pending statements. 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] Generate an execution plan for the updated statement block to be analyzed and execute it.
[0085] Example 2
[0086] Figure 2 This is a flowchart of a method for converting a statement to be converted provided by the second embodiment of the present invention. This embodiment is based on the method for converting a statement to be converted into a statement to be executed in the above embodiment. Figure 2 As shown, the method includes:
[0087] S210 . For a statement to be converted in a statement block to be analyzed, obtain the statement to be converted and parsing information of the statement to be converted.
[0088] S220: Determine 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 semantically parsing the statement to be converted, parsed information can be obtained. The parsed information includes static features of the statement to be converted and information indicating the structure of the statement to be converted. The statement to be converted can be composed of at least one static feature, which can include inputs, outputs, object names, and expressions of the statement to be converted.
[0091] S230: For each of the static features, rewrite the static feature into a dynamic feature according to the dynamic statement characteristics.
[0092] Specifically, the type information of each static feature is determined. Different types of static features are rewritten into dynamic features in different ways. Based on the type information of each static feature and the solution indicated by the dynamic statement characteristics, the static feature is rewritten into a dynamic feature. The type information can indicate the type of the static feature, which can include expression type, object type, input type, and output type.
[0093] Optionally, rewriting the static features into dynamic features according to the dynamic statement characteristics includes:
[0094] determining type information of the static feature, where the type information indicates a type of the static feature;
[0095] According to the type information, the static features are rewritten into 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. The static features are then rewritten into dynamic features according to the scheme indicated by the type information that satisfies the characteristics of the dynamic statement. Static features can include expression types, object types, input types, and output types. Static features of expression types can be rewritten into dynamic features first, and then static features of object types, input types, and output types can be rewritten into corresponding dynamic features.
[0097] Optionally, the type information includes an expression type, an object type, an input type, and an output type, and rewriting the static feature into a dynamic feature 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, rewriting the static feature into a dynamic feature according to a setting scheme, the setting scheme including replacing an expression in the static feature related to the statement block to be analyzed with an expression indicated by the dynamic statement characteristic;
[0099] In the case where the type information indicates that the static feature is an object type, in accordance with the dynamic sentence characteristics, spelling the object name according to the entity object indicated by the static feature, and using the object name as the dynamic feature;
[0100] In a case where the type information indicates that the static feature is an input type, rewriting the static feature into a parameter binding clause, and using the parameter binding clause as a dynamic feature;
[0101] In a case where the type information indicates that the static feature is of an output type, the static feature is used 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 the dynamic statement. 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, the static feature is rewritten into a dynamic feature according to the set scheme. The variables, parameters, and other parts of the static feature of the expression type that are related to the statement block to be analyzed can be skipped, and only the parts related to the dynamic statement characteristics can be retained. 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 characteristic can be: EXECUTE IMMEDIATE'SELECT MAX(X)FROM TEST1 WHERE Y=? '. The "?" represents the parameter binding of the statement to be executed, that is, the parameter binding of the dynamic statement. The dynamic feature skips the variables VAR1 and VAR2, that is, the variables and parameters in the statement block to be analyzed are skipped.
[0104] If the type information indicates that the static feature is an object type, for example, an entity object, the object name in the statement to be converted is spelled according to the entity object. For example, a table name is spelled as schema name.table name, and a column name is spelled as schema name.table name.column name. In the above expression, if the column name is X, it is rewritten as SYSDBA.TEST1.X, and if the table name is TEST1, it is rewritten as SYSDBA.TEST1. The rewritten dynamic feature is then added to the expression indicated by the dynamic statement characteristic: EXECUTE IMMEDIATE 'SELECT MAX(SYSDBA.TEST1.X) FROM SYSDBA.TEST1 WHERE SYSDBA.TEST1.Y = ? '.
[0105] When the type information indicates that the static feature is of output type, the INTO output part of the static feature is changed to the INTO output part of the dynamic feature, and the statement to be executed is obtained: EXECUTE IMMEDIATE 'SELECT MAX(SYSDBA.TEST1.X) FROM SYSDBA.TEST1 WHERE SYSDBA.TEST1.Y=? ' INTO VAR1.
[0106] If the type information indicates that the static feature is an input type, the input portion of the static feature (including variables and parameters) is replaced with a parameter binding clause, such as a USING clause. 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. The "?" indicates the parameter binding of the statement to be executed. The "?" can also be replaced with: <1> , indicating that the first variable following USING is used at this location.
[0107] S240: Assemble the dynamic features corresponding to the static features according to the structural information indicated by the parsing information to obtain a statement to be executed.
[0108] The structural information is information included in the parsing information and indicating the structure of the static statement.
[0109] In this embodiment, the structural information may indicate the structure of the static sentence, including information such as the position of the static feature in the static sentence.
[0110] Specifically, according to the static statement structure information 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 rewritten from the static features of the expression type can be primarily used, and the dynamic features corresponding to the static features of the object type, input type, and output type are filled into the dynamic features of the expression type to obtain the statement to be executed.
[0111] For example, for a statement to be converted, namely the static statement: SELECT MAX(X) INTO VAR1 FROM TEST1 WHERE Y = VAR2, you can first rewrite the static characteristics of the expression type to obtain the dynamic characteristics: EXECUTE IMMEDIATE 'SELECT MAX(X) FROM TEST1 WHERE Y = ? '. Next, rewrite the static characteristics of the object type, input type, and output type, and assemble the dynamic characteristics corresponding to the aforementioned static characteristics into the dynamic characteristics corresponding to the static characteristics of the expression type. There is no restriction on the order of assembling the dynamic characteristics corresponding to the aforementioned static characteristics. For example, first assemble the dynamic characteristics corresponding to the static characteristics of the object type to obtain 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 an updated statement block to be analyzed.
[0113] The technical solution of an embodiment of the present invention determines static features included in the parsed information, wherein the statement to be converted is composed of at least one of these static features; for each static feature, the static feature is rewritten into a dynamic feature according to the characteristics of the dynamic statement; and the dynamic features corresponding to each static feature are assembled according to the structural information indicated by the parsed information to obtain the statement to be executed, wherein the structural information is information indicating the structure of the static statement included in the parsed information. By rewriting the static features in the parsed information into dynamic features, the method for 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, thereby stripping the 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 structural diagram of a sentence conversion device provided by the third embodiment of the present invention. Figure 3 As shown, the device includes:
[0116] The acquisition module 310 is used to obtain the statements to be converted in the statement block to be analyzed, as well as the parsing information of the statements to be converted, wherein the parsing information includes information obtained by semantically parsing the statements to be converted, and the statements to be converted include static statements in the statement block to be analyzed, and the static statements include statements with pre-constructed execution plans.
[0117] The conversion module 320 is configured to convert the statements to be converted into statements to be executed according to the parsing information, wherein 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.
[0118] The replacement module 330 is configured to replace the statement to be converted in the statement block to be analyzed with the statement to be executed, thereby obtaining an updated statement block to be analyzed.
[0119] The task allocation device provided by the embodiment of the present invention obtains the to-be-converted statements and the parsing information of the to-be-converted statements in the to-be-converted statement block through an acquisition module; converts the to-be-converted statements into to-be-executed statements based on the parsing information through a conversion module; and replaces the to-be-converted statements in the to-be-converted statement block with the to-be-executed statements through a replacement module to obtain an updated to-be-converted statement block. Through the mutual cooperation between the modules, the to-be-converted statements and their corresponding parsing information are obtained for the to-be-converted statements in the to-be-converted statement block, thereby achieving the conversion of the to-be-converted statements into to-be-executed statements based on the parsing information, that is, achieving the conversion of static statements into dynamic statements, so that an execution plan can be constructed in real time when the to-be-converted statement block is executed, thereby improving the execution efficiency of the to-be-converted statement block. Replacing the to-be-converted statements in the to-be-converted statement block with the to-be-executed statements solves the problem of static statement errors caused by changes in object definitions in the to-be-converted statement block due to the execution of the data definition language, thereby achieving the beneficial effect of ensuring the normal execution of the to-be-converted statement block in the database.
[0120] In one embodiment, the conversion module 320 includes:
[0121] a first determining unit, configured to determine static features included in the parsed information, wherein the sentence to be converted is composed of at least one of the static features;
[0122] a rewriting unit, configured to rewrite each of the static features into a dynamic feature according to the dynamic statement characteristics;
[0123] An assembling unit is used to assemble the dynamic features corresponding to the static features according to the structural information indicated by the parsing information to obtain a statement to be executed, wherein the structural information is information indicating the structure of the static statement included in the parsing information.
[0124] In one embodiment, the rewriting unit includes:
[0125] a determining subunit, configured to determine type information of the static feature, where the type information indicates the type of the static feature;
[0126] The rewriting subunit is used to rewrite the static features into dynamic features according to the type information and the dynamic statement characteristics.
[0127] In one embodiment, the type information includes expression type, object type, input type, and output type, and the rewriting subunit is specifically used to:
[0128] When the type information indicates that the static feature is an expression type, rewriting the static feature into a dynamic feature according to a setting scheme, the setting scheme including replacing an expression in the static feature related to the statement block to be analyzed with an expression indicated by the dynamic statement characteristic;
[0129] In the case where the type information indicates that the static feature is an object type, in accordance with the dynamic sentence characteristics, spelling the object name according to the entity object indicated by the static feature, and using the object name as the dynamic feature;
[0130] In a case where the type information indicates that the static feature is an input type, rewriting the static feature into a parameter binding clause, and using the parameter binding clause as a dynamic feature;
[0131] In a case where the type information indicates that the static feature is of an output type, the static feature is used as a dynamic feature.
[0132] In one embodiment, the acquisition module 310 includes:
[0133] A second determining unit is configured to determine a statement to be analyzed in the statement block to be analyzed, wherein the statement block to be analyzed is composed of at least one statement to be analyzed;
[0134] The third determining unit is configured to determine, for each of the statements to be analyzed, whether the statement to be analyzed is a static statement; if so, perform semantic parsing on the statement to be analyzed; and if the parsing is successful, determine the statement to be analyzed as a statement to be converted.
[0135] In one embodiment, the second determining unit is specifically configured to:
[0136] Obtaining an original sentence block and a sentence block feature of the original sentence block, wherein the original sentence block is composed of an original sentence;
[0137] If the statement block feature indicates that the original statement block meets a set condition, determining the original statement block as a statement block to be analyzed, wherein the set condition includes a condition related to an execution subject of the original statement block;
[0138] The original sentences constituting the sentence block to be analyzed are determined as the sentences to be analyzed.
[0139] In one embodiment, the statement conversion device further includes an execution module, specifically configured to:
[0140] An execution plan for the updated statement block to be analyzed is generated based on the statement to be executed in the updated statement block to be analyzed, and the execution plan is executed. The execution plan includes a plan for executing the statement to be executed in the updated statement block to be analyzed.
[0141] The statement conversion device provided in the embodiment of the present invention can execute the statement conversion method provided in any embodiment of the present invention, completes the conversion of the statement through the mutual cooperation and collaboration between the modules, and has the functional modules and beneficial effects corresponding to the execution method.
[0142] Example 4
[0143] According to an embodiment of the present invention, the present invention further provides an electronic device, a computer-readable storage medium, and a computer program product.
[0144] Figure 4 is a block diagram of an electronic device provided according to embodiment four of the present invention, which can implement the sentence conversion method described in the embodiment 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 processing, cellular phones, smart phones, 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 examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0145] like Figure 4As shown, the electronic device 410 includes at least one processor 411, and a memory connected to the at least one processor 411 in communication, such as a read-only memory (ROM) 412, a random access memory (RAM) 413, etc., wherein the memory stores a computer program that can be executed by the at least one processor, and the processor 411 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 412 or the computer program loaded from the storage unit 418 to the random access memory (RAM) 413. Various programs and data required for the operation of the electronic device 410 can also be stored in the RAM 413. The processor 411, ROM 412 and RAM 413 are connected to each other 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 magnetic disk, optical disk, etc.; and a communication unit 419, such as a network card, modem, wireless communication transceiver, etc. The communication unit 419 allows the electronic device to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0147] Processor 411 can be various general-purpose and / or specialized 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 specialized artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. Processor 411 executes the various methods and processes described above, such as the statement conversion method.
[0148] In some embodiments, the statement conversion method can be implemented as a computer program that is tangibly contained in a computer-readable storage medium, such as storage unit 418. In some embodiments, part or all of the computer program can be loaded and / or installed 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 conversion method described above can be performed. Alternatively, in other embodiments, processor 411 can be configured to perform the statement conversion method in any other appropriate manner (e.g., by means of firmware).
[0149] Various embodiments of the systems and techniques described 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), system-on-chip systems (SOCs), programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0150] Computer programs for implementing 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 the computer program is executed by the processor, the functions / operations specified in the flowcharts and / or block diagrams are implemented. The computer program may be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0151] In the context of the present invention, computer-readable storage media can be tangible media that can contain or store a computer program for use with an instruction execution system, device or equipment or used in combination with an instruction execution system, device or equipment. Computer-readable storage media can include but are not limited to electronic, magnetic, optical, electromagnetic, infrared or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, computer-readable storage media can be machine-readable signal media. More specific examples of machine-readable storage media can include electrical connections based on one or more lines, portable computer disks, hard disks, random access memories (RAM), read-only memories (ROM), erasable programmable read-only memories (EPROM or flash memory), optical fibers, portable compact disk read-only memories (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[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 can provide input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, the 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 acoustic input, voice input, or tactile input).
[0153] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0154] A computing system may include clients and servers. The clients and servers are typically remote from each other and typically interact via a communication network. This client-server relationship arises through computer programs running on the respective computers, creating a client-server relationship. The server may be a cloud server, also known as a cloud computing server or cloud host. This server is a hosting product within the cloud computing service ecosystem that addresses the management difficulties and limited scalability of traditional physical hosting and VPS services.
[0155] In some embodiments, the computer program product includes a computer program, and when the computer program is executed by a processor, it implements the statement conversion method provided by the embodiment of the present invention.
[0156] The technical solution of the embodiment of the present invention is provided through a statement conversion method, device, electronic device, storage medium and program product. 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; according to the parsing information, the statement to be converted is converted into a statement to be executed; the statement to be converted in the statement block to be analyzed is replaced with the statement to be executed to obtain an updated statement block to be analyzed. For the statement to be converted in the statement block to be analyzed, the statement to be converted and its corresponding parsing information are obtained, and the statement to be converted is converted into a statement to be executed according to the parsing information, that is, the static statement is converted into a dynamic statement, so that an 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 statement to be executed solves the problem that the object definition in the statement block to be analyzed changes due to the execution of the data definition language, thereby causing static statement errors, and achieves the beneficial effect of ensuring the normal execution of the statement block to be analyzed in the database.
[0157] The above specific embodiments do not limit the scope of protection of the present invention. Those skilled in the art will appreciate that various modifications, combinations, sub-combinations, and substitutions may be made based on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention are intended to be included within the scope of protection of the present invention.
Claims
1. A sentence conversion method, characterized in that: include: For a statement to be converted in a statement block to be analyzed, obtaining the statement to be converted and parsing information of the statement to be converted, wherein the parsing information includes information obtained by semantically parsing the statement to be converted, the statement to be converted includes a static statement in the statement block to be analyzed, and the static statement includes a statement for which an execution plan is pre-constructed; Converting the to-be-converted statements into to-be-executed statements based on the parsed information, wherein the to-be-executed statements include dynamic statements that conform to dynamic statement characteristics, and the dynamic statements include statements for constructing an execution plan in real time; The statement to be converted in the statement block to be analyzed is replaced with the statement to be executed to obtain an updated statement block to be analyzed.
2. The method according to claim 1, characterized in that The step of converting the statement to be converted into a statement to be executed according to the parsed information includes: Determining static features included in the parsed information, wherein the sentence to be converted is composed of at least one of the static features; For each of the static features, rewrite the static feature into a dynamic feature according to the dynamic statement characteristics; According to the structural information indicated by the parsing information, the dynamic features corresponding to the static features are assembled to obtain a statement to be executed, wherein the structural information is information indicating the structure of the static statement included in the parsing information.
3. The method according to claim 2, characterized in that The step of rewriting the static features into dynamic features according to the dynamic statement characteristics includes: determining type information of the static feature, where the type information indicates a type of the static feature; According to the type information, the static features are rewritten into dynamic features according to the dynamic statement characteristics.
4. The method according to claim 3, characterized in that The type information includes an expression type, an object type, an input type, and an output type. The rewriting of the static feature into a dynamic feature according to the type information and the dynamic statement characteristics includes: When the type information indicates that the static feature is an expression type, rewriting the static feature into a dynamic feature according to a setting scheme, the setting scheme including replacing an expression in the static feature related to the statement block to be analyzed with an expression indicated by the dynamic statement characteristic; In the case where the type information indicates that the static feature is an object type, in accordance with the dynamic sentence characteristics, spelling the object name according to the entity object indicated by the static feature, and using the object name as the dynamic feature; In a case where the type information indicates that the static feature is an input type, rewriting the static feature into a parameter binding clause, and using the parameter binding clause as a dynamic feature; In a case where the type information indicates that the static feature is of an output type, the static feature is used as a dynamic feature.
5. The method according to claim 1, characterized in that The obtaining of the statement to be converted includes: Determining a statement to be analyzed in the statement block to be analyzed, where the statement block to be analyzed consists of at least one statement to be analyzed; For each of the statements to be analyzed, it is determined whether the statement to be analyzed is a static statement. If so, semantic parsing is performed on the statement to be analyzed. If the parsing is successful, the statement to be analyzed is determined as a statement to be converted.
6. The method according to claim 5, characterized in that The determining of the to-be-analyzed statements in the to-be-analyzed statement block includes: Obtaining an original sentence block and a sentence block feature of the original sentence block, wherein the original sentence block is composed of an original sentence; If the statement block feature indicates that the original statement block meets a set condition, determining the original statement block as a statement block to be analyzed, wherein the set condition includes a condition related to an execution subject of the original statement block; The original sentences constituting the sentence block to be analyzed are determined as the sentences to be analyzed.
7. The method according to claim 1, characterized in that After replacing the to-be-converted statement in the to-be-analyzed statement block with the to-be-executed statement to obtain an updated to-be-analyzed statement block, the method further includes: An execution plan for the updated statement block to be analyzed is generated based on the statement to be executed in the updated statement block to be analyzed, and the execution plan is executed. The execution plan includes a plan for executing the statement to be executed in the updated statement block to be analyzed.
8. A sentence conversion device, characterized in that: include: an acquisition module, configured to acquire, for a statement to be converted in a statement block to be analyzed, the statement to be converted and parsing information of the statement to be converted, wherein the parsing information includes information obtained by semantically parsing the statement to be converted, the statement to be converted includes a static statement in the statement block to be analyzed, and the static statement includes a statement for which an execution plan is pre-constructed; a conversion module, configured to convert the to-be-converted statements into to-be-executed statements based on the parsed information, wherein the to-be-executed statements include dynamic statements that conform to dynamic statement characteristics, and the dynamic statements include statements that construct an execution plan in real time; 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 to obtain an updated statement block to be analyzed.
9. An electronic device, characterized in that: The electronic device comprises: 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 is 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 to 7.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the statement conversion method according to any one of claims 1 to 7 when executed.
11. A computer program product, characterized in that The computer program product comprises a computer program, which implements the statement conversion method according to any one of claims 1 to 7 when executed by a processor.