CN-121996704-A - Database query method, device and storage medium
Abstract
The application discloses a database query method, equipment and a storage medium, which relate to the technical field of data processing, wherein the disclosed database query method comprises the steps of responding to a received user natural language query request, carrying out entity identification and semantic understanding on the natural language query request to obtain a business entity to be queried and a query intention; generating a main query statement based on the business entity, the query intention and a preset database relation graph, generating an extended query statement based on an execution result of the main query statement and the database relation graph, and executing the extended query statement to obtain a query result corresponding to the natural language query request. The method and the device can improve the database query accuracy in the multi-table association scene.
Inventors
- ZHAN XINLONG
- CHEN ZHONGXIAN
- SONG GUOHUI
Assignees
- 深圳前海微众银行股份有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20260205
Claims (10)
- 1. A database query method, the database query method comprising: responding to a received user natural language query request, and carrying out entity identification and semantic understanding on the natural language query request to obtain a business entity to be queried and a query intention; generating a main query sentence based on the service entity, the query intention and a preset database relation map; generating an extended query statement based on an execution result of the main query statement and the database relationship graph; And executing the extended query statement to obtain a query result corresponding to the natural language query request.
- 2. The database query method of claim 1, wherein prior to the step of generating a master query statement based on the business entity, the query intent, and a preset database relationship graph, further comprising: Acquiring metadata information of each data table in a target database; calculating importance scores of the data tables based on the metadata information, and carrying out hierarchical division on the data tables according to the importance scores; Determining an association relationship between the data tables based on a preset relationship discovery strategy according to a hierarchical division result, wherein the relationship discovery strategy comprises a foreign key constraint analysis strategy, a LLM semantic analysis strategy and a field similarity calculation strategy; verifying and optimizing each association relation, and constructing a database relation map based on the verified and optimized association relation.
- 3. The database query method of claim 1, wherein the step of generating a master query statement based on the business entity, the query intent, and a preset database relationship graph comprises: screening a core data table from a preset database relation map according to the service entity and the query intention; and generating a main query statement by adopting a preset query strategy based on the core data table and the association relation of the core data table in the database relation map.
- 4. The database query method of claim 1, wherein prior to the step of generating an expanded query statement based on the results of execution of the main query statement and the database relational graph, further comprising: executing the main query statement; If the main query statement is successfully executed, an execution result of the main query statement is obtained; And if the execution of the main query statement fails, regenerating the main query statement based on feedback information of the execution failure.
- 5. The database query method of claim 1, wherein the step of generating an extended query statement based on the execution result of the main query statement and the database relational graph comprises: Determining a target data table corresponding to an execution result of the main query statement; taking the target data table as a starting node, and performing graph traversal search in the database relation graph to determine an associated data table; And generating an expanded query statement according to the execution result of the main query statement and the associated data table.
- 6. The method of claim 5, wherein the step of performing a graph traversal search in the database relational graph with the target data table as a starting node to determine an associated data table comprises: Taking the target data table as a starting node, and performing graph traversal search in the database relation graph by adopting a breadth-first search algorithm; determining the exploration priority of the adjacent nodes according to the confidence of the connecting edges between the starting node and the adjacent nodes in the graph traversal searching process; Selecting at least one node from the adjacent nodes as an associated node according to the exploration priority; And determining the data table corresponding to the association node as an association data table.
- 7. The database query method of claim 1, wherein the step of executing the extended query statement to obtain a query result corresponding to the natural language query request comprises: Executing the extended query statement in a streaming manner; In the execution process of the extended query statement, if an error occurs, triggering an error processing flow comprising a retry mechanism or a path switching mechanism; If no error occurs, returning part of query results in real time, and obtaining query results corresponding to the natural language query request after the query is completed.
- 8. The database query method according to any one of claims 1 to 7, wherein after the step of executing the extended query statement to obtain a query result corresponding to the natural language query request, further comprising: inputting the query result to a preset intelligent dialogue agent, so as to analyze the query result through the intelligent dialogue agent and obtain an analysis conclusion in a natural language form; And outputting a visual query result according to the analysis conclusion.
- 9. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the computer program being configured to implement the steps of the database querying method according to any of claims 1 to 8.
- 10. A storage medium, characterized in that the storage medium is a computer-readable storage medium, on which a computer program is stored, which computer program, when being executed by a processor, carries out the steps of the database query method according to any one of claims 1 to 8.
Description
Database query method, device and storage medium Technical Field The present application relates to the field of data processing technologies, and in particular, to a database query method, a database query device, and a storage medium. Background With the development of information technology, relational databases are widely applied to enterprise data management, the scale of the relational databases is becoming huge, and data tables and association relations among tables in the databases are becoming complex. At present, a technology for converting natural language into SQL (StructuredQueryLanguage ) based on a large language model (LargeLanguageModel, LLM) is mature gradually, and database query intentions input by users in a natural language form can be converted into canonical SQL sentences through the technology and executed by a database management system so as to reduce the threshold of querying databases by the users. However, when complex query related to multi-table association is performed, the connection path between each data table is either strictly dependent on the predefined foreign key constraint in the database, a large number of implicit service associations actually existing cannot be found and utilized, or a large number of rules are manually pre-written or association mapping is maintained, so that flexibility is poor and the dynamic change service requirements are difficult to adapt, and the generated SQL statement often has problems of association table deletion, connection path redundancy, error and the like under the multi-table association scene, and the query accuracy is affected. In summary, how to improve the database query accuracy in the multi-table association scenario is a significant technical problem in the art. Disclosure of Invention The application mainly aims to provide a database query method, equipment and a storage medium, aiming at improving the database query accuracy under a multi-table association scene. In order to achieve the above object, the present application provides a database query method, which includes: responding to a received user natural language query request, and carrying out entity identification and semantic understanding on the natural language query request to obtain a business entity to be queried and a query intention; generating a main query sentence based on the service entity, the query intention and a preset database relation map; generating an extended query statement based on an execution result of the main query statement and the database relationship graph; And executing the extended query statement to obtain a query result corresponding to the natural language query request. In an embodiment, before the step of generating the main query sentence based on the service entity, the query intention and the preset database relational graph, the method further includes: Acquiring metadata information of each data table in a target database; calculating importance scores of the data tables based on the metadata information, and carrying out hierarchical division on the data tables according to the importance scores; Determining an association relationship between the data tables based on a preset relationship discovery strategy according to a hierarchical division result, wherein the relationship discovery strategy comprises a foreign key constraint analysis strategy, a LLM semantic analysis strategy and a field similarity calculation strategy; verifying and optimizing each association relation, and constructing a database relation map based on the verified and optimized association relation. In an embodiment, the step of generating the main query sentence based on the business entity, the query intention and a preset database relationship graph includes: screening a core data table from a preset database relation map according to the service entity and the query intention; and generating a main query statement by adopting a preset query strategy based on the core data table and the association relation of the core data table in the database relation map. In an embodiment, before the step of generating the extended query statement based on the execution result of the main query statement and the database relational graph, the method further includes: executing the main query statement; If the main query statement is successfully executed, an execution result of the main query statement is obtained; And if the execution of the main query statement fails, regenerating the main query statement based on feedback information of the execution failure. In one embodiment, the step of generating an extended query statement based on the execution result of the main query statement and the database relational graph includes: Determining a target data table corresponding to an execution result of the main query statement; taking the target data table as a starting node, and performing graph traversal search in the database relation graph to determin