A SQL grammar parsing performance benchmarking method and device based on antlr4

Through the SQL syntax parsing performance benchmark test method based on antlr4, the SQL syntax parsing process is simplified, the antlr4 syntax file encoding is optimized, the problem of high developer capability requirements and hot start caching is solved, and the effect of quickly obtaining and comparing performance data is achieved. .

CN118377692BActive Publication Date: 2024-10-15杭州玳数科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410832988.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-26
Publication Date
2024-10-15
Estimated Expiration
2044-06-26

AI Technical Summary

Technical Problem

In big data development, syntax parsing to support different SQL languages ​​is a heavy workload and requires high developer capabilities. Moreover, there is a cache problem caused by hot start after antlr4 is executed, which affects the reference value of performance data for multiple executions.

Method used

Provide a SQL syntax parsing performance benchmark test method based on antlr4. Compile the antlr4 g4 format source file of SQL through antlr4ts, encapsulate the Parser class, prepare SQL test cases, and write benchmark scripts to test with the SQLBenchmark class, and clear the require cache to ensure After each cold start, record and compare performance data.

Benefits of technology

It simplifies the SQL syntax parsing process, quickly obtains performance data, optimizes the encoding of antlr4 syntax files, solves the problem of hot start caching, makes performance data valuable for reference, and can quickly detect performance changes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118377692B_ABST
    Figure CN118377692B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of big data development, solves the problems of large workload of SQL syntax parsing and high requirements on developer ability in the prior art in big data development, and discloses a SQL syntax parsing performance benchmarking method and device based on antlr4. The method comprises: compiling an antlr4 syntax source file of SQL into a syntax parser file that can be run on a node through antlr4ts, writing a corresponding SQLParser class and encapsulating syntax verification, syntax analysis and other methods, writing a benchmarking script, performing performance testing on the methods in the SQL class, recording the syntax parsing speed performance for different types of DDL, DML, DQL statements and different SQL line numbers, so as to continuously optimize the actual performance of the antlr4 file of the SQL. The method realizes the performance benchmarking of SQL syntax parsing, can timely discover the influence of changes to the antlr4 syntax file or changes within the system on the actual SQL parsing performance, thereby improving the performance of SQL syntax parsing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of big data development technology, and in particular to a SQL grammar parsing performance benchmarking method and device based on antlr4. Background Art

[0002] SQL, the full name of which is Structured Query Language, is a special-purpose programming language specifically used to manage relational database systems. SQL is a database query and programming language used to access data and query, update, and manage relational database systems. Usually, a program programmed with SQL has multiple SQL statements, and executing multiple SQL statements in a set order will achieve a specific data query function.

[0003] Under the Internet wave of big data, more and more SQL languages ​​have emerged, and the syntax of different SQL languages ​​is also different. In big data development, syntax support for different SQL languages ​​is required, such as reporting errors for incorrect SQL statements and completing the syntax of some SQL statements. However, the workload of supporting the syntax of a SQL language is huge. Supporting the syntax of a language through antlr4 is a generally reliable implementation method. Writing syntax files through antlr4 syntax has great requirements on the developer's ability. If the syntax file is written with inappropriate nesting and writing style, it will have a great performance impact on syntax parsing. Summary of the invention

[0004] The purpose of this application is to overcome the problems of large SQL grammar parsing workload and high developer capability requirements in the prior art in big data development, and to provide a SQL grammar parsing performance benchmarking method and device based on antlr4.

[0005] In a first aspect, a SQL grammar parsing performance benchmarking method based on antlr4 is provided, comprising:

[0006] Use antlr4ts to compile all SQL antlr4 g4 format source files and output parser files that can be run on the node side, such as .ts and .js format files, and identify the SQL language corresponding to each parser file in a certain storage path format;

[0007] According to the syntax parser file, the Parser class corresponding to SQL is encapsulated, wherein the Parser class includes a syntax checking method and an SQL segmentation method, that is, the Parser class corresponding to SQL is encapsulated for each syntax parser file, the Parser class realizes the conversion of SQL text input stream to antlr4 Token input stream, and encapsulates methods including syntax checking, SQL segmentation, syntax prompting, etc., so as to simplify the syntax parsing process;

[0008] Prepare corresponding SQL test cases according to different SQL types, classify and archive each SQL language in a folder naming manner, and prepare corresponding SQL files as test case input streams;

[0009] Obtaining benchmark test configuration information and SQL test cases by writing a benchmark test script, wherein the benchmark test configuration information includes at least one of the following: a tested SQL language type, an excluded SQL language type, a path of the SQL to be tested, a method in a Parser class to be tested, a test number, and a test name;

[0010] Based on the benchmark test configuration information and SQL test cases, a SQLBenchmark class for benchmark test is written and benchmark test is performed, wherein the SQLBenchmark class includes running the method to be tested of the Parser class, outputting a terminal report and saving the test results.

[0011] In some possible implementations, the output of the parser file that can be run on the node side includes:

[0012] Obtain all SQL type antlr4 g4 format source files, wherein the antlr4 g4 format source files include lexical files and grammar files;

[0013] The lexical file and the grammar file are compiled through the antlr4ts command line, and the compilation results are output and saved.

[0014] In some possible implementations, encapsulating the Parser class corresponding to SQL according to the syntax parser file includes: introducing the syntax parser file and encapsulating syntax parsing related methods, wherein the syntax parsing related methods include a syntax checking method and an SQL segmentation method.

[0015] In some possible implementations, corresponding SQL file test cases are prepared according to different SQL types, including: naming folders according to SQL types, and naming each test case file in a preset standardized format.

[0016] In some possible implementations, a SQLBenchmark class for performing a benchmark test is written based on the benchmark test configuration information, SQL test cases, and historical test results, including:

[0017] Receive the SQL language type in the constructor and save it in the class instance;

[0018] Provide the run method to run the methods in the Parser class and record the running information;

[0019] Provide the printResults method to output the results of each run method to the terminal;

[0020] Provide saveResults method to save the final test results locally;

[0021] Read the last test result and compare it with the current test result and optimize the antlr4 g4 format source file.

[0022] Optionally, write a startup script to query and obtain the SQL language type that needs to be benchmarked in the terminal, create a subprocess to run the benchmark script and pass the SQL language type as a parameter;

[0023] In the benchmark script, according to the received SQL language type, the benchmark configuration information is read, a SQLBenchmark class corresponding to the SQL language is instantiated, and various required test parameters are passed to various methods of the SQLBenchmark class instance for operation;

[0024] The SQLBenchmark class is used to process and run benchmark tests. The SQLBenchmark class includes getSQLParser (get the SQL Parser class according to the SQL language type), run (run the Parser class method to be tested corresponding to the SQL language), printResults (method for terminal report output), saveResults (method for saving test benchmark results), etc.

[0025] When getting the Parser class in the getSQLParser method, since the classes exported in the compiled executable ts file (i.e. the syntax parser file that can be run on the node side) are all subclasses of antlr4, the ATN cache mechanism of antlr4 will cache the parsing information in the static variables of the parent class for each run, so that different Parser classes will affect each other when they run in succession, resulting in the final result having no reference value. Therefore, in the getSQLParser method, it is necessary to introduce the Parser class through the form of requrie dynamic import, and clear the relevant module cache stored in require.cache before importing, so as to ensure that the test is run in the form of cold start each time;

[0026] When executing the run method, insert performance.now() before and after the method to be tested to obtain the actual time spent on the method to be tested, read the previously saved local benchmark report information, parse and filter to obtain the time spent on the last run of the method to be tested, and save these key indicators in the class instance variables;

[0027] Finally, the results are printed in the terminal and the user is asked whether to save the benchmark results.

[0028] If the selected SQL language type is all SQL languages, the execution time data of each SQL language corresponding to each test case will be output at the end to compare the differences in syntax parsing performance of different SQL languages.

[0029] In some possible implementations, the benchmark test includes: instantiating a SQLBenchmark class corresponding to the SQL language type, reading the benchmark test configuration information, passing the benchmark test configuration information to an instance of the SQLBenchmark class and running a run method to perform a benchmark test, wherein in the run method, a Parser class corresponding to the SQL language is introduced in the form of require dynamic import, the require cache is cleared before the corresponding Parser class is introduced, the corresponding method is executed according to the benchmark test configuration information and the timestamps before and after the execution are recorded to obtain the time spent on this execution, the last test result is read to obtain the time spent on the last execution, and the time spent on this execution and the time spent on the last execution are saved in the SQLBenchmark class.

[0030] In a second aspect, a SQL grammar parsing performance benchmark test device based on antlr4 is provided, comprising:

[0031] Compilation module, used to compile all SQL antlr4 g4 format source files using antlr4ts and output syntax parser files that can be run on the node side;

[0032] An encapsulation module, used to encapsulate the Parser class corresponding to the SQL according to the grammar parser file, wherein the Parser class includes a grammar checking method and an SQL segmentation method;

[0033] Preparation module, used to prepare corresponding SQL test cases for different SQL types;

[0034] The acquisition module is used to obtain benchmark test configuration information and SQL test cases by writing benchmark test scripts;

[0035] The test module is used to write a SQLBenchmark class for benchmark testing based on the benchmark test configuration information and SQL test cases and perform benchmark testing, wherein the SQLBenchmark class includes running the Parser class method to be tested, outputting a terminal report, and saving test results.

[0036] In a third aspect, a computer-readable storage medium is provided, wherein the computer-readable medium stores a program code for execution by a device, wherein the program code includes steps for executing the method in any one of the implementations of the first aspect described above.

[0037] In a fourth aspect, an electronic device is provided, comprising a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction, when executed by the processor, implements a method as in any one of the implementations in the first aspect above.

[0038] The present application has the following beneficial effects: the present application can obtain the performance data of SQL grammar parsing more conveniently and quickly, so as to continuously optimize the antlr4 grammar file encoding; secondly, it solves the problem of cache caused by hot start after antlr4 is executed once, so that the performance data of grammar parsing executed multiple times at the same time has actual reference value; in addition, the present application adds the comparison information of the last runtime, so that the performance change can be quickly perceived after the antlr4 grammar file is modified. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] The drawings constituting a part of the present application are used to provide a further understanding of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application.

[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0041] Figure 1 It is a flowchart of the SQL grammar parsing performance benchmarking method based on antlr4 in Example 1 of the present application;

[0042] Figure 2 It is a structural block diagram of an antlr4-based SQL grammar parsing performance benchmark test device according to Embodiment 2 of the present application;

[0043] Figure 3 It is a schematic diagram of the internal structure of the electronic device of Example 4 of the present application.

[0044] Reference numerals:

[0045] 100, compilation module; 200, packaging module; 300, preparation module; 400, acquisition module; 500, testing module. DETAILED DESCRIPTION

[0046] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments 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 creative work are within the scope of protection of the present invention.

[0047] Example 1

[0048] The embodiment 1 of the present application involves an antlr4-based SQL grammar parsing performance benchmark test method, comprising: using antlr4ts to compile all SQL antlr4 g4 format source files and outputting a grammar parser file executable on the node end; encapsulating a Parser class corresponding to the SQL according to the grammar parser file, wherein the Parser class includes a grammar verification method and an SQL segmentation method; preparing corresponding SQL test cases according to different SQL types; obtaining benchmark test configuration information and SQL test cases by writing a benchmark test script; writing a SQLBenchmark class for benchmarking based on the benchmark test configuration information and the SQL test case and performing a benchmark test, recording grammar parsing speed performance for different types of DDL, DML, DQL statements and different SQL line number scales, to continuously optimize the actual performance of the antlr4 file of the SQL, and finally the terminal outputs the result of this benchmark test, and stores the result in a markdown file for benchmark comparison next time, the method can more conveniently and quickly obtain the performance data of SQL grammar parsing, so as to continuously optimize the antlr4 grammar file encoding.

[0049] Specifically, Figure 1 A flowchart of an antlr4-based SQL grammar parsing performance benchmarking method in application embodiment 1 is shown, including:

[0050] S100. Use the antlr4ts command to compile all SQL source files in antlr4 g4 format and output them to a specified directory, wherein the source files in antlr4 g4 format include the lexical file MySQLLexer.g4 and the grammar file MySQLParser.g4, for example: compile / grammar / mySQL / MySQLParser.g4 to / lib / mySQL / MySQLParser.ts.

[0051] S200. Create a new Parser class file for each SQL language in the / parser / folder. The Parser class file is named according to the SQL language type. For example, the Parser class file is named mySQL.ts.

[0052] Specifically, taking mySQL as an example, write a Parser class and simply implement a syntax validation method validate. The code example is as follows:

[0053] validate(SQL: string) {

[0054] const chars = new antlr4.InputStream(SQL);

[0055] const lexer = new MySQLLexer(chars);

[0056] const tokens = new antlr4.CommonTokenStream(lexer);

[0057] const parser = new MySQLParser(tokens);

[0058] let hasError = false;

[0059] parser.addErrorListener(new ErrorListener(err =>hasError = true));

[0060] parser.program();

[0061] return hasError;

[0062] }.

[0063] S300. Prepare corresponding SQL test cases according to different SQL types, and create a new / data / folder to store SQL test cases. Since different SQL languages ​​have different syntaxes, different SQL statements need to be benchmarked separately. For example, SQL files are stored in the path format of / data / {mySQL} / create.SQL.

[0064] S400, obtain benchmark test configuration information and SQL test cases by writing a benchmark test script, use an object to store the benchmark test configuration information, the benchmark test configuration information includes the benchmark test name, SQL file name, methods in the Parser class to be tested, test times, excluded SQL languages, tested SQL language types, etc., the benchmark test configuration information example is as follows:

[0065] const testFiles: TestFile[] = [

[0066] {

[0067] name: 'Query Collection (100 Rows)',

[0068] path: 'select.SQL',

[0069] loopTimes: 3,

[0070] testTypes: ['validate', 'getAllTokens'],

[0071] excludes: ['pgSQL', 'mySQL'],

[0072] includes: ['sparkSQL']

[0073] },

[0074] {

[0075] name: 'Create Table (100 Rows)',

[0076] path: 'create.SQL',

[0077] loopTimes: 3,

[0078] testTypes: ['validate'],

[0079] excludes: ['pgSQL', 'mySQL'],

[0080] },

[0081] ].

[0082] S500. Write a node startup script, use the prompt method in inquirer to inquire the SQL language type that needs to be benchmarked in the terminal, and after obtaining the SQL language type, use spawn in child_process to start a child process to run the benchmark script and pass the parameter lang (i.e., language abbreviation).

[0083] In the benchmark script, the SQL language type parameter lang is received, and the SQL input stream is read according to the SQL file to be tested in the configuration file. A SQLBenchmark class is instantiated according to the current SQL language type, and the benchmark test is started according to the configuration information such as loopTimes and testTypes in the configuration file.

[0084] In the SQLBenchmark class, lang is received as a constructor parameter and saved in the language instance attribute. To start executing the benchmark, you also need to get an instance of the Parser class corresponding to the SQL language.

[0085] Encapsulate a getSQLParser method. Before instantiating the Parser class, you need to clear the module cache related to antlr4, and obtain the storage path of the Parser class file according to the language and dynamically import it for instantiation. The code example is as follows:

[0086] getSQLParser(){

[0087] const caches = Object.keys(require.cache);

[0088] const cacheModules = [

[0089] path.join(__dirname, ` / parser / ${this.language}.ts`),

[0090] path.join(__dirname, ` / lib / ${this.language} / `),

[0091] path.normalize(require.resolve('antlr4ts')), ];

[0093] caches

[0094] .filter((moduleName) =>

[0095] cacheModules.some((cacheModuleName)=>moduleName.includes(cacheModuleName)) )

[0097] .forEach((moduleName) =>delete require.cache[moduleName]);

[0098] const Parser = require(path.join(__dirname, ` / parser / ${this.language}.ts`)).default;

[0099] return new Parser();

[0100] }.

[0101] The run method receives parameters such as the name of the method to be tested, the test SQL, and the number of loops. The method to be tested will be executed N times according to the number of loops N. Finally, the average value is taken as a reference value, and the last report result is obtained for comparison. The simplified code is as follows:

[0102] run(name, type, SQL, loopTimes) {

[0103] const costTimes = [];

[0104] / / Get the average time spent on the last test item

[0105] const lastCostTime = this.getLastCostTime(name, type);

[0106] for (let i = 0; i <loopTimes; i++) {

[0107] const parser = this.getSQLParser();

[0108] if (!parser[type] || typeof parser[type]!== 'function')return;

[0109] const startTime = performance.now();

[0110] parser[type](SQL);

[0111] const costTime = performance.now() - startTime;

[0112] costTimes.push(Math.round(costTime));

[0113] }

[0114] / / Save relevant data

[0115] }.

[0116] After executing all test cases, the benchmark report information is output in the terminal in a table format, including SQL language type, benchmark name, average execution time, last recorded execution time, total execution time, number of loops, etc. If you choose to benchmark all SQL language types at the beginning, the performance data of different SQLs for each test case will be output in the dimension of SQL language type.

[0117] Save the benchmark report to / reports / {mySQL}.benchmark.markdown, including the report generation time, SQL language type, test device information, current dependency package version information (such as antrl4, antlr4ts), and table summary information. In addition, you need to insert an input tag in HTML at the end and use a hidden field type to save the JSON data of the test result for easy comparison next time.

[0118] In this embodiment, the antlr4 grammar source file and the encapsulated Parser class can be continuously optimized through the performance benchmark test report, thereby improving the SQL grammar parsing performance.

[0119] Example 2

[0120] like Figure 2 As shown, an antlr4-based SQL grammar parsing performance benchmark testing device involved in Embodiment 2 of the present application includes:

[0121] The compiling module 100 is used to compile all SQL source files in antlr4 g4 format using antlr4ts and output a syntax parser file that can be run on the node end;

[0122] The encapsulation module 200 is used to encapsulate the Parser class corresponding to the SQL according to the grammar parser file, wherein the Parser class includes a grammar checking method and an SQL segmentation method;

[0123] Preparation module 300, used to prepare corresponding SQL test cases for different SQL types;

[0124] An acquisition module 400 is used to acquire benchmark test configuration information and SQL test cases by writing a benchmark test script;

[0125] The test module 500 is used to write a SQLBenchmark class for benchmark testing based on the benchmark test configuration information and SQL test cases and perform benchmark testing, wherein the SQLBenchmark class includes running the Parser class method to be tested, outputting a terminal report, and saving test results.

[0126] It should be noted that for other specific implementations of the SQL grammar parsing performance benchmark testing device based on antlr4 in the embodiment of the present invention, reference can be made to the specific implementation of the SQL grammar parsing performance benchmark testing method based on antlr4 mentioned above. To avoid redundancy, they will not be repeated here.

[0127] Example 3

[0128] A computer-readable storage medium according to Embodiment 3 of the present application, wherein the computer-readable storage medium stores a program code for execution by a device, wherein the program code includes steps for executing a method in any one of the implementations in Embodiment 1 of the present application;

[0129] Among them, the computer-readable storage medium can be a read-only memory (ROM), a static storage device, a dynamic storage device or a random access memory (RAM); the computer-readable storage medium can store program code, and when the program stored in the computer-readable storage medium is executed by the processor, the processor is used to execute the steps of the method in any one of the implementation methods in Example 1 of the present application.

[0130] Example 4

[0131] like Figure 3 As shown, an electronic device involved in Embodiment 4 of the present application includes a processor, a memory, and a program or instruction stored in the memory and executable on the processor, and when the program or instruction is executed by the processor, a method in any one of the implementations in Embodiment 1 of the present application is implemented;

[0132] Among them, the processor can adopt a general-purpose central processing unit (CPU), a microprocessor, an application specific integrated circuit (ASIC), a graphics processing unit (GPU) or one or more integrated circuits to execute relevant programs to implement the method in any one of the implementation methods in Example 1 of the present application.

[0133] The processor may also be an integrated circuit electronic device with signal processing capability. In the implementation process, each step of the method in any implementation of Embodiment 1 of the present application may be completed by an integrated logic circuit of hardware in the processor or by instructions in software form.

[0134] The above-mentioned processor may also be a general-purpose processor, a digital signal processor, an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present application may be implemented or executed. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application may be directly embodied as being executed by a hardware decoding processor, or may be executed by a combination of hardware and software modules in a decoding processor. The software module may be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in a memory, and the processor reads the information in the memory, and completes the functions required to be performed by the unit included in the data processing device of the embodiment of the present application in combination with its hardware, or executes the method in any one of the implementation modes in the embodiment 1 of the present application.

[0135] The above are only preferred specific implementations of the present application; however, the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can make equivalent replacements or changes according to the technical solution and its improved ideas of the present application within the technical scope disclosed in the present application, which should be included in the protection scope of the present application.

Claims

1. A SQL grammar parsing performance benchmarking method based on antlr4, It is characterized in that include: Use antlr4ts to compile all SQL antlr4 g4 format source files and output a syntax parser file that can be run on the node side; Encapsulate the Parser class corresponding to SQL according to the syntax parser file, wherein the Parser class includes a syntax checking method and an SQL segmentation method; Prepare corresponding SQL test cases according to different SQL types; Obtaining benchmark test configuration information and SQL test cases by writing a benchmark test script, wherein the benchmark test configuration information includes at least one of the following: a tested SQL language type, an excluded SQL language type, a path of the SQL to be tested, a method in a Parser class to be tested, a test number, and a test name; Based on the benchmark test configuration information and the SQL test case, a SQLBenchmark class for benchmark test is written and the benchmark test is performed, wherein the SQLBenchmark class includes running the method to be tested of the Parser class, outputting a terminal report and saving the test results; Wherein, based on the benchmark test configuration information, SQL test cases and historical test results, a SQLBenchmark class for benchmark testing is written, specifically including: Receive the SQL language type in the constructor and save it in the class instance; Provide the run method to run the methods in the Parser class and record the running information; Provide the printResults method to output the results of each run method to the terminal; Provide saveResults method to save the final test results locally; Read the last test result and compare it with the current test result and optimize the antlr4 g4 format source file; The benchmark test includes: instantiating a SQLBenchmark class corresponding to an SQL language type, reading the benchmark test configuration information, passing the benchmark test configuration information to an instance of the SQLBenchmark class and running a run method to perform a benchmark test, wherein in the run method, a Parser class corresponding to the SQL language is introduced in the form of require dynamic import, the require cache is cleared before the corresponding Parser class is introduced, the corresponding method is executed according to the benchmark test configuration information and the timestamps before and after the execution are recorded to obtain the time spent on this execution, the last test result is read to obtain the time spent on the last execution, and the time spent on this execution and the time spent on the last execution are saved in the SQLBenchmark class.

2. The SQL grammar parsing performance benchmarking method based on antlr4 according to claim 1, It is characterized in that Output the parser file that can be run on the node side, including: Obtain all SQL type antlr4 g4 format source files, wherein the antlr4 g4 format source files include lexical files and grammar files; The lexical file and the grammar file are compiled through the antlr4ts command line, and the compilation results are output and saved.

3. The SQL grammar parsing performance benchmarking method based on antlr4 according to claim 1, It is characterized in that Encapsulating the Parser class corresponding to SQL according to the syntax parser file includes: introducing the syntax parser file and encapsulating syntax parsing related methods, wherein the syntax parsing related methods include a syntax checking method and an SQL segmentation method.

4. The SQL grammar parsing performance benchmarking method based on antlr4 according to claim 1, It is characterized in that Prepare corresponding SQL file test cases according to different SQL types, including: distinguish and name folders according to SQL types, and name each test case file in a preset standardized format.

5. A SQL grammar parsing performance benchmark test device based on antlr4, It is characterized in that include: Compilation module, used to compile all SQL antlr4 g4 format source files using antlr4ts and output syntax parser files that can be run on the node side; An encapsulation module, used to encapsulate the Parser class corresponding to the SQL according to the syntax parser file, wherein the Parser class includes a syntax checking method and an SQL segmentation method; Preparation module, used to prepare corresponding SQL test cases for different SQL types; An acquisition module is used to acquire benchmark test configuration information and SQL test cases by writing a benchmark test script, wherein the benchmark test configuration information includes at least one of the following: a tested SQL language type, an excluded SQL language type, a path of the SQL to be tested, a method in a Parser class to be tested, a test number, and a test name; A test module, used to write a SQLBenchmark class for benchmark testing based on the benchmark test configuration information and SQL test cases and perform benchmark testing, wherein the SQLBenchmark class includes running the Parser class method to be tested, outputting a terminal report, and saving test results; Wherein, based on the benchmark test configuration information, SQL test cases and historical test results, a SQLBenchmark class for benchmark testing is written, specifically including: Receive the SQL language type in the constructor and save it in the class instance; Provide the run method to run the methods in the Parser class and record the running information; Provide the printResults method to output the results of each run method to the terminal; Provide saveResults method to save the final test results locally; Read the last test result and compare it with the current test result and optimize the antlr4 g4 format source file; The benchmark test includes: instantiating a SQLBenchmark class corresponding to an SQL language type, reading the benchmark test configuration information, passing the benchmark test configuration information to an instance of the SQLBenchmark class and running a run method to perform a benchmark test, wherein in the run method, a Parser class corresponding to the SQL language is introduced in the form of require dynamic import, the require cache is cleared before the corresponding Parser class is introduced, the corresponding method is executed according to the benchmark test configuration information and the timestamps before and after the execution are recorded to obtain the time spent on this execution, the last test result is read to obtain the time spent on the last execution, and the time spent on this execution and the time spent on the last execution are saved in the SQLBenchmark class.

6. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a program code for execution by a device, wherein the program code includes steps for executing the method according to any one of claims 1 to 4.

7. An electronic device, It is characterized in that The electronic device includes a processor, a memory, and a program or instruction stored in the memory and executable on the processor, wherein the program or instruction implements the method according to any one of claims 1 to 4 when executed by the processor.