CN116991882B - Query optimization method and device based on service priority and electronic equipment - Google Patents

Query optimization method and device based on service priority and electronic equipment Download PDF

Info

Publication number
CN116991882B
CN116991882B CN202311268425.6A CN202311268425A CN116991882B CN 116991882 B CN116991882 B CN 116991882B CN 202311268425 A CN202311268425 A CN 202311268425A CN 116991882 B CN116991882 B CN 116991882B
Authority
CN
China
Prior art keywords
sql
executed
priority
data table
target data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202311268425.6A
Other languages
Chinese (zh)
Other versions
CN116991882A (en
Inventor
文严
裴雁峰
高斌
王发修
王鑫
徐志华
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Chengdu New Hope Finance Information Co Ltd
Original Assignee
Chengdu New Hope Finance Information Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Chengdu New Hope Finance Information Co Ltd filed Critical Chengdu New Hope Finance Information Co Ltd
Priority to CN202311268425.6A priority Critical patent/CN116991882B/en
Publication of CN116991882A publication Critical patent/CN116991882A/en
Application granted granted Critical
Publication of CN116991882B publication Critical patent/CN116991882B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2453Query optimisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Mathematical Physics (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application provides a query optimization method, a query optimization device and electronic equipment based on service priority. When the access amount of the target data table exceeds the preset maximum access amount, copying the target data table to obtain a corresponding slave table, wherein the data in the target data table and the data in the slave table are synchronized. In addition, the plurality of SQL to be executed are divided into a first SQL group and a second SQL group, each SQL to be executed is sequentially executed according to the priority weight of each SQL to be executed in the first SQL group so as to perform read-write operation on the target data table, and each SQL to be executed is sequentially executed according to the priority weight of each SQL to be executed in the second SQL group so as to perform read-write operation on the slave table. The method and the device can relieve the processing pressure of the target data table when the processing pressure is overlarge, and ensure the preferential execution of SQL with high priority weight.

Description

Query optimization method and device based on service priority and electronic equipment
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method, an apparatus, and an electronic device for optimizing query based on service priority.
Background
The enterprise uses the database when storing the data, and the data is stored in different types of databases according to the attribute of the business data. For example, data used at high frequency is stored in Redis, data desired to be retained for a long period of time is stored in MySQL, data which is large in data amount and needs to be retrieved is stored in elastic search, and a large amount of unstructured data is stored in HBase. Different systems may use one or more databases to meet the actual business needs.
The developers of the respective systems inevitably use databases when realizing specific requirements. In order to ensure that the written SQL can be executed with high performance, a developer optimizes the database used and also optimizes the written SQL.
However, each system is invoking a common database resource, and in a production environment, one database is often used by multiple systems, and the developer of each system is unaware of how other developers are operating the database. For example, when one system is performing a large batch of operations on a table in a database, other systems may be blocked from operating on the table. Furthermore, limited data resources may be contended for by multiple systems simultaneously.
From a technical perspective, a single SQL acquisition can improve the efficiency of execution and reduce the occupation of database resources by optimizing. But in the case of resource criticality, optimization of a single SQL cannot bring too much change to such a critical scenario. And under the competition condition, the flow of part of the business can wait for the execution of other systems, and can continue to execute after releasing the resources. The blocked portion of the service inevitably presents a scenario in which the service is not available.
Existing database management tools are generally based on larger dimensions, and management and control of the larger dimensions can only avoid and process risks for conventional situations. When facing emergency, the problem of fast processing cannot be accurately solved, and risks are avoided or reduced.
Disclosure of Invention
The invention aims at providing a query optimization method, a query optimization device and electronic equipment based on service priority, which can relieve processing pressure and guarantee preferential execution of SQL with high priority.
Embodiments of the invention may be implemented as follows:
in a first aspect, the present invention provides a method for optimizing a query based on service priority, the method comprising:
acquiring a plurality of structured query statements SQL to be executed aiming at a target data table, and acquiring priority weights of the SQL to be executed;
Copying the target data table to obtain a corresponding slave table when the access amount of the target data table exceeds a preset maximum access amount, wherein the slave table and the data in the target data table are synchronous;
dividing a plurality of SQL to be executed into a first SQL group and a second SQL group;
and sequentially executing the SQL to be executed according to the priority weight of the SQL to be executed in the first SQL group so as to perform read-write operation on the target data table, and sequentially executing the SQL to be executed according to the priority weight of the SQL to be executed in the second SQL group so as to perform read-write operation on the slave table.
In an alternative embodiment, the method further comprises the step of pre-determining a target data table, the step comprising:
counting executed SQL in a history period, and obtaining a data table for each executed SQL;
obtaining the frequency of the read-write operation executed by each data table in the history period;
and taking the data table with the frequency of the read-write operation arranged in the preset position as a target data table.
In an alternative embodiment, the step of obtaining the priority weight of each SQL to be executed includes:
storing the obtained SQL to be executed into a created waiting queue;
Obtaining priority levels and priority values of the SQL to be executed, wherein each priority level corresponds to a plurality of priority values;
obtaining the total quantity of SQL to be executed currently in the waiting queue and the quantity of SQL to be executed under each priority level;
and for each SQL to be executed, calculating to obtain the priority weight of the SQL to be executed according to the priority value of the SQL to be executed, the quantity of the SQL to be executed under the priority level and the total quantity.
In an optional embodiment, the step of calculating the priority weight of the SQL to be executed according to the priority value of the SQL to be executed, the number of the SQL to be executed under the priority level and the total amount includes:
calculating the ratio between the quantity of SQL to be executed and the total quantity under the priority level of the SQL to be executed;
and calculating to obtain the priority weight of the SQL to be executed according to the priority value of the SQL to be executed and the ratio.
In an optional implementation manner, the step of sequentially executing each of the to-be-executed SQLs according to the priority weight of each of the to-be-executed SQLs in the first SQL group to perform the read-write operation on the target data table includes:
For each SQL to be executed of the first SQL group in the waiting queue, sequentially adding the SQL to be executed into an execution queue according to the order of priority weights from high to low;
and extracting SQL to be executed from the execution queue and executing the SQL to perform read-write operation on the target data table.
In an alternative embodiment, the step of dividing the plurality of SQLs to be executed into a first SQL group and a second SQL group includes:
obtaining the aging grade of each SQL to be executed;
dividing the to-be-executed SQL with the aging level higher than the preset level in the plurality of to-be-executed SQL into a first SQL group, and dividing the rest of the to-be-executed SQL into a second SQL group.
In an alternative embodiment, the method further comprises:
deleting the slave table when the read-write pressure of the target data table is monitored to be lower than a preset pressure;
and sequentially executing the obtained SQL to be executed aiming at the target data table according to the corresponding priority weight so as to perform read-write operation on the target data table.
In an optional embodiment, the step of deleting the slave table when the read-write pressure of the target data table is monitored to be lower than a preset pressure includes:
Obtaining the peak flow when the access quantity of the target data table exceeds the preset maximum access quantity;
and obtaining access flow in the statistic period according to the set statistic period, judging that the read-write pressure of the target data table is lower than the preset pressure when the access flow in the continuous preset statistic period is smaller than the peak flow of the preset multiple, and deleting the slave table.
In a second aspect, the present invention provides a service priority-based query optimization apparatus, the apparatus comprising:
the acquisition module is used for acquiring a plurality of structured query sentences SQL to be executed aiming at the target data table and acquiring priority weights of the SQL to be executed;
the copying module is used for copying the target data table to obtain a corresponding slave table when the access amount of the target data table exceeds the preset maximum access amount, wherein the slave table and the data in the target data table are synchronous;
the division module is used for dividing the SQL to be executed into a first SQL group and a second SQL group;
and the read-write module is used for sequentially executing the SQL to be executed according to the priority weight of the SQL to be executed in the first SQL group so as to read and write the target data table, and sequentially executing the SQL to be executed according to the priority weight of the SQL to be executed in the second SQL group so as to read and write the slave table.
In a third aspect, the present application provides an electronic device comprising one or more storage media and one or more processors in communication with the storage media, the one or more storage media storing machine-executable instructions that are executable by the processor to perform the method steps recited in any one of the preceding embodiments when the electronic device is operated.
The beneficial effects of the embodiment of the application include, for example:
the application provides a query optimization method, a query optimization device and electronic equipment based on service priority. When the access amount of the target data table exceeds the preset maximum access amount, copying the target data table to obtain a corresponding slave table, wherein the data in the target data table and the data in the slave table are synchronized. In addition, the plurality of SQL to be executed are divided into a first SQL group and a second SQL group, each SQL to be executed is sequentially executed according to the priority weight of each SQL to be executed in the first SQL group so as to perform read-write operation on the target data table, and each SQL to be executed is sequentially executed according to the priority weight of each SQL to be executed in the second SQL group so as to perform read-write operation on the slave table.
In the scheme, under the condition of overlarge processing pressure, the slave table is copied to map partial read-write operation of the target data table to the slave table, so that the processing pressure of the target data table is relieved. In addition, each SQL is executed in sequence according to the priority weight, so that smooth execution of the SQL with high priority weight can be ensured, and the problem of system risk is avoided.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the embodiments will be briefly described below, it being understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and other related drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flowchart of a query optimization method based on service priority according to an embodiment of the present application;
FIG. 2 is a flowchart of a method for determining a target data table according to an embodiment of the present application;
FIG. 3 is a flow chart of sub-steps included in step S11 of FIG. 1;
FIG. 4 is a schematic diagram of the distribution of SQL across priority and timeliness dimensions;
FIG. 5 is a flow chart of sub-steps included in step S13 of FIG. 1;
FIG. 6 is a flow chart of sub-steps included in step S14 of FIG. 1;
FIG. 7 is a flowchart of a method for deleting slave tables according to an embodiment of the present application;
fig. 8 is a block diagram of an electronic device according to an embodiment of the present application;
fig. 9 is a functional block diagram of a query optimization device based on service priority according to an embodiment of the present application.
Icon: 110-a processor; 120-memory; 130-a communication module; 140-a query optimization device based on service priority; 141-an acquisition module; 142-a replication module; 143-dividing modules; 144-read-write module.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present application more apparent, the technical solutions of the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application, and it is apparent that the described embodiments are some embodiments of the present application, but not all embodiments of the present application. The components of the embodiments of the present application generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the application, as presented in the figures, is not intended to limit the scope of the application, as claimed, but is merely representative of selected embodiments of the application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
It should be noted that: like reference numerals and letters denote like items in the following figures, and thus once an item is defined in one figure, no further definition or explanation thereof is necessary in the following figures.
In the description of the present invention, it should be noted that, if the terms "first," "second," and the like are used merely to distinguish the descriptions, they are not to be construed as indicating or implying relative importance.
It should be noted that the features of the embodiments of the present invention may be combined with each other without conflict.
In order to ensure that the written SQL can be executed with high performance, a developer optimizes the database used and optimizes the written SQL. In the prior art, optimization for databases mainly involves the following ways.
The first way is to reduce database access, which can reduce the overhead of the disk when the database retrieves data internally, and the occupation of network bandwidth when the data is transmitted in the network. By using the index to greatly increase the DML overhead of the record, the correct index can greatly improve the performance and reduce the overhead of the database accessing the disk.
The second way is to return less data, and get the data according to page number by using paging, so only the needed fields are queried, the cost of the database disk is reduced, and the network transmission is reduced.
The third way is to submit in batches to reduce the number of interactions, and the access framework of the database server typically provides an interface for batch submission, where when one million pieces of data need to be inserted into the database in one scenario, if the normal update process is used, the number of interactions with the database is one million. If batch submission is used, the number of interactions is reduced to one thousand per submission.
The fourth way is to reduce the CPU overhead of the server, for example, using binding variables, to hit the execution plan of the SQL buffer as much as possible, and for example, reasonably use the sorting operation, or avoid the fuzzy query of the whole module as much as possible, or put a large number of complex operations on the client to process as much as possible, etc.
The fifth way is to use more resources, such as increasing the CPU and disk resources of the physical machine, etc.
The method adopted in the prior art can improve the performance of the database to a certain extent, but under the condition of resource shortage, the problem of resource competition exists among the SQL, and some SQL with low timeliness requirements and SQL with high timeliness requirements compete for resources together. When the resource is in a critical state, it is difficult to ensure smooth execution of some important SQL, so that a problem of system risk may occur.
Based on the research, the application provides a query optimization method based on service priority, which obtains a slave table by copying a target data table under the condition of overlarge processing pressure, namely resource shortage, so as to map partial read-write operation of the target data table to the slave table and relieve the processing pressure of the target data table. In addition, each SQL is executed in sequence according to the priority weight, so that smooth execution of the SQL with high priority weight can be ensured, and the problem of system risk is avoided.
Fig. 1 is a flow chart illustrating a service priority-based query optimization method according to an embodiment of the present application, where the service priority-based query optimization method may be performed by a service priority-based query optimization device, and the service priority-based query optimization device may be implemented by software and/or hardware, and may be configured in an electronic device, where the electronic device may be a computer device. The detailed steps of the query optimization method based on the service priority are described as follows.
S11, acquiring a plurality of structured query statements SQL to be executed aiming at a target data table, and acquiring priority weights of the SQL to be executed.
And S12, copying the target data table to obtain a corresponding slave table when the access amount of the target data table exceeds the preset maximum access amount, wherein the slave table and the data in the target data table are synchronous.
S13, dividing the SQL to be executed into a first SQL group and a second SQL group.
S14, sequentially executing the SQL to be executed according to the priority weight of the SQL to be executed in the first SQL group so as to perform read-write operation on the target data table, and sequentially executing the SQL to be executed according to the priority weight of the SQL to be executed in the second SQL group so as to perform read-write operation on the slave table.
In this embodiment, the target data table is a data table that needs to be subjected to key optimization management, for example, a data table that is frequently accessed, where the data table in this embodiment may be understood as a database.
In this embodiment, the optimization management platform may be configured to implement query optimization for SQL, where query optimization for SQL also involves call optimization for resources, and thus may be understood as a resource scheduling platform.
The developer correspondingly develops SQL based on different business requirements, for example, SQL comprising presentation class statistics, SQL of index calculation classes, SQL on authorization flow, and the like.
The data table stores related data required by the service, and the related SQL is executed to read and write the data from the data table, so that a certain service is completed.
For the same target data table, there may be multiple SQL's that need to be executed to read and write data from the target data table within the same period of time. If the number of SQL to be executed is too large, which means that more processing resources are needed to support the execution of SQL, the resource occupation may be too large, resulting in too great processing pressure.
In the case that the access amount of the target data table exceeds the preset maximum access amount, in this embodiment, the target data table may be copied to obtain a slave table, and part of the read-write operation of the target data table is mapped to the slave table, so as to relieve the read-write pressure of the target data table. The data in the target data table and the slave table can be synchronized, and processing resources can be respectively configured for the target data table and the slave table, for example, the processing resources configured for the target data table can be more than the processing resources configured for the slave table, so that smooth reading and writing of the data in the target data table can be ensured.
For example, for the target data table t_user, the corresponding slave table t_user1 is copied. For a partial query statement for the target data table t_user, the platform will be replaced with the slave table t_user1.
For example, SELECTFROM t_user WHERE ip LIKE%% substitution is:
SELECTFROM t_user1 WHERE ip LIKE %%
meanwhile, in this embodiment, the plurality of to-be-executed SQLs originally aimed at the target data table are divided into a first SQL group and a second SQL group, so that the to-be-executed SQL in the first SQL group can be executed based on the target data table, and the to-be-executed SQL in the second SQL group can be executed based on the slave table.
When the SQL to be executed in the first SQL group and the second SQL group is executed specifically, the priority weight of each SQL to be executed can be obtained, wherein the priority weight can be set based on the importance degree of the SQL service. Thus, when the first SQL group and the second SQL group are executed respectively, the first SQL group and the second SQL group can be executed in the order of the priority weights from high to low.
In this embodiment, the number of slave tables may be one or more, for example, in the case where copying one slave table can successfully relieve the read/write pressure of the target data table, the number of slave tables may be one. If the read-write pressure of the target data table is still relatively high after copying one slave table, the slave table can be copied continuously, for example, two slave tables are copied to map part of read-write operation of the target data table to the two slave tables, so that the processing pressure of the target data table is further relieved.
Accordingly, the number of the second SQL groups is the same as that of the slave tables, and the second SQL groups can be one or a plurality of the second SQL groups, and each second SQL group can execute SQL to be executed based on the corresponding slave table so as to perform data read-write operation from the corresponding slave table.
According to the query optimization method based on the service priority, on one hand, under the condition that the processing pressure of the target data table is too high, the slave table is obtained through copying, so that part of read-write operation of the target data table is mapped to the slave table, and the processing pressure of the target data table is relieved. On the other hand, each SQL to be executed is executed in sequence according to the priority weight of the SQL to be executed, so that the priority execution of the important SQL can be ensured, and the occurrence of the condition of system risk is avoided.
As can be seen from the foregoing, the target data table may be understood as a data table that needs to be subjected to query optimization management, referring to fig. 2, in this embodiment, the target data table may be determined by the following manner:
s21, counting executed SQL in the history period, and obtaining a data table for each executed SQL.
S22, obtaining the frequency of the read-write operation executed by each data table in the history period.
S23, the data table with the frequency of read-write operation arranged in the preset position is used as a target data table.
In this embodiment, the service system sends the SQL to be executed to the platform, and the platform parses the pointed data table and the executed operation from the SQL, for example, the parsing information is as follows:
SELECTFROM t_user WHERE ip LIKE % %
From the parsed information, the table name of the data table pointed to by the SQL is t_user, and the operation performed is SELECT.
The platform can store the analyzed information into the memory, and can store the information according to the following storage format:
{
"SELECT":{
"t_user":"1",
"t_school":"2"
}
}
through statistics of SQL in a period of time, the frequency of the read-write operation executed by each data table can be obtained through statistics, and the data table with higher frequency is a hot spot data table, and the hot spot data table is the target data table in the embodiment. The statistics of the hot spot data table can be determined statistically by taking hours as dimensions, or by taking days as dimensions.
On the basis, query optimization management is performed on the determined target data table, and in the step of obtaining the priority weight of each SQL to be executed, for the SQL accessing the target data table, the query optimization management can be realized by the following way, please refer to fig. 3 in combination:
s111, storing the obtained SQL to be executed into a created waiting queue.
S112, obtaining the priority level and the priority value of each SQL to be executed, wherein each priority level corresponds to a plurality of priority values.
S113, obtaining the total quantity of the SQL to be executed currently in the waiting queue and the quantity of the SQL to be executed under each priority level.
S114, calculating the priority weight of the SQL to be executed according to the priority value of the SQL to be executed, the quantity of the SQL to be executed under the priority level and the total quantity aiming at each SQL to be executed.
In this embodiment, according to the importance degrees of different service requirements, corresponding priority levels and priority values may be set for corresponding SQLs. For example, a developer may enter the developed SQL into the platform and set the priority level and priority value of each SQL. Priority levels can be classified into high priority, medium priority, and low priority, with priority values of 0-10. Wherein, the priority values 0-3 belong to low priority, the priority values 4-6 belong to medium priority, and the priority values 7-10 belong to high priority. The statement of the setting of the priority value of SQL is as follows:
{
"sql":"SELECTFROM t_user WHERE ip LIKE/>",
"priority":"8"
}
where sql refers to sql and priority value refers to priority value.
After the platform registers the priority value and priority level of each SQL, the platform returns an ID corresponding to the SQL, which may be S20230731113801234567, for example.
In this embodiment, a waiting queue and an execution queue are created in advance, and the execution queue is a first-in first-out queue. For each received SQL to be executed, the received SQL is firstly stored in a waiting queue, and then enters an execution queue again according to a certain rule for execution.
In order to avoid that the SQL to be executed in the waiting queue is simply executed with the priority value or the priority level, when more SQL with lower priority exists, the condition that the SQL with lower priority is not executed for a long time occurs, so in the embodiment, each SQL is executed sequentially according to the priority weight.
The calculation of the priority weight of each SQL to be executed is obtained by calculating according to the priority value, the quantity of SQL to be executed under the belonging priority level and the total quantity of SQL to be executed in the waiting queue.
Specifically, the ratio between the number and the total amount of the SQL to be executed under the priority level to which the SQL to be executed belongs can be calculated, and the priority weight of the SQL to be executed is calculated according to the priority value and the ratio of the SQL to be executed.
For example, in conjunction with the illustration in table 1, assume that the total amount T of the current SQL to be executed in the waiting queue is 100, where the number G of the high-priority SQL to be executed is equal to 20, the data Z of the medium-priority SQL to be executed is equal to 50, and the data D of the low-priority SQL to be executed is equal to 30. From the above, the priority value is 0 to 10, and Q is set.
Table 1 SQL information table
For the SQL to be executed with high priority, the calculation formula of the priority weight is Q+ (G/T)C;
For medium priorityThe calculation formula of the priority weight of SQL to be executed is Q+ (Z/T)C;
For low priority SQL to be executed, the calculation formula of the priority weight is Q+ (D/T)C。
Wherein, C is a weight parameter, for example, may be 5.
And calculating the priority weight of each SQL to be executed according to the mode, and executing each SQL to be executed in turn according to the priority weight. Under the condition that the quantity of the SQL with the lower priority level is more and the quantity of the SQL with the higher priority level is less, the priority weight of the SQL with the lower priority level can be higher than that of the SQL with the higher priority level, so that the stacking of the SQL with the lower priority level can be relieved first, and the phenomenon that the SQL with the lower priority level cannot be processed for a long time is avoided.
In this embodiment, the priority of the SQL is mainly set based on its priority value, and the level of the priority value is mainly affected by its importance. In addition, as can be seen from the above description, the requirements of the SQL of different service types on timeliness are different, for example, the requirements of the SQL of the presentation class statistics, the SQL of some index calculation classes, etc. on timeliness are lower, while the requirements of the SQL of the calculation classes of the core anti-fraud index on the trust flow of the client on timeliness are higher.
In this embodiment, the priority and timeliness may be used as two-dimensional indexes of the SQL, where the two-dimensional indexes are related to some extent, but are not completely consistent, for example, some SQL with high priority may have a lower timeliness requirement, and some SQL with low priority may have a higher timeliness requirement. However, there may be cases where the timeliness requirement is higher for some high-priority SQLs and lower for some low-priority SQLs. For example, as shown in fig. 4, the distribution of the SQL (each point in the graph) in both the priority and timeliness dimensions is shown.
SQL with higher timeliness requirements needs to be processed quickly, so that timely feedback can be guaranteed, and SQL with lower timeliness requirements has no higher requirements on processing speed.
As described above, the target data table and the slave table may be allocated with more processing resources and the slave table may be allocated with less processing resources. Thus, referring to fig. 5, when dividing the plurality of SQLs to be executed into the first SQL group and the second SQL group, the division may be performed as follows:
s131, obtaining the aging grade of each SQL to be executed.
S132, dividing the to-be-executed SQL with the aging level higher than the preset level in the plurality of to-be-executed SQL into a first SQL group, and dividing the rest of the to-be-executed SQL into a second SQL group.
In this embodiment, the corresponding aging level may be set based on the requirement of each SQL to be executed for aging, for example, the higher the aging level, the higher the requirement of SQL for aging. Because the target data table is allocated with more processing resources compared with the slave table, the processing speed is faster compared with the slave table, the SQL to be executed with the aging level higher than the preset level can be divided into the first SQL group so as to be convenient for the data read-write processing of the target data table. In addition, the rest of the SQL to be executed, namely, the SQL to be executed with the aging level lower than the preset level is divided into a second SQL group so as to facilitate the data read-write processing from the slave table. Therefore, SQL with high timeliness requirements can be guaranteed to be processed rapidly.
In this embodiment, on the basis of dividing the to-be-executed SQL with higher timeliness requirement into the first SQL group and dividing the to-be-executed SQL with lower timeliness requirement into the second SQL group, and obtaining the priority weights of the to-be-executed SQLs in each SQL group, when executing each to-be-executed SQL, the method may be implemented as follows, please refer to fig. 6 in combination:
S141, for each SQL to be executed of the first SQL group in the waiting queue, sequentially adding each SQL to be executed into an execution queue according to the order of priority weights from high to low.
S142, extracting SQL to be executed from the execution queue and executing the SQL to perform read-write operation on the target data table.
In this embodiment, when performing read-write operation on the target data table, the to-be-executed SQL in the first SQL group in the waiting queue may be sequentially added to the execution queue according to the priority weight, for example, if the maximum number of the SQLs that can be stored in the execution queue is 10 and the number of the SQLs in the current execution queue is 2, 8 to-be-executed SQLs with the front priority weight may be extracted from the first SQL group in the waiting queue and added to the execution queue for execution.
In this embodiment, the SQL to be executed in the first SQL group and the second SQL group may be stored in the same waiting queue, and there may be one corresponding execution queue. In addition, the data may be stored in two waiting queues, and two execution queues may be provided correspondingly, which is not limited in detail and may be set according to the requirements.
Similar to the above-mentioned execution of the SQL to be executed for the target data table, the embodiment is not described herein.
As can be seen from the above, when the processing pressure of the target data table is too high, the slave table is triggered to release the processing pressure of the target data table, and generally, when the processing pressure of the target data table is too high in a specific scenario, for example, when the flow rate such as impulse suddenly increases, the processing pressure of the target data table will decrease after the flow rate is exceeded, so as to avoid redundancy of data, the query optimization method provided in this embodiment further includes the following steps, please refer to fig. 7 in combination:
and S31, deleting the slave table when the read-write pressure of the target data table is monitored to be lower than a preset pressure.
S32, sequentially executing the obtained SQL to be executed aiming at the target data table according to the corresponding priority weight so as to perform read-write operation on the target data table.
In this embodiment, after the flow rate in the impulse or other scenario passes, the read-write pressure of the target data table is relieved, for example, when the read-write pressure of the target data table is lower than the preset pressure, the slave table may be deleted. In this case, the subsequently obtained SQL to be executed for the target data table will be executed by performing a read-write operation on the target data table, and when executing, the SQL is executed sequentially according to the priority weight of the SQL to be executed.
In this embodiment, when determining whether the read-write pressure of the target data table is lower than the preset pressure, the peak flow when the access amount of the target data table exceeds the preset maximum access amount may be obtained, and the access flow in the statistical period may be obtained according to the set statistical period, and when the access flows in the continuous preset statistical periods are all smaller than the peak flow of the preset multiple, it is determined that the read-write pressure of the target data table is lower than the preset pressure, and the slave table is deleted.
For example, the statistics period may be a period taking a day as a period, the preset statistics period may be 5 statistics periods, the preset multiple may be 1/3, that is, when the access flow obtained by statistics in 5 consecutive days is smaller than the peak flow of 1/3 times, it may be determined that the read-write pressure of the target data table is lower than the preset pressure, and the slave table may be deleted.
In the query optimization method provided in this embodiment, in a scenario where the flow suddenly increases, under a situation that the access amount to the target data table exceeds the preset maximum access amount, the SQL execution under the slave table replication and priority mechanism is triggered. In the case where the platform is in a healthy state, that is, the processing resources are sufficient, the execution may be sequentially performed according to the order in which the SQL is received.
According to the scheme, the copy of the slave table and the setting of the priority weight and the setting of the efficiency level can be adopted, so that the pressure of the read-write operation of the target data table can be relieved under the condition that the access quantity is suddenly increased, the priority execution of the SQL with high priority can be ensured, and the quick response of the SQL with high timeliness requirement can be ensured.
Referring to fig. 8, a block diagram of an electronic device according to an embodiment of the application may include a memory 120, a processor 110, and a communication module 130. The memory 120, the processor 110, and the communication module 130 are electrically connected directly or indirectly to each other to realize data transmission or interaction. For example, the components may be electrically connected to each other via one or more communication buses or signal lines.
Wherein the memory 120 is used for storing programs or data. The Memory 120 may be, but is not limited to, random access Memory (Random Access Memory, RAM), read Only Memory (ROM), programmable Read Only Memory (Programmable Read-Only Memory, PROM), erasable Read Only Memory (Erasable Programmable Read-Only Memory, EPROM), electrically erasable Read Only Memory (Electric Erasable Programmable Read-Only Memory, EEPROM), etc.
The processor 110 is configured to read/write data or programs stored in the memory 120 and execute the service priority-based query optimization method according to any embodiment of the present application.
The communication module 130 is used for establishing communication connection between the electronic device and other communication terminals through a network, and is used for receiving and transmitting data through the network.
It should be understood that the configuration shown in fig. 8 is merely a schematic diagram of the configuration of the electronic device, and the electronic device may also include more or fewer components than those shown in fig. 8, or have a different configuration than that shown in fig. 8.
Based on the same inventive concept, please refer to fig. 9, which is a schematic diagram illustrating functional modules of a service priority-based query optimization device 140 according to an embodiment of the present application, where the service priority-based query optimization device 140 may be divided into functional modules according to the above-described method embodiment. For example, each functional module may be divided corresponding to each function, or two or more functions may be integrated in one processing module.
The integrated modules may be implemented in hardware or in software functional modules. It should be noted that, in the embodiment of the present application, the division of the modules is schematic, which is merely a logic function division, and other division manners may be implemented in actual implementation.
For example, in the case of dividing each function module by corresponding each function, the service priority-based query optimizing apparatus 140 shown in fig. 9 is only one apparatus schematic. The service priority-based query optimization device 140 may include an acquisition module 141, a replication module 142, a partitioning module 143, and a read-write module 144, and the functions of each functional module of the service priority-based query optimization device 140 are described in detail below.
The obtaining module 141 is configured to obtain a plurality of to-be-executed structured query terms SQL for the target data table, and obtain priority weights of the to-be-executed SQL;
it will be appreciated that the acquisition module 141 may be configured to perform the step S11 described above, and reference may be made to the details of the implementation of the acquisition module 141 in relation to the step S11 described above.
A copying module 142, configured to copy the target data table to obtain a corresponding slave table when the access amount of the target data table exceeds a preset maximum access amount, where the slave table is synchronous with data in the target data table;
it will be appreciated that the replication module 142 may be used to perform step S12 described above, and reference may be made to the details of step S12 regarding the implementation of the replication module 142.
A dividing module 143, configured to divide the plurality of SQLs to be executed into a first SQL group and a second SQL group;
it is understood that the dividing module 143 may be used to perform the above step S13, and reference may be made to the details of the above step S13 for the detailed implementation of the dividing module 143.
The read-write module 144 is configured to sequentially execute each of the to-be-executed SQLs according to the priority weights of each of the to-be-executed SQLs in the first SQL group to perform read-write operations on the target data table, and sequentially execute each of the to-be-executed SQLs according to the priority weights of each of the to-be-executed SQLs in the second SQL group to perform read-write operations on the slave table.
It is understood that the read/write module 144 may be used to perform the step S14, and reference may be made to the details of the implementation of the read/write module 144 in the step S14.
In one possible implementation, the service priority based query optimization device 140 further includes a determining module that may be configured to:
counting executed SQL in a history period, and obtaining a data table for each executed SQL;
obtaining the frequency of the read-write operation executed by each data table in the history period;
And taking the data table with the frequency of the read-write operation arranged in the preset position as a target data table.
In one possible implementation, the acquiring module 141 may be configured to:
storing the obtained SQL to be executed into a created waiting queue;
obtaining priority levels and priority values of the SQL to be executed, wherein each priority level corresponds to a plurality of priority values;
obtaining the total quantity of SQL to be executed currently in the waiting queue and the quantity of SQL to be executed under each priority level;
and for each SQL to be executed, calculating to obtain the priority weight of the SQL to be executed according to the priority value of the SQL to be executed, the quantity of the SQL to be executed under the priority level and the total quantity.
In one possible implementation, the obtaining module 141 may be specifically configured to:
calculating the ratio between the quantity of SQL to be executed and the total quantity under the priority level of the SQL to be executed;
and calculating to obtain the priority weight of the SQL to be executed according to the priority value of the SQL to be executed and the ratio.
In one possible implementation, the read/write module 144 may be configured to:
For each SQL to be executed of the first SQL group in the waiting queue, sequentially adding the SQL to be executed into an execution queue according to the order of priority weights from high to low;
and extracting SQL to be executed from the execution queue and executing the SQL to perform read-write operation on the target data table.
In one possible implementation, the dividing module 143 may be configured to:
obtaining the aging grade of each SQL to be executed;
dividing the to-be-executed SQL with the aging level higher than the preset level in the plurality of to-be-executed SQL into a first SQL group, and dividing the rest of the to-be-executed SQL into a second SQL group.
In one possible implementation, the service priority-based query optimization device 140 further includes a deletion module that can be used to:
deleting the slave table when the read-write pressure of the target data table is monitored to be lower than a preset pressure;
and sequentially executing the obtained SQL to be executed aiming at the target data table according to the corresponding priority weight so as to perform read-write operation on the target data table.
In one possible implementation manner, the deleting module may specifically be used to:
obtaining the peak flow when the access quantity of the target data table exceeds the preset maximum access quantity;
And obtaining access flow in the statistic period according to the set statistic period, judging that the read-write pressure of the target data table is lower than the preset pressure when the access flow in the continuous preset statistic period is smaller than the peak flow of the preset multiple, and deleting the slave table.
The process flow of each module in the apparatus and the interaction flow between the modules may be described with reference to the related descriptions in the above method embodiments, which are not described in detail herein.
Further, the embodiment of the application also provides a computer readable storage medium, and the computer readable storage medium stores machine executable instructions, which when executed, implement the query optimization method based on the service priority provided by the embodiment.
In particular, the computer readable storage medium can be a general purpose storage medium, such as a mobile disk, a hard disk, etc., and the computer program on the computer readable storage medium can execute the above-mentioned query optimization method based on service priority when being executed. With respect to the processes involved in the computer readable storage medium and when executed as executable instructions thereof, reference is made to the relevant descriptions of the method embodiments described above and will not be described in detail herein.
In summary, according to the query optimization method, the query optimization device and the electronic device based on the service priority provided by the embodiment of the application, after a plurality of SQL to be executed aiming at the target data table are obtained, the priority weight of each SQL to be executed is obtained. When the access amount of the target data table exceeds the preset maximum access amount, copying the target data table to obtain a corresponding slave table, wherein the data in the target data table and the data in the slave table are synchronized. In addition, the plurality of SQL to be executed are divided into a first SQL group and a second SQL group, each SQL to be executed is sequentially executed according to the priority weight of each SQL to be executed in the first SQL group so as to perform read-write operation on the target data table, and each SQL to be executed is sequentially executed according to the priority weight of each SQL to be executed in the second SQL group so as to perform read-write operation on the slave table.
In the scheme, under the condition of overlarge processing pressure, the slave table is copied to map partial read-write operation of the target data table to the slave table, so that the processing pressure of the target data table is relieved. In addition, each SQL is executed in sequence according to the priority weight, so that smooth execution of the SQL with high priority weight can be ensured, and the problem of system risk is avoided.
The foregoing is merely illustrative of the present application, and the present application is not limited thereto, and any changes or substitutions easily contemplated by those skilled in the art within the scope of the present application should be included in the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.

Claims (10)

1. A method for optimizing queries based on service priorities, the method comprising:
acquiring a plurality of structured query statements SQL to be executed aiming at a target data table, and acquiring priority weights of the SQL to be executed;
copying the target data table to obtain a corresponding slave table when the access amount of the target data table exceeds a preset maximum access amount, wherein the slave table and the data in the target data table are synchronous;
dividing a plurality of SQL to be executed into a first SQL group and a second SQL group;
and sequentially executing the SQL to be executed according to the priority weight of the SQL to be executed in the first SQL group so as to perform read-write operation on the target data table, and sequentially executing the SQL to be executed according to the priority weight of the SQL to be executed in the second SQL group so as to perform read-write operation on the slave table.
2. The traffic priority based query optimization method as claimed in claim 1, wherein said method further comprises the step of pre-determining a target data table, the step comprising:
counting executed SQL in a history period, and obtaining a data table for each executed SQL;
obtaining the frequency of the read-write operation executed by each data table in the history period;
And taking the data table with the frequency of the read-write operation arranged in the preset position as a target data table.
3. The service priority-based query optimization method as claimed in claim 1, wherein said step of obtaining priority weights of respective SQLs to be executed comprises:
storing each obtained SQL to be executed into a created waiting queue;
obtaining priority levels and priority values of the SQL to be executed, wherein each priority level corresponds to a plurality of priority values;
obtaining the total quantity of SQL to be executed currently in the waiting queue and the quantity of SQL to be executed under each priority level;
and for each SQL to be executed, calculating to obtain the priority weight of the SQL to be executed according to the priority value of the SQL to be executed, the quantity of the SQL to be executed under the priority level and the total quantity.
4. The service priority-based query optimization method according to claim 3, wherein the step of calculating the priority weight of the SQL to be executed according to the priority value of the SQL to be executed, the number of the SQL to be executed under the priority level and the total amount comprises:
Calculating the ratio between the quantity of SQL to be executed and the total quantity under the priority level of the SQL to be executed;
and calculating to obtain the priority weight of the SQL to be executed according to the priority value of the SQL to be executed and the ratio.
5. The business priority-based query optimization method as claimed in claim 3, wherein said step of sequentially executing each of said to-be-executed SQLs according to the priority weight of each of said to-be-executed SQLs in said first SQL group to perform a read/write operation on said target data table comprises:
for each SQL to be executed of the first SQL group in the waiting queue, sequentially adding the SQL to be executed into an execution queue according to the order of priority weights from high to low;
and extracting SQL to be executed from the execution queue and executing the SQL to perform read-write operation on the target data table.
6. The business priority based query optimization method of claim 1, wherein the step of dividing the plurality of SQLs to be executed into a first SQL group and a second SQL group comprises:
obtaining the aging grade of each SQL to be executed;
dividing the to-be-executed SQL with the aging level higher than the preset level in the plurality of to-be-executed SQL into a first SQL group, and dividing the rest of the to-be-executed SQL into a second SQL group.
7. The business priority based query optimization method of claim 1, wherein the method further comprises:
deleting the slave table when the read-write pressure of the target data table is monitored to be lower than a preset pressure;
and sequentially executing the obtained SQL to be executed aiming at the target data table according to the corresponding priority weight so as to perform read-write operation on the target data table.
8. The service priority-based query optimization method as claimed in claim 7, wherein said step of deleting said slave table when it is detected that the read-write pressure of said target data table is lower than a preset pressure comprises:
obtaining the peak flow when the access quantity of the target data table exceeds the preset maximum access quantity;
and obtaining access flow in the statistic period according to the set statistic period, judging that the read-write pressure of the target data table is lower than the preset pressure when the access flow in the continuous preset statistic period is smaller than the peak flow of the preset multiple, and deleting the slave table.
9. A traffic priority based query optimization device, the device comprising:
the acquisition module is used for acquiring a plurality of structured query sentences SQL to be executed aiming at the target data table and acquiring priority weights of the SQL to be executed;
The copying module is used for copying the target data table to obtain a corresponding slave table when the access amount of the target data table exceeds the preset maximum access amount, wherein the slave table and the data in the target data table are synchronous;
the division module is used for dividing the SQL to be executed into a first SQL group and a second SQL group;
and the read-write module is used for sequentially executing the SQL to be executed according to the priority weight of the SQL to be executed in the first SQL group so as to read and write the target data table, and sequentially executing the SQL to be executed according to the priority weight of the SQL to be executed in the second SQL group so as to read and write the slave table.
10. An electronic device comprising one or more storage media and one or more processors in communication with the storage media, the one or more storage media storing processor-executable machine-executable instructions that, when the electronic device is run, are executed by the processor to perform the method steps recited in any of claims 1-8.
CN202311268425.6A 2023-09-28 2023-09-28 Query optimization method and device based on service priority and electronic equipment Active CN116991882B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311268425.6A CN116991882B (en) 2023-09-28 2023-09-28 Query optimization method and device based on service priority and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311268425.6A CN116991882B (en) 2023-09-28 2023-09-28 Query optimization method and device based on service priority and electronic equipment

Publications (2)

Publication Number Publication Date
CN116991882A CN116991882A (en) 2023-11-03
CN116991882B true CN116991882B (en) 2023-12-01

Family

ID=88530686

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311268425.6A Active CN116991882B (en) 2023-09-28 2023-09-28 Query optimization method and device based on service priority and electronic equipment

Country Status (1)

Country Link
CN (1) CN116991882B (en)

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101329686A (en) * 2008-07-31 2008-12-24 中国科学院计算技术研究所 System for implementing network search caching and search method
CN107168977A (en) * 2016-03-08 2017-09-15 阿里巴巴集团控股有限公司 A kind of optimization method and device of data query
CN109889562A (en) * 2018-01-15 2019-06-14 广东电网有限责任公司信息中心 A kind of offline access method and system of the advanced application platform of Enterprise Mobile
CN110362404A (en) * 2019-06-28 2019-10-22 北京淇瑀信息科技有限公司 A kind of resource allocation methods based on SQL, device and electronic equipment
CN113468215A (en) * 2020-03-30 2021-10-01 阿里巴巴集团控股有限公司 Data processing method and device, electronic equipment and computer storage medium
CN114116783A (en) * 2021-11-19 2022-03-01 北京达佳互联信息技术有限公司 Data table operation request processing method and device, server and storage medium
CN114398371A (en) * 2022-01-13 2022-04-26 九有技术(深圳)有限公司 Multi-copy fragmentation method, device, equipment and storage medium for database cluster system
CN116126973A (en) * 2022-12-29 2023-05-16 国家气象信息中心(中国气象局气象数据中心) Meteorological lattice data management method and device
CN116804994A (en) * 2023-08-23 2023-09-26 北京逐风科技有限公司 Data synchronization method, system, device, electronic equipment and storage medium

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10838981B2 (en) * 2017-08-30 2020-11-17 Sap Se Database optimization using special partition specifications for replicas
US10810229B2 (en) * 2018-10-19 2020-10-20 Oracle International Corporation Database replication based on data access scores
US11379486B2 (en) * 2019-09-20 2022-07-05 Sap Se Virtual database tables with updatable logical table pointers

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101329686A (en) * 2008-07-31 2008-12-24 中国科学院计算技术研究所 System for implementing network search caching and search method
CN107168977A (en) * 2016-03-08 2017-09-15 阿里巴巴集团控股有限公司 A kind of optimization method and device of data query
CN109889562A (en) * 2018-01-15 2019-06-14 广东电网有限责任公司信息中心 A kind of offline access method and system of the advanced application platform of Enterprise Mobile
CN110362404A (en) * 2019-06-28 2019-10-22 北京淇瑀信息科技有限公司 A kind of resource allocation methods based on SQL, device and electronic equipment
CN113468215A (en) * 2020-03-30 2021-10-01 阿里巴巴集团控股有限公司 Data processing method and device, electronic equipment and computer storage medium
CN114116783A (en) * 2021-11-19 2022-03-01 北京达佳互联信息技术有限公司 Data table operation request processing method and device, server and storage medium
CN114398371A (en) * 2022-01-13 2022-04-26 九有技术(深圳)有限公司 Multi-copy fragmentation method, device, equipment and storage medium for database cluster system
CN116126973A (en) * 2022-12-29 2023-05-16 国家气象信息中心(中国气象局气象数据中心) Meteorological lattice data management method and device
CN116804994A (en) * 2023-08-23 2023-09-26 北京逐风科技有限公司 Data synchronization method, system, device, electronic equipment and storage medium

Also Published As

Publication number Publication date
CN116991882A (en) 2023-11-03

Similar Documents

Publication Publication Date Title
CN109947668B (en) Method and device for storing data
CN108776934B (en) Distributed data calculation method and device, computer equipment and readable storage medium
EP2921975B1 (en) Determining and extracting changed data from a data source
CA2785398C (en) Managing queries
US20140075030A1 (en) Managing allocation of thread resources for message queues in an on-demand services environment
US20080065588A1 (en) Selectively Logging Query Data Based On Cost
CN111506559A (en) Data storage method and device, electronic equipment and storage medium
US8751446B2 (en) Transference control method, transference control apparatus and recording medium of transference control program
Goel et al. Resource fairness and prioritization of transactions in permissioned blockchain systems (industry track)
US20240129251A1 (en) Data processing method and apparatus, computer device, and readable storage medium
US11243979B1 (en) Asynchronous propagation of database events
CN116991882B (en) Query optimization method and device based on service priority and electronic equipment
CN116089477B (en) Distributed training method and system
EP4216076A1 (en) Method and apparatus of processing an observation information, electronic device and storage medium
US10346371B2 (en) Data processing system, database management system, and data processing method
CN116166181A (en) Cloud monitoring method and cloud management platform
Koschel et al. Evaluating time series database management systems for insurance company
JP2013200601A (en) Database system, commitment method in database system, and program
CN106528577B (en) Method and device for setting file to be cleaned
EP4184325A1 (en) Method and system for high-throughput distributed computing of computational jobs
US20230153305A1 (en) Method and system for high-throughput distributed computing of computational jobs
US11327802B2 (en) System and method for exporting logical object metadata
CN112148491B (en) Data processing method and device
CN117950577A (en) Cluster capacity management method, device, equipment and storage medium
CN114647701A (en) Load balancing method and device for distributed database, electronic equipment and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant