Methods and devices for query control of databases
By creating resource sub-groups within database systems to manage CPU and I/O resources at a session level, the method addresses the issue of resource misuse and instability, ensuring stable operation and efficient resource allocation.
Patent Information
- Application Number
- PCT/CN2024/118867
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-12-26
- Filing Date
- 2024-09-13
- Publication Date
- 2025-07-03
AI Technical Summary
Current database systems lack the ability to differentiate between normal and abnormal queries at a fine granularity, leading to resource misuse and potential system instability due to the minimum resource isolation being limited to the database process or user level.
Implementing a method that creates multiple resource sub-groups under a resource group, allowing for different control strategies based on query instances, using cgroups v1 technology to manage CPU and I/O resources at a session level, enabling finer control over resource usage.
This approach ensures stable database operation by preventing resource misuse, ensuring high-priority tasks are not starved of resources and reducing the occurrence of exceptions, while optimizing resource allocation for different queries.
Smart Images

Figure CN2024118867_03072025_PF_FP_ABST
Abstract
Description
METHODS AND DEVICES FOR QUERY CONTROL OF DATABASES
[0001] CROSS-REFERENCE TO RELATED APPLICATIONS
[0002] This application claims priority of Chinese Patent Application No. 202311814251.9, filed on December 26, 2023, the entire contents of which are incorporated herein by reference.TECHNICAL FIELD
[0003] The present disclosure relates to the technical field of database querying, and in particular, to methods and devices for query control of databases.BACKGROUND
[0004] Database SQL statement writing has a certain technical threshold, once there is a SQL statement written irrationally, it may affect the normal operation of all the business in the whole system. Currently, the main means to minimize unreasonable SQL statements is through the use of standardized training empowerment and SQL review. A database product may be used in several business platforms, a large number of developers are involved in product interfacing, and it is difficult to completely avoid any problem by relying on human constraints. In order to solve the gap that exists between people and systems, it is necessary to rely on the underlying database to adapt to the abnormal use case, thus ensuring the stable operation of the database.
[0005] The minimum granularity of resource isolation in current database products is only up to the database process level or the user level, which means that after a database user / role is attributed to a resource group, different types of queries under the user cannot differentiate between the use of resources. And some business queries are often used by the same database user, which makes it impossible to differentiate between the resource usage of abnormal and normal queries.
[0006] In view of the foregoing, there is a need to provide a method and a device for query control of the database and a storage medium for effectively supervising the use of resources.SUMMARY
[0007] One or more embodiments of the present disclosure provide a method implemented on at least one machine, each of which having at least one processor and a storage device for query control of a database. The method comprises: creating a plurality of resource sub-groups under at least one resource group of the database, the at least one resource group being associated with a user, wherein at least two of the plurality of resource sub-groups have different control strategies for database resources; determining an execution sub-group based on one or more instructions in a query instance, the execution sub-group being a resource sub-group of the plurality of resource sub-groups corresponding to the query instance; and controlling, based on a control strategy of the execution sub-group, a resource usage of the database when the query instance is executed.
[0008] One or more embodiments of the present disclosure provide a device for query control of a database, wherein the device comprises at least one processor and at least one storage device; the at least one storage device is configured to store computer instructions; the at least one processor is configured to execute at least a portion of the computer instructions to implement a method for query control of the database.
[0009] One or more embodiments of the present disclosure provide a non-transitory computer-readable storage medium storing computer instructions, wherein when reading the computer instructions in the storage medium, a computer implements a method for query control of a database.BRIEF DESCRIPTION OF THE DRAWINGS
[0010] This specification will be further illustrated by way of exemplary embodiments, which will be described in detail by means of the accompanying drawings. These embodiments are not limiting, and in these embodiments, the same numbering denotes the same structure, wherein:
[0011] FIG. 1 is a schematic diagram illustrating an implementation of a default resource group in a prior art;
[0012] FIG. 2 is an exemplary flowchart illustrating a method for query control of a database according to some embodiments of the present disclosure;
[0013] FIG. 3 is an exemplary schematic diagram illustrating determination of a control strategy according to some embodiments of the present disclosure;
[0014] FIG. 4 is an exemplary schematic diagram illustrating a database query method according to some embodiments of the present disclosure;
[0015] FIG. 5 is an exemplary flowchart illustrating determination of an execution sub-group according to some embodiments of the present disclosure;
[0016] FIG. 6 is another exemplary schematic diagram illustrating determination of an execution sub-group according to some embodiments of the present disclosure;
[0017] FIG. 7 is a flowchart of an embodiment illustrating a query instance creation method according to some embodiments of the present disclosure;
[0018] FIG. 8 is a schematic diagram of an embodiment illustrating a resource group implementation according to some embodiments of the present disclosure;
[0019] FIG. 9 is a schematic diagram of another embodiment illustrating a resource group implementation according to some embodiments of the present disclosure;
[0020] FIG. 10 is a schematic representation illustrating a resource group implementation shown in FIG. 9;
[0021] FIG. 11 is a schematic diagram illustrating an operation of a distributed database cluster according to some embodiments of the present disclosure;
[0022] FIG. 12 is a flowchart of an embodiment illustrating a database querying method according to some embodiments of the present disclosure;
[0023] FIG. 13 is a schematic diagram illustrating an initialization check for the startup phase of a database according to some embodiments of the present disclosure;
[0024] FIG. 14 is a schematic diagram illustrating an initialization configuration for the startup phase of a database according to some embodiments of the present disclosure;
[0025] FIG. 15 is a schematic diagram illustrating a resource group creation for the startup phase of a database according to some embodiments of the present disclosure;
[0026] FIG. 16 is a schematic diagram of an embodiment illustrating the structure of a database processing device according to some embodiments of the present disclosure; and
[0027] FIG. 17 is a schematic diagram of an embodiment illustrating the structure of a non-transitory computer-readable storage medium according to some embodiments of the present disclosure.DETAILED DESCRIPTION
[0028] In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the accompanying drawings required to be used in the description of the embodiments are briefly described below. Obviously, the accompanying drawings in the following description are only some examples or embodiments of the present disclosure, and it is possible for a person of ordinary skill in the art to apply the present disclosure to other similar scenarios in accordance with these drawings without creative labor. the present disclosure may be applied to other similar scenarios based on these drawings without creative labor. Unless obviously obtained from the context or the context illustrates otherwise, the same numeral in the drawings refers to the same structure or operation.
[0029] It should be understood that as used herein, the terms "system" , "device" , "unit" and / or "module" are used herein as a way to distinguish between different components, elements, parts, sections or assemblies at different levels. However, the words may be replaced by other expressions if other words accomplish the same purpose.
[0030] Unless the context clearly suggests an exception, the words "one" , "a" , "one" , "a" , and / or "the" do not refer specifically to the singular, but may also include the plural. Generally, the terms "including" and "comprising" suggest only the inclusion of clearly identified steps and elements. In general, the terms "including" and "comprising" only suggest the inclusion of explicitly identified steps and elements that do not constitute an exclusive list, and the method or apparatus may also include other steps or elements.
[0031] Flowcharts are used in this specification to illustrate operations performed by a system according to embodiments of this specification. It should be appreciated that the preceding or following operations are not necessarily performed in an exact sequence. Instead, steps may be processed in reverse order or simultaneously. Also, it is possible to add other operations to these processes or remove a step or steps from these processes.
[0032] The technical solutions in some embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings in some embodiments of the present disclosure, and it is clear that the embodiments described are only some of the embodiments of the present disclosure, and not all of them. Based on the embodiments in the present disclosure, all other embodiments obtained by a person of ordinary skill in the art without making creative labor fall within the scope of protection of the present disclosure.
[0033] The terms "first" , "second" , "third" , "fourth" , etc., if any, are used in the present disclosure and claims of the present disclosure and in the drawings described above to distinguish similar objects and need not be used to describe a particular order or sequence. It should be understood that the data so used may be interchangeable, so that the embodiments of the present disclosure described herein may be carried out, for example, in an order other than those illustrated or described herein. In addition, the terms "including" and "having" , and any variations thereof, are intended to cover non-exclusive inclusion, e.g., a process, method, system, product, or device that includes a series of steps or units need not be limited to those that are clearly listed, but may include other steps or units that are not clearly listed or are inherent to the process, method, product, or device.
[0034] The present disclosure relates to the technical field of hardware resource isolation of a database and other technical areas, and improves the robustness of the database by a query instance creation method of the present disclosure. The query instance creation method of the present disclosure provides the ability to limit the hardware resources used by the database at the session level, including but not limited to: CPU (central processing unit) resources, or I / O (input / output) resources, to avoid one or some unreasonable operation to occupy all the resources, resulting in high-priority tasks not being able to obtain the resources, or even leading to the occurrence of database exceptions.
[0035] Some embodiments of the present disclosure use the cgroups v1 technology within the database, making it possible to limit the use of resources for different statements of even the same database user to achieve a finer granularity of control, i.e., session level granularity control, while providing support for limiting I / O. The MPP (Massively Parallel Processor) database on which some embodiments of the present disclosure are based is Greenplum (hereinafter referred to as GP) .
[0036] The MPP database is a specific type of database management system designed to handle large-scale datasets and complex queries with high performance, high availability, and high scalability features, which may provide a cost-effective, general-purpose computing for the management of very large-scale data. Greenplum is an open source data warehouse, and is transformed based on the open source PostgreSQL, which is mainly used to handle large-scale data analysis tasks.
[0037] Cgroups (control groups) is a Linux kernel function used to limit, control and separate the resources of a process (group) , such as cpu, memory, disk input and output. Currently there are v1 and v2 versions, and the v2 version requires a higher system kernel. Some embodiments of the present disclosure use version v1. There are a number of sub-systems in the cgroups v1 technology such as cpu, cpuacct, cpuset, memory, blkio, devices, net_cls, net_prio, freezer, and other sub-systems. In some embodiments of the present disclosure, only the cpu sub-system and blkio sub-system among them will be described, and the other sub-systems are also applicable to the query instance creation method of the present disclosure, which is not repeated herein.
[0038] Before the query instance creation method of the present disclosure is implemented, the MPP database GP may have a default resource group implementation, which may be roughly described as follows: it creates the gpdb / cgroup group under the cpu sub-system as a resource root group, and after that, each created resource group (via SQL create resource group ... (cpu_RATE_LIMIT=integer, ... ) syntax) may have an associated group oid, which may be located under the gpdb / as a sub-cgroup (i.e., a resource sub-group) . As the user necessarily belongs to one of the resource groups, a query process issued by the user may also be attributed to the corresponding sub-cgroup, as shown in FIG. 1. FIG. 1 is a schematic diagram illustrating an implementation of a default resource group in a prior art.
[0039] According to FIG. 1, if <gid1> and <gid2> are created with rate limits specified as 50 and 25, respectively, with the ratio there between is two, which actually correspond to the weight values of cpu. shares in the cgroup. When there is a cpu resource competition, <gid1> may be able to get twice as many cpu resources as <gid2>. In other words, for the same number of identical queries, the query process attributed to <gid1> may be able to be executed faster than the query process attributed to <gid2>.
[0040] Through FIG. 1, it may be known that there are two main restrictions:
[0041] (1) The GP's default resource group implementation may use only cpu-related sub-systems, without using sub-systems such as blkio, which has no control over I / O read / write speeds.
[0042] (2) The GP's default resource group implementation may have the finest control granularity for users, i.e., all queries from the same user may be necessarily attributed to the same cgroup.
[0043] In real business application scenarios, in some cases the client may use only one user, and may not create many different users to differentiate between them. Although the client includes several queries, GP's default resource group functionality may be unable to differentiate and limit the use of resources for each of these queries because there is only one user.
[0044] Therefore, the query instance creation method provided in the present disclosure addresses the two major restrictions mentioned above, more descriptions may be found in FIGs. 2-17 of the present disclosure.
[0045] FIG. 2 is an exemplary flowchart illustrating a method for query control of a database according to some embodiments of the present disclosure. As shown in FIG. 2, process 200 may include one or more of the following operations. In some embodiments, the process 200 may be executed by a processor (e.g., a processor 61 shown in FIG. 16) .
[0046] In 210, a plurality of resource sub-groups may be created under at least one resource group of the database.
[0047] The database is a repository that organizes, stores, and manages data according to a data structure. The resource group is a sub-group used to manage the allocation of database resources. For example, the resource group may be a cgroup. More descriptions regarding the cgroup may be found in the related description of FIG. 1. The database resources may refer to all or some of the hardware equipment, software facilities, data, etc., that are required to perform database queries.
[0048] In some embodiments, the database may include an MPP database. More descriptions regarding the MPP database may be found in the related description of FIG. 1.
[0049] In some embodiments, the resource group of the MPP database may include a resource group corresponding to at least one of a CPU sub-system and an I / O sub-system. For example, the resource group of the MPP database may include a CPU resource group corresponding to the CPU sub-system and / or an I / O resource group corresponding to the I / O sub-system. More descriptions regarding the CPU sub-system and the I / O sub-system and the corresponding resource groups may be found elsewhere in the present disclosure.
[0050] In some embodiments, each resource group may be represented by a unique ID, referred to as a gid.
[0051] In some embodiments, the processor may use SQL create resource group (CPU_RATE_LIMIT=integer, BLKIO_RATE_LIMIT=integer... ) syntax to create the resource group for the database.
[0052] In some embodiments of the present disclosure, by setting up the resource group of the database, it is possible to make different users belong to different groups, and the processor can allocate resources to different groups through the resource group based on a control strategy. Users can set their specific CPU, memory, and concurrency limits individually for each group, for the purpose of controlling the allocation and use of resources at different levels.
[0053] The user may be a user entity that may operate and use the database. In some embodiments, the resource groups may be associated with a user. For example, a user may necessarily belong to a particular resource group, and every query may belong to a particular user, i.e., a query process may belong to a particular user, and therefore the query process may also belong to a particular resource group. The query process may be an instance of an ongoing query program.
[0054] The resource group is used to restrict, record and / or isolate the resource use of processes. The object on which the operations are performed is the process. The database query operation is essentially a process, and may be understood as a connection established between the client and the database. The user logged in through user information (asession) , and executed one or more query operations (aplurality of queries) . At the level of an operating system, the above a plurality of query operations may be viewed as a same process.
[0055] It may be understood that the database query must be attributed to a user, the user of the database must be attributed to the resource group, a query process must be created when the database query is performed, and the query process must correspond to a process number. That is, after a user logged in (session) , a plurality of database queries must be attributed to a database resource group, belong to the same process, and correspond to the same process number.
[0056] In some embodiments, the processor may write the process number to the corresponding resource group, and the processor may limit the database resources for the process based on the resource group corresponding to the process number.
[0057] It may be understood that the resource group controls the resource use of the process, the database query is a process, the database query may have a corresponding process number, the processor may realize the resource control by writing the process number to the resource sub-group of the resource group.
[0058] The resource sub-group is a further subdivision of the resource group. In some embodiments, at least two of the plurality of resource sub-groups under the resource group have different control strategies for the database resources.
[0059] The control strategy refers to a strategy for controlling the allocation of the database resources. For example, the control strategy may include assigning different database resources to be used by the resource sub-groups with different weights based on the query statement. More descriptions regarding the control strategy may be found in FIG. 3. More descriptions regarding the query statement may be found in descriptions of FIG. 4.
[0060] In some embodiments, the processor may create the plurality of resource sub-groups in a plurality of ways. FIG. 10 is a schematic diagram illustrating a resource group implementation shown in FIG. 9. As shown in FIG. 10, the numbers 6437, 6438, and 68903 in the figure represent the resource groups (gid cgroup) of the database, and under each gid cgroup, there are four resource sub-groups marked as “lowest” , “low” , “middle” , and “high” , representing the four resource sub-groups have the lowest, low, middle, and high weight levels, which are a further refinement of the same resource group (i.e., gid cgroup) . In some embodiments, the count of the resource sub-groups may be any other number, and the weight levels may be set to other levels (e.g., a resource group may include 3 resource sub-groups with weight levels of lowest, low, middle, etc. ) . More descriptions regarding the weight levels and creating the plurality of resource sub-groups may be found in the descriptions of FIG. 3.
[0061] In some embodiments, the processor may create a resource root group for the database under the CPU sub-system and the I / O sub-system of the operating system on which the resource group is running, respectively; identify a central processing unit resource root group and an input / output resource root group; create at least one resource group under a central processing unit resource root group and an input / output resource root group, respectively; create at least one resource group under the at least one resource group; and create a plurality of resource sub-groups under the at least one resource group.
[0062] The operating system is a built-in program that is used to collaborate with a computer's various pieces of hardware to interact with the user and implement resource management. For example, the operating system may be at least one of Windows, macOS, open source Linux, etc.
[0063] The CPU (Central Processing unit) sub-system refers to the sub-system that controls the allocation of the system's CPU time slice. The time slice, also known as a "quantum" or "processor slice" , is a microscopic amount of CPU time allocated to each running process.
[0064] In some embodiments, the CPU sub-system may provide resources to handle the execution of programs. For example, the CPU sub-system may control the allocation of the system CPU resources, i.e., the allocation of processing resources. The CPU is needed to execute the program when the program runs. The processing resources are the amount of time the CPU takes to execute the program.
[0065] The I / O (Input / Output) sub-system refers to the sub-system that controls the allocation of the system's I / O resources (read and write resources) . In some embodiments, the I / O sub-system may provide read and write resources. For example, the I / O sub-system may control the allocation of I / O resources, i.e., read and write resources. The read and write resources refer to the associated resources required to read and write to the storage device.
[0066] The above processing resources and the read and write resources are the resources that a query instance relies on to perform query operations. More descriptions regarding the query instance may be found later in the description.
[0067] In some embodiments, the I / O sub-system may be a blkio sub-system. The blkio sub-system is the sub-system used to limit the I / O rate (read and write rate) of a block device.
[0068] In some embodiments, the blkio sub-system may control and monitor accesses to block device read and write resources used by tasks in the resource group. For example, based on the "weight allocation"approach, the blkio sub-system may utilize the Completely Fair Queuing I / O scheduler to assign weights to the specified resource groups. As another example, based on an "IO throttling" approach, when a given device performs a read or write operation, the blkio sub-system may set an upper limit on the number of operations, i.e., a limit on the number of read or write operations for a device.
[0069] In some embodiments of the present disclosure, by setting the I / O sub-system being the blkio sub-system, the problem of processes interfering with each other when they jointly read and write to the same disk may be reduced, and the database resources can be fully utilized when not busy.
[0070] The resource root group refers to the root directory to which the resource groups of the database belong. In some embodiments, the CPU sub-system corresponds to the CPU resource root group. The I / O sub-system corresponds to the I / O resource root group.
[0071] In some embodiments, the processor may create at least one corresponding resource group under the CPU resource root group and the input / output resource root group, respectively, as a parent corresponding to the resource sub-group under the resource group (e.g., the CPU resource group and the I / O resource group) .
[0072] In some embodiments, the processor may create the plurality of resource sub-groups under the at least one resource group, e.g., under the CPU resource group and / or the I / O resource group, respectively.
[0073] The plurality of resource sub-groups may be created in a manner similar to the above, and may be referred to in the related descriptions thereof.
[0074] In some embodiments of the present disclosure, by creating the resource root groups under the CPU sub-system and the I / O sub-system of the operating system which is running the resource group, respectively, determining the corresponding resource groups, respectively, and creating the plurality of resource sub-groups under the corresponding resource groups, a finer-grained control of the database resources can be realized.
[0075] In 220, an execution sub-group may be determined based on one or more instructions in the query instance.
[0076] The query instance refers to a set of memory structures used to query a database file. For example, the query instance may be a series of system processes, a memory block allocated for a system process, etc.
[0077] In some embodiments, querying using the database requires logging into the database using the user information (e.g., account number, password, etc. ) . In a query, it is necessary to establish a database connection, keep the connection not closed, the query process may be called a session; the session may carry out a plurality of query operations for the database, and each query may carry the user information who establishes the connection, the a plurality of query operations above are attributed to the user who established the connection. The above session is the query instance.
[0078] In some embodiments, the processor needs to take up resources of the database each time the processor performs a query operation of the database, e.g., to take up processing resources, read and write resources, or the like.
[0079] The one or more instructions are computer instructions of the process used to determine the execution sub-group based on the user information or the query statement. More descriptions regarding the user information and the query statement may be found in the relevant descriptions of FIG. 3.
[0080] The execution sub-group refers to a resource sub-group that the query instance needs to specify before executing the query statement. In some embodiments, the execution sub-group may be a resource sub-group corresponding to the query instance. In some embodiments, the processor may determine the execution sub-group based on a default order of the weight levels. For example, if the default order is middle, high, low, and lowest, the execution sub-group may be prioritized to be set to the middle resource sub-group, and if the processing resources of the middle resource sub-group are not enough, the high resource sub-group may be added to the execution sub-group.
[0081] In some embodiments, the processor may, in a plurality of ways, determine the execution sub-group. For example, the processor may determine the execution sub-groups based on analysis of the query statement, manual evaluation, evaluation through a model, or the like. Exemplarily, the processor may determine the execution sub-group corresponding to the query statement via a query prediction model, based on the query statement.
[0082] The query prediction model refers to a model for determining anomaly likelihood in a query as well as query prediction time. In some embodiments, the query prediction model may be a machine learning model. In some embodiments, an input of the query prediction model may include the query instance and the one or more instructions, and an output may include the anomaly likelihood and the query prediction time. The anomaly likelihood refers to the likelihood that the query corresponding to the query statement is an anomalous query. The query prediction time refers to the estimated amount of time the query might take.
[0083] In some embodiments, the query prediction model may be obtained from a large number of labeled training samples. The training samples may include sample query statements and sample instructions, and the training labels may include whether the query corresponding to the training samples is actually an abnormal query and the actual query time spent. Whether the query is an abnormal query may be indicated by 0 or 1, with 0 indicating a normal query and 1 indicating an abnormal query.
[0084] The likelihood of the query statement being an anomalous query may be automatically evaluated with the query prediction model. In some embodiments, if the query statement has a high anomaly likelihood, the resource sub-group with lower resource weights is assigned (at which point no attention is paid to the query prediction time) . If it is a normal query (the anomaly likelihood is lower than a preset threshold) , the resource sub-groups may be allocated based on a preset allocation rule according to the query prediction time, e.g., assigning the resource sub-groups with higher resource weights to queries with longer query prediction time. More descriptions regarding determining the execution sub-groups may be found in the corresponding descriptions of FIG. 5 and 6. The preset threshold may be set by a technician based on experience.
[0085] By specifying the resource sub-group and then executing the query, it may make the database resources consumed by the query process be controlled by the resource sub-group.
[0086] In 230, a resource usage of the database when the query instance is executed may be controlled based on a control strategy of the execution sub-group.
[0087] The control strategy of the execution sub-group is the resource allocation strategy for the execution sub-group. For example, the control strategy of the execution sub-group may be the resource weight corresponding to the execution sub-group. In some embodiments, the control strategy of the execution sub-group may be a predetermined control strategy corresponding to the resource sub-group corresponding to the execution sub-group. More descriptions regarding determining the control strategy may be found in the corresponding description of FIG. 3.
[0088] In some embodiments, the processor may assign use weights of the database resources during the query process based on the control strategy of the execution sub-group when executing the query instance. For example, if the upper limit of processing resources is 1000, and a certain resource sub-group has a weight of 0.3 according to the control strategy of the execution sub-groups, the processor may determine that the resources corresponding to the execution sub-group are 1000*0.3=300, and use the portion of the resources to execute the query instance.
[0089] Exemplarily, a database user U belongs to an unique database resource group S, a resource group ID corresponding to S is SID, and after the resource group corresponding to SID as well as the subordinate lowest, low, middle and high resource sub-groups are configured, queries Q1 and Q2 performed by the user after the user logs in belong to the same unique process P, and the corresponding process number is PID, at this time, SID corresponds to a PID. Before the database executes Q1, it writes the SID corresponding GID into the cgroup. procs file under any one of the lowest, low, middle, and high resource sub-groups under the resource group corresponding to the SID, and then executes the query statement, and the resource group finds the querying process according to the PID, and restricts the resources of its process, that is, restricts the database resources occupied by the query.
[0090] In some embodiments of the present disclosure, by establishing a correspondence between different resources of the system and the resource group, further dividing the resource group into the resource sub-groups based on the granularity to be controlled, and determining the execution sub-groups based on the one or more instructions, and then based on the control strategy of the execution sub-group to control the resource usage of the database when executing the query instance, resource control of a single query service can be realized, and then granularity control at the database session level can be realized to facilitate the control of resource usage of the different query statements.
[0091] FIG. 3 is an exemplary schematic diagram illustrating determination of a control strategy according to some embodiments of the present disclosure.
[0092] In some embodiments, the processor may create a plurality of resource sub-groups 321 with different weight levels 322 under at least one resource group 310, as shown in FIG. 3. More descriptions regarding the resource group and the resource sub-groups may be found in the corresponding description of FIG. 2.
[0093] The weight levels may characterize the size of the proportion of database resources that may be allocated to different resource sub-groups. In some embodiments, the higher the weight level corresponding to the resource sub-group, the larger the proportion of the database resources that may be allocated. In some embodiments, when there is a competition for the database resources for a plurality of query statements, the higher the weight level of the resource sub-group, the easier it is to prioritize the allocation of resources to the resource group for executing the corresponding query statement. Conversely, the lower the weight level, the less likely the resource sub-group is to be assigned a resource of the resource group to execute the corresponding query statement. More descriptions regarding the weight levels and the database resources may be found in the corresponding descriptions in FIG. 2. More descriptions regarding the query statements may be found in the corresponding descriptions in FIG. 4.
[0094] In some embodiments, the processor may create the plurality of resource sub-groups with the different weight levels utilizing an approach similar to creating the plurality of resource sub-groups in FIG. 2. For example, the processor may create four resource sub-groups with the weight levels from lowest, low, middle, and high.
[0095] In some embodiments, the processor may determine the control strategies for the plurality of resource sub-groups based on the weight levels and one or more configuration option parameters corresponding to the plurality of resource sub-groups.
[0096] The configuration option parameters are related parameters used to configure resource allocation for the resource sub-group. In some embodiments, the configuration option parameters may include, for example, a weight ratio for the different resource sub-groups. For example, the configuration option parameters may include a weight ratio of 1: 1: 2: 4, etc., for processing resources of the lowest, low, middle, and high resource sub-groups.
[0097] In some embodiments, the processor may determine the control strategies for the plurality of resource sub-groups in a plurality of ways based on the weight levels corresponding to the plurality of resource sub-groups and the configuration option parameters. For example, the weight ratio of the processing resources of the lowest, low, middle, and high resource sub-groups may be set to be 1: 1: 2: 4 based on the configuration option parameters, and in the event of a processing resource competition, assuming a CPU runtime is 10 seconds, the control strategy for the resource sub-group may be that the time slices allocated to the lowest, low, middle, and high resource sub-groups are 10 / 8 seconds, 10 / 8 seconds, 10 / 4 seconds, and 10 / 2 seconds, respectively.
[0098] In some embodiments of the present disclosure, by creating the plurality of resource sub-groups with the different weight levels under the resource groups, combined with the configuration option parameters to determine the control strategies for the different resource sub-groups, the use of resources can be restricted at a finer granularity, and more reasonable control strategies for the different resource sub-groups are determined to ensure the stable operation of the database.
[0099] In some embodiments, the configuration option parameters 330 may include a first configuration parameter 331. In some embodiments, as shown in FIG. 3, the processor may determine a standard resource sub-group 341 from the plurality of resource sub-groups 321 and obtain the first configuration parameter 331 for other resource sub-groups 342 of the plurality of resource sub-groups 321; based on the weight levels 322 and the first configuration parameter 331 of the other resource sub-groups 342, a weight multiplier 350 of the other resource sub-groups 342 with respect to the standard resource sub-group 341 may be determined; and based on the weight multiplier 350, a control strategy 360 of the resource sub-group may be determined.
[0100] The standard resource sub-group 341 is a resource sub-group that serves as a baseline for setting resource weights. In some embodiments, the processor may use any one of the plurality of resource sub-groups 321, as the standard resource sub-group. For example, the processor may identify the "middle" resource sub-group, as the standard resource sub-group. The other resource sub-groups 342 refer to the resource sub-groups other than the standard resource sub-group of the same resource group.
[0101] The first configuration parameter 331 is a configuration parameter configured for determining resource weight of the other resource sub-groups 342. For example, with the "middle" resource sub-group as the standard resource sub-group, the first configuration parameter may include the following six GUC options: gp_resgroup_cpu_lowest_factor, gp_resgroup_cpu_low_factor, gp_resgroup_cpu_high_factor, gp_resgroup_blkio_lowest_factor, gp_resgroup_blkio_low_factor, gp_resgroup_blkio_high_factor, wherein, the first three are used to determine the resource weights of the corresponding resource sub-groups of a processing resource group, and the last three are used to determine the resource weights of the corresponding resource sub-groups of a blkio resource group.
[0102] The GUC options refer to configuration parameters for the database. At the database startup, the processor may perform database initialization operations by reading the above configuration parameters. In some embodiments, the upper and lower bounds of the floating point values of the GUC options may be [0.01, 100] , and the GUC options may be determined by a user customization. In some embodiments, depending on the actual situation, the processor may adjust the upper and lower limits of the floating-point values of the GUC options, which is not limited to the interval [0.01, 100] .
[0103] The weight multiplier 350 refers to the multiplier of the resource weights of the other resource sub-groups, with respect to the resource weights of the standard resource sub-group. In some embodiments, the processor may determine the weight multiplier for the other resource sub-groups with respect to the standard resource sub-group based on the weight level and the first configuration parameter for the other resource sub-groups.
[0104] For example, taking the CPU sub-system as an example, with the middle resource sub-group as the standard resource sub-group, and three GUC options provided, i.e., the first configuration parameter may include floating point values corresponding to gp_resgroup_cpu_lowest_factor, gp_resgroup_cpu_low_factor, and gp_resgroup_cpu_high_factor, respectively, which is used to specify the weight multiplier of the corresponding resource weight compared to the middle resource sub-group. The processor may determine the control strategies for the plurality of resource sub-groups based on the weight multipliers described above (i.e., set the cpu. shares weights for the four resource sub-groups at the weight levels of lowest, low, middle, and high) . And the cpu. share refers to the weight of the processing resource that may be acquired when a processing resource competition occurs.
[0105] In some embodiments, by default, the weight ratio of the processing resources between lowest, low, middle, and high may be set to 1: 1: 2: 4, i.e., the default values of the three floating point values of gp_resgroup_cpu_lowest_factor, gp_resgroup_cpu_low_factor, gp_resgroup_cpu_high_factor are 0.5, 0.5, and 2, respectively, and the weight multiplier of the specified lowest, low, and the high resource sub-groups compared to the corresponding resources weight of the middle resource sub-group are 0.5, 0.5, and 2, respectively.
[0106] Taking the resource group of the blkio sub-system as an example, with the middle resource sub-group as the standard resource sub-group, and three GUC options are provided, i.e., the first configuration option parameter includes three floating-point values corresponding to the gp_resgroup_blkio_lowest_factor, gp_resgroup_blkio_low_factor, gp_resgroup_blkio_high_factor, respectively, which is used to specify the weight multiplier of the corresponding resource weights compared to the middle resource sub-group, and set the blkio. weight values of the four resource sub-groups lowest, low, middle, high. And the blkio. weight refers to the weight of the read and write resources that may be obtained when there is a read and write resource competition.
[0107] In some embodiments, by default, the ratio of blkio weights between lowest, low, middle, and high is 1: 1: 2: 4, i.e., the default value of the three floating-point values of gp_resgroup_blkio_lowest_factor, gp_resgroup_blkio_low_factor, gp_resgroup_blkio_high_factor are 0.5, 0.5, and 2, respectively, and the weight multiplier of the specified lowest, low, and high resource sub-groups compared to the corresponding resources weight of the middle resource sub-group are 0.5, 0.5, and 2, respectively.
[0108] In some embodiments, the processor may determine the control strategies for the plurality of resource sub-groups based on the weight multiplier in a plurality of ways. For example, assuming that the resource weight for the middle resource sub-group is 4 by default, and that the floating point value of gp_resgroup_cpu_lowest_factor in the first configuration parameter is 0.1 (i.e., the corresponding weight multiplier of the lowest resource sub-group is 0.1) , then the processor may calculate the resource weight of the lowest resource sub-group as 4*0.1=0.4, and the processor may calculate the corresponding resource weights of the other resource sub-groups according to the above method and allocate resources based on the resource weights of all resource sub-groups in the resource group, which is the way of allocating resources (i.e., the control strategy) .
[0109] In some embodiments of the present disclosure, by determining the standard resource sub-group, the weight multiplier of the other resource sub-groups compared to the standard resource sub-groups is determined, based on the weight level and the first configuration parameter, and thus the control strategy can be determined, the weight multiplier relationship between the different resource sub-groups can be set through the first configuration parameter, and a better control strategy can be determined to more rationally allocate the database resources when resource competition occurs.
[0110] In some embodiments of the present disclosure, the weight configuration is determined according to the database configuration GUC option, i.e., after the completion of the database startup, the weight proportions of the lowest, the low, the middle, and the high resource sub-groups corresponding to each resource group are the same, and considering that each resource group corresponds to a different number of query statements executed, when determining the weights for the resource sub-groups of each resource group, different weight ratios for the resource sub-groups can be set according to different resource groups. For example, a monitoring module may be added to monitor the execution of each resource group in stages, count the number of executed queries and the execution time, and so on, and determine the weight ratio of the resource sub-groups corresponding to the resource group in the next moment (e.g., the higher the number of executed queries and the closer the execution time is to the current time, the higher the weight ratio of the corresponding resource sub-group is adjusted) .
[0111] In some embodiments, the configuration option parameters 330 may include a second configuration parameter 332.
[0112] In some embodiments, the processor may determine a target resource sub-group 370 with a lowest weight level based on the weight levels 322; determine, based on the second configuration parameter 332, a resource limit value 380 for the target resource sub-group; and, set, based on the resource limit value 380, an upper limit 390 of a resource hard limit for the target resource sub-group.
[0113] The second configuration parameter 332 is a configuration parameter for determining the database resources and the resource hard limit of read and write resource. For example, the second configuration parameter may include the following three GUC options: cpu. cfs_quota_us, blkio. throttle. read_iops_device, and blkio. throttle. write_iops_device, which correspond to the resource limit values of the different resource groups, such as the CPU resource group and the I / O resource group, respectively. The second configuration parameter may be applied to the target resource sub-group that has the lowest weight level among the resource sub-groups. More descriptions regarding the GUC option may be found in the corresponding description above. More descriptions regarding the target resource sub-groups and the resource limit values may be found in the description below.
[0114] The target resource sub-group 370 refers to the resource sub-group with the lowest weight level among the resource sub-groups of the same resource group. For example, for the four resource sub-groups of the resource group with the weight levels lowest, low, middle, and high, the processor may take the resource sub-group with the lowest weight level as the target resource sub-group. That is, the lowest resource sub-group is determined as the target resource sub-group.
[0115] The resource limit value 380 is a limit value used to restrict the use of resources in the target resource sub-group. In some embodiments, the processor may determine the resource limit value for the target resource sub-group in a plurality of ways based on the second configuration parameter. For example, the processor may obtain, based on the second configuration parameter, the resource limit value that corresponds to the target resource sub-group.
[0116] The resource hard limit refers to a limit that restricts the absolute use of a resource, regardless of whether the resource competition occurs. The upper limit 390 of the resource hard limit refers to the upper limit of absolute use of the resource. As opposed to the resource hard limit, a resource soft limit refers to a limit that restricts the use of the resource only if the resource competition occurs.
[0117] Exemplarily, assuming that there are 100 processing resources and 50 queries need to be performed, with each query consuming one processing resource, if the restriction on processing resources is the resource soft limit, and at this moment there are more processing resources than queries and no resource competition, therefore the use of processing resources is not limited. If the restriction on processing resources is the resource hard limit, for example, the restriction is that only 30 processing resources may be used, then only 30 processing resources may be used for 50 queries, and even if there are free resources, they cannot be used. Since cpu. shares and blkio. weight above are weight values, they may be categorized as the resource soft limit.
[0118] In some embodiments, the processor may configure the resource limit value to be the upper limit of the resource hard limit for the target resource sub-group based on the resource limit value.
[0119] In some embodiments of the present disclosure, through determining the resource limit value based on the second configuration parameter, and thus configuring the upper limit of the resource hard limit for the target resource sub-group with the lowest weight level, some potentially invalid queries that consume a large amount of resources can be set to the target resource sub-group, making it possible to avoid a situation that a large amount of the database resources is occupied even under conditions where there is no resource competition.
[0120] For example, setting the gp_resgroup_cpu_lowest_quota of the lowest resource sub-group to 1000, which means that the CPU usage can only be 10%at most even if there is no resource competition, for an abnormal query, if the resource sub-group corresponding to the query is set to be the lowest resource sub-group, the abnormal query uses at most 10%of the CPU resources, preserving the margin of the database resources for normal queries.
[0121] In some embodiments, the resource group includes the CPU resource group and the I / O resource group. More descriptions about the CPU resource group and the I / O resource group may be found in the related description of operation 210 of FIG. 2 .
[0122] In some embodiments, under the CPU resource group, the resource hard limit is a resource usage limit; under the I / O resource group, the resource hard limit includes a resource read limit and a resource write limit.
[0123] The resource usage limit is a restriction used to limit the absolute use of CPU resources. For example, in the cpu sub-system, cpu. cfs_quota_us is provided to limit the absolute CPU resource usage limit. Exemplarily, specify cpu. cfs_quota_us for the lowest group via the GUC option gp_resgroup_cpu_lowest_quota. The default value of 100000 indicates 100%CPU resource usage for up to a single core.
[0124] The resource read limit is a restriction used to limit the reading of the upper limit of IOPS. For example, in the blkio sub-system, blkio. throttle. read_iops_device is provided to limit the upper limit of IOPS read by the device. IOPS (Input / Output Operations Per Second, reads and writes per second) is the maximum frequency of I / O (i.e., read and write times) that the system may handle per unit of time, and is one of the main indicators of disk performance. Exemplarily, blkio. throttle. read_iops_device for the lowest resource sub-group is set through the GUC option gp_resgroup_blkio_lowest_riops, with a default value of 500 indicating up to 500 reads per second.
[0125] The resource write limit is a restriction used to limit the upper limit of IOPS for writes. For example, in the blkio sub-system, blkio. throttle. write_iops_device is provided to limit the upper IOPS limit for device writes.
[0126] Exemplarily, blkio. throttle. write_iops_device for the lowest group is set through the GUC option gp_resgroup_blkio_lowest_wiops, with a default value of 200, indicating a maximum of 200 writes per second.
[0127] In some embodiments of the present disclosure, by setting the resource usage limit under the CPU resource group, and setting the resource read limit and the resource write limit under the I / O resource group, a reasonable resource hard limit can be set for the different resource groups respectively, avoiding the abnormal queries from occupying a large amount of the database resources, improving query efficiency and stability.
[0128] In some embodiments of the present disclosure, introducing the resource hard limit for the non-minimum resource sub-group of the resource sub-groups ensures that the use of the database resources for a normal query is maintained within a reasonable threshold, avoiding the occupation of a large amount of the database resources and improving the stability.
[0129] In some embodiments, the processor may remove the resource hard limit for the target resource sub-group when the second configuration parameter is a preset value. The preset value refers to the value of the GUC option in a preset second configuration parameter. For example, the preset value is 0 or -1, etc. For example, when gp_resgroup_cpu_lowest_quota is 0 or -1, the resource usage limit for CPU resource usage is turned off. When gp_resgroup_blkio_lowest_riops is 0 or -1, the resource read limit for read IOPS is turned off. When gp_resgroup_blkio_lowest_wiops is 0 or -1, the resource write limit for write IOPS is turned off.
[0130] In some embodiments of the present disclosure, by canceling the resource hard limit of the target resource sub-group when the second configuration parameter is the preset value, the second configuration parameter can be flexibly set according to the actual situation to control whether to use the resource hard limit to impose restrictions on the use of the processing resources and the resources for reading and writing.
[0131] In some embodiments, the processor may determine the database resources for the resource sub-group based on the control strategy and a database resource limit. For example, if the database resource limit is 1,000, and based on the control strategy, the resource sub-group has a weight of 0.3, the processor may determine that the database resources corresponding to the resource sub-group is 1,000*0.3=300.
[0132] The database resource limit refers to an upper limit of the database resources that may be used. In some embodiments, the database resource limit may include a processing resource limit, a read and write resource limit, etc. More descriptions regarding the control strategy, the resource sub-groups, and the database resources may be found in the corresponding descriptions in FIG. 2.
[0133] In some embodiments of the present disclosure, by determining the database resources of the resource sub-group based on the control strategy and the database resource limit, the database resources can be more reasonably allocated, and the use of the database resources can be better controlled.
[0134] FIG. 4 is an exemplary schematic diagram illustrating a database query method according to some embodiments of the present disclosure.
[0135] In some embodiments, the processor may determine an execution sub-group 440 in a query instance, based on one or more instructions 430, and at least one of user information 410 or a query statement 420. More descriptions regarding the execution sub-group, the query instance may be found in the corresponding descriptions of FIG. 2.
[0136] The user information 410 refers to user-related information used to log into a database. For example, the user information may include the user's account number, password, or the like.
[0137] The query statement 420 refers to a statement used to extract relevant data from the database. For example, the query statement may be an SQL (Structured Query Language) statement based on a SELECT statement. SQL is a database language with a plurality of functions such as data manipulation and data definition.
[0138] In some embodiments, the processor may determine the execution sub-group in the query instance, based on the one or more instructions, and at least one of the user information or the query statement in a variety of ways. For example, each user belongs to one resource group corresponding to each of them, and in the query instance, the processor may determine the resource group in which the user is located, based on the user information, and the execution sub-group based on the one or more instructions (GUC option gp_resgroup_default_level) .
[0139] As another example, the processor may prejudge the query statement before the query instance executes the query statement. For the pre-determination result that the query needs to occupy more database resources, the processor may determine the execution sub-group to be the resource sub-group with a high weight level based on the one or more instructions (GUC option gp_resgroup_default_level) , and on the contrary, determine the execution sub-group to be the resource sub-group with a low weight level. In some embodiments, the processor may prejudge the query statement based on predetermined rules. Exemplarily, the predetermined rules may be that prejudging, based on the number of indexes in the query statement, how much database resources need to be occupied during the query, such as, the more the number of indexes, the less the database resources are occupied (indexes may narrow the query scope) . The result of the prejudge may include the occupied database resources are less, moderate, more, etc. More descriptions about the prejudge method in the present disclosure is not limited.
[0140] As another example, the processor may determine the resource group to which the user belongs based on the user information. The processor may determine that the execution sub-group is a particular resource sub-group under the resource group to which it belongs based on the one or more instructions and the prejudge of the query statement.
[0141] In some embodiments, the processor may further identify a default execution sub-group as the execution sub-group in response to a resource load that is less than or equal to a predetermined detection threshold, as described in relation to FIG. 5.
[0142] In some embodiments, the processor may execute the query statement 420 based on the execution sub-group 440, and return a query result 450. For example, the processor may, based on the execution sub-group, invoke the processing resources corresponding to the execution sub-group, execute the query statement and return the query result. Among them, each query statement corresponds to a query process and a process number.
[0143] The query result refers to the result returned by a query corresponding to the query statement in the database. For example, the query result may be a value in a list in the database corresponding to the query statement.
[0144] In some embodiments, the processor may determine, based on a session query level, a target execution sub-group in the query instance corresponding to the user information.
[0145] The session query level refers to the weight level of resource usage set against the query statement.
[0146] The target execution sub-group refers to the resource sub-group to be allocated for a current query statement.
[0147] In some embodiments, the processor may determine, based on the session query level, the target execution sub-group in the query instance corresponding to the user information in a plurality of ways. For example, the user may preset a value for the GUC option gp_resgroup_default_level, and the processor may obtain the value for the GUC option gp_resgroup_default_level preset by the user, set the session query level, control the resource sub-group to which the current query statement should specifically belong, and use the resource sub-group as the target execution sub-group. If not set by the user, the processor may determine middle as the session query level for the current query statement by default and identify the corresponding middle resource sub-group as the target execution sub-group in the query instance corresponding to the user information.
[0148] In some embodiments, the user may change the session query level at any time by setting the GUC option gp_resgroup_default_level. For example, after a database connection has been established, i.e., after opening the query instance, and prior to executing the query, the user may change the value of gp_resgroup_default_level, and, after the change, the value of the gp_resgroup_default_level may affect the resource group in which all queries after the query instance reside. Setting the session query level may affect both a CPU sub-system and a blkio sub-system.
[0149] In some embodiments, the processor may execute, based on the target execution sub-group, the query statement and return the query result. More descriptions may be found in the related descriptions of FIG. 12.
[0150] In some embodiments of the present disclosure, by determining, based on the session query level, the target execution sub-group in the query instance corresponding to the user information, the resource sub-group corresponding to the query statement can be specified before each query by the GUC option gp_resgroup_default_level, so that the query process corresponding to the query statement is no longer attributed to the resource group itself, but must be attributed to one of the four resource sub-groups of lowest, low, middle, and high under the resource group, realizing statement level resource control.
[0151] In some embodiments of the present disclosure, by determining the execution sub-group in the query instance, based on the one or more instructions, and at least one of the user information or the query statement, and executing the query statement based on the execution sub-group and returning the query result, it is possible to more conveniently control different query statements of CPU resources and I / O resources of the resource sub-groups.
[0152] FIG. 5 is an exemplary flowchart illustrating determination of an execution sub-group according to some embodiments of the present disclosure. As shown in FIG. 5, process 500 is one embodiment of determining the execution sub-group 440, and may include one or more of the following operations. In some embodiments, the process 500 may be executed by a processor.
[0153] In 510, whether a resource load is less than or equal to a predetermined detection threshold may be determined.
[0154] The resource load refers to a situation related to the various resources required by a query process that is in progress at the current time. In some embodiments, the resource load may include a current CPU occupancy, current input / output resources, and the like. In some embodiments, the processor may obtain the resource load via a monitoring module. More descriptions regarding the monitoring module may be found in the corresponding descriptions of FIG. 3.
[0155] The current CPU occupancy refers to the percentage of total processing resources used by a current query process. The current input / output resources refers to the read and write rate corresponding to current read and write resources. More descriptions regarding the CPU resources and the I / O resources may be found in the corresponding descriptions of FIGs. 1-2.
[0156] The predetermined detection threshold refers to a threshold associated with the resource load. In some embodiments, the predetermined detection thresholds may include a CPU occupancy threshold and an I / O rate threshold. In some embodiments, the predetermined detection thresholds may be set by a technician based on actual needs or historical experience.
[0157] In some embodiments, the processor may determine whether the resource load is less than or equal to the predetermined detection threshold. In some embodiments, the resource load being less than or equal to the predetermined detection threshold may mean that both the current CPU occupancy and the current input / output resources are less than or equal to their respective corresponding predetermined detection thresholds, or it may be that one of the current CPU occupancy and the current input / output resources is less than or equal to the respective corresponding predetermined detection thresholds.
[0158] In some embodiments, the processor may determine the predetermined detection threshold every other predetermined cycle, based on a count of the at least one resource group and historical query data in a previous predetermined cycle.
[0159] The predetermined cycle refers to the period for determining the predetermined detection threshold. The predetermined cycle may be preset by a technician based on experience.
[0160] The count of the at least one resource group refers to the total number of the resource groups for the database. In some embodiments, the processor may count the number of the at least one resource group while creating the resource groups.
[0161] The historical query data is data related to historical queries. For example, the historical query data may include a historical query size, a historical query frequency, or the like. In some embodiments, the processor may obtain the historical query data from a storage device.
[0162] The historical query size is data reflecting the size of the historical query data volume over a period of time. In some embodiments, the historical query size within the previous predetermined cycle may be represented by the total amount of data volume queried by the query statement within the previous predetermined cycle of the current predetermined cycle. Among them, the query data volume may be the total data size involved in the query statement. In the case of a relational database, for example, the query data volume may be the sum of the data volumes of a plurality of data tables in the database involved in the query statement.
[0163] The historical query frequency is data reflecting the frequency of historical queries over a period of time. In some embodiments, the historical query frequency in the previous predetermined cycle may be represented by a ratio of the count of the query statements in the previous predetermined cycle to the duration of the previous predetermined cycle.
[0164] In some embodiments, the processor may determine the predetermined detection threshold in a plurality of ways based on the count of the at least one resource group and the historical query data in the previous predetermined cycle. For example, the processor may construct a feature vector based on the count of the at least one resource group and the historical query data in the previous predetermined cycle, and by matching in a vector database, determine a reference vector with the highest similarity as a target vector, and determine a detection threshold label corresponding to the target vector as the predetermined detection threshold.
[0165] Among them, the feature vector is a vector including a number of the resource groups to be matched and the historical query data. The vector database includes the reference vector and its corresponding detection threshold label. The reference vector includes the count of actual resource groups in historical data and the historical query data of a first historical cycle. The detection threshold label corresponding to the reference vector may be the predetermined detection threshold with the highest query efficiency in a second historical cycle corresponding to the reference vector in the historical data. The similarity may be calculated based on cosine distance, Euclidean distance, or the like. The highest query efficiency may mean that the variance of the query time of the plurality of query instances is minimized, or the total query time corresponding to the plurality of query instances (i.e., the sum of the query time consumed by the plurality of query instances) is minimized. The first history cycle, the second history cycle are predetermined cycles of the history, and the second history cycle is a future time period of the first history cycle.
[0166] In some embodiments of the present disclosure, by re-determining the predetermined detection threshold based on the historical query data every other predetermined cycle, the predetermined detection threshold can be adjusted in a timely manner based on the actual query situation of the previous predetermined cycle, so that the predetermined detection threshold can be set more reasonably, which in turn makes the determination of the execution sub-group more consistent with the actual situation and improves the query efficiency.
[0167] In 520, in response to the resource load being less than or equal to the predetermined detection threshold, a default execution sub-group may be designated as the execution sub-group.
[0168] The default execution sub-group refers to the execution sub-group determined by default. In some embodiments, the default execution sub-group may be set to a standard resource sub-group. More descriptions regarding the standard resource sub-group may be found in the related descriptions of FIG. 3.
[0169] In some embodiments, the processor may re-determine the default execution sub-group every other predetermined cycle, based on a gap between a historical resource load corresponding to the user and the predetermined detection threshold and a predetermined gap threshold.
[0170] In some embodiments, the gap between the historical resource load and the predetermined detection threshold may be the result of a weighted summation of the gap between the current CPU occupancy and a preset CPU occupancy, and the gap between the current I / O resources and preset I / O resources. The weight coefficient may be set according to the demand, exemplarily, since in the query process, the demand for CPU computing resources is usually smaller than the demand for I / O resources, the weight coefficient of the gap corresponding to I / O resources may be greater than the weight coefficient of the gap corresponding to the CPU occupancy.
[0171] The historical resource load refers to the resource load from the last predetermined cycle. The historical resource load is obtained in a manner similar to the manner in which the resource load is obtained, as may be found in the related descriptions in operation 510.
[0172] The predetermined gap threshold refers to a threshold related to the gap between the resource load and the predetermined detection threshold. The predetermined gap threshold may be preset by a technician based on actual requirements or historical experience.
[0173] In some embodiments, the processor may re-determine the default execution sub-group in a variety of ways, based on the gap between the historical resource load corresponding to the user and the predetermined detection threshold and the predetermined gap threshold. For example, if the absolute value of the gap between the historical resource load corresponding to the user and the predetermined detection threshold is greater than the predetermined gap threshold, the processor may adjust the default execution sub-group downward or upward accordingly, depending on the sign of the gap (positive, negative) between the historical resource load and the predetermined detection threshold.
[0174] Exemplarily, the current default execution sub-group is preset to be the middle resource sub-group, and when the absolute value of the gap between the historical resource load and the predetermined detection threshold is greater than the predetermined gap threshold: if the gap is a negative gap (i.e., the historical resource load is less than the predetermined detection threshold) , then the default execution sub-group is adjusted upward by one level, at which point the redetermined default execution sub-group is the high resource sub-group; if the gap is a positive gap (i.e., the historical resource load is greater than the predetermined detection threshold) , then the default execution sub-group is adjusted downward by one level, and the default execution sub-group is redetermined to be the low resource sub-group.
[0175] In some embodiments of the present disclosure, if the gap between the historical resource load corresponding to the user and the predetermined detection threshold is a negative gap, then it indicates that an average resource load in the last predetermined cycle was low, and the level of the default execution sub-group can be appropriately increased to ensure that the query statements can be executed in a more timely manner when the resource load is low. If the gap between the historical resource load corresponding to the user and the predetermined detection threshold is a positive gap, then it indicates that the average resource load in the previous predetermined cycle was high, and the level of the default execution sub-group can be appropriately lowered, so that when the query instance is set to the default execution sub-group, it will not generate a large amount of I / O load or consume too much CPU, thus ensuring the query efficiency of the subsequent query instances.
[0176] In some embodiments of the present disclosure, when the resource load is less than or equal to the predetermined detection threshold, by determining the default execution sub-group as the execution sub-group, the execution sub-group can be quickly determined when the resource load is more generous, which can improve the efficiency of the query, and keep the database in normal operation.
[0177] In 530, in response to the resource load being greater than the predetermined detection threshold, a resource group to which the user belongs may be determined based on the user information; and, the execution sub-group may be determined using a query scheduling model, based on query parameter of the query statement. More descriptions regarding the user information and the query statement may be found in the corresponding descriptions of FIG. 4.
[0178] In some embodiments, the processor may determine the resource group corresponding to the user as the resource group to which the user belongs based on the user information. More descriptions may be found in the relevant descriptions of FIGs. 2 and 4.
[0179] The query parameters refer to the relevant parameters involved when the user makes a query. For example, the query parameters may include at least one of a query data volume, a query condition, a data type involved in the query statement, a query priority, or the like. More descriptions regarding the query data volume may be found in the related description above. In some embodiments, the processor may obtain, based on the query statement, the corresponding query data volume, query conditions, data types involved in the query statement, or the like, by extracting keywords, or the like. More descriptions regarding the query priority may be found in the related descriptions below.
[0180] The query condition refers to a condition under which a query operation is performed in the database. For example, the query condition may include multi-table join, sub-queries, aggregate functions, and so on.
[0181] The data types involved in the query statement may include basic data types and complex data types, etc. The basic data types may include numbers, strings, dates, and so on. The complex data types may include large object data types (e.g., an image, a video, etc. ) , indexed data types (i.e., the query statement that include indexes) , composite data types (e.g., an array, a structure, a list, etc. ) , and so on.
[0182] In some embodiments, the processor may determine the query priority based on the data type involved in the query statement. The query priority is data reflecting a degree of precedence for the data type involved in the query statement. For example, the processor may determine the query priority by looking up a first predetermined table based on the data type involved in the query statement.
[0183] The first predetermined table may include a correspondence between the data type involved in the query statement and the query priority, and may be predetermined by a technician based on a prior knowledge and historical experience.
[0184] Exemplarily, the correspondence in the first predetermined table may include: if the data type is a data type containing only the basic data, the corresponding query priority is level one; if the data type is a data type containing only the basic data, and the composite data, the corresponding query priority is level two; if the data type is a data type containing the large object data, the corresponding query priority is level three; if the data type is a data type containing the index data, the corresponding query priority is at least one of level four, or the like. In some embodiments, the first predetermined table may also include any other data type corresponding to the query priority.
[0185] Different data types may have different levels of impact on I / O resource requirements when they are stored and / or accessed. For example, the complex data types may involve frequent read and write operations to the storage device, increasing the I / O load, so it is necessary to determine the query priority containing the complex data types as a lower level to avoid a large I / O load.
[0186] The query scheduling model is a model for determining the execution sub-group. In some embodiments, the query scheduling model may be a machine learning model. For example, the query scheduling model may be one of Neural Networks (NN) , Deep Neural Networks (DNN) , etc., or any combination. In some embodiments, an input of the query scheduling model may include the query data volume, the query conditions, and the query priority, and an output may be the execution sub-group.
[0187] In some embodiments, the query scheduling model may be acquired by training based on a large number of first training samples with first labels. The first training samples may include sample query parameters for sample query statements in historical data. Each set of the sample query parameters may include a sample query data volume, a sample query condition, a data type involved in the sample query statement, and a sample query priority. The first labels of the first training samples may be a preferred execution sub-group corresponding to the sample query parameters. The preferred execution sub-group may be the execution sub-group that has the smallest total query time corresponding to a plurality of the query instances in a future period of time corresponding to the sample query parameters in the historical data, and may be automatically labeled by the processor.
[0188] In some embodiments, the processor may input a large number of the first training samples into an initial query scheduling model, construct a loss function based on the output of the initial query scheduling model and the first labels, and iteratively update the initial query scheduling model based on the loss function; when the value of the loss function satisfies an iteration completion condition, the training is completed and a trained query scheduling model is obtained. The iteration completion condition may include the loss function converging, the number of iterations reaching a threshold, or the like.
[0189] In some embodiments of the present disclosure, when the resource load is greater than the predetermined detection threshold, by determining the execution sub-group based on the query parameters of the query statement and utilizing the query scheduling model, it is possible to determine, based on the query parameters, a more realistic and reasonable execution sub-group, which can effectively improve query efficiency.
[0190] In some embodiments, the input of the query scheduling model may also include an average query volume. In some embodiments, the processor may determine the average query volume based on the historical query data corresponding to the user and current data size corresponding to the historical query data. More descriptions regarding the historical query data may be found in the corresponding descriptions above, and it should be noted that the historical query data here is not limited to the data in the last predetermined cycle, but may be data in any historical period. The average query volume is data that reflects the average query size of a user.
[0191] The current data size corresponding to the historical query data refers to the current data volume of the data type involved in the historical query data corresponding to the user. Taking a relational database as an example, the current data size corresponding to the historical query data may be the sum of the data volume of a plurality of data tables in the database involved in the query statement in the historical query data at the current time.
[0192] In some embodiments, the processor may determine the average query volume based on the historical query data corresponding to the user and the current data size corresponding to the historical query data in a plurality of ways. For example, the processor may take the average of the historical query size in the historical query data corresponding to the user and the corresponding current data size, as the average query volume. More descriptions regarding the historical query size may be found in the related descriptions of the historical query data above.
[0193] In some embodiments, if the input of the query scheduling model includes the average query volume, the processor may add, based on the historical data, a sample average query volume corresponding to the sample query parameter to the first training sample, and obtain the trained query scheduling model by training the query scheduling model in a similar way to the above.
[0194] In some embodiments of the present disclosure, by including the average query volume in the inputs of the query scheduling model, the querying habits of the user can be taken into account to determine a reasonable execution sub-group. In most cases, the data queried by the same user is more centralized, for example, the same user usually queries a specific number of tables, and the query data volume directly affects the query execution time, the resource consumption, and the system performance. When determining the execution sub-groups, the accuracy of the query scheduling model can be improved by taking into account the historical query data corresponding to the user and the corresponding current data size.
[0195] In some embodiments, the input of the query scheduling model may also include the resource load. More descriptions regarding the resource load may be found in the corresponding description of the operation 510.
[0196] In some embodiments, if the input of the query scheduling model includes the resource load, the processor may add, based on the historical data, sample resource loads corresponding to the sample query parameters to the first training sample, and train the query scheduling model by training in a manner similar to the described above to obtain the trained query scheduling model.
[0197] In some embodiments of the present disclosure, the resource load may reflect the current remaining resources of the database and thus the size and efficiency of the queries that the database is currently able to process, and by considering adding the resource load to the input of the query scheduling model, it may improve the reasonableness of the execution sub-groups of the output of the query scheduling model.
[0198] It should be noted that the foregoing descriptions of the process 200 and / or the process 500, are for the purpose of exemplification and illustration only, and do not limit the scope of application of the present disclosure. For a person skilled in the art, various corrections and changes may be made to the process 200 and / or the process 500 under the guidance of this specification. However, these corrections and changes remain within the scope of this specification.
[0199] FIG. 6 is another exemplary schematic diagram illustrating determination of an execution sub-group according to some embodiments of the present disclosure.
[0200] FIG. 6 is another embodiment that determines the execution sub-group 440. In some embodiments, as shown in FIG. 6, every other predetermined cycle, the processor may perform: determining a query statement type 620 based on query parameters 610 of a query statement; and determining a correspondence 660 between the query statement type 620 and the execution sub-group in a next predetermined cycle, based on the query statement type 620, the user information 410, an average query volume 630, and a resource load 640, using a query segmentation model 650. More descriptions regarding the predetermined cycle, the query parameters, the resource load, and the average query volume may be found in the corresponding descriptions of FIG. 5. More descriptions regarding the user information and the query statements may be found in the corresponding descriptions of FIG. 4. More descriptions regarding the execution sub-group may be found in FIG. 2.
[0201] The query statement type 620 refers to the categorization result obtained by categorizing the query statement. For example, the query statement type may contain a plurality of different gradients obtained by categorizing the query statement. In some embodiments, the higher the gradient corresponding to the query statement type, the more prioritized the processor's allocation of resources to the query statement may be. In some embodiments, the gradient corresponding to the query statement type may be represented by an integer from 1 to n. For example, gradient 1 may be the highest gradient, etc.
[0202] In some embodiments, the processor may determine the query statement type based on the query parameter of the query statement by one or more predetermined rules. For example, the processor may utilize the determination of a query priority described in operation 530 of FIG. 5 to correspond the level of the query priority to a corresponding gradient (e.g., level one corresponds to gradient 1, level two corresponds to gradient 2, level three corresponds to gradient 3, and level four corresponds to gradient 4) .
[0203] As another example, the processor may determine a query complexity of the query statement based on a query condition and a query type of the query statement, and determine the query statement type based on the query complexity of the query statement. The query type may include at least one of reading data or writing data, or the like. The I / O resource load for the writing data is generally higher than that for the reading data because a read is typically performed prior to writing to obtain the location of the writing data. More descriptions regarding the query condition may be found in the descriptions of FIG. 5. In some embodiments, the processor may determine the query type by a keyword in the query statement. For example, if the query statement contains "insert " , "write" , or other keywords, the processor may determine that the query type is writing data, and determine the query type of other query statements is the reading data, and so on.
[0204] The query complexity is data that reflects the complexity of a query.
[0205] In some embodiments, the processor may set different weight coefficients for different query types and query conditions in advance, and determine the sum of the weight coefficients of the query types and the weight coefficients of the query conditions corresponding to the query statement, as the query complexity of the query statement.
[0206] Exemplarily, the processor may assign a weight coefficient 0 to the query type reading data, a weight coefficient a to the query type writing data, a weight coefficient b to the query condition multi-table join, a weight coefficient c to the query condition sub-query, a weight coefficient d to the query condition aggregate function, etc. An initial value of the sum of the weight coefficients may be 0. Whether the query type of the current query statement includes writing data may be judged. If yes, the weight coefficient a may be counted in the sum of weight coefficients. Whether the current query condition includes at least one of the multi-table join, the sub-query, the aggregate function, etc., may be judged. If yes, the processor may count the corresponding weight coefficient in the sum of weight coefficients.
[0207] In some embodiments, the processor may determine the query statement type based on the query complexity of the query statement by looking up a second predetermined table.
[0208] The second predetermined table is a table containing a correspondence between the query complexity and the query statement type. Exemplarily, the correspondence in the second predetermined table may include: a query complexity 0 to x_1 corresponds to the gradient 1 of the query statement type; a query complexity x_1 to x_2 corresponds to the gradient 2 of the query statement type; ......; and a query complexity x_n-1~x_n corresponds to gradient n of the query statement type. And wherein, 0~x_1, x_1~x_2 , ......, x_n-1~x_n may be of the same length, which is the result of dividing the range of values of the query complexity by n, and the value of the right endpoint belongs to the next gradient. For example, following the above example, the corresponding query statement type when the query complexity is x_1 may be the gradient 2. The value of n is greater than or equal to the number of the resource sub-groups, which may be set as required.
[0209] In some embodiments, the query statement type may further include the correspondence in the second predetermined table (e.g., it may be represented as a vector set (0~x_1, gradient 1) , (x_1~x_2, gradient 2) , ......, (x_2~x_n, gradient n) ) . More descriptions regarding the second predetermined table may be found in the descriptions above.
[0210] The query segmentation model 650 is a model for determining the correspondence between the query statement type and the execution sub-group. In some embodiments, the query segmentation model may be a machine learning model. The query segmentation model may be one of a neural network model, a deep neural network model, or the like, or any combination thereof. In some embodiments, an input of the query segmentation model may include the query statement type, the user information, the average query volume corresponding to the user, and the resource load, etc., and an output may be the correspondence between the query statement type and the execution sub-group.
[0211] In some embodiments, as the input of the query segmentation model, the query statement type may be a vector including all gradients, e.g., (gradient 1, gradient 2, ......, gradient n) , or it may be a vector group including the correspondence in the second predetermined table, and the form of the vector group may be referred to in the relevant formulation above.
[0212] The correspondence 660 between the query statement type and the execution sub-group refers to the correspondence between the query statement type and the execution sub-group that should be assigned. The correspondence between the query statement type and the execution sub-group may be represented as a preset table or a vector group, and the like. Exemplarily, the correspondence between the query statement type and the execution sub-group may be represented as a vector group: (gradient 1, the execution sub-group corresponding to gradient 1) , (gradient 2, the execution sub-group corresponding to gradient 2) , ......, (gradient n, the execution sub-group corresponding to gradient n) , and so on.
[0213] In some embodiments, the query segmentation model may be acquired by training based on a large number of second training samples with the second label. The second training samples may include a sample query statement type in the historical data, sample user information, and a sample average query volume corresponding to the user, and a sample resource load, and the second label may be constructed based on the correspondence between the query statement type with the highest query efficiency and the execution sub-group in the next predetermined cycle of the second training sample. The second label may be automatically labeled by the processor based on historical data. More descriptions regarding the highest query efficiency may be found in the corresponding descriptions of operation 530 in FIG. 5. The query segmentation model may be trained in a way similar to that of the query scheduling model, as described in operation 530 of FIG. 5.
[0214] In some embodiments of the present disclosure, the query segmentation model can be determined with higher accuracy by using a large number of second training samples with the second labels to train and obtain the query segmentation model, and the query statement type can be updated every other preset interval; the correspondence between the query statement type and the execution sub-group can be determined by the query segmentation model, and can be directly used for scheduling the execution sub-group, thereby reducing the number of times the query scheduling model is used, avoiding the waste of computing resources and saving the time cost of query statement scheduling.
[0215] In some embodiments, the processor may adjust the next predetermined cycle based on a historical query frequency of a previous predetermined cycle. For example, the greater the historical query frequency of the previous predetermined cycle, the smaller the processor may set the next predetermined cycle. The greater the historical query frequency of the previous predetermined cycle, the greater the magnitude of changes for the data in the database may be (data size, data type, etc. ) , and the next predetermined cycle may be shortened appropriately.
[0216] The above process of adjusting the predetermined cycle may occur before or after determining the correspondence between the query statement type and the execution sub-group. More descriptions regarding the predetermined cycle and the historical query frequency may be found in the corresponding description in operation 520 of FIG. 5.
[0217] In some embodiments of the present disclosure, by adjusting the length of the next predetermined cycle based on the historical query frequency of the previous predetermined cycle, the correspondence between the query statement type and the execution sub-group can be updated in a timely manner when the data is changed, and the accuracy of the query statement scheduling can be improved.
[0218] FIG. 7 is a flowchart of an embodiment illustrating a query instance creation method according to some embodiments of the present disclosure. As shown in FIG. 7, one or more of the following operations may be performed.
[0219] Operation S11: a resource root group may be created for a database under an operating system based on the system function.
[0220] In some embodiments, a database processing device may create the resource root group (i.e., gpdb / cgroup group) under a CPU sub-system.
[0221] Operation S12: at least one resource group may be created under the resource root group.
[0222] In some embodiments, the database processing device may make each of the at least one created resource root group (via SQL create resource group ... (cpu_RATE_LIMIT=integer, BLKIO_RATE_LIMIT=integer... ) syntax) have an associated group oid that may be located under gpdb / as a sub-cgroup (i.e., the resource group) .
[0223] Operation S13: a plurality of resource sub-groups may be created under the at least one resource group to form a query instance of the database.
[0224] In some embodiments, the database processing device may automatically creates four groups, i.e., the resource sub-groups under the resource group cgroup, including: lowest, low, middle, and high. The four resource sub-groups above have relative weights. It should be noted that in other embodiments, the count of the resource sub-groups may be any other number, and the weight levels may be set to other levels (e.g., a resource group may include 3 resource sub-groups with weight levels of lowest, low, middle, etc. ) .
[0225] Under cpu hierarchy, cpu. shares weights are controlled proportionally between the lowest, low, middle, and high resource sub-groups. There may be 3 GUC options provided based on the middle level, i.e., a first configuration parameter: gp_resgroup_cpu_lowest_factor, gp_resgroup_cpu_lowest_factor, gp_resgroup_cpu_high_factor may be set, and they are floating point values specifying a weight multiplier compared to the middle level, with upper and lower limits denoted by [0.01, 100] . By default, some embodiments of the present disclosure have a CPU weight ratio of 1: 1: 2: 4 between lowest, low, middle, and high. In other embodiments, other weight ratios may be set, and are not specifically limited herein. CPU resources allocated under the resource group cgroup may be allocated to the various resource sub-groups according to the above weight ratios.
[0226] For the above resource sub-groups, the lowest group is special in that it additionally provides resource hard limit support. More descriptions regarding the resource hard limit may be found in the related descriptions of FIG. 3. In some embodiments, the historical query size within the previous predetermined cycle may be represented by the total amount of data query amount by the query statement within the previous predetermined cycle of the current predetermined cycle. In the following GUC option, a second configuration parameter is added for lowest.
[0227] Please refer back to FIG. 1, if these queries contain one or more single full table scan queries, this type of query will consume quite a lot of read and write resources, but the processing resource use instead is not much, which is not limited by the GP default resource group feature. Some embodiments of the present disclosure may therefore also create several sub-systems at the same time as the query instance is created, such as a CPU sub-system and a blkio sub-system.
[0228] FIG. 8 is a schematic diagram of an embodiment illustrating a resource group implementation according to some embodiments of the present disclosure.
[0229] A query instance creation method of the present application is applied to a database processing device, wherein the database processing device of the present application may be a server, a terminal device, and a system including a server and a terminal device cooperating with each other. Correspondingly, the various portions included in the database processing device, such as the various units, sub-units, modules, and sub-modules, may be all disposed in the server, or may be all disposed in the terminal device, or may be separately disposed in the server and in the terminal device.
[0230] Further, the above server may be hardware or software. If the server is hardware, it may be implemented as a distributed server cluster of a plurality of servers or as a single server. If the server is software, it may be implemented as a plurality of software or software modules, such as those used to provide the distributed servers or software modules, or it may be implemented as a single piece of software or software module, which is not specifically limited herein.
[0231] FIG. 9 is a schematic diagram of another embodiment illustrating a resource group implementation according to some embodiments of the present disclosure.
[0232] As described in FIG. 9, the resource group implementation of some embodiments of the present disclosure uses both cgroups cpu sub-system and blkio sub-system, i.e., gpdb / cgroup group may be created under both the cpu sub-system and the blkio sub-system at the same time as root groups, the subsequent process is basically the same, which will not be repeated here.
[0233] Further, under the blkio hierarchy, the blkio. weight weights may be controlled proportionally among the lowest, low, middle, and high levels. More descriptions may be found in FIG. 3.
[0234] Specifically, the structure of cpu hierarchy and blkio hierarchy in FIG. 9 is roughly as shown in FIG. 10, and the numbers 6437, 6438, 68903 in FIG. 10 are group ids corresponding to the 3 resource groups created by the SQL create resource group. For the lowest group, in the cgroups v1 blkio sub-system, it also provides the blkio. throttle. read_iops_device and blkio. throttle. write_iops_device to limit the IOPS limit for reading and writing. More descriptions may be found in FIG. 3.
[0235] In some embodiments, a database processing device may create a resource root group of a database under an operating system based on system functions; create at least one resource group under the resource root group; and create a plurality of resource sub-groups under the resource group to form a database query instance; wherein each resource group may be used to bind a database user, and a number of the plurality of resource sub-groups under the resource group may execute query statements of the database user based on different database resources. With the above query instance creation method, it is also possible to limit the ability of the same database user to use different resources for different SQL. The query instance creation method of some embodiments of the present disclosure incorporates the operating system kernel cgroups function in the MPP distributed database kernel, with the help of its cpu sub-system and blkio sub-system and also limits the use of cpu resources and I / O resources.
[0236] According to the design in FIG. 9, any query process may be no longer attributed to the <gid>cgroup itself, but may be attributed to one of the following four groups: lowest, low, middle, and high under the <gid> cgroup. Another GUC option gp_resgroup_default_level may be used to control exactly to which group the query process belongs, i.e., a session query level may be set, which may be one of the optional values 'lowest' , 'low' , 'middle' , or 'high' ; and if it is not set, it may have a default value of 'middle' .
[0237] The key point of the database query method provided by some embodiments of the present disclosure is that the GUC option gp_resgroup_default_level belongs to a configurations which may be changed at any time, and more descriptions regarding this part may be found in the related descriptions of FIG. 4.
[0238] The GP used in some embodiments of the present disclosure is a distributed database cluster, which actually has a plurality of query instances, each query instance having the same configuration as in FIG. 9, and the entire GP cluster is shown in FIG. 11.
[0239] FIG. 11 is a schematic diagram illustrating an operation of a distributed database cluster according to some embodiments of the present disclosure. FIG. 12 is a flowchart of an embodiment illustrating a database querying method according to some embodiments of the present disclosure.
[0240] FIG. 12 is an embodiment of one of the database query methods shown in FIG. 4. As shown in FIG. 12, one or more of the following operations may be performed.
[0241] Operation S21: user information of a query client and a query statement may be obtained.
[0242] In some implementations, as shown in FIG. 11, the querying client may set a session query level based on actual need, i.e., the gp_resgroup_default_level option value. The Greenplum Master may automatically synchronize the level to the individual Segments, which may then adjust the cgroup group to which the session query process belongs based on the session query level.
[0243] Operation S22: a bound query instance may be queried according to the user information.
[0244] In some embodiments, the query client may be able to place a query SQL, and the execution of the query SQL will be subject to cgroups resource limit, including cpu limit for the cpu sub-system and I / O limit for the blkio sub-system.
[0245] Operation S23: the query statement may be input into a resource sub-group of the query instance, the query statement may be executed, and a query result may be returned.
[0246] Further, initialization checking and initialization configuration of the GP resource group function of some embodiments of the present disclosure may be performed during a database startup phase, as shown in FIGs. 13-14. FIG. 13 is a schematic diagram illustrating an initialization check for the startup phase of a database according to some embodiments of the present disclosure. FIG. 14 is a schematic diagram illustrating an initialization configuration for the startup phase of a database according to some embodiments of the present disclosure.
[0247] As shown in FIG. 14, to use the functions of some embodiments of the present disclosure, the system may need to have cgroups v1 enabled; if it is not enabled, an error may be reported and the program may exit. In some embodiments of the present disclosure, a blkio sub-system may be used, the scheduler for the disk block device may be configured properly to make the blkio weight feature take effect. Generic block device schedulers may include noop, deadline, cfq, and so on. And cfq is a scheduling algorithm that considers process weights as a starting point. In the startup process, whether the scheduler for the datadisk is cfq may be checked. If it is not the cfq, an error may be reported and the program may exit.
[0248] The individual <gid> cgroups created by the GP itself under gpdb / cgroup, as well as cgroups of lowest, low, middle, high, etc., are non-persistent, and when the node is rebooted, these are lost. They may be re-created when the database is started, as described in FIG. 15.
[0249] FIG. 15 is a schematic diagram illustrating a resource group creation for the startup phase of a database according to some embodiments of the present disclosure. As shown in FIG. 15, during the creation process, the values of the weight ratios in the lowest, low, middle, and high cgroups are initialized based on the above-described gp_resgroup_cpu_lowest_factor, gp_resgroup_cpu _low_factor, gp_resgroup_cpu_high_factor, gp_resgroup_blkio_lowest_factor, gp_resgroup_blkio_low_factor, gp_resgroup_blkio_high_factor , gp_resgroup_blkio_lowest_riops, and other GUC values.
[0250] The database query method of some embodiments of the present disclosure provides session level granularity control, which may easily control the CPU and I / O resource usage of different SQL statements; and it also provides four kinds of control levels from high to low, by setting the query level, the query process may migrate smoothly between the four levels.
[0251] It may be understood by those skilled in the art that, in the specific embodiments of the above method, the order in which the operations are written does not imply any limitation on the implementation process by implying a strict order of execution, and that the specific order in which the operations are to be performed should be determined in terms of their function and possible intrinsic logic.
[0252] In order to realize the above query instance creation method, and / or the database query method, some embodiments of the present disclosure also propose a database processing device, as shown in FIG. 16. FIG. 16 is a schematic diagram of an embodiment illustrating the structure of a database processing device according to some embodiments of the present disclosure. The database processing device 600 of the embodiment includes the processor 61, a memory 62, an input / output device 63, and a bus 64.
[0253] The processor 61, the memory 62, and the input / output device 63 are connected to the bus 64, respectively. The memory 62 stores program data, and the processor 61 is used to execute the program data for realizing the query instance creation method and / or the database query method, described in the above embodiment.
[0254] In some embodiments, the processor 61 may also be referred to as a CPU (Central Processing Unit) . The processor 61 may be an integrated circuit chip with signal processing capabilities. The processor 61 may also be a general purpose processor, a digital signal processor (DSP, Digital Signal Process) , an application specific integrated circuit (ASIC, Application Specific Integrated Circuit) , a field programmable gate array (FPGA, Field Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, and discrete hardware components. The general purpose processor may be a microprocessor, or the processor 61 may be any conventional processor, or the like.
[0255] Some embodiments of the present disclosure provide a non-transitory computer-readable storage medium, as shown in FIG. 17. FIG. 17 is a schematic diagram of an embodiment illustrating the structure of a non-transitory computer-readable storage medium according to some embodiments of the present disclosure. The non-transitory computer-readable storage medium 700 has stored therein a computer program 71, which, when executed by a processor, is used to implement a query instance creation method, and / or a database query method, of the above embodiments.
[0256] The embodiments of the present disclosure, when implemented as a software functional unit and sold or used as a stand-alone product, may be stored in a computer-readable storage medium. Based on the understanding, the technical solution of some embodiments of the present disclosure may be embodied essentially or in part as a contribution to the prior art, or in whole or in part, in the form of a software product that is stored in a storage medium and that includes a number of instructions for causing a computer device (which may be a personal computer, a server or a network device, etc. ) or a processor to perform all or part of the operations of the method described in various embodiments of the present disclosure. The aforementioned storage media may include: USB flash drives, removable hard disks, read-only memories (ROM, Read-Only Memory) , random access memories (RAM, Random Access Memory) , disks or CD-ROMs, or other media that may store program code.
[0257] The foregoing is only an implementation of some embodiments of the present disclosure, and is not intended to limit the scope of the patent of the present disclosure, and all the equivalent structures or equivalent process transformations utilizing the contents and the accompanying drawings of this application, or directly or indirectly applying them in other related technical fields, are similarly included in the scope of patent protection of the present disclosure.
[0258] Embodiments of the present disclosure further provide a query control device for a database including at least one processor and at least one storage device; wherein the at least one memory is configured to store computer instructions; and the at least one processor is configured to execute at least a portion of the computer instructions to implement the above-described query control method for the database.
[0259] Some embodiments of the present disclosure further provide a non-transitory computer-readable storage medium including computer instructions, wherein when the computer reads the computer instructions in the storage medium, the computer executes the above-described query control method for the database.
[0260] The basic concepts have been described above, and it is apparent to those skilled in the art that the foregoing detailed disclosure is intended as an example only and does not constitute a limitation of this specification. While not expressly stated herein, a person skilled in the art may make various modifications, improvements, and amendments to this specification. Those types of modifications, improvements, and amendments are suggested in this specification, so those types of modifications, improvements, and amendments remain within the spirit and scope of the exemplary embodiments of this specification.
[0261] In addition, unless expressly stated in the claims, the order of the processing elements and sequences, the use of numerical letters, or the use of other names as described herein are not intended to qualify the order of the processes and methods of this specification. While some embodiments of the invention that are currently considered useful are discussed in the foregoing disclosure by way of various examples, it should be appreciated that such details serve only illustrative purposes, and that additional claims are not limited to the disclosed embodiments, rather, the claims are intended to cover all amendments and equivalent combinations that are consistent with the substance and scope of the embodiments of this specification. For example, although the implementation of various components described above may be embodied in a hardware device, it may also be implemented as a software only solution, e.g., an installation on an existing server or mobile device.
[0262] Similarly, it should be noted that in order to simplify the presentation of the disclosure of this specification, and thereby aid in the understanding of one or more embodiments of the invention, the foregoing descriptions of embodiments of the specification sometimes group a plurality of features together in a single embodiment, accompanying drawings, or in a description thereof description thereof. However, this method of disclosure does not imply that more features are required for the objects of the present disclosure than are mentioned in the claims. Rather, claimed subject matter may lie in less than all features of a single foregoing disclosed embodiment.
[0263] Some embodiments use numbers to describe the number of components, attributes, and it should be understood that such numbers used in the description of the embodiments are modified in some examples by the modifiers "about" , "approximately" , or "substantially" . ", "approximately" , or "generally" is used in some examples. Unless otherwise noted, the terms "about, " "approximate, " or "approximately" indicates that a ±20%variation in the stated number is allowed. Correspondingly, in some embodiments, the numerical parameters used in the specification and claims are approximations, which may change depending on the desired characteristics of individual embodiments. In some embodiments, the numerical parameters should take into account the specified number of valid digits and employ general place-keeping. While the numerical domains and parameters used to confirm the breadth of their ranges in some embodiments of the present disclosure are approximations, in specific embodiments such values are set to be as precise as possible within a feasible range.
[0264] Finally, it should be understood that the embodiments described in this specification are only used to illustrate the principles of the embodiments of this specification. Other deformations may also fall within the scope of this specification. As such, alternative configurations of embodiments of the present disclosure may be considered to be consistent with the teachings of the present disclosure as an example, not as a limitation. Correspondingly, the embodiments of the present disclosure are not limited to the embodiments expressly presented and described herein.
Claims
1.A method implemented on at least one machine each of which has at least one processor and a storage device for query control of a database, the method comprising:creating a plurality of resource sub-groups under at least one resource group of the database, the at least one resource group is associated with a user, wherein at least two of the plurality of resource sub-groups have different control strategies for database resources;determining an execution sub-group based on one or more instructions in a query instance, the execution sub-group being a resource sub-group of the plurality of resource sub-groups corresponding to the query instance; andcontrolling, based on a control strategy of the execution sub-group, a resource usage of the database when the query instance is executed.2.The method of claim 1, wherein the creating a plurality of resource sub-groups under at least one resource group of the database includes:creating a central processing unit root resource group and an input / output root resource group for the database under a central processing unit sub-system and an input / output sub-system of an operating system on which the at least one resource group runs, respectively, wherein the central processing unit sub-system provides resources for executing programs of the operating system, and the input / output sub-system provides resources for reading and writing of the operating system;creating the at least one resource group under the central processing unit root resource group and the input / output root resource group, respectively; andcreating the plurality of resource sub-groups under the at least one resource group.3.The method of claim 2, wherein the input / output sub-system is a blkio sub-system.4.The method of claim 1, wherein the database includes a Massively Parallel Processing database, and the at least one resource group of the Massively Parallel Processing database includes a resource group corresponding to at least one of a central processing unit sub-system or an input / output sub-system of an operating system on which the at least one resource group runs.5.The method of claim 1, wherein:the creating a plurality of resource sub-groups under at least one resource group of the database includes: creating the plurality of resource sub-groups with different weighting levels under the at least one resource group; andthe method further includes: determining the control strategies for the plurality of resource sub-groups based on the weight levels and one or more configuration option parameters corresponding to the plurality of resource sub-groups.6.The method of claim 5, wherein the one or more configuration option parameters include a first configuration parameter, and the determining the control strategies for the plurality of resource sub-groups based on the weight levels and one or more configuration option parameters corresponding to the plurality of resource sub-groups includes:determining a standard resource sub-group from the plurality of resource sub-groups and obtaining the first configuration parameter for other resource sub-groups of the plurality of resource sub-groups;determining, based on the weight levels and the first configuration parameter for the other resource sub-groups, a weight multiplier for the other resource sub-groups with respect to the standard resource sub-group; anddetermining the control strategies for the plurality of resource sub-groups based on the weight multiplier.7.The method of claim 5, wherein the one or more configuration option parameters include a second configuration parameter, and the determining the control strategies for the plurality of resource sub-groups based on the weight levels and one or more configuration option parameters corresponding to the plurality of resource sub-groups includes:determining a target resource sub-group with a lowest weight level among the weight levels;determining, based on the second configuration parameter, a resource limit value for the target resource sub-group; andsetting, based on the resource limit value, an upper limit of a resource hard limit for the target resource sub-group.8.The method of claim 7, further comprising:in response to the second configuration parameter being a preset value, canceling the resource hard limit for the target resource sub-group.9.The method of claim 7, wherein the at least one resource group includes a central processing unit resource group and an input / output resource group, and wherein:under the central processing unit resource group, the resource hard limit includes a resource usage limit; andunder the input / output resource group, the resource hard limit includes a resource read limit and a resource write limit.10.The method of claim 1, wherein:the determining an execution sub-group based on one or more instructions in a query instance, includes: determining the execution sub-group in the query instance, based on the one or more instructions, and at least one of user information or a query statement;the method further includes: executing the query statement based on the execution sub-group and returning a query result.11.The method of claim 10, wherein:the determining the execution sub-group in the query instance, based on the one or more instructions, and at least one of user information or a query statement, includes: determining, based on a session query level, a target execution sub-group in the query instance corresponding to the user information;the executing the query statement based on the execution sub-group and returning a query result includes: executing the query statement based on the target execution sub-group and returning the query result.12.The method of claim 10, wherein the determining the execution sub-group in the query instance, based on the one or more instructions, and at least one of user information or a query statement, includes:in response to a resource load being less than or equal to a predetermined detection threshold, designating a default execution sub-group as the execution sub-group, the resource load including a current central processing unit occupancy and current input / output resources of an operating system on which the at least one resource group runs.13.The method of claim 12, further comprising:determining the predetermined detection threshold every other predetermined cycle based on a count of the at least one resource group and historical query data in a previous predetermined cycle.14.The method of claim 12, further comprising:redetermining the default execution sub-group every other predetermined cycle based on a gap between a historical resource load corresponding to the user and the predetermined detection threshold and a predetermined gap threshold.15.The method of claim 10, wherein the determining the execution sub-group in the query instance, based on the one or more instructions, and at least one of user information or a query statement, includes:in response to a resource load being greater than a preset detection threshold, determining, based on the user information, a resource group to which the user belongs, the resource load including a current central processing unit occupancy and current input / output resources; anddetermining the execution sub-group using a query scheduling model based on query parameters of the query statement, the query scheduling model being a machine learning model.16.The method of claim 15, wherein an input of the query scheduling model includes an average query volume, and the method further includes:determining the average query volume based on historical query data corresponding to the user and current data size corresponding to the historical query data.17.The method of claim 15, wherein an input of the query scheduling model includes the resource load.18.The method of claim 10, wherein the determining the execution sub-group in the query instance, based on the one or more instructions, and at least one of user information or a query statement, includes:every other predetermined cycle, performing:determining a query statement type based on query parameters of the query statement; anddetermining the correspondence between the query statement type and the execution sub-group in a next predetermined cycle based on the query statement type, the user information, an average query volume, and a resource load using a query segmentation model, the query segmentation model being a machine learning model.19.The method of claim 18, further comprising:adjusting the next predetermined cycle based on a historical query frequency of a previous predetermined cycle.20.A device for query control of a database, wherein the device comprises at least one processor and at least one storage device;the at least one storage device is configured to store computer instructions;the at least one processor is configured to execute at least a portion of the computer instructions to implement the method of any one of claims 1-19.21.A non-transitory computer readable medium storing computer instructions, wherein when reading the computer instructions in the storage medium, a computer implements the method of any one of claims 1-19.
Citation Information
Patent Citations
SQL-based resource allocation method and apparatus, and electronic device
CN110362404A
Database query method and device, electronic equipment and storage medium
CN110362611A
Resource group authorization management method
CN112688955A
Query instance creation method and device, database query method and device and storage medium
CN117931836A
Hierarchical multi-tenancy management of system resources in resource groups
US20120150912A1