A method and system for risk routing and task graph execution in heterogeneous database queries

By parsing query intent, calculating risk scores, and selecting appropriate paths in heterogeneous database queries, and performing local verification and repair, the problems of field attribution errors and result inflation in heterogeneous database queries are solved, achieving fast and accurate query results and low-latency responses.

CN123115189APending Publication Date: 2026-11-17DATA SPACE RES INST
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611602578.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-16
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

Existing technologies suffer from problems such as incorrect field attribution, incompatible types, illegal table joins, result bloat, inadequacy of task splitting, and difficulty in result tracing when querying heterogeneous databases, leading to query failures and response delays.

Method used

By acquiring natural language query requests, parsing them into structured query intents, reading heterogeneous database schema information, calculating risk scores, selecting appropriate query paths, performing legality checks and repairs locally, generating query task units, and aggregating result packages to achieve fast and accurate queries.

Benefits of technology

It improves the success rate and accuracy of queries in heterogeneous databases, reduces database resource consumption and response latency, avoids cross-table join bloat and field attribution errors, and achieves end-to-end traceability of query results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123115189A_ABST
    Figure CN123115189A_ABST
Patent Text Reader

Abstract

This invention discloses a method and system for risk routing and task graph execution in heterogeneous database queries. The method acquires natural language query requests, parses them into structured query intents using a large language model, reads heterogeneous database pattern information, calculates heterogeneous pattern risk scores, and routes single structured query language paths, hybrid paths, or constrained agent task graph paths based on the comparison results of the risk scores and preset thresholds. Corresponding query task units or combinations of query task units are generated. Before database execution, the query task units undergo local validity verification, and task units that fail verification are partially repaired or circuit-breaking is performed. Successfully verified or repaired task units are scheduled for execution, and the execution results of each task unit are aggregated into a query result package for output. This application improves the success rate and result traceability of natural language queries in heterogeneous databases through pre-assessment of risks, dynamic routing, pre-verification, and local repair mechanisms.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the fields of artificial intelligence and large language model intelligent agents, and in particular to a method and system for risk routing and task graph execution in heterogeneous database queries. Background Technology

[0002] With the rapid development of artificial intelligence technology, natural language-based database query systems have been widely used in various industries. These systems typically utilize large language models or Text-to-SQL models to convert users' natural language query requests into structured query language statements, and then retrieve target data from the database by executing these statements.

[0003] In application scenarios such as academic talent pools, scientific research achievement databases, institutional talent pools, expert discovery systems, and scientific research management systems, data on the same object is often distributed across multiple data tables with significantly different structures. For example, scholar information may be distributed across basic information tables, title and honor tables, paper achievement tables, patent invention tables, award record tables, news and updates tables, and scientific research funding project tables. These data tables suffer from inconsistencies in field naming conventions, inconsistent field data types, complex primary and foreign key relationships, and differences in statistical granularity.

[0004] In existing technologies, database query systems based on large language models typically employ the following approach: the large language model directly generates a structured query language statement based on the user's natural language query request; the system executes this statement and retrieves the results from the database. If execution fails, the system prompts the large language model again based on the error information returned by the database for correction, and iterates multiple times until the query succeeds. For single-table queries or simple statistical queries, this approach can obtain query results relatively quickly.

[0005] However, the above technical approach has the following technical drawbacks in heterogeneous database comprehensive query scenarios: First, during the structured query language generation stage, large language models struggle to accurately identify the mapping relationship between the information dimensions involved in the query request and the physical tables in the underlying database. Because field names differ between tables of different dimensions in heterogeneous databases, large language models are prone to incorrectly assigning fields from one table to another when generating structured query language, causing the generated query statement to fail due to referencing non-existent fields.

[0006] Second, differences in field type constraints across different tables in heterogeneous databases lead to type incompatibility issues. The same semantic field may be defined with different data types in different physical tables. When the data type used in the filtering conditions or sorting operations generated by the large language model is inconsistent with the actual field type of the target physical table, the query statement will throw an error during database execution due to type mismatch.

[0007] Third, large language models are prone to generating illegal table joins when generating join queries across multiple tables. In heterogeneous databases, not every two tables can be joined; some tables lack direct primary key-foreign key relationships. Without constraints on join relationships, large language models tend to generate structured queries containing illegal table joins, causing these queries to fail the database's syntax and semantic checks.

[0008] Fourth, when queries involve joining data tables with one-to-many relationships, directly generating comprehensive structured query statements can easily lead to result set bloat. For example, when a query request involves both basic information about scholars and a list of their publications, directly joining the basic information table with the publications table will result in each record in the basic information table being matched one-to-one with multiple records in the publications table. This leads to a large amount of redundant data in the returned results, which not only increases network transmission overhead but also distorts statistical results (such as the total number of publications).

[0009] To address the aforementioned issues, some existing technical solutions attempt to employ a query splitting strategy, which involves breaking down complex natural language query requests into multiple subtasks, generating corresponding structured query statements for each subtask, executing them sequentially, and finally merging the results of each subtask. However, this strategy still has the following shortcomings in heterogeneous database scenarios: First, existing splitting strategies lack a proactive risk awareness mechanism for underlying heterogeneous database schemas. Before splitting query tasks, the system does not assess the matching degree between the information dimensions involved in the query request and the underlying physical table structure, nor does it anticipate risks such as incorrect field attribution, type incompatibility, and illegal table joins. For query requests with high structural complexity, even after splitting, individual subtasks may still experience incorrect field attribution or type incompatibility issues, causing the entire query chain to be interrupted due to the failure of a single subtask.

[0010] Secondly, existing splitting strategies apply the same task splitting granularity to both low-complexity and high-complexity query requests, lacking a differentiated routing mechanism based on risk level. For low-complexity query requests involving only a single information dimension, mechanical splitting increases the number of large language model calls and additional database round-trip requests, leading to increased response latency. For high-complexity query requests involving multiple information dimensions and one-to-many relationships, if a single comprehensive structured query statement is still used, it is prone to repeated execution failures or the generation of statistically distorted results.

[0011] Third, in existing technical solutions, the verification of whether a query task unit is executable relies on feedback information from the database. After the structured query statement is sent to and executed by the database, the system determines whether the query unit has failed by capturing the error information returned by the database. This post-verification method means that failed query units have already consumed the database's computing resources and network transmission resources, and after the database returns error information, the system needs to re-prompt the large language model for correction, increasing the overall response time.

[0012] Fourth, in existing technical solutions, when a single query subtask fails, it is usually necessary to regenerate the entire query plan or prompt the large language model to output the complete query statement again. This approach does not limit the scope of the failed query to a single subtask, causing other subtasks that could have been executed normally to be delayed or repeated due to the reconstruction of the overall query plan, thus reducing the overall execution efficiency of the query chain.

[0013] Fifth, existing technical solutions lack a mechanism for tracing the source of query results. When multiple subtasks query data from different physical tables and merge the results, the final query result cannot be traced back to the specific source table of each data item, the corresponding query unit, or the intermediate processing procedures (such as field mapping, type conversion, and result pruning). This makes it difficult to pinpoint the cause of failure when query results are incorrect or abnormal.

[0014] In summary, existing heterogeneous database natural language query systems have significant technical shortcomings in areas such as field attribution identification, illegal association interception, connection expansion suppression, adaptive task splitting granularity, pre-validation, failure domain isolation, and result traceability. There is an urgent need for a technical solution that can identify heterogeneous query risks before the large language model generates query statements, adaptively select the execution mode according to the risk level, perform local validation and repair before database distribution, and perform traceable aggregation of query results. Summary of the Invention

[0015] To address the technical problems existing in the background art, this invention proposes a method and system for heterogeneous database query risk routing and task graph execution.

[0016] This invention proposes a method for heterogeneous database query risk routing and task graph execution, comprising the following steps: Obtain a natural language query request and call the large language model to parse the natural language query request into a structured query intent. The structured query intent includes the target object, the hit information dimensions, and the query requirement features. The large language model does not directly generate an executable structured query language. Read heterogeneous database schema information, which includes the mapping from dimensions to physical tables, the set of legal fields, field type constraints, allowed relationships, field alias mapping, and historical execution logs; The heterogeneous pattern risk score is calculated based on the structured query intent and heterogeneous database pattern information. Based on the comparison result of the heterogeneous pattern risk score and the preset threshold, a single structured query language path, a hybrid path, or a constrained agent task graph path is selected. A query task unit or a combination of query task units corresponding to the routing result is generated. The combination of query task units consists of two or more query task units. The query task unit is the smallest execution unit that can be independently verified and scheduled. Before execution in the heterogeneous database, a local validity check is performed on the query task unit. For query task units that fail the local validity check, a partial repair or unit circuit breaking is performed. Query task units that are circuit broken do not generate structured query language and are not sent to the heterogeneous database. The scheduler executes query task units that have passed local validity verification or repair. It aggregates the execution results of each query task unit into a query result package and outputs it. The query result package includes the execution result of each query task unit, the source table identifier, the repair status, and the failure status.

[0017] Preferably, the step of obtaining the natural language query request and calling a large language model to parse the natural language query request into a structured query intent specifically includes: Input the natural language query request, along with the preset output format constraints and a few sample examples, into the large language model. The preset output format constraints are used to limit the large language model to only output parsing results that conform to the preset structured data format. Guided by preset output format constraints and few sample examples, the large language model extracts the target object, the hit information dimensions, and the query requirement features from the natural language query request, and outputs the parsing confidence score. The preset output format constraints include a preset set of field names, a preset set of information dimension enumeration values, and a preset set of query requirement feature enumeration values.

[0018] Preferably, the step of calculating the heterogeneous pattern risk score based on the structured query intent and heterogeneous database pattern information specifically involves: ; in, For natural language query requests; Information on heterogeneous database schemas; This represents the heterogeneous mode risk score, with a value range of [0,1]. Dimension span risk is used to characterize the ratio of the number of hit information dimensions to the preset upper limit of dimension span. For pattern difference risk, it is used to characterize the normalized difference between database pattern signatures corresponding to each dimension of hit information; To mitigate cross-table join risk, this is used to characterize the ratio of the number of one-to-many relationship dimensions in the hit information dimension to the preset upper limit of one-to-many dimensions; For statistical detail mixed risk, it is used to characterize whether the query requirement features simultaneously include statistical requirements and detailed requirements; Historical error risk is used to characterize the failure rate of execution records in the historical execution log that are similar to the combination of hit dimensions of the structured query intent; and All values ​​have been normalized and range from [0,1]. Normalized weights for dimensional span risk; Normalized weights for pattern difference risk; Normalized weights for cross-table join risk; To calculate the normalized weights for the mixed risks in the statistical details; The normalized weights for historical error risk are defined, with each weight being no less than 0 and the sum being 1.

[0019] Preferably, the preset threshold includes a first threshold and a second threshold, and the first threshold is less than the second threshold; the step of routing and selecting a single structured query language path, a hybrid path, or a constrained agent task graph path based on the comparison result of the heterogeneous mode risk score and the preset threshold specifically includes: When the heterogeneous pattern risk score is less than the first threshold, the routing is selected using a single structured query language path; When the heterogeneous pattern risk score is greater than or equal to the first threshold and less than the second threshold, a hybrid path is selected for routing. When the heterogeneous pattern risk score is greater than or equal to the second threshold, the route selection is a constrained agent task graph path. The first threshold and the second threshold are determined by the historical validation set.

[0020] Preferably, the generation of query task units or combinations of query task units corresponding to the routing selection results specifically includes: When the route is selected as a single structured query language path, a single-node query task unit without dependent edges is generated. When the routing is selected as a mixed path, a combination of query task units is generated, which includes statistical query task units and detailed query task units; When the route is selected as a constrained agent task graph path, a task graph containing data dependency edges and control dependency edges is generated.

[0021] Preferably, when the routing is a hybrid path, a control dependency edge is constructed between the statistical query task unit and the detailed query task unit. The control dependency edge is used to skip the execution of the detailed query task unit when the execution result of the statistical query task unit is empty or zero.

[0022] Preferably, when the routing is selected as a constrained agent task graph path, the task graph includes an object location query task unit and two or more information dimension query task units that depend on the object location query task unit; each information dimension query task unit receives the object primary key output by the object location query task unit as a filtering condition through a data dependency edge.

[0023] Preferably, the query task unit includes an information dimension identifier, an operation type identifier, a target physical table name, a candidate field set, filtering conditions, sorting rules, a result quantity limit, candidate associations, and a repair strategy identifier; the step of performing local validity verification on the query task unit before execution on the heterogeneous database specifically includes: Verify whether the target physical table of the query task unit exists in the dimension-to-physical table mapping based on the heterogeneous database schema information; Verify whether each field in the candidate field set of the query task unit belongs to the valid field set of the target physical table; Verify whether the field types in the filter conditions of the query task unit are compatible with the corresponding types in the field type constraints; Verify whether the sorting field in the sorting rule of the query task unit belongs to the set of valid fields in the target physical table; Verify whether the candidate associations of the query task unit are allowed associations.

[0024] Preferably, the step of performing partial repair or unit circuit breaking on query task units that fail local validity verification specifically includes: For query task units that fail local validity checks, a set of candidate repair actions is generated. The candidate repair actions include field alias replacement, field pruning, target table rebinding, and unit circuit breaking. Calculate the estimated cost of each candidate repair action in the candidate repair action set, and select the candidate repair action with the lowest estimated cost to execute; When the selected candidate repair action is field alias replacement, the field names that fail the local validity check in the candidate field set of the query task unit will be replaced with the valid physical field names determined by the field alias mapping relationship; When the selected candidate repair action is field pruning, remove fields that fail the local validity check from the candidate field set of the query task unit; When the selected candidate repair action is target table rebinding, the target physical table name of the query task unit will be replaced with a valid physical table name that matches the current information dimension in the heterogeneous database schema information. When the selected candidate repair action is unit circuit breaking, the query task unit is marked as circuit breaking. The query task unit marked as circuit breaking does not generate structured query language and is not sent to the heterogeneous database.

[0025] This invention proposes a heterogeneous database query risk routing and task graph execution system, comprising: The structured semantic parsing module is used to obtain natural language query requests and call the large language model to parse the natural language query requests into structured query intents. The structured query intents include the target object, the hit information dimensions, and the query requirement features. The large language model does not directly generate executable structured query language. The heterogeneous database schema maintenance module is used to read heterogeneous database schema information, which includes the mapping from dimensions to physical tables, the set of legal fields, field type constraints, allowed relationships, field alias mapping, and historical execution logs. The heterogeneous pattern risk assessment module is used to calculate the heterogeneous pattern risk score based on the structured query intent and heterogeneous database pattern information. The query path routing module is used to select a single structured query language path, a hybrid path, or a constrained agent task graph path based on the comparison result of the heterogeneous pattern risk score and the preset threshold. The constrained agent task graph generation module is used to generate query task units or combinations of query task units corresponding to the routing selection results. The combination of query task units consists of two or more query task units, and the query task unit is the smallest execution unit that can be independently verified and scheduled. The validity verification module is used to perform local validity verification on the query task unit before execution on the heterogeneous database; The repair and circuit breaker module is used to perform partial repair or circuit breaker on query task units that fail local validity verification. The query scheduling and execution module is used to schedule and execute query task units that have passed local validity checks or repairs. The query result package aggregation module is used to aggregate the execution results of each query task unit into a query result package and output it. The query result package includes the execution result of each query task unit, the source table identifier, the repair status, and the failure status.

[0026] The proposed heterogeneous database query risk routing and task graph execution method and system, through pre-assessment of heterogeneous schema risks and dynamic path routing mechanisms, avoids unnecessary task graph generation overhead in low-risk scenarios to ensure rapid response. In high-risk scenarios, it decomposes complex queries into multiple independently verifiable query task units to avoid cross-table join bloat and field attribution errors. By performing local validity checks on query task units based on heterogeneous database schema information before database deployment, common query defects such as field incompatibility, illegal associations, and type errors are intercepted before the database execution stage, thereby eliminating risks to query performance. This application addresses the following issues: It addresses the post-dependency of database error feedback; through local repair and circuit breaking mechanisms at the query task unit level, the failure of a single query unit is isolated within its own scope without affecting the execution of other normal units in the query chain, thus preventing overall query failure; by using the control dependency edge between the statistical query unit and the detailed query unit, subsequent detailed query execution is skipped directly when the preceding statistical result is empty or zero, reducing invalid input / output requests to heterogeneous databases; further, by aggregating the execution results, source table identifiers, repair status, and failure status of each query task unit through structured query result packages, achieving end-to-end traceability of query results. This application can improve the success rate and accuracy of natural language queries on heterogeneous databases, while reducing database resource consumption and query response latency. Attached Figure Description

[0027] Figure 1 This is a flowchart illustrating the workflow of a heterogeneous database query risk routing and task graph execution method proposed in this invention. Figure 2 This is a schematic diagram of the system architecture of a heterogeneous database query risk routing and task graph execution system proposed in this invention. Detailed Implementation

[0028] Reference Figure 1 The present invention proposes a method for heterogeneous database query risk routing and task graph execution, comprising the following steps: S1. Obtain the natural language query request and call the large language model to parse the natural language query request into a structured query intent. The structured query intent includes the target object, the hit information dimensions, and the query requirement characteristics. The large language model does not directly generate an executable structured query language.

[0029] In this embodiment, a natural language query request is obtained, and a large language model is invoked to parse the natural language query request into a structured query intent, specifically including: Input the natural language query request, along with the preset output format constraints and a few sample examples, into the large language model. The preset output format constraints are used to limit the large language model to only output parsing results that conform to the preset structured data format. Guided by preset output format constraints and few sample examples, the large language model extracts the target object, the hit information dimensions, and the query requirement features from the natural language query request, and outputs the parsing confidence score. The preset output format constraints include a preset set of field names, a preset set of information dimension enumeration values, and a preset set of query requirement feature enumeration values.

[0030] Specifically, the target object is the entity object to be queried. The matched information dimension is used to characterize the data category involved in the query request. In one implementation, the matched information dimension is selected from the following enumerated value set: basic_info, honor, paper, patent, award, news, and fund, corresponding to seven business data categories: basic information, titles and honors, paper achievements, patent inventions, award records, news updates, and research funds, respectively. The query requirement feature is used to characterize the output format requirement of the query request, including at least one of statistical requirements, detailed requirements, and list requirements. The parsing confidence is used to characterize the degree of certainty of the large language model for the parsing result, and the value range is [0,1].

[0031] It should be noted that in all embodiments of this application, the large language model does not generate structured query language statements that can be deployed to heterogeneous databases for execution during the structured semantic parsing stage. The large language model only outputs structured query intents, which serve as input data for subsequent risk assessment, path routing, and task unit generation, rather than directly executable database query statements.

[0032] S2. Read heterogeneous database schema information, which includes the mapping from dimensions to physical tables, the set of legal fields, field type constraints, allowed relationships, field alias mapping, and historical execution logs.

[0033] Specifically, heterogeneous database schema information is represented as follows: ; in, This refers to the set of heterogeneous object information dimension identifiers supported by the system; in one implementation, ={basic_info, honor, paper, patent, award, news, fund}, which correspond to seven business data categories: basic information, titles and honors, paper achievements, patent inventions, award records, news and news, and research funds, respectively. For the underlying physical database table name set, in one implementation, T={user_info, honor_title, paper_pub, patent_list, award_record, news_record, fund_project}. The mapping relationship from dimensions to master data tables satisfies M(basic_info)=user_info, M(honor)=honor_title, M(paper)=paper_pub, M(patent)=patent_list, M(award)=award_record, M(news)=news_record, and M(fund)=fund_project. If the target physical table name selected by a query task unit is inconsistent with the physical table name determined by the mapping relationship M for the current information dimension, the system will identify the inconsistency and trigger corresponding repair or circuit breaker operations in the local validity verification stage of subsequent step S4. F(t) maps the set of valid physical fields of a data table to the set of fields in the physical table t that are allowed to be used by the query task unit. This set is determined by the database field metadata and field permission configuration. Y(f) is a field data type constraint function. It returns the normalized data type of field f and is used to identify filtering, comparison, and sorting operations that are incompatible with the field type. R(d) maps the set of allowed relationships for dimension d, returning the allowed table joins, join keys, and join directions under dimension d. Because there are many dimensions of object information, not all tables can be arbitrarily "JOINed"; the system only allows query units to use the relationships declared in R(d). For field alias mapping, A(a,d,t) returns the valid physical field corresponding to the field alias a in dimension d and target table t, where a represents the field alias to be mapped. The historical execution log data structure contains at least the following information for each log entry: timestamp, user-input request q, hit dimension subset, route path, execution status, and error type.

[0034] S3. Calculate the heterogeneous pattern risk score based on the structured query intent and heterogeneous database pattern information, and select a single structured query language path, a hybrid path, or a constrained agent task graph path based on the comparison result of the heterogeneous pattern risk score and the preset threshold. Generate query task units or combinations of query task units corresponding to the routing results. The combination of query task units consists of two or more query task units. The query task unit is the smallest execution unit that can be independently verified and scheduled.

[0035] In this embodiment, the heterogeneous pattern risk score is calculated based on the structured query intent and heterogeneous database pattern information, specifically as follows: ; in, For natural language query requests; Information on heterogeneous database schemas; This represents the heterogeneous mode risk score, with a value range of [0,1]. Dimension span risk is used to characterize the ratio of the number of hit information dimensions to the preset upper limit of dimension span. For pattern difference risk, it is used to characterize the normalized difference between database pattern signatures corresponding to each dimension of hit information; To mitigate cross-table join risk, this is used to characterize the ratio of the number of one-to-many relationship dimensions in the hit information dimension to the preset upper limit of one-to-many dimensions; For statistical detail mixed risk, it is used to characterize whether the query requirement features simultaneously include statistical requirements and detailed requirements; Historical error risk is used to characterize the failure rate of execution records in the historical execution log that are similar to the combination of hit dimensions of the structured query intent; and All values ​​have been normalized and range from [0,1]. Normalized weights for dimensional span risk; Normalized weights for pattern difference risk; Normalized weights for cross-table join risk; To calculate the normalized weights for the mixed risks in the statistical details; The normalized weights for historical error risk are defined, with each weight being no less than 0 and the sum being 1.

[0036] In this embodiment, the preset threshold includes a first threshold and a second threshold, and the first threshold is less than the second threshold; the routing selection based on the comparison result between the heterogeneous pattern risk score and the preset threshold includes a single structured query language path, a hybrid path, or a constrained agent task graph path, specifically including: When the heterogeneous pattern risk score is less than the first threshold, the routing is selected using a single structured query language path; When the heterogeneous pattern risk score is greater than or equal to the first threshold and less than the second threshold, a hybrid path is selected for routing. When the heterogeneous pattern risk score is greater than or equal to the second threshold, the route selection is a constrained agent task graph path. The first threshold and the second threshold are determined by the historical validation set.

[0037] In this embodiment, generating a query task unit or combination of query task units corresponding to the routing selection result specifically includes: When the route is selected as a single structured query language path, a single-node query task unit without dependent edges is generated. When the routing is selected as a mixed path, a combination of query task units is generated, which includes statistical query task units and detailed query task units; When the route is selected as a constrained agent task graph path, a task graph containing data dependency edges and control dependency edges is generated.

[0038] In this embodiment, when the routing selection is a hybrid path, a control dependency edge is constructed between the statistical query task unit and the detailed query task unit. The control dependency edge is used to skip the execution of the detailed query task unit when the execution result of the statistical query task unit is empty or zero.

[0039] In this embodiment, when the routing is selected as a constrained agent task graph path, the task graph includes an object location query task unit and two or more information dimension query task units that depend on the object location query task unit respectively; each information dimension query task unit receives the object primary key output by the object location query task unit as a filtering condition through a data dependency edge.

[0040] It should be noted that a query task unit is the smallest verifiable and schedulable query object formed around a specific information dimension and operation type. The i-th query task unit is represented as: ; Where i represents the sequence number of the query task unit. The information dimension identifier of the i-th query task unit is used to indicate the business dimension to which the query task unit belongs, and is selected from the element in the dimension identifier set D in step S2. The operation type indicates the type of operation to be performed in this query task unit, including at least one of count, list, locate, and aggregate; count indicates a total count operation, list indicates a detailed list query operation, locate indicates an object location operation, and aggregate indicates an aggregation calculation operation. This represents the target physical table name, used to indicate the underlying database physical table that will be accessed when this query task unit is executed; the target physical table name should belong to the physical table name set T in step S2. This represents the candidate field set, indicating the set of physical field names to be queried or output when this query task unit is executed. This represents the filtering conditions, used to indicate the data filtering criteria when this query task unit is executed. This indicates the sorting rules, used to specify the sorting fields and sorting direction for the results of this query task unit. Indicates the result quantity limit, indicating the maximum number of rows that can be returned by this query task unit. This indicates candidate join relationships, used to indicate the table join relationships allowed when this query task unit is executed. This indicates the repair strategy, used to indicate the repair action taken when the query task unit fails the local validity check. It is initially null. For a single-node query task unit, its candidate associations... It can be an empty set, and the set of dependent edges E corresponding to the task graph is an empty set.

[0041] S4. Before execution in the heterogeneous database, perform local validity checks on the query task units, and perform partial repair or unit circuit breaking on the query task units that fail the local validity checks. The circuit-broken query task units do not generate structured query language and are not sent to the heterogeneous database.

[0042] In this embodiment, the query task unit includes an information dimension identifier, an operation type identifier, a target physical table name, a candidate field set, filtering conditions, sorting rules, a result quantity limit, candidate associations, and a repair strategy identifier. Before execution on the heterogeneous database, a local validity check is performed on the query task unit, specifically including: Verify whether the target physical table of the query task unit exists in the dimension-to-physical table mapping based on the heterogeneous database schema information; Verify whether each field in the candidate field set of the query task unit belongs to the valid field set of the target physical table; Verify whether the field types in the filter conditions of the query task unit are compatible with the corresponding types in the field type constraints; Verify whether the sorting field in the sorting rule of the query task unit belongs to the set of valid fields in the target physical table; Verify whether the candidate associations of the query task unit are allowed associations.

[0043] In this embodiment, partial repair or unit circuit breaking is performed on query task units that fail local validity verification, specifically including: For query task units that fail local validity checks, a set of candidate repair actions is generated. The candidate repair actions include field alias replacement, field pruning, target table rebinding, and unit circuit breaking. Calculate the estimated cost of each candidate repair action in the candidate repair action set, and select the candidate repair action with the lowest estimated cost to execute; When the selected candidate repair action is field alias replacement, the field names that fail the local validity check in the candidate field set of the query task unit will be replaced with the valid physical field names determined by the field alias mapping relationship; When the selected candidate repair action is field pruning, remove fields that fail the local validity check from the candidate field set of the query task unit; When the selected candidate repair action is target table rebinding, the target physical table name of the query task unit will be replaced with a valid physical table name that matches the current information dimension in the heterogeneous database schema information. When the selected candidate repair action is unit circuit breaking, the query task unit is marked as circuit breaking. The query task unit marked as circuit breaking does not generate structured query language and is not sent to the heterogeneous database.

[0044] In one implementation, during the generation of the constrained agent task graph, query task units are generated using a preset toolset. This preset toolset includes: an object location tool, a pattern dictionary query tool, a statistical query unit generation tool, a detailed query unit generation tool, a field mapping tool, a validity pre-validation tool, and a result aggregation tool. The module generating the constrained agent task graph can only output tool call parameters or query task unit structures; it does not directly output unvalidated structured query language or directly send any query statements to the underlying heterogeneous database.

[0045] When entering the task graph path of a constrained agent, the request is represented as: ; in, To query the set of task units, This is a set of dependency edges. Dependency edges include data dependencies and control dependencies. Data dependencies are used to pass necessary inputs such as object primary keys, paper numbers, and patent numbers; control dependencies are used to skip subsequent detailed query units when the preceding total is empty or zero.

[0046] In this embodiment, the optimal repair action is selected from the candidate repair action set based on the estimated cost function. The expression for the estimated cost function is: ; Where i represents the sequence number of the query task unit; Indicates candidate repair actions; To apply candidate repair actions The estimated remaining failure rate after that, To apply candidate repair actions Information loss rate afterward; To apply candidate repair actions The estimated physical calculation cost afterwards; The weights are the remaining failure rate weight, the information loss rate weight, and the physical computation cost weight, respectively, and their sum is 1; the predicted cost function is selected such that... The candidate repair action with the smallest value is executed.

[0047] S5. Schedule and execute query task units that have passed local validity verification or repair. Aggregate the execution results of each query task unit into a query result package and output it. The query result package includes the execution result of each query task unit, the source table identifier, the repair status, and the failure status.

[0048] Specifically, local legitimacy verification includes the following five verification items: First, the system verifies whether the target physical table of the query task unit exists in the dimension-to-physical table mapping based on the heterogeneous database schema information. Determine information dimensions The corresponding master data table name, and validation. Is it true? If so... Not belonging to T or If so, the query task unit failed the target table validity check.

[0049] Second, verify whether each field in the candidate field set of the query task unit belongs to the valid field set of the target physical table. If any field in the candidate field set does not belong to the valid field set... If the defined valid fields are not found, the query task unit fails the field validity check.

[0050] Third, verify whether the field types in the filtering conditions of the query task unit are compatible with the corresponding types in the field type constraints. The system obtains the filtering conditions based on the field type constraint function Y(f). The normalized data types of each field are determined, and the values ​​provided in the filtering conditions are verified to be compatible with the normalized data types of the corresponding fields.

[0051] Fourth, verify whether the sorting field in the sorting rules of the query task unit belongs to the valid field set of the target physical table. If the sorting field is not in the valid field set... If the defined valid fields are not within the range, then the query task unit fails the validity check of the sorting field.

[0052] Fifth, verify whether the candidate relationships of the query task unit belong to the allowed relationships. If No relationship in If the defined allowable range is exceeded, then the query task unit fails the relationship validity check.

[0053] For query task units that fail local validity checks, the system does not directly send them to the database. Instead, it generates a set of candidate repair actions locally and selects the repair action to execute based on the estimated cost.

[0054] Candidate repair actions include field alias replacement, field pruning, target table rebinding, and cell circuit breaking.

[0055] Field alias replacement refers to: when the candidate field set If a field name fails the field validity check, the system will look up the field alias mapping A and replace the field name with the valid physical field name determined by the field alias mapping relationship.

[0056] Field pruning refers to: when the candidate field set If a field name fails the field validity check and there is no corresponding valid alias in the field alias mapping A, the system removes the field that failed the check from the candidate field set.

[0057] Target table rebinding refers to: when querying the target physical table name of a task unit... If the target table validity check fails, the system will Replace with dimensions from the heterogeneous database schema information that are consistent with the current information dimension. The valid physical table name that is matched, i.e. .

[0058] Unit circuit breaking refers to the system marking a query task unit as circuit-broken when all actions in the candidate repair action set fail to enable re-validation. Query task units marked as circuit-broken do not generate Structured Query Language (SCL) and do not send data to heterogeneous databases; that is, they do not generate any input / output requests for heterogeneous databases.

[0059] Example 1: Academic Object Information Query In the following embodiments, user input, object identifiers, and field identifiers have all been anonymized; among them, This represents the first threshold, which is the dividing line between low risk and medium risk. This represents the second threshold, which is the dividing line between medium and high risk. The risk component weights used in this embodiment are: , First threshold Second threshold The aforementioned weights and thresholds are determined by a historical validation set independent of the test data.

[0060] This embodiment uses seven information dimensions as the upper limit for dimensional span normalization. The one-to-many result dimensions include five categories: papers, patents, awards, news, and grants. In low-risk requests, i.e., when the heterogeneous pattern risk score is less than the first threshold, the anonymized user input is: "Query basic information about Li Moumou." The system parses the target object as "Li Moumou," and the hit dimension is only basic_info. It does not involve cross-dimensional pattern differences or one-to-many joins, and the query request does not include mixed requirements for statistical details. The risk component value is... After weighting, we get: ; because The system enters the single structured query language path, encapsulates the query into a single-node query task unit without dependent edges, and executes it after local validity verification.

[0061] In a medium-risk request, where the heterogeneous pattern risk score is greater than or equal to the first threshold and less than the second threshold, the anonymized user input is: "Query the number of papers by Li Moumou and his five most recent representative papers." This request targets the paper dimension and includes both statistical and detailed requirements. The risk component value is... After weighting, we get: ; because The system then enters a hybrid path, generating a total paper count query unit and a paper detail query unit, and establishing a control dependency between them. When the total paper count is 0, the paper detail query unit is not sent to the database for execution.

[0062] In high-risk requests, i.e., when the heterogeneous pattern risk score is greater than or equal to the second threshold, the anonymized user input is: "Please query Professor Li's complete academic information, including papers, patents, and awards." Based on the semantic trigger condition of "complete academic information," the system expands the hit dimensions to basic_info, honor, paper, patent, award, news, and fund. Each risk component is valued according to the following criteria: the hit dimensions are basic information, titles and honors, papers, patents, awards, news, and funding, totaling 7 dimensions; therefore, the risk spans across dimensions. Pairwise dissimilarity calculations were performed on the normalized pattern signatures across the seven hit dimensions, yielding 21 sets of dimensional dissimilarity values. The sum of these dissimilarity values ​​was 16.38, therefore the pattern dissimilarity risk is [not specified]. Among the hit dimensions, papers, patents, awards, news, and funding belong to one-to-many result dimensions, totaling 5 categories, therefore there is a risk of cross-table joins. The query requirements include both total statistics and detailed lists, thus posing a risk of mixed statistical and detailed data. In the historical verification logs used to determine weights and thresholds, there were 42 similar dimension combinations, of which 13 failed due to field attribution, illegal association, or join bloat, indicating a risk of historical errors. After weighting, we get: ; because The system then enters the constrained agent task graph path.

[0063] Task graph generated during this run It includes 12 query task units, as shown in Table 1. Table 1 shows the query task units and dependencies in the high-risk request task graph. Table 1: Query task units and dependencies in the high-risk request task graph

[0064] In this embodiment, subscript 6 represents query task unit Q6 in Table 1; the repair cost weight is taken as... , For the field alias replacement action, since the mapping confidence of "patent_no→patent_number" is 0.95, Therefore, the remaining failure rate is estimated. (Field alias replacement) is set to 0.05; this action does not delete output fields, resulting in an information loss rate. (Field alias replacement) is set to 0; this action only performs local dictionary replacement, with an estimated physical computation cost. (Field alias replacement) is set to 0.10. For field pruning, the completeness of patent details may still be affected after pruning; the estimated remaining failure rate is... (Field pruning) is set to 0.10; the pruned field accounts for 0.25 of the weight of the output fields in this query unit, resulting in an information loss rate. (Field pruning) is set to 0.25; this action only modifies the local query cell field set, with an estimated physical computation cost. (Field clipping) Take 0.05.

[0065] (Field alias replacement) ; (Field trimming) ; The system selects the field alias replacement with the lowest estimated cost, fixing only Q6 and not affecting other query task units. During execution, the total fund query unit Q11 returns 0. The system skips the fund details query unit Q12 based on the control dependency edge Q11→Q12 and records that this dimension is empty in the result package.

[0066] This embodiment selects 120 natural language request logs generated during the operation of an academic research management system and after anonymization as independent test data. These 120 test logs were not included in the risk component weighting or the first threshold. Second threshold The weights and thresholds were predetermined by another set of historical validation logs. Based on this independent test data, the following results were obtained, as shown in Table 2: Table 2: Comparison of results for different query schemes on independent test datasets

[0067] Traditional solutions do not include pre-emptive risk routing, so the recall rate for high-risk requests is recorded as "-". In the test dataset of this embodiment, 57 requests were identified as high-risk requests through manual annotation or execution result backtracking. Of these, 55 were correctly routed by the system to the constrained agent's task graph path, resulting in a high-risk request recall rate of 55 / 57 ≈ 96.5%. Two other requests were identified as high-risk requests during post-execution result backtracking, but their risk scores were below the first threshold. Therefore, the system routed the request to a single structured query language path, ultimately resulting in a field attribution error. Consequently, 118 out of 120 requests generated usable query result packages. The "Number of Requests Failing Due to Field Attribution Errors" and "Number of Requests with Statistical Distortion Due to Cross-Table Join Expansion" in the table are counted by request dimension; if multiple field attribution errors or multiple join expansion errors occur within the same request, they are still counted as one failed request in the corresponding metric. Therefore, the above number of failed requests is used to illustrate the main failure types and is not required to correspond exactly to the number of requests with usable query result packages.

[0068] The above results also demonstrate that the accuracy of the system's underlying schema information S affects the effectiveness of risk assessment. Inaccurate maintenance of S information leads to a decrease in the recall rate of high-risk requests and the effectiveness of query unit validity verification. Therefore, a normalized alignment mapping function based on manual configuration and semi-automatic maintenance through offline scanning of large models is an important technical foundation for reducing the degradation of risk calculation.

[0069] Reference Figure 2 This invention proposes a heterogeneous database query risk routing and task graph execution system, comprising: The structured semantic parsing module is used to obtain natural language query requests and call the large language model to parse the natural language query requests into structured query intents. The structured query intents include the target object, the hit information dimensions, and the query requirement features. The large language model does not directly generate executable structured query language. The heterogeneous database schema maintenance module is used to read heterogeneous database schema information, which includes the mapping from dimensions to physical tables, the set of legal fields, field type constraints, allowed relationships, field alias mapping, and historical execution logs. The heterogeneous pattern risk assessment module is used to calculate the heterogeneous pattern risk score based on the structured query intent and heterogeneous database pattern information. The query path routing module is used to select a single structured query language path, a hybrid path, or a constrained agent task graph path based on the comparison result of the heterogeneous pattern risk score and the preset threshold. The constrained agent task graph generation module is used to generate query task units or combinations of query task units corresponding to the routing selection results. The combination of query task units consists of two or more query task units, and the query task unit is the smallest execution unit that can be independently verified and scheduled. The validity verification module is used to perform local validity verification on the query task unit before execution on the heterogeneous database; The repair and circuit breaker module is used to perform partial repair or circuit breaker on query task units that fail local validity verification. The query scheduling and execution module is used to schedule and execute query task units that have passed local validity checks or repairs. The query result package aggregation module is used to aggregate the execution results of each query task unit into a query result package and output it. The query result package includes the execution result of each query task unit, the source table identifier, the repair status, and the failure status.

[0070] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.

Claims

1. A method for risk routing and task graph execution in heterogeneous database queries, characterized in that, Includes the following steps: Obtain a natural language query request and call the large language model to parse the natural language query request into a structured query intent. The structured query intent includes the target object, the hit information dimensions, and the query requirement features. The large language model does not directly generate an executable structured query language. Read heterogeneous database schema information, which includes the mapping from dimensions to physical tables, the set of legal fields, field type constraints, allowed relationships, field alias mapping, and historical execution logs; The heterogeneous pattern risk score is calculated based on the structured query intent and heterogeneous database pattern information. Based on the comparison result of the heterogeneous pattern risk score and the preset threshold, a single structured query language path, a hybrid path, or a constrained agent task graph path is selected. A query task unit or a combination of query task units corresponding to the routing result is generated. The combination of query task units consists of two or more query task units. The query task unit is the smallest execution unit that can be independently verified and scheduled. Before execution in the heterogeneous database, a local validity check is performed on the query task unit. For query task units that fail the local validity check, a partial repair or unit circuit breaking is performed. Query task units that are circuit broken do not generate structured query language and are not sent to the heterogeneous database. The scheduler executes query task units that have passed local validity verification or repair. It aggregates the execution results of each query task unit into a query result package and outputs it. The query result package includes the execution result of each query task unit, the source table identifier, the repair status, and the failure status.

2. The heterogeneous database query risk routing and task graph execution method according to claim 1, characterized in that, The process of obtaining natural language query requests and using a large language model to parse them into structured query intents specifically includes: Input the natural language query request, along with the preset output format constraints and a few sample examples, into the large language model. The preset output format constraints are used to limit the large language model to only output parsing results that conform to the preset structured data format. Guided by preset output format constraints and few sample examples, the large language model extracts the target object, the hit information dimensions, and the query requirement features from the natural language query request, and outputs the parsing confidence score. The preset output format constraints include a preset set of field names, a preset set of information dimension enumeration values, and a preset set of query requirement feature enumeration values.

3. The heterogeneous database query risk routing and task graph execution method according to claim 1, characterized in that, The calculation of the heterogeneous pattern risk score based on the structured query intent and heterogeneous database pattern information is specifically as follows: ; in, For natural language query requests; Information on heterogeneous database schemas; This represents the heterogeneous mode risk score, with a value range of [0,1]. Dimension span risk is used to characterize the ratio of the number of hit information dimensions to the preset upper limit of dimension span. For pattern difference risk, it is used to characterize the normalized difference between database pattern signatures corresponding to each dimension of hit information; To mitigate cross-table join risk, this is used to characterize the ratio of the number of one-to-many relationship dimensions in the hit information dimension to the preset upper limit of one-to-many dimensions; For statistical detail mixed risk, it is used to characterize whether the query requirement features simultaneously include statistical requirements and detailed requirements; Historical error risk is used to characterize the failure rate of execution records in the historical execution log that are similar to the combination of hit dimensions of the structured query intent; and All values ​​have been normalized and range from [0,1]. Normalized weights for dimensional span risk; Normalized weights for pattern difference risk; Normalized weights for cross-table join risk; To calculate the normalized weights for the mixed risks in the statistical details; The normalized weights for historical error risk are defined, with each weight being no less than 0 and the sum being 1.

4. The heterogeneous database query risk routing and task graph execution method according to claim 1, characterized in that, The preset threshold includes a first threshold and a second threshold, wherein the first threshold is less than the second threshold; the step of routing and selecting a single structured query language path, a hybrid path, or a constrained agent task graph path based on the comparison result between the heterogeneous mode risk score and the preset threshold specifically includes: When the heterogeneous pattern risk score is less than the first threshold, the routing is selected using a single structured query language path; When the heterogeneous pattern risk score is greater than or equal to the first threshold and less than the second threshold, a hybrid path is selected for routing. When the heterogeneous pattern risk score is greater than or equal to the second threshold, the route selection is a constrained agent task graph path. The first threshold and the second threshold are determined by the historical validation set.

5. The heterogeneous database query risk routing and task graph execution method according to claim 1, characterized in that, The generation of query task units or combinations of query task units corresponding to the routing selection results specifically includes: When the route is selected as a single structured query language path, a single-node query task unit without dependent edges is generated. When the routing is selected as a mixed path, a combination of query task units is generated, which includes statistical query task units and detailed query task units; When the route is selected as a constrained agent task graph path, a task graph containing data dependency edges and control dependency edges is generated.

6. The heterogeneous database query risk routing and task graph execution method according to claim 5, characterized in that, When the routing is a hybrid path, a control dependency edge is established between the statistical query task unit and the detailed query task unit. The control dependency edge is used to skip the execution of the detailed query task unit when the execution result of the statistical query task unit is empty or zero.

7. The heterogeneous database query risk routing and task graph execution method according to claim 5, characterized in that, When the route selection is a constrained agent task graph path, the task graph includes object location query task units and two or more information dimension query task units that depend on the object location query task units respectively; each information dimension query task unit receives the object primary key output by the object location query task unit as a filtering condition through the data dependency edge.

8. The heterogeneous database query risk routing and task graph execution method according to claim 1, characterized in that, The query task unit includes information dimension identifier, operation type identifier, target physical table name, candidate field set, filtering conditions, sorting rules, result quantity limit, candidate association relationship, and repair strategy identifier; The step of performing local validity checks on the query task unit before execution on the heterogeneous database specifically includes: Verify whether the target physical table of the query task unit exists in the dimension-to-physical table mapping based on the heterogeneous database schema information; Verify whether each field in the candidate field set of the query task unit belongs to the valid field set of the target physical table; Verify whether the field types in the filter conditions of the query task unit are compatible with the corresponding types in the field type constraints; Verify whether the sorting field in the sorting rule of the query task unit belongs to the set of valid fields in the target physical table; Verify whether the candidate associations of the query task unit are allowed associations.

9. The heterogeneous database query risk routing and task graph execution method according to claim 1, characterized in that, The process of performing partial repair or unit circuit breaking on query task units that fail local validity verification specifically includes: For query task units that fail local validity checks, a set of candidate repair actions is generated. The candidate repair actions include field alias replacement, field pruning, target table rebinding, and unit circuit breaking. Calculate the estimated cost of each candidate repair action in the candidate repair action set, and select the candidate repair action with the lowest estimated cost to execute; When the selected candidate repair action is field alias replacement, the field names that fail the local validity check in the candidate field set of the query task unit will be replaced with the valid physical field names determined by the field alias mapping relationship; When the selected candidate repair action is field pruning, remove fields that fail the local validity check from the candidate field set of the query task unit; When the selected candidate repair action is target table rebinding, the target physical table name of the query task unit will be replaced with a valid physical table name that matches the current information dimension in the heterogeneous database schema information. When the selected candidate repair action is unit circuit breaking, the query task unit is marked as circuit breaking. The query task unit marked as circuit breaking does not generate structured query language and is not sent to the heterogeneous database.

10. A heterogeneous database query risk routing and task graph execution system, characterized in that, include: The structured semantic parsing module is used to obtain natural language query requests and call the large language model to parse the natural language query requests into structured query intents. The structured query intents include the target object, the hit information dimensions, and the query requirement features. The large language model does not directly generate executable structured query language. The heterogeneous database schema maintenance module is used to read heterogeneous database schema information, which includes the mapping from dimensions to physical tables, the set of legal fields, field type constraints, allowed relationships, field alias mapping, and historical execution logs. The heterogeneous pattern risk assessment module is used to calculate the heterogeneous pattern risk score based on the structured query intent and heterogeneous database pattern information. The query path routing module is used to select a single structured query language path, a hybrid path, or a constrained agent task graph path based on the comparison result between the heterogeneous pattern risk score and the preset threshold. The constrained agent task graph generation module is used to generate query task units or combinations of query task units corresponding to the routing selection results. The combination of query task units consists of two or more query task units, and the query task unit is the smallest execution unit that can be independently verified and scheduled. The validity verification module is used to perform local validity verification on the query task unit before execution on the heterogeneous database; The repair and circuit breaker module is used to perform partial repair or circuit breaker on query task units that fail local validity verification. The query scheduling and execution module is used to schedule and execute query task units that have passed local validity checks or repairs. The query result package aggregation module is used to aggregate the execution results of each query task unit into a query result package and output it. The query result package includes the execution result of each query task unit, the source table identifier, the repair status, and the failure status.