Method and device for processing ddl statement, electronic equipment and storage medium
By replacing or deleting statement fragments describing table structure information in DDL statements, existing table structure information can be reused, solving the problem of high syntax parsing difficulty in DDL statements and improving the parsing performance of statements. In particular, in SaaS services and database sharding scenarios, it enhances the concurrent processing capability of DTS.
Patent Information
- Application Number
- CN202211400763.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-09
- Publication Date
- 2026-02-13
- Estimated Expiration
- 2042-11-09
AI Technical Summary
In SaaS service scenarios or database sharding scenarios, the high difficulty of parsing DDL statements affects the ability of DTS to concurrently process DDL statements, especially when processing a large number of CREATE or ALTER statements in a short period of time.
By extracting statement fragments describing table structure information from DDL statements, querying pre-cached parsed statement fragments, obtaining associated optimized statement fragments, and replacing or deleting them to reuse existing table structure information, the difficulty of syntax parsing is reduced, and syntax parsing is only performed on statement fragments related to database and table name information.
It greatly reduces the difficulty of parsing DDL statements, improves the parsing performance of statements, can effectively handle a large number of DDL statements triggered in a short period of time, and improves the concurrent processing capability of DTS.
Smart Images

Figure CN115658696B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, and particularly relates to a DDL statement processing method and device, electronic equipment and storage medium. BACKGROUND
[0002] DDL (Data Definition Language) statements are used to create, modify or delete database objects such as databases, database tables, columns, etc. Commonly used DDL statements mainly include CREATE statements for creating database objects, ALTER statements for modifying database objects and DROP statements for deleting database objects. In various application scenarios such as SaaS (Software-as-a-Service) service scenarios or split database and split table scenarios, a user may trigger a large number of CREATE statements or ALTER statements in a short time, for example, the user triggers tens of thousands of CREATE statements or ALTER statements per hour. Therefore, DTS needs to parse the syntax of a large number of CREATE statements or ALTER statements in a short time, and create or modify database tables based on the syntax parsing results of the CREATE statements or ALTER statements. Obviously, the syntax parsing performance of the DDL statements directly affects the ability of DTS to concurrently process the DDL statements.
[0003] In actual application, some CREATE statements or ALTER statements are relatively complex, and the syntax parsing difficulty also increases accordingly. Therefore, it is necessary to optimize the CREATE statements or ALTER statements to reduce the syntax parsing difficulty of the CREATE statements or ALTER statements, and to provide a basis for DTS to better concurrently process the DDL statements. SUMMARY
[0004] Aspects of the present application provide a DDL statement processing method and device, electronic equipment and storage medium, which greatly reduce the syntax parsing difficulty of the DDL statements and improve the parsing performance of the DDL statements.
[0005] The embodiment of the present application provides a processing method of a DDL statement, comprising the following steps: if a statement type of a to-be-processed DDL statement is a table creation type or a table modification type, extracting a first statement segment describing table structure information from the to-be-processed DDL statement; querying whether the first statement segment is included in at least one pre-cached parsed statement segment, the parsed statement segment being a statement segment describing table structure information extracted from an existing DDL statement which has completed syntax parsing; if the first statement segment is included in the at least one pre-cached parsed statement segment, obtaining a first optimization statement segment associated with the first statement segment pre-cached, the first optimization statement segment being used for indicating that existing table structure information obtained by syntax parsing of the first statement segment is reused in a syntax parsing stage; and replacing the first statement segment in the to-be-processed DDL statement with the first optimization statement segment to obtain a first optimization DDL statement.
[0006] The embodiment of the present application also provides a processing device of a DDL statement, comprising: an extraction module, used for extracting a first statement segment describing table structure information from a to-be-processed DDL statement if a statement type of the to-be-processed DDL statement is a table creation type or a table modification type; a querying module, used for querying whether the first statement segment is included in at least one pre-cached parsed statement segment, the parsed statement segment being a statement segment describing table structure information extracted from an existing DDL statement which has completed syntax parsing; an obtaining module, used for obtaining a first optimization statement segment associated with the first statement segment pre-cached if the first statement segment is included in the at least one pre-cached parsed statement segment, the first optimization statement segment being used for indicating that existing table structure information obtained by syntax parsing of the first statement segment is reused in a syntax parsing stage; and an optimization module, used for replacing the first statement segment in the to-be-processed DDL statement with the first optimization statement segment to obtain a first optimization DDL statement.
[0007] The embodiment of the present application also provides an electronic device, comprising: a memory and a processor; the memory is used for storing a computer program; and the processor is coupled to the memory and is used for executing the computer program to execute steps in the processing method of the DDL statement.
[0008] The embodiment of the present application also provides a computer readable storage medium storing a computer program, when the computer program is executed by a processor, the processor can implement steps in the processing method of the DDL statement.
[0009] In the embodiment of the present application, the optimized DDL statement is relatively shorter than the to-be-processed DDL statement before optimization. For the syntax analysis of the optimized DDL statement, only the statement segment related to the description of the library table name information is subjected to syntax analysis, and the existing table structure information is reused, thereby greatly reducing the syntax analysis difficulty of the DDL statement and improving the analysis performance of the DDL statement. Especially in the SaaS service scenario or the library-table separation scenario, a large number of DDL statements triggered in a short time can be effectively coped with, the syntax analysis performance of the DDL statement is greatly improved, and a basis is provided for the DTS to better concurrently process the DDL statement. BRIEF DESCRIPTION OF DRAWINGS
[0010] The accompanying drawings, which are included to provide a further understanding of the present application and are incorporated in and constitute a part of this application, illustrate embodiments of the present application and serve to explain the present application. In the drawings:
[0011] Figure 1 An exemplary application scenario diagram provided for the embodiment of the present application is shown in FIG. 1.
[0012] Figure 2 Another exemplary application scenario diagram provided for the embodiment of the present application is shown in FIG. 2.
[0013] Figure 3 A flowchart of a DDL statement processing method provided for the embodiment of the present application is shown in FIG. 3.
[0014] Figure 4 A flowchart of another DDL statement processing method provided for the embodiment of the present application is shown in FIG. 4.
[0015] Figure 5 A structural schematic diagram of a DDL statement processing apparatus provided for the embodiment of the present application is shown in FIG. 5.
[0016] Figure 6 A structural schematic diagram of an electronic device provided for the embodiment of the present application is shown in FIG. 6. DETAILED DESCRIPTION
[0017] To make the objectives, technical solutions and advantages of the present application clearer, the technical solutions of the present application will be described below in conjunction with the specific embodiments of the present application and the corresponding drawings. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the scope of protection of the present application.
[0018] In the embodiments of the present application, "at least one" means one or more, and "multiple" means two or more. "And / or" describes the access relationship between the associated objects, which means that there can be three relationships, for example, A and / or B can represent: A exists alone, A and B exist together, and B exists alone, of which A and B can be singular or plural. In the character description of the present application, the character " / " generally represents that the associated objects before and after it are in an "or" relationship. In addition, in the embodiments of the present application, "first", "second", "third" and the like are only to distinguish the contents of different objects, and have no other special meanings.
[0019] In practical applications, some CREATE statements or ALTER statements are more complex, and the syntax parsing difficulty also increases accordingly. Therefore, the embodiments of the present application provide a processing method and device of DDL statement, an electronic device and a storage medium. In the embodiments of the present application, the optimized DDL statement is relatively shorter than the to-be-processed DDL statement before optimization. For the syntax parsing of the optimized DDL statement, only the statement segment related to the description of the library table name information is parsed, and the existing table structure information is reused, which greatly reduces the syntax parsing difficulty of the DDL statement and improves the parsing performance of the DDL statement. Especially in the SaaS service scene or the library table separation scene, a large number of DDL statements triggered in a short time can be effectively coped with, the syntax parsing performance of the DDL statement is greatly improved, and the basis for better concurrent processing of the DDL statement by the DTS is provided.
[0020] Figure 1 An exemplary application scenario is provided for the embodiments of the present application. Referring to Figure 1The application scenario can include a source library, a data transmission service (DTS), and a target library. The source library or the target library can be a relational database or a non-relational database, and no longer limited. The data transmission service includes a pulling module, a data storage module, and a writing module. The pulling module is responsible for pulling source data for synchronization in the source library, and needs to parse a DDL statement when the DDL statement is pulled, and stores a syntax parsing result of the DDL statement locally. For example, information such as a library name, a table name, a column name, and a column type parsed from the DDL statement is stored as metadata locally. The source data pulled by the pulling module includes, but is not limited to, for example, a DDL statement, a DML (Data Manipulation Language) statement, and a DCL (Data Control Language) in the source library. The source data pulled by the pulling module is stored by the data storage module. The writing module is responsible for pulling data from the data storage module, and needs to parse a DDL statement when the DDL statement is pulled, and performs data filtering and mapping on a syntax parsing result of the DDL statement based on user configuration. The DDL statement is assembled based on a syntax rule of the target library to construct a new DDL statement. Finally, the writing module writes the pulled data and the new DDL statement to the target library.
[0021] It can be known from the above that the data transmission service involves parsing a DDL statement in the process of pulling data from a source library and writing data to a target library. The method provided in the embodiment of the application optimizes the DDL statement, so that the syntax parsing of the DDL statement can be performed efficiently, and thus the data transmission service can better perform data synchronization or data migration between the source library and the target library.
[0022] Figure 2 Another exemplary application scenario graph provided in the embodiment of the application is provided. Referring to Figure 2 The application scenario can include a source library, a data transmission service, and a target library. The data transmission service can include a DDL optimizer, a syntax parser, and an executor. Referring to Figure 2 If a user has a data synchronization or migration requirement, the user provides an original DDL statement for creating a database table to the data transmission service, as indicated by ① in Figure 2 The DDL optimizer optimizes the original DDL statement to obtain an optimized DDL statement, as indicated by ② in Figure 2 The DDL optimizer provides the optimized DDL statement to the syntax parser, as indicated by ③ in Figure 2 The syntax parser performs a syntax parsing operation on the optimized DDL statement, and only performs syntax parsing of a library table name and reuses existing table structure information in the syntax parsing process, as indicated by ④ inFigure 2 As shown in ⑤, the executor creates a new database table in the same library or different library based on the syntax analysis result. For example, the database table 1-2 in the source library is a synchronization table of the newly created database table 1-1. The database table 1-3 and the database table 1-4 in the target library are synchronization tables of the newly created database table 1-1 in the source library.
[0023] From the above, it can be seen that when the data transmission service performs syntax analysis based on the optimized DDL statement, only the syntax analysis of the library table name is performed, and the existing table structure information is reused, so that the syntax analysis of the table structure information is not needed again, the DDL statement parsing performance is greatly improved, and thus the data transmission service can better perform data synchronization or data migration in the same library or different library.
[0024] It should be noted that the above application scenarios are only exemplary, and the embodiments of the present application are not limited to specific application scenarios.
[0025] The technical solutions provided by the embodiments of the present application will be described in detail below with reference to the accompanying drawings.
[0026] Figure 3 A flowchart of a DDL statement processing method provided by an embodiment of the present application is shown in FIG. 3. As shown in FIG. 3, the method can include the following steps. Figure 3
[0027] 301. If the statement type of the to-be-processed DDL statement is a create table type or a modify table type, a first statement segment describing table structure information is extracted from the to-be-processed DDL statement.
[0028] 302. It is inquired whether the first statement segment is included in at least one pre-cached parsed statement segment.
[0029] 303. If the first statement segment is included in the at least one pre-cached parsed statement segment, a first optimized statement segment associated with the first statement segment is obtained, and the first optimized statement segment is used to indicate that the existing table structure information obtained by syntax analysis of the first statement segment is reused in the syntax analysis stage.
[0030] 304. The first statement segment in the to-be-processed DDL statement is replaced by the first optimized statement segment, and a first optimized DDL statement is obtained.
[0031] The method provided by the embodiment is suitable for optimizing the DDL statement of creating or modifying the table type, that is, the CREATE statement of creating the table type and the ALTER statement of modifying the table type. A CREATE statement or an ALTER statement usually consists of three statement segments. The statement segment at the head is used to describe the statement type of the DDL statement, the statement segment in the middle is used to describe the library table name, and the statement segment at the tail is used to describe the table structure information. The table structure information defines the column name, the column type, the constraint condition, the primary key, the foreign key and the index of a database table, and these basic attributes constitute the table structure information of the database table. Assuming that the CREATE statement of creating the table type is "CREATE TABLE DB_NAME.TB_NAME TALL", the CREATE statement is divided into "CREATE TABLE" statement segment, "DB_NAME.TB_NAME" statement segment and "TALL" statement segment in sequence. The "CREATE TABLE" statement segment at the head is used to describe that the statement type of the DDL statement is the table type, the "DB_NAME.TB_NAME" statement segment in the middle is used to describe the library table name (that is, the library name and the table name) of the database table to be created, and of course, the DB_NAME (library name) in the "DB_NAME.TB_NAME" statement segment in the middle can be omitted. The "TALL" statement segment at the tail is a relatively complex part in the entire CREATE statement, and the syntax analysis difficulty is the largest.
[0032] In actual application, the table structure information at the tail of some different DDL statements has the same corresponding statement fragment, and the only difference is the statement fragment corresponding to the library table name at the middle part. For example, the two DDL statements of CREATE TABLE `testDB1`.`testTB1`(f1 int, f2 varchar(100), f3 timestamp) and CREATE TABLE `testDB2`.`testTB2`(f1 int, f2 varchar(100), f3 timestamp) have the same statement fragment except the statement fragment describing the library table name. Based on this, when the statement fragment describing the table structure information is first appeared, the statement fragment describing the table structure information is parsed to obtain the corresponding table structure information, and the statement fragment describing the table structure information and the table structure information are associated and stored. When the statement fragment describing the table structure information appears again in a new DDL statement, the statement fragment describing the table structure information in the new DDL statement does not need to be parsed again when the new DDL statement is parsed, and the already parsed table structure information can be directly reused. Further, the syntax parsing difficulty of the new DDL statement is greatly reduced, and the parsing performance of the DDL statement is greatly improved.
[0033] Specifically, in order to facilitate understanding and distinction, the DDL statement which has not been parsed is referred to as a to-be-processed DDL statement. For the to-be-processed DDL statement, first, the type of the DDL statement is determined, and the type of the DDL statement includes, but is not limited to, a type for creating a database, a type for viewing a database, a type for selecting a database to be operated, a type for selecting a database to be operated, a type for viewing tables under a database, a type for deleting a database, a type for creating a table, and a type for modifying a table. Among them, the DDL statement for creating a database is “CREATE DATABASE dbname”, the DDL statement for viewing a database is “show databases”, the DDL statement for selecting a database to be operated is “USE dbname”, the DDL statement for viewing tables under a database is “show tables”, the DDL statement for deleting a database is “drop database dbname”, the DDL statement for creating a table is “CREATE TABLE tbname(col_name_1(column name) col_type_1(column type) constraints(constraints)”, and the DDL statement for modifying a table is “ALTER TABLE tbname(col_name_1(column name) col_type_1(column type) constraints(constraints)”.
[0034] Then, after confirming that the statement type of the to-be-processed DDL statement belongs to the table creation type or the table modification type, it is determined whether the statement segment describing the table structure information in the to-be-processed DDL statement has been parsed. For the convenience of understanding and distinguishing, the statement segment describing the table structure information in the to-be-processed DDL statement is referred to as the first statement segment. The first statement segment is extracted from the to-be-processed DDL statement, and it is queried whether the first statement segment is included in the at least one pre-cached parsed statement segment. The parsed statement segment refers to the statement segment describing the table structure information extracted from the existing DDL statement which has completed the syntax parsing. If the first statement segment is not found in the pre-cached parsed statement segment, it is indicated that there is no reusable syntax parsing result, and in this case, the to-be-processed DDL statement does not need to be optimized. In the subsequent syntax parsing stage, the syntax parsing is directly performed on each syntax segment in the to-be-processed DDL statement. This syntax parsing mode can be considered as complete syntax parsing of the DDL statement. Specifically, see step Figure 3 After step 302, the above method can further include the following steps:
[0035] 305. If the first statement segment is not included in the at least one pre-cached parsed statement segment, the second statement segment in the to-be-processed DDL statement is parsed in response to the syntax parsing request for the to-be-processed DDL statement, and the first database table name is obtained.
[0036] 306. The first statement segment in the to-be-processed DDL statement is parsed to obtain the table structure information corresponding to the first statement segment.
[0037] 307. A new optimized statement segment is allocated for the first statement segment, and the first statement segment is cached as a new parsed statement segment, and the optimized statement segment corresponding to the first statement segment and the table structure information are associated and cached.
[0038] In the case that the to-be-processed DDL statement does not have the existing table structure information that can be reused, in the syntax parsing stage, the to-be-processed DDL statement is parsed according to the conventional syntax parsing manner, that is, the second statement segment in the to-be-processed DDL statement that describes the library table name information needs to be parsed to obtain the corresponding library table name. For the purpose of understanding and distinguishing, the library table name parsed from the second statement segment is referred to as the first library table name. Meanwhile, the first statement segment in the to-be-processed DDL statement that describes the table structure information needs to be parsed to obtain the table structure information corresponding to the first statement segment. Thus, the syntax parsing task of the entire to-be-processed DDL statement is completed. Further, in order to enable the subsequent DDL statement including the first statement segment to reuse the table structure information corresponding to the first statement segment that has been parsed, to reduce the syntax parsing difficulty of the subsequent DDL statement, to assign a new optimized statement segment to the first statement segment, and to cache the first statement segment as a new parsed statement segment and associate the optimized statement segment and the table structure information corresponding to the first statement segment.
[0039] In practical applications, the first statement segment can be assigned a new optimized statement segment as needed. The optimized statement segment indicates that the existing table structure information obtained by parsing the first statement segment is reused in the syntax parsing stage. For example, the new optimized statement segment is "LIKE DUMMY". When "LIKE DUMMY" is parsed, it is indicated that the syntax parsing of the table structure information does not need to be performed again, and the existing table structure information is directly reused.
[0040] It is worth noting that the optimized statement segment should be designed to be as short as possible, and the fewer the characters, the better. The optimized statement segment does not need to include the specific content describing the table structure information, but only needs to indicate that the existing table structure information is reused. In practical applications, the optimized statement segment can be defined in the syntax file as the statement segment indicating that the existing table structure information is reused. Thus, in the syntax parsing stage, the definition of the optimized statement segment in the syntax file can be queried to know that the syntax parsing of the table structure information does not need to be performed again, and the existing table structure information is directly reused.
[0041] In the embodiment, if it is found that the first statement segment in the to-be-processed DDL statement is the pre-cached parsed statement segment, it is indicated that the syntax parsing result corresponding to the first statement segment that has been parsed can be reused, that is, the existing table structure information obtained by parsing the first statement segment is reused. At this time, the to-be-processed DDL statement can be optimized, and in the subsequent syntax parsing stage, the syntax parsing result of the first statement segment directly reuses the existing table structure information, and does not need to be parsed again. This syntax parsing manner can be regarded as a partial syntax parsing of the DDL statement.
[0042] Specifically, the DDL statement to be processed can be processed by using a sentence fragment replacement manner, that is, a first sentence fragment in the DDL statement to be processed is replaced by a first optimized sentence fragment pre-stored and associated with the first sentence fragment, and then an optimized DDL statement is obtained. For the convenience of understanding, the optimized DDL statement obtained by using the sentence fragment replacement manner is referred to as a first optimized DDL statement.
[0043] In the syntax analysis stage, in response to a syntax analysis request for the first optimized DDL statement, a second sentence fragment in the first optimized DDL statement describing the library table name information is analyzed to obtain a first library table name; and the first optimized sentence fragment in the first optimized DDL statement is used to obtain the existing table structure information corresponding to the first optimized sentence fragment from the existing table structure information corresponding to at least one pre-stored optimized sentence fragment.
[0044] Since the first sentence fragment and the corresponding optimized sentence fragment and existing table structure information have been pre-stored and syntax analyzed, the existing table structure information corresponding to the first optimized sentence fragment is obtained from the existing table structure information corresponding to at least one pre-stored optimized sentence fragment based on the first optimized sentence fragment.
[0045] In actual applications, the table structure information of a database table to be created or modified is relatively simple, and the number of characters of the sentence fragment describing the table structure information in the corresponding DDL statement is also relatively small. The parsing difficulty of such a DDL statement is not very large, and syntax optimization can also not be performed. Therefore, further optionally, after step 301 and before step 302, it can also be determined whether the number of characters of the first sentence fragment is greater than or equal to a first number, and if the number of characters of the first sentence fragment is greater than or equal to the first number, the step of querying whether the first sentence fragment is included in the at least one pre-stored analyzed sentence fragment is performed. If the number of characters of the first sentence fragment is less than the first number, the step of querying whether the first sentence fragment is included in the at least one pre-stored analyzed sentence fragment and subsequent steps are not performed.
[0046] Specifically, the first number is flexibly set according to actual application requirements. If the character number of the first statement fragment is greater than or equal to the first number, it indicates that the table structure information described by the first statement fragment is relatively complex, and the DDL statement to be processed in which the first statement fragment is located can be optimized. If the character number of the first statement fragment is less than the first number, it indicates that the table structure information described by the first statement fragment is relatively simple, and the DDL statement to be processed in which the first statement fragment is located can not be optimized, thereby ensuring better syntax analysis performance. Subsequently, in the syntax analysis stage, the DDL statement to be processed is directly subjected to syntax analysis, that is, both the syntax analysis of the library table name and the syntax analysis of the table structure information are performed, thereby ensuring better syntax analysis performance.
[0047] In actual application, the number of DDL statements to be processed in a short time can be more or less. For the case of more DDL statements, DDL statement optimization processing can be performed. For the case of less DDL statements, DDL statement optimization processing can not be performed. Therefore, further optionally, after step 301 and before step 302, it can also be: judging whether the number of DDL statements to be processed is greater than or equal to a second number; if the number of DDL statements to be processed is greater than or equal to the second number, performing the step of querying whether the first statement fragment is included in the at least one parsed statement fragment pre-cached. If the number of DDL statements to be processed is less than the second number, the step of querying whether the first statement fragment is included in the at least one parsed statement fragment pre-cached and subsequent steps are not performed.
[0048] Specifically, the second number is flexibly set according to actual application requirements. Since DDL statement optimization processing also consumes computing resources, in the case of less DDL statements, the DDL statement to be processed is directly subjected to syntax analysis, which can also ensure better syntax analysis performance. In the case of more DDL statements, the DDL statement is subjected to optimization processing to ensure better syntax analysis performance.
[0049] In actual application, the quantity of the DDL statements and the character quantity of the first statement segment can be combined to determine whether to perform the optimization processing on the DDL statements. Thus, in an optional implementation, after step 301 and before step 302, the following steps can also be included: determining whether the quantity of the DDL statements to be processed is greater than or equal to a second quantity; if the quantity of the DDL statements to be processed is greater than or equal to the second quantity, determining whether the character quantity of the first statement segment is greater than or equal to a first quantity; if the character quantity of the first statement segment is greater than or equal to the first quantity, performing the step of querying whether the first statement segment is included in the at least one parsed statement segment pre-cached. If the quantity of the DDL statements to be processed is less than the second quantity, or if the quantity of the DDL statements to be processed is less than the second quantity, the step of querying whether the first statement segment is included in the at least one parsed statement segment pre-cached and the subsequent steps are not performed.
[0050] The technical scheme provided by the embodiments of the present application is that the first optimized DDL statement is relatively shorter than the DDL statement to be processed before optimization, and for the syntax analysis of the first optimized DDL statement, only the statement segment related to the description of the library table name information is subjected to syntax analysis, and the existing table structure information is reused, which greatly reduces the syntax analysis difficulty of the DDL statement and improves the analysis performance of the DDL statement. Especially in the SaaS service scenario or the library and table separation scenario, a large number of DDL statements triggered in a short time can be effectively coped with, and the syntax analysis performance of the DDL statement is greatly improved, thereby providing a basis for the DTS to better concurrently process the DDL statements.
[0051] In actual application, when the DDL statement is optimized, the statement segment replacement manner can not be used, and the statement segment deletion manner can be used for optimization. Thus, in some optional embodiments, based on the embodiments shown in Figure 4 Figure 3 After step 302, the following steps can also be included:
[0052] 308. If the first statement segment is included in the at least one parsed statement segment pre-cached, the first statement segment in the DDL statement to be processed is deleted to obtain a second optimized DDL statement.
[0053] 309. An association relationship between the first statement segment and the second optimized DDL statement is established and stored, and the association relationship is used to assist in reusing the existing table structure information obtained by performing the syntax analysis on the first statement segment in the syntax analysis stage.
[0054] In the embodiment, the optimization DDL statement indicating that the statement piece describing the table structure information is deleted can be defined in the syntax file to reuse the existing table structure information. Thus, in the syntax analysis stage, the definition of the optimization DDL statement indicating that the statement piece describing the table structure information is deleted in the syntax file is inquired, and it is known that the syntax analysis of the table structure information is not needed to be performed again, and the existing table structure information is directly reused.
[0055] In the syntax analysis stage, the second library table name is obtained by performing syntax analysis on the second optimization DDL statement in response to a syntax analysis request for the second optimization DDL statement; the first statement piece associated with the second optimization DDL statement is obtained based on the association relationship; and the existing table structure information corresponding to the first statement piece is obtained from the existing table structure information corresponding to each of the at least one pre-cached analyzed statement piece.
[0056] Since the first statement piece and the existing table structure information corresponding to the first statement piece have been pre-cached and syntax analyzed, the existing table structure information corresponding to the first statement piece is obtained from the existing table structure information corresponding to each of the at least one pre-cached analyzed statement piece.
[0057] The second optimization DDL statement is shorter than the to-be-processed DDL statement before optimization, the syntax analysis of the second optimization DDL statement is only performed on the statement piece describing the library table name information, and the existing table structure information is reused, so that the syntax analysis difficulty of the DDL statement is greatly reduced, and the analysis performance of the DDL statement is improved. In particular, in the SaaS service scenario or the library and table separation scenario, a large number of DDL statements triggered in a short time can be effectively responded to, the syntax analysis performance of the DDL statement is greatly improved, and a basis for better concurrent processing of the DDL statement by the DTS is provided.
[0058] Figure 5 A structural schematic diagram of a DDL statement processing device provided in the embodiment is shown in FIG. 1. Figure 5 The device can include:
[0059] The extraction module 51 is configured to extract a first statement piece describing table structure information from the to-be-processed DDL statement if the statement type of the to-be-processed DDL statement is a create table type or a modify table type.
[0060] The query module 52 is configured to query whether the first statement piece is included in the at least one pre-cached analyzed statement piece, the analyzed statement piece being a statement piece describing table structure information extracted from an existing DDL statement that has been syntax analyzed.
[0061] The acquisition module 53 is configured to acquire a first optimized statement segment pre-stored and associated with the first statement segment if the first statement segment is included in the at least one pre-stored parsed statement segment, and the first optimized statement segment is used to indicate that the existing table structure information obtained by parsing the first statement segment in the syntax parsing stage is reused.
[0062] The optimization module 54 is configured to replace the first statement segment in the to-be-processed DDL statement with the first optimized statement segment to obtain a first optimized DDL statement.
[0063] Further, the device further includes a syntax parsing module 55 configured to, in response to a syntax parsing request for the first optimized DDL statement, parse a second statement segment in the first optimized DDL statement, which describes the library table name information, to obtain a first library table name, and acquire, from the existing table structure information corresponding to the at least one pre-stored optimized statement segment, the existing table structure information corresponding to the first optimized statement segment in the first optimized DDL statement.
[0064] Further, the syntax parsing module 55 is further configured to, if the first statement segment is not included in the at least one pre-stored parsed statement segment, parse the second statement segment in the to-be-processed DDL statement to obtain the first library table name in response to a syntax parsing request for the to-be-processed DDL statement, and parse the first statement segment in the to-be-processed DDL statement to obtain the table structure information corresponding to the first statement segment.
[0065] The device further includes a cache module 56 configured to allocate a new optimized statement segment for the first statement segment, cache the first statement segment as a new parsed statement segment, and associate the first statement segment with the optimized statement segment and the table structure information corresponding to the first statement segment.
[0066] Further, the device further includes a judgment module configured to judge whether the number of characters in the first statement segment is greater than or equal to a first number, and trigger the query module if the number of characters in the first statement segment is greater than or equal to the first number.
[0067] Further, the judgment module is configured to judge whether the number of to-be-processed DDL statements is greater than or equal to a second number, and trigger the query module if the number of to-be-processed DDL statements is greater than or equal to the second number.
[0068] Further, the judgment module is configured to, if the number of to-be-processed DDL statements is greater than or equal to the second number, judge whether the number of characters in the first statement segment is greater than or equal to the first number, and trigger the query module if the number of characters in the first statement segment is greater than or equal to the first number.
[0069] Further optionally, the optimization module 54 is further configured to, if the first statement segment is included in the at least one pre-cached parsed statement segment, delete the first statement segment in the DDL statement to be processed to obtain a second optimized DDL statement.
[0070] The apparatus further includes an association relationship establishing and storing module 57 configured to establish and store an association relationship between the first statement segment and the second optimized DDL statement, the association relationship being used to assist in reusing the existing table structure information obtained by parsing the first statement segment in the syntax parsing stage.
[0071] Further optionally, the syntax parsing module 55 is further configured to, in response to a syntax parsing request for the second optimized DDL statement, parse the second optimized DDL statement to obtain a second library table name; obtain the first statement segment associated with the second optimized DDL statement based on the association relationship; and obtain the existing table structure information corresponding to the first statement segment from the existing table structure information corresponding to each of the at least one pre-cached parsed statement segment.
[0072] Figure 5 The apparatus shown in the embodiments can perform the method shown in the embodiments Figure 3 or Figure 4 The implementation principles and technical effects of the method shown in the embodiments are not described again. For the apparatus shown in the embodiments Figure 5 The specific manners in which each module or unit of the apparatus shown in the embodiments performs operations have been described in detail in the embodiments related to the method, and will not be described in detail here.
[0073] It should be noted that the execution subject of each step of the method provided in the above embodiments can be the same device, or the method can also be executed by different devices as the execution subject. For example, the execution subject of steps 301 to 307 can be device A; for another example, the execution subject of steps 301 to 305 can be device A, and the execution subject of steps 306 and 307 can be device B; and so on.
[0074] In addition, in some of the processes described in the above embodiments and the accompanying drawings, a plurality of operations appearing in a specific order are included, but it should be clear that these operations can be executed in the order appearing in this document or in parallel. The serial numbers of the operations, such as 301, 302, etc., are only used to distinguish different operations, and the serial numbers themselves do not represent any execution order. In addition, these processes can include more or fewer operations, and the operations can be executed in sequence or in parallel. It should be noted that the descriptions of "first", "second", etc. in this document are used to distinguish different messages, devices, modules, etc., and do not represent the order of precedence. In addition, "first" and "second" are different types.
[0075] Figure 6A structural schematic diagram of an electronic device is provided in the embodiments of the present application. As shown in Figure 6 The electronic device includes a memory 61 and a processor 62.
[0076] The memory 61 is configured to store computer programs and can be configured to store various data to support operations on the computing platform. Examples of the data include instructions of any application program or method for operating on the computing platform, contact data, phonebook data, messages, pictures, videos, etc.
[0077] The memory 61 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as a static random-access memory (SRAM), an electrically erasable programmable read only memory (EEPROM), an erasable programmable read only memory (EPROM), a programmable read-only memory (PROM), a read-only memory (ROM), a magnetic memory, a flash memory, a magnetic disk or an optical disk.
[0078] The processor 62 is coupled to the memory 61 and is configured to execute the computer programs in the memory 61 to: if a statement type of a to-be-processed DDL statement is a create table type or a modify table type, extract a first statement segment describing table structure information from the to-be-processed DDL statement; query whether the first statement segment is included in at least one pre-cached parsed statement segment, the parsed statement segment being a statement segment describing table structure information extracted from an existing DDL statement that has completed syntax parsing; if the first statement segment is included in the at least one pre-cached parsed statement segment, obtain a first optimization statement segment pre-cached in association with the first statement segment, the first optimization statement segment being used to indicate that existing table structure information obtained by syntax parsing the first statement segment is reused in a syntax parsing stage; and replace the first statement segment in the to-be-processed DDL statement with the first optimization statement segment to obtain a first optimization DDL statement.
[0079] Further, as shown in Figure 6 The electronic device further includes a communication component 63, a display 64, a power supply component 65, an audio component 66 and other components. Figure 6 Only some components are shown in the figure, which does not mean that the electronic device only includes the components shown in the figure. In addition, Figure 6 Figure 6 The components in the dashed box are optional components, not mandatory components, and can be determined according to the product form of the electronic device. The electronic device in the embodiment can be implemented as a terminal device such as a desktop computer, a notebook computer, a smart phone, or an IOT (Internet of things) device, or a server device such as a general server, a cloud server, or a server array. Figure 6 The components in the dashed box are optional components, not mandatory components, and can be determined according to the product form of the electronic device. The electronic device in the embodiment can be implemented as a terminal device such as a desktop computer, a notebook computer, a smart phone, or an IOT (Internet of things) device, or a server device such as a general server, a cloud server, or a server array. Figure 6 The components in the dashed box are optional components, not mandatory components, and can be determined according to the product form of the electronic device. The electronic device in the embodiment can be implemented as a terminal device such as a desktop computer, a notebook computer, a smart phone, or an IOT (Internet of things) device, or a server device such as a general server, a cloud server, or a server array.
[0080] The detailed implementation process of the processor performing each action can refer to the related description in the foregoing method embodiment or device embodiment, which will not be described here.
[0081] Correspondingly, the embodiment of the application also provides a computer readable storage medium storing a computer program, which can implement each step that can be executed by the electronic device in the foregoing method embodiment when the computer program is executed.
[0082] Correspondingly, the embodiment of the application also provides a computer program product, which includes a computer program / instruction, and when the computer program / instruction is executed by a processor, the processor can implement each step that can be executed by the electronic device in the foregoing method embodiment.
[0083] The communication component is configured to facilitate wired or wireless communication between the device where the communication component is located and other devices. The device where the communication component is located can access a wireless network based on a communication standard, such as a WiFi, 2G, 3G, 4G / LTE, 5G, or the like, or a combination thereof. In an example embodiment, the communication component receives a broadcast signal or broadcast related information from an external broadcast management system via a broadcast channel. In an example embodiment, the communication component also includes a near field communication (NFC) module to facilitate short-range communication. For example, the NFC module can be implemented based on radio frequency identification (RFID) technology, infrared data association (IrDA) technology, ultra wide band (UWB) technology, Bluetooth (BT) technology, and other technologies.
[0084] The aforementioned display includes a screen, which may include a Liquid Crystal Display (LCD) and a touch panel (TP). If the screen includes a touch panel, the screen can be implemented as a touchscreen to receive input signals from the user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors can sense not only the boundaries of touch or swipe actions but also the duration and pressure associated with the touch or swipe operation.
[0085] The aforementioned power supply components provide power to various components within the device in which they reside. These power supply components may include a power management system, one or more power sources, and other components associated with generating, managing, and distributing power to the device in which they reside.
[0086] The aforementioned audio component can be configured to output and / or input audio signals. For example, the audio component includes a microphone (MIC) configured to receive external audio signals when the device containing the audio component is in an operating mode, such as call mode, recording mode, or voice recognition mode. The received audio signals can be further stored in memory or transmitted via a communication component. In some embodiments, the audio component also includes a speaker for outputting audio signals.
[0087] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-readable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0088] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0089] These computer program instructions can also be stored in a computer readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer readable memory produce an article of manufacture including instructions which implement the flow Figure 1 The flow or flows and / or blocks Figure 1 The flow or flows and / or blocks
[0090] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions that are executed on the computer or other programmable apparatus provide steps for implementing the flow Figure 1 The flow or flows and / or blocks Figure 1 The flow or flows and / or blocks
[0091] In one typical configuration, a computing device includes one or more processors (central processing units, CPUs), input / output interfaces, network interfaces, and memory.
[0092] The memory can include non-persistent memory and / or persistent memory, both of which can be in the form of a computer-readable medium, such as random access memory (RAM) or read only memory (ROM), for example. The memory is an example of computer-readable media.
[0093] Computer-readable media includes permanent and non-permanent, movable and non-movable media that can implement information storage by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassette, magnetic tape disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information accessible to a computing device. According to the definition herein, computer-readable media does not include transitory media such as modulated data signals and carriers.
[0094] It should also be noted that the terms "comprising", "containing", or any other variant thereof are intended to cover a non-exclusive inclusion, such that a process, method, article or apparatus that comprises a list of elements does not only include those elements, but can also include other elements not expressly listed or inherent to such process, method, article or apparatus. Without more limitations, the element defined by the statement "comprising a" does not exclude the presence of additional identical elements in the process, method, article or apparatus that includes the element.
[0095] The above is only an embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application can have various modifications and changes. Any modification, equivalent replacement, improvement, etc. within the spirit and principle of the present application shall be included in the scope of claims of the present application.
Claims
1. A method for processing DDL statements, characterized in that, include: If the statement type of the DDL statement to be processed is a table creation type or a table modification type, then extract the first statement fragment describing the table structure information from the DDL statement to be processed. Query whether the first statement fragment is included in at least one pre-cached parsed statement fragment, wherein the parsed statement fragment is a statement fragment containing description table structure information extracted from an existing DDL statement that has already completed syntax parsing; If the first statement fragment is included in at least one pre-cached parsed statement fragment, then the first optimized statement fragment associated with the first statement fragment is obtained from the pre-cached parsing, and the first optimized statement fragment is used to indicate the reuse of the existing table structure information obtained by parsing the first statement fragment during the syntax parsing stage. The first statement fragment in the DDL statement to be processed is replaced with the first optimized statement fragment to obtain the first optimized DDL statement.
2. The method according to claim 1, characterized in that, After obtaining the first optimized DDL statement, the following is also included: In response to the syntax parsing request for the first optimized DDL statement, the second statement segment describing the library table name information in the first optimized DDL statement is parsed to obtain the first library table name; And for the first optimized statement fragment in the first optimized DDL statement, obtain the existing table structure information corresponding to the first optimized statement fragment from the existing table structure information corresponding to at least one pre-cached optimized statement fragment.
3. The method according to claim 1, characterized in that, Also includes: If the first statement fragment is not included in at least one pre-cached parsed statement fragment, then in response to the syntax parsing request for the DDL statement to be processed, the second statement fragment describing the library table name information in the DDL statement to be processed is parsed to obtain the first library table name. And perform syntax parsing on the first statement fragment in the DDL statement to be processed to obtain the table structure information corresponding to the first statement fragment; Assign a new optimized statement fragment to the first statement fragment, cache the first statement fragment as a new parsed statement fragment, and associate the cache with the optimized statement fragment and table structure information corresponding to the first statement fragment.
4. The method according to any one of claims 1 to 3, characterized in that, Before querying whether the first statement fragment is included in at least one pre-cached parsed statement fragment, the process also includes: Determine whether the number of characters in the first statement fragment is greater than or equal to the first number; If the number of characters in the first statement fragment is greater than or equal to the first number, then the step of querying whether at least one pre-cached parsed statement fragment includes the first statement fragment is performed.
5. The method according to any one of claims 1 to 3, characterized in that, Before querying whether the first statement fragment is included in at least one pre-cached parsed statement fragment, the process also includes: Determine whether the number of DDL statements to be processed is greater than or equal to the second number; If the number of DDL statements to be processed is greater than or equal to the second number, then the step of checking whether the first statement fragment is included in at least one parsed statement fragment pre-cached is performed.
6. The method according to claim 5, characterized in that, Also includes: If the number of DDL statements to be processed is greater than or equal to the second number, then it is determined whether the number of characters in the first statement fragment is greater than or equal to the first number. If the number of characters in the first statement fragment is greater than or equal to the first number, then the step of querying whether at least one pre-cached parsed statement fragment includes the first statement fragment is performed.
7. The method according to claim 1, characterized in that, After checking whether the first statement fragment is included in at least one pre-cached parsed statement fragment, the process also includes: If the first statement fragment is included in at least one pre-cached parsed statement fragment, then the first statement fragment in the DDL statement to be processed is deleted to obtain the second optimized DDL statement. In addition, the association between the first statement fragment and the second optimized DDL statement is established and stored. The association is used to assist in reusing the existing table structure information obtained by parsing the first statement fragment during the syntax parsing stage.
8. The method according to claim 7, characterized in that, Also includes: In response to the syntax parsing request for the second optimized DDL statement, the second optimized DDL statement is parsed to obtain the second database table name; Based on the aforementioned association, obtain the first statement fragment associated with the second optimized DDL statement; Obtain the existing table structure information corresponding to the first statement fragment from the existing table structure information corresponding to at least one pre-cached parsed statement fragment.
9. A DDL statement processing apparatus, characterized in that, include: The extraction module is used to extract a first statement fragment describing the table structure information from the DDL statement to be processed if the statement type of the DDL statement to be processed is a table creation type or a table modification type. The query module is used to query whether the first statement fragment is included in at least one pre-cached parsed statement fragment, wherein the parsed statement fragment is a statement fragment containing description table structure information extracted from an existing DDL statement that has already completed syntax parsing. The acquisition module is configured to acquire a first optimized statement fragment associated with the first statement fragment if at least one pre-cached parsed statement fragment includes the first statement fragment. The first optimized statement fragment is used to indicate the reuse of existing table structure information obtained by parsing the first statement fragment during the syntax parsing stage. An optimization module is used to replace the first statement fragment in the DDL statement to be processed with the first optimized statement fragment to obtain a first optimized DDL statement.
10. The apparatus according to claim 9, characterized in that, Also includes: Establish a storage module; The optimization module is further configured to delete the first statement fragment in the DDL statement to be processed if at least one parsed statement fragment pre-cached includes the first statement fragment, thereby obtaining a second optimized DDL statement. The establishment storage module is used to establish and store the association between the first statement fragment and the second optimized DDL statement. The association is used to assist in reusing the existing table structure information obtained by parsing the first statement fragment during the syntax parsing stage.
11. An electronic device, characterized in that, include: Memory and processor; The memory is used to store computer programs; The processor is coupled to the memory for executing the computer program to perform the steps of the method according to any one of claims 1-8.
12. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it causes the processor to perform the steps of the method according to any one of claims 1-8.
Citation Information
Patent Citations
Information processing method, device and equipment and computer readable storage medium
CN110069489A
Query statement optimization method and device
CN112559554A