Query data table generation method, data query method, device and electronic equipment
By filtering historical query statements to generate query data tables and transferring query operations, it solves the problem of reduced database query efficiency and improves query efficiency and resource utilization.
Patent Information
- Application Number
- CN202410805696.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-21
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2044-06-21
AI Technical Summary
As the amount of data increases, database query efficiency decreases, especially when multiple indicators are calculated simultaneously, resulting in increased database load and slower query efficiency.
By obtaining the query attribute information of historical query records, slow query statements are filtered out, and a query data table is generated based on these statements, and some query operations are transferred to the query data table for processing, thereby reducing the access load to the database.
It improves data query efficiency, reduces database access pressure, optimizes resource utilization, and ensures the accuracy of query results.
Smart Images

Figure CN118377797B
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing, and in particular to a method for generating a query data table, a data query method, a device and an electronic device. Background Art
[0002] In various industries, companies will quantify the capabilities of their customers through various indicators to provide more accurate decisions and services. When calculating indicators, it is necessary to access the database to obtain the data used for indicator calculation. Generally speaking, the more complete the data sample and the larger the data volume, the more reference significance the calculated indicators have.
[0003] However, with the surge in data volume, the speed of querying data used for indicator calculation is getting slower and slower when calculating indicators. In particular, when a large number of indicators are calculated at the same time, the database load will increase, which will lead to slower query efficiency. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a query data table generation method, a data query method, a device and an electronic device, which are used to generate a query data table corresponding to an original data table. When executing a data query, part of the query is transferred to the query data table for query, thereby reducing the access load to the database and improving data query efficiency.
[0005] In a first aspect, an embodiment of the present application provides a method for generating a query data table, the method comprising: obtaining historical query records according to a first preset time period; the historical query records include historical query statements and query attribute information of the historical query statements; the query attribute information is used to characterize the behavior information generated during the execution of the historical query statements; based on the query attribute information, the historical query statements are screened to obtain slow query statements; the slow query statements are used to characterize query statements whose execution time exceeds a first preset time threshold; and a query data table is generated based on the slow query statements and the data queried by the slow query statements.
[0006] The embodiment of the present application obtains slow query statements by using query attribute information to filter historical query statements, and generates a query data table based on the slow query statements and the data queried by the slow query statements, so that when executing data queries, part of the query is transferred to the query data table for query, thereby reducing the access load to the original database and improving data query efficiency.
[0007] In some embodiments, historical query statements are filtered based on query attribute information to obtain slow query statements, including: performing a first filtering of historical query statements based on the execution time in the query attribute information to obtain a first slow query statement; performing a second filtering of the first slow query statement using the query object in the query attribute information to obtain a slow query statement; the query object includes at least one of a queried data table, a queried field, and a filter condition.
[0008] The embodiment of the present application greatly reduces the number of slow query statements through two screenings, so that the corresponding query data table is generated based on only a small number of query statements. This not only reduces the access pressure on the original database, but also improves the data query efficiency.
[0009] In some embodiments, a first screening is performed on historical query statements based on the execution time in the query attribute information to obtain a first slow query statement, including: taking historical query statements whose execution time is greater than a second preset time threshold as the first slow query statement; the second preset time threshold is not less than the first preset time threshold.
[0010] The embodiment of the present application reduces the number of query data tables generated by filtering historical query statements using execution time, thereby eliminating the need to allocate a large amount of additional storage resources to store the query data tables and reducing the impact on service storage resources.
[0011] In some embodiments, a first screening is performed on historical query statements based on the execution time in the query attribute information to obtain a first slow query statement, including: inserting the historical query statements into the queue in order of execution time from low to high, and taking the historical query statement whose queue position is greater than the preset queue position as the first slow query statement.
[0012] The embodiment of the present application reduces the number of query data tables generated by filtering historical query statements using execution time.
[0013] In some embodiments, the first slow query statement is screened for the second time using the query object in the query attribute information to obtain a slow query statement, including: if the first slow query statement contains: a first target slow query statement in which the number of queried fields is less than a preset number of fields, then the first target slow query statement is used as the slow query statement; and / or if the first slow query statement contains: a second target slow query statement in which the number of data items stored in the queried data table is greater than a preset number of data items, then the second target slow query statement is used as the slow query statement; and / or if the first slow query statement contains: a third target slow query statement including a preset filtering condition, then the third target slow query statement is used as the slow query statement.
[0014] The embodiment of the present application further screens the first slow query statements, so that corresponding query data tables are generated based on only a small number of query statements, which not only reduces the access pressure on the original database, but also improves data query efficiency and service resource utilization.
[0015] In some embodiments, the slow query statement includes a historical data table name and a historical field name for the query; a query data table is generated based on the slow query statement and the data queried by the slow query statement, including: obtaining field information of the corresponding data table based on the historical data table name, and generating a first query data table name based on the historical data table name; using the historical field name to filter the field information to obtain target field information corresponding to the historical field name; creating an initial query data table based on the first query data table name and the target field information; and writing the data queried by the slow query statement into the initial query data table to generate a query data table.
[0016] The embodiment of the present application generates a query data table by generating the historical data table name and historical field name based on the slow query statement query, so that the data volume of the query data table is smaller than the corresponding original data table. If there is a corresponding query data table for a certain query original data table, the query data table can be directly queried, thereby improving data query efficiency.
[0017] In some embodiments, after generating a query data table based on a slow query statement and the data queried by the slow query statement, the method also includes: receiving an update statement; the update statement includes an update data table name and update data; using the update statement to write the update data into the original data table corresponding to the update data table name; querying a pre-generated first data relationship mapping table based on the update data table name to obtain a second query data table name corresponding to the update data table name; the first data relationship mapping table is used to characterize the update mapping relationship between the original data table and the query data table; determining a field name of the data to be written based on the second query data table name, and modifying the update statement based on the second query data table name and the field name of the data to be written to generate a new update statement; and writing the update data into the query data table corresponding to the second query data table name based on the new update statement.
[0018] The embodiment of the present application improves the accuracy of data query by synchronously updating the original data table and the query data table.
[0019] In some embodiments, the query data table includes a query range; the method further includes: deleting data in the query data table corresponding to the second query data table name that does not conform to the query range according to a second preset time period.
[0020] The embodiment of the present application deletes the data in the query data table that does not meet the query range, so that the data volume of the query data table is kept in a smaller range, thereby improving the efficiency of data query.
[0021] In some embodiments, after generating a query data table based on a slow query statement and the data queried by the slow query statement, the method further includes: obtaining a pre-generated copy statement according to a third preset time period, the copy statement including the name of the original data table where the data to be copied is located and the name of the target query data table to be stored; executing the copy statement to copy the data to be copied from the original data table corresponding to the original data table name to the query data table corresponding to the target query data table name.
[0022] The embodiment of the present application lays a foundation for the accuracy of data query by regularly copying the data in the original data table to the query data table.
[0023] In a second aspect, an embodiment of the present application provides a data query method, the method comprising: receiving a data query request; the data query request comprises a query statement; the query statement comprises a first data table name, a field name and a query condition for query; a query feature of the query statement is generated according to the first data table name, the field name and the query condition; a pre-generated second data relationship mapping table is queried using the query feature; the second data relationship mapping table is used to characterize the query mapping relationship between the original data table and the query data table; the query data table is generated based on the method of the first aspect; the query data table comprises a second data table name; if a second data table name corresponding to the first data table name exists in the second data relationship mapping table, the data in the query data table corresponding to the second data table name is used as the query result.
[0024] In the embodiment of the present application, when there is a corresponding query data table in the original data table, the data query request is redirected to the query data table for query. Since the data volume of the query data table is small, the query efficiency is improved.
[0025] In some embodiments, after querying the pre-generated second data relationship mapping table using the query feature, the method further includes: if the second data relationship mapping table does not have a second data table name corresponding to the first data table name, querying the original data table corresponding to the first data table name through a query statement.
[0026] In the embodiment of the present application, data query requests that do not need to be redirected are directly queried in the original data layer in the database, thereby improving data query efficiency.
[0027] In a third aspect, an embodiment of the present application provides a query data table generating device, the device comprising: an acquisition module, used to acquire historical query records according to a first preset time period; the historical query records include historical query statements and query attribute information of the historical query statements; the query attribute information is used to characterize the behavior information generated during the execution of the historical query statements; a screening module, used to screen the historical query statements based on the query attribute information to obtain slow query statements; the slow query statements are used to characterize query statements whose execution time exceeds a first preset time threshold; a first generation module, used to generate a query data table based on the slow query statements and the data queried by the slow query statements.
[0028] In a fourth aspect, an embodiment of the present application provides a data query device, which includes: a receiving module for receiving a data query request; the data query request includes a query statement; the query statement includes a first data table name, a field name and a query condition to be queried; a second generating module for generating query features of the query statement according to the first data table name, the field name and the query condition; a first query module for using the query features to query a pre-generated second data relationship mapping table; the second data relationship mapping table is used to characterize the query mapping relationship between the original data table and the query data table; the query data table is generated based on the method of the first aspect; the query data table includes a second data table name; a second query module for using the data in the query data table corresponding to the second data table name as the query result if there is a second data table name corresponding to the first data table name in the second data relationship mapping table.
[0029] In a fifth aspect, an embodiment of the present application provides an electronic device, comprising: a processor, a memory, a storage medium and a bus, wherein the processor and the memory communicate with each other through the bus; the memory stores program instructions that can be executed by the processor, and the processor calls the program instructions to execute the method steps of the first and second aspects.
[0030] In a sixth aspect, an embodiment of the present application provides a non-transitory computer-readable storage medium, comprising: the computer-readable storage medium stores computer instructions, and the computer instructions enable the computer to execute the method steps of the first aspect and the second aspect.
[0031] In a seventh aspect, an embodiment of the present application provides a computer program product, including: a computer program, which executes the method steps of the first aspect and the second aspect when executed by a processor.
[0032] The beneficial effects of the present application are as follows: by using query attribute information to filter historical query statements to obtain slow query statements, and generating a query data table based on the slow query statements and the data queried by the slow query statements, when executing data queries, part of the query is transferred to the query data table for query, and since the amount of data in the generated query data table is less than the amount of data in the corresponding original data table, the query efficiency is improved. At the same time, the mutual influence between the queries is also reduced.
[0033] Other features and advantages of the present application will be described in the subsequent description, and in part will become apparent from the description, or will be understood by implementing the embodiments of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0035] Figure 1 A flowchart of a method for generating a query data table provided in an embodiment of the present application;
[0036] Figure 2 A flowchart of a data query method provided in an embodiment of the present application;
[0037] Figure 3 A schematic diagram of data layering provided in an embodiment of the present application;
[0038] Figure 4 A schematic diagram of the structure of a query data table generating device provided in an embodiment of the present application;
[0039] Figure 5 A schematic diagram of the structure of a data query device provided in an embodiment of the present application;
[0040] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0041] The following embodiments of the technical solution of the present application are described in detail in conjunction with the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solution of the present application, and are therefore only used as examples, and cannot be used to limit the scope of protection of the present application.
[0042] It should be noted that all technical and scientific terms used in this document have the same meanings as those generally understood by technicians in the technical field to which this application belongs; the terms used in this document are only for the purpose of describing specific embodiments and are not intended to limit this application; the terms "including" and "having" in the specification and claims of this application and the above-mentioned figure descriptions and any variations thereof are intended to cover non-exclusive inclusions.
[0043] In the description of the embodiments of the present application, the technical terms "first", "second", etc. are only used to distinguish different objects, and cannot be understood as indicating or implying relative importance or implicitly indicating the number, specific order or primary and secondary relationship of the indicated technical features. In the description of the embodiments of the present application, the meaning of "multiple" is more than two, unless otherwise clearly and specifically defined.
[0044] In the description of the embodiments of the present application, the term "and / or" is only a description of the association relationship of the associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0045] In various industries, companies will quantify the capabilities of their customers through various indicators to provide more accurate decisions and services. When calculating indicators, it is necessary to access the database to obtain the data used for indicator calculation. Generally speaking, the more complete the data sample and the larger the data volume, the more reference significance the calculated indicators have.
[0046] However, in a microservice cluster, multiple services often use one data set. Different indicators have different characteristics, which results in different impacts on the database when accessing the database to obtain data for indicator calculation.
[0047] In addition, the time for indicator calculation increases as the data set expands; some indicators will not have any problems when they are first created due to the small data set, but when the data volume increases, a series of problems such as long query data will arise; some indicators are affected after other indicators are created, and the calculation time increases sharply.
[0048] Also, as the size of the enterprise increases, in the early stages of system design, some core data is often written into one dataset (for example, writing data into ES). As the number of development teams increases, each development team will write data into the core dataset, which will cause the pressure on certain datasets to increase over time.
[0049] Therefore, in order to reduce the access pressure of certain data sets, reduce the access pressure of the database, and improve the query efficiency during indicator calculation, the embodiment of the present application provides a query data table generation method and a data query method to transfer the newly added data query pressure to the query data table, avoiding most of the pressure from being concentrated on one or two data sets in the database.
[0050] Figure 1 A flowchart of a method for generating a query data table provided in an embodiment of the present application is provided. The method can be applied to a terminal device (also referred to as an electronic device) and a server; the terminal device can specifically be a smart phone, a tablet computer, a computer, a personal digital assistant (PDA), etc.; the server can specifically be an application server or a Web server. To facilitate understanding of the technical solution provided in the embodiment of the present application, the application scenario of the method for generating a query data table provided in the embodiment of the present application is introduced below, taking the server as the execution subject as an example.
[0051] like Figure 1 As shown, the method includes:
[0052] Step S101, the server obtains historical query records according to a first preset time period; the historical query records include historical query statements and query attribute information of the historical query statements; the query attribute information is used to characterize the behavior information generated during the execution of the historical query statements.
[0053] Optionally, the server automatically triggers the process of generating the query data table according to the first preset time period. However, it should be known that the server may also trigger the process of generating the query data table after receiving a trigger instruction sent manually according to the first preset time period.
[0054] The first preset time period is a preset value. For example, the first preset time period is every one hour, every two hours, or every three hours, etc. It can be set according to actual conditions.
[0055] The historical query record refers to the log or record of the query executed by the server in the historical time from the moment when the process of generating the query data table is triggered. Exemplary, the query record executed within the historical hour from the moment when the process of generating the query data table is triggered. The historical query record includes the historical query statement and the query attribute information of the historical query statement.
[0056] Historical query statements refer to the query statements actually executed during the historical time period. It should be noted that the query statement is determined according to the type of database actually queried. For example, if the queried database is MySql or Oracle, the query statement is the SELECT statement in the SQL statement, such as: SELECT * FROMstudents. If the queried database is MongoDB, the query statement is find, such as: db.students.find().
[0057] Query attribute information is used to represent the behavior information generated during the execution of historical query statements. It includes the following:
[0058] (1) Query object: the data table to be queried, the field name to be queried, the filtering conditions, etc.;
[0059] (2) Execution time: the total time required for the query from start to finish;
[0060] (3) Execution time: the specific time point or time period when the query is executed;
[0061] (4) User information: the name of the user or application executing the query;
[0062] (5) Return results: the number of rows or result sets returned by the query;
[0063] (6) Execution plan: The execution strategy selected by the query optimizer, including which indexes to use, connection methods, etc.
[0064] (7) Resource usage: query the system resources consumed during execution, such as CPU time, memory usage, disk I / O, etc.
[0065] (8) Error message: If an error occurs during query execution, the corresponding error message will also be recorded.
[0066] Taking one-hour interval as an example, when obtaining historical query records, the server obtains the historical query records once every one-hour interval.
[0067] Step S102: the server screens historical query statements based on query attribute information to obtain slow query statements; slow query statements are used to represent query statements whose execution time exceeds a first preset time threshold.
[0068] Optionally, although creating a query data table can reduce the access pressure of the original database, if corresponding query data tables are created for most of the original data tables in the database, it will not only occupy a large amount of additional resources of the service, but also transfer the access pressure from the original data table to the query data table. This process only transfers the access pressure, but when querying the query data table, the query efficiency is also low, and it does not solve the problem of query efficiency.
[0069] Therefore, the server needs to filter the historical query statements and generate the corresponding query data table based on the filtered historical query statements. Data tables with slower query speeds are usually considered to need to generate corresponding query data tables to reduce the access pressure on the original data tables and improve query efficiency.
[0070] For example, the server filters historical query statements based on query attribute information to obtain slow query statements.
[0071] The specific execution status of each historical query statement can be understood by querying the attribute information. Therefore, the historical query statements can be screened using the query attribute information to obtain the target query statement. The target query statement can be a slow query statement or a query statement that obtains the target result. In the embodiment of the present application, the target query statement is a slow query statement.
[0072] The slow query statement is used to characterize a query statement whose execution time exceeds a first preset time threshold. The first preset time threshold is a pre-set value, which may be 3 seconds, 4 seconds, or 5 seconds, etc. For example, a query statement whose execution time exceeds 3 seconds is defined as a slow query statement.
[0073] It should be noted that although the execution time can directly evaluate the query speed of a query statement, the slow query speed is caused by many factors, such as too much data in the queried data table, limited service resources during the query process, unreasonable execution plan, or complex query logic.
[0074] Therefore, the server filters historical query statements based on the query attribute information, and when obtaining slow query statements, in addition to considering the execution time, other contents in the query attribute information may also be considered.
[0075] For example, the server may filter historical query statements based on execution time to obtain slow query statements.
[0076] The server can also filter historical query statements based on execution time and query objects to obtain slow query statements.
[0077] The server can also filter historical query statements based on the execution time and resource usage of the service during the execution time to obtain slow query statements.
[0078] The specific method of screening can be set according to the actual situation.
[0079] Step S103: The server generates a query data table according to the slow query statement and the data queried by the slow query statement.
[0080] Optionally, after filtering out the slow query statements, the server can generate a query data table based on the slow query statements and the data queried by the slow query statements.
[0081] It should be noted that historical query statements usually query some fields or some data in the original data table. Therefore, the amount of data in the query data table generated based on the slow query statement and the data queried by the slow query statement is smaller than the amount of data in the corresponding original data table. Due to the reduction in data volume, the query speed is improved.
[0082] The embodiment of the present application obtains slow query statements by using query attribute information to filter historical query statements, and generates a query data table based on the slow query statements and the data queried by the slow query statements, so that when executing data queries, part of the query is transferred to the query data table for query, thereby reducing the access load to the original database and improving data query efficiency.
[0083] In some embodiments, the server filters historical query statements based on query attribute information to obtain slow query statements, including: the server performs a first screening of historical query statements based on the execution time in the query attribute information to obtain a first slow query statement; the server uses the query object in the query attribute information to perform a second screening of the first slow query statement to obtain a slow query statement; the query object includes at least one of a queried data table, a queried field, and a filtering condition.
[0084] Optionally, in the process of filtering historical query statements based on query attribute information, since the purpose of filtering is to obtain slow query statements, and the execution time can directly reflect the query speed of the historical query statements, the server first performs a first filtering of historical query statements based on the execution time in the query attribute information to obtain the first slow query statement. Some historical query statements are filtered out by the execution time, so that the number of query data tables generated in the end is less than the number of original data tables in the original database.
[0085] Furthermore, based on the above content, it can be known that since the slow query speed may be caused by many reasons, if the historical query statements are filtered only based on the execution time, the number of the first slow query statements filtered out may still be relatively large.
[0086] Therefore, the first slow query statement needs to be further screened. For example, the server uses the query object in the query attribute information to perform a second screening on the first slow query statement to obtain a slow query statement.
[0087] Through two rounds of screening, the number of slow query statements is greatly reduced, so that the corresponding query data table is generated based on only a small number of query statements. This not only reduces the access pressure on the original database, but also improves data query efficiency.
[0088] In some embodiments, the server performs a first screening of historical query statements based on the execution time in the query attribute information to obtain a first slow query statement, including: the server uses historical query statements whose execution time is greater than a second preset time threshold as the first slow query statement; the second preset time threshold is not less than the first preset time threshold.
[0089] Optionally, the second preset time threshold is a pre-set value. Since the first preset time threshold is only used as a measure of whether a query statement is a slow query statement, and the second preset time threshold is used to filter historical query statements, in the actual execution process, the second preset time threshold is not less than the first preset time threshold.
[0090] Exemplarily, if the first duration threshold is 3 seconds, the server uses the historical query statement with an execution time greater than 4 seconds as the first slow query statement.
[0091] The embodiment of the present application reduces the number of query data tables generated by filtering historical query statements using execution time.
[0092] In some embodiments, the server performs a first screening of historical query statements based on the execution time in the query attribute information to obtain a first slow query statement, including: the server inserts the historical query statements into the queue in order of execution time from low to high, and takes the historical query statement whose queue position is greater than the preset queue position as the first slow query statement.
[0093] Optionally, since the historical query records are obtained according to the first preset time period, the number of historical query statements obtained in each period is different.
[0094] Therefore, in addition to using a pre-set fixed value as the criterion for judging whether a historical query statement is the first slow query statement, the historical query statements obtained within the period can also be sorted in ascending order according to the execution time, and inserted into the queue in sequence, and the historical query statement whose queue position is greater than the preset queue position is taken as the first slow query statement.
[0095] It should be noted that the preset queue position is related to the number of historical query statements obtained in the current period, that is, the preset queue position changes dynamically with the number of historical query statements obtained in different periods.
[0096] For example, if the number of historical query statements acquired in the cycle is 100, they are inserted into the queue in order from low to high execution time, and the last 20 historical query statements are used as the first slow query statements.
[0097] If the number of historical query statements obtained in the cycle is 80, they are inserted into the queue in order from low to high execution time, and the last 16 historical query statements are taken as the first slow query statements.
[0098] The embodiment of the present application reduces the number of query data tables generated by filtering historical query statements using execution time.
[0099] In some embodiments, the server uses the query object in the query attribute information to perform a second screening on the first slow query statement to obtain a slow query statement, including: if the first slow query statement contains: a first target slow query statement in which the number of queried fields is less than a preset number of fields, then the first target slow query statement is used as the slow query statement; and / or if the first slow query statement contains: a second target slow query statement in which the number of data items stored in the queried data table is greater than a preset number of data items, then the second target slow query statement is used as the slow query statement; and / or if the first slow query statement contains: a third target slow query statement including a preset filtering condition, then the third target slow query statement is used as the slow query statement.
[0100] Optionally, the developer maintains the filtering rules in advance, so as to perform a second filtering on the first slow query statement through the filtering rules to obtain the slow query statement. The process of the server performing a second filtering on the first slow query statement using the query object in the query attribute information is actually a process of matching the query object in the first slow query statement with the filtering rules.
[0101] Exemplary, the screening rules are:
[0102] (1) Get the data table and fields queried by the first slow query statement. The number of queried fields is less than 70% of the total number of fields in the queried data table. For example, if the queried data table has 100 fields, but the number of queried fields is only 15, then the first slow query statement only queries 15% of the fields in the data table, which is less than 70%, that is, less than 70. 70% can also be set to other values.
[0103] That is, if there is a first target slow query statement in the first slow query statement whose number of queried fields is less than the preset number of fields, the first target slow query statement is used as the slow query statement.
[0104] It should be noted that the purpose of generating a query data table is to improve query efficiency. If the data volume of the generated query data table is not much different from the data volume of the corresponding original data table, the effect of improving query efficiency will not be significant. Therefore, if the number of fields to be queried is too large, the original data table can be queried directly, and there is no need to generate a query data table that is not much different from the original data table.
[0105] (2) The number of data items in the data table queried by the first slow query statement is obtained, and the number of data items is greater than 500,000. 500,000 can also be set to other values. Since the more data items a data table has, the more time it takes to query. Therefore, it is necessary to generate a corresponding query data table for such data tables to improve query efficiency.
[0106] That is, if there is a second target slow query statement in the first slow query statement whose number of data entries stored in the queried data table is greater than the preset number, the second target slow query statement is used as the slow query statement.
[0107] (3) Whether the first slow query statement contains filtering conditions such as grouping conditions or sorting conditions. It should be noted that the filtering conditions may also include logical operators, fuzzy matching, range search, comparison operators, etc.
[0108] Since the query target of the first slow query statement with filtering conditions is partial data of certain fields in the data table, for example, a data table includes the wages of employees aged 20-60, but the first slow query statement only queries the wages of employees aged 30-50. At this time, a corresponding query data table is generated for such data table. The next time the wages of employees aged 30-50 are queried, the query data table can be directly queried, thereby improving query efficiency.
[0109] That is, if there is a third target slow query statement including a preset filtering condition in the first slow query statement, the third target slow query statement is used as the slow query statement.
[0110] It should be noted that the above screening rules can be used alone or in combination, or at the same time.
[0111] When used simultaneously, the number of slow query statements can be minimized. The data table in the first slow query statement that meets all the screening rules can be considered as the core data table. At this time, in order to reduce the access pressure of the core data table, a corresponding query data table can be generated to improve data query efficiency.
[0112] The embodiment of the present application further screens the first slow query statements, so that corresponding query data tables are generated based on only a small number of query statements, which not only reduces the access pressure on the original database, but also improves the data query efficiency.
[0113] In some embodiments, the slow query statement includes a historical data table name and a historical field name for the query; the server generates a query data table based on the slow query statement and the data queried by the slow query statement, including: the server obtains field information of the corresponding data table based on the historical data table name, and generates a first query data table name based on the historical data table name; the server uses the historical field name to filter the field information to obtain target field information corresponding to the historical field name; the server creates an initial query data table based on the first query data table name and the target field information; the server writes the data queried by the slow query statement into the initial query data table to generate a query data table.
[0114] Optionally, after filtering out the slow query statements, the server can generate a query data table based on the slow query statements and the data queried by the slow query statements.
[0115] For example, the server parses the slow query statement, obtains the historical data table name and historical field name queried by the slow query statement, and stores the parsed historical data table name and historical field name in the data structure mapping table TableMap <String,Set <string>>, where the historical data table name is used as the key of TableMap, and TableMap <String,Set <string>> corresponds to the first String in the table, the historical field name is used as the value of TableMap, and TableMap <String,Set <string>> corresponds to the second String.
[0116] It should be noted that in actual query, it is possible to query multiple fields in the data table, so the storage structure of the historical field name is a set Set. In addition, it is also possible to query multiple data tables, so the specific form of TableMap can be as follows:
[0117] {
[0118] tb_a1:[f1,f2,f3],
[0119] tb_a2:[f4,f5,f6],
[0120] tb_a3:[s1,s2,s9]
[0121] }
[0122] Among them, tb_a1, tb_a2 and tb_a3 are data table names, [f1,f2,f3], [f4,f5,f6] and [s1,s2,s9] are field name sets.
[0123] Generating a data table usually involves the following steps:
[0124] (1) Design the table structure: determine the fields (columns) required for the data table and the data type and properties of each field. This includes considering the field name, data type (such as integer, text, date, etc.), whether it is allowed to be empty, default value, etc.
[0125] (2) Define constraints: Implement data integrity constraints, including entity integrity (ensuring the uniqueness of each row of data, usually achieved through a primary key), referential integrity (ensuring the correctness of foreign keys, that is, a foreign key in one table must be a valid value for the primary key of another table), and domain integrity (ensuring that the data in a specific column meets specific rules or restrictions).
[0126] (3) Create a data table: For example, use the CREATE TABLE SQL statement to create a data table. This statement will contain the table structure information designed previously, including field names, data types, constraints, etc.
[0127] (4) Inserting data: After the data table is created, for example, you can insert data into the table using the INSERT INTO statement, thereby starting to use the data table for data storage and query operations.
[0128] Since the historical data table is a data table that has been created, after parsing and obtaining the historical data table, the server can query by the historical data table name to obtain field information of each field in the historical data table.
[0129] For example, for a MySql database, you can get the field information of a data table from the INFORMATION_SCHEMA.COLUMNS view, which contains the field information of all tables in the database. You can query this view with a SELECT statement to get the field information of a specified data table. For example,
[0130] SELECT
[0131] COLUMN_NAME,
[0132] ORDINAL_POSITION,
[0133] DATA_TYPE,
[0134] CHARACTER_MAXIMUM_LENGTH,
[0135] NUMERIC_PRECISION,
[0136] NUMERIC_SCALE,
[0137] IS_NULLABLE,
[0138] COLUMN_DEFAULT,
[0139] COLUMN_KEY
[0140] FROM
[0141] INFORMATION_SCHEMA.COLUMNS
[0142] WHERE
[0143] TABLE_NAME = 'employees_table';
[0144] Among them, "employees_table": the name of the historical data table;
[0145] COLUMN_NAME: column name;
[0146] ORDINAL_POSITION: The position of the column in the data table (starting from 1);
[0147] DATA_TYPE: data type of the column (such as INT, VARCHAR, DECIMAL, etc.);
[0148] CHARACTER_MAXIMUM_LENGTH: For a column of string type, it indicates the maximum number of characters;
[0149] NUMERIC_PRECISION: For numeric columns, it indicates the maximum number of digits;
[0150] NUMERIC_SCALE: For numeric columns, it indicates the number of digits after the decimal point;
[0151] IS_NULLABLE: Indicates whether the column allows nulls (YES means allowed, NO means not allowed);
[0152] COLUMN_DEFAULT: The default value of the column (if any);
[0153] COLUMN_KEY: Indicates the index type of the column in the data table (such as PRIMARY for primary key, UNIQUE for unique key, MUL for index, etc.).
[0154] The server generates a first query data table name according to the historical data table name, and stores the first query data table name and the historical field name in TableMap accordingly.
[0155] For example, the first query data table name is generated by adding a suffix to the historical data table name. For example, if the historical data table name is table_name, then the first query data table name is table_name_query.
[0156] It should be noted that due to different businesses, queries of different scopes can be executed on the same table, and these query statements of different scopes may all be slow query statements. In order to reduce the mutual influence of various query statements during the query process, a corresponding query data table is generated for each slow query statement. Therefore, when the first query data table name is generated according to the historical data table name, there is a situation where the same name exists.
[0157] In order to avoid this situation, each time the first query data table name is generated, TableMap is queried to determine whether the first query data table name exists. If it exists, the value 01 is added to the first query data table name. If it still exists, the value is automatically increased by 1, and so on until the newly generated first query data table name does not exist.
[0158] For example, the name of the first query data table generated is table_name_query. After querying TableMap, if the table name exists, table_name_query is changed to table_name_query01. If it still exists, table_name_query is changed to table_name_query02.
[0159] Based on the above steps of generating a data table, it can be known that after the first query data table name is generated and the server uses the historical field name to filter the queried field information and obtains the target field information corresponding to the historical field name, an initial query data table can be created based on the first query data table name and the target field information. Finally, the data queried by the slow query statement is written into the initial query data table to generate a query data table.
[0160] For example: Generate a query data table named student, which contains three columns: id, name, and addr_name.
[0161] CREATE TABLE student (
[0162] id INT PRIMARY KEY,
[0163] name VARCHAR(50) NOT NULL,
[0164] addr_name VARCHAR(50) NOT NULL, ) ;
[0166] Since there may be multiple query data tables, in the application embodiment, the layer where the query data table is located is called the query data layer.
[0167] The embodiment of the present application generates a query data table by generating the historical data table name and historical field name based on the slow query statement query, so that the data volume of the query data table is smaller than the corresponding original data table. If there is a corresponding query data table for a certain query original data table, the query data table can be directly queried, thereby improving data query efficiency.
[0168] In some embodiments, after the server generates a query data table based on the slow query statement and the data queried by the slow query statement, the method also includes: the server receives an update statement; the update statement includes an update data table name and update data; the server uses the update statement to write the update data into the original data table corresponding to the update data table name; the server queries a pre-generated first data relationship mapping table based on the update data table name to obtain a second query data table name corresponding to the update data table name; the first data relationship mapping table is used to characterize the update mapping relationship between the original data table and the query data table; the server determines the field name of the data to be written based on the second query data table name, and modifies the update statement based on the second query data table name and the field name of the data to be written to generate a new update statement; the server writes the update data into the query data table corresponding to the second query data table name based on the new update statement.
[0169] Optionally, operations on a data table generally include adding, deleting, modifying, and querying. After a query data table is generated, in order to ensure the accuracy of data query, in addition to querying, adding, deleting, and modifying the query data table are also involved.
[0170] To facilitate data update of the original data table and the query data table, after the query data table is generated, the corresponding relationship between the query data table and the original data table is stored in the first data relationship mapping table. The table name of the original data table is the key of the first data relationship mapping table, and the table name of the query data table is the value of the first data relationship mapping table. When updating, the corresponding query data table can be queried through the original data table.
[0171] For example, after receiving the update statement, the server uses the update statement to write the update data into the original data table corresponding to the updated data table name.
[0172] In order to know which query data tables need to be updated synchronously, the server needs to query the pre-generated first data relationship mapping table based on the updated data table name to obtain the second query data table name corresponding to the updated data table name; the first data relationship mapping table is used to represent the update mapping relationship between the original data table and the query data table.
[0173] Since the number of fields in the query data table is less than the number of fields in the corresponding original data table, the update statement needs to be rewritten to correctly write the updated data into the query data table.
[0174] For example, the server determines the field name of the data to be written based on the second query data table name, and modifies the update statement based on the second query data table name and the field name of the data to be written to generate a new update statement; the server writes the updated data into the query data table corresponding to the second query data table name based on the new update statement.
[0175] The embodiment of the present application improves the accuracy of data query by synchronously updating the original data table and the query data table.
[0176] In some embodiments, the query data table includes a query range; the method further includes: the server deletes data that does not conform to the query range in the query data table corresponding to the second query data table name according to a second preset time period.
[0177] Optionally, the data range of some query data tables is a subset of the corresponding original data table. For example, the data range of the original data table is the salary of employees aged 20-60, while the data range of the query data table is the salary of employees aged 30-50.
[0178] When using the update statement to update, only the data table name and field name in the update statement are modified, and the data range is not modified. Therefore, after the update is executed, there will be redundant data in the query data table that does not meet the query range.
[0179] Therefore, the data in the query data table corresponding to the second query data table name that does not meet the query range will be deleted according to the second preset time period. For example, the employee salary data of [20, 30) and (50, 60) in the query data table corresponding to the second query data table name will be deleted.
[0180] The second preset time period is a preset value, and the deletion operation can be performed immediately after the data is updated, or can be performed every 30 minutes. The second preset time period can be the same as the first preset time period, or can be different.
[0181] The embodiment of the present application deletes the data in the query data table that does not meet the query range, so that the data volume of the query data table is kept in a smaller range, thereby improving the efficiency of data query.
[0182] In some embodiments, after the server generates a query data table based on the slow query statement and the data queried by the slow query statement, the method also includes: the server obtains a pre-generated copy statement according to a third preset time period, the copy statement including the original data table name where the data to be copied is located and the target query data table name to be stored; executes the copy statement to copy the data to be copied from the original data table corresponding to the original data table name to the query data table corresponding to the target query data table name.
[0183] Optionally, in addition to synchronously updating the original data table and the query data table, the updated data may be first written into the original data table, and then the data written into the original data table may be copied into the query data table according to a third preset time period.
[0184] Since the table structures of the original data table and the query data table are fixed, to facilitate the execution of this method, the maintenance personnel pre-build the copy statement for storage and set the trigger time to periodically run the copy statement through the trigger time to achieve data update of the query data table.
[0185] It should be noted that the third preset time period is a preset value, which can be set to trigger execution once every 30 minutes or once every 10 minutes. The third preset time period, the first preset time period, and the second preset time period can be the same or different.
[0186] The embodiment of the present application lays a foundation for the accuracy of data query by regularly copying the data in the original data table to the query data table.
[0187] Figure 2 A flow chart of a data query method provided in an embodiment of the present application, which can be applied to a terminal device (also referred to as an electronic device) and a server; the terminal device can specifically be a smart phone, a tablet computer, a computer, a personal digital assistant (PDA), etc.; the server can specifically be an application server or a Web server. To facilitate understanding of the technical solution provided in the embodiment of the present application, the application scenario of the data query method provided in the embodiment of the present application is introduced below, taking the server as the execution subject as an example.
[0188] like Figure 2 As shown, the method includes:
[0189] Step S201, the server receives a data query request; the data query request includes a query statement; the query statement includes the name of the first data table to be queried, the name of the field and the query condition.
[0190] Optionally, from a business perspective, it is not clear for which data tables the query data tables are created, so the operation statements initiated by the business layer still operate on the original data tables in the database.
[0191] After the query data table is generated based on the method of the above embodiment, the server needs to determine whether to redirect the received data query request to the query data layer to query the query data table, thereby improving the query efficiency.
[0192] Because one original data table can correspond to multiple query data tables. When updating, you can query all the corresponding query data tables through the original data table name and update them. But when querying data, it is not clear which query data table of the original data table to query. Therefore, it is necessary to generate features for each slow query statement to uniquely determine the query data table for query through the features and the original data table name.
[0193] However, it should be noted that a slow query statement can query multiple tables. Therefore, in the slow query statement, each original data table name corresponds to a query data table name.
[0194] An example of the second data relationship mapping table is as follows:
[0195] {
[0196] "E4B88E5C9A146919E6199B2D3E151634":{
[0197] "isEnable":false,
[0198] "Original data table name 1":"Query data table name 1",
[0199] "Original data table name 2":"Query data table name 2",
[0200] "Original data table name 3":"Query data table name 3",
[0201] }
[0202] }
[0203] Among them, "E4B88E5C9A146919E6199B2D3E151634" indicates the feature, "isEnable" indicates whether it is enabled (optional field), and "false" indicates that it is not enabled.
[0204] Since one original data table may correspond to multiple query data tables, the difference is that the data range of each query data table is different. Therefore, in order to improve the accuracy and uniqueness of the query data table queried, the embodiment of the present application generates query features based on the data table name, field name and query condition of the slow query statement.
[0205] For example, the data table name, field name, and query condition of the slow query statement are concatenated to obtain a string, and the string is hashed to obtain the query feature.
[0206] It should be noted that if the slow query statement queries multiple tables, it is necessary to concatenate each data table name, field name and query condition to generate features.
[0207] For example, sqlHash = Hash (tempStr), where tempStr = tableName1 +
[0208] field11+field12+field13+tableName2+field21+field22+field23+tableName3+field31+field32+field33.
[0209] After receiving the data query request, the server parses the data query request to obtain specific contents such as the source system, source IP, query statement, etc. of the data query request, wherein the query statement includes the name of the first data table to be queried, the name of the field, and the query condition.
[0210] It should be noted that the maintenance personnel can conduct a specific analysis of the request initiator based on the source system and source IP of the query to optimize the query process.
[0211] Step S202: The server generates query features of a query statement according to the first data table name, field name and query condition.
[0212] Step S203, the server uses the query feature to query the pre-generated second data relationship mapping table; the second data relationship mapping table is used to characterize the query mapping relationship between the original data table and the query data table; the query data table is generated based on the method of the above embodiment; the query data table includes the second data table name.
[0213] Optionally, the server generates a query feature of the query statement according to the first data table name, field name and query condition, so as to query the second data relationship mapping table through the query feature to determine whether there is a query data table corresponding to the first data table name.
[0214] Step S204: If there is a second data table name corresponding to the first data table name in the second data relationship mapping table, the server uses the data in the query data table corresponding to the second data table name as the query result.
[0215] Optionally, if there is a second data table name corresponding to the first data table name in the second data relationship mapping table, indicating that there is a corresponding query data table, the data query request can be redirected to the query data layer to query the query data table, thereby improving query efficiency.
[0216] It should be noted that since the query statement in the data query request is a query on the original data table, the query statement needs to be modified in order to correctly query the query data table.
[0217] For example, the first data table name in the query statement is replaced with the second data table name, so as to perform data query on the query data table corresponding to the second data table name through the changed query statement to obtain the query result.
[0218] Exemplary:
[0219] The original query statement is: SELECT AVG(salary) as average_salary FROM employeesWHERE age BETWEEN 20 AND 50.
[0220] The changed query statement is: SELECT AVG(salary) as average_salary FROMemployees_t_query WHERE age BETWEEN 20 AND 50.
[0221] Furthermore, when the service resources are sufficient, or the query demand is small, or the query data table has not been successfully generated, the original data table of the database can be directly operated. Therefore, a state information can be set for the second data relationship mapping table, and only when the state of the second data relationship mapping table is enabled, it will be determined whether to redirect the data query request to the query data layer for data query.
[0222] In the embodiment of the present application, when there is a corresponding query data table in the original data table, the data query request is redirected to the query data table for query. Since the data volume of the query data table is small, the query efficiency is improved.
[0223] In some embodiments, after the server uses the query feature to query the pre-generated second data relationship mapping table, the method also includes: if the second data relationship mapping table does not have a second data table name corresponding to the first data table name, the server queries the original data table corresponding to the first data table name through a query statement.
[0224] Optionally, since not all original data tables have corresponding query data tables, if the second data relationship mapping table does not have a second data table name corresponding to the first data table name, the server queries the original data table corresponding to the first data table name through a query statement.
[0225] In the embodiment of the present application, data query requests that do not need to be redirected are directly queried in the original data layer in the database, thereby improving data query efficiency.
[0226] Figure 3 A schematic diagram of data layering provided in an embodiment of the present application, such as Figure 3 As shown, the data layer includes a business layer, a query data layer and an original data layer.
[0227] The business layer is used to initiate business requests, including various services, such as anti-fraud services, pre-loan services, loan services, post-loan services, basic services, etc. The query data table is used to store various data query tables and receive redirected data query requests. The original data layer is used to store various original data tables. The original data layer can be MySql, ES or Oracle, etc.
[0228] Figure 4 A schematic diagram of a query data table generation device provided in an embodiment of the present application is shown in FIG. Figure 4 As shown, the device includes: an acquisition module 401, a screening module 402 and a first generation module 403; wherein,
[0229] An acquisition module 401 is used to acquire historical query records according to a first preset time period; the historical query records include historical query statements and query attribute information of the historical query statements; the query attribute information is used to characterize the behavior information generated during the execution of the historical query statements; a screening module 402 is used to screen the historical query statements based on the query attribute information to obtain slow query statements; the slow query statements are used to characterize query statements whose execution time exceeds a first preset time threshold; a first generation module 403 is used to generate a query data table based on the slow query statements and the data queried by the slow query statements.
[0230] Based on the above embodiment, the screening module 402 is specifically used for: performing a first screening of historical query statements based on the execution time in the query attribute information to obtain a first slow query statement; performing a second screening of the first slow query statement using the query object in the query attribute information to obtain a slow query statement; the query object includes at least one of the queried data table, the queried field and the filtering condition.
[0231] Based on the above embodiment, the screening module 402 is specifically used to: use the historical query statement whose execution time is greater than the second preset time threshold as the first slow query statement; the second preset time threshold is not less than the first preset time threshold.
[0232] Based on the above embodiment, the screening module 402 is specifically used to: insert historical query statements into the queue in order of execution time from low to high, and use the historical query statement whose queue position is greater than the preset queue position as the first slow query statement.
[0233] On the basis of the above embodiment, the screening module 402 is specifically used for: if the first slow query statement contains: a first target slow query statement in which the number of queried fields is less than a preset number of fields, the first target slow query statement is used as the slow query statement; and / or if the first slow query statement contains: a second target slow query statement in which the number of data items stored in the queried data table is greater than a preset number of data items, the second target slow query statement is used as the slow query statement; and / or if the first slow query statement contains: a third target slow query statement including a preset filtering condition, the third target slow query statement is used as the slow query statement.
[0234] Based on the above embodiment, the slow query statement includes the historical data table name and historical field name of the query; the first generation module 303: obtains the field information of the corresponding data table based on the historical data table name, and generates the first query data table name according to the historical data table name; uses the historical field name to filter the field information to obtain the target field information corresponding to the historical field name; creates an initial query data table according to the first query data table name and the target field information; writes the data queried by the slow query statement into the initial query data table to generate a query data table.
[0235] Based on the above embodiment, the device also includes a first update module, which is used to: receive an update statement; the update statement includes an update data table name and update data; use the update statement to write the update data into the original data table corresponding to the update data table name; query the pre-generated first data relationship mapping table based on the update data table name to obtain the second query data table name corresponding to the update data table name; the first data relationship mapping table is used to characterize the update mapping relationship between the original data table and the query data table; determine the field name of the data to be written according to the second query data table name, and modify the update statement according to the second query data table name and the field name of the data to be written to generate a new update statement; write the update data into the query data table corresponding to the second query data table name based on the new update statement.
[0236] Based on the above embodiment, the query data table includes a query range; the device also includes a deletion module for deleting data that does not conform to the query range in the query data table corresponding to the second query data table name according to a second preset time period.
[0237] Based on the above embodiment, the device also includes a second update module, which is used to: obtain a pre-generated copy statement according to a third preset time period, the copy statement including the name of the original data table where the data to be copied is located and the name of the target query data table to be stored; execute the copy statement to copy the data to be copied from the original data table corresponding to the original data table name to the query data table corresponding to the target query data table name.
[0238] It should be understood that the device corresponds to the above-mentioned query data table generation method embodiment and can execute the various steps involved in the above-mentioned method embodiment. The specific functions of the device can be found in the above description. To avoid repetition, the detailed description is appropriately omitted here. The device includes at least one software function module that can be stored in a memory in the form of software or firmware or solidified in the operating system (OS) of the device.
[0239] Figure 5 A schematic diagram of a data query device provided in an embodiment of the present application is shown in FIG. Figure 5 As shown, the device includes: a receiving module 501, a second generating module 502, a first query module 503 and a second query module 504; wherein,
[0240] A receiving module 501 is used to receive a data query request; the data query request includes a query statement; the query statement includes a first data table name, a field name and a query condition to be queried; a second generating module 502 is used to generate a query feature of the query statement according to the first data table name, the field name and the query condition; a first query module 503 is used to query a pre-generated second data relationship mapping table using the query feature; the second data relationship mapping table is used to characterize the query mapping relationship between the original data table and the query data table; the query data table is generated based on the method of the first aspect; the query data table includes a second data table name; a second query module 504 is used to use the data in the query data table corresponding to the second data table name as the query result if there is a second data table name corresponding to the first data table name in the second data relationship mapping table.
[0241] Based on the above embodiment, the device further includes a third query module, which is used to: if the second data relationship mapping table does not have a second data table name corresponding to the first data table name, query the original data table corresponding to the first data table name through a query statement.
[0242] It should be understood that the device corresponds to the above-mentioned data query method embodiment and can execute the various steps involved in the above-mentioned method embodiment. The specific functions of the device can be found in the above description. To avoid repetition, the detailed description is appropriately omitted here. The device includes at least one software function module that can be stored in a memory in the form of software or firmware or solidified in the operating system (OS) of the device.
[0243] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application, such as Figure 6 As shown, the electronic device includes a processor 601 (processor), a memory 602 (memory) and a bus 603; wherein the processor 601 and the memory 602 communicate with each other through the bus 603. The processor 601 is used to call the program instructions in the memory 602 to execute the methods provided by the above-mentioned method embodiments.
[0244] The processor 601 may be an integrated circuit chip with signal processing capability. The processor 601 may be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), an off-the-shelf programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. It may implement or execute various methods, steps and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0245] The memory 602 may include, but is not limited to, random access memory (RAM), read only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc.
[0246] This embodiment discloses a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the methods provided by the above-mentioned method embodiments.
[0247] This embodiment provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions enable the computer to execute the methods provided by the above-mentioned method embodiments.
[0248] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some communication interfaces, and the indirect coupling or communication connection of the devices or units can be electrical, mechanical or other forms.
[0249] In addition, the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0250] Furthermore, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0251] The above description is only an embodiment of the present application and is not intended to limit the protection scope of the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.< / string> < / string> < / string>
Claims
1. A method for generating a query data table, characterized in that: The method comprises: Acquire historical query records according to a first preset time period; the historical query records include historical query statements and query attribute information of the historical query statements; the query attribute information is used to characterize behavior information generated during the execution of the historical query statements; The historical query statements are screened based on the query attribute information to obtain slow query statements; the slow query statements are used to represent query statements whose execution time exceeds a first preset time threshold; Generate a query data table according to the slow query statement and the data queried by the slow query statement; the number of fields in the query data table is less than the number of fields in the corresponding original data table; the data range of the query data table is a subset of the corresponding original data table; The filtering of the historical query statements based on the query attribute information to obtain the slow query statements includes: Performing a first screening of the historical query statements based on the execution time in the query attribute information to obtain a first slow query statement; Performing a second screening on the first slow query statement using the query object in the query attribute information to obtain the slow query statement; the query object includes at least one of a queried data table, a queried field, and a filtering condition; The second screening of the first slow query statement by using the query object in the query attribute information to obtain the slow query statement includes: If the first slow query statement contains: a first target slow query statement whose number of queried fields is less than a preset number of fields, the first target slow query statement is used as the slow query statement; and / or If the first slow query statement contains a second target slow query statement in which the number of data items stored in the queried data table is greater than a preset number, the second target slow query statement is used as the slow query statement.
2. The method according to claim 1, characterized in that The first screening of the historical query statements based on the execution time in the query attribute information to obtain a first slow query statement includes: The historical query statement whose execution time is longer than the second preset time threshold is used as the first slow query statement; the second preset time threshold is not less than the first preset time threshold.
3. The method according to claim 1, characterized in that: The first screening of the historical query statements based on the execution time in the query attribute information to obtain a first slow query statement includes: The historical query statements are inserted into the queue in order of the execution time from low to high, and the historical query statement whose queue position is greater than the preset queue position is used as the first slow query statement.
4. The method according to claim 1, characterized in that: The slow query statement includes a historical data table name and a historical field name for query; the step of generating a query data table according to the slow query statement and the data queried by the slow query statement includes: Acquire field information of a corresponding data table based on the historical data table name, and generate a first query data table name according to the historical data table name; Using the historical field name to filter the field information, obtaining target field information corresponding to the historical field name; Create an initial query data table according to the first query data table name and the target field information; The data queried by the slow query statement is written into the initial query data table to generate a query data table.
5. The method according to any one of claims 1 to 4, characterized in that: After generating a query data table according to the slow query statement and the data queried by the slow query statement, the method further includes: Receive an update statement; the update statement includes an update data table name and update data; Using the update statement, writing the update data into the original data table corresponding to the update data table name; Based on the updated data table name, a pre-generated first data relationship mapping table is queried to obtain a second query data table name corresponding to the updated data table name; the first data relationship mapping table is used to represent the updated mapping relationship between the original data table and the query data table; Determine the field name of the data to be written according to the second query data table name, and transform the update statement according to the second query data table name and the field name of the data to be written to generate a new update statement; The updated data is written into the query data table corresponding to the second query data table name based on the new update statement.
6. The method according to claim 5, characterized in that The query data table includes a query range; the method further includes: According to a second preset time period, the data in the query data table corresponding to the second query data table name that does not conform to the query range is deleted.
7. The method according to any one of claims 1 to 4, characterized in that: After generating a query data table according to the slow query statement and the data queried by the slow query statement, the method further includes: Acquire a pre-generated copy statement according to a third preset time period, wherein the copy statement includes the name of the original data table where the to-be-copied data is located and the name of the target query data table to be stored; The copy statement is executed to copy the to-be-copied data from the original data table corresponding to the original data table name to the query data table corresponding to the target query data table name.
8. A data query method, characterized in that: The method comprises: Receive a data query request; the data query request includes a query statement; the query statement includes a first data table name, a field name and a query condition; Generate a query feature of the query statement according to the first data table name, the field name and the query condition; Utilize the query feature to query a pre-generated second data relationship mapping table; the second data relationship mapping table is used to characterize the query mapping relationship between the original data table and the query data table; the query data table is generated based on the method described in any one of claims 1 to 7; the query data table includes a second data table name; If the second data table name corresponding to the first data table name exists in the second data relationship mapping table, the data in the query data table corresponding to the second data table name is used as the query result.
9. The method according to claim 8, characterized in that After querying the pre-generated second data relationship mapping table using the query feature, the method further includes: If the second data relationship mapping table does not contain the second data table name corresponding to the first data table name, the original data table corresponding to the first data table name is queried through the query statement.
10. A query data table generating device, characterized in that: The device comprises: An acquisition module, configured to acquire historical query records according to a first preset time period; the historical query records include historical query statements and query attribute information of the historical query statements; the query attribute information is used to characterize behavior information generated during the execution of the historical query statements; A screening module, used to screen the historical query statements based on the query attribute information to obtain slow query statements; the slow query statements are used to represent query statements whose execution time exceeds a first preset time threshold; A first generating module is used to generate a query data table according to the slow query statement and the data queried by the slow query statement; the number of fields in the query data table is less than the number of fields in the corresponding original data table; the data range of the query data table is a subset of the corresponding original data table; Wherein, the screening module is specifically used for: Performing a first screening of the historical query statements based on the execution time in the query attribute information to obtain a first slow query statement; Performing a second screening on the first slow query statement using the query object in the query attribute information to obtain the slow query statement; the query object includes at least one of a queried data table, a queried field, and a filtering condition; The screening module is specifically used for: If the first slow query statement contains: a first target slow query statement whose number of queried fields is less than a preset number of fields, the first target slow query statement is used as the slow query statement; and / or If the first slow query statement contains a second target slow query statement in which the number of data items stored in the queried data table is greater than a preset number, the second target slow query statement is used as the slow query statement.
11. A data query device, characterized in that: The device comprises: A receiving module, used for receiving a data query request; the data query request includes a query statement; the query statement includes a first data table name, a field name and a query condition to be queried; A second generating module, used for generating a query feature of the query statement according to the first data table name, the field name and the query condition; A first query module, used to query a pre-generated data relationship mapping table using the query feature; the data relationship mapping table is used to characterize the mapping relationship between the original data table and the query data table; the query data table is generated based on the method described in any one of claims 1 to 7; the query data table includes a second data table name; A second query module is configured to use the data in the query data table corresponding to the second data table name as the query result if the second data table name corresponding to the first data table name exists in the data relationship mapping table.
12. An electronic device, characterized in that: include: A processor and a memory, wherein the memory stores machine-readable instructions executable by the processor, and when the machine-readable instructions are executed by the processor, the method according to any one of claims 1 to 9 is performed.
13. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 9 is executed.
14. A computer program product, characterized in that include: A computer program, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 9 is executed.
Citation Information
Patent Citations
Method and device for identifying and analyzing slow query statements, and method and device for counting query statements
CN113297249A
Data query method and device, equipment and storage medium
CN114281819A
Method for high-risk query SQL based on database middleware
CN114706881A
Query optimization method and device for slow SQL (Structured Query Language) statement and computer equipment
CN117033424A
