A virtual primary key generation method, device, equipment and storage medium
By generating a merged hash string through binary conversion and hash operation, randomly determining the starting bit, and executing a binary matching algorithm to generate a high-quality VPK set, this method solves the problems of insufficient control over the proportion of attribute participation and low proportion of unique values in existing virtual primary key generation methods, thereby improving resistance and the effectiveness of the watermarking algorithm.
Patent Information
- Application Number
- CN202310091530.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-29
- Publication Date
- 2025-12-16
- Estimated Expiration
- 2043-01-29
AI Technical Summary
Existing virtual primary key generation methods cannot effectively control the participation ratio of each attribute, and the proportion of unique values in the VPK set is not high, resulting in weak robustness and resistance to attribute deletion attacks, and cannot effectively replace the role of the primary key in the watermarking algorithm.
By obtaining the participation ratio of attributes, attribute values, and virtual primary key keys, binary conversion and hash operations are performed. Bit cross-merging is used to generate a merged hash string. The starting bit is randomly determined, and a binary matching algorithm is executed to determine whether the attribute value participates in the VPK construction. Finally, a VPK set is generated based on the assembly rules.
It achieves precise control over the participation ratio of attributes, generates high-quality VPK sets, improves robustness against attribute deletion attacks and the proportion of unique values, and can effectively replace the role of primary keys in watermarking algorithms.
Smart Images

Figure CN116126863B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of database security, and in particular to a virtual primary key generation method, device, equipment and storage medium. BACKGROUND
[0002] At present, the amount of data generated worldwide is still increasing rapidly, and the market size of the database is also increasing. The marketization of data elements will further tap the value of data and stimulate economic growth potential. However, due to the non-competitive, low-cost and easy-to-copy characteristics of data, data rights and leakage tracing problems often occur in data transaction circulation, and database watermarking technology is considered to be an effective solution. However, most of the existing watermarking technologies have the problem of primary key dependence, and primary key attacks will make the technology ineffective. Therefore, researchers hope to solve this problem by proposing a virtual primary key generation method.
[0003] Generally, the virtual primary key generation method randomly selects attribute values of non-primary keys in a data table to construct a VPK set, and uses the set to replace the primary key to perform watermark-related operations in the process of running the watermark algorithm. However, the existing virtual primary key generation method has four problems: 1. The resistance is not good enough when facing attribute deletion attacks; 2. When constructing the VPK set, the scheme cannot control the proportion of each participating attribute alone, and it is easy to have a high proportion of a certain attribute; 3. The controllable proportion range is limited and the error is not small enough; 4. The proportion of unique values in the VPK set is not high enough, and the number is still far from the number of primary keys. SUMMARY
[0004] The present application proposes a virtual primary key generation method, which aims to solve the problem that the existing scheme cannot control the participation proportion of each attribute when generating VPK.
[0005] In a first aspect, the present embodiment provides a virtual primary key generation method, which comprises:
[0006] Obtaining the participation proportion, attribute value, least significant bit number and virtual primary key key of the attribute;
[0007] Converting the participation proportion of the attribute into a binary string to generate a proportion string of the attribute, wherein the proportion string of the attribute is a binary string of the participation proportion of the attribute;
[0008] Converting the attribute value into a binary form, and dividing it into two parts according to the least significant bit number, i.e. the most significant bit part MSB part and the least significant bit LSB part;
[0009] Performing a hash operation on the MSB part and the virtual primary key key to obtain a hash string of the attribute value;
[0010] In the hash string of the multiple attribute values of the same tuple, a first hash string is obtained, the first hash string being a hash string with the largest numerical value;
[0011] The hash string of the attribute value and the first hash string are merged by a bit cross-merging manner to generate a merged hash string;
[0012] A random starting bit is determined in the merged hash string;
[0013] According to the random starting bit, a hash string is intercepted in the merged hash string to obtain a final attribute string;
[0014] Based on a preset matching manner, a binary matching algorithm is performed on the final attribute string and the proportion string;
[0015] According to a matching result, it is judged whether the attribute value participates in construction of a virtual primary key (VPK);
[0016] When the attribute value participates in construction of the virtual primary key (VPK), multiple final attribute strings that match successfully are assembled and spliced into a VPK of the tuple based on a preset assembly rule, and a VPK set is constructed based on multiple VPKs of the tuples.
[0017] As an optional implementation, the random starting bit is determined in the merged hash string, and specifically,
[0018] A preset random bit searching model is used to determine the random starting bit in the merged hash string;
[0019] The random bit searching model is as follows:
[0020] ;
[0021] The random bit searching model is as follows: pos The random starting bit is A tmp The hash string of the attribute value is A max The hash string with the largest numerical value is A cross The merged hash string is B The proportion string of the attribute is len The length of the proportion string of the attribute is returned.
[0022] As an optional implementation, the final attribute string is obtained by intercepting the hash string in the merged hash string according to the random starting bit, and specifically,
[0023] adopting a preset intercepting model, intercepting a hash string in the merged hash string according to a random starting bit and the intercepting model, and obtaining a final attribute string;
[0024] wherein the intercepting model is:
[0025] ;
[0026] wherein, pos is the random starting bit, A s-vpk is the final attribute string, A cross is the merged hash string, Substring is an intercepting function.
[0027] As an optional implementation, the binary matching algorithm is performed on the final attribute string and the ratio string according to the preset bit matching direction, specifically as follows:
[0028] The current bit of the final attribute string and the current bit of the ratio string are obtained according to the preset bit matching direction;
[0029] The binary matching is performed on the current bit of the final attribute string and the current bit of the ratio string;
[0030] If the current bit of the final attribute string is 1 and the current bit of the ratio string is 0, the matching fails;
[0031] If the current bit of the final attribute string is 1 and the current bit of the ratio string is 1, the matching succeeds;
[0032] If the current bit of the final attribute string is 0, it is determined whether the current bit of the ratio string is the last bit of the ratio string. If the current bit of the ratio string is not the last bit of the ratio string, the binary matching is performed on the next bit of the current bit of the final attribute string and the next bit of the current bit of the ratio string according to the preset matching manner. If the current bit of the ratio string is the last bit of the ratio string, the matching ends and the matching fails.
[0033] As an optional implementation, the current bit of the final attribute string and the current bit of the ratio string are obtained according to the preset bit matching direction, specifically as follows:
[0034] The i-th bit of the final attribute string is obtained as the current bit of the final attribute string in the direction from right to left, and the i-th bit of the ratio string is obtained as the current bit of the ratio string in the direction from left to right; wherein the i is a positive integer.
[0035] As an optional implementation, when the attribute value participates in the construction of the virtual primary key VPK, a plurality of matched final attribute strings are assembled into the VPK of the tuple based on a preset assembly rule, and a VPK set is constructed based on a plurality of VPKs of the tuple, specifically:
[0036] Obtaining the number of 0s in the numerical maximum hash string;
[0037] When the number of 0s in the numerical maximum hash string is even, a plurality of matched final attribute strings are merged from small to large to splice into the VPK of the tuple, and a VPK set is constructed based on a plurality of VPKs of the tuple;
[0038] When the number of 0s in the numerical maximum hash string is odd, a plurality of matched final attribute strings are merged from large to small to splice into the VPK of the tuple, and a VPK set is constructed based on a plurality of VPKs of the tuple.
[0039] As an optional implementation, the VPK set is constructed based on a plurality of VPKs of the tuple, specifically:
[0040] Obtaining n tuples of a database table, obtaining m VPKs generated by the n tuples, and constructing a VPK set based on the m VPKs, wherein 0 <= m <= n, and n and m are positive integers. In the second aspect, the embodiment also provides a virtual primary key generation device, which includes a processor and a memory, the memory stores a computer program, and the processor invokes the computer program in the memory to execute the virtual primary key generation method described above.
[0041] In the third aspect, the embodiment also provides a device, which includes the virtual primary key generation device described above.
[0042] In the fourth aspect, the embodiment also provides a storage medium for storing a computer program, and the computer program is executed by a processor to make the processor implement the virtual primary key generation method described above.
[0043] The embodiment obtains the participation ratio, attribute value, minimum significant bit number and virtual primary key of an attribute; performs binary conversion on the participation ratio of the attribute to generate a ratio string of the attribute, which is a binary string of the participation ratio of the attribute; converts the attribute value into a binary form and divides it into two parts according to the minimum significant bit number, that is, a most significant bit part MSB part and a least significant bit part LSB part; performs a hash operation on the MSB part and the virtual primary key to obtain a hash string of the attribute value; obtains a first hash string from the hash strings of the attribute value of the same tuple, which is the hash string with the largest value; merges the hash string of the attribute value and the first hash string in a bit cross-merging manner to generate a merged hash string; determines a random starting bit in the merged hash string; intercepts a hash string in the merged hash string according to the random starting bit to obtain a final attribute string; performs a binary matching algorithm on the final attribute string and the ratio string based on a preset matching mode; determines whether the attribute value participates in the construction of a virtual primary key VPK according to a matching result; when the attribute value participates in the construction of the virtual primary key VPK, assembles multiple final attribute strings that match successfully into a VPK of the tuple based on a preset assembly rule, and constructs a VPK set based on multiple VPKs of the tuple. The embodiment has two advantages. On the one hand, through the above steps, the largest hash value in the tuple is used to distribute and map the hash value of each attribute to a more scattered distribution, and then the binary matching method is used to select the attribute value, so as to finally control the participation ratio of the attribute and generate a high-quality VPK set. The scheme can set the same ratio for each attribute to balance the influence of deleting the attribute, or can assign different ratios to each attribute according to the importance of each attribute, so as to limit the deletion attack of the attacker through data availability. Therefore, the scheme solves the problem that the existing virtual primary key generation method has weak robustness and resistance when facing the deletion of attributes by the attacker. On the other hand, the scheme also solves the problem that the existing scheme has few unique values in the VPK set. Because the proportion of unique values in the VPK set generated by the scheme is high, the scheme can fully replace the role of the PK in the execution process of the watermark algorithm to complete the operations of watermark embedding and extraction. BRIEF DESCRIPTION OF DRAWINGS
[0044] The application will be further described below in combination with the drawings and embodiments.
[0045] Figure 1 A flowchart of a virtual primary key generation method provided by the embodiment;
[0046] Figure 2 Another flowchart of a virtual primary key generation method provided by the embodiment;
[0047] Figure 3 A flowchart of the virtual primary key assembly method provided by the embodiment is shown in the figure.
[0048] Figure 4 A schematic block diagram of the virtual primary key generation device provided by the embodiment is shown in the figure. DETAILED DESCRIPTION
[0049] This part will describe the specific embodiments of the present application in detail, and the preferred embodiments of the present application are shown in the accompanying drawings, which serve to supplement the description of the text part of the specification and enable people to intuitively and visually understand each technical feature and the overall technical scheme of the present application, but it cannot be understood as a limitation on the protection scope of the present application.
[0050] In order to solve the problem that the virtual primary key generation method in the prior art cannot control the participation ratio of attributes, the present application provides a virtual primary key generation method.
[0051] It should be noted that the virtual primary key generation method mentioned in the present application is mainly used for generating a virtual primary key set for a database.
[0052] Please refer to Figure 1 , Figure 1 A flowchart of the virtual primary key generation method provided by the embodiment is shown in the figure, and the virtual primary key generation method comprises:
[0053] S1, obtaining the participation ratio, attribute value, least significant bit number and virtual primary key of the attribute.
[0054] Among them, the original relation data set has multiple attributes, and each attribute corresponds to a participation ratio.
[0055] Among them, the same ratio can be set for each attribute to balance the influence of deleting attributes, or the importance of each attribute can be used to give each attribute a different ratio, and the data availability is used to limit the deletion attack of the attacker.
[0056] Among them, the participation ratio of each attribute is input by the user or set by the system, and the value range of the participation ratio is a decimal number from 0 to 1. Among them, the participation ratio is the proportion of the attribute value of the attribute in the process of constructing VPK.
[0057] Among them, the attribute value is the value of the attribute in the original relation data set.
[0058] Among them, the value of the attribute in the original relation data set is the attribute value, and the original relation data set can be user input data or directly called relational database data.
[0059] The relational database is established on the basis of a relational data model, and data is processed by means of mathematical concepts and methods such as set algebra. The relational database stores data in the form of rows and columns. A series of rows and columns are referred to as a table, and a group of tables constitutes a database.
[0060] Each attribute value is converted into a binary form, and the entire binary bit string is divided into two parts, namely, a most significant bit part MSB and a least significant bit part LSB. The division is based on the number of least significant bits.
[0061] In the virtual primary key construction process, a key SK is required, which meets the cryptographic security standard. Different keys will produce completely different effects when generating a virtual primary key. Assuming that an attribute value of attribute A is 15, which is converted into a binary string 1111, and the number of least significant bits is 1, the MSB part is 111. For example, user A adopts his own key SecretA, and generates a pseudo-random hash value 1q1e5od8a8an0i14756efe2f24a37q8w9qu81jh0 by using MD5 on the attribute value; user B adopts the key SecretB, and generates a pseudo-random hash value 93j1k5a8s9j1dlkj28ajld923jamf01kas2han91. Slight differences in the key will produce completely different results for the virtual primary key scheme.
[0062] S2, converting the participation ratio of the attribute into a binary form to generate a ratio string of the attribute, the ratio string of the attribute being a binary string of the participation ratio of the attribute.
[0063] Each attribute value is converted into a binary form, and the entire binary bit string is divided into two parts, namely, a most significant bit part MSB and a least significant bit part LSB. The division is based on the number of least significant bits.
[0064] It should be noted that not all attribute participation ratios can be converted into binary strings completely and accurately. In many cases, the value of the binary string can only be infinitely close to the attribute participation ratio. Therefore, there are two stopping conditions in the conversion process. One is that the attribute participation ratio has been equal before reaching the set maximum number of bits, and the other is that the set maximum number of bits is reached. Assuming that the set ratio of an attribute is 0.375, the final ratio string is 011.
[0065] S3, converting the attribute value into a binary form, and dividing it into two parts, namely, a most significant bit part MSB and a least significant bit part LSB, according to the number of least significant bits.
[0066] S4, performing a hash operation on the MSB part and the virtual primary key to obtain a hash string of the attribute value.
[0067] S5, obtaining a first hash string from hash strings of multiple attribute values of the same tuple, the first hash string being a hash string with the largest value.
[0068] The hash strings of the multiple attribute values of the same tuple are sorted, and the hash string of the attribute value with the largest value is taken as the first hash string.
[0069] S6, merging the hash string of the attribute value and the first hash string in a bit cross-merging manner to generate a merged hash string.
[0070] S7, determining a random starting bit in the merged hash string.
[0071] The determination of the random starting bit in the merged hash string specifically includes:
[0072] A preset random bit searching model is used to determine the random starting bit in the merged hash string.
[0073] S8, according to the random starting bit, intercepting a hash string from the merged hash string to obtain a final attribute string.
[0074] The final attribute string is obtained by intercepting a hash string from the merged hash string according to the random starting bit and a preset interception model.
[0075] The intercepted hash string in the merged hash string is taken as the final attribute string.
[0076] S9, performing a binary matching algorithm on the final attribute string and the proportion string based on a preset matching manner.
[0077] The implementation of S9 is described as follows:
[0078] According to a preset bit matching direction, obtaining a current bit of the final attribute string and a current bit of the proportion string;
[0079] Performing binary matching on the current bit of the final attribute string and the current bit of the proportion string;
[0080] If the current bit of the final attribute string is 1 and the current bit of the proportion string is 0, the matching fails.
[0081] If the current bit of the final attribute string is 1 and the current bit of the ratio string is 1, the matching is successful;
[0082] If the current bit of the final attribute string is 0, it is determined whether the current bit of the ratio string is the last bit of the ratio string. If the current bit of the ratio string is not the last bit of the ratio string, the next bit of the current bit of the final attribute string and the next bit of the current bit of the ratio string are subjected to binary matching according to a preset matching mode. If the current bit of the ratio string is the last bit of the ratio string, the matching is ended and the matching is failed.
[0083] For the convenience of description, the following examples are given:
[0084] If the current bit of the ratio string is not the last bit of the ratio string, the next bit is needed to be observed according to the preset matching mode.
[0085] Suppose that the final attribute string is A and the ratio string is B, the matching process is started from the rightmost bit of A and the leftmost bit of B. If it is not ended, the next bit is observed according to the corresponding direction, not only one bit.
[0086] That is, the next bit of the rightmost bit of A and the next bit of the leftmost bit of B are matched until the current bit of B is the last bit. If it is still not confirmed, it is considered that the matching is failed and the matching is ended. For B, the direction of bit matching is from left to right; for A, the direction of bit matching is from right to left.
[0087] For the convenience of description, there are three kinds of ending conditions of the matching process of A and B, which are described as follows:
[0088] One kind is to end when the matching is confirmed to be successful in the matching process. Another kind is to end when the matching is confirmed to be failed in the matching process. The last kind is to always observe the next bit until the last bit of the ratio string B is reached and it is still not confirmed, and then it is considered that the matching is failed and the matching is ended.
[0089] The current bit of the final attribute string and the current bit of the ratio string are obtained according to the preset direction of bit matching, which is specifically as follows:
[0090] The i-th bit of the final attribute string is obtained as the current bit of the final attribute string according to the direction from right to left, and the i-th bit of the ratio string is obtained as the current bit of the ratio string according to the direction from left to right; wherein, the i is a positive integer.
[0091] S10, judging whether the attribute value participates in the construction of the virtual primary key VPK according to the matching result.
[0092] The S10 is specifically: obtaining the matching result, when the matching result is a matching success, judging that the attribute value participates in the construction of the virtual primary key VPK. When the matching result is a matching failure, it is judged that the attribute value does not participate in the construction of the virtual primary key VPK.
[0093] S11, when the attribute value participates in the construction of the virtual primary key VPK, based on the preset assembly rule, the final attribute string of the multiple matching successes is assembled and spliced into the VPK of the tuple, and the VPK set is constructed based on the multiple VPKs of the tuples.
[0094] The n tuples of the database table are obtained, m VPKs generated by the n tuples are obtained, and the VPK set is constructed based on the m VPKs, wherein 0 <= m <= n, and the n and the m are positive integers.
[0095] The steps of S1 to S11 are performed on each tuple, and for one tuple, one tuple may generate one VPK or not, therefore, the number m of VPKs is less than or equal to the number n of tuples.
[0096] The embodiment has two advantages. On the one hand, through the above steps, the hash value of each attribute is distributed and mapped to a more hash distribution by using the maximum hash value in the tuple, and then the attribute value is selected by using the binary matching method, so as to finally realize the control of the participation ratio of the attribute and generate a high-quality VPK set. The scheme can set the same ratio for each attribute to balance the influence of deleting the attribute, or can give different ratios to each attribute according to the importance of each attribute, so as to limit the deletion attack of the attacker through the data availability. Therefore, the scheme solves the problem that the existing virtual primary key generation method has weak robustness and resistance when facing the deletion of the attribute by the attacker. On the other hand, the present scheme also solves the problem that the existing scheme has a small number of unique values in the VPK set. Because the proportion of unique values in the VPK set generated by the present scheme is high, the operation of watermark embedding and extraction can be completed by replacing the PK in the execution process of the watermark algorithm.
[0097] Please refer to Figure 2 , Figure 2 Another flowchart of the virtual primary key generation method provided by the embodiment is provided, and the virtual primary key generation method is applied to a relational database, which is described in detail as follows.
[0098] S201, obtaining the participation ratio of each attribute, the original relational data set, the least significant bit number and the virtual primary key;
[0099] S202, converting the participation proportion of each attribute into a binary string;
[0100] S203, converting each attribute value into binary form, and dividing it into two parts according to the number of the least significant bits, namely MSB part and LSB part;
[0101] S204, performing hash operation on the MSB part of the attribute value and the virtual primary key to obtain a binary hash string;
[0102] S205, recording the hash string with the largest value for each tuple;
[0103] S206, merging the hash string of the attribute value and the hash string with the largest value of the tuple in which the attribute value is located by means of cross-merging of bit positions;
[0104] S207, determining a random starting bit position in the merged hash string, and cutting the merged hash string according to the random starting bit position;
[0105] S208, performing binary matching algorithm on the cut hash string and its corresponding proportion string;
[0106] S209, performing the above steps on each attribute value of each tuple in the data table to determine whether to participate in the construction of VPK;
[0107] Wherein, the above steps S201 to S209 are performed on each attribute value of each tuple in the data table to determine whether the attribute value participates in the construction of VPK.
[0108] S210, if there are multiple matching attribute value hash strings in a tuple, the multiple hash strings are spliced according to the number of 0 in the hash string with the largest value;
[0109] S211, running the above process in all tuples to finally obtain a VPK set;
[0110] Wherein, the above steps S201 to S211 are performed on each tuple to obtain the VPK generated by the tuple, and the VPK generated by all tuples is recorded to obtain a VPK set.
[0111] For convenience of illustration, the following example is given. Before determining whether an attribute value participates in the construction of VPK, the attribute value needs to be converted into a binary attribute string, and the steps include:
[0112] 1. converting the attribute value into binary form, and dividing it into MSB part according to the number of the least significant bits, performing hash operation on the MSB part and the virtual primary key SK to obtain a binary hash string, and the calculation method is:
[0113]
[0114] where H is a hash function, SK is a virtual primary key, MSB A val 2 represents the highest significant bit part, A tmp is the hash string of the attribute value.
[0115] 2. In a tuple, there are multiple attributes, and each attribute can be calculated A tmp , where the maximum A tmp is denoted as A max .
[0116] 3. A tmp and A max are cross-merged to obtain A cross .
[0117] 4. Randomly find bits in A cross , and the finding method is:
[0118]
[0119] where pos is the random starting bit, pos A A tmp is the hash string of the attribute value, A max is the hash string with the maximum value, A cross is the merged hash string, B is the proportion string of the attribute, len is the length of the proportion string of the attribute.
[0120] where B is the binary proportion string of the attribute participating in the proportion conversion, and len returns the length of the binary string.
[0121] 5. A cross is obtained by cutting A s-vpk based on the random starting bit pos, and the cutting method is:
[0122]
[0123] where pos is the random starting bit, pos A A s-vpk is the final attribute string, A cross is the merged hash string, Substring is the cutting function.
[0124] Whether an attribute value participates in the construction of VPK is determined according to the attribute string A s-vpk The matching result with the proportion string B, the matching step includes:
[0125] (1) If the current bit of the attribute string is 1 and the current bit of the proportion string is 0, the attribute string will not match any divided result, so it can be determined that the matching fails, and the attribute value will not participate in the construction of VPK;
[0126] (2) If the current bit of the attribute string is 1 and the current bit of the proportion string is 1, the attribute string matches successfully, hits a divided result, and the attribute value will participate in the construction of VPK;
[0127] (3) If the current bit of the attribute string is 0, if the last bit of the proportion string is reached, the matching ends and the matching fails; otherwise, whether the current bit of the proportion string is 0 or 1, it can be determined that no division is hit, but at the same time it cannot be determined whether the attribute string will match failure in the subsequent bits or will hit a division in the subsequent bits, so the situation of the subsequent bits needs to be observed.
[0128] For the proportion string B, the bit matching direction is from left to right; for the attribute string A s-vpk , the bit matching direction is from right to left. Each bit is judged by the above three steps, and the matching is successful. Participate in the construction of VPK.
[0129] In a tuple, there are usually multiple A s-vpk matching success, which needs to be assembled based on certain random rules to form a VPK, and the assembly rule is:
[0130] When the number of 0 in A max is even, merge A s-vpk from small to large;
[0131] When the number of 0 in A max is odd, merge A s-vpk from large to small;
[0132] Finally, a VPK is generated in a tuple.
[0133] The embodiment has two advantages. On the one hand, by the above steps, the hash value distribution of each attribute is mapped to a more hash distribution by using the maximum hash value in the tuple, and then the attribute value is selected by using the binary matching mode, so that the participation ratio of the attribute is controlled, and a high-quality VPK set is generated. The scheme can set the same ratio for each attribute to balance the influence of deleting the attribute, or can give different ratios to each attribute according to the importance of each attribute, so as to limit the deletion attack of the attacker through data availability. Therefore, the scheme solves the problem that the existing virtual primary key generation method has weak robustness and resistance when facing the deletion of the attribute. On the other hand, the scheme also solves the problem that the existing scheme has a small number of unique values in the VPK set. The ratio of unique values in the VPK set generated by the scheme is high, and in the execution process of the watermark algorithm, the role of the PK can be fully replaced to complete the operations of watermark embedding and extraction.
[0134] Referring to Figure 3 , Figure 3 A flowchart of assembling a virtual primary key provided by the embodiment is shown as follows.
[0135] S301, obtaining the number of 0 in the hash string with the largest numerical value;
[0136] S302, when the number of 0 in the hash string with the largest numerical value is even, merging multiple final attribute strings matched successfully from small to large, and splicing to the VPK of the tuple, and constructing a VPK set based on multiple VPKs of the tuple;
[0137] S303, when the number of 0 in the hash string with the largest numerical value is odd, merging multiple final attribute strings matched successfully from large to small, and splicing to the VPK of the tuple, and constructing a VPK set based on multiple VPKs of the tuple.
[0138] The embodiment assembles and splices the VPK of the tuple based on a certain random rule, which is beneficial to generate a high-quality VPK set.
[0139] Referring to Figure 4 , Figure 4 A schematic block diagram of a virtual primary key generation device provided by the embodiment is shown as follows.
[0140] As Figure 4 shown, the virtual primary key generation device 400 can include a processor 411 and a memory 412, and the processor 411 and the memory 412 are connected through a bus, such as an I2C (Inter-integrated Circuit) bus.
[0141] Specifically, the processor 411 can be a micro-controller unit (MCU), a central processing unit (CPU), or a digital signal processor (DSP), etc.
[0142] Specifically, the memory 412 can be a flash chip, a read-only memory (ROM) disk, an optical disk, a U disk, or a mobile hard disk, etc. The memory 412 stores various computer programs for the processor 411 to execute.
[0143] The processor 411 is configured to run the computer programs stored in the memory 412 and implement the following steps when executing the computer programs:
[0144] Obtaining a participation ratio, an attribute value, a least significant bit number, and a virtual primary key of an attribute;
[0145] Converting the participation ratio of the attribute into a binary form to generate a ratio string of the attribute, the ratio string of the attribute being a binary string of the participation ratio of the attribute;
[0146] Converting the attribute value into a binary form and dividing the attribute value into two parts according to the least significant bit number, the two parts being a most significant bit (MSB) part and a least significant bit (LSB) part;
[0147] Performing a hash operation on the MSB part and the virtual primary key to obtain a hash string of the attribute value;
[0148] Obtaining a first hash string from hash strings of a plurality of attribute values of the same tuple, the first hash string being a hash string with the largest value;
[0149] Merging the hash string of the attribute value and the first hash string by a bit cross-merging manner to generate a merged hash string;
[0150] Determining a random starting bit in the merged hash string;
[0151] According to the random starting bit, intercepting a hash string in the merged hash string to obtain a final attribute string;
[0152] Performing a binary matching algorithm on the final attribute string and the ratio string based on a preset matching manner;
[0153] According to a matching result, determining whether the attribute value participates in construction of a virtual primary key (VPK);
[0154] When the attribute value participates in the construction of the virtual primary key VPK, based on a preset assembly rule, the multiple matched final attribute strings are assembled into the VPK of the tuple, and the VPK set is constructed based on the multiple VPKs of the tuples.
[0155] To solve the above problems, the application further provides a storage medium, wherein the computer program makes the processor execute the virtual primary key generation method when executed by the processor.
[0156] It should be noted that since the storage medium of the application contains all the steps of the virtual primary key generation method, the storage medium can also implement all the schemes of the virtual primary key for the relational database, and has the same beneficial effects, which will not be described here.
[0157] The virtual primary key generation method is executed. The apparatus embodiments described above are merely illustrative, wherein the units described as separate components can or can not be physically separate, i.e., can be located in one place or distributed on multiple network units. Part or all of the modules can be selected to achieve the purpose of the embodiment scheme according to actual needs. Those skilled in the art can understand that all or some of the steps in the above method and system can be implemented as software, firmware, hardware and their appropriate combinations. Some or all physical components can be implemented as software executed by a processor, such as a central processing unit, a digital signal processor or a microprocessor, or as hardware, or as an integrated circuit, such as an application specific integrated circuit. Such software can be distributed on a computer readable medium, which can include computer storage media (or non-transitory media) and communication media (or transitory media). As known by those skilled in the art, the term computer storage media includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information, such as computer readable instructions, data structures, program modules or other data. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory or other memory technology, CD-ROM, digital versatile disk (DVD) or other optical disk storage, magnetic cassettes, magnetic tapes, magnetic disk storage or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. In addition, as known by those skilled in the art, communication media generally includes computer readable instructions, data structures, program modules or other data in a modulated data signal carrier or other transmission mechanism, and can include any information delivery medium.
[0158] Any technical features in the above embodiments can be combined, and for the sake of brevity, not all possible combinations are described, however, any combination of the technical features is considered to be within the scope of the present specification.
Claims
1. A method for generating virtual primary keys, characterized in that, The virtual primary key generation method includes: Retrieve the participation ratio, attribute value, minimum number of valid bits, and virtual primary key of the attribute; The participation ratio of the attribute is converted into binary to generate the ratio string of the attribute, which is the binary string of the participation ratio of the attribute. The attribute value is converted into binary form and divided into two parts according to the number of least significant bits: the most significant bit (MSB) part and the least significant bit (LSB) part. The MSB portion and the virtual primary key are hashed to obtain the hash string of the attribute value; Among the hash strings of multiple attribute values in the same tuple, the first hash string is obtained, and the first hash string is the hash string with the largest value. The hash string of the attribute value and the first hash string are merged by bit cross-merging to generate a merged hash string; Determine a random starting bit in the merged hash string; Based on the random starting bit, the hash string is truncated from the merged hash string to obtain the final attribute string; Based on a preset matching method, a binary matching algorithm is executed on the final attribute string and the ratio string; Based on the matching results, determine whether the attribute value participates in the construction of the virtual primary key (VPK). When the attribute value is used in the construction of the virtual primary key (VPK), based on the preset assembly rules, multiple successfully matched final attribute strings are assembled and concatenated into the VPK of the tuple, and a VPK set is constructed based on the VPK of the multiple tuples.
2. The virtual primary key generation method as described in claim 1, characterized in that, The step of determining a random starting bit in the merged hash string specifically involves: A preset random bit-finding model is used to determine a random starting bit in the merged hash string; The random bit search model is as follows: ; in, pos The random starting bit, A tmp The hash string of the attribute value. A max The hash string with the largest value. A cross For the merged hash string, B The ratio string of the attribute, len To return the length of the proportion string of the attribute.
3. The virtual primary key generation method as described in claim 1, characterized in that, The step of extracting a hash string from the merged hash string based on the random starting bit to obtain the final attribute string is as follows: Using a preset truncation model, based on a random starting bit and the truncation model, the hash string is truncated from the merged hash string to obtain the final attribute string; The interception model is as follows: ; in, pos The random starting bit, A s-vpk For the final attribute string, A cross For the merged hash string, s ubstring This is a truncation function.
4. The virtual primary key generation method as described in claim 1, characterized in that, The binary matching algorithm, based on a preset matching method, is performed on the final attribute string and the ratio string, specifically as follows: According to the preset bit matching direction, obtain the current bit of the final attribute string and the current bit of the ratio string; Perform a binary match between the current bits of the final attribute string and the current bits of the ratio string; If the current bit of the final attribute string is 1 and the current bit of the ratio string is 0, then the match fails. If the current bit of the final attribute string is 1 and the current bit of the ratio string is 1, then the match is successful; If the current bit of the final attribute string is 0, then determine whether the current bit of the ratio string is the last bit of the ratio string. If the current bit of the ratio string is not the last bit of the ratio string, perform binary matching on the next bit of the current bit of the final attribute string and the next bit of the current bit of the ratio string according to a preset matching method. If the current bit of the ratio string is the last bit of the ratio string, the matching ends and the matching fails.
5. The virtual primary key generation method as described in claim 4, characterized in that, The step of obtaining the current bit of the final attribute string and the current bit of the ratio string according to the preset bit matching direction is specifically as follows: Starting from right to left, the i-th bit of the final attribute string is obtained as the current bit of the final attribute string; starting from left to right, the i-th bit of the ratio string is obtained as the current bit of the ratio string; where i is a positive integer.
6. The virtual primary key generation method as described in claim 1, characterized in that, When the attribute value participates in the construction of the virtual primary key (VPK), based on preset assembly rules, multiple successfully matched final attribute strings are assembled and concatenated into the VPK of the tuple, and a VPK set is constructed based on the VPKs of multiple tuples, specifically as follows: Obtain the number of 0s in the hash string with the largest value; When the number of 0s in the hash string with the largest value is even, multiple successfully matched final attribute strings are merged from smallest to largest and concatenated into the VPK of the tuple. A VPK set is constructed based on the VPK of multiple tuples. When the number of 0s in the hash string with the largest value is odd, multiple successfully matched final attribute strings are merged from largest to smallest and concatenated into the VPK of the tuple. A VPK set is constructed based on the VPK of multiple tuples.
7. The virtual primary key generation method according to any one of claims 1 to 6, characterized in that, The construction of a VPK set based on multiple tuples of VPKs specifically involves: Obtain n tuples from the database table, obtain m VPKs generated from the n tuples, and construct a VPK set based on the m VPKs, where 0 <= m <= n, and n and m are positive integers.
8. A virtual primary key generation device, characterized in that, The virtual primary key generation device includes a processor and a memory. The memory stores a computer program that can be executed by the processor. When the computer program is executed by the processor, it implements the virtual primary key generation method as described in any one of claims 1 to 7.
9. A device, characterized in that, The device includes the virtual primary key generation apparatus as described in claim 8.
10. A storage medium for computer-readable storage, characterized in that, The storage medium stores one or more programs, which can be executed by one or more processors to implement the steps of the virtual primary key generation method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Database primary key generation method and device and sub-table positioning method and device
CN113704245A
Apparatus and Method for generating a virtual tuple
KR1020090011641A