Database query method and apparatus, electronic device, and storage medium

By parsing and estimating the syntax tree and data volume of the query request, full table queries are blocked, thus solving the problem of server memory exhaustion caused by full table queries in traditional databases and ensuring database stability and performance.

CN116795865BActive Publication Date: 2026-02-24PING AN BANK CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310764247.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-06-26
Publication Date
2026-02-24
Estimated Expiration
2043-06-26

AI Technical Summary

Technical Problem

In the era of big data, full table queries in traditional relational databases can cause server nodes to run out of memory, affecting database stability. Furthermore, insufficient testing environments have prevented the full table query problem from being discovered.

Method used

By parsing the syntax tree of the query request, validating the query conditions, estimating the data volume ratio of the query fields, blocking full table queries, and using a sampled database for data volume estimation, unnecessary data processing is avoided.

Benefits of technology

It effectively avoids full table queries, maintains the stability of the server and database, reduces unnecessary time consumption, is imperceptible to users, and has low performance overhead.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116795865B_ABST
    Figure CN116795865B_ABST
Patent Text Reader

Abstract

Embodiments of the application disclose a database query method and device, electronic equipment and a storage medium, wherein the method comprises: in the case of detecting a query request, parsing a query statement of the query request into a syntax tree; checking a query condition in the syntax tree, if the query condition in the syntax tree does not satisfy a preset condition, confirming that the query request is a full table query, and not allowing the query request; if the query condition in the syntax tree satisfies the preset condition, estimating a ratio of a value of a query field in the query request to a total data amount; if the ratio is greater than a preset data amount ratio, not allowing the query request; and if the ratio is not greater than the preset data amount ratio, executing a query operation corresponding to the query request, which can avoid full table query, unnecessary time consumption and data processing, and maintain stability of a server and a database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, and in particular to a database query method, apparatus, electronic device and storage medium. Background Technology

[0002] In the era of big data, the types and scale of database systems are constantly expanding, which brings certain challenges to database management.

[0003] Currently, the main data storage in the equity system uses a traditional relational database, resulting in a significant number of full table queries. Full table queries are time-consuming, and sometimes they can cause the server node to run out of memory, leading to node crashes. In severe cases, this can even affect database functionality; if the database is affected, all functions of the equity system will be impacted. Furthermore, due to inadequate code development standards and limited data in the testing environment, the full table query issue cannot be accurately identified during the testing phase. Summary of the Invention

[0004] This application provides a database query method, apparatus, electronic device, and storage medium that can avoid full table queries, avoid unnecessary time consumption and data processing, and maintain the stability of the server and database.

[0005] In a first aspect, embodiments of this application provide a database query method, the method comprising:

[0006] Upon detecting a query request, the query statement of the query request is parsed into a syntax tree;

[0007] The query conditions in the syntax tree are verified. If the query conditions in the syntax tree do not meet the preset conditions, the query request is confirmed to be a full table query and the query request is not allowed.

[0008] If the query conditions in the syntax tree meet the preset conditions, estimate the ratio of the value of the query field in the query request to the total amount of data.

[0009] If the ratio is greater than the preset data volume ratio, the query request is not allowed;

[0010] If the ratio is not greater than the preset data volume ratio, execute the query operation corresponding to the query request.

[0011] In one optional implementation, the preset conditions include:

[0012] The query conditions in the syntax tree exist and are not static conditions.

[0013] In one optional implementation, estimating the ratio of the value of the query field in the query request to the total data volume includes:

[0014] Data for the query field is extracted from the sampling database. Based on the ratio of the data for the query field in the sampling database to the total data volume of the sampling database, the ratio of the value of the query field in the query request to the total data volume is estimated.

[0015] In an optional implementation, before estimating the ratio of the value of the query field in the query request to the total amount of data, the method further includes:

[0016] Establish the same sampling database as the production database;

[0017] Data from the production database is synchronized to the sampling database through sample collection. The amount of data in the sampling database is smaller than that in the production database.

[0018] In an optional implementation, before parsing the query statement of the query request into a syntax tree, the method further includes:

[0019] The query statement is parsed and verified, and full table query statements are filtered out.

[0020] Secondly, embodiments of this application provide a database query apparatus, including a syntax tree parsing module, a verification module, and an execution module. The verification module includes an analysis module and a data volume evaluation module.

[0021] The syntax tree parsing module is used to parse the query statement of the query request into a syntax tree when a query request is detected.

[0022] The analysis module is used to verify the query conditions in the syntax tree;

[0023] The execution module is configured to, if the query conditions in the syntax tree do not meet the preset conditions, confirm that the query request is a full table query and disallow the query request.

[0024] The data volume evaluation module is used to estimate the ratio of the value of the query field in the query request to the total data volume if the query conditions in the syntax tree meet the preset conditions.

[0025] The execution module is further configured to disallow the query request if the ratio is greater than a preset data volume ratio.

[0026] The execution module is further configured to execute the query operation corresponding to the query request if the query conditions in the syntax tree meet the preset conditions and the ratio is not greater than the preset data volume ratio.

[0027] Optionally, the preset conditions include:

[0028] The query conditions in the syntax tree exist and are not static conditions.

[0029] Optionally, the execution module is specifically used for:

[0030] If the query condition in the syntax tree does not exist, or if the query condition in the syntax tree is a static condition, the query request is confirmed to be a full table query and the query request is not allowed.

[0031] Optionally, the data volume assessment module is specifically used for:

[0032] Data for the query field is extracted from the sampling database. Based on the ratio of the data for the query field in the sampling database to the total data volume of the sampling database, the ratio of the value of the query field in the query request to the total data volume is estimated.

[0033] Optionally, the database query device further includes a creation module, used for:

[0034] Establish the same sampling database as the production database;

[0035] Data from the production database is synchronized to the sampling database through sample collection. The amount of data in the sampling database is smaller than that in the production database.

[0036] Optionally, the database query device further includes a parsing module, used to parse and verify the query statement before parsing the query statement of the query request into a syntax tree, and to filter full table query statements.

[0037] Thirdly, embodiments of this application also provide an electronic device, including a processor, an input device, an output device, and a memory, wherein the processor, input device, output device, and memory are interconnected, wherein the memory is used to store a computer program, the computer program includes program instructions, and the processor is configured to invoke the program instructions to execute the method as described in the first aspect and any possible implementation thereof.

[0038] Fourthly, embodiments of this application provide a computer storage medium storing a computer program, the computer program including program instructions, which, when executed by a processor, cause the processor to perform the method described in the first aspect and any of its possible implementations.

[0039] This application embodiment effectively avoids full table queries by parsing the query statement into a syntax tree upon detecting a query request; it then verifies the query conditions in the syntax tree. If the query conditions in the syntax tree do not meet preset conditions, the query request is confirmed as a full table query and is not allowed. If the query conditions in the syntax tree meet the preset conditions, the ratio of the value of the query field in the query request to the total data volume is estimated. If the ratio is greater than a preset data volume ratio, the query request is not allowed. If the ratio is not greater than the preset data volume ratio, the query operation corresponding to the query request is executed. This approach effectively avoids full table queries by parsing the query statement and estimating the data volume, without the user's awareness, thus avoiding unnecessary time consumption and data processing, and maintaining server and database stability. Attached Figure Description

[0040] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below.

[0041] Figure 1 This is a schematic flowchart of a database query method provided in an embodiment of this application;

[0042] Figure 2 This is a flowchart illustrating another database query method provided in an embodiment of this application;

[0043] Figure 3 This is a schematic diagram of the structure of a database query device provided in an embodiment of this application;

[0044] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0045] 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, not all, of the embodiments of this application. The term "embodiment" as used herein means that a specific feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of this application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.

[0046] Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0047] The terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or apparatuses.

[0048] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the scope of the application. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.

[0049] It should also be further understood that the term “and / or” as used in this application specification and the appended claims means any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0050] As used in this specification and the appended claims, the term "if" may be interpreted, depending on the context, as "when," "once," "in response to determination," or "in response to detection." Similarly, the phrases "if determined" or "if [described condition or event] is detected" may be interpreted, depending on the context, as "once determined," "in response to determination," "once [described condition or event] is detected," or "in response to detection of [described condition or event]."

[0051] To better understand the embodiments of this application, the methods of applying the embodiments of this application will be described below.

[0052] The database mentioned in this application embodiment is a computer software system that stores and manages data according to a data structure.

[0053] A Database Management System (DBMS) is a software system designed for managing databases, generally possessing basic functions such as storage, retrieval, security, and backup. DBMSs can be categorized based on the database model they support (e.g., relational, XML); the type of computer they support (e.g., server clusters, mobile); the query language used (e.g., SQL, XQuery); performance priorities (e.g., maximum scale, maximum operating speed); or other classification methods. Regardless of the classification method used, some DBMSs can cross categories, for example, supporting multiple query languages ​​simultaneously.

[0054] The database query in this embodiment of the application, which queries the contents of all tables in the database, is also called a full table query or a large table query.

[0055] The terminal devices mentioned in this application embodiment are devices capable of communicating with a server. The server in this application embodiment, also called a server server, is a device that provides computing services and allows multiple terminal devices to access it. The aforementioned terminal devices include, but are not limited to, desktop computers and mobile terminals. The aforementioned mobile terminals may include various handheld devices with wireless communication functions, wearable devices, computing devices or other processing devices connected to a wireless modem, as well as various forms of user equipment (UE), mobile stations (MS), etc.

[0056] Please see Figure 1 This is a schematic flowchart illustrating a database query method provided in an embodiment of this application, such as... Figure 1 The method shown may include:

[0057] 101. Upon detecting a query request, parse the query statement of the above query request into a syntax tree.

[0058] The execution entity in this application embodiment can be a database query device. The database query method can be applied to the rights and interests system, thus it is a rights and interests system database query device. It can also be understood as a database management system, which can be implemented through the rights and interests system database server.

[0059] The benefits system in this application embodiment can be understood as a business model that incentivizes user participation and interaction by issuing and using prizes. It includes various forms, such as coupons, points, and red envelopes, which can be obtained through lotteries, redemptions, etc. Simultaneously, the benefits system also requires a management rule plugin to achieve flexible rule configuration and support various activity scenarios. Through these methods, users can obtain specific prizes, enhancing the business promotion effect of the activity. For the benefits system, the amount of data to be processed and stored is large, and database access is frequent. Therefore, this application mainly proposes a database query method for the benefits system to avoid queries with huge data processing volumes, such as full table queries, and maintain system stability.

[0060] This application embodiment can utilize an SQL Server database, which can effectively improve the speed of data request and response, and effectively handle complex tasks. Users can use SQL statements to perform operations such as querying views and base tables.

[0061] The above query request is a request instruction to the database to query data, which can be called a Query. The query statement in the query request is the specific query operation command statement, which can be an SQL statement.

[0062] The syntax tree mentioned in this application embodiment, also known as a syntax number, is an abstract representation of the syntax structure of source code. It represents the syntax structure of a programming language in a tree-like form, with each node in the tree representing a structure in the source code.

[0063] The Structured Query Language (SQL) mentioned in this application embodiment is a database language with multiple functions such as data manipulation and data definition. This language has interactive features and can provide great convenience to users. Database management systems can make full use of SQL to improve the working quality and efficiency of computer application systems.

[0064] Specifically, upon detecting a query request, the query statement can be parsed to obtain the corresponding syntax tree. A parsing method can be selected as needed; for example, Apache Calcite can be used. Apache Calcite, mentioned in this embodiment, is a framework that provides standard SQL, various query optimizations, and connectivity to various data sources, allowing users to easily access various data and perform SQL queries.

[0065] In an optional implementation, this embodiment of the application can perform preliminary parsing and verification before each query request reaches the database, filtering out suspected full-table query statements. The query statements to be filtered can be preset, for example:

[0066] select*from table, or select*from table where 1=1;

[0067] The two statements above represent a query without any restrictions, and a query with restrictions, but those restrictions are invalid.

[0068] After parsing and obtaining the syntax tree, step 102 can be performed.

[0069] 102. Validate the query conditions in the above syntax tree. If the query conditions in the above syntax tree do not meet the preset conditions, confirm that the above query request is a full table query and do not allow the above query request.

[0070] In this stage of validation, the query conditions in the syntax tree are first validated to determine whether they meet the preset conditions, thus confirming whether it is a full table query.

[0071] In one optional implementation, the above-mentioned preset conditions include:

[0072] The query conditions in the above syntax tree exist and are not static conditions.

[0073] Specifically, the above query conditions can be WHERE clauses. Using WHERE clauses allows you to filter data in the table, and records that meet the conditions will appear in the result set. If the WHERE clause does not exist, or if it exists but is a static condition (e.g., 1=1), the query request will be considered a full table scan and will not be allowed, resulting in an error. If the WHERE clause exists and is not a static condition, the validation can continue, and step 103 can be executed.

[0074] 103. If the query conditions in the above syntax tree meet the above preset conditions, estimate the ratio of the value of the query field in the above query request to the total amount of data.

[0075] 104. If the above ratio is greater than the preset data volume ratio, the above query request will not be allowed.

[0076] 105. If the above ratio is not greater than the above preset data volume ratio, execute the query operation corresponding to the above query request.

[0077] Even if valid query conditions exist, it doesn't guarantee that the query request will be approved. For example, if a user table's gender field only has two values ​​(male and female), and the user table has a large amount of data, and the WHERE clause only includes gender as a filter field, the query will still retrieve only half the data, resulting in an excessively large data volume. Therefore, this embodiment also includes a data volume assessment module to estimate the ratio of the query field's value to the total data volume.

[0078] In one optional implementation, estimating the ratio of the value of the query field in the query request to the total data volume includes:

[0079] Data for the above query field is extracted from the sample database. Based on the ratio of the data for the above query field in the sample database to the total data volume of the sample database, the ratio of the value of the query field in the above query request to the total data volume is estimated.

[0080] In an optional implementation, prior to step 103, the method further includes:

[0081] Establish the same sampling database as the production database described above;

[0082] Data from the production database is synchronized to the sampling database through sample collection. The amount of data in the sampling database is smaller than that in the production database.

[0083] Specifically, after the query conditions are validated, the data volume of the query request can be assessed. This embodiment of the application can estimate the data volume of the query request using a sampled database. Data for the query field can be extracted from the sampled database, and then the ratio of the data for that query field in the sampled database to the total data volume of the sampled database can be calculated. This allows for an estimation of the ratio of the query field's value to the total data volume in the aforementioned query request.

[0084] The database in this embodiment can be called the production database. First, a sampling database that is exactly the same as the production database can be built. Data in the production database is synchronized to the sampling database through sample collection. The data volume of the sampling database is much smaller than that of the production database. The data volume can be set as needed. For example, the data volume of the sampling database can be set to only one percent of the data volume of the production database to reduce the amount of data processing and improve the estimation efficiency.

[0085] After the query conditions are validated, the ratio of the value of the queried field to the total data volume can be estimated. If this ratio is greater than a preset data volume ratio, the query request will not be allowed. The preset data volume ratio can be set as needed, for example, 30%.

[0086] For example, if this query requests users whose gender is male from the user table, then first, all data from the sampled user table is retrieved from the sampled database. Then, the proportion of male users to the total number of users is calculated. If this proportion exceeds a preset data volume threshold, the query request is not allowed. This data volume estimation-based validation method can limit queries involving large datasets.

[0087] If the estimated ratio is not greater than the preset data volume ratio, the query operation corresponding to the query request can be executed. That is, if the query conditions in the syntax tree meet the preset conditions and the ratio is not greater than the preset data volume ratio, the database can be queried normally.

[0088] Figure 2 A flowchart illustrating another database query method provided in this application embodiment is shown below. Figure 2 As shown, a sampling database can be pre-established based on the production database according to the sample collection method in the aforementioned embodiments. The specific data query process is as follows:

[0089] 1. Parse and validate each query before it is sent to the database, and filter out statements that are suspected of being full table queries.

[0090] 2. The incoming query statement will first be parsed into a syntax tree and then passed to the validation module. The analysis module will validate the WHERE condition in the syntax tree. If the WHERE condition does not exist or exists but is a static condition (e.g., 1=1), the query request will be regarded as a full table query and an error will be reported directly.

[0091] 3. If the query statement passes validation, proceed to data volume assessment validation to estimate the ratio of the value of this field in the current query to the total data volume. For example, if the query in this query is for users whose gender is male, then first retrieve the table data from the sample database, that is, extract all the data from the sample user table, and then calculate the proportion of users whose gender is male to the total number of users. If it exceeds a certain threshold, the query request will not be allowed.

[0092] 4. If both of the above checks pass, you can query the database normally.

[0093] In optional implementations, the methods in this application embodiment can also be applied to the data query process of other systems, and can be adapted to specific application situations. This application embodiment does not limit this.

[0094] Currently, the main data storage in the equity system still uses a traditional relational database. Full table queries are not the primary time-consuming operation, but sometimes they can cause the server node to run out of memory, leading to node crashes. In severe cases, they can even affect the database itself; if the database is affected, all functions of the equity system will be impacted. Ultimately, the root cause of full table queries is the lack of standardized code development and the limited data in the testing environment, making it impossible to detect issues during the testing phase.

[0095] The database query method in this embodiment of the application, upon detecting a query request, parses the query statement of the query request into a syntax tree; verifies the query conditions in the syntax tree; if the query conditions in the syntax tree do not meet preset conditions, confirms that the query request is a full table query and disallows the query request; if the query conditions in the syntax tree meet the preset conditions, estimates the ratio of the value of the query field in the query request to the total data volume; if the ratio is greater than a preset data volume ratio, disallows the query request; if the ratio is not greater than the preset data volume ratio, executes the query operation corresponding to the query request. The method effectively blocks full table queries by parsing the query statement and estimating the query data volume without the user's awareness. Furthermore, by sampling the database to estimate the actual query data volume with a small amount of data, the performance consumption is low, there is no intrusion into the original database, and the estimation is relatively accurate.

[0096] Based on the foregoing method embodiments, this application also provides a database query device.

[0097] Please see Figure 3 , Figure 3 This is a schematic diagram of the structure of a database query device provided in an embodiment of this application. Figure 3 As shown, the database query device 300 includes a syntax tree parsing module 310, a verification module 320, and an execution module 330. The verification module 320 includes an analysis module 321 and a data volume evaluation module 322.

[0098] The syntax tree parsing module 310 described above is used to parse the query statement of the query request into a syntax tree when a query request is detected.

[0099] The analysis module 321 described above is used to verify the query conditions in the syntax tree described above;

[0100] The execution module 330 is used to confirm that the query request is a full table query and not allow the query request if the query conditions in the syntax tree do not meet the preset conditions.

[0101] The aforementioned data volume evaluation module 322 is used to estimate the ratio of the value of the query field in the query request to the total data volume if the query conditions in the syntax tree meet the aforementioned preset conditions.

[0102] The aforementioned execution module 330 is also used to disallow the aforementioned query request if the aforementioned ratio is greater than a preset data volume ratio.

[0103] The execution module 330 is further configured to execute the query operation corresponding to the query request if the query conditions in the syntax tree meet the preset conditions and the ratio is not greater than the preset data volume ratio.

[0104] Optionally, the above preset conditions include:

[0105] The query conditions in the above syntax tree exist and are not static conditions.

[0106] In an optional implementation, the execution module 330 is specifically used for:

[0107] If the query conditions in the above syntax tree do not exist, or if the query conditions in the above syntax tree are static conditions, the above query request is confirmed to be a full table query and is not allowed.

[0108] In an optional implementation, the data volume evaluation module 322 described above is specifically used for:

[0109] Data for the above query field is extracted from the sample database. Based on the ratio of the data for the above query field in the sample database to the total data volume of the sample database, the ratio of the value of the query field in the above query request to the total data volume is estimated.

[0110] In an optional embodiment, the database query device 300 further includes a creation module 340, used for:

[0111] Establish the same sampling database as the production database;

[0112] Data from the production database is synchronized to the sampling database through sample collection. The amount of data in the sampling database is smaller than that in the production database.

[0113] In an optional implementation, the database query device 300 further includes a parsing module 350, which is used to parse and verify the query statement before parsing the query statement of the query request into a syntax tree, and to filter full table query statements.

[0114] According to the specific implementation of the embodiments of this application, Figure 1 and Figure 2 The steps involved in the database query method shown can be from Figure 3 The database query device 300 shown is executed by various modules, which will not be described in detail here.

[0115] The database query device 300 of this application embodiment, upon detecting a query request, parses the query statement of the query request into a syntax tree; verifies the query conditions in the syntax tree; if the query conditions in the syntax tree do not meet preset conditions, confirms that the query request is a full table query and disallows the query request; if the query conditions in the syntax tree meet the preset conditions, estimates the ratio of the value of the query field in the query request to the total data volume; if the ratio is greater than a preset data volume ratio, disallows the query request; if the ratio is not greater than the preset data volume ratio, executes the query operation corresponding to the query request; wherein, by parsing the query statement and estimating the query data volume, full table queries are effectively blocked without the user's awareness, and by using a sampled database to estimate the actual query data volume with a small amount of data, performance consumption is low, there is no intrusion into the original database, and the estimation is relatively accurate.

[0116] Please see Figure 4 , Figure 4 This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of this application. For example... Figure 4As shown, the electronic device 400 includes a processor 401 and a memory 402. The electronic device 400 may also include a bus 403, through which the processor 401 and the memory 402 can be interconnected. The bus 403 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus 403 can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, Figure 4 The bus is represented by a single thick line, but this does not indicate that there is only one bus or one type of bus. The electronic device 400 may further include an input / output device 404, which may include a display screen, such as a liquid crystal display (LCD). The memory 402 is used to store one or more programs containing instructions; the processor 401 is used to invoke the instructions stored in the memory 402 to execute the above-mentioned... Figure 1 or Figure 2 Some or all of the method steps mentioned in the embodiments.

[0117] It should be understood that, in the embodiments of this application, the processor 401 may be a central processing unit (CPU), but it may also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor.

[0118] Input device 402 may include a touchpad, a fingerprint sensor (for collecting the user's fingerprint information and fingerprint orientation information), a microphone, etc., and output device 403 may include a display (LCD, etc.), a speaker, etc.

[0119] The memory 404 may include read-only memory and random access memory, and provides instructions and data to the processor 1101. A portion of the memory 404 may also include non-volatile random access memory. For example, the memory 404 may also store device type information.

[0120] The electronic device 400 of this application embodiment can, upon detecting a query request, parse the query statement of the query request into a syntax tree; verify the query conditions in the syntax tree; if the query conditions in the syntax tree do not meet preset conditions, confirm that the query request is a full table query and disallow the query request; if the query conditions in the syntax tree meet the preset conditions, estimate the ratio of the value of the query field in the query request to the total data volume; if the ratio is greater than a preset data volume ratio, disallow the query request; if the ratio is not greater than the preset data volume ratio, execute the query operation corresponding to the query request; wherein, by parsing the query statement and estimating the query data volume, full table queries are effectively blocked without the user's awareness; furthermore, by using a sampled database to estimate the actual query data volume with a small amount of data, performance consumption is low, there is no intrusion into the original database, and the estimation is relatively accurate.

[0121] This application also provides a computer storage medium storing a computer program for electronic data interchange, which causes a computer to perform some or all of the steps of any of the database query methods described in the above method embodiments.

[0122] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0123] In the several embodiments provided in this application, it should be understood that the disclosed apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or modules may be electrical or other forms.

[0124] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network modules. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0125] If the integrated module is implemented as a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned memory includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.

Claims

1. A database query method, characterized in that, The method includes: Upon detecting a query request, the query statement of the query request is parsed into a syntax tree; The query conditions in the syntax tree are verified. If the query conditions in the syntax tree do not meet the preset conditions, the query request is confirmed to be a full table query and the query request is not allowed. If the query conditions in the syntax tree meet the preset conditions, estimate the ratio of the value of the query field in the query request to the total data volume; estimating the ratio of the value of the query field in the query request to the total data volume includes: extracting data of the query field from the sample database, and estimating the ratio of the value of the query field in the query request to the total data volume based on the ratio of the data of the query field in the sample database to the total data volume of the sample database. If the ratio is greater than the preset data volume ratio, the query request is not allowed; If the ratio is not greater than the preset data volume ratio, execute the query operation corresponding to the query request.

2. The method according to claim 1, characterized in that, The preset conditions include: The query conditions in the syntax tree exist and are not static conditions.

3. The method according to claim 1, characterized in that, Before estimating the ratio of the value of the query field in the query request to the total amount of data, the method further includes: Establish the same sampling database as the production database; Data from the production database is synchronized to the sampling database through sample collection. The amount of data in the sampling database is smaller than that in the production database.

4. The method according to claim 3, characterized in that, Before parsing the query statement of the query request into a syntax tree, the method further includes: The query statement is parsed and verified, and full table query statements are filtered out.

5. A database query device, characterized in that, It includes a syntax tree parsing module, a verification module, and an execution module. The verification module includes an analysis module and a data volume evaluation module. The syntax tree parsing module is used to parse the query statement of the query request into a syntax tree when a query request is detected. The analysis module is used to verify the query conditions in the syntax tree; The execution module is configured to, if the query conditions in the syntax tree do not meet the preset conditions, confirm that the query request is a full table query and disallow the query request. The data volume evaluation module is used to estimate the ratio of the value of the query field in the query request to the total data volume if the query conditions in the syntax tree meet the preset conditions. The data volume assessment module is specifically used to: extract data of the query field from the sampling database, and estimate the ratio of the data of the query field in the query request to the total data volume based on the ratio of the data of the query field in the sampling database to the total data volume of the sampling database; The execution module is further configured to disallow the query request if the ratio is greater than a preset data volume ratio. The execution module is further configured to execute the query operation corresponding to the query request if the query conditions in the syntax tree meet the preset conditions and the ratio is not greater than the preset data volume ratio.

6. The apparatus according to claim 5, characterized in that, The execution module is specifically used for: If the query condition in the syntax tree does not exist, or if the query condition in the syntax tree is a static condition, the query request is confirmed to be a full table query and the query request is not allowed.

7. The apparatus according to claim 5, characterized in that, The data volume assessment module is specifically used for: Data for the query field is extracted from the sampling database. Based on the ratio of the data for the query field in the sampling database to the total data volume of the sampling database, the ratio of the value of the query field in the query request to the total data volume is estimated.

8. An electronic device, characterized in that, The system includes a processor, an input device, an output device, and a memory, which are interconnected. The memory is used to store a computer program, which includes program instructions. The processor is configured to invoke the program instructions to perform the method as described in any one of claims 1-4.

9. A computer storage medium, characterized in that, The computer storage medium stores a computer program, the computer program including program instructions, which, when executed by a processor, cause the processor to perform the method as described in any one of claims 1-4.

Citation Information

Patent Citations

  • Data query management method and device, computer equipment and readable storage medium

    CN113468217A

  • Instruction control method and device, computer system and computer readable storage medium

    CN113760893A