A page data processing method and device, a storage medium and an apparatus
By renaming the temporary table in the MySQL database to a partitioned table and performing partitioned table queries in the statistics table, the problem of slow web page queries in large data volume scenarios was solved, achieving faster data delivery and improved ease of use.
Patent Information
- Application Number
- CN202310281405.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-21
- Publication Date
- 2025-12-12
- Estimated Expiration
- 2043-03-21
AI Technical Summary
In scenarios with large amounts of data, web page queries for MySQL databases are prone to lag, resulting in poor usability.
When the amount of data in a temporary table reaches a preset threshold, it is renamed and recorded as a shard in the statistics table. A new temporary table is created, and a shard query is performed in the statistics table when a user makes a query request. This splits a large data table into multiple smaller data tables to provide data quickly.
It effectively reduces page lag in scenarios with large amounts of data, improving query speed and ease of use.
Smart Images

Figure CN116340667B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of Internet, in particular to a page data processing method and device, a storage medium and equipment. BACKGROUND
[0002] Data display is an indispensable part of the function provided by a Web page. At present, most of the data of a Web page is stored in MySQL. MySQL is a relational database management system. A relational database saves data in different tables instead of putting all data in a large warehouse, thus increasing speed and improving flexibility. However, as the amount of data in MySQL continues to grow, the page may appear to be stuck when querying, resulting in poor usability. SUMMARY
[0003] Embodiments of the present application aim to provide a page data processing method and device, a storage medium and equipment, and solve the problem that page querying is prone to lag in a large data amount scenario in the related art.
[0004] In a first aspect, a page data processing method is provided, including:
[0005] When receiving to-be-inserted data, if the amount of data of a current temporary table is greater than a preset threshold, renaming the temporary table, recording the temporary table as a sub-table in a statistics table, and creating a new temporary table; the table name of the temporary table before renaming and the table name of the new temporary table are both a specified table name;
[0006] Writing the to-be-inserted data into the temporary table corresponding to the specified table name at present;
[0007] When receiving a user query request, querying a sub-table in the statistics table according to the user query request, and returning the queried data to a page.
[0008] In the implementation process, new data is received through a temporary table, when it is determined that the amount of data of the temporary table is greater than a preset threshold, the temporary table is renamed, and the renamed table is recorded as a sub-table in a statistics table, and then a new temporary table is created. When a user query request is received, a sub-table is queried in the statistics table according to the request, and the queried data is returned to a page. In this way, sub-table management and sub-table querying are implemented, a large data table is divided into multiple small data tables, so that corresponding data can be quickly provided according to the needs of a page, and the phenomenon that the page appears to be stuck when querying in a large data amount scenario is effectively reduced.
[0009] Further, in some embodiments, the temporary table is a data table of a target database; and the preset threshold is set based on historical traffic of the target database.
[0010] In the implementation process, the preset threshold is set according to the historical traffic of the target database, so that the set table limit is more reasonable, and the management of the data table is facilitated.
[0011] Further, in some embodiments, the method further comprises:
[0012] creating a timing task, the timing task being configured to perform the operations of renaming the temporary table, recording the temporary table as a sub-table in the statistics table, and creating a new temporary table at a preset time point.
[0013] In the implementation process, the temporary table is renamed at a preset time point by the timing task, the renamed table is recorded in the statistics table, and a new temporary table is created, so that the historical data is facilitated to be managed.
[0014] Further, in some embodiments, the user query request comprises a query condition and a specified query quantity;
[0015] The querying of the sub-tables in the statistics table according to the user query request and the returning of the queried data to the page comprise:
[0016] determining a to-be-displayed page number based on the specified query quantity and a single-page display number corresponding to the page, and returning the to-be-displayed page number to the page for display;
[0017] querying target data meeting the query condition and the single-page display number from the sub-tables of the statistics table, and returning the target data to the page for display.
[0018] In the implementation process, the target data meeting the query condition and the single-page display number is queried from the sub-tables and returned to the page for display, which reduces the amount of queried data to a certain extent and reduces the occurrence of page lag.
[0019] Further, in some embodiments, the querying of the target data meeting the query condition and the single-page display number from the sub-tables of the statistics table comprises:
[0020] calculating the number of records meeting the query condition in each sub-table of the statistics table, and storing the number of records in a target array;
[0021] traversing the target array, and defining a first variable and a second variable to be accumulated respectively, the first variable being configured to accumulate the number of records from the first sub-table to the current sub-table, and the second variable being configured to accumulate the number of records from the first sub-table to the last sub-table of the current sub-table;
[0022] determine a sub-table in which the target data is located based on the single-page display number, the first variable and the second variable;
[0023] query the target data from the determined sub-table.
[0024] In the implementation process, a specific way of quickly querying data from a sub-table is provided, and the time consumed for querying is reduced.
[0025] Further, in some embodiments, the determining of the sub-table in which the target data is located based on the single-page display number, the first variable and the second variable comprises:
[0026] determining a first record number and a second record number based on the single-page display number; the first record number is a product of the single-page display number and a specified page number, and the second record number is a difference between the first record number and the single-page display number;
[0027] In the traversal process, if the first record number is less than or equal to the first variable and the second record number is greater than or equal to the second variable, it is determined that the sub-table in which the target data is located is only the current sub-table; if the first record number is greater than the first variable and the second record number is less than the first variable, it is determined that the current sub-table is one of a plurality of sub-tables in which the target data is located, and the last sub-table of the plurality of sub-tables is a sub-table corresponding to a first time when the first variable is greater than or equal to the first record number.
[0028] In the implementation process, a specific way of quickly determining a sub-table in which target data is located is provided.
[0029] Further, in some embodiments, the querying of the target data from the determined sub-table comprises:
[0030] if the sub-table in which the target data is located is only the current sub-table, determining records in the current sub-table that meet the query condition as a first set, and sequentially reading out records of the single-page display number from a first query position of the first set as the target data; the first query position is determined based on a difference between the second record number and the second variable.
[0031] If the table where the target data is located is multiple tables, records in a first table that meet the query condition are determined as a second set, records in a last table that meet the query condition are determined as a third set, and records in an intermediate table that meet the query condition are determined as a fourth set, records from a second query position to the last bit in the second set, records from the first bit to a third query position in the third set, and all records in the fourth set are read as the target data; the second query position is determined based on a difference between the second record number and the second variable when the first table is traversed; and the third query position is determined based on a difference between the first variable when the last table is traversed and the first record number.
[0032] In the implementation process, after the table where the target data is located is determined, the query position of the required data in the table is calculated, so that the target data is quickly queried.
[0033] In a second aspect, an embodiment of the present application provides a page data processing apparatus, including:
[0034] The creating module is configured to, when receiving to-be-inserted data, if a data amount of a current temporary table is greater than a preset threshold, rename the temporary table, record the temporary table into a statistics table as a sub-table, and create a new temporary table; a table name of the temporary table before being renamed and a table name of the new temporary table are both a specified table name.
[0035] The writing module is configured to write the to-be-inserted data into a temporary table corresponding to the specified table name.
[0036] The querying module is configured to, when receiving a user query request, query a sub-table in the statistics table according to the user query request, and return the queried data to a page.
[0037] In a third aspect, an embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and capable of running on the processor, and the processor implements steps of the method according to any one of the first aspect when executing the computer program.
[0038] In a fourth aspect, an embodiment of the present application provides a computer readable storage medium, and instructions are stored on the computer readable storage medium, and when the instructions run on a computer, the computer executes the method according to any one of the first aspect.
[0039] In a fifth aspect, an embodiment of the present application provides a computer program product, and when the computer program product runs on a computer, the computer executes the method according to any one of the first aspect.
[0040] Other features and advantages of the present application will be set forth in the descriptions that follow, and in part will be apparent from the description, or can be learned by practice of the application as hereinafter more fully described, or can be learned by practice of the application. It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the application, as claimed.
[0041] In order to make the above objectives, features and advantages of the present application more apparent, the following will specifically describe a preferred embodiment in conjunction with the accompanying drawings, and make a detailed description as follows. BRIEF DESCRIPTION OF DRAWINGS
[0042] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the following will briefly introduce the drawings needed to be used in the embodiments of the present application. It should be understood that the following drawings only show some embodiments of the present application, and therefore should not be considered as a limitation to the scope. For those skilled in the art, other related drawings can also be obtained without creative labor on the basis of these drawings.
[0043] Figure 1 A flow chart of a page data processing method provided by the embodiments of the present application;
[0044] Figure 2 A schematic diagram of a working flow of a solution provided by the embodiments of the present application to solve the problem of page query lag in large data volume of MySQL;
[0045] Figure 3 A block diagram of a page data processing device provided by the embodiments of the present application;
[0046] Figure 4 A structural block diagram of an electronic device provided by the embodiments of the present application. DETAILED DESCRIPTION
[0047] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0048] It should be noted that: similar reference numerals and letters represent similar items in the following drawings, and therefore, once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings. Meanwhile, in the description of the present application, the terms “first”, “second”, etc. are only used for distinguishing description, and cannot be understood as indicating or implying relative importance.
[0049] As described in the background, there is a problem that page query is prone to lag in large data volume scenarios in the related art. Based on this, the embodiments of the present application provide a page data processing solution to solve the above problem.
[0050] Next, the embodiments of the present application will be introduced:
[0051] As shown in the background, Figure 1 ,Figure 1 is a flowchart of a page data processing method provided by an embodiment of the present application. The method can be applied to a device that provides data display through a Web page, such as a Web server that displays Web site data, a firewall that provides log viewing functions, and the like.
[0052] The method comprises:
[0053] In step 101, when receiving data to be inserted, if the data amount of the current temporary table is greater than a preset threshold, the temporary table is renamed, the temporary table is recorded in a statistics table as a sub-table, and a new temporary table is created; the table name of the temporary table before being renamed and the table name of the new temporary table are both specified table names.
[0054] The data to be inserted mentioned in this step can be new data that needs to be saved in a database. Taking the case where the embodiment is applied to the log viewing functions of a firewall as an example, the inserted data can be at least one of operation logs, administrator logs, access control logs, and the like. In the embodiment, when receiving new data, it is first determined whether the data amount of the current temporary table is greater than a preset threshold. If yes, it is considered that the data amount of the current temporary table has reached the table limit, at which time the temporary table is renamed, the renamed table is recorded in a statistics table, and a new temporary table is created. In this way, the data amount of the temporary table can be prevented from being too large.
[0055] In some embodiments, the temporary table can be a data table of a target database, and the preset threshold can be set based on the historical traffic of the target database. The target database here can be MySQL or other types of databases. The preset threshold is set based on the historical traffic of the target database, which can make the set table limit more reasonable. For example, when the average historical daily traffic of the target database is within ten million, the preset threshold can be set to three million, which can both avoid the data amount of the temporary table being too large and avoid too many tables being created, facilitating the management of data tables.
[0056] The table name of the temporary table before being renamed and the table name of the new temporary table are both specified table names, that is, the newly created temporary table adopts the table name of the original temporary table, and the original temporary table is replaced with a table name. For example, the table name of the current temporary table is “Temporary1”, when receiving new data, because the data amount is greater than the preset threshold, the temporary table is renamed as “Work1”, the temporary table is recorded in a statistics table, and then a new temporary table is created, and the table name of the new temporary table still adopts “Temporary1”.
[0057] In step 102, the data to be inserted is written into the temporary table corresponding to the specified table name at present;
[0058] The step refers to: if the data amount of the current temporary table is not greater than the preset threshold, directly inserting the new data into the temporary table, otherwise, creating a new temporary table and inserting the new data into the new temporary table. In this way, the table management is realized, the large data table is divided into multiple small data tables, so that the corresponding data can be quickly provided according to the needs of the page, and the page lag problem is solved.
[0059] In step 103, when receiving the user query request, querying the sub-table in the statistical table according to the user query request, and returning the queried data to the page.
[0060] In some embodiments, the above method can further include: creating a timing task, the timing task is used to execute the operation of renaming the temporary table, recording the temporary table as a sub-table in the statistical table, and creating a new temporary table at a preset time point. That is, through the timing task, the temporary table is renamed at a preset time point, such as every day at 0 o'clock, and then the renamed table is recorded in the statistical table, and a new temporary table is created. In this way, it is convenient to manage the historical data.
[0061] In addition to the above improvement in data table operation, other embodiments of the present application also provide improvements in data operation to further solve the problem of page query lag in the scene of large data amount.
[0062] The user query request mentioned above can include a query condition and a specified query quantity. The query condition can be time, keyword, numerical value, etc., and the specified query quantity can refer to the number of data that the user requests to query, for example, the user can request to query 100 pieces of data about Zhang San, and in the user query request, the query condition is the keyword "Zhang San" and the specified query quantity is 100 pieces. In some embodiments, step 103 can include determining the number of pages to be displayed based on the specified query quantity and the number of single-page displays corresponding to the page, and returning the number of pages to be displayed to the page for display; querying the target data that meets the query condition and the number of single-page displays from the sub-table of the statistical table, and returning the target data to the page for display. The number of single-page displays here refers to the number of data pieces displayed on a single page of a Web page, which can be different according to the display style of different Web pages. When the specified query quantity is greater than the number of single-page displays, the Web page is usually displayed in pages, for example, the specified query quantity is 100 pieces and the number of single-page displays is 20 pieces, so the number of pages to be displayed is 5, that is, the user required data is displayed through 5 pages. After the device determines the number of pages to be displayed, the number of pages to be displayed is returned to the page for display, so that the user can view the data by paging or selecting a certain page. In this way, for the device, only the target data that meets the query condition and the number of single-page displays needs to be queried from the sub-table of the statistical table and returned to the page for display, without the need to query all the required data at one time, that is, only 20 pieces of target data need to be queried each time the user operates. In this way, the amount of data queried is reduced to a certain extent, and the situation of page lag is reduced.
[0063] Further, in some embodiments, the aforementioned querying of the target data from the sub-tables of the statistical table that meet the query condition and the single-page display number can include: calculating the number of records in each sub-table of the statistical table that meet the query condition, and storing the number of records in a target array; traversing the target array and defining a first variable and a second variable to accumulate respectively, the first variable being used to accumulate the number of records from the first sub-table to the current sub-table, and the second variable being used to accumulate the number of records from the first sub-table to the last sub-table of the current sub-table; determining the sub-table in which the target data is located based on the single-page display number, the first variable and the second variable; and querying the target data from the determined sub-table. For example, there are six sub-tables in the statistical table, and when querying, the number of records in these sub-tables that meet the query condition is obtained in sequence as 20, 18, 16, 14, 12 and 10, which are stored in the countArr array. The countArr array can be {20, 18, 16, 14, 12, 10}. The countArr array is traversed in a loop, and two variables sum1 and sum2 are defined to accumulate respectively, sum1 accumulating from the statistical result of the first sub-table to the statistical result of the sub-table currently traversed to, and sum2 accumulating from the statistical result of the first sub-table to the last statistical result of the sub-table currently traversed to. Assuming that the first sub-table is currently traversed to, sum1 = 20 and sum2 = 0, and the third sub-table is currently traversed to, sum1 = 20 + 18 + 16 = 54 and sum2 = 20 + 18 = 38. In this way, based on the single-page display number, sum1 and sum2, it can be determined in which sub-table or sub-tables the required data is located, and the required data is then read from the determined sub-table. In this way, data can be quickly queried from the sub-tables, reducing the time consumed for querying.
[0064] Optionally, the sub-table where the target data is located can be determined based on the following manner: determining a first record number and a second record number based on the single-page display number; the first record number is a product of the single-page display number and a specified page number, and the second record number is a difference between the first record number and the single-page display number; in the traversal process, if the first record number is less than or equal to the first variable and the second record number is greater than or equal to the second variable, it is determined that the sub-table where the target data is located is only the current sub-table; if the first record number is greater than the first variable and the second record number is less than the first variable, it is determined that the current sub-table is one of a plurality of sub-tables where the target data is located, and the last sub-table of the plurality of sub-tables is a sub-table corresponding to the first time when the first variable is greater than or equal to the first record number. The specified page number here refers to the page number that needs to be displayed in the page. After returning the page number to be displayed to the page for display, if the user does not select to page or specify a certain page number, the page displays the data of the first page by default, that is, the specified page number is 1. If the user selects to page to the third page, the page displays the data of the third page, that is, the specified page number is 3. According to the single-page display number and the specified page number, the first record number and the second record number can be determined. For example, if the single-page display number is 20 and the specified page number is 3, the first record number is 60 and the second record number is 40. Then, the relationship between the first record number, the second record number, the first variable and the second variable is compared. Generally, the first variable and the second variable are different when the current sub-table is traversed. When the first record number is less than or equal to the first variable and the second record number is greater than or equal to the second variable when traversing to a certain sub-table, it is determined that the sub-table is the sub-table where the target data is located, and the sub-table where the target data is located is a single table, that is, the required data is in the sub-table. When the first record number is greater than the first variable and the second record number is less than the first variable when traversing to a certain sub-table, it is determined that the sub-table is one of a plurality of sub-tables where the target data is located, that is, part of the required data is in the sub-table. At this time, the position of the next sub-table is traversed. At this time, if the first record number is greater than the first variable and the second record number is less than the first variable, it is determined that the sub-table is also one of the plurality of sub-tables where the target data is located. Or at this time, if the first variable is greater than or equal to the first record number, it is determined that the sub-table is the last one of the plurality of sub-tables where the target data is located. Otherwise, it is considered that the sub-table is not the sub-table where the target data is located. In this way, the sub-table where the required data is located can be quickly queried, thereby effectively reducing the time consumed for querying. It should be noted that when the sub-table where the target data is located is determined, the name of the sub-table or the serial number of the sub-table can be recorded at the same time, so as to facilitate subsequent data reading.
[0065] Further, after determining the sub-table where the target data is located, the target data can be obtained based on the following manners: if the sub-table where the target data is located is only the current sub-table, records in the current sub-table that meet the query condition are determined as a first set, and records of the single-page display number are sequentially read out from a first query position of the first set as the target data; the first query position is determined based on a difference between the second record number and the second variable; if the sub-table where the target data is located is multiple sub-tables, records in a first sub-table that meet the query condition are determined as a second set, records in a last sub-table that meet the query condition are determined as a third set, and records in an intermediate sub-table that meet the query condition are determined as a fourth set, records from a second query position to the last record in the second set, records from the first record to a third query position in the third set, and all records in the fourth set are read as the target data; the second query position is determined based on a difference between the second record number and the second variable when the first sub-table is traversed; the third query position is determined based on a difference between a record number of the last sub-table and a target record number; and the target record number is a difference between the first variable when the last sub-table is traversed and the first record number. That is, if the required data is located in a single table, a starting query position is calculated first, and then records of the single-page display number are sequentially read out from the starting query position among all records in the sub-table that meet the query condition as the target data; if the required data is located in multiple tables, a position where the first sub-table starts is calculated for query, and a position where the last sub-table ends is calculated for query, and then the query results are combined as the target data.
[0066] For example, the target array formed by the records in the sub-table 1, the sub-table 2, the sub-table 3, the sub-table 4 and the sub-table 5 meeting the user query condition is {22, 12, 10, 30, 12}, and the number of records displayed on a single page is 20; when the specified page number is 1, the first record number is 20, and the second record number is 0. Since the first variable is 22 and the second variable is 0 when the traversal reaches the statistical number corresponding to the sub-table 1, it is determined that the required data is in the sub-table 1, and the difference obtained by subtracting the second variable from the second record number is 0 at this time, so it is determined that the first query position is the first position, that is, the records from the first position to the twentieth position in the records meeting the user query condition in the sub-table 1 are read as the target data; when the specified page number is 2, the first record number is 40, and the second record number is 20. According to the above correspondence, it can be determined that the required data is in the sub-table 1, the sub-table 2 and the sub-table 3, and the difference obtained by subtracting the second variable when the traversal reaches the sub-table 1 from the second record number is 20, so it is determined that the second query position is the twenty-first position. The difference obtained by subtracting the first record number from the first variable when the traversal reaches the sub-table 3 is 4, so it is determined that the third query position is the fourth position. Therefore, the records from the twenty-first position to the last position in the records meeting the user query condition in the sub-table 1 are read as data 1, all the records meeting the user query condition in the sub-table 2 are read as data 2, and the records from the first position to the fourth position in the records meeting the user query condition in the sub-table 3 are read as data 3, and then data 1, data 2 and data 3 are combined into the target data.
[0067] The target data is queried in the above manner and then returned to the page, which can effectively reduce the phenomenon of page query lag in a large data scenario. Of course, in other embodiments, other manners can be used to determine the sub-table in which the target data is located and the query position in the sub-table, for example, while the first variable and the second variable are defined, a third variable for recording the position of a start table, a fourth variable for recording the required number of the start table, a fifth variable for recording the position of an end table, and a sixth variable for recording the required number of the end table are defined, and then the data is quickly queried based on these variables. The present application does not limit this.
[0068] In the embodiments of the present application, the new data is received through the temporary table. When it is judged that the data amount of the temporary table is greater than a preset threshold, the temporary table is renamed, the renamed table is recorded in the statistical table as a sub-table, a new temporary table is created, and then when a user query request is received, the sub-table is queried in the statistical table according to the request, and the queried data is returned to the page. In this way, the sub-table management and sub-table query are implemented, the large data table is divided into multiple small data tables, and the corresponding data can be quickly provided according to the needs of the page, thereby effectively reducing the phenomenon of page query lag in a large data scenario.
[0069] In order to make a more detailed description of the scheme of the present application, a specific embodiment is introduced as follows:
[0070] The embodiment provides a solution to solve the lag of a large amount of data page query of MySQL, which is applied to a log query function of a firewall, and the solution comprises two parts, namely a data table operation part and a data operation part.
[0071] In the data table operation part, a temporary table is created, log data is inserted into the temporary table, and it is judged whether the data quantity of the temporary table is greater than three million, if yes, the temporary table is renamed, and record is made to a statistics table, and then a new temporary table is created; and a timing task is created, the temporary table is renamed at zero point every day, and record is made to the statistics table, and then the new temporary table is created, so as to facilitate management of historical data.
[0072] In the data operation part, when a user performs log query, a target algorithm is used to quickly query data from a subtable, and the data is returned to a page, specifically, the working process of the data operation part is as shown in Figure 2 , and comprises:
[0073] S201, according to a user query condition, a subtable is queried in a statistics table, the number of subtables meeting the user query condition is counted and stored in a countArr array;
[0074] S202, according to the page number page where a page is located and the number rows required by the page, the total number total is calculated as total = page * rows; wherein the page number page where the page is located is specified by a user or adopts a default value;
[0075] S203, the countArr array is looped, and a first variable sum1 and a second variable sum2 are defined to be accumulated respectively, sum1 is accumulated to the current position i of the array, that is, the current subtable, and sum2 is accumulated to i-1, that is, the previous subtable of the current subtable;
[0076] S204, the relationship between total and sum1 and sum2 is compared to determine the subtable where the required data is located; specifically, if total is less than or equal to sum1, and total-rows is greater than or equal to sum2, the required data is only in the current subtable, and the name of the current subtable is recorded; if total is greater than sum1, and total-rows is less than sum1, part of the required data is in the current subtable, the name of the current subtable is recorded, the array is continuously looped, and the last one of the multiple subtables where the required data is located is the subtable corresponding to the first time when sum1 is greater than or equal to total;
[0077] 205、determine the query position, query data in the determined sub-table; specifically, if the required data is in a single table, determine the starting query position start = total-rows-sum2, query the primary key index first, and in the records meeting the requirements in the sub-table, sequentially read rows records from the starting query position start as target data, and then back to the table; if the required data is in multiple tables, calculate the position of the first table to query, and calculate the end position of the last table to query, and then merge the query results;
[0078] S206、return the data to the page.
[0079] Experiments show that, through the embodiment scheme, the memory consumption is reduced from 4G to 500M in the case of ten thousand data, that is, the memory consumption is effectively reduced, and the query consumption time is reduced from 20 minutes to 2 minutes, that is, the query consumption time is effectively reduced. The embodiment scheme actually provides a sub-table management and sub-table query method, which divides a large data table into multiple small data tables, quickly provides the required data according to the needs of the page, solves the page viewing lag problem in the large data scenario, and enhances the ease of use and improves the user experience.
[0080] Corresponding to the embodiments of the foregoing method, the application also provides embodiments of a page data processing device and a terminal applying the same:
[0081] As shown in Figure 3 , Figure 3 is a block diagram of a page data processing device provided by an embodiment of the application, and the device comprises:
[0082] A creating module 31 is configured to, when receiving to-be-inserted data, if the data amount of a current temporary table is greater than a preset threshold, rename the temporary table, record the temporary table as a sub-table in a statistics table, and create a new temporary table; the table name of the temporary table before being renamed and the table name of the new temporary table are both a specified table name.
[0083] A writing module 32 is configured to write the to-be-inserted data into the temporary table currently corresponding to the specified table name.
[0084] A querying module 33 is configured to, when receiving a user query request, query a sub-table in the statistics table according to the user query request, and return the queried data to a page.
[0085] The implementation process of the functions and effects of each module in the above device is specifically described in the implementation process of the corresponding steps in the above method, and will not be repeated here.
[0086] The application also provides an electronic device, please see Figure 4 ,Figure 4 A structural block diagram of an electronic device is provided for an embodiment of the present application. The electronic device can include a processor 410, a communication interface 420, a memory 430, and at least one communication bus 440. The communication bus 440 is used to realize direct connection communication among the components. The communication interface 420 of the electronic device in the embodiment of the present application is used to communicate signaling or data with other node devices. The processor 410 can be an integrated circuit chip with signal processing capability.
[0087] The processor 410 described above can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc. It can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component. It can implement or execute the disclosed methods, steps, and logic block diagrams in the embodiments of the present application. The general-purpose processor can be a microprocessor or the processor 410 can also be any conventional processor.
[0088] The memory 430 can be, but is not limited to, a random access memory (RAM), a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), etc. The memory 430 stores computer readable instructions, which, when executed by the processor 410, enable the electronic device to perform the above Figure 1 The method embodiments involve various steps.
[0089] Optionally, the electronic device can further include a storage controller, an input / output unit.
[0090] The memory 430, the storage controller, the processor 410, the peripheral interface, and the input / output unit are directly or indirectly electrically connected to each other to realize data transmission or interaction. For example, these elements can be electrically connected to each other through one or more communication buses 440. The processor 410 is configured to execute executable modules stored in the memory 430, such as software function modules or computer programs included in the electronic device.
[0091] The input / output unit is used to provide a user with creating a task and creating a selectable period of time or a preset execution time for the task to realize the interaction between the user and the server. The input / output unit can be, but is not limited to, a mouse, a keyboard and the like.
[0092] It can be understood that Figure 4 The structure shown is only schematic, and the electronic device can further include more or fewer components than those shown, or have a different configuration of components than those shown. Figure 4 The components shown in the figures can be implemented in hardware, software, or a combination thereof. Figure 4 The components shown in the figures can be implemented in hardware, software, or a combination thereof. Figure 4 The components shown in the figures can be implemented in hardware, software, or a combination thereof.
[0093] The embodiments of the present application further provide a storage medium, wherein instructions are stored on the storage medium, and when the instructions are run on a computer, the computer program is executed by a processor to implement the method of the method embodiments. To avoid repetition, details are not described here.
[0094] The present application also provides a computer program product, which, when run on a computer, causes the computer to execute the method of the method embodiments.
[0095] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are only schematic, for example, the flowcharts and block diagrams in the drawings show the possible implementation architectures, functions and operations of the devices, methods and computer program products according to the embodiments of the present application. In this regard, each block in the flowchart or block diagram can represent a module, a program segment or a part of code, which contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in some alternative implementations, the functions noted in the blocks can occur in different orders from those shown in the drawings. For example, two consecutive blocks can actually be executed substantially in parallel, and sometimes they can be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and the combination of blocks in the block diagram and / or flowchart, can be implemented by a dedicated hardware-based system for executing the specified functions or actions, or can be implemented by a combination of dedicated hardware and computer instructions.
[0096] In addition, each functional module in the various embodiments of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0097] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application essentially or the parts of the prior art that make contributions or parts of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.
[0098] The above merely provides an example 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 can have various modifications and changes. 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. It should be noted that similar reference numbers and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings.
[0099] The above merely provides an example 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 can have various modifications and changes. 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. It should be noted that similar reference numbers and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings.
[0100] It should be noted that, in this document, the terms such as first and second are used merely to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "contain" or any other variants thereof are intended to cover non-exclusive inclusion, so that the processes, methods, articles or devices including a series of elements not only include those elements, but also include other elements not explicitly listed or inherent to such processes, methods, articles or devices. Without more limitations, the element defined by the statement "including a" does not exclude the presence of another identical element in the process, method, article or device including the element.
Claims
1. A method of processing page data, characterized by, The method comprises the following steps: when receiving to-be-inserted data, if the data amount of a current temporary table is greater than a preset threshold, renaming the temporary table, recording the temporary table as a sub-table into a statistics table, and creating a new temporary table; the table name of the temporary table before renaming and the table name of the new temporary table are both specified table names; the to-be-inserted data is new data that needs to be saved in a database; writing the to-be-inserted data into the temporary table currently corresponding to the specified table name; when receiving a user query request, querying a sub-table in the statistics table according to the user query request, and returning the queried data to a page.
2. The method of claim 1, wherein, The temporary table is a data table of a target database; and the preset threshold is set based on historical traffic of the target database.
3. The method of claim 1, wherein, The method further comprises the following steps: creating a timing task, which is used to perform the operation of renaming the temporary table, recording the temporary table as a sub-table into a statistics table, and creating a new temporary table at a preset time point.
4. The method of claim 1, wherein, The user query request comprises a query condition and a specified query quantity; the operation of querying a sub-table in the statistics table according to the user query request and returning the queried data to a page comprises the following steps: determining a to-be-displayed page number based on the specified query quantity and the single-page display number corresponding to the page, and returning the to-be-displayed page number to the page for display; querying target data meeting the query condition and the single-page display number from the sub-table of the statistics table, and returning the target data to the page for display.
5. The method of claim 4, wherein, The operation of querying target data meeting the query condition and the single-page display number from the sub-table of the statistics table comprises the following steps: calculating the record number meeting the query condition in each sub-table of the statistics table, and storing the record number in a target array; traversing the target array, and defining a first variable and a second variable to be accumulated respectively, wherein the first variable is used to accumulate the record number from the first sub-table to the current sub-table, and the second variable is used to accumulate the record number from the first sub-table to the last sub-table of the sub-tables before the current sub-table; determining the sub-table in which the target data is located based on the single-page display number, the first variable, and the second variable; querying the target data from the determined sub-table.
6. The method of claim 5, wherein, The operation of determining the sub-table in which the target data is located based on the single-page display number, the first variable, and the second variable comprises the following steps: determining a first record number and a second record number based on the single-page display number; the first record number is the product of the single-page display number and a specified page number, and the second record number is the difference between the first record number and the single-page display number; in the traversing process, if the first record number is less than or equal to the first variable, and the second record number is greater than or equal to the second variable, it is determined that the sub-table in which the target data is located is only the current sub-table; if the first record number is greater than the first variable, and the second record number is less than the first variable, it is determined that the current sub-table is one of a plurality of sub-tables in which the target data is located, and the last sub-table of the plurality of sub-tables is the sub-table corresponding to the first time when the first variable is greater than or equal to the first record number.
7. The method of claim 6, wherein, The operation of querying the target data from the determined sub-table comprises the following steps: If the sub-table where the target data is located is only the current sub-table, records in the current sub-table that meet the query condition are determined as a first set, and the target data is sequentially read out from a first query position of the first set as the single-page display number of records; the first query position is determined based on a difference between the second record number and the second variable; If the sub-table where the target data is located is multiple sub-tables, records in a first sub-table that meet the query condition are determined as a second set, records in a last sub-table that meet the query condition are determined as a third set, and records in an intermediate sub-table that meet the query condition are determined as a fourth set, the target data is read as records from a second query position to the last position in the second set, records from the first position to a third query position in the third set, and all records in the fourth set; the second query position is determined based on a difference between the second record number and the second variable when the first sub-table is traversed; the third query position is determined based on a difference between a record number of the last sub-table and the target record number; and the target record number is a difference between the first variable when the last sub-table is traversed and the first record number.
8. A page data processing apparatus characterized by comprising: Comprise: A creating module, configured to, when receiving to-be-inserted data, if a data amount of a current temporary table is greater than a preset threshold, rename the temporary table, record the temporary table as a sub-table in a statistics table, and create a new temporary table; The table name of the temporary table before being renamed and the table name of the new temporary table are both specified table names; and the to-be-inserted data is new data that needs to be saved in a database; A writing module, configured to write the to-be-inserted data into the temporary table currently corresponding to the specified table name; A query module, configured to, when receiving a user query request, query a sub-table in the statistics table according to the user query request, and return the queried data to a page.
9. A computer-readable storage medium, characterized in that, A computer program is stored thereon, and the computer program is executed by a processor to implement the method in any one of claims 1 to 7.
10. An electronic device, comprising: Comprise a processor, a memory, and a computer program stored on the memory and executable on the processor, wherein the processor implements the method in any one of claims 1 to 7 when executing the computer program.
Citation Information
Patent Citations
A method and apparatus for updating data
CN109388644A
Paging query method and device for database sub-libraries and sub-tables and computer equipment
CN110569255A