A structured query language processing method, device, equipment and medium

By understanding the semantic intentions and reasoning of large language model of user input information, automatically analyzing and optimizing slow SQL, the inefficiency and high cost problems caused by relying on professional knowledge in the existing technology are solved, and fast response and efficient optimization are achieved.

CN118796869BActive Publication Date: 2025-02-07HUNDSUN CLOUD FINANCING NETWORK TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411286572.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-09-13
Publication Date
2025-02-07
Estimated Expiration
2044-09-13

AI Technical Summary

Technical Problem

The prior art relies on expertise in analyzing and optimizing slow SQL, resulting in low processing efficiency and high cost, and strong dependence on user expertise.

Method used

By obtaining user input information, analyzing and assembling the initial input data, using the trained large language model for semantic meaning understanding, extracting table names and table information, assembling table information input data, and using the large language model for inference to generate the final processing Suggestions and solutions.

Benefits of technology

It realizes the analysis and optimization of slow SQL in a very short time, reduces the dependence on professional DBAs, reduces the dependence on expensive optimization tools and professionals, reduces the cost of labor and tooling, and improves processing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118796869B_ABST
    Figure CN118796869B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device, equipment and medium for processing structured query language, and relates to the field of data processing technology. The method comprises: obtaining user input information, parsing and assembling the user input information to obtain initial input data; understanding the semantic intent of the initial input data and inputting it into a trained large language model to obtain a first reasoning result output by the large language model; extracting at least one table name from the first reasoning result, and extracting the table information of the table name from each table name based on the database system; summarizing the table information of all table names, and assembling the table information to obtain table information input data; inputting the table information input data into the trained large language model to obtain a second reasoning result output by the large language model. The present invention automatically analyzes the input slow SQL and database information through the database knowledge, reasoning ability and language understanding ability of LLM, quickly locates performance bottlenecks and puts forward optimization suggestions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data processing, and in particular to a method, device, equipment and medium for processing structured query language. Background Art

[0002] Structured Query Language (SQL) is a standardized programming language used to manage and operate relational databases. This language is interactive and can provide great convenience for users. Database management systems should make full use of SQL to improve the work quality and efficiency of computer application systems. SQL can not only be used independently in terminals, but also as a sub-language to provide effective assistance for other program designs. In this program application, SQL can optimize program functions together with other program languages, thereby providing users with more comprehensive information.

[0003] With the popularization of data applications and the rapid growth of data volume, the performance problems of database systems have become more and more prominent. During the operation of the system, the operating efficiency is often reduced due to the need to process a large amount of data, especially when it comes to complex SQL queries such as slow SQL queries. At this time, these slow SQLs need to be analyzed and optimized. Analyzing and optimizing slow SQLs involves a lot of professional knowledge. Usually, a specific database administrator (Database Administrator, DBA) is required to analyze the problem and make optimization suggestions based on the current database version, table structure, index, number of table records, etc., combined with his knowledge and experience. This process is highly dependent on the user's professional knowledge, resulting in low overall processing efficiency and high costs.

[0004] Therefore, it is necessary to provide a SQL processing solution that can improve processing efficiency and reduce processing costs. Summary of the invention

[0005] In view of this, the embodiments of the present invention provide a structured query language processing method, device, equipment and medium to solve the problem that the analysis and optimization of slow SQL is highly dependent on user professional knowledge and has low processing efficiency and high cost.

[0006] According to a first aspect, an embodiment of the present invention provides a method for processing a structured query language, the method comprising:

[0007] Obtaining user input information, parsing and assembling the user input information to obtain initial input data; the input information includes: a database system selected by the user, a selected large language model, a structured query language exceeding a preset time, and content to be analyzed;

[0008] Inputting the initial input data into the trained large language model to obtain a first inference result output by the large language model; the first inference result includes: instructions, context information, input data to be processed, and output data, the context information includes at least one keyword of interest of the user, and the keyword of interest is user intention understanding information extracted from the information of interest obtained based on the user's input information;

[0009] Extracting at least one table name from the first inference result, and extracting table information of each table name based on the database system; the table information includes table creation information, table capacity information and database basic information;

[0010] Summarizing the table information of all the table names and assembling the table information to obtain table information input data;

[0011] The table information input data is input into the trained large language model to obtain a second inference result output by the large language model; the second inference result includes the answer content to the content that needs to be analyzed.

[0012] In combination with the first aspect, in a first implementation of the first aspect, the information of interest is obtained in the following manner:

[0013] Obtaining user input information, and extracting content to be analyzed from the input information;

[0014] Convert the content to be analyzed into text to be parsed;

[0015] The text to be parsed is input into a trained first semantic understanding model to obtain the information of interest output by the first semantic understanding model; the first semantic understanding model is trained based on sample text and sample intent understanding results corresponding to the sample text.

[0016] In combination with the first implementation of the first aspect, in the second implementation of the first aspect, the keyword of interest is obtained by:

[0017] The information of interest is input into the trained second semantic understanding model to obtain the keywords of interest output by the second semantic understanding model; the second semantic understanding model is trained based on sample text, sample intent understanding results corresponding to the sample text, and intent background features; the intent background features represent the natural language description text for the background field of the text to be parsed.

[0018] In combination with the second implementation of the first aspect, in the third implementation of the first aspect, the second semantic understanding model is trained in the following manner:

[0019] Acquire a sample text, and determine the sample intention understanding result of the sample text;

[0020] Perform feature matching of the sample text with a preset knowledge base to obtain the intended background features corresponding to the sample text;

[0021] The sample text and the intent background features are used as input data for training, and the sample intent understanding results are used as label data. A supervised training method is adopted to train the second semantic understanding model for outputting keywords of interest in information of interest.

[0022] In combination with the first aspect, in a fourth implementation of the first aspect, before obtaining the user's input information and parsing and assembling the user's input information to obtain the initial input data, the method further includes:

[0023] Deploy database systems and large language models.

[0024] In combination with the first aspect, in the fifth implementation of the first aspect, the second inference result in the method also includes answer content to the information of interest; the answer content to the information of interest is obtained by combining a well-trained large language model with keywords of interest in the information of interest, answering the information of interest one by one to obtain sub-answer content, and merging and filtering all sub-answer content of the information of interest.

[0025] In combination with the first aspect, in a sixth implementation of the first aspect, extracting at least one table name from the first inference result, and extracting table information of the table name from each of the table names based on a database system, specifically includes:

[0026] Retrieving parsing information from a data system selected by a user in an offline and / or online manner; the parsing information includes database connection information and / or local files;

[0027] Parse each of the extracted table names according to the parsing information to obtain the table information of each of the table names;

[0028] Determine whether the table information contains a preset type, and if it is determined that the preset type is contained, output the table information; the preset type includes a table creation information type, a table capacity information type, and a database basic information type.

[0029] According to a third aspect, an embodiment of the present invention further provides a structured query language processing device, the device comprising:

[0030] The first assembly module is used to obtain user input information, parse and assemble the user input information to obtain initial input data; the input information includes: the database system selected by the user, the selected large language model, the structured query language exceeding the preset time, and the content to be analyzed;

[0031] a first reasoning module, configured to input the initial input data into a trained large language model to obtain a first reasoning result output by the large language model; the first reasoning result includes: instructions, context information, input data to be processed, and output data, the context information includes at least one keyword of interest of the user, and the keyword of interest is user intention understanding information extracted from the information of interest obtained based on the user's input information;

[0032] A data parsing module, used to extract at least one table name from the first reasoning result, and extract table information of each table name from the table name based on the database system; the table information includes table creation information, table capacity information and database basic information;

[0033] A second assembling module is used to summarize the table information of all the table names and assemble the table information to obtain table information input data;

[0034] The second reasoning module is used to input the table information input data into the trained large language model to obtain a second reasoning result output by the large language model; the second reasoning result includes the answer content to the content that needs to be analyzed.

[0035] According to a third aspect, an embodiment of the present invention further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of any of the structured query language processing methods described above are implemented.

[0036] According to a fourth aspect, an embodiment of the present invention further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the structured query language processing method as described in any one of the above are implemented.

[0037] According to a fifth aspect, an embodiment of the present invention further provides a computer program product, including a computer program, wherein when the computer program is executed by a processor, the steps of the structured query language processing method as described in any one of the above items are implemented.

[0038] The structured query language processing method, device, equipment and medium of the present invention first assembles the user's input information to obtain initial input data, then understands the user's semantic intention on the initial input data to obtain a first reasoning result, and then fully explores the questions raised by the user and the expected answer results, thereby reducing the understanding deviation and error rate of the user's input information, and then reduces subsequent ambiguity and misunderstanding, and then parses the first reasoning result to obtain the table name and table information, assembles the table information to obtain table information input data, and then uses the trained LLM to perform a second reasoning to obtain a second reasoning result. The second reasoning result is the final processing suggestion and solution obtained after the LLM performs reasonable reasoning based on the context and the knowledge it has mastered through a large amount of training. The second reasoning result is a better result obtained through multiple rounds of dialogue. Therefore, through LLM's database knowledge, reasoning ability and language comprehension ability, it automatically analyzes the input slow SQL and database information, quickly locates performance bottlenecks and puts forward optimization suggestions, and completes the analysis and optimization of slow SQL in a very short time, such as within a few seconds. It greatly improves the processing efficiency of slow SQL and can quickly respond to system performance issues. Moreover, through this automated analysis and optimization process, it significantly reduces the dependence on professional DBAs, reduces the dependence on expensive optimization tools and professionals, and reduces labor and tool costs. It has good scalability and adaptability, can adapt to different database versions and structures, and provides flexible slow SQL optimization solutions to meet the needs of various environments. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] The features and advantages of the present invention will be more clearly understood by referring to the accompanying drawings, which are schematic and should not be construed as limiting the present invention in any way. In the accompanying drawings:

[0040] Figure 1 A schematic diagram showing a flow chart of a method for processing structured query language provided by the present invention;

[0041] Figure 2 A schematic diagram showing the overall structured query language processing method provided by the present invention;

[0042] Figure 3 The specific flow chart of step S30 in the structured query language processing method provided by the present invention is shown;

[0043] Figure 4 A schematic diagram showing the structure of a processing device for structured query language provided by the present invention is shown;

[0044] Figure 5 It is a schematic diagram of the hardware structure of the electronic device provided in the embodiment of the present application. DETAILED DESCRIPTION

[0045] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are 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 those skilled in the art without creative work are within the scope of protection of the present invention.

[0046] SQL is a standardized programming language used to manage and operate relational databases. This language is interactive and can provide great convenience for users. Database management systems should make full use of SQL to improve the work quality and efficiency of computer application systems. SQL can not only be used independently in terminals, but also as a sub-language to provide effective assistance for other program designs. In this program application, SQL can optimize program functions together with other program languages, thereby providing users with more comprehensive information.

[0047] With the popularity of data applications and the rapid growth of data volume, the performance problems of database systems have become more and more prominent. During the operation of the system, the operating efficiency is often reduced due to the need to process a large amount of data, especially when it comes to complex SQL queries. When the amount of data is small, the impact of SQL on the performance of the database system is not obvious, but as the amount of data continues to increase, multiple slow SQLs will significantly affect the overall operating efficiency of the system.

[0048] Among them, slow SQL refers to SQL queries or operations that take longer than a specified time to execute. The specified time can be set or configured by the user, that is, the specified time can be determined based on specific application scenarios and performance requirements. It should be noted that in some special cases, SQL that consumes too much database resources can also be judged as slow SQL. These SQLs will also increase the data load and reduce the response speed of the database. Some slow SQLs may also cause the database lock to be occupied, thereby affecting the performance of the entire system.

[0049] Currently, the analysis and optimization of slow SQL mainly depends on the DBA. The DBA needs to conduct a comprehensive analysis of the current database version, table structure, index, number of table records and other information, and optimize these slow SQLs one by one based on the preset knowledge and experience. The above process is time-consuming and labor-intensive, highly dependent on users, low processing efficiency, and high cost.

[0050] For example, DBAs manually analyze slow SQL statements through users and optimize them in combination with indexes and table structures. This approach relies on the DBA's experience and expertise, is inefficient, and cannot respond quickly. Some databases provide built-in analysis and optimization tools, such as Oracle's SQL Tuning Advisor and SQL Access Advisor. These tools can automatically analyze query performance and provide optimization suggestions, but their effectiveness depends on the tool's own algorithms and the specific circumstances of the database, and these tools often require additional license fees. There are also some third-party tools that can help analyze and optimize slow SQL statements, such as SolarWinds Database Performance Analyzer. These tools can automatically detect slow SQL statements and provide optimization suggestions, but their effectiveness depends on the tool's configuration and the user's familiarity with the tool.

[0051] It can be seen that these processing methods are still difficult to quickly respond to performance issues of the database system. Even if the optimization tools built into the database system or third-party optimization tools are used, it takes a certain amount of time to configure and adjust, and the processing efficiency is low. In addition, the optimization tools built into the database system or third-party optimization tools often require additional license fees or usage fees, further increasing the cost burden.

[0052] In order to solve the above problems, a method for processing a structured query language is provided in this specification, aiming to provide a database performance optimization solution that is efficient, low-cost, highly automated and has good scalability. The method for processing a structured query language provided in this specification can be applied to electronic devices with SQL processing functions. The electronic devices may include notebooks, desktop computers, smart phones, smart wearable devices (virtual reality glasses, smart watches, etc.), tablet computers, etc. Of course, the method for processing a structured query language provided in this specification can also be applied to applications running in the above-mentioned electronic devices. For example, the method for processing a structured query language can be applied to a browser with an SQL processing function, or it can be applied to software with an SQL processing function. Figure 1 is a flow chart of a method for processing structured query language according to an embodiment of the present invention, such as Figure 1 As shown, the method may include the following steps:

[0053] S10, obtaining the user's input information, parsing and assembling the user's input information to obtain initial input data, where the initial input data is a prompt template. The user's input information at least includes: the database system (DBS) selected by the user, the large language model (LLM) selected, the structured query language (slow SQL) that exceeds the preset time, and the content to be analyzed (the question raised by the user).

[0054] LLM is a natural language processing model based on deep learning, which usually has billions or even hundreds of billions of parameters. These models are trained on large-scale text data and can understand and generate natural language texts and perform various language tasks such as text generation, translation, question answering, summarization, sentiment analysis, etc.

[0055] In LLM, a prompt is a piece of text or instruction that the user inputs to LLM to guide LLM to generate the corresponding output. Specifically, a prompt can be a question, an incomplete sentence, a task description, or any other form of text that is intended to clearly tell LLM what the user wants it to generate. The design and quality of the prompt have a great impact on the accuracy and relevance of the generated results. Prompts are usually clear, specific, and contextual, which can help LLM better understand the user's needs and generate more expected output.

[0056] To give a specific example, in this embodiment, the assembled initial input data (Prompt1) is as follows:

[0057] Extract the table names involved in the following `SQL`, and output them in `markdown` format

[0058] ```Markdown

[0059] | Table Name |

[0060] | ---- |

[0061] ||

[0062] ```

[0063] SQL

[0064] {SQL}

[0065] ```

[0066] Among them, {SQL} is the user's input information, that is, the SQL input by the user that exceeds the preset time, that is, the slow SQL input by the user.

[0067] In particular, Prompt consists of the following four elements: instruction, context, input data to be processed, and output data. Output data is also an output indicator, which is used to specify the type or format of the output.

[0068] In this embodiment, the context information of the initial input data includes at least one keyword of interest of the user, and the keyword of interest is the user intention understanding information extracted from the information of interest obtained based on the user's input information, that is, the keyword of interest is used to characterize the user's answer intention, and the information of interest is used to infer the content that the user needs to analyze. For example, the content that the user needs to analyze is: "the final number of medals of country A in the Nth Olympic Games", then the information of interest that may be obtained is: the medal table of all previous Olympic Games, the time and place of all previous Olympic Games, country A, etc. Correspondingly, the keywords of interest extracted based on the information of interest may include: Olympic Games, XX place, YY time, total medal table, daily medal table, medal table for each sub-item, country A, etc.

[0069] Different from the existing LLM analysis and optimization process of SQL, this method does not directly use the user's input information as input data. Instead, it first performs semantic understanding of the user's input information, fully explores the questions raised by the user and the expected answer results, thereby reducing the understanding deviation and error rate of the user's input information, and further reducing subsequent ambiguity and misunderstanding.

[0070] In this embodiment, a trained semantic understanding model is used to parse the content that needs to be analyzed in the user's input information, thereby obtaining the above-mentioned information of interest.

[0071] Preferably, the process of parsing the user's required analysis content is:

[0072] A10. Obtain the user's input information, and extract the content that needs to be analyzed from the input information.

[0073] A20. Convert the content to be analyzed into text to be analyzed. The text to be analyzed can be understood as relevant information input by the user through human-computer interaction. The human-computer interaction method can be text box input, voice input, gesture input, and other methods.

[0074] In particular, when the user inputs the above input information, various input text boxes can be provided to the user, such as the "Please select a database" text box for the user to input or select a DBS, the "Please select LLM" text box for the user to input or select an LLM, the "Please enter the slow SQL to be analyzed" text box for the user to input a structured query language (slow SQL) that exceeds a preset time, and the "Please enter the content to be analyzed" text box for the user to input the content to be analyzed. In this way, the text to be parsed can be directly obtained.

[0075] A30, input the text to be parsed into the trained first semantic understanding model to obtain the information of interest output by the first semantic understanding model. The first semantic understanding model is trained based on the sample text and the sample intention understanding results corresponding to the sample text, so that the trained first semantic understanding model can perform the first semantic intention understanding of the text to be parsed and obtain the information of interest.

[0076] The sample intent understanding result corresponding to the sample text is obtained by manual annotation by the user, and can also be obtained by annotation combined with expert experience. In addition, the sample intent understanding result can be understood as the label information used in the training process of the first semantic understanding model.

[0077] In this embodiment, the first semantic understanding model can be a currently commonly used natural language intention understanding model, which can understand the intention of the natural language sent by the user and can also perform corresponding operations accordingly. No restrictions are imposed on the first semantic understanding model and the network architecture.

[0078] A40, inputting the information of interest into the trained second semantic understanding model to obtain the keywords of interest output by the second semantic understanding model. The second semantic understanding model is trained based on the sample text, the sample intent understanding result corresponding to the sample text, and the intent background feature, so that the trained second semantic understanding model can perform a second semantic intent understanding on the information of interest and extract the keywords of interest.

[0079] Similarly, the sample intent understanding result corresponding to the sample text is obtained by manual annotation by the user, or can be obtained by annotation combined with expert experience, and the sample intent understanding result is also the label information used in the training process of the second semantic understanding model.

[0080] In this embodiment, the intent background feature represents the feature information (text) of the natural language description of the background field of the text to be parsed, such as the above-mentioned "the final number of medals of country A in the Nth Olympic Games", and its corresponding intent understanding feature can be: obtaining the number of medals corresponding to country A according to the hosting time, obtaining the number of medals corresponding to country A according to the corresponding number of sessions, etc.

[0081] The intent background feature is the professional knowledge information (feature) obtained by inputting the sample text into a professional search library, database or knowledge base and matching the background features. Therefore, this method also needs to build or prepare the search library, database or knowledge base required for the intent background feature. Then, through vector matching and other methods, the intent background feature of the information of interest is returned.

[0082] The second semantic understanding model obtained in this way can perform more refined semantic understanding and intent extraction based on the user's information of interest, combine the information of interest and more professional background fields, conduct deeper information mining on the information of interest, obtain the background knowledge required to answer user questions, assist LLM in reasoning, and give full play to the understanding and reasoning ability of the trained LLM.

[0083] S20 , input the initial input data into the trained LLM to obtain a first inference result (LLM_OUTPUT1) output by the LLM. The first inference result is expected to be a markdown table.

[0084] S30, extract at least one table name (TABLE) from the first reasoning result, and extract the table information of each table name based on the database system. The table information includes table creation information (TABLE_DEFINE), table capacity information (TABLE_INFO) and database basic information (DB_INFO). It should be noted that the table creation information includes index information, and the database basic information includes database type, version, configuration and other information. In addition, if the table name is not extracted, a prompt message such as "extraction error" can be returned to the user.

[0085] S40, summarize the table information of all table names, assemble the table information, and obtain table information input data. After summarizing the table information, the total table creation information (TABLES_DEFINE), the total table capacity information (TABLES_INFO) and the basic database information (DB_INFO) can be obtained.

[0086] To give a specific example, in this embodiment, the assembled table information input data (Prompt2) is as follows:

[0087] Combined with the current `slow SQL`, `database information`, `table creation SQL information`, `table capacity information`, reply to `user questions`

[0088] #### Slow SQL

[0089] {SQL}

[0090] #### Database Information

[0091] {DB_INFO}

[0092] #### Create table SQL information

[0093] {TABLES_DEFINE}

[0094] #### Table capacity information

[0095] {TABLES_INFO}

[0096] #### User Questions

[0097] {INPUT_TEXT}

[0098] S50. Input the table information input data into the trained LLM to obtain the second reasoning result (LLM_OUTPUT2) output by the LLM. The second reasoning result is the final processing suggestion and solution obtained by the LLM after reasonable reasoning based on the context and the knowledge acquired through a large amount of training. The second reasoning result is a better result obtained through multiple rounds of dialogue. The second reasoning result can quickly locate the performance bottleneck of slow SQL and make optimization suggestions. The second reasoning result contains the answer to the content that needs to be analyzed, such as: "The final number of medals of country A in the Nth Olympic Games is B, of which the number of gold medals is B1, the number of silver medals is B2, and the number of bronze medals is B3".

[0099] In other possible embodiments, the second inference result also includes the answer content to the information of interest, and is displayed together with the answer content to the content to be analyzed, such as the answer content to the information of interest: "The total medal list of the Nth Olympic Games", "The daily medal list of the Nth Olympic Games", "The medal list of each event of the Nth Olympic Games", "The total medal list of all Olympic Games", etc.

[0100] More specifically, the answer content of the information of interest can still be obtained by combining the trained LLM with the interesting keywords of the information of interest, answering the information of interest one by one to obtain sub-answer content, and then merging and filtering all the sub-answer content of the information of interest to obtain the answer content of the information of interest.

[0101] In this embodiment, the specific application also needs to perform the pre-environment deployment in the early stage, that is, deploy DSB and LLM:

[0102] LIST_DBS is the database information for slow SQL that needs to be analyzed:

[0103] 1) TABLE_INFO: connection information of the target database, used to obtain online information such as table structure, index, and number of table records involved in the current slow SQL. Database information can also be collected regularly or manually, and the database information file in the agreed format can be uploaded to the intelligent tool as private data during the tool operation.

[0104] 2) DB_INFO: target database type and version information, and related main configuration information;

[0105] LIST_LLM, the large language model operating environment preparation:

[0106] Since LLM is the core of processing, it is necessary to select a suitable LLM for processing. If data security is involved, it is necessary to deploy a suitable large language model locally and provide a running environment and corresponding calling API: If data security is not involved in the use of the tool, you can use the API to call advanced large language models such as gpt-4o and qwen2-max for reasoning.

[0107] The structured query language processing method of the present invention first assembles the user's input information to obtain initial input data, then understands the user's semantic intention on the initial input data to obtain a first reasoning result, and then fully explores the questions raised by the user and the expected answer results, thereby reducing the understanding deviation and error rate of the user's input information, and then reducing subsequent ambiguity and misunderstanding, and then parses the first reasoning result to obtain the table name and table information, assembles the table information to obtain table information input data, and then uses the trained LLM to perform a second reasoning to obtain a second reasoning result. The second reasoning result is the final processing suggestion and solution obtained after the LLM performs reasonable reasoning based on the context and the knowledge it has mastered through a large amount of training, and The second reasoning result is a better result obtained through multiple rounds of dialogue. Therefore, through LLM's database knowledge, reasoning ability and language comprehension ability, it automatically analyzes the input slow SQL and database information, quickly locates performance bottlenecks and puts forward optimization suggestions, and completes the analysis and optimization of slow SQL in a very short time, such as within a few seconds. It greatly improves the processing efficiency of slow SQL and can quickly respond to system performance issues. Moreover, through this automated analysis and optimization process, it significantly reduces the dependence on professional DBAs, reduces the dependence on expensive optimization tools and professionals, and reduces labor and tool costs. It has good scalability and adaptability, can adapt to different database versions and structures, and provides flexible slow SQL optimization solutions to meet the needs of various environments.

[0108] Combine the following Figure 2 and Figure 3 The structured query language processing method of the present invention is described, and step S30 specifically includes:

[0109] S31, calling parsing information from the DBS selected by the user in an offline (offline) and / or online (online) manner, wherein the parsing information includes database connection information and / or local files.

[0110] S32. parse each extracted table name according to the parsing information to obtain table information of each table name.

[0111] S33, determining whether the table information type includes a preset type, and outputting the table information if it is determined that the preset type is included. In this embodiment, the preset type includes three types, namely, table creation information type, table capacity information (table data) type, and database basic information type. In particular, if the parsed table information does not include all of the above three types, a prompt message such as "parsing error" can be returned to the user.

[0112] The following describes a structured query language processing device provided by an embodiment of the present invention. The structured query language processing device described below and the structured query language processing method described above can refer to each other.

[0113] In order to solve the above problems, a structured query language processing device is provided in this specification, aiming to provide a database performance optimization solution with high efficiency, low cost, high automation and good scalability. Figure 4 is a schematic diagram of the structure of a processing device for structured query language according to an embodiment of the present invention, such as Figure 4 As shown, the device may include:

[0114] The first assembly module 10 is used to obtain the user's input information, parse and assemble the user's input information to obtain initial input data, and the initial input data is a prompt template. The user's input information at least includes: the DBS selected by the user, the selected LLM, the structured query language (slow SQL) that exceeds the preset time, and the content to be analyzed (the question raised by the user).

[0115] LLM is a natural language processing model based on deep learning, which usually has billions or even hundreds of billions of parameters. These models are trained on large-scale text data and can understand and generate natural language texts and perform various language tasks such as text generation, translation, question answering, summarization, sentiment analysis, etc.

[0116] In LLM, a prompt is a piece of text or instruction that the user inputs to LLM to guide LLM to generate the corresponding output. Specifically, a prompt can be a question, an incomplete sentence, a task description, or any other form of text that is intended to clearly tell LLM what the user wants it to generate. The design and quality of the prompt have a great impact on the accuracy and relevance of the generated results. Prompts are usually clear, specific, and contextual, which can help LLM better understand the user's needs and generate more expected output.

[0117] In particular, Prompt consists of the following four elements: instruction, context, input data to be processed, and output data. Output data is also an output indicator, which is used to specify the type or format of the output.

[0118] In this embodiment, the context information of the initial input data includes at least one keyword of interest of the user, and the keyword of interest is the user intention understanding information extracted from the information of interest obtained based on the user's input information, that is, the keyword of interest is used to characterize the user's answer intention, and the information of interest is used to infer the content that the user needs to analyze. For example, the content that the user needs to analyze is: "the final number of medals of country A in the Nth Olympic Games", then the information of interest that may be obtained is: the medal table of all previous Olympic Games, the time and place of all previous Olympic Games, country A, etc. Correspondingly, the keywords of interest extracted based on the information of interest may include: Olympic Games, XX place, YY time, total medal table, daily medal table, medal table for each sub-item, country A, etc.

[0119] Different from the existing LLM analysis and optimization process of SQL, this method does not directly use the user's input information as input data. Instead, it first performs semantic understanding of the user's input information, fully explores the questions raised by the user and the expected answer results, thereby reducing the understanding deviation and error rate of the user's input information, and further reducing subsequent ambiguity and misunderstanding.

[0120] In this embodiment, a trained semantic understanding model is used to parse the content that needs to be analyzed in the user's input information, thereby obtaining the above-mentioned information of interest.

[0121] The first reasoning module 20 is used to understand the semantic intent of the initial input data and input it into the trained LLM to obtain a first reasoning result (LLM_OUTPUT1) output by the LLM. The first reasoning result is expected to be a markdown table.

[0122] The data parsing module 30 is used to extract at least one table name (TABLE) from the first reasoning result, and extract the table information of each table name based on the database system. The table information includes table creation information (TABLE_DEFINE), table capacity information (TABLE_INFO) and database basic information (DB_INFO). It should be noted that the table creation information includes index information, and the database basic information includes database type, version, configuration and other information. In addition, if the table name is not extracted, a prompt message such as "extraction error" can be returned to the user.

[0123] The second assembly module 40 is used to summarize the table information of all table names and assemble the table information to obtain table information input data. After summarizing the table information, the total table creation information (TABLES_DEFINE), the total table capacity information (TABLES_INFO) and the basic database information (DB_INFO) can be obtained.

[0124] The second reasoning module 50 is used to input the table information input data into the trained LLM to obtain the second reasoning result (LLM_OUTPUT2) output by the LLM. The second reasoning result is the final processing suggestion and solution obtained by the LLM after reasonable reasoning based on the context and the knowledge acquired through a large amount of training. The second reasoning result is a better result obtained through multiple rounds of dialogue. The second reasoning result can quickly locate the performance bottleneck of slow SQL and make optimization suggestions. The second reasoning result contains the answer content to the content that needs to be analyzed, such as: "The final number of medals of country A in the Nth Olympic Games is B, of which the number of gold medals is B1, the number of silver medals is B2, and the number of bronze medals is B3".

[0125] In other possible embodiments, the second inference result also includes the answer content to the information of interest, and is displayed together with the answer content to the content to be analyzed, such as the answer content to the information of interest: "The total medal list of the Nth Olympic Games", "The daily medal list of the Nth Olympic Games", "The medal list of each event of the Nth Olympic Games", "The total medal list of all Olympic Games", etc.

[0126] More specifically, the answer content of the information of interest can still be obtained by combining the trained LLM with the interesting keywords of the information of interest, answering the information of interest one by one to obtain sub-answer content, and then merging and filtering all the sub-answer content of the information of interest to obtain the answer content of the information of interest.

[0127] In this embodiment, the specific application also needs to perform the pre-environment deployment in the early stage, that is, deploy DSB and LLM:

[0128] LIST_DBS is the database information for slow SQL that needs to be analyzed:

[0129] 2) TABLE_INFO: connection information of the target database, used to obtain online information such as table structure, index, and number of table records involved in the current slow SQL. Database information can also be collected regularly or manually, and the database information file in the agreed format can be uploaded to the intelligent tool as private data during the tool operation.

[0130] 2) DB_INFO: target database type and version information, and related main configuration information;

[0131] LIST_LLM, the large language model operating environment preparation:

[0132] Since LLM is the core of processing, it is necessary to select a suitable LLM for processing. If data security is involved, it is necessary to deploy a suitable large language model locally and provide a running environment and corresponding calling API: If data security is not involved in the use of the tool, you can use the API to call advanced large language models such as gpt-4o and qwen2-max for reasoning.

[0133] The structured query language processing device of the present invention first assembles the user's input information to obtain initial input data, then understands the user's semantic intention on the initial input data to obtain a first reasoning result, and then fully explores the questions raised by the user and the expected answer results, thereby reducing the understanding deviation and error rate of the user's input information, and then reducing subsequent ambiguity and misunderstanding, and then parses the first reasoning result to obtain the table name and table information, assembles the table information to obtain table information input data, and then uses the trained LLM to perform a second reasoning to obtain a second reasoning result. The second reasoning result is the final processing suggestion and solution obtained after the LLM performs reasonable reasoning based on the context and the knowledge it has mastered through a large amount of training, and The second reasoning result is a better result obtained through multiple rounds of dialogue. Therefore, through LLM's database knowledge, reasoning ability and language comprehension ability, it automatically analyzes the input slow SQL and database information, quickly locates performance bottlenecks and puts forward optimization suggestions, and completes the analysis and optimization of slow SQL in a very short time, such as within a few seconds. It greatly improves the processing efficiency of slow SQL and can quickly respond to system performance issues. Moreover, through this automated analysis and optimization process, it significantly reduces the dependence on professional DBAs, reduces the dependence on expensive optimization tools and professionals, and reduces labor and tool costs. It has good scalability and adaptability, can adapt to different database versions and structures, and provides flexible slow SQL optimization solutions to meet the needs of various environments.

[0134] Figure 5An example of a physical structure diagram of an electronic device is shown in FIG. Figure 5 As shown, the electronic device may include: a processor 510 (processor), a communication interface 520 (Communications Interface), a memory 530 (memory) and a communication bus 540, wherein the processor 510, the communication interface 520, and the memory 530 communicate with each other through the communication bus 540. The processor 510 may call the logic command in the memory 530 to execute the structured query language processing method, which includes:

[0135] Obtaining user input information, parsing and assembling the user input information to obtain initial input data; the input information includes: a database system selected by the user, a selected large language model, a structured query language exceeding a preset time, and content to be analyzed;

[0136] Inputting the initial input data into a trained large language model to obtain a first inference result output by the large language model;

[0137] Extracting at least one table name from the first inference result, and extracting table information of each table name based on the database system; the table information includes table creation information, table capacity information and database basic information;

[0138] Summarizing the table information of all the table names and assembling the table information to obtain table information input data;

[0139] The table information input data is input into the trained large language model to obtain a second inference result output by the large language model.

[0140] In addition, the logic instructions in the above-mentioned memory 530 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memor), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0141] On the other hand, the present invention further provides a computer program product, the computer program product comprising a computer program stored on a non-transitory computer-readable storage medium, the computer program comprising program instructions, and when the program instructions are executed by a computer, the computer can execute the structured query language processing method provided by the above methods, the method comprising:

[0142] Obtaining user input information, parsing and assembling the user input information to obtain initial input data; the input information includes: a database system selected by the user, a selected large language model, a structured query language exceeding a preset time, and content to be analyzed;

[0143] Performing semantic intent understanding on the initial input data and inputting the data into a trained large language model to obtain a first inference result output by the large language model;

[0144] Extracting at least one table name from the first inference result, and extracting table information of each table name based on the database system; the table information includes table creation information, table capacity information and database basic information;

[0145] Summarizing the table information of all the table names and assembling the table information to obtain table information input data;

[0146] The table information input data is input into the trained large language model to obtain a second inference result output by the large language model.

[0147] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the processing method for executing the structured query language provided above is implemented, and the method includes:

[0148] Obtaining user input information, parsing and assembling the user input information to obtain initial input data; the input information includes: a database system selected by the user, a selected large language model, a structured query language exceeding a preset time, and content to be analyzed;

[0149] Performing semantic intent understanding on the initial input data and inputting the data into a trained large language model to obtain a first inference result output by the large language model;

[0150] Extracting at least one table name from the first inference result, and extracting table information of each table name based on the database system; the table information includes table creation information, table capacity information and database basic information;

[0151] Summarizing the table information of all the table names and assembling the table information to obtain table information input data;

[0152] The table information input data is input into the trained large language model to obtain a second inference result output by the large language model.

[0153] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0154] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0155] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for processing structured query language, characterized in that: The method comprises: Obtaining user input information, parsing and assembling the user input information to obtain initial input data; the input information includes: a database system selected by the user, a selected large language model, a structured query language exceeding a preset time, and content to be analyzed; The initial input data is semantically understood and input into a trained large language model to obtain a first inference result output by the large language model; the first inference result includes: instructions, context information, input data to be processed, and output data, the context information includes at least one keyword of interest to the user, and the keyword of interest is user intention understanding information extracted from the information of interest obtained based on the user's input information; Extracting at least one table name from the first inference result, and extracting table information of each table name based on the database system; the table information includes table creation information, table capacity information and database basic information; Summarizing the table information of all the table names and assembling the table information to obtain table information input data; The table information input data is input into the trained large language model to obtain a second inference result output by the large language model; the second inference result includes the answer content to the content that needs to be analyzed.

2. The method for processing structured query language according to claim 1, characterized in that: The information of interest is obtained in the following manner: Obtaining user input information, and extracting content to be analyzed from the input information; Convert the content to be analyzed into text to be parsed; The text to be parsed is input into a trained first semantic understanding model to obtain the information of interest output by the first semantic understanding model; the first semantic understanding model is trained based on sample text and sample intent understanding results corresponding to the sample text.

3. The method for processing structured query language according to claim 2, characterized in that: The keywords of interest are obtained in the following way: The information of interest is input into the trained second semantic understanding model to obtain the keywords of interest output by the second semantic understanding model; the second semantic understanding model is trained based on sample text, sample intent understanding results corresponding to the sample text, and intent background features; the intent background features represent the natural language description text for the background field of the text to be parsed.

4. The method for processing structured query language according to claim 3, characterized in that: The second semantic understanding model is trained in the following way: Acquire a sample text, and determine the sample intention understanding result of the sample text; Perform feature matching of the sample text with a preset knowledge base to obtain the intended background features corresponding to the sample text; The sample text and the intent background features are used as input data for training, and the sample intent understanding results are used as label data. A supervised training method is adopted to train the second semantic understanding model for outputting keywords of interest in information of interest.

5. The method for processing structured query language according to claim 1, characterized in that: The method also includes, before obtaining the user's input information, parsing and assembling the user's input information to obtain the initial input data: Deploy database systems and large language models.

6. The method for processing structured query language according to claim 1, characterized in that: The second inference result in this method also includes the answer content to the information of interest; the answer content to the information of interest is obtained by combining the trained large language model with the interesting keywords of the information of interest, answering the information of interest one by one to obtain sub-answer content, and merging and filtering all the sub-answer content of the information of interest.

7. The method for processing structured query language according to claim 1, characterized in that: The step of extracting at least one table name from the first inference result, and extracting table information of each table name based on a database system, specifically includes: Retrieving parsing information from a data system selected by a user in an offline and / or online manner; the parsing information includes database connection information and / or local files; Parse each of the extracted table names according to the parsing information to obtain the table information of each of the table names; Determine whether the table information contains a preset type, and if it is determined that the preset type is contained, output the table information; the preset type includes a table creation information type, a table capacity information type, and a database basic information type.

8. A structured query language processing device, characterized in that: The device comprises: The first assembly module is used to obtain user input information, parse and assemble the user input information to obtain initial input data; the input information includes: the database system selected by the user, the selected large language model, the structured query language exceeding the preset time, and the content to be analyzed; A first reasoning module is used to understand the semantic intent of the initial input data and input it into the trained large language model to obtain a first reasoning result output by the large language model; the first reasoning result includes: instructions, context information, input data to be processed, and output data, the context information includes at least one keyword of interest of the user, and the keyword of interest is user intention understanding information extracted from the information of interest obtained based on the user's input information; A data parsing module, used to extract at least one table name from the first reasoning result, and extract table information of each table name from the table name based on the database system; the table information includes table creation information, table capacity information and database basic information; A second assembling module is used to summarize the table information of all the table names and assemble the table information to obtain table information input data; The second reasoning module is used to input the table information input data into the trained large language model to obtain a second reasoning result output by the large language model; the second reasoning result includes the answer content to the content that needs to be analyzed.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the steps of the method for processing the structured query language according to any one of claims 1 to 7 are implemented.

10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for processing the structured query language as claimed in any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Large language model training method and device, medium and electronic equipment

    CN117932019A

  • Method for converting complex database text into structured query language and related equipment

    CN118331998A