Method and apparatus for multi-factor quality assessment and dynamic resource allocation for SQL statements
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-22
- Publication Date
- 2026-08-11
AI Technical Summary
[0005]基于此,有必要针对上述技术问题,提供一种面向SQL语句的多因子质量评估与动态资源调配方法及装置,以解决上述现有技术中存在的至少一个问题
[0046]上述面向SQL语句的多因子质量评估与动态资源调配方法及装置,其方法实现,包括:对待验证SQL语句进行可靠性验证;若验证通过,基于目标用户的历史行为和权限信息,动态计算用户可信度;以及基于多维度评分函数以及知识检索空间,对待验证SQL语句进行质量评分,得到SQL质量评分;基于所述用户可信度以及所述SQL质量评分,动态调整计算资源分配策略,以基于调整后的资源分配策略执行对应操作。本申请实施例中,一方面,通过先对SQL语句进行可靠性验证、再结合多维度评分函数与结构化知识检索空间开展全维度质量评估,不仅能识别传统静态检查难以覆盖的语义偏差、性能瓶颈问题,还能拦截高危操作与违规语句,大幅降低SQL语句执行失败率及数据库安全风险,提升大模型生成SQL语句的执行可靠性;另一方面,基于用户多维度历史行为数据与权限信息动态计算用户可信度,实现了对不同可信度用户的差异化识别,同时,依托用户可信度与SQL质量评分双因子动态调整资源分配策略,既能为高可信度用户的高质量SQL语句优先分配资源以保障执行效率,又能对低可信度用户的低质量SQL语句合理管控资源消耗,显著提升多租户、高并发场景下数据库的资源利用率与运行稳定性。
Smart Images

Figure CN121210482B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database management technology, and in particular to a method and apparatus for multi-factor quality assessment and dynamic resource allocation oriented towards SQL statements. Background Technology
[0002] As a structured query language, SQL statements directly impact the stability, security, and resource utilization efficiency of database systems through their reliability and execution control efficiency. Related technological research and applications have already established a certain foundation. In recent years, with the rapid development of Large Language Models (LLMs) in the fields of natural language understanding and program generation, their application in database interaction tasks has become increasingly widespread, providing a new technical path for the automated generation of SQL statements. Current mainstream large-model SQL statement generation methods are mostly based on instruction tuning or in-context learning techniques. The core process is as follows: receiving a natural language query (NLQ) input from the user, parsing the query intent contained within it through the large model, and automatically generating the corresponding SQL statement by combining it with database schema information. The generated SQL statement is then submitted to the database for execution, and finally, the query results are returned to the user.
[0003] However, large-scale models are essentially statistical inference models, and their output is affected by factors such as the distribution of training data and model parameter settings, resulting in uncertainty and uncontrollability. This directly leads to multiple quality and security issues in the generated SQL statements: First, if the database schema information in the training data of a large-scale model is insufficiently covered, or if there are deviations in the parsing of the user's natural language intent, it is easy to generate SQL statements containing invalid table references, field matching errors, etc., leading to query execution failure. Second, when dealing with complex query scenarios (such as multi-table JOINs and nested queries), the model may generate inefficient query structures, significantly increasing the consumption of database computing resources and causing performance bottlenecks. Third, some generated results may contain high-risk operation statements such as DELETE and DROP, or contain content that violates preset access control policies, posing potential risks to the data security and operational stability of the database.
[0004] Furthermore, in practical database applications, different users exhibit significant differences in their operational behavior characteristics (such as usage frequency and historical operational compliance) and account permission levels, resulting in varying user trust levels and demands for system resources. However, existing database systems lack dynamic evaluation mechanisms and intelligent resource scheduling strategies for generating SQL statements for large models. They cannot make comprehensive decisions based on SQL statement quality and user trust levels, making it difficult to achieve efficient allocation of computing resources while ensuring database security. This restricts the improvement of intelligent management capabilities and operational stability of database systems in large model collaboration scenarios. Summary of the Invention
[0005] Therefore, it is necessary to provide a method and apparatus for multi-factor quality assessment and dynamic resource allocation for SQL statements to address the above-mentioned technical problems, so as to solve at least one of the problems existing in the prior art.
[0006] Firstly, a multi-factor quality assessment and dynamic resource allocation method for SQL statements is provided, including:
[0007] Perform reliability verification on the SQL statement to be verified;
[0008] If the verification passes, the user's credibility is dynamically calculated based on the target user's historical behavior and permission information, and the quality score of the SQL statement to be verified is obtained based on the multi-dimensional scoring function and knowledge retrieval space.
[0009] Based on the user's trustworthiness and the SQL quality score, the computing resource allocation strategy is dynamically adjusted to execute corresponding operations based on the adjusted resource allocation strategy.
[0010] In one possible implementation, dynamically calculating user credibility based on the target user's historical behavior and permission information includes:
[0011] Based on historical behavior scoring association data, historical behavior scoring information is calculated, wherein the historical behavior scoring association data includes at least one of the following: access frequency, query success rate, error frequency, number of violations, response time stability, and high resource low efficiency query ratio.
[0012] Based on the historical behavior scoring information, a historical behavior scoring feature vector is determined;
[0013] The basic features for obtaining permissions are the user context vector and the set of historical behavior trajectories.
[0014] The user's credibility is calculated based on the historical behavior scoring feature vector, the permission base score feature vector, the user context vector, and the historical behavior trajectory set.
[0015] In one possible implementation, the historical behavior scoring association data includes access frequency, query success rate, error frequency, number of violations, response time stability, and the proportion of high-resource, low-efficiency queries. The calculation of historical behavior scoring information based on the historical behavior scoring association data includes:
[0016] An adjustment constant is introduced to control the rate at which the marginal contribution of the access frequency to the historical behavior score decreases.
[0017] Set a penalty intensity parameter for violations, and control the degree to which the number of violations reduces the score of the historical behavior;
[0018] The success rate of the query is positively weighted and the error frequency is negatively weighted. The accuracy of the user's operation is reflected by the comprehensive calculation of the two.
[0019] The response time stability is used as a positive indicator in the calculation to reflect the stability of user operations on system resource consumption.
[0020] The inverse value of the ratio of high-resource, low-efficiency queries is used as an indicator in the calculation to measure the resource utilization efficiency of user operations.
[0021] By integrating and calculating data from various dimensions using pre-defined association rules, historical behavior scoring information is obtained.
[0022] In one possible implementation, the process of scoring the SQL statement to be verified based on a multi-dimensional scoring function and a knowledge retrieval space to obtain an SQL quality score includes:
[0023] Construct a multi-dimensional scoring function set, which includes at least one of the following: syntax compliance scoring function, semantic rationality scoring function, security scoring function, performance prediction scoring function, and large model confidence scoring function;
[0024] Construct a structured knowledge retrieval space, wherein the knowledge retrieval space includes at least one of a syntactic knowledge subspace, a semantic knowledge subspace, a security knowledge subspace, a performance knowledge subspace, and a generative knowledge subspace;
[0025] Based on the corresponding knowledge subspace in the structured knowledge retrieval space, the matching dimension scoring function from the multi-dimensional scoring function set is invoked to calculate the target dimension score.
[0026] The SQL quality score is obtained based on the preset scoring rules and the target dimension score.
[0027] In one possible implementation, the target dimension score includes multiple dimensions, and the process of obtaining the SQL quality score based on preset scoring rules and the target dimension score includes:
[0028] Determine the weight coefficients corresponding to the scores of each of the aforementioned target dimensions;
[0029] The weighted score for each objective dimension is obtained by multiplying the score of each objective dimension by its corresponding weight coefficient.
[0030] The SQL quality score is obtained by summing the weighted scores of all target dimensions.
[0031] In one possible implementation, the dynamic adjustment of computing resource allocation strategy based on the user's trustworthiness and the SQL quality score includes:
[0032] Determine the user's credibility and the level of trust corresponding to the SQL quality score;
[0033] Based on the level of trust, user credibility, and SQL quality score, a priority index is constructed.
[0034] The computing resource allocation strategy is dynamically adjusted based on the aforementioned priority indicators.
[0035] In one possible implementation, after dynamically adjusting the computing resource allocation strategy based on the user trustworthiness and the SQL quality score, the method further includes:
[0036] Once the adjusted resource allocation strategy has been executed, obtain the execution result data and the actual resource consumption data.
[0037] Obtain user evaluation data on the query results of the SQL statement to be verified, and record the rating data and task blocking status.
[0038] The execution result data, actual resource consumption data, evaluation data, scoring data, and task blocking status are cleaned and labeled to construct a feedback sample set;
[0039] The large model is iteratively optimized based on the feedback sample set, wherein the large model is used to generate the SQL statement to be verified.
[0040] Secondly, a multi-factor quality assessment and dynamic resource allocation device for SQL statements is provided, including:
[0041] The reliability verification unit is used to perform reliability verification on the SQL statement to be verified.
[0042] The evaluation unit is used to dynamically calculate the user's credibility based on the target user's historical behavior and permission information if the verification passes, and to score the quality of the SQL statement to be verified based on a multi-dimensional scoring function and knowledge retrieval space, so as to obtain the SQL quality score.
[0043] The resource allocation unit is used to dynamically adjust the computing resource allocation strategy based on the user's trustworthiness and the SQL quality score, so as to execute the corresponding operation based on the adjusted resource allocation strategy.
[0044] Thirdly, a computer device is provided, including a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor, wherein the processor, when executing the computer-readable instructions, implements the steps of the multi-factor quality assessment and dynamic resource allocation method for SQL statements as described above.
[0045] Fourthly, a readable storage medium is provided, which stores computer-readable instructions that, when executed by a processor, implement the steps of the multi-factor quality assessment and dynamic resource allocation method for SQL statements as described above.
[0046] The aforementioned method and apparatus for multi-factor quality assessment and dynamic resource allocation of SQL statements includes the following steps: performing reliability verification on the SQL statement to be verified; if the verification passes, dynamically calculating user credibility based on the target user's historical behavior and permission information; performing quality scoring on the SQL statement to be verified based on a multi-dimensional scoring function and a knowledge retrieval space to obtain an SQL quality score; and dynamically adjusting the computing resource allocation strategy based on the user credibility and the SQL quality score, so as to execute corresponding operations based on the adjusted resource allocation strategy. In this embodiment, on the one hand, by first verifying the reliability of SQL statements and then conducting a comprehensive quality assessment by combining multi-dimensional scoring functions and structured knowledge retrieval space, it can not only identify semantic biases and performance bottlenecks that are difficult to cover by traditional static checks, but also intercept high-risk operations and illegal statements, significantly reducing the SQL statement execution failure rate and database security risks, and improving the execution reliability of SQL statements generated by large models. On the other hand, based on multi-dimensional historical behavior data and permission information of users, user credibility is dynamically calculated, realizing differentiated identification of users with different credibility levels. At the same time, relying on the dual factors of user credibility and SQL quality score to dynamically adjust the resource allocation strategy, it can prioritize the allocation of resources to high-quality SQL statements of high-credibility users to ensure execution efficiency, and reasonably control the resource consumption of low-quality SQL statements of low-credibility users, significantly improving the resource utilization and operational stability of the database in multi-tenant, high-concurrency scenarios. Attached Figure Description
[0047] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0048] Figure 1 This is a flowchart illustrating a method for multi-factor quality assessment and dynamic resource allocation for SQL statements in one embodiment of this application;
[0049] Figure 2 This is a schematic diagram of a multi-factor quality assessment and dynamic resource allocation device for SQL statements in one embodiment of this application;
[0050] Figure 3 This is a schematic diagram of a computer device according to one embodiment of this application. Detailed Implementation
[0051] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0052] In one embodiment, such as Figure 1 As shown, a multi-factor quality assessment and dynamic resource allocation method for SQL statements is provided, including the following steps:
[0053] In step S110, the reliability of the SQL statement to be verified is performed;
[0054] Optionally, the SQL statement to be verified is obtained. This SQL statement can be generated by a Large Language Model (LLM) or derived from user-written scripts or system-automated scripts. Taking the LLM as an example, its core logic for generating SQL statements is based on the mapping relationship between natural language and SQL in the training data, combined with the user-input Natural Language Queries (NLQ) and database schema information, to output the target statement through semantic understanding and syntax generation capabilities. The SQL statement can then be verified for reliability from dimensions such as syntax parsing, semantic verification, and execution plan analysis. Multi-dimensional reliability verification ensures that the SQL statement is semantically logically sound and complies with database permission requirements, avoiding execution failures or erroneous results due to semantic or permission issues.
[0055] Specifically, reliability verification at the grammar parsing level refers to using a context-free grammar (CFG) to perform structured parsing of the input SQL statement to be verified. This identifies and marks statements that do not conform to the database standard syntax specifications, ensuring that the SQL statement to be verified is grammatically compliant. A context-free grammar is a formal grammar description tool composed of a set of production rules used to define the grammatical structure of a language. When an SQL statement is input, the CFG-based parser breaks down and analyzes the structure of the SQL statement (such as keywords, column name lists, table names, conditional expressions, etc.) according to the predefined production rules, checking whether each component conforms to the corresponding rules in the CFG. If, during the parsing process, a part of the SQL statement is found to be inconsistent with the CFG production rules, it indicates that the statement contains a grammatical error.
[0056] Reliability verification from a semantic verification perspective involves using the database metadata interface to verify the existence of table names and field names, the validity of JOIN conditions, and the closure of subqueries. It also checks field access permissions to ensure the SQL statement is semantically logical and complies with access control requirements. Specifically: Table name and field name verification: Database metadata contains information about all tables and their fields. The metadata interface allows querying whether a specific table exists and whether a specific field exists within it. JOIN condition validity: JOIN operations combine multiple tables according to certain conditions. Verification checks whether the fields used in the JOIN exist in the relevant tables and whether the JOIN logic is valid. Subquery closure: Subqueries are nested queries. Verification checks whether the parentheses in the subquery match correctly (i.e., whether there are correct opening and closing parentheses) to ensure the subquery's structure is complete. It also checks whether the subquery's logic is complete and returns a valid result set so that the outer query can correctly use the subquery's results. Checking field access permissions: Different users or user groups may have different access permissions to fields in the database. By combining a metadata interface with a permission management system, it's possible to detect whether the user of the SQL statement to be verified has the necessary permissions to query, modify, or perform other operations on the relevant fields. If the user lacks the appropriate permissions, the execution of the SQL statement to be verified will fail due to insufficient permissions, and thus be identified as problematic.
[0057] Reliability verification of the SQL statement to be verified through execution plan analysis involves calling the database optimizer interface (such as the EXPLAIN command in PostgreSQL) to pre-generate an execution plan. This plan breaks down the complete execution flow of the SQL statement to be verified. For example, for single-table queries, it specifies whether a full table scan or an index scan is used; for multi-table join queries, it specifies the join algorithm, the order of table joins, and the timing of the execution of filter conditions. The database's built-in cost model assigns a quantified cost to each operation step in the execution plan. These costs can be calculated based on actual resource consumption. By analyzing the total cost and the cost ratio of each step, potential performance bottlenecks can be located, and potential performance risks can be assessed.
[0058] In step S120, if the verification passes, the user's credibility is dynamically calculated based on the target user's historical behavior and permission information, and the quality score of the SQL statement to be verified is obtained based on the multi-dimensional scoring function and knowledge retrieval space.
[0059] Optionally, the credibility level can be dynamically calculated based on the user's historical behavior and permission information, which can more accurately reflect the credibility and risk level of the user's SQL statement operation behavior. By using a multi-factor fusion scoring mechanism based on historical behavior, compared to traditional static permission control methods based on roles or attributes, it can dynamically quantify user operation risks, avoiding the problem of overly coarse control granularity caused by relying solely on preset strategies, thereby improving the system's ability to fine-grainedly identify and control user behavior. Specifically, it can comprehensively consider factors such as the scoring characteristics of the user's historical behavior at time t, the basic score characteristics of the account's permissions, the user's context, and the set of historical behavior trajectories from the initial moment to time t. Through specific calculation logic, the user's confidence level at that time point can be obtained, thus reflecting the user's credibility at the current moment.
[0060] The scoring features of historical behavior can be obtained in the following way: First, historical behavior is scored by preset scoring rules to obtain historical behavior scores. Then, the scores can be reduced in dimensionality or key information can be extracted to obtain historical behavior scoring features that can accurately reflect the user's historical behavior patterns and compliance characteristics, which can be used for subsequent calculation of user credibility.
[0061] The basic characteristics of account permissions can include: the inherent permission level of the user's role (such as the permission range corresponding to different roles such as administrator, ordinary user, and visitor), the effective time of permissions (such as the start and end dates of temporary permissions), and permission change records (such as whether there have been permission upgrades or downgrades). This basic score can be generated according to preset rules (such as the administrator's basic score being higher than that of ordinary users).
[0062] The user's context can be obtained by collecting real-time environmental data of the user's current operation (such as device hardware identification, geographical location of IP address resolution, and system time) and comparing it with environmental characteristics in the user's historical operation records. Specifically, this may include the current login device (such as whether it is a frequently used device), login location (such as whether it is within a frequently used geographical area), login time (such as whether it matches the user's usual operating time), and the business scenario of the current operation (such as whether it is within the scope of the user's job responsibilities).
[0063] The historical behavior trajectory set from the initial time to time t can be obtained by querying the system log. The log can aggregate all historical operation records by user ID and time order to form a complete behavior trajectory dataset, which supports backtracking query by time range.
[0064] Furthermore, by introducing multi-dimensional scoring functions such as grammatical compliance, semantic rationality, security, performance prediction, and large model confidence, and constructing a structured knowledge retrieval space (including subspaces for grammar, semantics, security, performance, and generated knowledge), if multiple scoring functions are used simultaneously, corresponding weight coefficients can be assigned to each dimension, and all weight coefficients satisfy the normalization condition. Finally, by combining the scores and weights of each dimension, the final quality score of the SQL statement generated by the large model is obtained, thereby achieving a comprehensive evaluation of the SQL statement.
[0065] It should be noted that the calculation order of SQL quality score and user trustworthiness is not important. The calculation process of SQL quality score can be executed first, followed by the calculation process of user trustworthiness, or vice versa, or both can be executed simultaneously.
[0066] In step S130, the computing resource allocation strategy is dynamically adjusted based on the user's trustworthiness and the SQL quality score, so as to execute the corresponding operation based on the adjusted resource allocation strategy.
[0067] Optionally, the allocation strategy for computing resources can be dynamically adjusted based on pre-obtained SQL quality scores and user trust levels. Specifically, a priority metric can be constructed that comprehensively considers both the knowledge-enhanced SQL statement quality score and user trust level, and uses specific parameters to adjust the emphasis on SQL statement quality and user identity trust.
[0068] Then, the resource scheduling decision engine receives the constructed priority indicators and dynamically adjusts resource allocation strategies such as CPU resource quotas, memory limits, I / O bandwidth control, and concurrent connection limits to achieve efficient resource utilization. For example, with reasonable CPU resource quota settings, high-priority SQL statements can obtain higher concurrent execution privileges; dynamically setting the sorting buffer size and temporary storage space limit enables memory limits to prevent memory overflow exceptions; I / O bandwidth control prevents inefficient SQL statements from consuming excessive I / O resources, avoiding queue blocking; and setting maximum connection counts and concurrent connection limits for different priority SQL statements prevents system overload.
[0069] In addition, the system is also configured with an abnormal SQL statement blocking mechanism to identify and block potentially risky SQL statements. The triggering conditions may include:
[0070] SQL Quality Score: S <T s (T s (The security threshold set for the system);
[0071] User credibility U <T u (T u (User trust threshold).
[0072] Among them, T s and T u It can be grouped and configured according to different business scenarios. For example, the production environment can adopt higher standards, while the testing environment can allow lower scores to pass. Simultaneously, it supports an adaptive threshold adjustment mechanism based on historical misjudgment rates. For example, it continuously records "misjudgment events" that occurred when using SQL statement scoring thresholds and user trust thresholds in the past (such as misjudging normal and compliant SQL statements as low-quality interceptions, or omitting low-scoring SQL statements with risks). It also periodically calculates the proportion of these misjudgment cases in the total number of judgments (i.e., historical misjudgment rate). Then, it dynamically adjusts the values of the two thresholds according to the misjudgment rate. If the misjudgment rate is too high (such as the proportion of normal SQL statements being misinterpreted exceeding the preset standard), the system will analyze the reasons for the misjudgment: if it is due to the SQL statement scoring threshold being set too strictly, the threshold will be appropriately lowered to reduce the misinterpretation of normal operations; if it is due to the user trust threshold being too high, resulting in excessive restrictions on low-trust but risk-free user operations, the threshold will be appropriately lowered; conversely, if there are cases of missed judgment of risky SQL statements (such as low misjudgment rate but risky cases not being intercepted), the threshold will be increased accordingly to enhance security protection, thereby improving the system's flexibility and accuracy.
[0073] When any one of the triggering conditions is met, operations such as pausing execution, recording audit logs, issuing security alerts, and providing automatic learning feedback will be performed. Specific operations may include:
[0074] Execution is paused, and the SQL statements awaiting verification are transferred to the manual review queue.
[0075] The audit log records the SQL statement to be verified, the submitting user, the scoring result, and the triggering reason.
[0076] Security alert notifications: Send email or SMS alerts to administrators and provide analysis reports of the SQL statements to be verified.
[0077] Automatic learning feedback feeds back abnormal SQL statements and their context information to the scoring system and user credibility model for subsequent model optimization.
[0078] In this embodiment, by integrating SQL quality score and user dynamic trustworthiness into a priority index through adjustable weight parameters, and based on this index, a mechanism for dynamic scheduling of computing resources and automatic identification and blocking of abnormal SQL statements triggered by dual thresholds is implemented, which effectively improves the system's resource utilization efficiency, security control capabilities and risk response accuracy in high-concurrency scenarios.
[0079] This application provides a method for multi-factor quality assessment and dynamic resource allocation of SQL statements, including: performing reliability verification on the SQL statement to be verified; if the verification passes, dynamically calculating the user's credibility based on the target user's historical behavior and permission information; and performing a quality score on the SQL statement to be verified based on a multi-dimensional scoring function and a knowledge retrieval space to obtain an SQL quality score; and dynamically adjusting the computing resource allocation strategy based on the user credibility and the SQL quality score, so as to execute corresponding operations based on the adjusted resource allocation strategy. In this embodiment, on the one hand, by first verifying the reliability of SQL statements and then conducting a comprehensive quality assessment by combining multi-dimensional scoring functions and structured knowledge retrieval space, it can not only identify semantic biases and performance bottlenecks that are difficult to cover by traditional static checks, but also intercept high-risk operations and illegal statements, significantly reducing the SQL statement execution failure rate and database security risks, and improving the execution reliability of SQL statements generated by large models. On the other hand, based on multi-dimensional historical behavior data and permission information of users, user credibility is dynamically calculated, realizing differentiated identification of users with different credibility levels. At the same time, relying on the dual factors of user credibility and SQL quality score to dynamically adjust the resource allocation strategy, it can prioritize the allocation of resources to high-quality SQL statements of high-credibility users to ensure execution efficiency, and reasonably control the resource consumption of low-quality SQL statements of low-credibility users, significantly improving the resource utilization and operational stability of the database in multi-tenant, high-concurrency scenarios.
[0080] In one embodiment of this application, the step of dynamically calculating user credibility based on the target user's historical behavior and permission information includes:
[0081] Based on historical behavior scoring association data, historical behavior scoring information is calculated, wherein the historical behavior scoring association data includes at least one of the following: access frequency, query success rate, error frequency, number of violations, response time stability, and high resource low efficiency query ratio.
[0082] Based on the historical behavior scoring information, a historical behavior scoring feature vector is determined;
[0083] The basic features for obtaining permissions are the user context vector and the set of historical behavior trajectories.
[0084] The user's credibility is calculated based on the historical behavior scoring feature vector, the permission base score feature vector, the user context vector, and the historical behavior trajectory set.
[0085] Optionally, at least one data point is extracted from the user operation logs and behavior records stored in the system, such as access frequency, query success rate, error frequency, number of violations, response time stability, and high-resource-low-efficiency query ratio, as historical behavior scoring associated data. This data is then input into a preset calculation model to calculate the historical behavior score. Next, this scoring information is transformed into a structured historical behavior score feature vector, making it more intuitively reflect the key characteristics of the user's historical behavior. Simultaneously, the basic permission score corresponding to the user's role is obtained from the system permission management module and organized into a basic permission score feature vector. Real-time collection of environmental and scenario information such as the user's current login device, login region, and operation time period forms a user context vector. Furthermore, complete operation records from the user's first use of the system to the current time are retrieved and summarized into a historical behavior trajectory set. Finally, by comprehensively combining the historical behavior score feature vector (reflecting past operational performance), the permission base score feature vector (reflecting the inherent permission baseline), the user context vector (reflecting the rationality of the current operational scenario), and the historical behavior trajectory set (reflecting long-term behavioral trends), the user confidence score, which reflects the user's current operation, is calculated as the user credibility score to reflect the user's level of trustworthiness through cross-analysis and comprehensive evaluation of multi-dimensional information.
[0086] The user confidence level can be calculated using the following formula:
[0087]
[0088] Where U(t) represents the user's confidence level at time point t; f θ It is a parameterized function with parameter θ, used to model the calculation logic of user confidence; This represents the feature vector of a user's historical behavior rating at time point t. This represents the feature vector of account permissions at time point t. H represents the user's context vector at time point t; [0,t) This represents the set of historical behavioral trajectories from the initial time to time t.
[0089] In one embodiment of this application, the historical behavior scoring association data includes access frequency, query success rate, error frequency, number of violations, response time stability, and the proportion of high-resource, low-efficiency queries. The calculation of historical behavior scoring information based on the historical behavior scoring association data includes:
[0090] An adjustment constant is introduced to control the rate at which the marginal contribution of the access frequency to the historical behavior score decreases.
[0091] Set a penalty intensity parameter for violations, and control the degree to which the number of violations reduces the score of the historical behavior;
[0092] The success rate of the query is positively weighted and the error frequency is negatively weighted. The accuracy of the user's operation is reflected by the comprehensive calculation of the two.
[0093] The response time stability is used as a positive indicator in the calculation to reflect the stability of user operations on system resource consumption.
[0094] The inverse value of the ratio of high-resource, low-efficiency queries is used as an indicator in the calculation to measure the resource utilization efficiency of user operations.
[0095] By integrating and calculating data from various dimensions using pre-defined association rules, historical behavior scoring information is obtained.
[0096] Optionally, when calculating historical behavior scores, the system comprehensively processes related data such as access frequency, query success rate, error frequency, number of violations, response time stability, and the proportion of high-resource-inefficient queries. For access frequency, an adjustment constant is introduced to control the rate at which its marginal contribution to the score decreases with increasing frequency. For the number of violations, a violation penalty intensity parameter is set to adjust the degree to which it causes a decrease in the score. Query success rate is positively weighted, and error frequency is negatively weighted; both are combined to reflect the accuracy of user operations. Response time stability is included as a positive indicator in the calculation, reflecting the stability of user operations' consumption of system resources. The negative value of the proportion of high-resource-inefficient queries is used as an indicator to measure the resource utilization efficiency of user operations. Finally, according to preset correlation calculation rules, the data from each dimension are integrated and calculated to obtain the historical behavior score. This historical behavior score can be calculated using the following formula:
[0097]
[0098] Among them, the access frequency h represents the number of SQL statement queries performed daily, with a value of [0, +∞); the adjustment constant c controls the rate at which the marginal contribution of the access frequency h to the historical behavior score decreases, avoiding infinite querying that leads to an artificially high score, while allowing reasonably active users to obtain higher scores; the query success rate s is the proportion of successfully executed SQL statements in the total number of submitted SQL statements, with a value range of [0, 1]; the error frequency e is the proportion of erroneous SQL statements (syntax / semantics) in the total number of submitted SQL statements, with a value range of [0, 1]; the number of violations v represents the number of unauthorized access or high-risk command attempts, with a value range of [0, +∞]; the violation penalty intensity parameter k1 controls the degree of decay of the number of violations v to the historical behavior score, usually taking a positive real number, and the larger the value of this parameter, the lower the tolerance for violations; the response time stability r is a measure of the volatility of the query response, defined as the normalized value of the reciprocal of the standard deviation of the response time, with a value range of [0, 1], and the higher the value, the more stable the response; the high resource low efficiency query ratio q represents the proportion of slow queries with high resource consumption, with a value range of [0, 1].
[0099] In one embodiment of this application, the step of scoring the quality of the SQL statement to be verified based on a multi-dimensional scoring function and a knowledge retrieval space to obtain an SQL quality score includes:
[0100] Construct a multi-dimensional scoring function set, which includes at least one of the following: syntax compliance scoring function, semantic rationality scoring function, security scoring function, performance prediction scoring function, and large model confidence scoring function;
[0101] Construct a structured knowledge retrieval space, wherein the knowledge retrieval space includes at least one of a syntactic knowledge subspace, a semantic knowledge subspace, a security knowledge subspace, a performance knowledge subspace, and a generative knowledge subspace;
[0102] Based on the corresponding knowledge subspace in the structured knowledge retrieval space, the matching dimension scoring function from the multi-dimensional scoring function set is invoked to calculate the target dimension score.
[0103] The SQL quality score is obtained based on the preset scoring rules and the target dimension score.
[0104] Optionally, when scoring the quality of SQL statements, firstly, a multi-dimensional scoring function set is constructed, including at least one of the following: syntax compliance, semantic rationality, security, performance prediction, and large model confidence. Simultaneously, a structured knowledge retrieval space is built, consisting of at least one of the following: syntax knowledge, semantic knowledge, security knowledge, performance knowledge, and generative knowledge. Then, based on the corresponding knowledge subspace in the knowledge retrieval space, the matching dimension scoring function from the scoring function set is called to calculate the score for each target dimension. Finally, according to preset scoring rules, these target dimension scores are integrated to obtain the final SQL quality score. This final SQL quality score can be calculated using the following formula:
[0105]
[0106] Where S represents the final quality score of the SQL statements generated by the large model; f i (x; K) is the i-th scoring function, which depends not only on the large input model to generate SQL statements, but also on the external knowledge retrieval space K; w i The weight coefficients for the corresponding rating dimensions (rating functions) satisfy the normalization condition w. i ∈[0,1] and
[0107] It should be noted that the syntax compliance scoring function f1(x; K) syntax The system can perform structured parsing of SQL statements based on the grammar knowledge subspace. A fully compliant SQL statement scores 1, while a SQL statement with grammatical errors scores close to 0. For example, by calling the SQL statement grammar rule base (including keyword specifications, statement structure templates, and symbol usage standards) in the grammar knowledge subspace, the system can perform lexical and grammatical parsing on the input SQL statement, identifying issues such as missing keywords, mismatched brackets, and misspelled table / field names. Points are deducted proportionally based on the type and number of errors (e.g., 10% deduction for a single grammatical error, and over 50% deduction for serious structural errors). A perfect score is awarded for no errors.
[0108] Semantic rationality scoring function f2(x; K) semantic ,K security The semantic consistency of SQL statements is evaluated, including aspects such as the validity of field references and the appropriateness of aggregate function usage. For example, database metadata (table structure, field types, and relationships) and business logic rules within the semantic knowledge subspace can be used to verify the existence of tables and fields, data type matching (e.g., comparing numeric fields with strings), and the correspondence between aggregate functions and grouping conditions. Points are deducted for semantic inconsistencies (e.g., referencing non-existent fields) and added to logically consistent joins, resulting in a comprehensive semantic consistency score.
[0109] Security scoring function f3(x; K) security This is used to identify potential security risks such as SQL injection signature strings, access to sensitive fields, and attempts at high-risk operations. For example, based on the risk signature library in the security knowledge subspace (including SQL injection signature words, lists of sensitive fields, and high-risk operation templates), it can scan SQL statements to see if they contain malicious injection fragments, access unauthorized sensitive data, or perform delete / update operations without filtering conditions. For each high-risk feature detected, corresponding points are deducted; for low-risk features, points are deducted appropriately; and for no-risk items, a base score is awarded, thus obtaining a security score.
[0110] Performance prediction scoring function f4(x; K) performance Based on the SQL statement execution plan and cost estimation model, the system load during SQL statement execution can be predicted. For example, by using execution plan templates, cost model parameters, and historical performance data in the performance knowledge subspace, the execution plan of the SQL statement to be verified can be generated, and performance influencing factors such as the proportion of full table scans, index usage efficiency, multi-table join complexity, and data sorting scale can be analyzed. A performance risk score can then be calculated according to preset scoring rules.
[0111] Large model confidence scoring function f5(x; K) LLM When SQL statements are generated by a large language model (LLM), the model's confidence level in its output is obtained as an auxiliary reference metric. For example, the confidence level parameter of the large model's output can be retrieved from the generated knowledge subspace, and the model's own confidence in the correctness of the SQL statement can be directly mapped to a score. If the model identifies potential errors (such as low-probability field references), the score is calculated proportionally to the confidence level.
[0112] Furthermore, it should be noted that the knowledge retrieval space K is a structured and scalable knowledge base system, which includes, but is not limited to, the grammatical knowledge subspace K. syntax Semantic knowledge subspace K semantic Security knowledge subspace K security Performance knowledge subspace K performance and generating knowledge subspace K LLM Each subspace supports multiple knowledge retrieval methods, including keyword matching, vector similarity comparison, and rule engine judgment.
[0113] In one embodiment of this application, the target dimension score includes multiple components, and the step of obtaining the SQL quality score based on preset scoring rules and the target dimension score includes:
[0114] Determine the weight coefficients corresponding to the scores of each of the aforementioned target dimensions;
[0115] The weighted score for each objective dimension is obtained by multiplying the score of each objective dimension by its corresponding weight coefficient.
[0116] The SQL quality score is obtained by summing the weighted scores of all target dimensions.
[0117] Optionally, when deriving the SQL quality score by combining preset scoring rules with scores for each target dimension, the following steps are taken: First, based on the needs of the actual business scenario (e.g., performance in high-concurrency scenarios, security in sensitive data scenarios), corresponding weight coefficients are assigned to each target dimension score, such as syntax compliance, semantic rationality, and security, to clarify the degree of influence of different dimensions on the overall SQL statement quality. Next, the specific score for each target dimension is multiplied by its assigned weight coefficient to obtain the weighted score that dimension actually contributes to the overall score. Finally, the weighted scores for all target dimensions are summed, and the result obtained through the summation operation is the SQL quality score that comprehensively reflects the overall quality level of the SQL statement to be verified. This weight coefficient satisfies the normalization condition, and the sum is 1.
[0118] In one embodiment of this application, the step of dynamically adjusting the computing resource allocation strategy based on the user's trustworthiness and the SQL quality score includes:
[0119] Determine the user's credibility and the level of trust corresponding to the SQL quality score;
[0120] Based on the level of trust, user credibility, and SQL quality score, a priority index is constructed.
[0121] The computing resource allocation strategy is dynamically adjusted based on the aforementioned priority indicators.
[0122] Optionally, when dynamically adjusting the computing resource allocation strategy based on user trustworthiness and SQL quality score, the trust level corresponding to user trustworthiness and SQL quality score must first be determined, that is, the trust level they represent in the resource allocation decision is clarified; then, by combining these two trust levels and incorporating the numerical values of user trustworthiness and SQL quality score themselves, an indicator for measuring the priority of resource allocation is constructed; finally, based on this constructed priority indicator, the computing resource allocation strategy is dynamically adjusted to achieve reasonable and efficient resource allocation.
[0123] The priority index can be calculated using the following formula:
[0124] R = λ·S + (1-λ)·U;
[0125] Where S represents the knowledge-enhanced SQL statement score, with a value range of [0,1]; U represents the user credibility score, calculated by the multi-dimensional credibility assessment system; and λ represents the system's emphasis on the quality of the SQL statement and the user's identity, with a value range of [0,1].
[0126] In one embodiment of this application, after dynamically adjusting the computing resource allocation strategy based on the user trustworthiness and the SQL quality score, the method further includes:
[0127] Once the adjusted resource allocation strategy has been executed, obtain the execution result data and the actual resource consumption data.
[0128] Obtain user evaluation data on the query results of the SQL statement to be verified, and record the rating data and task blocking status.
[0129] The execution result data, actual resource consumption data, evaluation data, scoring data, and task blocking status are cleaned and labeled to construct a feedback sample set;
[0130] The large model is iteratively optimized based on the feedback sample set, wherein the large model is used to generate the SQL statement to be verified.
[0131] Optionally, after dynamically adjusting the computing resource allocation strategy based on user trust and SQL quality scores and executing it, the system first acquires the execution result data and actual resource consumption data generated during this execution to facilitate subsequent model optimization. The execution result data may include whether the SQL statement was successfully executed, the execution time, whether errors occurred, the number of records affected, and the indexes used. The actual resource consumption may include CPU utilization, memory usage, and I / O throughput. At the same time, the system collects user evaluation data on the satisfaction level of the SQL statement query results to assist in deciding whether to constrain and optimize the model later. In addition, the system can continuously record scoring data and task blocking status, and combine historical feedback information to achieve automatic optimization and iterative upgrades of query control strategies and risk assessment mechanisms.
[0132] Subsequently, the system cleans and labels these execution result data, actual resource consumption data, evaluation data, scoring data, and task blocking statuses (e.g., labeling each data point in the feedback sample set with SQL quality level (excellent / medium / poor), user satisfaction (0-1 points), and resource consumption rationality (whether it exceeds the average of similar tasks, etc.), constructing a feedback sample set. Finally, this feedback sample set is used to iteratively optimize the large model used to generate the SQL statements to be verified, thereby improving the quality of the SQL statements generated by the large model. Through the feedback self-optimization mechanism constructed above, the system achieves dynamic control and continuous improvement of the output results of the large language model, forming a complete closed-loop process of "generation—evaluation—execution—feedback—optimization". This closed-loop mechanism not only improves the model's generalization ability and robustness under different database structures and business scenarios, but also significantly enhances the system's intelligence, security, and practicality by introducing incremental learning, prompt optimization, knowledge enhancement, and error avoidance, providing solid technical support for the automatic generation of high-quality SQL statements.
[0133] It should be noted that the model can be optimized based on this feedback sample set from multiple dimensions: First, incremental fine-tuning is adopted, without retraining the entire original large language model. Instead, the model's parameters are updated lightly periodically using newly collected feedback data. This reduces computational resource consumption and allows the model to gradually improve the accuracy and adaptability of SQL statement generation in specific business domains (such as financial data queries and e-commerce order statistics) or high-frequency operation scenarios. Second, through prompt engineering optimization, combined with user evaluations of SQL query results (such as "target field not obtained" or "query logic does not meet requirements"), the prompt templates input to the model are continuously adjusted (such as supplementing business scenario descriptions and clarifying field constraints). This helps the model more accurately understand the user's true query intent and reduces SQL statement generation deviations caused by misunderstanding of intent. Third, the feedback contains specific... Reusable content (such as correct table join logic, compliant sensitive field query methods, and efficient index usage examples) is integrated into the knowledge retrieval space to provide richer knowledge support for the subsequent SQL statement scoring submodule in syntax verification, semantic judgment, performance evaluation, and other aspects, indirectly improving the quality of SQL statements generated by the model. Fourth, an error pattern recognition and avoidance mechanism is constructed. First, common SQL statement generation error types (such as misspelled field names, missing table join conditions, and improper use of aggregate functions) are sorted out from the feedback sample set through cluster analysis. Then, constraint strategies (such as preset field name verification rules and mandatory checking of table join logic) are introduced in advance for these error types during the model's SQL statement generation stage, thereby effectively reducing the probability of the same type of error recurring.
[0134] In this embodiment, relying on a multi-factor fusion historical behavior scoring mechanism, the limitations of traditional static permission control are broken through, the risk of user operation is dynamically quantified, and the problem of overly coarse granularity of preset strategy control is solved, significantly improving the system's ability to fine-grainedly identify and control user behavior. An innovative adjustable weight fusion mechanism of SQL quality score and user dynamic credibility is constructed to form a comprehensive priority index, thereby achieving dynamic scheduling of computing resources. Combined with the automatic identification and blocking function of abnormal SQL statements triggered by dual thresholds (SQL quality score below a preset threshold and user credibility below a preset threshold), resource utilization efficiency is significantly optimized in high-concurrency scenarios, while strengthening the system's security control capabilities and risk response accuracy. A complete feedback loop is built through a model-driven reward submodule, collecting execution results, resource consumption, and user feedback data to construct a training sample set. Combined with incremental fine-tuning, prompt engineering optimization, knowledge graph updates, and error pattern avoidance, the model is continuously iterated, overcoming the pain point of existing systems lacking self-evolution capabilities, and significantly enhancing the robustness and adaptability of large models in complex business scenarios. Ultimately, this solution not only enhances the security and reliability of SQL statements generated by large language models, effectively mitigating risks such as data leaks and system crashes, thus building a strong security barrier for enterprise database services, but also helps enterprises reduce server procurement investment and lower overall operating costs by optimizing the allocation of data query task resources, achieving a dual improvement in security and efficiency.
[0135] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0136] In one embodiment, a multi-factor quality assessment and dynamic resource allocation device for SQL statements is provided, which corresponds one-to-one with the multi-factor quality assessment and dynamic resource allocation method for SQL statements described in the above embodiments. For example... Figure 2 As shown, this multi-factor quality assessment and dynamic resource allocation device for SQL statements includes a reliability verification unit 10, an assessment unit 20, and a resource allocation unit 30. Detailed descriptions of each functional module are as follows:
[0137] Reliability verification unit 10 is used to perform reliability verification on the SQL statement to be verified.
[0138] Evaluation unit 20 is used to dynamically calculate user credibility based on the target user's historical behavior and permission information if the verification passes, and to score the quality of the SQL statement to be verified based on a multi-dimensional scoring function and knowledge retrieval space to obtain the SQL quality score.
[0139] The resource allocation unit 30 is used to dynamically adjust the computing resource allocation strategy based on the user's trustworthiness and the SQL quality score, so as to execute the corresponding operation based on the adjusted resource allocation strategy.
[0140] In one embodiment of this application, the evaluation unit 20 is further configured to:
[0141] Based on historical behavior scoring association data, historical behavior scoring information is calculated, wherein the historical behavior scoring association data includes at least one of the following: access frequency, query success rate, error frequency, number of violations, response time stability, and high resource low efficiency query ratio.
[0142] Based on the historical behavior scoring information, a historical behavior scoring feature vector is determined;
[0143] The basic features for obtaining permissions are the user context vector and the set of historical behavior trajectories.
[0144] The user's credibility is calculated based on the historical behavior scoring feature vector, the permission base score feature vector, the user context vector, and the historical behavior trajectory set.
[0145] In one embodiment of this application, the historical behavior scoring associated data includes access frequency, query success rate, error frequency, number of violations, response time stability, and the proportion of high-resource, low-efficiency queries. The evaluation unit 20 is further used for:
[0146] An adjustment constant is introduced to control the rate at which the marginal contribution of the access frequency to the historical behavior score decreases.
[0147] Set a penalty intensity parameter for violations, and control the degree to which the number of violations reduces the score of the historical behavior;
[0148] The success rate of the query is positively weighted and the error frequency is negatively weighted. The accuracy of the user's operation is reflected by the comprehensive calculation of the two.
[0149] The response time stability is used as a positive indicator in the calculation to reflect the stability of user operations on system resource consumption.
[0150] The inverse value of the ratio of high-resource, low-efficiency queries is used as an indicator in the calculation to measure the resource utilization efficiency of user operations.
[0151] By integrating and calculating data from various dimensions using pre-defined association rules, historical behavior scoring information is obtained.
[0152] In one embodiment of this application, the evaluation unit 20 is further configured to:
[0153] Construct a multi-dimensional scoring function set, which includes at least one of the following: syntax compliance scoring function, semantic rationality scoring function, security scoring function, performance prediction scoring function, and large model confidence scoring function;
[0154] Construct a structured knowledge retrieval space, wherein the knowledge retrieval space includes at least one of a syntactic knowledge subspace, a semantic knowledge subspace, a security knowledge subspace, a performance knowledge subspace, and a generative knowledge subspace;
[0155] Based on the corresponding knowledge subspace in the structured knowledge retrieval space, the matching dimension scoring function from the multi-dimensional scoring function set is invoked to calculate the target dimension score.
[0156] The SQL quality score is obtained based on the preset scoring rules and the target dimension score.
[0157] In one embodiment of this application, the target dimension scoring includes multiple components, and the evaluation unit 20 is further used for:
[0158] Determine the weight coefficients corresponding to the scores of each of the aforementioned target dimensions;
[0159] The weighted score for each objective dimension is obtained by multiplying the score of each objective dimension by its corresponding weight coefficient.
[0160] The SQL quality score is obtained by summing the weighted scores of all target dimensions.
[0161] In one embodiment of this application, the resource allocation unit 30 is further configured to:
[0162] Determine the user's credibility and the level of trust corresponding to the SQL quality score;
[0163] Based on the level of trust, user credibility, and SQL quality score, a priority index is constructed.
[0164] The computing resource allocation strategy is dynamically adjusted based on the aforementioned priority indicators.
[0165] In one embodiment of this application, the apparatus further includes a model optimization unit, used for:
[0166] Once the adjusted resource allocation strategy has been executed, obtain the execution result data and the actual resource consumption data.
[0167] Obtain user evaluation data on the query results of the SQL statement to be verified, and record the rating data and task blocking status.
[0168] The execution result data, actual resource consumption data, evaluation data, scoring data, and task blocking status are cleaned and labeled to construct a feedback sample set;
[0169] The large model is iteratively optimized based on the feedback sample set, wherein the large model is used to generate the SQL statement to be verified.
[0170] In this embodiment, on the one hand, by first verifying the reliability of SQL statements and then conducting a comprehensive quality assessment by combining multi-dimensional scoring functions and structured knowledge retrieval space, it can not only identify semantic biases and performance bottlenecks that are difficult to cover by traditional static checks, but also intercept high-risk operations and illegal statements, significantly reducing the SQL statement execution failure rate and database security risks, and improving the execution reliability of SQL statements generated by large models. On the other hand, based on multi-dimensional historical behavior data and permission information of users, user credibility is dynamically calculated, realizing differentiated identification of users with different credibility levels. At the same time, relying on the dual factors of user credibility and SQL quality score to dynamically adjust the resource allocation strategy, it can prioritize the allocation of resources to high-quality SQL statements of high-credibility users to ensure execution efficiency, and reasonably control the resource consumption of low-quality SQL statements of low-credibility users, significantly improving the resource utilization and operational stability of the database in multi-tenant, high-concurrency scenarios.
[0171] Specific limitations regarding the multi-factor quality assessment and dynamic resource allocation device for SQL statements can be found in the limitations of the multi-factor quality assessment and dynamic resource allocation method for SQL statements mentioned above, and will not be repeated here. Each module in the aforementioned multi-factor quality assessment and dynamic resource allocation device for SQL statements can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in or independent of the processor in a computer device in hardware form, or stored in the memory of a computer device in software form, so that the processor can call and execute the operations corresponding to each module.
[0172] In one embodiment, a computer device is provided, which may be a terminal device, and its internal structure diagram may be as follows: Figure 3 As shown, the computer device includes a processor, memory, and a network interface connected via a system bus. The processor provides computing and control capabilities. The memory includes a readable storage medium storing computer-readable instructions. The network interface communicates with external terminals via a network connection. When executed by the processor, the computer-readable instructions implement a multi-factor quality assessment and dynamic resource allocation method oriented towards SQL statements. The readable storage medium provided in this embodiment includes both non-volatile and volatile readable storage media.
[0173] In this application embodiment, a computer device is provided, including a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor. When the processor executes the computer-readable instructions, it implements the steps of the multi-factor quality assessment and dynamic resource allocation method for SQL statements as described above.
[0174] In one embodiment of the application, a readable storage medium is provided, which stores computer-readable instructions. When the computer-readable instructions are executed by a processor, they implement the steps of the multi-factor quality assessment and dynamic resource allocation method for SQL statements described above.
[0175] Those skilled in the art will understand that all or part of the processes in the methods of the above embodiments can be implemented by instructing related hardware with computer-readable instructions. These computer-readable instructions can be stored in a non-volatile readable storage medium or a volatile readable storage medium. When executed, these computer-readable instructions can include the processes of the embodiments of the above methods. Any references to memory, storage, databases, or other media used in the embodiments provided in this application can include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), dual data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0176] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is used as an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0177] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application, and should all be included within the protection scope of this application.
Claims
1. A multi-factor quality assessment and dynamic resource allocation method for SQL statements, characterized in that, The method includes: Perform reliability verification on the SQL statement to be verified; If the verification passes, the user's credibility is dynamically calculated based on the target user's historical behavior and permission information. Furthermore, a quality score is awarded to the SQL statement to be verified based on multi-dimensional scoring functions and a knowledge retrieval space. This process includes: constructing a multi-dimensional scoring function set, which includes at least one of the following: syntax compliance scoring function, semantic rationality scoring function, security scoring function, performance prediction scoring function, and large model confidence scoring function; constructing a structured knowledge retrieval space, which includes at least one of the following: syntax knowledge subspace, semantic knowledge subspace, security knowledge subspace, performance knowledge subspace, and generation knowledge subspace; calling the matching dimension scoring function from the multi-dimensional scoring function set based on the corresponding knowledge subspace in the structured knowledge retrieval space to calculate the target dimension score; and obtaining the SQL quality score based on preset scoring rules and the target dimension score. Based on the user's trustworthiness and the SQL quality score, the computing resource allocation strategy is dynamically adjusted to execute corresponding operations based on the adjusted resource allocation strategy.
2. The method for multi-factor quality assessment and dynamic resource allocation for SQL statements as described in claim 1, characterized in that, The dynamic calculation of user credibility based on the target user's historical behavior and permission information includes: Based on historical behavior scoring association data, historical behavior scoring information is calculated, wherein the historical behavior scoring association data includes at least one of the following: access frequency, query success rate, error frequency, number of violations, response time stability, and high resource low efficiency query ratio. Based on the historical behavior scoring information, a historical behavior scoring feature vector is determined; The basic features for obtaining permissions are the user context vector and the set of historical behavior trajectories. The user's credibility is calculated based on the historical behavior scoring feature vector, the permission base score feature vector, the user context vector, and the historical behavior trajectory set.
3. The method for multi-factor quality assessment and dynamic resource allocation for SQL statements as described in claim 2, characterized in that, The historical behavior scoring association data includes access frequency, query success rate, error frequency, number of violations, response time stability, and the proportion of high-resource, low-efficiency queries. The calculation of historical behavior scoring information based on this association data includes: An adjustment constant is introduced to control the rate at which the marginal contribution of the access frequency to the historical behavior score decreases. Set a penalty intensity parameter for violations, and control the degree to which the number of violations reduces the score of the historical behavior; The success rate of the query is positively weighted and the error frequency is negatively weighted. The accuracy of the user's operation is reflected by the comprehensive calculation of the two. The response time stability is used as a positive indicator in the calculation to reflect the stability of user operations on system resource consumption. The inverse value of the ratio of high-resource, low-efficiency queries is used as an indicator in the calculation to measure the resource utilization efficiency of user operations. By integrating and calculating data from various dimensions using pre-defined association rules, historical behavior scoring information is obtained.
4. The method for multi-factor quality assessment and dynamic resource allocation for SQL statements as described in claim 1, characterized in that, The target dimension scoring includes multiple aspects. The SQL quality score is obtained based on preset scoring rules and the target dimension scoring, including: Determine the weight coefficients corresponding to the scores of each of the aforementioned target dimensions; The weighted score for each objective dimension is obtained by multiplying the score of each objective dimension by its corresponding weight coefficient. The SQL quality score is obtained by summing the weighted scores of all target dimensions.
5. The method for multi-factor quality assessment and dynamic resource allocation for SQL statements as described in claim 1, characterized in that, The dynamic adjustment of computing resource allocation strategy based on the user's trustworthiness and the SQL quality score includes: Determine the user's credibility and the level of trust corresponding to the SQL quality score; Based on the level of trust, user credibility, and SQL quality score, a priority index is constructed. The computing resource allocation strategy is dynamically adjusted based on the aforementioned priority indicators.
6. The method for multi-factor quality assessment and dynamic resource allocation for SQL statements as described in any one of claims 1-5, characterized in that, After dynamically adjusting the computing resource allocation strategy based on the user's trustworthiness and the SQL quality score, the method further includes: Once the adjusted resource allocation strategy has been executed, obtain the execution result data and the actual resource consumption data. Obtain user evaluation data on the query results of the SQL statement to be verified, and record the rating data and task blocking status. The execution result data, actual resource consumption data, evaluation data, scoring data, and task blocking status are cleaned and labeled to construct a feedback sample set; The large model is iteratively optimized based on the feedback sample set, wherein the large model is used to generate the SQL statement to be verified.
7. A multi-factor quality assessment and dynamic resource allocation device for SQL statements, characterized in that, The device includes: The reliability verification unit is used to perform reliability verification on the SQL statement to be verified. An evaluation unit, if verification passes, dynamically calculates user credibility based on the target user's historical behavior and permission information, and scores the quality of the SQL statement to be verified based on multi-dimensional scoring functions and a knowledge retrieval space to obtain an SQL quality score. This includes: constructing a multi-dimensional scoring function set, which includes at least one of a syntax compliance scoring function, a semantic rationality scoring function, a security scoring function, a performance prediction scoring function, and a large model confidence scoring function; constructing a structured knowledge retrieval space, which includes at least one of a syntax knowledge subspace, a semantic knowledge subspace, a security knowledge subspace, a performance knowledge subspace, and a generation knowledge subspace; based on the corresponding knowledge subspace in the structured knowledge retrieval space, calling the matching dimension scoring function from the multi-dimensional scoring function set to calculate the target dimension score; and obtaining the SQL quality score based on preset scoring rules and the target dimension score. The resource allocation unit is used to dynamically adjust the computing resource allocation strategy based on the user's trustworthiness and the SQL quality score, so as to execute the corresponding operation based on the adjusted resource allocation strategy.
8. A computer device comprising a memory, a processor, and computer-readable instructions stored in the memory and executable on the processor, characterized in that, When the processor executes the computer-readable instructions, it implements the steps of the multi-factor quality assessment and dynamic resource allocation method for SQL statements as described in any one of claims 1-6.
9. A readable storage medium storing computer-readable instructions, characterized in that, When the computer-readable instructions are executed by the processor, they implement the steps of the multi-factor quality assessment and dynamic resource allocation method for SQL statements as described in any one of claims 1-6.
Citation Information
Patent Citations
Financial database SQL quality scoring method, system and device based on deep learning and storable medium
CN117827882A
Query method and system for generating SQL statement based on natural language
CN119377241A