Data table selection method and device, electronic equipment and storage medium
By decomposing natural language query requests and utilizing foreign key relationship graphs and reinforcement learning to optimize multi-table join paths, the problem of path breakage and redundant connections in multi-table join scenarios is solved, achieving highly accurate data table selection.
Patent Information
- Application Number
- CN202511713103.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-11-20
- Publication Date
- 2026-02-27
AI Technical Summary
Existing technologies are not accurate enough in selecting tables in multi-table join scenarios, cannot effectively deduce multi-hop join paths, and are difficult to adapt to the long chain logic deduction requirements of multi-hop foreign key dependencies in complex database environments.
By acquiring natural language query requests, atomic operations are decomposed, and a reinforcement learning action space and reward function are constructed using foreign key relationship graphs. Multi-table connection paths are optimized, and foreign key topology features are encoded by cross-modal attention mechanisms and graph neural networks. Textual, structural, and statistical modal information are dynamically fused to optimize candidate table selection.
It improves the accuracy of table selection in multi-table join scenarios, reduces path breakage and redundant connections, and enhances natural language interaction capabilities in complex database environments.
Smart Images

Figure CN121579474A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and more specifically, to a method, apparatus, electronic device, and storage medium for selecting a data table. Background Technology
[0002] Currently, with the continuous development of databases, their capacity is also increasing. However, in some cases, only a portion of the database tables needs to be retrieved, not the entire database content. Therefore, static table selection strategies based on rule templates or single-modality retrieval can be adopted. These strategies rely on fixed rules or single-modality text similarity matching, that is, using keyword matching or text similarity calculation to directly map user queries to database table names or column names. However, they ignore the structural relationships and statistical characteristics between tables, resulting in insufficient accuracy in table selection in multi-table join scenarios. For example, when queries involve fields with the same name or complex foreign key dependencies, relying solely on text matching can easily confuse table ownership and cannot effectively deduce multi-hop join paths, making it difficult to adapt to the long chain logic derivation requirements of multi-hop foreign key dependencies in complex database environments. Summary of the Invention
[0003] The purpose of some embodiments of this application is to provide a method, apparatus, electronic device, and storage medium for selecting data tables. Through the technical solutions of the embodiments of this application, a natural language query request is obtained; the query request is decomposed into atomic operations to obtain key fields; based on a pre-established foreign key relationship graph, a target query path corresponding to the key fields is searched in a pre-stored database; and based on the target query path, a target data table corresponding to the key fields is determined. The target data table includes the key fields and the data content corresponding to the key fields. In the embodiments of this application, by decomposing natural language queries into atomic operation tasks and constructing a reinforcement learning action space and reward function based on a foreign key constraint graph, multi-table join paths are dynamically optimized through a policy network. The logical coherence of the paths is quantitatively evaluated based on the reinforcement learning reward function, thereby systematically solving the problem of path breakage or redundant connections in multi-table join scenarios, improving the accuracy of table selection in multi-table join scenarios, effectively addressing the natural language interaction needs of highly complex database environments, and possessing broad application prospects.
[0004] Firstly, some embodiments of this application provide a method for selecting a data table, including: Obtain natural language query requests; The query request is decomposed into atomic operations to obtain the key fields in the query request; Based on the pre-established foreign key relationship graph, the target query path corresponding to the key field is found in the pre-stored database; Based on the target query path, a target data table corresponding to the key field is determined, wherein the target data table includes the key field and the data content corresponding to the key field.
[0005] Some embodiments of this application decompose natural language queries into atomic operation tasks, construct an action space and reward function for reinforcement learning based on foreign key constraint graphs, dynamically optimize multi-table join paths through policy networks, and quantitatively evaluate the logical coherence of paths based on the reward function of reinforcement learning. This systematically solves the problem of path breakage or redundant connections in multi-table join scenarios, improves the accuracy of table selection in multi-table join scenarios, effectively meets the natural language interaction needs of highly complex database environments, and has broad application prospects.
[0006] Optionally, the step of searching for the target query path corresponding to the key field in a pre-stored database based on a pre-established foreign key relationship graph includes: Foreign key association information and data type matching rules in the database are used as constraints on the state space and reward function in the reinforcement learning strategy. Based on the constraints, the initial path corresponding to the key field is trimmed to obtain the target query path.
[0007] Some embodiments of this application constrain the path search space through foreign key relationship graphs and quantify the logical coherence of paths based on the reward function of reinforcement learning, thereby systematically solving the problem of path breakage or redundant connection in multi-table association scenarios.
[0008] Optionally, the step of pruning the initial path corresponding to the key field according to the constraints to obtain the target query path includes: During the trimming process of the initial path, the data type and name corresponding to the key field are validated; The target query path is obtained by constructing the path from the key fields that pass the validation.
[0009] Some embodiments of this application rigidly embed logical rules such as database foreign key associations and data type compatibility into reinforcement learning strategies, and introduce a lightweight execution verifier to pre-screen candidate paths to ensure the feasibility of generated paths and execution success rate.
[0010] Optionally, determining the target data table corresponding to the key field based on the target query path includes: Based on the key fields, determine the text data, structured data, and statistical data in the database corresponding to the key fields; The text data, the structured data, and the statistical data are jointly encoded to obtain encoded data; A cross-modal attention mechanism is used to match the encoded data with the database, and the key fields and corresponding data content that are successfully matched are determined as the target data table.
[0011] Some embodiments of this application utilize graph neural networks to encode foreign key topological features, combine statistical embedding vectors to represent data distribution features, and dynamically fuse textual, structural, and statistical modal information through a cross-modal attention mechanism to improve the accuracy of candidate table screening. Optionally, determining the target data table corresponding to the key field based on the target query path includes: Based on the target query path, determine the SQL statement corresponding to the key field; Based on the pre-set index hints, preset generation format, and name modification information, the SQL statement is processed to obtain the processed SQL statement; Based on the processed SQL statement, a target data table corresponding to the key fields is generated.
[0012] Some embodiments of this application optimize the execution performance of generated SQL statements during the SQL generation post-processing stage by using techniques such as injecting index hints, rewriting JOIN types, and automatically completing aliases.
[0013] Secondly, some embodiments of this application provide a data table selection device, including: The acquisition module is used to acquire natural language query requests; The decomposition module is used to perform atomic operations to decompose the query request and obtain the key fields in the query request. The search module is used to search for the target query path corresponding to the key field in a pre-stored database based on a pre-established foreign key relationship graph. The determination module is used to determine the target data table corresponding to the key field based on the target query path, wherein the target data table includes the key field and the data content corresponding to the key field.
[0014] Some embodiments of this application decompose natural language queries into atomic operation tasks, construct an action space and reward function for reinforcement learning based on foreign key constraint graphs, dynamically optimize multi-table join paths through policy networks, and quantitatively evaluate the logical coherence of paths based on the reward function of reinforcement learning. This systematically solves the problem of path breakage or redundant connections in multi-table join scenarios, improves the accuracy of table selection in multi-table join scenarios, effectively meets the natural language interaction needs of highly complex database environments, and has broad application prospects.
[0015] Optionally, the search module is used to: Foreign key association information and data type matching rules in the database are used as constraints on the state space and reward function in the reinforcement learning strategy. Based on the constraints, the initial path corresponding to the key field is trimmed to obtain the target query path.
[0016] Some embodiments of this application constrain the path search space through foreign key relationship graphs and quantify the logical coherence of paths based on the reward function of reinforcement learning, thereby systematically solving the problem of path breakage or redundant connection in multi-table association scenarios.
[0017] Optionally, the search module is used to: During the trimming process of the initial path, the data type and name corresponding to the key field are validated; The target query path is obtained by constructing the path from the key fields that pass the validation.
[0018] Some embodiments of this application rigidly embed logical rules such as database foreign key associations and data type compatibility into reinforcement learning strategies, and introduce a lightweight execution verifier to pre-screen candidate paths to ensure the feasibility of generated paths and execution success rate.
[0019] Optionally, the determining module is configured to: Based on the key fields, determine the text data, structured data, and statistical data in the database corresponding to the key fields; The text data, the structured data, and the statistical data are jointly encoded to obtain encoded data; A cross-modal attention mechanism is used to match the encoded data with the database, and the key fields and corresponding data content that are successfully matched are determined as the target data table.
[0020] Some embodiments of this application utilize graph neural networks to encode foreign key topological features, combine statistical embedding vectors to represent data distribution features, and dynamically fuse textual, structural, and statistical modal information through a cross-modal attention mechanism to improve the accuracy of candidate table screening. Optionally, the determining module is configured to: Based on the target query path, determine the SQL statement corresponding to the key field; Based on the pre-set index hints, preset generation format, and name modification information, the SQL statement is processed to obtain the processed SQL statement; Based on the processed SQL statement, a target data table corresponding to the key fields is generated.
[0021] Some embodiments of this application optimize the execution performance of generated SQL statements during the SQL generation post-processing stage by using techniques such as injecting index hints, rewriting JOIN types, and automatically completing aliases.
[0022] Thirdly, some embodiments of this application provide an electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, can implement the data table selection method as described in any embodiment of the first aspect.
[0023] Fourthly, some embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, can implement the data table selection method as described in any embodiment of the first aspect.
[0024] Fifthly, some embodiments of this application provide a computer program product, the computer program product including a computer program, wherein when the computer program is executed by a processor, it can implement the data table selection method as described in any embodiment of the first aspect. Attached Figure Description
[0025] To more clearly illustrate the technical solutions of some embodiments of this application, the accompanying drawings used in some embodiments of this application will be briefly described below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0026] Figure 1 A flowchart illustrating a data table selection method provided in an embodiment of this application; Figure 2 A flowchart illustrating another data table selection method provided in this application embodiment; Figure 3 A schematic diagram of the structure of a data table selection device provided in an embodiment of this application; Figure 4This is a schematic diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0027] The technical solutions of some embodiments of this application will now be described with reference to the accompanying drawings.
[0028] It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures. Furthermore, in the description of this application, terms such as "first," "second," etc., are used only to distinguish descriptions and should not be construed as indicating or implying relative importance.
[0029] Currently, with the continuous development of databases, their capacity is also increasing. However, in some cases, it is only necessary to retrieve a portion of the tables in the database, rather than the entire database content. Therefore, a static table selection strategy based on rule templates or single-modality retrieval can be adopted. This strategy relies on fixed rules or single-modality text similarity matching, that is, it relies on keyword matching or text similarity calculation to directly map user queries to database table names or column names. However, it ignores the structural relationships and statistical characteristics between tables, resulting in insufficient accuracy in table selection in multi-table join scenarios. For example, when queries involve fields with the same name or complex foreign key dependencies, relying solely on text matching can easily confuse table attribution and cannot effectively deduce multi-hop join paths. This makes it difficult to adapt to the long-chain logical deduction requirements of multi-hop foreign key dependencies in complex database environments. In view of this, some embodiments of this application provide a data table selection method. This method includes obtaining a natural language query request; performing atomic operations to decompose the query request to obtain key fields in the query request; searching for the target query path corresponding to the key fields in a pre-stored database based on a pre-established foreign key relationship graph; and determining the target data table corresponding to the key fields based on the target query path. The target data table includes the key fields and the data content corresponding to the key fields. In the embodiments of this application, by decomposing the natural language query into atomic operation tasks and constructing a reinforcement learning action space and reward function based on the foreign key constraint graph, the multi-table join paths are dynamically optimized through a policy network. The logical coherence of the paths is quantitatively evaluated based on the reinforcement learning reward function, thereby systematically solving the problem of path breakage or redundant connections in multi-table join scenarios, improving the accuracy of table selection in multi-table join scenarios, effectively meeting the natural language interaction requirements of highly complex database environments, and having broad application prospects.
[0030] like Figure 1 As shown, an embodiment of this application provides a method for selecting a data table, the method comprising: S101. Obtain the query request in natural language; S102. Perform atomic operations to decompose the query request and obtain the key fields in the query request; Specifically, the terminal device obtains the user's natural language query request, performs semantic parsing and intent recognition on the natural language query request, and then performs atomic operation decomposition, that is, splits it into multiple operations that cannot be disrupted or switched. In this way, the key fields, tables or matching conditions in the query request can be obtained.
[0031] S103. Based on the pre-established foreign key relationship graph, find the target query path corresponding to the key field in the pre-stored database; Specifically, the terminal device pre-establishes a relationship graph of various foreign keys in the database. Foreign keys in the database are constraint mechanisms used in relational databases to establish data relationships between tables. They ensure data consistency and integrity between child tables and foreign key tables by referencing the primary key or unique key of the parent table. Their field values must exactly match the corresponding fields in the parent table, and cross-table relationships are achieved through syntax structures (such as FOREIGN KEY(Sno) REFERENCES Student(Sno)), supporting cascading update / delete operations.
[0032] After obtaining the key fields, the terminal device searches for the target query path corresponding to the foreign key relationship graph in the pre-stored database. In this way, the action space and reward function of reinforcement learning are constructed based on the foreign key constraint graph, and the multi-table join path is dynamically optimized through the policy network.
[0033] S104. Based on the target query path, determine the target data table corresponding to the key fields, wherein the target data table includes the key fields and the data content corresponding to the key fields.
[0034] Subsequently, after obtaining the target query path, the terminal device finds the target data table corresponding to the key field in the pre-stored database. That is, the target data table includes the key field and the data content corresponding to the key field.
[0035] Some embodiments of this application decompose natural language queries into atomic operation tasks, construct an action space and reward function for reinforcement learning based on foreign key constraint graphs, dynamically optimize multi-table join paths through policy networks, and quantitatively evaluate the logical coherence of paths based on the reward function of reinforcement learning. This systematically solves the problem of path breakage or redundant connections in multi-table join scenarios, improves the accuracy of table selection in multi-table join scenarios, effectively meets the natural language interaction needs of highly complex database environments, and has broad application prospects.
[0036] Another embodiment of this application further explains the method for selecting data tables provided in the above embodiments.
[0037] like Figure 2 As shown, the dynamic step decomposition module performs semantic parsing and intent recognition on user query requests, parsing the user query requests into atomic operation tasks. Combined with reinforcement learning algorithms constrained by foreign key relationship graphs, the candidate paths are dynamically optimized. The logical coherence is quantified by a reward mechanism. Natural language queries are decomposed into atomic operation tasks, and fields, tables, and conditions in the query requests are extracted. Based on the foreign key constraint graph, the action space and reward function of reinforcement learning are constructed, and the multi-table join paths are dynamically optimized through a policy network.
[0038] Existing technologies rely on fixed rules or shallow text matching to generate table join paths, which cannot adapt to complex scenarios with multi-hop foreign key dependencies. This application's embodiments decompose queries into atomic operations through dynamic task decomposition and dynamically optimize paths based on reinforcement learning algorithms constrained by foreign key relationship graphs. By constraining the path search space through foreign key graphs and combining reward mechanisms such as coverage field integrity and foreign key relevance, the accuracy of path derivation in multi-table join scenarios is significantly improved, effectively reducing invalid join operations and enhancing the logical coherence of complex queries.
[0039] This application embodiment uses a dynamic step decomposition module to parse natural language queries layer by layer into atomic operation tasks, including field location, candidate table filtering, and association path derivation. It also combines a logical path reinforcement learning algorithm to dynamically optimize candidate connection paths. This dynamic task decomposition and path optimization mechanism improves the table selection accuracy in multi-table association scenarios. Compared to existing static table selection strategies that rely on fixed rules or single similarity matching, this application embodiment constrains the path search space through a foreign key relationship graph and quantifies the logical coherence of paths based on a reinforcement learning reward function, thereby systematically solving the problem of path breakage or redundant connections in multi-table association scenarios.
[0040] Optionally, based on a pre-established foreign key relationship graph, the target query path corresponding to the key field is searched in a pre-stored database, including: Foreign key association information and data type matching rules in the database are used as constraints on the state space and reward function in the reinforcement learning strategy. Based on the constraints, the initial path corresponding to the key fields is trimmed to obtain the target query path.
[0041] Some embodiments of this application constrain the path search space through foreign key relationship graphs and quantify the logical coherence of paths based on the reward function of reinforcement learning, thereby systematically solving the problem of path breakage or redundant connection in multi-table association scenarios.
[0042] Optionally, based on constraints, the initial path corresponding to the key fields is trimmed to obtain the target query path, including: During the initial path trimming process, the data type and name corresponding to the key fields are validated; The target query path is obtained by constructing the path from the key fields that pass the validation.
[0043] Specifically, the logical path reinforcement learning optimization module in the terminal device includes candidate path generation, reinforcement learning strategy, and execution verifier. It hard-embeds foreign key association and type matching rules into the reinforcement learning state space and reward function, and introduces a lightweight execution verifier to pre-screen candidate paths, force the policy network to meet logical constraints, dynamically prune illegal paths, hard-embed logical rules such as database foreign key association and data type compatibility into the reinforcement learning strategy, and introduces a lightweight execution verifier to pre-screen candidate paths to ensure the feasibility of generated paths and execution success rate.
[0044] The existing technology does not embed database logical rules into the reinforcement learning strategy, resulting in infeasible generated paths. In this embodiment, logical rules are forcibly embedded into the reinforcement learning state space and reward function, and an execution verifier is introduced to pre-screen paths. This realizes the transformation from decoupling reinforcement learning and logical constraints to deep coupling, significantly improving the execution success rate of generated paths, greatly reducing the logical error rate, and improving path optimization efficiency, thus achieving dual protection of logical correctness and execution efficiency.
[0045] The embodiments of this application deeply embed database logical constraints in the reinforcement learning strategy design, taking rules such as foreign key association and data type matching as hard constraints on the state space and reward function, and introducing a lightweight execution verifier to pre-screen candidate paths. The logical constraint-driven reinforcement learning framework ensures the feasibility and execution efficiency of the generated paths.
[0046] Existing technologies, due to the lack of joint optimization of logical constraints and strategy training, are prone to generating syntactically correct but execution-failed SQL. The embodiments of this application improve the logical correctness and execution feasibility of the generated results by dynamically pruning candidate paths that violate foreign key or type rules, and by combining a reward mechanism to prioritize the connection order that covers complete semantics and conforms to the execution rules.
[0047] Some embodiments of this application rigidly embed logical rules such as database foreign key associations and data type compatibility into reinforcement learning strategies, and introduce a lightweight execution verifier to pre-screen candidate paths to ensure the feasibility of generated paths and execution success rate.
[0048] Optionally, based on the target query path, determine the target data table corresponding to the key fields, including: Based on the key fields, determine the text data, structured data, and statistical data in the database that correspond to the key fields; Text data, structured data, and statistical data are jointly encoded to obtain encoded data; A cross-modal attention mechanism is used to match coded data with the database, and the key fields and corresponding data content that are successfully matched are identified as the target data table.
[0049] In this embodiment, a graph neural network is used to encode foreign key topological features, combined with statistical embedding vectors to represent data distribution features. A cross-modal attention mechanism dynamically fuses textual, structural, and statistical modal information to achieve multi-modal metadata fusion retrieval, improving the accuracy of candidate table selection. The textual, structural, and statistical modalities of database metadata are jointly encoded, and multi-dimensional information is dynamically fused through a cross-modal attention mechanism to achieve multiple adaptations between retrieval results and query semantics, structural constraints, and statistical features. A graph neural network is used to perform structure-aware encoding of foreign key topological relationships between tables, generating vector representations that combine local column semantics with global table associations.
[0050] Existing technologies only match text similarity tables / column names, ignoring structural and statistical features. This application's embodiments employ a cross-modal attention mechanism using text modality encoding, structural modality encoding, and statistical modality embedding. It encodes foreign key topological relationships using graph neural networks and represents data distribution using statistical embedding vectors. Furthermore, it dynamically fuses multi-dimensional features using the cross-modal attention mechanism, upgrading from single-modal retrieval to multi-modal fusion retrieval. This significantly reduces the probability of mismatches with identically named fields, improves the adaptability of implicit conditions (such as numerical range filtering), and achieves a qualitative leap in candidate table selection accuracy, outperforming traditional single-modal retrieval methods. This application's embodiments also utilize a multi-modal metadata vectorization module to jointly encode the textual, structural, and statistical features of database metadata and dynamically fuse multi-dimensional information using the cross-modal attention mechanism. Existing technologies rely solely on textual similarity calculations, failing to distinguish the logical affiliation of fields with the same name in different tables and neglecting the impact of statistical features on table selection decisions. Multimodal metadata fusion enhances the semantic adaptability of search results to query requirements. By modeling foreign key topological relationships between tables through graph neural networks and combining statistical embedding vectors to capture implicit semantics, the retrieval process can comprehensively consider semantic matching degree, structural correlation, and data distribution characteristics, thereby accurately filtering candidate tables and fields.
[0051] Some embodiments of this application utilize graph neural networks to encode foreign key topological features, combine statistical embedding vectors to represent data distribution features, and dynamically fuse textual, structural, and statistical modal information through a cross-modal attention mechanism to improve the accuracy of candidate table screening. Furthermore, the terminal device also includes a phased generation and dynamic verification mechanism. A semantic correction module is embedded during the syntax tree construction phase, combining backtracking path optimization and local correction to achieve error location and real-time feedback iteration. Semantic correction and execution performance optimization are embedded in stages during the SQL generation process, combined with backtracking path reselection to achieve localized error correction. By constructing an SQL syntax tree and then using a semantic correction module to trigger errors, the path for generating SQL statements is backtracked and optimized.
[0052] The lack of intermediate verification in some technologies leads to the propagation of errors throughout the entire chain. In this application, the embodiment embeds a semantic correction module in the syntax tree construction stage and combines backtracking path reselection and local correction to realize the evolution from end-to-end generation to a phased dynamic verification mechanism. The first-pass rate of complex query generation results is significantly improved, the efficiency of error location and correction is improved, and the robustness and fault tolerance of the system are significantly enhanced.
[0053] This application's embodiments achieve error localization and real-time correction through a phased generation and dynamic verification mechanism. This solves the problem that existing end-to-end generation technologies, due to the lack of intermediate process verification, can cause deviations in the entire chain due to early errors. It embeds execution feasibility prediction in the path optimization stage and checks data type compatibility, alias conflicts, and other issues through a semantic correction module in the SQL syntax tree construction stage. Combined with backtracking path reselection and local syntax correction, it ensures the dual correctness of the generated results at both the logical and execution levels. The phased generation and dynamic verification mechanism improves the robustness and fault tolerance of the generation process.
[0054] Optionally, based on the target query path, determine the target data table corresponding to the key fields, including: Based on the target query path, determine the SQL statement corresponding to the key fields; Based on the pre-set index hints, preset generation format, and name modification information, the SQL statement is processed to obtain the processed SQL statement; Based on the processed SQL statement, generate the target data table corresponding to the key fields.
[0055] Specifically, in this embodiment of the application, the input index prompt information, as well as the preset generation format (join type) and name modification information, and the statistical information drive optimization—executable SQL output.
[0056] Existing technologies typically only focus on syntactic correctness without specifically optimizing the execution plan. This application's embodiments utilize a multi-dimensional performance optimization mechanism to improve the execution efficiency of generated SQL. During the SQL generation post-processing stage, techniques such as injecting index hints, rewriting JOIN types, and automatically completing aliases are used to optimize the execution performance of the generated SQL statements. Based on database statistics, the JOIN order and index usage strategy are dynamically adjusted to generate SQL statements that balance correctness and execution efficiency.
[0057] Some embodiments of this application optimize the execution performance of generated SQL statements during the SQL generation post-processing stage by using techniques such as injecting index hints, rewriting JOIN types, and automatically completing aliases.
[0058] In this embodiment, the dynamic task decomposition module can use sequence labeling or rule templates based on pre-trained models to force splitting queries, replacing the dependency syntax and knowledge graph parsing of the original scheme; multimodal metadata retrieval can replace the fusion strategy with feature splicing, gating mechanisms or random walk graph embedding, and supports statistical feature processing methods such as binning encoding; the logical path optimization algorithm can be extended to non-reinforcement learning methods such as Monte Carlo tree search and genetic algorithms; the execution verification mechanism allows the use of static dependency analysis or syntax tree abstraction interpretation to replace dynamic simulation; the metadata encoding model can be replaced with Transformer, CNN or traditional statistical methods.
[0059] This application's embodiments systematically address the shortcomings of existing technologies in path generation, retrieval accuracy, logical feasibility, and error control through dynamic path derivation, multimodal fusion retrieval, logical constraint-driven optimization, and phased verification mechanisms. The improved technology significantly enhances table selection accuracy, SQL execution success rate, and generation efficiency in multi-table join scenarios, effectively meeting the natural language interaction needs of highly complex database environments and possessing broad application prospects.
[0060] It should be noted that each of the implementable methods in this embodiment can be implemented individually or in any combination without conflict. This application does not limit this.
[0061] Another embodiment of this application provides a data table selection device for executing the data table selection method provided in the above embodiments.
[0062] like Figure 3 The diagram shown is a structural schematic of a data table selection device provided in an embodiment of this application. The data table selection device includes an acquisition module 301, a disassembly module 302, a search module 303, and a determination module 304, wherein: The acquisition module 301 is used to acquire natural language query requests; The decomposition module 302 is used to perform atomic operations to decompose the query request and obtain the key fields in the query request; The lookup module 303 is used to search for the target query path corresponding to the key field in the pre-stored database based on the pre-established foreign key relationship graph. The determination module 304 is used to determine the target data table corresponding to the key fields based on the target query path. The target data table includes the key fields and the data content corresponding to the key fields.
[0063] Regarding the apparatus in this embodiment, the specific manner in which each module performs its operations has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0064] Some embodiments of this application decompose natural language queries into atomic operation tasks, construct an action space and reward function for reinforcement learning based on foreign key constraint graphs, dynamically optimize multi-table join paths through policy networks, and quantitatively evaluate the logical coherence of paths based on the reward function of reinforcement learning. This systematically solves the problem of path breakage or redundant connections in multi-table join scenarios, improves the accuracy of table selection in multi-table join scenarios, effectively meets the natural language interaction needs of highly complex database environments, and has broad application prospects.
[0065] Another embodiment of this application further explains the data table selection device provided in the above embodiments.
[0066] Optionally, the lookup module is used for: Foreign key association information and data type matching rules in the database are used as constraints on the state space and reward function in the reinforcement learning strategy. Based on the constraints, the initial path corresponding to the key fields is trimmed to obtain the target query path.
[0067] Some embodiments of this application constrain the path search space through foreign key relationship graphs and quantify the logical coherence of paths based on the reward function of reinforcement learning, thereby systematically solving the problem of path breakage or redundant connection in multi-table association scenarios.
[0068] Optionally, the lookup module is used for: During the initial path trimming process, the data type and name corresponding to the key fields are validated; The target query path is obtained by constructing the path from the key fields that pass the validation.
[0069] Some embodiments of this application rigidly embed logical rules such as database foreign key associations and data type compatibility into reinforcement learning strategies, and introduce a lightweight execution verifier to pre-screen candidate paths to ensure the feasibility of generated paths and execution success rate.
[0070] Optionally, a module is defined for: Based on the key fields, determine the text data, structured data, and statistical data in the database that correspond to the key fields; Text data, structured data, and statistical data are jointly encoded to obtain encoded data; A cross-modal attention mechanism is used to match coded data with the database, and the key fields and corresponding data content that are successfully matched are identified as the target data table.
[0071] Some embodiments of this application utilize graph neural networks to encode foreign key topological features, combine statistical embedding vectors to represent data distribution features, and dynamically fuse textual, structural, and statistical modal information through a cross-modal attention mechanism to improve the accuracy of candidate table screening. Optionally, a module is defined for: Based on the target query path, determine the SQL statement corresponding to the key fields; Based on the pre-set index hints, preset generation format, and name modification information, the SQL statement is processed to obtain the processed SQL statement; Based on the processed SQL statement, generate the target data table corresponding to the key fields.
[0072] Some embodiments of this application optimize the execution performance of generated SQL statements during the SQL generation post-processing stage by using techniques such as injecting index hints, rewriting JOIN types, and automatically completing aliases.
[0073] Regarding the apparatus in this embodiment, the specific manner in which each module performs its operations has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0074] It should be noted that each of the implementable methods in this embodiment can be implemented individually or in any combination without conflict. This application does not limit this.
[0075] This application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, can perform the operation of any of the methods corresponding to the data table selection methods provided in the above embodiments.
[0076] This application also provides a computer program product, which includes a computer program, wherein when the computer program is executed by a processor, it can implement the operation of any of the methods corresponding to the data table selection methods provided in the above embodiments.
[0077] like Figure 4 As shown, some embodiments of this application provide an electronic device 400, which includes a memory 410, a processor 420, and a computer program stored in the memory 410 and executable on the processor 420. When the processor 420 reads the program from the memory 410 via a bus 430 and executes the program, it can implement any of the methods included in the above-described data table selection method.
[0078] Processor 420 can process digital signals and may include various computing architectures. For example, it may be a complex instruction set computer architecture, a reduced instruction set computer architecture, or an architecture that implements multiple instruction set combinations. In some examples, processor 420 may be a microprocessor.
[0079] Memory 410 can be used to store instructions executed by processor 420 or data related to the execution of instructions. These instructions and / or data may include code for implementing some or all of the functions of one or more modules described in the embodiments of this application. The processor 420 of this disclosure embodiment can be used to execute instructions in memory 410 to implement the methods shown above. Memory 410 includes dynamic random access memory, static random access memory, flash memory, optical memory, or other memories well known to those skilled in the art.
[0080] The above are merely embodiments of this application and are not intended to limit the scope of protection of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application. It should be noted that similar reference numerals and letters in the following figures indicate similar items; therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0081] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0082] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
Claims
1. A method of selecting a data table, characterized by, The method includes: Obtain natural language query requests; The query request is decomposed into atomic operations to obtain the key fields in the query request; Based on the pre-established foreign key relationship graph, the target query path corresponding to the key field is found in the pre-stored database; Based on the target query path, a target data table corresponding to the key field is determined, wherein the target data table includes the key field and the data content corresponding to the key field.
2. The data table selection method according to claim 1, characterized in that, The step of searching for the target query path corresponding to the key field in a pre-stored database based on a pre-established foreign key relationship graph includes: Foreign key association information and data type matching rules in the database are used as constraints on the state space and reward function in the reinforcement learning strategy. Based on the constraints, the initial path corresponding to the key field is trimmed to obtain the target query path.
3. The data table selection method according to claim 2, characterized in that, The step of pruning the initial path corresponding to the key field according to the constraints to obtain the target query path includes: During the trimming process of the initial path, the data type and name corresponding to the key field are validated; The target query path is obtained by constructing the path from the key fields that pass the validation.
4. The data table selection method according to claim 3, characterized in that, The step of determining the target data table corresponding to the key field based on the target query path includes: Based on the key fields, determine the text data, structured data, and statistical data in the database corresponding to the key fields; The text data, the structured data, and the statistical data are jointly encoded to obtain encoded data; A cross-modal attention mechanism is used to match the encoded data with the database, and the key fields and corresponding data content that are successfully matched are determined as the target data table.
5. The data table selection method according to claim 4, characterized in that, The step of determining the target data table corresponding to the key field based on the target query path includes: Based on the target query path, determine the SQL statement corresponding to the key field; Based on the pre-set index hints, preset generation format, and name modification information, the SQL statement is processed to obtain the processed SQL statement; Based on the processed SQL statement, a target data table corresponding to the key fields is generated.
6. A data table selection device, characterized in that, The device includes: The acquisition module is used to acquire natural language query requests; The decomposition module is used to perform atomic operations to decompose the query request and obtain the key fields in the query request. The search module is used to search for the target query path corresponding to the key field in a pre-stored database based on a pre-established foreign key relationship graph. The determination module is used to determine the target data table corresponding to the key field based on the target query path, wherein the target data table includes the key field and the data content corresponding to the key field.
7. The data table selection device according to claim 6, characterized in that, The search module is used for: Foreign key association information and data type matching rules in the database are used as constraints on the state space and reward function in the reinforcement learning strategy. Based on the constraints, the initial path corresponding to the key field is trimmed to obtain the target query path.
8. The data table selection device according to claim 7, characterized in that, The search module is used for: During the trimming process of the initial path, the data type and name corresponding to the key field are validated; The target query path is obtained by constructing the path from the key fields that pass the validation.
9. The data table selection device according to claim 8, characterized in that, The determining module is used for: Based on the key fields, determine the text data, structured data, and statistical data in the database corresponding to the key fields; The text data, the structured data, and the statistical data are jointly encoded to obtain encoded data; A cross-modal attention mechanism is used to match the encoded data with the database, and the key fields and corresponding data content that are successfully matched are determined as the target data table.
10. The data table selection device according to claim 9, characterized in that, The determining module is used for: Based on the target query path, determine the SQL statement corresponding to the key field; Based on the pre-set index hints, preset generation format, and name modification information, the SQL statement is processed to obtain the processed SQL statement; Based on the processed SQL statement, a target data table corresponding to the key fields is generated.
11. An electronic device, characterized in that, It includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, it can implement the data table selection method according to any one of claims 1-5.
12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, characterized in that, when the program is executed by a processor, it can implement the data table selection method according to any one of claims 1-5.