Method and device for processing sub-table data
By generating and using primary keys to directly locate data tables, the problem of low performance and efficiency in processing sub-table data in the existing technology is solved, efficient database operations are achieved, database pressure is reduced and performance is improved.
Patent Information
- Application Number
- CN201810979311.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2018-08-27
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2038-08-27
AI Technical Summary
The performance and efficiency of the existing method of processing sub-table data are not high, and all data tables need to be looped to obtain processing results, resulting in high pressure on the database and low performance.
By generating the primary key, using the primary key to directly locate the data table, and executing the instructions of the dynamic structured query language in the data table, the cumbersome operation of looping through all data tables is avoided. The primary key generation method includes using the hash code value of the sub-table field and the server MAC address, combined with the timestamp and sequence number, to ensure uniqueness and global uniqueness in a distributed cluster.
It effectively improves the efficiency of processing sub-table data, reduces the access pressure on the database, improves database performance, and avoids redundant loop problems caused by the complexity of the database structure.
Smart Images

Figure CN110866002B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and device for processing sub-table data. Background Art
[0002] Table sharding can refer to the data originally stored in one table being divided into blocks and stored in multiple data tables, and table sharding data can refer to the data stored in each data table after table sharding. For the processing of table sharding data, in the prior art, since it is impossible to directly locate the data table storing the data to be processed, the only way is to globally query the data records corresponding to all tables, that is, query, modify, delete and other processing operations need to loop through all data tables, obtain the processing results in each data table, and then aggregate all the processing results.
[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art: the performance and efficiency of the method of processing sub-table data in the prior art are not high. Summary of the invention
[0004] In view of this, an embodiment of the present invention provides a method and device for processing sub-table data, which can solve the problem of low ability and efficiency in processing sub-table data due to the need to loop all data tables to obtain processing results in each data table and then aggregate all processing results.
[0005] To achieve the above-mentioned purpose, according to one aspect of an embodiment of the present invention, a method for processing sub-table data is provided, comprising: obtaining data to be processed and instructions of a dynamic structured query language; determining whether the data to be processed carries a primary key; if so, determining a data table corresponding to the data to be processed according to a data table number in the primary key; in the data table, processing the data to be processed according to the instructions of the dynamic structured query language.
[0006] Optionally, the primary key is generated in the following manner: obtain a sub-table field and determine a hash code value of the sub-table field; divide the hash code value of the sub-table field by the total number of data tables, and use the remainder as the data table number corresponding to the sub-table field; obtain the MAC address of the server and determine the hash code value of the MAC address; divide the hash code value of the MAC address by the total number of data tables, and use the remainder as the serial number; generate the primary key based on the timestamp of the current time, the serial number, the database number and the data table number.
[0007] Optionally, the primary key includes in sequence: a sign bit, a 41-bit timestamp, an 8-bit sequence number, a 6-bit database number and an 8-bit data table number.
[0008] Optionally, the method further includes: if the data to be processed does not carry a primary key, determining whether there is a sub-table field; if there is a sub-table field, determining a hash code value of the sub-table field; dividing the hash code value of the sub-table field by the total number of data tables, as the remainder of the hash code value of the sub-table field corresponding to the data to be processed, and determining the data table corresponding to the data to be processed according to the data table number; if there is no sub-table field, cyclically searching for the data table corresponding to the data to be processed in all data tables.
[0009] Optionally, judging whether the data to be processed carries a primary key; if so, determining a data table corresponding to the data to be processed according to the data table number in the primary key, further comprising: if the instruction of the dynamic structured query language is an instruction to modify data or delete data or query data, and the data to be processed carries a primary key, then: determining a data table corresponding to the data to be processed according to the data table number in the primary key; if the instruction of the dynamic structured query language is an instruction to add data, then: the data to be processed does not carry a primary key; obtaining a sub-table field, and determining a hash code value of the sub-table field; taking the remainder of the hash code value of the sub-table field divided by the total number of data tables as the data table number corresponding to the data to be processed, and determining the data table corresponding to the data to be processed according to the data table number.
[0010] To achieve the above-mentioned purpose, according to one aspect of an embodiment of the present invention, a device for processing sub-table data is provided, comprising: an acquisition module, used to: acquire data to be processed and instructions of a dynamic structured query language; a data table determination module, used to: determine whether the data to be processed carries a primary key; if so, determine the data table corresponding to the data to be processed according to the data table number in the primary key; and an instruction execution module, used to: process the data to be processed in the data table according to the instructions of the dynamic structured query language.
[0011] Optionally, the device also includes a primary key generation module, which is used to: obtain a sub-table field and determine a hash code value of the sub-table field; divide the hash code value of the sub-table field by the total number of data tables, and use the remainder as the data table number corresponding to the sub-table field; obtain a MAC address of the server and determine the hash code value of the MAC address; divide the hash code value of the MAC address by the total number of data tables, and use the remainder as the serial number; generate a primary key based on the timestamp of the current time, the serial number, the database number and the data table number.
[0012] Optionally, the primary key generation module is further used to: generate a primary key that includes a sign bit, a 41-bit timestamp, an 8-bit sequence number, a 6-bit database number and an 8-bit data table number in sequence.
[0013] Optionally, the data table determination module is also used to: if the data to be processed does not carry a primary key, determine whether there is a sub-table field; if there is a sub-table field, determine the hash code value of the sub-table field; divide the hash code value of the sub-table field by the total number of data tables as the data table number corresponding to the data to be processed, and determine the data table corresponding to the data to be processed according to the data table number; if there is no sub-table field, cyclically search for the data table corresponding to the data to be processed in all data tables.
[0014] Optionally, the data table determination module is also used for: if the instruction of the dynamic structured query language is an instruction to modify data or delete data or query data, and the data to be processed carries a primary key, then: determining the data table corresponding to the data to be processed according to the data table number in the primary key; if the instruction of the dynamic structured query language is an instruction to add data, then: the data to be processed does not carry a primary key; obtaining the sub-table field and determining the hash code value of the sub-table field; taking the remainder of dividing the hash code value of the sub-table field by the total number of data tables as the data table number corresponding to the data to be processed, and determining the data table corresponding to the data to be processed according to the data table number.
[0015] To achieve the above-mentioned purpose, according to one aspect of an embodiment of the present invention, there is provided an electronic device, comprising: one or more processors; a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method for processing sub-table data as proposed in an embodiment of the present invention.
[0016] To achieve the above objective, according to one aspect of an embodiment of the present invention, a computer readable medium is provided, on which a computer program is stored, and when the program is executed by a processor, the method for processing sub-table data proposed in the embodiment of the present invention is implemented.
[0017] An embodiment of the above invention has the following advantages or beneficial effects: because it adopts a technical means of directly and correctly locating the data table according to the primary key and executing the instructions of the dynamic structured query language in the data table, there is no need to loop all the data tables that need to be operated, which effectively avoids the problem of redundant loops caused by the complexity of the database structure, improves the efficiency of processing sub-table data, thereby reducing the pressure of processing data in the database and improving the performance of the database.
[0018] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0020] Figure 1 is a schematic diagram of the basic flow of a method for processing sub-table data according to an embodiment of the present invention;
[0021] Figure 2 is a schematic diagram of a primary key generation strategy according to an embodiment of the present invention;
[0022] Figure 3 is a schematic diagram of a preferred process of a method for processing sub-table data according to an embodiment of the present invention;
[0023] Figure 4 is a schematic diagram of basic modules of a device for processing sub-table data according to an embodiment of the present invention;
[0024] Figure 5 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0025] Figure 6 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0026] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0027] Figure 1 FIG. 2 is a schematic diagram of the basic flow of the method for processing sub-table data according to an embodiment of the present invention. Figure 1 As shown, an embodiment of the present invention provides a method for processing table data, including:
[0028] Step S101. Obtaining data to be processed and dynamic structured query language (SQL) instructions;
[0029] Step S102: Determine whether the data to be processed carries a primary key; if so, determine the data table corresponding to the data to be processed according to the data table number in the primary key;
[0030] Step S103: In the data table, the data to be processed is processed according to instructions of the dynamic structured query language.
[0031] The data table number can be the serial number of the data table or the data table ID. The primary key can refer to a unique record representing a certain data in the database. The embodiment of the present invention adopts a technical means to directly and correctly locate the data table according to the primary key, and execute the instructions of the dynamic structured query language in the data table, without looping all the data tables that need to be operated, effectively avoiding the problem of loop redundancy caused by the complexity of the database structure, improving the efficiency of processing sub-table data, thereby reducing the access pressure of the database and improving the performance of the database.
[0032] In the embodiment of the present invention, the primary key is generated in the following manner: obtaining a sub-table field and determining a hash code value of the sub-table field; dividing the hash code value of the sub-table field by the total number of data tables according to the hash code value of the sub-table field and the total number of data tables, as the data table number corresponding to the sub-table field; obtaining the media access control address (i.e., MAC address) of the server and determining the hash code value of the media access control address; dividing the hash code value of the media access control address by the total number of data tables according to the hash code value of the media access control address and the total number of data tables, as the sequence number; generating the primary key according to the timestamp of the current time, the sequence number, the database number, and the data table number. After the primary key is generated, the primary key needs to be added to the data newly added to the data table. Based on the snowflake algorithm (snowFlake), the embodiment of the present invention optimizes the generation method of the primary key, so that the primary key can save the information of the database and the data table, and realizes the beneficial effect of locating the database and the data table by the primary key in the process of processing the sub-table data. SnowFlake is an algorithm for generating a globally unique ID (i.e., primary key) under a distributed cluster. In the embodiment of the present invention, a globally unique ID in a distributed cluster can also be generated by a third party similar to a distributed application coordination service zookerper.
[0033] In the embodiment of the present invention, the primary key includes in sequence: a sign bit, a 41-bit timestamp, an 8-bit sequence number, a 6-bit database number and an 8-bit data table number. Figure 2 Schematic diagram of a primary key generation strategy according to an embodiment of the present invention; Figure 2As shown, the first bit is a sign bit, which has no business significance; the following 41 bits represent the timestamp, which is in milliseconds. 41 bits can represent the value of 2^41-1 milliseconds, which is 69 years when converted into years; the following 8-bit serial number is used to distinguish the same data generated in the same millisecond. In a cluster environment, when multiple instances have the same timestamp, an 8-bit value needs to be generated based on the mac address of the instance to distinguish; the following 6-bit database number represents the serial number of the generated database, which supports a total of 63 databases; the last 8-bit data table number represents the serial number of the generated data table, which supports a total of 128 database tables. Based on the snowflake algorithm, the embodiment of the present invention optimizes the generation method of the primary key, so that the primary key can save the information of the database and the data table, and achieves the beneficial effect of locating the database and the data table by using the primary key in the process of processing the sub-table data.
[0034] In an embodiment of the present invention, determining the data table corresponding to the data to be processed according to the data table number in the primary key includes: determining the last 8 bits in the primary key as the data table number according to the primary key; and locating the data table corresponding to the data to be processed according to the data table number. Based on the snowflake algorithm, the embodiment of the present invention optimizes the generation method of the primary key, so that the primary key can save the information of the data table, and achieves the beneficial effect of locating the data table by using the primary key in the process of processing the sub-table data.
[0035] In an embodiment of the present invention, the method further includes: if the data to be processed does not carry a primary key, determining whether there is a sub-table field; if there is a sub-table field, determining the hash code value of the sub-table field; according to the hash code value of the sub-table field and the total number of data tables, dividing the hash code value of the sub-table field by the total number of data tables, as the data table number corresponding to the data to be processed, and determining the data table corresponding to the data to be processed according to the data table number; if there is no sub-table field, cyclically searching for the data table corresponding to the data to be processed in all data tables. The sub-table field is the basis for storing the data in a table into multiple data tables, and determines the result of the sub-table. For example, user information is stored in two data tables according to "gender", and in the process of sub-table, "gender" is the sub-table field. In the case of no primary key, the embodiment of the present invention adopts the technical means of locating the data table according to the sub-table field, without cyclically looping all the data tables that need to be operated, effectively avoiding the problem of cyclic redundancy caused by the complexity of the database structure, improving the efficiency of processing sub-table data, thereby reducing the access pressure of the database and improving the performance of the database.
[0036] In an embodiment of the present invention, it is determined whether the data to be processed carries a primary key; if so, a data table corresponding to the data to be processed is determined according to the data table number in the primary key, and it also includes: if the instruction of the dynamic structured query language is an instruction to modify data or delete data or query data, and the data to be processed carries a primary key, then: the data table corresponding to the data to be processed is determined according to the data table number in the primary key; if the instruction of the dynamic structured query language is an instruction to add data, then: the data to be processed does not carry a primary key; a sub-table field is obtained to determine a hash code value of the sub-table field; according to the hash code value of the sub-table field and the total number of data tables, the remainder of dividing the hash code value of the sub-table field by the total number of data tables is used as the data table number corresponding to the data to be processed, and the data table corresponding to the data to be processed is determined according to the data table number. For new data that needs to be added to the data table, since it does not carry a primary key, it is necessary to locate the data table based on the sub-table fields (that is, determine the data table to which the new data is to be added); after generating the primary key based on the sub-table fields, add the primary key to the new data, so that when the new data is modified, deleted, queried, etc., the primary key can be used to directly locate the data table, thereby improving the efficiency of processing sub-table data and reducing the pressure of processing data in the database.
[0037] An embodiment of realizing adding new data is further proposed, and the steps are as follows:
[0038] Generate dynamic SQL statements (or instructions) with new functions according to the SQL rules of the mybatis framework; the parameters representing the database table in the dynamic SQL statement are dynamic parameters;
[0039] Calculate the hash code value based on the sub-table field, divide it by the total number of data tables and take the remainder to get the data table number;
[0040] Generate a unique primary key based on the timestamp, sequence number, database sequence and data table sequence, where the sequence number is calculated by dividing the hashCode value of the Media Access Control (MAC) address by the total number of data tables and taking the remainder;
[0041] Specifically, you can use the invoke method in the proxy class MapperProxy to use the generated primary key to initialize the primary key of the entity class object (that is, add the generated primary key to the new data), determine the data table according to the data table number, get the parameters of the data table, and dynamically replace the parameters with the parameters in the dynamic SQL statement; after the dynamic replacement, add the new data directly to the data table and save it to complete the data addition.
[0042] Among them, the timestamp represents a long integer binary code of the current time, which can be understood as the current time. The serial number is an 8-bit binary code generated by processing the MAC address of the physical machine (server). The database table sequence is an 8-bit binary code generated according to the routing rules. Dynamic SQL statements support dynamic replacement of database tables that need to be added or queried. For example, the statement: "select * from [table A]" in [table A] is dynamically generated according to the routing rules. The hash code (hashCode) value is an int type value calculated by the toolkit JDK based on the address, string or number of the object. Mybatis is a middleware that supports persistence layer operations and dynamic replacement of data.
[0043] Further, embodiments for implementing other data processing functions in addition to the newly added functions are as follows:
[0044] Generate dynamic SQL statements (or instructions) with new functions according to the SQL rules of the mybatis framework. The parameters representing the database table in the dynamic SQL statement are dynamic parameters.
[0045] You can use the invoke method of MapperProxy to determine whether there is a primary key. If there is a primary key, then directly locate the corresponding data table based on the primary key, dynamically replace the parameters of the corresponding database table, and then execute the dynamic SQL statement. If there is no primary key, then determine whether the value of the sub-table field exists. If it does, then get the data table number based on the sub-table field, so as to locate the corresponding data table, dynamically replace the parameters of the corresponding database table, and then execute the dynamic SQL statement. If it does not exist, then it is necessary to recursively search the corresponding data table in full (that is, loop all data tables of the current data structure, query the data that meets the conditions, and the data table where the data is located is the corresponding data table) to execute the dynamic SQL statement.
[0046] Figure 3 Schematic diagram of the preferred process of the method for processing sub-table data according to an embodiment of the present invention; Figure 3 As shown, the specific modification, deletion, and query process can be as follows:
[0047] Modification process: Determine whether the modification condition has a primary key. If so, directly obtain the last 8 digits of the id and directly locate the data table. If the primary key does not exist, determine whether there is a sub-table field to calculate the hash value and the data table, modify the data and return. If none of them exist, then it is necessary to loop all tables to modify the data.
[0048] Deletion process: Determine whether the modification condition has a primary key. If so, directly obtain the last 8 digits of the id and define it directly to the data table. If the primary key does not exist, determine whether there is a sub-table field to calculate the hash value and calculate the data table, delete the data and return. If none of them exist, then it is necessary to loop through all tables to delete the data.
[0049] Query process: Determine whether the modified condition has a primary key. If so, directly obtain the last 8 digits of the id and define it directly to the data table. If the primary key does not exist, determine whether there is a sub-table field to calculate the hash value and calculate the data table, query the data and return it. If none of them exist, then it is necessary to loop all tables to query the data.
[0050] The embodiment of the present invention provides a device 400 for processing data in a sub-table, including: an acquisition module 401, used to: acquire data to be processed and instructions of a dynamic structured query language; a data table determination module 402, used to: determine whether the data to be processed carries a primary key; if so, determine the data table corresponding to the data to be processed according to the data table number in the primary key; an instruction execution module 403, used to: in the data table, process the data to be processed according to the instructions of the dynamic structured query language. The embodiment of the present invention adopts a technical means of directly and correctly locating a data table according to a primary key, and executing instructions of a dynamic structured query language in the data table, without looping all data tables that need to be operated, effectively avoiding the problem of loop redundancy caused by the complexity of the database structure, improving the efficiency of processing sub-table data, thereby reducing the access pressure of the database and improving the performance of the database.
[0051] In the embodiment of the present invention, the device further comprises a primary key generation module, which is used to: obtain the sub-table field, determine the hash code value of the sub-table field; divide the hash code value of the sub-table field by the total number of data tables according to the hash code value of the sub-table field and the total number of data tables, and use the remainder of the hash code value of the sub-table field divided by the total number of data tables as the data table number corresponding to the sub-table field; obtain the media access control address of the server, determine the hash code value of the media access control address; divide the hash code value of the media access control address by the total number of data tables according to the hash code value of the media access control address and the total number of data tables, and use the remainder of the hash code value of the media access control address divided by the total number of data tables as the sequence number; generate the primary key according to the timestamp of the current time, the sequence number, the database number and the data table number. The embodiment of the present invention optimizes the generation method of the primary key based on the snowflake algorithm, so that the primary key can save the information of the database and the data table, and realizes the beneficial effect of locating the database and the data table by the primary key in the process of processing the sub-table data.
[0052] In the embodiment of the present invention, the primary key generation module is further used to: generate a primary key including a sign bit, a 41-bit timestamp, an 8-bit sequence number, a 6-bit database number and an 8-bit data table number in sequence. Based on the snowflake algorithm, the embodiment of the present invention optimizes the generation method of the primary key, so that the primary key can save the information of the database and the data table, and achieves the beneficial effect of locating the database and the data table by using the primary key in the process of processing the sub-table data.
[0053] In the embodiment of the present invention, the data table determination module is further used to: determine the last 8 bits of the primary key as the data table number according to the primary key; and locate the data table corresponding to the data to be processed according to the data table number. The embodiment of the present invention optimizes the generation method of the primary key based on the snowflake algorithm, so that the primary key can save the information of the data table, and achieves the beneficial effect of locating the data table by using the primary key in the process of processing the sub-table data.
[0054] In an embodiment of the present invention, the module for determining the data table is also used to: if the data to be processed does not carry a primary key, determine whether there is a sub-table field; if there is a sub-table field, determine the hash code value of the sub-table field; according to the hash code value of the sub-table field and the total number of data tables, divide the hash code value of the sub-table field by the remainder of the total number of data tables as the data table number corresponding to the data to be processed, and determine the data table corresponding to the data to be processed according to the data table number; if there is no sub-table field, loop through all data tables to find the data table corresponding to the data to be processed. In the case of no primary key, the embodiment of the present invention adopts a technical means of locating the data table according to the sub-table field, without looping all the data tables that need to be operated, effectively avoiding the problem of loop redundancy caused by the complexity of the database structure, improving the efficiency of processing sub-table data, thereby reducing the access pressure of the database and improving the performance of the database.
[0055] In an embodiment of the present invention, the data table determination module is further used for: if the instruction of the dynamic structured query language is an instruction to modify data or delete data or query data, and the data to be processed carries a primary key, then: determining the data table corresponding to the data to be processed according to the data table number in the primary key; if the instruction of the dynamic structured query language is an instruction to add data, then: the data to be processed does not carry a primary key; obtaining a sub-table field and determining a hash code value of the sub-table field; according to the hash code value of the sub-table field and the total number of data tables, dividing the hash code value of the sub-table field by the total number of data tables is the remainder as the data table number corresponding to the data to be processed, and determining the data table corresponding to the data to be processed according to the data table number. For new data that needs to be added to the data table, since it does not carry a primary key, it is necessary to locate the data table based on the sub-table fields (that is, determine the data table to which the new data is to be added); after generating the primary key based on the sub-table fields, add the primary key to the new data, so that when the new data is modified, deleted, queried, etc., the primary key can be used to directly locate the data table, thereby improving the efficiency of processing sub-table data and reducing the pressure of processing data in the database.
[0056] Figure 5 An exemplary system architecture 500 is shown to which the method or apparatus for processing data in a divided table according to an embodiment of the present invention can be applied.
[0057] like Figure 5 As shown, system architecture 500 may include terminal devices 501, 502, 503, a network 504 and a server 505. Network 504 is used to provide a medium for communication links between terminal devices 501, 502, 503 and server 505. Network 504 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.
[0058] Users can use terminal devices 501, 502, 503 to interact with server 505 through network 504 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 501, 502, 503, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0059] The terminal devices 501 , 502 , and 503 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.
[0060] Server 505 may be a server that provides various services, such as a backend management server that provides support for shopping websites browsed by users using terminal devices 501, 502, and 503. The backend management server may analyze and process received data such as product information query requests, and feed back the processing results to the terminal device.
[0061] It should be noted that the method for processing sub-table data provided in the embodiment of the present invention is generally executed by the server 505 , and accordingly, the device for processing sub-table data is generally disposed in the server 505 .
[0062] It should be understood that Figure 5 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0063] According to an embodiment of the present invention, the present invention also provides an electronic device and a computer-readable medium.
[0064] The electronic device of the embodiment of the present invention includes: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement the method for processing sub-table data proposed in the embodiment of the present invention.
[0065] The computer-readable medium of the embodiment of the present invention stores a computer program, and when the program is executed by a processor, the method for processing sub-table data proposed in the embodiment of the present invention is implemented.
[0066] Reference below Figure 6 , which shows a schematic diagram of the structure of a computer system 600 of a terminal device suitable for implementing an embodiment of the present invention. Figure 6 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0067] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage part 608 into a random access memory (RAM) 603. In the RAM 603, various programs and data required for the operation of the system 600 are also stored. The CPU 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0068] The following components are connected to the I / O interface 605: an input section 606 including a keyboard, a mouse, etc.; an output section 607 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, a modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the I / O interface 605 as needed. A removable medium 611, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 610 as needed, so that a computer program read therefrom is installed into the storage section 608 as needed.
[0069] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 609, and / or installed from the removable medium 611. When the computer program is executed by the central processing unit (CPU) 601, the above-mentioned functions defined in the system of the present invention are executed.
[0070] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0071] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0072] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor, for example, it may be described as: a processor includes: an acquisition module, a data table determination module, and an instruction execution module. The names of these modules do not constitute a limitation on the modules themselves in some cases, for example, the acquisition module may also be described as "a module for acquiring data to be processed and instructions of a dynamic structured query language".
[0073] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes: step S101. Obtaining the data to be processed and the instructions of the dynamic structured query language; step S102. Determining whether the data to be processed carries a primary key; if so, determining the data table corresponding to the data to be processed according to the data table number in the primary key; step S103. In the data table, processing the data to be processed according to the instructions of the dynamic structured query language.
[0074] The embodiment of the present invention adopts a technical means to directly and correctly locate the data table according to the primary key and execute the instructions of the dynamic structured query language in the data table, without looping all the data tables that need to be operated. It effectively avoids the problem of redundant loops caused by the complexity of the database structure, improves the efficiency of processing sub-table data, thereby reducing the pressure of processing data in the database and improving the performance of the database.
[0075] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for processing sub-table data, characterized in that: include: Get data to be processed and dynamic structured query language instructions; Determine whether the data to be processed carries a primary key; If so, the data table corresponding to the data to be processed is determined according to the data table number in the primary key; wherein the primary key is generated in the following manner: obtaining a sub-table field and determining a hash code value of the sub-table field; dividing the hash code value of the sub-table field by the total number of data tables, as the remainder of the data table number corresponding to the sub-table field; obtaining the MAC address of the server and determining the hash code value of the MAC address; dividing the hash code value of the MAC address by the total number of data tables, as the remainder of the sequence number; generating a primary key according to the timestamp of the current time, the sequence number, the database number and the data table number; wherein the sub-table field is the basis for storing data in a table in blocks into multiple data tables, and determines the result of the sub-table; If the data to be processed does not carry a primary key, determine whether there is a sub-table field; if there is a sub-table field, determine the hash code value of the sub-table field; divide the hash code value of the sub-table field by the total number of data tables to obtain the remainder as the data table number corresponding to the data to be processed, and determine the data table corresponding to the data to be processed according to the data table number; if there is no sub-table field, search the data table corresponding to the data to be processed in all data tables in a loop; In the data table, the data to be processed is processed according to instructions of the dynamic structured query language.
2. The method according to claim 1, characterized in that The primary key includes in sequence: a sign bit, a 41-bit time stamp, an 8-bit sequence number, a 6-bit database number and an 8-bit data table number.
3. The method according to claim 1, characterized in that: Determine whether the data to be processed carries a primary key; If yes, then determining the data table corresponding to the data to be processed according to the data table number in the primary key, further comprising: If the instruction of the dynamic structured query language is an instruction to modify data, delete data or query data, and the data to be processed carries a primary key, then: Determine the data table corresponding to the data to be processed according to the data table number in the primary key; If the instruction of the dynamic structured query language is an instruction to add data, then: The data to be processed does not carry a primary key; a sub-table field is obtained, and a hash code value of the sub-table field is determined; a remainder of dividing the hash code value of the sub-table field by the total number of data tables is used as the data table number corresponding to the data to be processed, and a data table corresponding to the data to be processed is determined according to the data table number.
4. A device for processing sub-table data, characterized in that: include: A primary key generation module is used to obtain a sub-table field and determine a hash code value of the sub-table field; The remainder of dividing the hash code value of the sub-table field by the total number of data tables is used as the data table number corresponding to the sub-table field; the MAC address of the server is obtained, and the hash code value of the MAC address is determined; the remainder of dividing the hash code value of the MAC address by the total number of data tables is used as the sequence number; the primary key is generated according to the timestamp of the current time, the sequence number, the database number and the data table number; An acquisition module, used to: acquire data to be processed and instructions of a dynamic structured query language; Determine a data table module, used to: determine whether the data to be processed carries a primary key; If yes, determining the data table corresponding to the data to be processed according to the primary key; If the data to be processed does not carry a primary key, determine whether there is a sub-table field; If the sub-table field exists, determine the hash code value of the sub-table field; The remainder of dividing the hash code value of the sub-table field by the total number of data tables is used as the data table number corresponding to the data to be processed, and the data table corresponding to the data to be processed is determined according to the data table number; If the sub-table field does not exist, then loop through all data tables to find the data table corresponding to the data to be processed; The instruction execution module is used to: in the data table, process the data to be processed according to the instruction of the dynamic structured query language.
5. The device according to claim 4, characterized in that The primary key generation module is also used to: generate a primary key which includes a sign bit, a 41-bit time stamp, an 8-bit sequence number, a 6-bit database number and an 8-bit data table number in sequence.
6. The device according to claim 4, characterized in that The data table determination module is further used for: If the instruction of the dynamic structured query language is an instruction to modify data, delete data or query data, and the data to be processed carries a primary key, then: Determine the data table corresponding to the data to be processed according to the data table number in the primary key; If the instruction of the dynamic structured query language is an instruction to add data, then: The data to be processed does not carry a primary key; a sub-table field is obtained, and a hash code value of the sub-table field is determined; a remainder of dividing the hash code value of the sub-table field by the total number of data tables is used as the data table number corresponding to the data to be processed, and a data table corresponding to the data to be processed is determined according to the data table number.
7. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 3.
8. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 3 is implemented.
