Non-equivalent connection query method, device and equipment of SQL (Structured Query Language) and storage medium
By constructing a table-hopping table to determine the correspondence between point sequence and interval sequence, the problem of inefficient non-equal value connection query in the Spark data processing framework is solved, and more efficient query performance and resource utilization are achieved.
Patent Information
- Application Number
- CN202410306232.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-18
- Publication Date
- 2024-11-05
AI Technical Summary
The inefficiency of non-equivalent connection queries in the existing Spark data processing framework is especially when processing large-scale data, which causes the connection process to take a long time or cannot be completed due to exhaustion of disk space.
By constructing the first hop table and the second hop table, the overlap and non-overlapping situations of interval sequences are processed respectively, the correspondence between point sequences and interval sequences is determined, the spatial complexity and time complexity of the query are reduced, and the disk space resource occupation is reduced.
Improves the efficiency of non-equal connection queries, reduces disk space resource usage, and significantly improves query performance.
Smart Images

Figure CN118897841A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data query, and in particular to an SQL non-equivalent join query method, device, equipment and storage medium. Background Art
[0002] In the process of modern big data processing and big data analysis, data workers often encounter query challenges involving non-equijoins, especially when performing join operations containing conditions such as "whether a point is in an interval" or "whether two intervals intersect", such queries often show inefficiency. In the existing Spark data processing framework, such non-equijoins are usually implemented using the BroadcastNestedLoop strategy. This implementation method has a particularly obvious performance bottleneck when processing large-scale data, for example, when the amount of data in the two tables involved is large, for example, when the number of records in each table exceeds 1,000. At this time, the space complexity and time complexity of the BroadcastNestedLoop strategy both show linear growth. The efficiency problem of this strategy causes the join process to take hours or even longer to complete, and sometimes even fails to produce results due to disk space exhaustion. Summary of the invention
[0003] The present invention provides a SQL non-equijoin query method, device, equipment and storage medium, which are used to solve the technical problem that the space complexity and time complexity of non-equijoin query in the SQL query of the prior art are relatively large.
[0004] In order to solve the above technical problems, in a first aspect, the present invention provides a SQL non-equijoin query method, the method comprising:
[0005] Get point sequence and interval sequence;
[0006] If there are no overlapping intervals in the interval sequence, the correspondence between the point values in the point sequence and the intervals in the interval sequence is determined according to the constructed first skip table; the first value of the element in the first skip table is the element of the interval in the interval sequence, and the second value of the element in the first skip table is a preset value set in relation to the position of the first value of the element in the first skip table in the interval sequence;
[0007] If there are overlapping intervals in the interval sequence, the correspondence between the point values in the point sequence and the intervals in the interval sequence is determined according to the constructed second skip table; the first value of the element in the second skip table is an element of the interval in the interval sequence, and the second value of the element in the second skip table is a preset value related to the position of the interval associated with the first value of the element in the second skip table in the interval sequence.
[0008] Optionally, the step of constructing the first jump table includes:
[0009] Sorting the intervals in the interval sequence from small to large according to the starting node value of each interval;
[0010] Traversing each interval in the sorted interval sequence, and converting the expression of each interval into an end node value of the interval and a preset value related to the position of the end node value in the interval sequence;
[0011] The intervals in the interval sequence are merged to construct a first skip list with the end node value of each interval as the first value of each element in the skip list and a preset value related to the position of the end node value of the interval in the interval sequence as the second value of each element in the skip list.
[0012] Optionally, determining the correspondence between the point values in the point sequence and the intervals in the interval sequence according to the constructed first skip table includes:
[0013] The current point value in the point sequence is compared with the first value of each element in the first jump table in turn. If the current point value in the point sequence is greater than the first value of the current element in the first jump table and less than the first value of the next element in the first jump table, it is determined that there is a corresponding relationship between the current point value and the interval pointed to by the second value of the next element in the first jump table.
[0014] Optionally, the step of constructing the second jump table includes:
[0015] Extracting the start node value and the end node value of each interval in the interval sequence, removing duplicates and sorting them to obtain a reconstructed sequence;
[0016] Constructing a hash table according to the interval sequence, determining the intervals associated with the start node value and the end node value of each interval in the interval sequence in the interval sequence, and setting preset values related to the positions of the associated intervals in the interval sequence;
[0017] According to the reconstruction sequence and the hash table, a second skip table is constructed in which the element in the reconstruction sequence having the same value as the starting node in the interval sequence is used as the first value of each element in the skip table, and the preset value related to the position of the associated interval of the element obtained in the hash table in the interval sequence is used as the second value of each element in the skip table.
[0018] Optionally, determining the correspondence between the point values in the point sequence and the elements in the interval sequence according to the constructed second skip table includes:
[0019] The current point value in the point sequence is compared with the first value of each element in the second jump table in turn. If the current point value in the point sequence is greater than the first value of the current element in the second jump table and less than the first value of the next element in the second jump table, it is determined that there is a corresponding relationship between the current point value and the interval associated with the position pointed to by the second value of the current element in the second jump table.
[0020] Optionally, the SQL non-equijoin query method further includes traversing the interval sequence sorted from small to large according to the start node value of each interval, and determining whether the end node value of the previous interval of two adjacent intervals in the interval sequence is greater than the start node value of the next interval of the two adjacent intervals; if so, there are overlapping intervals in the interval sequence; otherwise, there are no overlapping intervals in the interval sequence.
[0021] Optionally, when there are overlapping intervals in the interval sequence, it also includes updating the end node value of the interval with the smallest start node value in the two adjacent intervals with overlap in the interval sequence to the largest end node value in the two adjacent intervals with overlap, obtaining an updated interval, and deleting the original two adjacent intervals with overlap; the updated interval sequence is processed as an interval sequence without overlapping intervals.
[0022] In a second aspect, the present invention provides a non-equivalent join query device of SQL, comprising a sequence acquisition module, a first query module and a second query module;
[0023] The sequence acquisition module is used to acquire point sequences and interval sequences;
[0024] The first query module is used to determine the correspondence between the point value in the point sequence and the interval in the interval sequence according to the constructed first skip table if there is no overlapping interval in the interval sequence; the first value of the element in the first skip table is the element of the interval in the interval sequence, and the second value of the element in the first skip table is a preset value set in relation to the position of the first value of the element in the first skip table in the interval sequence;
[0025] The second query module is used to determine the correspondence between the point values in the point sequence and the intervals in the interval sequence according to the constructed second skip table if there are overlapping intervals in the interval sequence; the first value of the element in the second skip table is the element of the interval in the interval sequence, and the second value of the element in the second skip table is a preset value related to the position of the interval associated with the first value of the element in the second skip table in the interval sequence.
[0026] In a third aspect, the present invention provides a non-equijoin query device for SQL, comprising a memory and a processor, wherein:
[0027] The memory is used to store computer programs;
[0028] The processor is used to read the program in the memory and execute the steps of the SQL non-equijoin query method provided in the first aspect.
[0029] In a fourth aspect, the present invention provides a computer-readable storage medium having a readable computer program stored thereon, which, when executed by a processor, implements the steps of the SQL non-equijoin query method provided in the first aspect above.
[0030] Compared with the prior art, the SQL non-equijoin query method, device, equipment and storage medium provided by the present invention have the following beneficial effects:
[0031] By obtaining a point sequence and an interval sequence; if there is no overlapping interval in the interval sequence, then determining the correspondence between the point value in the point sequence and the interval in the interval sequence according to a pre-constructed first skip table; the first value of the element in the first skip table is an element of the interval in the interval sequence, and the second value of the element in the first skip table is a preset value set in relation to the position of the first value of the element in the first skip table in the interval sequence; if there are overlapping intervals in the interval sequence, then determining the correspondence between the point value in the point sequence and the interval in the interval sequence according to a constructed second skip table; the first value of the element in the second skip table is an element of the interval in the interval sequence, and the second value of the element in the second skip table is a preset value set in relation to the position of the interval associated with the first value of the element in the second skip table in the interval sequence; in a non-equivalued join query of SQL, it is possible to reduce the space complexity and time complexity of the query, reduce the disk space resources required for the query, and improve the query efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0032] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in 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 only part of the embodiments of the present invention, rather than all of the embodiments. For ordinary technicians in this field, without paying creative work, other drawings obtained based on these drawings all fall within the scope of protection of this application.
[0033] Figure 1 It is a flowchart of a non-equijoin query method of SQL provided by an embodiment of the present invention;
[0034] Figure 2 It is a structural schematic diagram of a SQL non-equivalue join query device provided by an embodiment of the present invention;
[0035] Figure 3 It is a structural schematic diagram of a non-equivalent join query device of SQL provided by an embodiment of the present invention;
[0036] Figure 4 It is a structural schematic diagram of a computer-readable storage medium provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0037] In order to make the purpose, technical solution and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and specific embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0038] In order to make the description of the disclosed content more detailed and complete, the following is an illustrative description of the implementation mode and specific examples of the present invention; however, this is not the only form of implementing or applying the specific embodiments of the present invention. The implementation mode covers the features of multiple specific embodiments and the method steps and their sequence for constructing and operating these specific embodiments. However, other specific embodiments can also be used to achieve the same or equal functions and step sequences. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0039] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein.
[0040] In the description of the embodiments of the present application, "multiple" refers to two or more than two, and other quantifiers are similar and should be understood. The preferred embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention. In addition, the embodiments of the present application and the features therein may be combined with each other if there is no conflict.
[0041] Non-equijoin queries are common in big data processing. Possible application scenarios of non-equijoin queries may include logistics companies analyzing vehicle task highway fees. In this scenario, the vehicle task information is recorded in the company's task system, while the vehicle highway fees come from the statement of the national highway toll system. Only the license plate can be associated between the two pieces of data. There is no way to directly correspond to which task a specific highway fee belongs to. Considering the actual situation, the driving on the highway section occurs during the task execution period. With the help of the accounting time of the highway fee table, the task execution time is calculated as the highway fee of which task. It should be noted that the SQL non-equijoin query method execution code provided in the embodiment of the present invention needs to be encapsulated in the jar package in advance. Most big data computing engines support loading jar and can import user-defined functions. Only after importing the custom function can the SQL non-equijoin query method provided in the embodiment of the present invention be used. The specific embodiment of the SQL non-equijoin query method provided by the present invention is described as follows.
[0042] Example 1
[0043] like Figure 1 As shown, it is a flow chart of a SQL non-equijoin query method provided by an embodiment of the present invention. The SQL non-equijoin query method includes the following steps.
[0044] Step S101, obtaining a point sequence and an interval sequence;
[0045] Among them, the point sequence is a collection of multiple point values, the interval sequence is a collection of multiple intervals, and the interval includes the start node value and the end node value.
[0046] In a specific embodiment, the non-equijoin query of SQL will appear in the analysis scenario of the highway fee for vehicle tasks of logistics enterprises. In this scenario, the highway fee table comes from the statement of the national highway toll system, which includes the payment time and license plate number; the vehicle task table is recorded in the task system within the company, which includes the task start time and task end time and license plate number. Only the license plate number can be associated between these two data tables, but there is no way to directly correspond to which task a specific highway fee belongs to. For the convenience of explanation, the present invention exemplifies the content of the solution in conjunction with this scenario. It should be noted that the exemplification of the present invention in this scenario does not limit the applicability of the present invention to other actual scenarios of non-equijoin queries of other SQL.
[0047] In this step, for the highway toll table, the payment times in the table are grouped and aggregated according to the above license plate numbers, and a set of point values at several moments is obtained through processing, namely, the above point sequence; for the vehicle task table, the task start time and end time in the table are grouped and aggregated according to the above license plate numbers, and a set of interval values including the start time and end time is obtained through processing, namely, the above interval sequence.
[0048] Step S102: if there is no overlapping interval in the interval sequence, determine the correspondence between the point value in the point sequence and the interval in the interval sequence according to the constructed first skip table; the first value of the element in the first skip table is the element of the interval in the interval sequence, and the second value of the element in the first skip table is a preset value set in relation to the position of the first value of the element in the first skip table in the interval sequence;
[0049] The elements of the intervals in the interval sequence are values of each interval contained in the interval sequence that can be used to compare the size with the point value, and can be the starting node value of the interval, or the ending node value of the interval, or other values associated with the interval. In the constructed first skip list, the elements of the intervals in the interval sequence can be the ending node value of the interval.
[0050] As an optional implementation, the step of constructing the first jump table includes:
[0051] Sorting the intervals in the interval sequence from small to large according to the starting node value of each interval;
[0052] Traversing each interval in the sorted interval sequence, and converting the expression of each interval into an end node value of the interval and a preset value related to the position of the end node value in the interval sequence;
[0053] The intervals in the interval sequence are merged to construct a first skip list with the end node value of each interval as the first value of each element in the skip list and a preset value related to the position of the end node value of the interval in the interval sequence as the second value of each element in the skip list.
[0054] In a specific embodiment, the point sequence obtained by processing the highway fee table is set to a ’ , the interval sequence obtained by processing the vehicle task table is set to b ’ For interval sequence b ’ The intervals in are sorted from small to large according to the starting node value of each interval. The interval sequence b obtained after sorting is [(s_0, e_0), (s_1, e_1), …, (s_i, e_i), ...], where s_i represents the starting node value of the interval and e_i represents the ending node value of the interval.
[0055] Traverse each interval in the sorted interval sequence b, and convert the expression of each interval (s_i, e_i) into (s_i, -1), (e_i, i). (s_i, -1) is set to an invalid value, (e_i, i) contains the end point value e_i of the interval, and the preset value i related to the position of the end node value e_i in the interval sequence, that is, the serial number of the interval where the end node value e_i is located after the interval sequence is sorted, which also reflects the position of the interval in the interval sequence.
[0056] The intervals after the conversion expression in the interval sequence b are merged to obtain the first skip list c, c = [(s_0, -1), (e_0, 0), (s_1, -1), (e_1, 1), ..., (s_i, -1), (e_i, i), ..]. Among them, (s_i, -1), (e_i, i) are elements in the first skip list c, but because (s_i, -1) is set to an invalid value, the first value of each element in the first skip list c is the end node value e_i of the interval, and the second value of each element in the first skip list c is a preset value i related to the position of the end node value e_i in the above interval sequence. At the same time, the i value also reflects the position of the interval in the interval sequence.
[0057] As an optional implementation manner, determining the correspondence between the point values in the point sequence and the intervals in the interval sequence according to the constructed first jump table includes:
[0058] The current point value in the point sequence is compared with the first value of each element in the first jump table in turn. If the current point value in the point sequence is greater than the first value of the current element in the first jump table and less than the first value of the next element in the first jump table, it is determined that there is a corresponding relationship between the current point value and the interval pointed to by the second value of the next element in the first jump table.
[0059] As an optional implementation, before comparing the current point value of the point sequence with the first value of each element in the first jump list in sequence, the point values in the point sequence are first sorted from small to large.
[0060] In a specific embodiment, it is necessary to obtain a point sequence a ’ The corresponding relationship between the point values in and the intervals in interval sequence b is then the point sequence a obtained by processing the highway fee table ’The point values in are sorted from small to large, and the point sequence a = [p_0, p_1, … p_i, …] is obtained after sorting. The corresponding relationship between the elements in the point sequence a (i.e., point values) and the intervals in the interval sequence b is determined. By comparing the elements in a with the first value of the elements in the constructed first skip table c, an element in the first skip table c that meets the requirements is found, and then the corresponding interval in the interval sequence b is found by the second value of the element in the first skip table c.
[0061] Specifically, declare the serial number idx=0, which is used to traverse the first jump table c; declare the result set result=[]. For the first element p_0 in the point sequence a, starting from the first element c[0] in c, compare it with the first value c[0][0] of c[0]. If c[0][0] is smaller than p_0, compare it with the first value c[1][0] of the next element c[1] in c, and so on, until the first c[idx][0] larger than p_0 is found, which means that p_0 falls into the interval (c[idx-1][0], c[idx][0]); at this time, the second value c[idx][1] of c[idx] represents the sequence number of the interval in the interval sequence b that corresponds to the interval falling into (c[idx-1][0], c[idx][0]), so the corresponding interval in the interval sequence b is b[c[idx][1]], so the relationship (p_0, b[c[idx][1]]) is recorded, that is, it is determined that there is a corresponding relationship between the current point value and the interval pointed to by the second value of the next element in the first jump table mentioned above.
[0062] Then, the next element p_1 in the point sequence a is processed. Since the elements in the point sequence a are sorted from small to large, for the next element p_1 in the point sequence a, it is not necessary to continue to traverse from the first element in the first jump table c, but only to start from the position record c[idx] in the first jump table c corresponding to the previous element p_0 in the point sequence a, and determine the size of p_1 and c[idx][0]; the elements after the element p_1 in the point sequence a are processed in the same way, that is, after determining the interval in which the current point value in the point sequence has a corresponding relationship with the interval sequence, the next point value of the current point value in the point sequence only needs to start from the interval in which the current point value in the first jump table has a corresponding relationship, and search for the interval correspondence. Finally, put the corresponding relationship results of all the point values in a and the intervals in the interval sequence b into result=[].
[0063] It should be noted that if the first jump table c is traversed until idx=length(c), it means that there is no element in the first jump table c that is larger than p_i, which means that there is no element that can be hit in the first jump table c, that is, the point value has no corresponding interval in the interval sequence b.
[0064] Step S103: If there are overlapping intervals in the interval sequence, determine the correspondence between the point values in the point sequence and the intervals in the interval sequence based on the constructed second skip table; the first value of the element in the second skip table is an element of the interval in the interval sequence, and the second value of the element in the second skip table is a preset value related to the position of the interval associated with the first value of the element in the second skip table in the interval sequence.
[0065] The existence of overlapping intervals in the interval sequence means that at least two intervals in the interval sequence have overlapping interval value ranges formed by the start node values and end node values contained therein. In the constructed second skip list, the elements of the intervals in the interval sequence can be the start node values of the intervals.
[0066] As an optional implementation manner, the step of constructing the second jump table includes:
[0067] Extracting the start node value and the end node value of each interval in the interval sequence, removing duplicates and sorting them to obtain a reconstructed sequence;
[0068] Constructing a hash table according to the interval sequence, determining the intervals associated with the start node value and the end node value of each interval in the interval sequence in the interval sequence, and setting preset values related to the positions of the associated intervals in the interval sequence;
[0069] According to the reconstruction sequence and the hash table, a second skip table is constructed in which the element in the reconstruction sequence having the same value as the starting node in the interval sequence is used as the first value of each element in the skip table, and the preset value related to the position of the associated interval of the element obtained in the hash table in the interval sequence is used as the second value of each element in the skip table.
[0070] In an optional embodiment, a hash table is constructed according to the interval sequence. When constructing the hash table, the intervals in the interval sequence are first sorted from small to large according to the start node value of each interval.
[0071] In a specific embodiment, the point sequence obtained by processing the highway fee table is set to a ’ , the interval sequence obtained by processing the vehicle task table is set to b ’ For interval sequence b ’ The intervals in are sorted from small to large according to the starting node value of each interval. The interval sequence b obtained after sorting is [(s_0, e_0), (s_1, e_1), …, (s_i, e_i), ...], where s_i represents the starting node value of the interval, e_i represents the ending node value of the interval, and the subscript i of s_i or e_i represents the serial number of the interval after the interval sequence is sorted, reflecting the position of the interval in the interval sequence.
[0072] Construct hash table tmp according to interval sequence b: traverse interval sequence b and perform the following processing. First, add suffix _0 to each start node value s_i in interval sequence b, and use the resulting string as the key of hash table tmp. If the key does not exist in hash table tmp, create an array and insert the subscript i of the start node value s_i into the array. If the key exists in hash table tmp, insert the subscript i of the start node value s_i into the corresponding value value. Then, add suffix _1 to the end node value e_i, and use the resulting string as the key of hash table tmp. If the key does not exist in hash table tmp, create an array and insert the subscript i of the end node e_i into the array. If the key exists in hash table tmp, insert the subscript i of the end node e_i into the value value. The hash table tmp finally constructed is presented as {"1_0":[1,2,3],"2_0":[2],...}. For each element in the hash table tmp, the first value is the start node value s_i or the end node value e_i of each interval, and the second value is the interval associated with the start node value s_i or the end node value e_i in the interval sequence. Take the element "1_0":[1,2,3] in the hash table tmp as an example, where 1_0 is the start node value in the interval sequence b, and the elements in the array [1,2,3] represent the interval associated with the start node value in the interval sequence. ’ After sorting, the position of the associated interval in the interval sequence can be quickly located by the subscript of the start node value s_i or the end node value e_i, that is, the elements 1, 2, 3 in the array [1, 2, 3] are the subscript i of the start node s_i of the associated interval, indicating the serial number of the associated interval in the sorted interval sequence b, reflecting the position of the interval in the interval sequence. The hash table tmp is further explained in conjunction with the number axis. If the start node value and the end node value in the interval sequence are sorted from small to large to form a number axis, then the element "1_0": [1, 2, 3] in the hash table tmp indicates that the node corresponding to the value 1 on the number axis is the start node of the interval corresponding to the sorting numbers 1, 2, and 3 in the interval sequence b.
[0073] Extract the interval sequence b ’ The start node value and the end node value of each interval in are sorted from small to large after removing duplicates to obtain the reconstructed sequence s.
[0074] The second jump table d is constructed according to the above reconstruction sequence s and hash table tmp as follows:
[0075] First create a container curr that represents the current interval set;
[0076] Based on the reconstruction sequence s, initialize the skip list d = [(b_0, []), (b_1, []), ..., (b_i, [])], where b_i is an element in the reconstruction sequence s. Traverse the array s. If the string n0 obtained by adding the suffix _0 to b_i is in the hash table tmp, then add all the elements in the array tmp[n0] in the hash table to the container curr; if the string n1 obtained by adding the suffix _1 to b_i is in the hash table tmp, then remove all the elements in the array tmp[n1] from the container curr. Through this processing, only the interval information associated with the start node value of each interval in the hash table tmp is obtained in the container curr.
[0077] Add all the elements in the container curr to the array d[i][1]. The final second jump table d can present information [(1_0,[1,2,3]),(2_0,[1,3]),...]. Through the processing of the container curr, the first value of the element contained in the constructed second jump table d is the interval sequence b. ’ The starting node value of the interval in the middle, the second value of the element is the preset value related to the position of the interval associated with the starting node value in the interval sequence b of the sorted number, that is, the sorted sequence number in the sorted interval sequence b. Taking the middle element ((1_0,[1,2,3])) of the second jump table d as an example, "1_0" represents the starting node value of the interval in the interval sequence, and the elements in the array "[1,2,3]" represent the interval associated with the starting node value "1_0". Since the interval sequence b ’ After sorting, the element information 1, 2, 3 in the array [1, 2, 3] represents the serial number of the associated interval in the sorted interval sequence b, reflecting the position of the associated interval in the interval sequence.
[0078] As an optional implementation manner, determining the correspondence between the point values in the point sequence and the intervals in the interval sequence according to the constructed second jump table includes:
[0079] The current point value in the point sequence is compared with the first value of each element in the second jump table in turn. If the current point value in the point sequence is greater than the first value of the current element in the second jump table and less than the first value of the next element in the second jump table, it is determined that there is a corresponding relationship between the current point value and the interval associated with the position pointed to by the second value of the current element in the second jump table.
[0080] As an optional implementation, before comparing the current point value of the point sequence with the first value of each element in the first jump list in sequence, the point values in the point sequence are first sorted from small to large.
[0081] In a specific embodiment, it is necessary to obtain a point sequence a ’ The corresponding relationship between the point values in and the intervals in interval sequence b is then the point sequence a obtained by processing the highway fee table ’ The point values in are sorted from small to large, and the point sequence a = [p_0, p_1, ... p_i, ...] is obtained after sorting. The corresponding relationship between the elements in the point sequence a (i.e., point values) and the intervals in the interval sequence b is determined. By comparing the elements in a with the first value of the elements in the constructed second skip table d, an element in the second skip table d that meets the requirements is found, and then the associated interval in the corresponding interval sequence b is found through the second value of the element in the second skip table d.
[0082] Specifically, declare the serial number idx=0, which is used to traverse the second jump table d; declare the result set result=[]. At this time, the second element of the second jump table d is not a value, but an array. All elements in this array and the corresponding point value p are formed into relationship pairs and stored in the result set result=[].
[0083] For the first element p_0 in a, starting from the first element d[0] in d, compare the size with the first value d[0][0] of d[0]: if d[0][0] is smaller than p_0, compare the size with the first value d[1][0] of the next element d[1] in d, until the first d[idx][0] larger than p_0 is found, which means that p_0 falls into the interval (d[idx-1][0], d[idx][0]). At this time, the second value d[idx-1][1] of d[idx-1] is the set of sorting numbers corresponding to the associated intervals in the interval sequence b when p_0 falls into (c[idx-1][0], c[idx][0]), so the relationship (p_0, d[c[idx-1][1]]) is recorded, that is, it is determined that the current point value has a corresponding relationship with the associated interval pointed to by the second value of the current element in the second jump table.
[0084] As an optional implementation, after finding the associated interval corresponding to the current point value, continue to traverse the associated interval to obtain the final corresponding interval.
[0085] In a specific embodiment, after finding the set d[idx-1][1] of sorted numbers corresponding to the associated intervals corresponding to p_0 in the interval sequence b, continue to traverse the set and obtain the interval corresponding to p_0 in the interval sequence b as e=b[d[idx-1][1][j]], where j is the subscript of the set d[idx][1]. Then the relationship (p, e) is recorded.
[0086] Then process the next element p_1 in the point sequence a. Since the elements in the point sequence a are sorted from small to large, for the next element p_1 in the point sequence a, it is not necessary to re-traverse from the first element in the second jump table d. It is only necessary to start from the position record d[idx-1] in the first jump table d corresponding to the previous element p_0 in the point sequence a, and determine the size of p_{i+1} and d[idx-1][0]. The elements after the element p_1 in the point sequence a are processed in the same way, that is, after determining the interval in which the current point value in the point sequence has a corresponding relationship with the interval sequence, the next point value of the current point value in the point sequence only needs to start from the interval in which the current point value has a corresponding relationship in the second jump table, and search for the interval correspondence. Finally, put the corresponding relationship results of all the point values in a and the intervals in the interval sequence b into result=[].
[0087] It should be noted that if the second jump table d is traversed until idx=length(d), it means that there is no element in the second jump table d that is larger than p_i, which means that there is no element that can be hit in the second jump table d, that is, the point value has no corresponding interval in the interval sequence b.
[0088] An embodiment of the present invention provides an SQL non-equijoin query method, which obtains a point sequence and an interval sequence; if there is no overlapping interval in the interval sequence, then according to a constructed first skip table, determines the correspondence between the elements in the point sequence and the elements in the interval sequence; the first value of the element in the first skip table is an element of the interval sequence, and the second value of the element in the first skip table is a preset value set in relation to the position of the first value of the element in the first skip table in the interval sequence; if there is an overlapping interval in the interval sequence, then according to a constructed second skip table, determines the correspondence between the elements in the point sequence and the elements in the interval sequence; the first value of the element in the second skip table is an element of the interval sequence, and the second value of the element in the second skip table is a preset value set in relation to the position of the interval associated with the first value of the element in the second skip table in the interval sequence; in an SQL non-equijoin query, the space complexity and time complexity of the query can be reduced, the disk space resources required for the query can be reduced, and the query efficiency can be improved.
[0089] As an optional implementation, the SQL non-equijoin query method further includes traversing the interval sequence sorted from small to large according to the start node value of each interval, and determining whether the end node value of the previous interval of two adjacent intervals in the interval sequence is greater than the start node value of the next interval of the two adjacent intervals; if so, there are overlapping intervals in the interval sequence; otherwise, there are no overlapping intervals in the interval sequence.
[0090] After the interval sequence is obtained, it is determined whether there are overlapping intervals in the interval sequence, so as to respectively construct a first skip table or a second skip table to determine the corresponding relationship between the point values in the point sequence and the intervals in the interval sequence.
[0091] In a specific embodiment, the interval sequence b is sorted from small to large according to the start node value of each interval, and then the intervals in the sorted interval sequence b are traversed, and two adjacent intervals are compared each time. Two adjacent intervals are compared in sequence. Assuming that the current interval is interval A and the next adjacent interval is interval B, it is determined whether the end node value e_{i} of interval A is greater than the start node value s_{i+1} of interval B. If the end node value e_{i} of interval A is greater than the start node value s_{i+1} of interval B, this means that interval A does not end before interval B begins, so the two intervals overlap, and it is determined that there are overlapping intervals in the interval sequence b.
[0092] As an optional implementation, when there are overlapping intervals in the interval sequence, it also includes updating the end node value of the interval with the smallest start node value in the two adjacent intervals with overlap in the interval sequence to the largest end node value in the two adjacent intervals with overlap, obtaining an updated interval, and deleting the original two adjacent intervals with overlap; the updated interval sequence is processed as an interval sequence without overlapping intervals.
[0093] In some business scenarios of SQL non-equijoin queries, it is necessary to query whether the point value has a corresponding interval, but the specific corresponding interval is not important. In this scenario, the overlapping intervals in the interval sequence can be merged. When merging, the end node value of the interval with the smallest start node value in the two adjacent overlapping intervals in the interval sequence is updated to the largest end node value in the two adjacent overlapping intervals to obtain the updated interval, and the original two adjacent overlapping intervals are deleted. The updated interval sequence is processed as an interval sequence without overlapping intervals.
[0094] In a specific embodiment, the interval sequence b is sorted from small to large according to the start node value of each interval = [(s_0, e_0), (s_1, e_1), ...]. Assume that interval A and interval B in the interval sequence b overlap, and the end node value e_{i} of interval A is greater than the start node value s_{i+1} of interval B, but less than the end node value e_{i+1} of interval B. Then, interval A is updated to interval A', whose start node value is the start node value s_{i} of interval A, and the end node value is the largest end node value of interval A and interval B, that is, the node value e_{i+1} of interval B. At the same time, interval A and interval B are deleted, and the interval sequence is updated.
[0095] An embodiment of the present invention provides an SQL non-equijoin query method. For queries that only focus on whether a point value has a corresponding interval, when it is determined that there are overlapping intervals in an interval sequence, the overlapping intervals are merged to update an interval with a minimum coverage range to replace the two overlapping intervals, and the updated interval sequence is processed as an interval sequence without overlapping intervals to determine the correspondence between the point values in the point sequence and the intervals in the interval sequence, so that the calculation amount is further optimized and the performance is greatly improved.
[0096] An embodiment of the present invention provides an SQL non-equijoin query method, which obtains a point sequence and an interval sequence; if there is no overlapping interval in the interval sequence, then according to a constructed first skip table, determines the correspondence between the elements in the point sequence and the elements in the interval sequence; the first value of the element in the first skip table is an element of the interval sequence, and the second value of the element in the first skip table is a preset value set in relation to the position of the first value of the element in the first skip table in the interval sequence; if there is an overlapping interval in the interval sequence, then according to a constructed second skip table, determines the correspondence between the elements in the point sequence and the elements in the interval sequence; the first value of the element in the second skip table is an element of the interval sequence, and the second value of the element in the second skip table is a preset value set in relation to the position of the interval associated with the first value of the element in the second skip table in the interval sequence; in an SQL non-equijoin query, the space complexity and time complexity of the query can be reduced, the disk space resources required for the query can be reduced, and the query efficiency can be improved.
[0097] Without loss of generality, taking the scenario of analyzing vehicle task tolls by logistics enterprises as an example, the existing method has a space complexity and time complexity of T*N*M, where T represents the number of vehicles, N represents the average number of payments for each license plate in the toll table payments, and M represents the average number of tasks for each vehicle in the vehicle task table tasks; if there is no overlapping interval in the above interval sequence, the space complexity of querying using a non-equijoin query method of SQL provided in an embodiment of the present invention is T*(N+2M), and the time complexity is T*(N*log(N)+M*log(M)+N+M). Among them, the time complexity of point sequence sorting is N*log(N), the time complexity of interval sequence sorting is M*log(M), and the time complexity of fast and slow traversal is N+M. For the scenario where N=10000 and M=10000, the space complexity is optimized by N*M / (N+2M)=3333 times, and the time complexity is optimized by N*M / ((N*log(N)+M*log(M)+N+M))=490 times.
[0098] An SQL non-equijoin query method provided by an embodiment of the present invention is optimized for specialized scenarios, and the performance is greatly improved, especially in the scenario of M>>N (the query interval is much larger than the point value).
[0099] Example 2
[0100] Based on the above SQL non-equijoin query method, the embodiment of the present invention further provides an SQL non-equijoin query device, as shown in the structural diagram. Figure 2 As shown, the SQL non-equi-join query device 20 includes a sequence acquisition module 21, a first query module 22 and a second query module 23;
[0101] The sequence acquisition module 21 is used to acquire a point sequence and an interval sequence;
[0102] The first query module 22 is used to determine the correspondence between the point value in the point sequence and the interval in the interval sequence according to the constructed first skip table if there is no overlapping interval in the interval sequence; the first value of the element in the first skip table is the element of the interval in the interval sequence, and the second value of the element in the first skip table is a preset value set in relation to the position of the first value of the element in the first skip table in the interval sequence;
[0103] The second query module 23 is used to determine the correspondence between the point value in the point sequence and the interval in the interval sequence according to the constructed second skip table if there are overlapping intervals in the interval sequence; the first value of the element in the second skip table is the element of the interval in the interval sequence, and the second value of the element in the second skip table is a preset value related to the position of the interval associated with the first value of the element in the second skip table in the interval sequence.
[0104] For other details about how each module in the above-mentioned SQL non-equijoin query device implements the above-mentioned technical solution, reference may be made to the description of the SQL non-equijoin query method provided in the above-mentioned invention embodiment, which will not be repeated here.
[0105] Example 3
[0106] Based on the above SQL non-equijoin query method, the embodiment of the present invention further provides a SQL non-equijoin query device, as shown in the structural diagram. Figure 3 As shown, the device 30 includes a processor 31 and a memory 32 coupled to the processor 31. The memory 32 stores a computer program, and when the computer program is executed by the processor 31, the processor 31 executes the steps of the SQL non-equijoin query method in the above embodiment.
[0107] For other details about the processor 31 in the above-mentioned SQL non-equijoin query device implementing the above-mentioned technical solution, please refer to the description of the above-mentioned SQL non-equijoin query method provided in the above-mentioned invention embodiment, which will not be repeated here.
[0108] Among them, the processor 31 can also be called a CPU (Central Processing Unit), and the processor 31 may be an integrated circuit chip with signal processing capabilities; the processor 31 can also be a general-purpose processor, DSP (Digital Signal Process), ASIC (Application Specific Integrated Circuit), FPGA (Field Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, among which the general-purpose processor can be a microprocessor or the processor 31 can also be any conventional processor, etc.
[0109] Example 4
[0110] like Figure 4 As shown, the embodiment of the present invention also provides a computer-readable storage medium, and its structural diagram, the storage medium 40 stores a readable computer program 41; wherein, the computer program 41 can be stored in the above storage medium 40 in the form of a software product, including a number of instructions for a computer device (which can be a personal computer, server, or network device, etc.) or a processor (processor) to perform all or part of the steps of the above methods of various embodiments of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, magnetic disk or optical disk, ROM (Read-Only Memory), RAM (Random Access Memory) and other media that can store program codes, or terminal devices such as computers, servers, mobile phones, tablets, etc.
[0111] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the above modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.
[0112] The modules described above as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0113] In addition, each functional module in each embodiment of the present application may be integrated into a processing module, or each module may exist physically separately, or two or more modules may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the above-mentioned integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may be stored in a computer-readable storage medium.
[0114] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.
[0115] The above-mentioned computer program product includes one or more computer instructions. When the above-mentioned computer program instructions are loaded and executed on a computer, the above-mentioned process or function according to the embodiment of the present application is generated in whole or in part. The above-mentioned computer may be a general-purpose computer, a special-purpose computer, a computer network or other programmable devices. The above-mentioned computer instructions may be stored in a computer-readable storage medium, or transmitted from a computer-readable storage medium to another computer-readable storage medium, for example, the above-mentioned computer instructions may be transmitted from a website site, a computer, a server or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, server or data center. The above-mentioned computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a server, a data center, etc. that includes one or more available media integration. The above-mentioned available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.
[0116] The technical solution provided by the present application is introduced in detail above. The principles and implementation methods of the present application are explained by using specific examples in the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
[0117] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0118] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices and computer program products according to the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0119] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0120] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0121] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A SQL non-equijoin query method, characterized in that: include: Get point sequence and interval sequence; If there are no overlapping intervals in the interval sequence, the correspondence between the point values in the point sequence and the intervals in the interval sequence is determined according to the constructed first skip table; the first value of the element in the first skip table is the element of the interval in the interval sequence, and the second value of the element in the first skip table is a preset value set in relation to the position of the first value of the element in the first skip table in the interval sequence; If there are overlapping intervals in the interval sequence, the correspondence between the point values in the point sequence and the intervals in the interval sequence is determined according to the constructed second skip table; the first value of the element in the second skip table is an element of the interval in the interval sequence, and the second value of the element in the second skip table is a preset value related to the position of the interval associated with the first value of the element in the second skip table in the interval sequence.
2. The SQL non-equijoin query method according to claim 1, characterized in that: The step of constructing the first jump table includes: Sorting the intervals in the interval sequence from small to large according to the starting node value of each interval; Traversing each interval in the sorted interval sequence, and converting the expression of each interval into an end node value of the interval and a preset value related to the position of the end node value in the interval sequence; The intervals in the interval sequence are merged to construct a first skip list with the end node value of each interval as the first value of each element in the skip list and a preset value related to the position of the end node value of the interval in the interval sequence as the second value of each element in the skip list.
3. The SQL non-equijoin query method according to claim 2, characterized in that: Determining the correspondence between the point values in the point sequence and the intervals in the interval sequence according to the constructed first jump table includes: The current point value in the point sequence is compared with the first value of each element in the first jump table in turn. If the current point value in the point sequence is greater than the first value of the current element in the first jump table and less than the first value of the next element in the first jump table, it is determined that there is a corresponding relationship between the current point value and the interval pointed to by the second value of the next element in the first jump table.
4. The SQL non-equijoin query method according to claim 1, characterized in that: The step of constructing the second jump table includes: Extracting the start node value and the end node value of each interval in the interval sequence, removing duplicates and sorting them to obtain a reconstructed sequence; Constructing a hash table according to the interval sequence, determining the intervals associated with the start node value and the end node value of each interval in the interval sequence in the interval sequence, and setting preset values related to the positions of the associated intervals in the interval sequence; According to the reconstruction sequence and the hash table, a second skip table is constructed in which the element in the reconstruction sequence having the same value as the starting node in the interval sequence is used as the first value of each element in the skip table, and the preset value related to the position of the associated interval of the element obtained in the hash table in the interval sequence is used as the second value of each element in the skip table.
5. The SQL non-equijoin query method according to claim 4, characterized in that: Determining the correspondence between the point values in the point sequence and the intervals in the interval sequence according to the constructed second jump table includes: The current point value in the point sequence is compared with the first value of each element in the second jump table in turn. If the current point value in the point sequence is greater than the first value of the current element in the second jump table and less than the first value of the next element in the second jump table, it is determined that there is a corresponding relationship between the current point value and the interval associated with the position pointed to by the second value of the current element in the second jump table.
6. The SQL non-equijoin query method according to claim 1, characterized in that: The method further includes traversing the interval sequence after sorting the start node value of each interval from small to large, and determining whether the end node value of the previous interval of two adjacent intervals in the interval sequence is greater than the start node value of the next interval of the two adjacent intervals. If so, there are overlapping intervals in the interval sequence, otherwise there are no overlapping intervals in the interval sequence.
7. The SQL non-equijoin query method according to claim 6, characterized in that: When there are overlapping intervals in the interval sequence, the method further includes updating the end node value of the interval with the smallest start node value in the two adjacent intervals with overlap in the interval sequence to the largest end node value in the two adjacent intervals with overlap, obtaining an updated interval, and deleting the original two adjacent intervals with overlap; the updated interval sequence is processed as an interval sequence without overlapping intervals.
8. A non-equivalent join query device for SQL, characterized in that: It includes a sequence acquisition module, a first query module and a second query module; The sequence acquisition module is used to acquire point sequences and interval sequences; The first query module is used to determine the correspondence between the point value in the point sequence and the interval in the interval sequence according to the constructed first skip table if there is no overlapping interval in the interval sequence; the first value of the element in the first skip table is the element of the interval in the interval sequence, and the second value of the element in the first skip table is a preset value set in relation to the position of the first value of the element in the first skip table in the interval sequence; The second query module is used to determine the correspondence between the point values in the point sequence and the intervals in the interval sequence according to the constructed second skip table if there are overlapping intervals in the interval sequence; the first value of the element in the second skip table is the element of the interval in the interval sequence, and the second value of the element in the second skip table is a preset value related to the position of the interval associated with the first value of the element in the second skip table in the interval sequence.
9. A non-equivalent join query device for SQL, characterized in that: comprising a memory and a processor, wherein: The memory is used to store computer programs; The processor is used to read the computer program in the memory and execute the steps of the SQL non-equijoin query method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: A readable computer program is stored thereon, and when the program is executed by a processor, the steps of the SQL non-equi-join query method as claimed in any one of claims 1 to 7 are implemented.
