A page-turning query method and system with consistent result set

By calculating the hash value to determine the sharding order and serially executing the materialization of the sharded result set, it solves the problem of page turning query performance attenuation and consistency in a cluster environment, and achieves efficient page turning query result consistency and performance maintenance.

CN118277457BActive Publication Date: 2024-09-10TIANJIN NANKAI UNIV GENERAL DATA TECH
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202410704682.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-06-03
Publication Date
2024-09-10
Estimated Expiration
2044-06-03

AI Technical Summary

Technical Problem

In large-scale clusters and high-concurrency environments, page turning query performance degradation and result consistency are difficult to guarantee, especially due to the increase in IO and computing overhead caused by sorting operations, which affects data migration and summary processing.

Method used

A paging query method with consistent result sets is adopted. The starting shard is determined by calculating the hash value, and the materialization of the sharded result set is performed serially to avoid sorting operations and ensure the consistency and performance of the paging query results.

Benefits of technology

Without reducing page turning query performance, the result set consistency is maintained, the performance degradation of the sorting operator is reduced, the load is balanced, computing hot spots are avoided, and query efficiency is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118277457B
    Figure CN118277457B
Patent Text Reader

Abstract

The present invention relates to the technical field of paging query of cluster databases, and discloses a paging query method and system with consistent result sets, the method comprising: obtaining a paging query statement, the paging query statement comprising a table name, query content, offset number of items and number of items obtained; querying and obtaining the number of result items of each shard of the table according to the paging query statement; calculating the starting shard of the query homepage using the cluster name, database name and table name; calculating the result set range of each shard according to the starting shard, the number of result items of each shard, the offset number of items and the number of items obtained; and serially executing the materialization of the result sets of the shards according to the result set range, aggregating the materialized results of the result sets, and obtaining the paging query results. The present invention does not produce performance degradation with the increase of offset, and can maintain the paging query performance while ensuring the consistency of the paging result set.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of page turning query of cluster databases, and in particular to a page turning query method and system for consistent result sets. Background Art

[0002] At present, for large-scale business application systems, the data volume is mostly above 100T level. In such a large data volume environment, how to provide fast query to end users will become more and more important. The Chinese invention patent application publication number CN116680317A discloses that the present disclosure provides a multi-table query paging method, device and electronic device, which relates to the field of data query. The specific steps are: obtaining a query request, determining a target table according to the query request; determining the target data corresponding to the query request in the cache; querying the target data according to the query request to obtain feedback data, and generating a response message according to the feedback data.

[0003] At the business or application level, for the same fixed query statement, only part of the query result set is displayed or obtained each time in the screen display or subsequent data processing. We call this page turning. Usually, to achieve the need for page turning, SQL (Structured Query Language) generally uses the limit offset clause to achieve it. At the same time, in order to ensure the consistency of the calculation results, the sorting operation will be performed first, that is, the primary key is sorted using the order by clause, and then the limit offset clause is used to calibrate the result range.

[0004] However, as more and more pages are viewed, the performance will become slower and slower. This is mainly because as the offset increases, the amount of data that needs to be read and sorted will increase significantly, significantly increasing the system's IO and computing overhead. In addition, sorting itself is also an aggregation operation, which will ultimately be limited by the computing performance of a single node. If the sorting operation with high performance overhead is removed, the consistency of the results of page-turning queries in large-scale clusters and high-concurrency environments cannot be guaranteed. Summary of the invention

[0005] The present invention aims to solve the problem of how to reduce the aggregation processing such as mass data migration by optimizing the scheduling of cluster nodes in a large-scale cluster environment without sorting, and how to ensure the consistency of paging results in a high-concurrency environment. To this end, the present invention provides a paging query method and system with consistent result sets, which ensure the consistency of paging query results without degradation of paging query performance. The consistency of paging query results means that the content and the order of the result set in the same page (not referring to the ascending / descending order of values) are the same and do not change.

[0006] The present invention provides a page turning query method with consistent result set, and the technical scheme adopted is as follows: comprising:

[0007] Obtain a page-turning query statement, wherein the page-turning query statement includes a table name, a query content, a number of offset entries, and a number of obtained entries;

[0008] According to the page-turning query statement, the number of result entries of each shard of the table is queried;

[0009] The string formed by concatenating the cluster name, library name and table name is used as input to calculate the hash value, and the total number of shards is modulo the hash value to obtain the starting shard of the query homepage; the cluster name and library name are the names of the cluster and library where the table is located;

[0010] Calculate the result set range of each shard according to the starting shard, the number of result entries of each shard, the number of offset entries, and the number of obtained entries;

[0011] According to the result set range, the result set materialization of the shards is executed serially.

[0012] According to the materialized results of the result set, the page-turning query results are obtained.

[0013] Furthermore, the calculation algorithm of the hash value is a CRC32 encryption algorithm.

[0014] Furthermore, the number of result items is the number of items of the query content in the shard.

[0015] Furthermore, the result set range of each shard is the number of offset entries and the number of acquisition entries of each shard.

[0016] Furthermore, the calculation process of the result set range of each shard is as follows:

[0017] s1: Starting from the starting shard, traverse all shards in order. If the count of the current shard is greater than the offset, determine whether count>offset. If so, proceed to s2, otherwise proceed to s7; count is the number of results, and offset is the offset value;

[0018] s2: Mark the current shard as the shard to be queried, assign a value to s_offset so that s_offset is equal to offset, that is, set s_offset=offset, and then enter s3; s_offset is the offset value of the shard to be queried;

[0019] s3: If the difference between count and offset is greater than limit, it determines whether count-offset>limit is true. If so, it goes to s4, otherwise it goes to s5; limit is the extracted value;

[0020] s4: Assign a value to s_limit to make it equal to limit, that is, set s_limit=limit, and go to s6; s_limit is the value to be queried for the shard to be queried;

[0021] s5: Assign a value to s_limit so that s_limit is equal to the difference between count and offset, that is, s_limit = count - offset, and enter s6;

[0022] s6: Assign a value to limit so that the new value of limit is equal to the difference between the original value of limit and s_limit, that is, let limit = limit - s_limit. If the new value of limit is 0, exit the loop, otherwise offset = 0 and return to s1.

[0023] s7: Assign a value to offset so that the new value of offset is equal to the difference between the original value of offset and count, that is, set offset = offset - count, and return to s1.

[0024] The present invention also provides a page-turning query system with consistent result sets, which adopts the following technical solution: comprising a cluster node, a cluster layer executor and a plurality of computing nodes, wherein the cluster node is connected to the cluster layer executor, and the cluster layer executor is connected to the plurality of computing nodes.

[0025] The cluster node is used to obtain a page-turning query statement and send it to the cluster layer executor; the page-turning query statement includes a table name, query content, offset number of entries and acquisition number of entries,

[0026] The cluster layer executor is used to generate a conditional filtering statement according to the paging query statement, and send it to the computing node where each shard of the table is located; use the string formed by splicing the cluster name, library name and table name as input to calculate the hash value, and take the modulus of the total number of shards by the hash value to obtain the starting shard of the query homepage, and the cluster name and library name are the names of the cluster and library where the table is located; calculate the result set range of each shard according to the starting shard, the number of result items of each shard, the number of offset items and the number of acquired items; generate the paging query sub-statement of each shard according to the result set range, and send it serially to the computing node where the corresponding shard is located in sequence; generate the paging query result according to the materialized result of the result set;

[0027] The computing node is used to execute the conditional filtering statement, query the number of result items for each shard of the table, and send the number of result items to the cluster layer executor; serially execute the page query sub-statements, materialize the result set for the shard, and send the result of the result set materialization to the cluster layer executor.

[0028] Furthermore, the table is distributed on multiple computing nodes, a portion of the content of the table on a computing node is a shard of the table, and the number of result entries is the number of entries of the query content in the shard.

[0029] Furthermore, a plurality of the computing nodes execute the conditional filtering statements in parallel.

[0030] The present invention also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned page-turning query method with consistent result sets is implemented.

[0031] The present invention also provides a computer program product, including a computer program, which implements the above-mentioned page turning query method with consistent result set when executed by a processor.

[0032] The above one or more technical solutions in the embodiments of the present invention have at least one of the following technical effects:

[0033] 1. The present invention is applicable to paging query scenarios that do not require sorting operations on the result set but require consistency of the result set. It can maintain the performance of paging queries while ensuring consistency of the paging result set without causing performance degradation as the offset increases. The present invention does not use the order by clause, and the result sets obtained by querying the same page are consistent. Since there are no aggregation operations such as sorting, the distributed paging query plan will not generate intermediate table steps, eliminating the performance degradation caused by the sorting operator, and confirming that the executor directly distributes the statement to each computing node.

[0034] 2. The present invention fully considers that the query and return of the number of result entries of each shard of the table have no effect on the consistency of the result set, and executes in parallel by default, thus shortening the query time.

[0035] 3. The present invention uses the cluster name + library name + table name of different tables as dependent variables to calculate the hash value, and then the hash value is modulo the total number of shards to determine the starting shard of the query home page. It can not only ensure that the starting shard of the query home page calculated on different cluster layer executors is consistent, but also ensure to the greatest extent possible that when querying pages of different tables, the starting shard of the query home page is located at different computing nodes, solving the computing hotspot problem in the case of concurrent queries, and can effectively balance the load and reduce the possibility of hotspots.

[0036] 4. The cluster layer executor of the present invention sequentially sends the page-turning query sub-statements to the computing nodes where the corresponding shards are located in order to ensure the consistency of the result set for each page-turning query. After receiving the statement, the computing node executes it serially in the result set materialization and final sending stages, which also ensures the consistency of the page-turning results.

[0037] Additional aspects and advantages of the present invention will be given in part in the following description and in part will be obvious from the following description, or will be learned through practice of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0039] Figure 1 It is a flow chart of the method provided by the present invention.

[0040] Figure 2 It is a structural schematic diagram of the system provided by the present invention.

[0041] Reference numerals:

[0042] 1. Cluster node; 2. Cluster layer executor; 3. Computing node. DETAILED DESCRIPTION

[0043] In order to make the purpose, technical scheme and advantages of the present invention clearer, the technical scheme of the present invention will be clearly and completely described below in conjunction with the drawings in the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present invention. The following embodiments are used to illustrate the present invention, but cannot be used to limit the scope of the present invention.

[0044] In the description of this specification, the description referring to terms such as "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the embodiments of the present invention. In this specification, the schematic expressions of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples. In addition, without contradiction, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples.

[0045] The following is a further detailed description of the present invention in conjunction with Figure 1-Figure 2 to describe a paging query method and system with consistent result sets of the present invention:

[0046] In this embodiment, as Figure 1 shown, a paging query method with consistent result sets is provided, including the following steps:

[0047] Step 1: Obtain a paging query statement, where the paging query statement includes a table name, query content, offset number, and fetch number. The paging query statement is generally written as select from t where a = 10 limit 100, 30. t is the table name, where a = 10 is the query content, 100 is the offset number, and 30 is the fetch number. According to the table name, the cluster name and database name where the table is located can be determined. Since there are no aggregation operations such as sorting, no intermediate table steps will be generated, saving the performance degradation caused by the sorting operator.

[0048] Step 2: According to the paging query statement, a conditional filtering statement for each table shard can be generated: select count( ) from t_n (shard) where a = 10. According to the conditional filtering statement, the result number of each shard of the table is queried. The result number is the number of the query content in the shard. The operation of querying the result number of the shard has no impact on the consistency of the result set and can be executed in parallel.

[0049] According to the paging query statement, a string formed by splicing the cluster name, database name, and table name is used as the input to calculate the hash value. The calculation algorithm of the hash value is the CRC32 encryption algorithm. By taking the modulo of the hash value by the total number of shards, the starting shard of the query home page is obtained. The cluster name and database name are the names of the cluster and database where the table is located. After determining the starting shard of the query home page, the query order of each shard can be determined.

[0050] If the executor uses the default first shard as the initial shard for all tables (the initial page of a page-turning query will most likely query the first shard), then in the scenario of concurrent queries on different tables, the pressure on the computing node where the first shard is located will inevitably be too high, forming a performance bottleneck. The starting shard for the query home page can be calculated based on the cluster name + database name + table name where different tables are located, so that the initial shards of different tables can be broken up. In this way, when concurrent page-turning queries are performed on different tables, the load can be effectively balanced and the possibility of hot spots can be reduced.

[0051] Step 3: Calculate the result set range of each shard based on the starting shard, the number of result items, the number of offset items, and the number of items obtained for each shard. The result set range of each shard is the number of offset items and the number of items obtained for each shard.

[0052] The calculation process of the result set range of each shard is:

[0053] s1: Starting from the starting shard, traverse all shards in order. If the count of the current shard is greater than the offset, determine whether count>offset. If so, proceed to s2, otherwise proceed to s7; count is the number of results, and offset is the offset value;

[0054] s2: Mark the current shard as the shard to be queried, assign a value to s_offset so that s_offset is equal to offset, that is, set s_offset=offset, and then enter s3; s_offset is the offset value of the shard to be queried;

[0055] s3: If the difference between count and offset is greater than limit, it determines whether count-offset>limit is true. If so, it goes to s4, otherwise it goes to s5; limit is the extracted value;

[0056] s4: Assign a value to s_limit to make it equal to limit, that is, set s_limit=limit, and go to s6; s_limit is the value to be queried for the shard to be queried;

[0057] s5: Assign a value to s_limit so that s_limit is equal to the difference between count and offset, that is, s_limit = count - offset, and enter s6;

[0058] s6: Assign a value to limit so that the new value of limit is equal to the difference between the original value of limit and s_limit, that is, let limit = limit - s_limit, and then determine whether the new value of limit is 0. If the new value of limit is 0, exit the loop, otherwise offset = 0 and return to s1;

[0059] s7: Assign a value to offset so that the new value of offset is equal to the difference between the original value of offset and count, that is, set offset = offset - count, and return to s1.

[0060] Step 4: Based on the result set range, a page-turning query sub-statement can be generated: select from t_n(shard) where a = 10 limit s_offset, s_limit. According to the query order of each shard determined in step 2, the result set of the shard is materialized serially to ensure the consistency of the result set during each page query.

[0061] Step 5: Obtain the page-turning query results according to the materialization order of the sharded result sets and the materialized results of the result sets, and complete the page-turning query.

[0062] The present invention calculates the result set range of each shard according to the starting shard, the number of result items of each shard, the number of offset items and the number of acquired items. The number of offset items and the number of acquired items in the paging query statement are decomposed into the number of offset items and the number of acquired items of each shard, and the paging query result corresponding to each shard is determined. The order by clause is not used in the entire paging query process, and there is no aggregation operation such as sorting. The paging query result meets the result set consistency requirement and can avoid performance degradation as the offset increases.

[0063] In this embodiment, Figure 2 As shown, a page-turning query system with consistent result sets is provided, and the technical solution adopted is as follows: it includes a cluster node 1, a cluster layer executor 2 and multiple computing nodes 3, the cluster node 1 is connected to the cluster layer executor 2, and the cluster layer executor 2 is connected to the multiple computing nodes 3.

[0064] The cluster node 1 is used to obtain a page-turning query statement and send it to the cluster layer executor 2; the page-turning query statement includes a table name, query content, offset number of entries and acquisition number of entries.

[0065] The cluster layer executor 2 is used to generate a conditional filtering statement according to the paging query statement, and send it to the computing node 3 where each shard of the table is located; use the string formed by splicing the cluster name, library name and table name as input to calculate the hash value, the hash value calculation algorithm is the CRC32 encryption algorithm, and the total number of shards is modulo the hash value to obtain the starting shard of the query homepage, and the cluster name and library name are the names of the cluster and library where the table is located; according to the starting shard, the number of result items, the number of offset items and the number of acquired items of each shard, the result set range of each shard is calculated; according to the result set range, a paging query sub-statement for each shard is generated, and it is sent serially to the computing node 3 corresponding to the shard in sequence; and the paging query result is generated according to the materialized result of the result set.

[0066] The computing node 3 is used to execute the conditional filtering statement in parallel, query the number of result items for each shard of the table, and send the number of result items to the cluster layer executor 2; execute the page query sub-statement in serial, materialize the result set of the shard, and send the result of the result set materialization to the cluster layer executor 2.

[0067] The table is distributed on multiple computing nodes 3, the partial content of the table on one computing node 3 is a shard of the table, and the number of result entries is the number of the query content in the shard.

[0068] The result set range of each shard is the number of offset entries and the number of entries obtained for each shard. The calculation process of the result set range of each shard is:

[0069] s1: Starting from the starting shard, traverse all shards in order. If the count of the current shard is greater than the offset, determine whether count>offset. If so, proceed to s2, otherwise proceed to s7; count is the number of results, and offset is the offset value;

[0070] s2: Mark the current shard as the shard to be queried, assign a value to s_offset so that s_offset is equal to offset, that is, set s_offset=offset, and then enter s3; s_offset is the offset value of the shard to be queried;

[0071] s3: If the difference between count and offset is greater than limit, it determines whether count-offset>limit is true. If so, it goes to s4, otherwise it goes to s5; limit is the extracted value;

[0072] s4: Assign a value to s_limit to make it equal to limit, that is, set s_limit=limit, and go to s6; s_limit is the value to be queried for the shard to be queried;

[0073] s5: Assign a value to s_limit so that s_limit is equal to the difference between count and offset, that is, s_limit = count - offset, and enter s6;

[0074] s6: Assign a value to limit so that the new value of limit is equal to the difference between the original value of limit and s_limit, that is, let limit = limit - s_limit, and then determine whether the new value of limit is 0. If the new value of limit is 0, exit the loop, otherwise offset = 0 and return to s1;

[0075] s7: Assign a value to offset so that the new value of offset is equal to the difference between the original value of offset and count, that is, set offset = offset - count, and return to s1.

[0076] The following is a description of the working principle of this page-turning query system with Table 1. Table 1 shows a 3-node cluster vc and two randomly distributed tables under its test database. The three computing nodes are named n1, n2, and n3. The two distributed tables are named t1 and t2. The shards of each table on each computing node are named t1_n1, t1_n2, t1_n3 and t2_n1, t2_n2, ​​t2_n3.

[0077] Table 1 Example of the range of each shard result set

[0078]

[0079] Cluster node A receives the SQL and interprets it as a page-turning query statement for table t1 that does not require sorting: select from t1where a = 10 limit 100, 30. The meaning of the page-turning query statement is: first, filter the column a in table t1 with the single table condition where a=10, then offset the filtered result set by 100, and finally take 30 results based on this as the benchmark and return them. Cluster node A sends the page-turning query statement to the cluster layer executor.

[0080] The cluster layer executor 2 generates a conditional filtering statement based on the page query statement, and sends it to the computing node 3 where each shard of table t1 is located. The conditional filtering statement is select count( ) from t_n (shard) where a = 10. In this example, there are three shards, so the conditional filtering statements are select count( )from t1_n1 where a = 10; select count( ) from t1_n2 where a = 10; selectcount( ) from t1_n3 where a = 10.

[0081] Since parallel execution has no effect on the consistency of the result set, after receiving the conditional filtering statement, the three computing nodes 3 execute the conditional filtering statement in parallel by default, query the number of result items for each shard of the table, and send the number of result items to the cluster layer executor 2. The number of result items after filtering for each shard is 50, 60, and 50 respectively, as shown in the brackets after the shard in Table 1.

[0082] The cluster layer executor 2 uses the string (vc+test+t1) formed by concatenating the cluster name vc, the library name test and the table name t1 as input, calculates the hash value through the CRC32 encryption algorithm, takes the modulus of the total number of shards (3) through the hash value, obtains the starting shard of the query homepage, and determines that the starting shard of the table is t1_n1. The query order of the three shards is t1_n1, t1_n2 and t1_n3.

[0083] The cluster layer executor 2 calculates the result set range of each shard according to the starting shard: t1_n1, the number of result items for each shard: 50, 60 and 50, the number of offset items: 100, and the number of items obtained: 30.

[0084] The calculation process of the result set range is as follows:

[0085] a. The calculation process performed on t1_n1:

[0086] s1: Start execution from the starting slice t1_n1, where count=50, and judge count>offset, 50>100, which is not true, and enter s7;

[0087] s7: Assign a value to offset, set offset=offset-count, calculate offset=100-50=50, and return s1. The starting shard t1_n1 has only 50 data, which is not enough for the offset. There is no s_limit, so there is no need to issue a page-turning query sub-statement.

[0088] b. The calculation process performed on t1_n2:

[0089] s1: t1_n1 has been executed, and the next shard t1_n2 of t1_n1 is executed. The count of t1_n2 is 60. The count>offset is checked, and 60>50. The result is true, and the process goes to s2.

[0090] s2: Mark t1_n2 as the shard to be queried, set s_offset=50, and then enter s3;

[0091] s3: judge count-offset>limit, 60-50>30, the result is not established, enter s5;

[0092] s5: Assign a value to s_limit, set s_limit=count-offset, calculate s_limit=60-50=10, and enter s6;

[0093] s6: Assign limit a value, set limit = limit - s_limit, and calculate limit = 30 - 10 = 20. The new value of limit is not 0. Set offset = 0 and return s1. Since t1_n2 has 60 records, plus the 50 records of t1_n1, it not only meets the offset number but also has a surplus. The calculated s_offset of t1_n2 is 50 and s_limit is 10. The page query substatement of t1_n2 is: select from t1_n2 where a = 10 limit 50, 10.

[0094] c. The calculation process performed on t1_n3:

[0095] s1: Execute t1_n3, count of t1_n3 = 50, judge count>offset, 50>0, the result is true, enter s2;

[0096] s2: Mark t1_n3 as the shard to be queried, set s_offset = 0, and then enter s3;

[0097] s3: judge count-offset>limit, 50-0>20, the result is true, enter s4;

[0098] s4: Assign a value to s_limit, set s_limit=limit, that is, s_limit=20, and enter s6;

[0099] s6: Assign limit a value, set limit = limit - s_limit, calculate limit = 20 - 20 = 0, the new value of limit is 0, and exit the loop. t1_n3 has 50 data items, including the previous 10 items, which already meets the requirement of 30 result items. Calculate s_offset of t1_n3 to be 0 and s_limit to be 20. The page query substatement of t1_n3 is: select from t1_n3where a = 10 limit 0, 20.

[0100] The cluster layer executor 2 calculates the offset value of the shard to be queried and the extracted value to be queried of the shard to be queried of each shard. The value of the offset value affects the offset value of the shard to be queried of each shard, and the content of the offset does not need to be read. The value of the offset value in the page turning query statement has almost no effect on the performance of the system, that is, the present invention can avoid performance degradation as the offset increases.

[0101] The cluster layer executor 2 sends the two page-turning query sub-statements serially to the computing nodes n2 and n3 where t1_n2 and t1_n3 are located. The general format of the page-turning query sub-statement is: select from t_n (shard) where a = 10limit s_offset, s_limit.

[0102] Computing nodes n2 and n3 execute the page-turning query sub-statement in series, that is, after n2 finishes executing the page-turning query sub-statement, n3 starts to execute the page-turning query sub-statement. Computing nodes n2 and n3 materialize the result set of the shards and send the result of the result set materialization to the cluster layer executor 2.

[0103] The cluster layer executor 2 generates a page-turning query result according to the materialized result of the result set.

[0104] Similarly, cluster node B receives the SQL and parses it into a page-turning query statement for table t2 that does not require sorting: select from t2 where a = 10 limit 100, 30. Send the page-turning query statement to the cluster layer executor 2.

[0105] The cluster layer executor 2 generates a conditional filtering statement according to the page-turning query statement, and sends it to the computing nodes n1, n2 and n3 where each shard of the table t2 is located.

[0106] Computing nodes n1, n2, and n3 execute the conditional filtering statement in parallel, and the number of results after filtering of each shard is 10, 120, and 5 respectively.

[0107] The cluster layer executor 2 takes the string vc+test+t2 as input, calculates the hash value through the CRC32 encryption algorithm, and determines the starting shard of the table as t2_n2 by taking the hash value modulo 3. Then the query order of the three shards is t2_n2, ​​t2_n3 and t2_n1.

[0108] The cluster layer executor 2 calculates the result set range of each shard based on the starting shard: t2_n2, ​​the number of result items for each shard: 10, 120 and 5, the number of offset items: 100, and the number of items obtained: 30. The starting shard t2_n2 has 120 data items, which satisfies the offset of 100 and has a surplus. The statement issued is select from t2_n2 where a = 10 limit 100,20; then look at t2_n3 in sequence and there are 5 records, so there is select from t2_n3 where a = 10 limit 0, 5; Finally, look at t2_n1, because it has 10 data, including the previous 25, taking 5 can meet the requirement of 30 result items, so there is select from t2_n1 where a = 10 limit 0, 5.

[0109] The cluster layer executor 2 sends the three page-turning query sub-statements in serial order to the computing nodes n2, n3 and n1 where the corresponding 2_n2, ​​t2_n3 and t2_n1 are located.

[0110] The computing nodes n2, n3 and n1 execute the page-turning query sub-statement in series, materialize the result set of the shards, and send the result of the result set materialization to the cluster layer executor 2.

[0111] The cluster layer executor 2 generates a page-turning query result according to the materialized result of the result set.

[0112] When executing a page-turning query statement that does not require sorting for table t1 and table t2, this embodiment queries the starting shards of the home page at different computing node locations, thereby solving the computing hotspot problem that occurs in the case of concurrent queries, effectively balancing the load, and reducing the possibility of hotspots.

[0113] This embodiment also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned page-turning query method with consistent result sets is implemented.

[0114] This embodiment also provides a computer program product, including a computer program, which, when executed by a processor, implements the above-mentioned page-turning query method with consistent result sets.

[0115] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A page-turning query method with consistent result set, characterized in that: include: Obtain a page-turning query statement, wherein the page-turning query statement includes a table name, a query content, a number of offset entries, and a number of obtained entries; According to the page-turning query statement, a conditional filtering statement is generated for each table shard, and according to the conditional filtering statement, the number of result items of each shard of the table is queried; the number of result items is the number of items of the query content in the shard; The string formed by concatenating the cluster name, database name, and table name is used as input to calculate the hash value. The hash value is modulo the total number of shards to obtain the starting shard for querying the homepage, thereby determining the query order of each shard. The cluster name and library name are the names of the cluster and library where the table is located; Calculate the result set range of each shard according to the starting shard, the number of result entries of each shard, the number of offset entries, and the number of obtained entries; Generate a page-turning query sub-statement according to the result set range, and execute the materialization of the result set of the shards in series according to the determined query order of each shard. According to the materialization order of the sharded result sets, the page-turning query results are obtained based on the materialization results of the result sets; The result set range of each shard is the number of offset entries and the number of entries obtained for each shard. The calculation process of the result set range of each shard is: s1: Starting from the starting shard, traverse all shards in order. If the count of the current shard is greater than the offset, enter s2, otherwise enter s7; count is the number of result entries, and offset is the offset value; s2: Mark the current shard as the shard to be queried, assign a value to s_offset so that s_offset is equal to offset, and then enter s3; s_offset is the offset value of the shard to be queried; s3: If the difference between count and offset is greater than limit, go to s4, otherwise go to s5; limit is the extracted value; s4: Assign a value to s_limit to make it equal to limit, and then go to s6; s_limit is the value to be queried for the shard to be queried; s5: Assign a value to s_limit so that s_limit is equal to the difference between count and offset, and enter s6; s6: Assign a value to limit so that the new value of limit is equal to the difference between the original value of limit and s_limit. If the new value of limit is 0, exit the loop; otherwise, offset = 0 and return to s1. s7: Assign a value to offset so that the new value of offset is equal to the difference between the original value of offset and count, and return s1.

2. A page turning query method with consistent result set as claimed in claim 1, characterized in that: The calculation algorithm of the hash value is the CRC32 encryption algorithm.

3. A page-turning query system with consistent result sets, characterized in that: The method for executing a page-turning query with consistent result sets as claimed in any one of claims 1 to 2 comprises a cluster node, a cluster layer executor and a plurality of computing nodes, wherein the cluster node is connected to the cluster layer executor, and the cluster layer executor is connected to the plurality of computing nodes. The cluster node is used to obtain a page turning query statement and send it to the cluster layer executor; The page turning query statement includes the table name, query content, offset number and acquisition number. The cluster layer executor is used to generate a conditional filtering statement according to the page-turning query statement, and send it to the computing node where each shard of the table is located; The string formed by concatenating the cluster name, library name and table name is used as input to calculate the hash value, and the total number of shards is modulo the hash value to obtain the starting shard of the query homepage. The cluster name and library name are the names of the cluster and library where the table is located; According to the starting shard, the number of result entries, the number of offset entries, and the number of obtained entries of each shard, the result set range of each shard is calculated; according to the result set range, a page-turning query sub-statement of each shard is generated, and the sub-statements are sent to the computing nodes corresponding to the shards in sequence; Generate a page-turning query result according to the materialized result of the result set; the result set range of each shard is the number of offset entries and the number of acquisition entries of each shard, and the calculation process of the result set range of each shard is: s1: Starting from the starting shard, traverse all shards in order. If the count of the current shard is greater than the offset, enter s2, otherwise enter s7; count is the number of result entries, and offset is the offset value; s2: Mark the current shard as the shard to be queried, assign a value to s_offset so that s_offset is equal to offset, and then enter s3; s_offset is the offset value of the shard to be queried; s3: If the difference between count and offset is greater than limit, go to s4, otherwise go to s5; limit is the extracted value; s4: Assign a value to s_limit to make it equal to limit, and then go to s6; s_limit is the value to be queried for the shard to be queried; s5: Assign a value to s_limit so that s_limit is equal to the difference between count and offset, and enter s6; s6: Assign a value to limit so that the new value of limit is equal to the difference between the original value of limit and s_limit. If the new value of limit is 0, exit the loop; otherwise, offset = 0 and return to s1. s7: Assign a value to offset so that the new value of offset is equal to the difference between the original value of offset and count, and return s1; The computing node is used to execute the conditional filtering statement, query and obtain the number of result entries for each shard of the table, and send the number of result entries to the cluster layer executor; The page-turning query sub-statements are executed serially, result sets are materialized for the shards, and the result set materialization results are sent to the cluster layer executor.

4. A page-turning query system with consistent result set as claimed in claim 3, characterized in that: The table is distributed on multiple computing nodes, and a portion of the table on one computing node is a shard of the table.

5. A page turning query system with consistent result set as claimed in claim 3 or 4, characterized in that: The plurality of computing nodes execute the conditional filtering statements in parallel.

6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, a page turning query method with consistent result sets according to any one of claims 1 to 2 is implemented.

7. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, a page turning query method with consistent result sets as described in any one of claims 1 to 2 is implemented.

Citation Information

Patent Citations

  • Multi-table query paging method and device and electronic equipment

    CN116680317A

  • Data query method and device, equipment and storage medium

    CN111752986A

  • Method and terminal for improving deep paging query efficiency of database

    CN114490737A

  • Data query method and device, equipment and medium

    CN116644090A

  • Distributed database-based result set paging return method and system

    CN117951184A