A table structure inspection method, a table structure inspection device, and an electronic device
By acquiring and parsing the header field information of the database table structure file, dependency-free inspection was achieved, solving the problem of dependence on online database instances in existing technologies and improving inspection efficiency and database stability.
Patent Information
- Application Number
- CN202111529277.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-14
- Publication Date
- 2026-02-17
- Estimated Expiration
- 2041-12-14
AI Technical Summary
Existing methods for inspecting financial system databases rely on online database instances, which leads to strong dependency and may affect database performance and stability.
By obtaining the table structure file containing the data tables, the file type is obtained from the header field of the file, and the inspection information is obtained based on the field corresponding to the file type. This allows for dependency-free inspection and querying of the table structure information.
This enables inspections that do not rely on online database instances, reducing resource consumption, avoiding the consumption of database connections and buffer pools, and improving inspection efficiency and database stability.
Smart Images

Figure CN114385679B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the technical field of data processing of financial technology (Fintech), and relate to but are not limited to a table structure inspection method, a table structure inspection device, an electronic device and a storage medium. BACKGROUND
[0002] With the development of computer computing, more and more technologies are applied in the financial field, and the traditional financial industry is gradually changing to financial technology (Fintech). However, due to the security and real-time requirements of the financial industry, Fintech also puts forward higher requirements for technology.
[0003] In the field of Fintech, at present, due to the existence of vulnerabilities or imprecise code implementation in the database in the financial system, such as the relational database, it may cause instability of the performance of the database when running, or cause the problem of failure, restart and even data loss of the database. In order to ensure the data security and data consistency in the database of the financial system, in the actual use process, the database administrator (DBA) will control the permission of the business user, and at the same time, regulate the use of the database in the form of internal document to avoid the situation of data inconsistency or even data loss to the greatest extent. However, only through propaganda is not enough to ensure that the use of the business side is carried out according to the specification. Further, as the operator of the database, the DBA also needs to regularly inspect the table structure in the online database to ensure that the specification is executed.
[0004] In the related art, the method of inspecting the table structure includes:
[0005] 1) Through the "show create table t1\G" statement, the table structure of each table in the database instance is displayed in the form of a table creation statement at a regular time;
[0006] 2) Through the mysqldump command, the table structure of all tables in the database instance is exported in the form of a table creation statement, such as "mysqldump -h localhost -u root -p --no-data --compact some_db";
[0007] 3) Find out the table structure that violates the rules by querying the meta information of the table in the information_schema library in a timely manner, such as using "select TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME from information_schema.tables where row_format='compressed'", all tables with row record format compressed in the database instance are screened out.
[0008] However, the above three methods must rely on the database instance running online, and at least there is a strong dependence problem. SUMMARY
[0009] Embodiments of the present application provide a table structure inspection method, a table structure inspection device, an electronic device and a storage medium to solve the problem that related technologies must rely on a database instance running online, at least there is a strong dependence problem.
[0010] The technical solutions of the embodiments of the present application are as follows:
[0011] The embodiments of the present application provide a method, comprising:
[0012] obtaining a file storing table structure of a data table;
[0013] obtaining a file type from a header field of the file;
[0014] for a to-be-inspected object corresponding to the file type, obtaining to-be-inspected information based on a field corresponding to the file type in the file;
[0015] inspecting the to-be-inspected object based on the to-be-inspected information to query table structure information of the data table.
[0016] The embodiments of the present application provide a device, comprising:
[0017] an obtaining module configured to obtain a file storing table structure of a data table;
[0018] The obtaining module is further configured to obtain a file type from a header field of the file;
[0019] The obtaining module is further configured to, for a to-be-inspected object corresponding to the file type, obtain to-be-inspected information based on a field corresponding to the file type in the file;
[0020] a processing module configured to inspect the to-be-inspected object based on the to-be-inspected information to query table structure information of the data table.
[0021] The embodiment of the present application provides an electronic device, comprising:
[0022] a memory for storing executable instructions;
[0023] a processor for executing the executable instructions stored in the memory to implement the method.
[0024] The embodiment of the present application provides a storage medium, which stores executable instructions, and is used for causing a processor to execute the method.
[0025] The embodiment of the present application has the following beneficial effects:
[0026] The electronic device of the present application obtains a file in which a table structure of a data table is stored, obtains a file type from a header field of the file, then determines a field corresponding to the file type in the file to obtain to-be-inspected information according to a to-be-inspected object corresponding to the file type, and finally inspects the to-be-inspected object based on the to-be-inspected information, so that the table structure information of the data table is queried. In this way, the present application solves the problem that the related art must depend on a database instance in online operation, at least the problem of strong dependence; the present application realizes the inspection without depending on the database instance in operation, so that no database connection or buffer pool resource is occupied; in this way, while processing the inspection task, no additional storage space is consumed, and resource occupation is reduced. BRIEF DESCRIPTION OF DRAWINGS
[0027] Figure 1 is an optional architecture schematic diagram of the electronic device provided by the embodiment of the present application;
[0028] Figure 2 is an optional flow schematic diagram of the table structure inspection method provided by the embodiment of the present application;
[0029] Figure 3 is an optional flow schematic diagram of the table structure inspection method provided by the embodiment of the present application;
[0030] Figure 4 is an optional flow schematic diagram of the table structure inspection method provided by the embodiment of the present application;
[0031] Figure 5 is an optional flow schematic diagram of the table structure inspection method provided by the embodiment of the present application;
[0032] Figure 6 is an optional flow schematic diagram of the table structure inspection method provided by the embodiment of the present application;
[0033] Figure 7 is an optional flow schematic diagram of the table structure inspection method provided by the embodiment of the present application;
[0034] Figure 8 is an optional flowchart of the table structure inspection method provided by the embodiments of the present application. DETAILED DESCRIPTION
[0035] In order to make the objects, technical solutions and advantages of the present application clearer, the present application will be further described in detail below with reference to the accompanying drawings, and the described embodiments should not be regarded as limiting the present application. All other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.
[0036] In the following description, "some embodiments" are related to a subset of all possible embodiments, but it can be understood that "some embodiments" can be the same subset or different subsets of all possible embodiments, and can be combined with each other without conflict. Unless otherwise defined, all technical and scientific terms used in the embodiments of the present application have the same meaning as understood by those skilled in the art to which the embodiments of the present application belong. The terms used in the embodiments of the present application are only for the purpose of describing the embodiments of the present application and are not intended to limit the present application.
[0037] The exemplary application of the electronic device provided by the embodiments of the present application will be described below. The electronic device provided by the embodiments of the present application can be implemented as a notebook computer, a tablet computer, a desktop computer, a smart robot, etc. any terminal with screen display function, or as a server. Below, the exemplary application when implemented as an electronic device will be described.
[0038] Referring to Figure 1 , Figure 1 is a structural schematic diagram of the electronic device 100 provided by the embodiments of the present application, Figure 1 The electronic device 100 shown in the figure includes at least one processor 110, at least one network interface 120, a user interface 130 and a memory 150. The various components in the electronic device 100 are coupled together through a bus system 140. It can be understood that the bus system 140 is used to realize the connection communication between the components. In addition to including a data bus, the bus system 140 also includes a power bus, a control bus and a status signal bus. However, for the purpose of clear illustration, all kinds of buses are marked as the bus system 140 in Figure 1 .
[0039] The processor 110 can be an integrated circuit chip with signal processing capability, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc., wherein the general-purpose processor can be a microprocessor or any conventional processor.
[0040] The user interface 130 includes one or more output devices 131 that enable presentation of media content, including one or more speakers and / or one or more visual display screens. The user interface 130 also includes one or more input devices 132 that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
[0041] The memory 150 can be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard drives, optical drives, and the like. The memory 150 optionally includes one or more storage devices remotely located from the processor 110. The memory 150 comprises a volatile memory or non-volatile memory, and can also include both volatile and non-volatile memory. Non-volatile memory can be read only memory (ROM), volatile memory can be random access memory (RAM). The memory 150 described in embodiments of the present application is intended to include any suitable type of memory. In some embodiments, the memory 150 is capable of storing data to support various operations, examples of which include programs, modules, and data structures or a subset or superset thereof, which are exemplarily explained below.
[0042] The operating system 151 includes systems programs for handling various basic system services and for performing hardware dependent tasks, such as a framework layer, a core library layer, a driver layer, and the like, for implementing various basic services and processing hardware-based tasks;
[0043] The network communication module 152 is used to reach other computing devices via one or more (wired or wireless) network interfaces 120, exemplary network interfaces 120 include: Bluetooth, wireless compatibility certification (Wi-Fi), and universal serial bus (USB), and the like;
[0044] The input processing module 153 is used to detect and translate one or more user inputs or interactions from one or more input devices 132.
[0045] In some embodiments, the apparatus provided by the embodiments of the present application can be realized in software, Figure 1A table structure inspection device 154 stored in the memory 150 is shown, which can be a table structure inspection device in the electronic device 100, which can be software in the form of programs and plug-ins, etc., including the following software modules: an acquisition module 1541, a processing module 1542, and a determination module 1543, which are logical, and thus can be combined or further split according to the implemented functions. The functions of the various modules will be described below.
[0046] In some other embodiments, the device provided by the embodiments of the present application can be implemented in a hardware manner. As an example, the device provided by the embodiments of the present application can be a processor in the form of a hardware decoding processor, which is programmed to execute the table structure inspection method provided by the embodiments of the present application. For example, the processor in the form of a hardware decoding processor can use one or more application specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), field-programmable gate arrays (FPGAs), or other electronic elements.
[0047] The table structure inspection method provided by the embodiments of the present application will be described below in conjunction with an exemplary application and implementation of the electronic device 100 provided by the embodiments of the present application. Referring to Figure 2 , Figure 2 is an optional flowchart of the table structure inspection method provided by the embodiments of the present application, which will be described in conjunction with the steps shown in Figure 2 ,
[0048] Step 201: Acquire a file storing the table structure of a data table.
[0049] In the embodiments of the present application, the file includes the table structure of the data table. Here, the file can be an frm file, and the file can also be other files storing the table structure of the data table, which is not specifically limited in the present application; here, the file can be a binary file, an octal file, or a hexadecimal file, which is not specifically limited in the present application. Here, the present application is described by taking the file as a binary file.
[0050] In the embodiments of the present application, the size of the file in the database management system is fixed. The size of the file can be 256K, and the size of the file can also be 512K. Therefore, the memory consumed for parsing the content in the file will not exceed 512K. Assuming that the memory size of the storage of the electronic device is 128G, the memory space consumed for parsing the content in the file will not exceed 1 / 262144 of the total amount of the memory, so that the memory space occupied for parsing the file will not affect the performance of the electronic device.
[0051] It should be noted that the electronic device will generate a file with the same name as the data table when creating the data table through the database such as MySQL, that is, the file name is the same as the data table name, and the file stores the table structure or framework structure of the data table. It should be emphasized that the file is irrelevant to the operating system used by the electronic device and the data engine used when the database creates the data table, that is, no matter what operating system the database runs on and what storage engine is used to create the data table, a file storing the table structure of the data table will be generated.
[0052] In step 202, the file type is obtained from the header field of the file.
[0053] In the embodiments of the present application, the file type is used to locate the field where the to-be-inspected information in the file is located, and the file type includes a table structure type and a view type. Here, if the file type is a table type, it indicates that the type of the data table is a basic table, and the field where the to-be-inspected information is located includes the header field; if the file type is a view type, it indicates that the type of the data table is a view, and the field where the to-be-inspected information is located is the remaining field in the file except the header field.
[0054] In the embodiments of the present application, the file includes a header field, the length of the header field is a fixed byte, for example, the fixed byte is 64 bytes, that is, the header field contains 64 bytes, and the specified field in the header field, such as the first 2 bytes, indicates the file type of the file.
[0055] Here, the view is a table established based on the base table, the structure (i.e., the defined columns) and the content (i.e., all data rows) of which are from the base table; the view exists in accordance with the base table. Here, one view can correspond to one base table or multiple base tables. The view is an abstraction of the base table and a new relationship established in a logical sense. It should be noted that the view is a structured query language (SQL) statement that has been compiled, is a logical concept, does not occupy physical space, and the modification of the view can only be made by the created statement; the base table occupies physical space and direct modification can be made to the base table. The view is a method of viewing the data table and can query data composed of some fields in the data table, which is only a collection of some SQL statements. From the perspective of security, the user does not touch the data table through the view and thus does not know the table structure. The establishment and deletion of the view only affect the view itself and do not affect the corresponding base table. In short, the view is a result set queried by the select statement.
[0056] In an implementable application scenario, if the file is a binary frm file, and the header field of the file contains 64 bytes, the storage value corresponding to the 1st-2nd byte of the header field indicates the file type of the file. If the storage value corresponding to the 1st-2nd byte is 0x01fe, it represents that the file is a table type file; if the storage value corresponding to the 1st-2nd byte is 0x5954, it represents that the file is a view type file.
[0057] In step 203, for the to-be-inspected object corresponding to the file type, the to-be-inspected information is acquired based on the field corresponding to the file type in the file.
[0058] In the embodiment of the application, if the file type is the table type, the to-be-inspected object includes the storage engine, the character set, the column name, the column character set, the column annotation, the primary key, and whether the row format type includes the compressed mode. If the file type is the view type, the to-be-inspected object includes the table creation statement.
[0059] It should be noted that the compressed format is a row storage format of the innodb table. The table of the innodb engine stored in the compressed format has the advantages of occupying less disk space. However, in the actual use process, under the condition that the page size of the database is 4K, the disk sector is 4K, and the innodb_flush_method is O_DIRECT, accessing the compressed table can cause the database to restart. In order to avoid this vulnerability, the use of the table in the compressed format is generally prohibited.
[0060] In the embodiment of the present application, the electronic device obtains a file corresponding to each data table and storing the table structure of the data table, and obtains the file type from a specified field of the header field of the file; for the to-be-inspected object corresponding to the file type, the to-be-inspected information of the to-be-inspected object is obtained based on the field corresponding to the file type in the file.
[0061] In other embodiments of the present application, before the electronic device obtains the to-be-inspected information of the to-be-inspected object based on the field corresponding to the file type in the file, the header field of the file is decoded by using the set data type.
[0062] Here, the set data type includes unsigned char type, unsigned short type, and the set data type further includes unsigned int type.
[0063] In an implementable application scenario, if B represents unsigned char type, H represents unsigned short type, and I represents unsigned int type, the header field such as BBBBHHIHHIHHHHHBBIBBBBBIIIIBBBHH is decoded by using the set data type, and low byte priority is used. In this way, the header field is decoded into binary.
[0064] It should be noted that what type is used to decode the byte is determined in the source code of the storage engine. In the source code, if the data type of the stored data is unsigned int type, then the decoding should be decoded by using unsigned int type; if the data type of the stored data is unsigned char type, then the decoding should be decoded by using unsigned char type; if the data type of the stored data is unsigned short type, then the decoding should be decoded by using unsigned short type, otherwise, garbled code will be parsed.
[0065] In step 204, the to-be-inspected object is inspected based on the to-be-inspected information to query the table structure information of the data table.
[0066] In the embodiment of the present application, the table structure information includes the storage engine used to store the data table, the character set in the data table, the column name, column character set and column annotation in the data table, whether the data table contains a primary key, and whether the row format type of the data table includes compressed mode. If the file type is a view type, the to-be-inspected object includes a table creation statement used to create the view.
[0067] In the embodiment of the present application, the electronic device obtains the to-be-inspected information based on the field corresponding to the file type in the file, and inspects the to-be-inspected object based on the to-be-inspected information, to query the table structure information of the data table.
[0068] The present application provides a table structure inspection method, which obtains a file storing table structure of a data table, obtains a file type from a header field of the file, then determines a field corresponding to the file type in the file to obtain to-be-inspected information for a to-be-inspected object corresponding to the file type, and finally inspects the to-be-inspected object based on the to-be-inspected information, to query the table structure information of the data table. In this way, the present application solves the problem that the related art must depend on a database instance running online, at least the problem of strong dependence; and the present application realizes the inspection without dependence on the running database instance, so as to not occupy resources such as database connections or buffer pools; in this way, the present application does not consume additional storage space while processing the inspection task, and reduces resource occupation.
[0069] Referring to Figure 3 , Figure 3 is an optional flowchart of the table structure inspection method provided by the embodiment of the present application, which will be described in combination with steps 301 to 305 shown in Figure 3 , or steps 301 to 304 and steps 306 to 309.
[0070] Step 301, obtaining a file storing table structure of a data table.
[0071] Step 302, obtaining a file type from a header field of the file.
[0072] Step 303, if the file type is a table type, determining a first to-be-inspected object corresponding to the table type.
[0073] In the embodiment of the present application, if the file type is the table type, the to-be-inspected object includes a storage engine, a character set, a column name, a column character set, a column annotation, a primary key, and whether a row format type includes a compressed mode. The first to-be-inspected object can be one of the plurality of to-be-inspected objects.
[0074] Step 304, if the first to-be-inspected object is a storage engine, extracting a first storage value from a first field in the header field.
[0075] The to-be-inspected information includes the first storage value.
[0076] In the embodiment of the present application, the header field includes a specified field and a first field. The first storage value corresponding to the first field is used to indicate a storage engine used by the storage data table, or the data table is a partitioned table. For example, the header field contains 64 bytes, and the first field can be the 4th byte in the header field.
[0077] In step 305, if the first storage value indicates the storage engine used by the storage data table, the storage engine is inspected to query the storage engine used by the storage data table.
[0078] The table structure information includes the storage engine used by the storage data table.
[0079] In the embodiment of the present application, the first storage value can indicate the storage engine used by the storage data table, and the first storage value can also indicate that the data table is a partitioned table.
[0080] In the embodiment of the present application, the first storage value is a binary data value, which needs to be converted into a decimal number to inspect the storage engine to query the storage engine used by the storage data table. For example, if the first storage value converted into a decimal number is 9, the storage engine used by the storage data table is the MYISAM storage engine; if the first storage value converted into a decimal number is 12, the storage engine used by the storage data table is the INNODB storage engine; if the first storage value converted into a decimal number is 19, the storage engine used by the storage data table is the BLACKHOLE storage engine. It should be emphasized that if the first storage value converted into a decimal number is 20, it indicates that the data table is a partitioned table, and the storage engine used by the storage partitioned table needs to be further determined.
[0081] In the embodiment of the present application, if the first to-be-inspected object of the electronic device is the storage engine, the first storage value is extracted from the first field in the header field. If the first storage value indicates the storage engine used by the storage data table, the storage engine is inspected to determine the storage engine used by the storage data table.
[0082] In step 306, if the first storage value indicates that the data table is a partitioned table, the second storage value is extracted from the second field in the header field, the third storage value is extracted from the third field in the header field, and the fourth storage value is extracted from the fourth field in the header field.
[0083] The second storage value is used to indicate the byte size of file write-once, the third storage value is used to indicate the storage index record, and the fourth storage value is used to indicate the storage default value.
[0084] In the embodiment of the present application, the header field includes a specified field, a first field, a second field, a third field and a fourth field. The second storage value corresponding to the second field is used to indicate the byte size of one-time writing of the file; the third storage value corresponding to the third field is used to indicate the storage index record; and the fourth storage value corresponding to the fourth field is used to indicate the storage of the default value. For example, the header field contains 64 bytes, the second field can be the 7th-8th byte in the header field, the third field can be the 15th-16th byte in the header field, and the fourth field can be the 17th-18th byte in the header field.
[0085] In step 307, the partition field of the file is determined based on the second storage value, the third storage value and the fourth storage value.
[0086] In the embodiment of the present application, the file includes a header field and a partition field.
[0087] In the embodiment of the present application, the partition field stores the information of the storage engine used by the storage partition table of the electronic device and the partition information.
[0088] In the embodiment of the present application, if the first storage value indicates that the data table is a partition table, and the second storage value is extracted from the second field in the header field, the third storage value is extracted from the third field in the header field, and the fourth storage value is extracted from the fourth field in the header field, the partition field of the file is determined based on the second storage value, the third storage value and the fourth storage value.
[0089] In some embodiments, step 307 of determining the partition field of the file based on the second storage value, the third storage value and the fourth storage value can be implemented by Figure 4
[0090] In step A1, the sum of the second storage value, the third storage value and the fourth storage value is determined as the first byte offset.
[0091] In the embodiment of the present application, if the second field, the third field and the fourth field are each a plurality of bytes, the storage values corresponding to the plurality of bytes are converted into decimal numbers in a low-to-high order manner, and then processed.
[0092] In the embodiment of the present application, if the second field is a plurality of bytes, the second storage value is converted into a decimal number in a low-to-high order manner; if the third field is a plurality of bytes, the third storage value is converted into a decimal number in a low-to-high order manner; and if the fourth field is a plurality of bytes, the fourth storage value is converted into a decimal number in a low-to-high order manner. Then, the sum of the second storage value, the third storage value and the fourth storage value is calculated and used as the first byte offset.
[0093] In step A2, a second byte offset is obtained.
[0094] The second byte offset is used to represent the split byte.
[0095] For example, the second byte offset can be two bytes.
[0096] Step A3, based on the first byte of the obtained file, the first byte offset and the second byte offset, determine the start position of the partition field.
[0097] In the embodiment of the application, the electronic device determines the sum of the second storage value, the third storage value and the fourth storage value as the first byte offset, obtains the set second byte offset, and then skips the first byte offset bytes from the first byte of the file, so as to skip the header field, the index element field and the default value field in the file. Further, the electronic device continues to skip the second byte offset, that is, determines the start position of the partition field. Here, the file includes the header field, the index element field, the default value field and the partition field.
[0098] Step 308, obtain a plurality of fifth storage values from the partition field.
[0099] The to-be-inspected information further includes the second storage value, the third storage value, the fourth storage value and the plurality of fifth storage values. The fifth storage value is used to indicate the storage engine used by the storage partition table.
[0100] In some embodiments, step 308 of obtaining a plurality of fifth storage values from the partition field can be implemented by Figure 5 as shown in the steps:
[0101] Step B1, extract the total byte number from the transition field adjacent to the start position of the partition field.
[0102] The total byte number is used to record the number of bytes occupied by the storage engine used by the storage partition table.
[0103] In the embodiment of the application, the partition field includes a transition field. The transition field stores the total byte number occupied by the storage engine used by the storage partition table, and the electronic device extracts the total byte number from the transition field adjacent to the start position of the partition field, so that the electronic device extracts the storage value used to indicate the storage engine used by the storage partition table from the target field adjacent to the transition field of the partition field.
[0104] In other embodiments of the present application, the electronic device extracts the seventh storage value from the first subfield in the transition field adjacent to the start position of the partition field, and converts the seventh storage value into a decimal number in a low-to-high order; skips the second subfield starting from the end position of the first subfield, wherein the length of the second subfield is the number of bytes corresponding to the seventh storage value; and extracts the total number of bytes from the third subfield adjacent to the second subfield. Here, the transition field includes the first subfield, the second subfield, and the second subfield.
[0105] Step B2, extract a plurality of fifth storage values from the target field adjacent to the transition field of the partition field.
[0106] In embodiments of the present application, the electronic device extracts a plurality of fifth storage values from the target field adjacent to the transition field of the partition field.
[0107] The length of the target field is the total number of bytes.
[0108] In an implementable application scenario, after the electronic device determines the start position of the partition field, first, the electronic device converts the seventh storage value corresponding to the first 1-2 bytes in the first subfield in the transition field adjacent to the start position of the partition field into a decimal number in a low-to-high order to obtain the number of bytes required by the recording storage engine character; second, skips the second subfield starting from the end position of the first subfield, and the length of the second subfield is the number of bytes corresponding to the seventh storage value; and then extracts the total number of bytes PB occupied by the partition string recorded in the third subfield adjacent to the second subfield, such as four bytes, to extract a plurality of storage values corresponding to PB bytes.
[0109] Step 309, based on the plurality of fifth storage values, the storage engine is inspected to query the storage engine used by the storage partition table.
[0110] The table structure information includes the storage engine used by the storage partition table.
[0111] In some embodiments, step 309 based on the plurality of fifth storage values, the storage engine is inspected to query the storage engine used by the storage partition table, which can be achieved by Figure 6 as shown in the steps:
[0112] Step C1, convert each fifth storage value into a first character, and compose a plurality of first characters into a first string.
[0113] In the example of the present application, the electronic device can convert each fifth storage value into a corresponding first character by referring to an ASCII code table; the electronic device can also convert each fifth storage value into a corresponding first character by referring to a set relationship table. The present application does not make a specific limitation in this regard. It should be noted that, if referring to the ASCII code table, the electronic device needs to first convert each fifth storage value into hexadecimal, and then convert each fifth storage value into a first character through the ASCII code table.
[0114] In step C2, the first string is matched with the engine identifier through a regular expression to obtain a storage engine used by the storage partition table.
[0115] In the example of the present application, the engine identifier is used to identify the storage engine used by the storage partition table. For example, the engine identifier can be a keyword such as engine or yinqing, and the engine identifier can also be other symbols, which are not limited in the present application.
[0116] In the example of the present application, the regular expression is a string matching method in software development, which matches a certain string with a fixed string pattern. For example, if the regular expression is "^select", it means matching all strings starting with "select".
[0117] In the example of the present application, when the electronic device obtains a plurality of fifth storage values, first, the electronic device converts each fifth storage value into a first character, and forms a first string by combining a plurality of first characters; second, the electronic device matches the first string with the engine identifier through a regular expression to obtain a storage engine used by the storage partition table.
[0118] In one possible application scenario, after the electronic device extracts a plurality of fifth storage values corresponding to PB bytes, the electronic device refers to an ASCII code table to parse the plurality of fifth storage values into a first string ps. For example, the electronic device converts the plurality of fifth storage values into hexadecimal through a hexdump function, such as: "70 61 72 74 69 74 69 6F6E……". The electronic device converts the first fifth storage value 70 into a corresponding first character "p" by referring to the ASCII code table, and converts the second fifth storage value "61" into a corresponding first character "a". The first string ps converted from the above plurality of fifth storage values is "partition". Finally, the electronic device matches the first string ps and the engine identifier such as the engine field model through a regular expression to obtain a storage engine used by the storage partition table.
[0119] Here, taking 3517 data tables as an example, in the same test environment, the storage engine used to store the data table is inspected, the table structure inspection method of the present scheme is compared with the calculation efficiency of the three existing schemes proposed in the background art, and the results are shown in the following table:
[0120]
[0121] Here, the test time in the above table uses the time command of the operating system. The time command outputs three times: the time consumed by the entire program real, the time consumed by the user state user, and the time consumed by the program running in the core state sys. Among them, only the real time is used to compare the inspection time. It should be noted that because the database instance during running caches part of the meta information of the table structure in the memory, resulting in deviation in the statistical time, therefore, in the test of the present scheme, the time for querying when the database is initially started is selected as the standard.
[0122] From the above table, it can be seen that the table structure inspection method proposed in the present scheme, compared with the three existing schemes proposed in the background art, reduces the inspection time by inspecting the storage engine used to store the data table through the file, improves the inspection efficiency; at the same time, without relying on the running database instance, and without occupying the database connection or buffer pool and other resources, the storage engine of the table type data table is inspected, which makes the inspection task completely not affect the normal service of the database instance, improves the robustness of the method, and completely does not consume additional storage space, reduces the resource occupation.
[0123] It should be noted that the same steps and the same content in the present embodiment and other embodiments can refer to the description in other embodiments, and will not be repeated here.
[0124] Referring to Figure 7 , Figure 7 is an optional flowchart of the table structure inspection method provided by the present embodiment, which will be described in combination with the steps shown in Figure 7 ,
[0125] Step 401, obtaining a file storing the table structure of a data table.
[0126] Step 402, obtaining the file type from the header field of the file.
[0127] Step 403, if the file type is a table type, determining a first to-be-inspected object corresponding to the table type.
[0128] Step 404, if the first to-be-inspected object is a character set, obtaining the version information of the database running the data table and the character sequence number of the data table from the header field.
[0129] The inspection information includes version information of the database and character sequence number of the data table.
[0130] In the embodiment, the version information is a version corresponding to an update of a defect or a vulnerability in the database every interval of a period of time. It should be noted that the database has a version information corresponding to each update. Here, the version information can be a version number of the database.
[0131] In the embodiment, the character sequence number is a sequence number set for each character sequence.
[0132] In step 405, a character dictionary corresponding to the version information is obtained.
[0133] In the embodiment, the character dictionary includes the character sequence number, the character set name, the character sequence name, the maximum length of each character in the character set, and whether to contain a null value.
[0134] Here, the character set can be understood as a collection of various characters and symbols, such as characters of various countries, punctuation marks, graphical symbols, numbers, etc.; the character set can also be understood as a coding method of characters, that is, a mapping rule of binary data and characters. The character set name includes ASCII, ISO 8859-1, GB2312, and the character set name can also include GBK, utf8, and utf8mb4.
[0135] Here, the character sequence is a rule for comparing characters in a group of character sets, such as whether to ignore case, whether to compare characters according to binary. The character sequence name includes utf8_croatian_ci, utf8mb4_unicode_ci, and utf8mb4_swedish_ci, and the character name can also include utf8mb4_persian_ci, utf8mb4_croatian_ci, utf8mb4_bin, and utf8mb4_spanish_ci. Exemplarily, as shown below is a character dictionary,
[0136] ["576", "utf8", "utf8_croatian_ci", "3", ""],
[0137] ["224", "utf8mb4", "utf8mb4_unicode_ci", "4", ""],
[0138] ["232", "utf8mb4", "utf8mb4_swedish_ci", "4", ""],
[0139] ["240", "utf8mb4", "utf8mb4_persian_ci", "4", ""],
[0140] ["608", "utf8mb4", "utf8mb4_croatian_ci", "4", ""],
[0141] ["46", "utf8mb4", "utf8mb4_bin", "4", ""],
[0142] ["231", "utf8mb4", "utf8mb4_spanish_ci", "4", ""]
[0143] The above character dictionary, the first column is the character sequence number, the second column is the character set name, the third column is the character sequence name, the fourth column is the maximum length of each character in the character set, and the fifth column is whether to contain null value.
[0144] Step 406, the character dictionary is inspected according to the character sequence number, so as to query the character set and character sequence in the data table.
[0145] Wherein, the table structure information includes the character set and character sequence in the data table.
[0146] In the embodiment of the application, the electronic device determines that the first to-be-inspected object is a character set, first, obtains the version information of the database running the data table and the character sequence number of the data table from the header field; second, the electronic device obtains the character dictionary corresponding to the version information; finally, the electronic device inspects the character dictionary according to the character sequence number, so as to query the character set and character sequence in the data table corresponding to the character sequence number of the data table.
[0147] Here, taking 3517 data tables as an example, under the same test environment, the character set in the data table is inspected, the computing efficiency of the table structure inspection method of the present solution is compared with that of the three existing solutions in the background art, and the results are shown in the following table:
[0148]
[0149] Here, the test time in the above table uses the time command of the operating system. The time command outputs three times: the time consumed by the entire program real, the time consumed by the user state user, and the time consumed by the program running in the core state sys. Among them, only the real time is used to compare the inspection time. It should be noted that, due to the fact that the database instance will cache part of the meta information of the table structure in the memory during running, the statistical time will be biased, so the time for querying when the database is initially started is selected as the standard in the test of the present solution.
[0150] As can be seen from the above table, compared with the three existing schemes in the background art, the table structure inspection method proposed in the present scheme reduces the inspection time and improves the inspection efficiency by inspecting the character set in the data table through the file; at the same time, the method does not need to rely on the running database instance, and does not occupy the database connection or the buffer pool and other resources, and inspects the character set of the data table of the table type, which makes the inspection task completely not affect the normal service of the database instance, improves the robustness of the method, and completely does not consume extra storage space, reduces the resource occupation.
[0151] In other embodiments of the present application, if the first to-be-inspected object is in row format, the electronic device can implement the method by the following way,
[0152] extracting an eighth stored value from the fifth field in the header field, and if the eighth stored value indicates the row format type corresponding to the data table, inspecting the row format to query the row format type corresponding to the data table.
[0153] The table structure information includes the row format type corresponding to the data table; the to-be-inspected information includes the eighth stored value; and the table structure information includes the row format type corresponding to the data table.
[0154] Here, the eighth stored value is a binary data value, which needs to be converted into a decimal number to inspect the row format to query the row format type corresponding to the data table. For example, if the eighth stored value is converted into a decimal number and is 0, the row format type corresponding to the data table is the default type; if the eighth stored value is converted into a decimal number and is 1, the row format type corresponding to the data table is the fixed type; if the eighth stored value is converted into a decimal number and is 2, the row format type corresponding to the data table is the DYNAMIC type; if the eighth stored value is converted into a decimal number and is 3, the row format type corresponding to the data table is the COMPRESSED type; if the eighth stored value is converted into a decimal number and is 4, the row format type corresponding to the data table is the REDUNDANT type; if the eighth stored value is converted into a decimal number and is 5, the row format type corresponding to the data table is the COMPACT type; and if the eighth stored value is converted into a decimal number and is 6, the row format type corresponding to the data table is the PAGE type. In this way, the row format corresponding to the data table is inspected through the file, the inspection time is reduced, and the inspection efficiency is improved; at the same time, the method does not need to rely on the running database instance, and does not occupy the database connection or the buffer pool and other resources, and inspects the row format of the data table of the table type, which makes the inspection task completely not affect the normal service of the database instance, improves the robustness of the method, and completely does not consume extra storage space, reduces the resource occupation.
[0155] In other embodiments of the present application, if the first to-be-inspected object is a primary key, the electronic device can implement the method as follows,
[0156] D1, extracting the index number from the first transition field adjacent to the start position of the index field of the file.
[0157] In the embodiments of the present application, the electronic device skips the header field of the file, and can determine the index field, and then extract the index number nk from the first transition field adjacent to the start position of the index field.
[0158] D2, extracting the first total number of bytes from the sixth field adjacent to the first transition field of the index field.
[0159] The first total number of bytes is used to indicate the total number of fields contained in the index nkp.
[0160] Here, there are multiple index element fields, and each index element field is composed of an index header field and an index information field. The index header field occupies 8 bytes, and the index information field occupies np×9 bytes, where the value of np is obtained by decoding the fifth byte of the index header field as an unsigned char type, and this bit indicates the total number of fields contained in the index. Therefore, the total number of bytes included in the index element field is nk×(8+np×9). If the number of fields occupied by each index is added, it is equal to the first total number of bytes.
[0161] D3, determining the first target field of the index field based on the first total number of bytes and the sixth field, and extracting the index number of ninth storage values from the first target field.
[0162] The to-be-inspected information includes the ninth storage value.
[0163] Here, the electronic device determines the first target field of the index field by skipping the first total number of bytes from the start position of the sixth field, and then extracts the index number nk of the ninth storage values from the first target field.
[0164] D4, based on the index number of the ninth storage values, inspecting the primary key to query the primary key in the data table.
[0165] The ninth storage value is used to indicate whether the data table has a primary key; and the table structure information includes the primary key in the data table.
[0166] In an implementable application scenario, first, the electronic device determines that the number of bytes of the header field of the file is 64 bytes, and determines the index field of the file after skipping 64 bytes from the start position of the file. The index number nk is read from the first transition field adjacent to the start position in the index field, i.e., the first byte. The first total number of bytes nkp is read from the sixth field adjacent to the first transition field of the index field, i.e., the second byte, which is the total number of fields contained in the index. The ninth storage value is extracted from the first target field adjacent to the sixth field of the index field, wherein the length of the first target field is the first total number of bytes nkp. Here, the ninth storage value includes multiple characters. Before parsing the index name, the electronic device reads in one character, decodes it as a char type to obtain the separator t between each index name. Then, the characters are read in byte by byte in turn and decoded as a char type. If the decoded character is not the separator t, the character belongs to the index name. If the decoded character is t, it means that the current index name has been read, and the next character belongs to the next index name. When nk separators t are read, it means that all the index names have been read. It is checked whether the primary key identifier such as the PRIMARY field exists in the read index name. If it exists, it means that the table has a primary key, otherwise it means that it does not. In this way, the primary key of the data table is inspected through the file, the inspection time is reduced, and the inspection efficiency is improved. At the same time, it does not need to rely on the running database instance, and does not occupy database connections or buffer pools and other resources. The primary key of the table type data table is inspected, which makes the inspection task completely not affect the normal service of the database instance, improves the robustness of the method, and completely does not consume additional storage space, reduces resource occupation.
[0167] In other embodiments of the present application, if the first to-be-inspected object is a column name, the electronic device can implement it in the following way,
[0168] E1, extracting a third storage value from the third field in the header field, extracting a fourth storage value from the fourth field in the header field, and extracting a tenth storage value from the seventh field in the header field.
[0169] The third storage value is used to indicate the storage of the index record, the fourth storage value is used to indicate the storage of the default value, and the tenth storage value is used to indicate the primary key information value.
[0170] E2, determining the column meta field of the file based on the third storage value, the fourth storage value, and the tenth storage value.
[0171] In an implementation scenario, the third field can be the 15th-16th byte in the header field, the fourth field can be the 17th-18th byte in the header field, and the seventh field can be the 29th-30th byte in the header field, when the header field contains 64 bytes. The electronic device decodes the data stored in the third field, the fourth field, and the seventh field using a target data type corresponding to the data type of the data stored in the third field, the fourth field, and the seventh field, such as unsigned short, to obtain a third stored value, a fourth stored value, and a tenth stored value. Further, the electronic device determines a third byte offset based on the third stored value, the fourth stored value, and the tenth stored value, and then skips, by the electronic device, a number of bytes equal to the third byte offset from the start of the header field of the file to determine a column metadata field of the file. Here, the electronic device can determine the third byte offset by the following formula:
[0172] third byte offset = (((64 + third stored value + fourth stored value + twelfth stored value) / 64) + 1) * 64 + 258.
[0173] E3. Extracting a column number from a transition field adjacent to the start of the column metadata field.
[0174] The column number is used to record the number of columns in the data table.
[0175] E4. Extracting a second total number of bytes occupied by each column name from an eighth field adjacent to the transition field of the column metadata field.
[0176] E5. Extracting a column number of eleventh stored values from a second target field adjacent to the eighth field of the column metadata field.
[0177] The length of the second target field is determined by the second total number of bytes and the column number; and the to-be-inspected information includes the column number of eleventh stored values.
[0178] It should be noted that in one case, there is no interval byte number between the adjacent two fields storing each column name, i.e., there is no white byte number, and the length of the second target field is equal to the product of the second total number of bytes and the column number. In another case, there is an interval byte number between the adjacent two fields storing each column name, i.e., there is a white byte number, and the length of the second target field can be determined by the second total number of bytes, the column number, and the interval byte number. Here, the interval byte number can be fixed or random, which is not limited in the present application.
[0179] E6. Inspecting the column names based on the column number of eleventh stored values to query the column names in the data table.
[0180] The table structure information includes the column names in the data table.
[0181] In an implementable application scenario, the electronic device extracts a third storage value from a third field in the header field, extracts a fourth storage value from a fourth field in the header field, and extracts a tenth storage value from a seventh field in the header field; based on the third storage value, the fourth storage value, and the tenth storage value, after determining the column field of the file, first, the electronic device extracts the column number nc from the transition field adjacent to the start position of the column field, i.e., the first two bytes; second, the electronic device extracts the total number of second bytes L occupied by each column name from the eighth field adjacent to the transition field of the column field, i.e., the third byte; third, the electronic device extracts the eleventh storage value of the column number nc from the second target field adjacent to the eighth field of the column field; here, if there is a gap byte number between the adjacent two fields storing each column name, and the gap byte number is fixed, the length of the second target field is determined by the total number of second bytes, the column number, and the gap byte number, i.e., the length of the second target field = column number nc x (1+total number of second bytes L+gap byte number). Further, the electronic device converts each eleventh storage value into a third character, and groups the column number nc third characters into a third string to obtain the column name of the data table, thereby implementing the inspection of the column name. It should be noted that if it is detected whether the column name in the table contains a capital letter, the obtained column name, i.e., the third string, is detected character by character. In this way, the electronic device inspects the column name corresponding to the data table through the file, reduces the inspection time, and improves the inspection efficiency; at the same time, the inspection of the column name of the table type data table does not depend on the running database instance, and does not occupy database connections or buffer pools and other resources, which makes the inspection task completely not affect the normal service of the database instance, improves the robustness of the method, and completely does not consume additional storage space, reduces resource occupation.
[0182] In other embodiments of the present application, if the first to-be-inspected object is a column character set, after the electronic device performs E6 to inspect the column name based on the column number of eleventh storage values to query the column name in the data table, the following processes need to be performed:
[0183] E7, determining the column field separated by the second target field of the column field and the character set, and extracting a twelfth storage value from a third target field of the column field.
[0184] The twelfth storage value is used to indicate the character set used by the column; the to-be-inspected information includes the twelfth storage value.
[0185] E8, based on the twelfth storage value, the column character set is inspected to query the character set used by the column in the data table.
[0186] The table structure information includes the character set used by the column in the data table.
[0187] In an implementable scenario, after the electronic device queries the column names in the data table based on the column number of the eleventh storage value, the electronic device determines the column metadata field separated by the second target field interval character of the column metadata field, that is, the electronic device determines the column metadata field after determining the second target field, and then skips one interval character. It should be noted that the storage order of the metadata field of each column is consistent with the storage order of the column name. Here, the metadata field of each column occupies 17 bytes, and the number of bytes occupied by the metadata fields of all columns is 17 x nc. Further, according to the storage order of the column name, the electronic device extracts the twelfth storage value used to indicate the character set used by the column from the third target field of the metadata field of each column, that is, the 15th byte. Finally, the electronic device inspects the column character set based on the twelfth storage value of each column, and compares the obtained character set dictionary to query the character set used by each column in the data table. In this way, the electronic device inspects the character set used by the column corresponding to the data table through the file, reduces the inspection time, and improves the inspection efficiency. At the same time, the inspection of the character set used by the column of the table type data table does not depend on the running database instance, and does not occupy database connections or buffer pools and other resources, which makes the inspection task completely not affect the normal service of the database instance, improves the robustness of the method, and completely does not consume additional storage space, reduces resource occupation.
[0188] In other embodiments of the present application, if the first to-be-inspected object is a column annotation, the electronic device performs E6 based on the column number of the eleventh storage value to inspect the column name to query the column name in the data table, and further performs the following process:
[0189] E9, determining the metadata field of the column separated by the second target field interval character of the column metadata field, and extracting the third total number of bytes of the column annotation from the ninth field of the metadata field.
[0190] E10, extracting the column number of the thirteenth storage value from the column annotation field adjacent to the metadata field of the column metadata field.
[0191] The length of the column annotation field is determined by the third total number of bytes and the column number; the to-be-inspected information includes the column number of the thirteenth storage value.
[0192] It should be noted that in one case, there is no interval byte number between the adjacent two fields of the column annotation of each column, that is, there is no white byte number, and the length of the column annotation field is equal to the product of the third total number of bytes and the column number. In another case, there is an interval byte number between the adjacent two fields of the column annotation of each column, that is, there is a white byte number, and the length of the column annotation field can be determined by the third total number of bytes, the column number and the interval byte number. Here, the interval byte number can be fixed or random, which is not limited in the present application.
[0193] E11, based on the column number of the thirteenth storage value, the column annotation is inspected to query the annotation of the column in the data table.
[0194] The table structure information includes the annotation of the column in the data table.
[0195] In a realizable scenario, after the electronic device inspects the column name based on the column number of the eleventh storage value to query the column name in the data table, the electronic device inspects the column name based on the column number of the eleventh storage value to query the column name in the data table, and determines the meta field of the column separated by the second target field interval character of the column meta field, that is, the electronic device determines the second target field, and then skips one interval character to determine the meta field of the column. It should be noted that the storage order of the meta field of each column is consistent with the storage order of the column name. Here, the meta field of each column occupies 17 bytes, and the number of bytes occupied by the meta field of all columns is 17 x nc. Further, according to the storage order of the column name, the electronic device extracts the third total number of bytes cl used to indicate the annotation of the column from the ninth field of the meta field of each column, i.e. the 16-17th byte. Then, the electronic device extracts the column number of the thirteenth storage value from the column annotation field adjacent to the meta field of the column meta field. It should be noted that the storage order of the column annotation of each column is consistent with the storage order of the column name. Here, if there is no interval byte number between the adjacent two fields of each column, the length of the column annotation field is the product of the third total number of bytes and the column number, i.e. the length of the column annotation field = column number nc x third total number of bytes. In this way, based on the third total number of bytes, the division position between the annotations of the adjacent two columns can be known. For example, if the third total number of bytes is 10, the first column annotation starts from the beginning of the column annotation field and reads ten bytes, and the second column annotation starts from the eleventh byte.
[0196] Finally, the electronic device converts each thirteenth storage value into a fourth character, and here the electronic device needs to concatenate all the characters represented by the bytes of each column annotation to obtain the complete annotation of each column, i.e. the fourth string, and obtains nc fourth strings to obtain the column annotation of each column of the data table, thereby realizing the inspection of the column annotation. It should be noted that if it is required to inspect whether the annotation contains a high-risk character, it can be checked whether each column annotation contains the character.
[0197] As can be known from the above, in the embodiment of the application, the electronic device inspects the annotations of the columns corresponding to the data table through the file, reduces the inspection time length, and improves the inspection efficiency; meanwhile, the annotations of the columns of the data table of the table type are inspected without relying on the running database instance and without occupying database connections or buffer pools and other resources, which makes the inspection task completely not affect the normal service of the database instance, improves the robustness of the method, and completely does not consume additional storage space, and reduces the resource occupation.
[0198] It should be noted that the descriptions of the same steps and the same contents in the embodiment and other embodiments can refer to the descriptions in other embodiments, and will not be described here.
[0199] Referring to Figure 7 , Figure 7 is an optional flowchart of the table structure inspection method provided by the embodiment of the application, which will be described in combination with the steps shown in Figure 7
[0200] Step 501: Obtain a file storing a table structure of a data table.
[0201] Step 502: Obtain a file type from a header field of the file.
[0202] Step 503: If the file type is a view type, determine that a second to-be-inspected object corresponding to the view type is a table creation statement.
[0203] Step 504: Extract a plurality of sixth storage values from the remaining fields of the file.
[0204] The to-be-inspected information includes the sixth storage value.
[0205] In the embodiment of the application, the file includes the header field and the remaining field.
[0206] Step 505: Convert each sixth storage value into a second character, and compose a plurality of second characters into a second string.
[0207] In the example of the application, the electronic device can convert each sixth storage value into a corresponding second character by referring to an ASCII code table; the electronic device can also convert each sixth storage value into a corresponding second character by referring to a set relationship table. In this regard, the application does not make specific limitations. It should be noted that if the ASCII code table is referred to, the electronic device needs to first convert each sixth storage value into hexadecimal, and then convert each sixth storage value into a second character through the ASCII code table.
[0208] Step 506: Match the second string and the table creation identifier through a regular expression to obtain a table creation statement used for creating a data table.
[0209] The table structure information includes a table creation statement used for creating the data table.
[0210] In the embodiment, the table creation identifier is used to identify the table creation statement used for creating the data table. For example, the table creation identifier can be a keyword, such as create.
[0211] In the embodiment, the regular expression is a string matching method in software development, which matches a certain string with a fixed string pattern. For example, if the regular expression is ^create, it means matching all strings starting with create.
[0212] In the embodiment, when the electronic device obtains a plurality of sixth storage values, the electronic device first converts each sixth storage value into a second character and groups a plurality of second characters into a second string; secondly, the electronic device matches the second string and the table creation identifier by using the regular expression to obtain the table creation statement used for creating the data table.
[0213] In an implementable application scenario, after the electronic device extracts a plurality of sixth storage values, the electronic device parses the plurality of sixth storage values into a second string ps by referring to the ASCII code table, and matches the second string ps and the table creation identifier such as the create field by using the regular expression to obtain the table creation statement used for creating the data table.
[0214] As described above, the electronic device obtains a file storing a table structure of a data table, determines that the file type is a view type from a header field of the file, then extracts a sixth storage value as the to-be-inspected information from a remaining field corresponding to the view type in the file, further converts each sixth storage value into a character to form a second string, and finally matches the second string and the table creation identifier by using the regular expression to obtain the table creation statement used for creating the data table. In this way, the electronic device can inspect the data table of the view type without relying on a running database instance, and thus does not occupy resources such as database connections or buffer pools, thereby reducing resource occupation.
[0215] The following continues to describe an exemplary structure of the table structure inspection apparatus 154 implemented as a software module provided in the embodiment, which, in some embodiments, can be a table structure inspection apparatus in the electronic device 100, and includes: Figure 1 As shown in FIG. 1, the software module stored in the table structure inspection apparatus 154 in the memory 150 can be a table structure inspection apparatus in the electronic device 100, and includes:
[0216] The obtaining module 1541 is configured to obtain a file storing a table structure of a data table. The matching module 1542 is configured to match the second string and the table creation identifier by using the regular expression to obtain the table creation statement used for creating the data table.
[0217] The obtaining module 1541 is further configured to obtain the file type from a header field of the file.
[0218] The obtaining module 1541 is further configured to, for the to-be-inspected object corresponding to the file type, obtain the to-be-inspected information based on a field corresponding to the file type in the file.
[0219] The processing module 1542 is configured to perform inspection on the to-be-inspected object based on the to-be-inspected information, to query the table structure information of the data table.
[0220] In some embodiments, the determining module 1543 is configured to, if the file type is a table type, determine a first to-be-inspected object corresponding to the table type; and the obtaining module 1541 is further configured to, if the first to-be-inspected object is a storage engine, extract a first storage value from a first field in the header field, where the to-be-inspected information includes the first storage value.
[0221] In some embodiments, the processing module 1542 is further configured to, if the first storage value indicates a storage engine used by a storage data table, perform inspection on the storage engine, to query the storage engine used by the storage data table, where the table structure information includes the storage engine used by the storage data table.
[0222] In some embodiments, the obtaining module 1541 is further configured to, if the first storage value indicates that the data table is a partition table, extract a second storage value from a second field in the header field, extract a third storage value from a third field in the header field, and extract a fourth storage value from a fourth field in the header field, where the second storage value is used to indicate a file write-once byte size, the third storage value is used to indicate storage index records, and the fourth storage value is used to indicate storage of default values; the determining module 1543 is further configured to determine a partition field of the file based on the second storage value, the third storage value, and the fourth storage value; and the obtaining module 1541 is further configured to obtain a plurality of fifth storage values from the partition field, where the to-be-inspected information further includes the second storage value, the third storage value, the fourth storage value, and the plurality of fifth storage values, and the fifth storage value is used to indicate a storage engine used by a storage partition table; and the processing module 1542 is further configured to perform inspection on the storage engine based on the plurality of fifth storage values, to query the storage engine used by the storage partition table, where the table structure information includes the storage engine used by the storage partition table.
[0223] In some embodiments, the processing module 1542 is further configured to convert each fifth storage value into a first character, and group a plurality of first characters into a first string; and perform matching between the first string and an engine identifier through a regular expression, to obtain the storage engine used by the storage partition table.
[0224] In some embodiments, the determining module 1543 is further configured to determine that the sum of the second storage value, the third storage value and the fourth storage value is the first byte offset; the obtaining module 1541 is further configured to obtain a set second byte offset, where the second byte offset is used to represent a split byte; and the determining module 1543 is further configured to determine the start position of the partition field based on the obtained first byte of the file, the first byte offset and the second byte offset.
[0225] In some embodiments, the obtaining module 1541 is further configured to extract a total byte number from a transition field adjacent to the start position of the partition field, where the total byte number is used to record the number of bytes occupied by a storage engine used to store the partition table; and extract a plurality of fifth storage values from a target field adjacent to the transition field of the partition field, where the length of the target field is the total byte number.
[0226] In some embodiments, the obtaining module 1541 is further configured to, if the first to-be-inspected object is a character set, obtain, from the header field, version information of a database used to run the data table and a character sequence number of the data table, where the inspection information includes the version information of the database and the character sequence number of the data table; obtain a character dictionary corresponding to the version information; and the processing module 1542 is further configured to inspect, in the character dictionary, according to the character sequence number, to query the character set and the character sequence in the data table, where the table structure information includes the character set and the character sequence in the data table.
[0227] In some embodiments, the determining module 1543 is further configured to, if the file type is a view type, determine that a second to-be-inspected object corresponding to the view type is a table creation statement; the obtaining module 1541 is further configured to extract a plurality of sixth storage values from the remaining fields of the file, where the to-be-inspected information includes the sixth storage values; and the processing module 1542 is further configured to convert each sixth storage value into a second character, and group a plurality of second characters into a second string; and match the second string with a table creation identifier through a regular expression to obtain a table creation statement used to create the data table, where the table structure information includes the table creation statement used to create the data table.
[0228] The embodiments of the present application provide a storage medium storing executable instructions, where the executable instructions are stored, and when the executable instructions are executed by a processor, the processor will execute the method provided by the embodiments of the present application, for example, the method shown in Figures 2-8 .
[0229] The application provides a storage medium. A file storing a table structure of a data table is acquired, a file type is acquired from a header field of the file, a field corresponding to the file type in the file is determined to obtain to-be-inspected information for a to-be-inspected object corresponding to the file type, and finally, the to-be-inspected object is inspected based on the to-be-inspected information, so that table structure information of the data table is queried. In this way, the application solves the problem that related technologies must depend on a database instance in online operation, at least a strong dependency problem exists; a database instance in operation is not required, so that database connections or buffer pools and other resources are not occupied; in this way, while processing an inspection task, no additional storage space is consumed, and resource occupation is reduced.
[0230] In some embodiments, the storage medium can be a computer-readable storage medium, such as a ferroelectric memory (FRAM), a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a flash memory, a magnetic surface memory, an optical disc, a compact disc read-only memory (CD-ROM), or the like. The storage medium can also be various devices including one or any combination of the above storage mediums.
[0231] In some embodiments, the executable instructions can be in the form of programs, software, software modules, scripts or codes, written in any form of programming language, including a compiled or interpreted language, or a declarative or procedural language, and can be deployed in any form, including being deployed as a standalone program or as a module, component, subroutine or other unit suitable for use in a computing environment.
[0232] By way of example, an executable instruction can be, but is not limited to, a file, a part of a file, executing on a storage, a library, a service, a procedure, etc. Whether such an instruction is stored in an object, a library, a procedure, or a file (e.g., in a file that stores other programs or data), the instruction need not be stored in its own file, or in a file dedicated to such an instruction. By way of example, the executable files can be, but need not be, stored on memory devices, such as single or multiple USBs and / or hard drives, or in files, such as in those installed on a system when an application or program associated with such file is installed. An executable file can be, for example, but need not be, stored on memory devices, such as single or multiple USBs and / or hard drives, or in files, such as in those installed on a system when an application or program associated with such file is installed. Further, those skilled in the relevant art will also recognize how to implement the application using other technologies now known or later developed, and it will be recognized how to implement those aspects at a higher level while providing for all the functionality, etc.
[0233] The above merely provides an example of the embodiments of the present application, but is not intended to limit the protection scope of the present application. Any modification, equivalent replacement and improvement within the spirit and scope of the present application shall be included in the protection scope of the present application.
Claims
1. A method for inspecting a table structure, characterized by, The method comprises: obtaining a file storing a table structure of a data table; the file is generated when a database creates the data table, and the file name is the same as the data table name; obtaining a file type from a header field of the file; the file type is used to locate a field in which information to be inspected in the file is located; for an object to be inspected corresponding to the file type, obtaining the information to be inspected based on the field corresponding to the file type in the file; if the file type is a table type, the field in which the information to be inspected is located comprises a header field; if the file type is a view type, the field in which the information to be inspected is located is a remaining field in the file except the header field; based on the information to be inspected, inspecting the object to be inspected to query table structure information of the data table; the table structure information comprises one or more of the following: a storage engine used to store the data table, a character set in the data table, column names, column character sets and column annotations in the data table, whether the data table contains a primary key, whether a row format type of the data table comprises a compressed mode, and a table creation statement used to create the data table; wherein, for the object to be inspected corresponding to the file type, the information to be inspected is obtained based on the field corresponding to the file type in the file, comprising: if the file type is a table type, determining a first object to be inspected corresponding to the table type; if the first object to be inspected is a storage engine, extracting a first storage value from a first field in the header field, wherein the information to be inspected comprises the first storage value; if the first storage value indicates that the data table is a partition table, extracting a second storage value from a second field in the header field, a third storage value from a third field in the header field, and a fourth storage value from a fourth field in the header field, wherein the second storage value is used to indicate a byte size of one-time writing of the file, the third storage value is used to indicate storage of index records, and the fourth storage value is used to indicate storage of default values; based on the second storage value, the third storage value and the fourth storage value, determining a partition field of the file; obtaining a plurality of fifth storage values from the partition field, wherein the information to be inspected further comprises the second storage value, the third storage value, the fourth storage value and the plurality of fifth storage values, and the fifth storage value is used to indicate a storage engine used to store the partition table; correspondingly, based on the plurality of fifth storage values, the storage engine is inspected to query the storage engine used to store the partition table, wherein the table structure information comprises the storage engine used to store the partition table. If the first to-be-inspected object is a character set, version information of a database running the data table and a character sequence number of the data table are obtained from the header field, and the inspection information includes the version information of the database and the character sequence number of the data table; Correspondingly, the inspection of the to-be-inspected object based on the to-be-inspected information includes: obtaining a character dictionary corresponding to the version information; inspecting the character dictionary according to the character sequence number to obtain a character set and a character sequence in the data table, wherein the table structure information includes the character set and the character sequence in the data table.
2. The method of claim 1, wherein, The inspection of the to-be-inspected object based on the to-be-inspected information to query the table structure information of the data table includes: If the first storage value indicates a storage engine used by the data table, the storage engine is inspected to query the storage engine used by the data table, wherein the table structure information includes the storage engine used by the data table.
3. The method of claim 1, wherein, The inspection of the storage engine based on the plurality of fifth storage values to query the storage engine used by the partition table includes: convert each fifth storage value into a first character, and group a plurality of first characters into a first string; matching the first string with an engine identifier through a regular expression to obtain the storage engine used by the partition table.
4. The method of claim 1, wherein, The determination of the partition field of the file based on the second storage value, the third storage value and the fourth storage value includes: determining that the sum of the second storage value, the third storage value and the fourth storage value is a first byte offset; obtaining a set second byte offset, wherein the second byte offset represents a split byte; determining a starting position of the partition field based on the first byte of the file, the first byte offset and the second byte offset.
5. The method of claim 4, wherein, The obtaining of a plurality of fifth storage values from the partition field includes: extracting a total byte number from a transition field adjacent to the starting position of the partition field, wherein the total byte number is used to record the number of bytes occupied by the storage engine used by the partition table; extracting the plurality of fifth storage values from a target field adjacent to the transition field of the partition field, wherein the length of the target field is the total byte number.
6. The method according to any one of claims 1 to 5, characterized in that, The obtaining of to-be-inspected information based on the field corresponding to the file type in the file for the to-be-inspected object corresponding to the file type includes: if the file type is a view type, determining a second to-be-inspected object corresponding to the view type as a table creation statement; extracting a plurality of sixth storage values from the remaining fields of the file, wherein the to-be-inspected information includes the sixth storage values; Correspondingly, the inspection of the to-be-inspected object based on the to-be-inspected information to query the table structure information of the data table includes: convert each sixth storage value into a second character, and group a plurality of second characters into a second string; The second string is matched with a table creation identifier through a regular expression to obtain a table creation statement used for creating the data table, wherein the table structure information comprises the table creation statement used for creating the data table.
7. A table structure inspection device characterized by comprising: The apparatus comprises: An obtaining module is configured to obtain a file in which table structure of a data table is stored; the file is generated when the database creates the data table, and the file name is the same as the data table name; The obtaining module is further configured to obtain a file type from a header field of the file; the file type is used to locate a field in which to-be-inspected information is located in the file; the obtaining module is further configured to obtain the to-be-inspected information based on a field corresponding to the file type in the file for a to-be-inspected object corresponding to the file type; if the file type is a table type, the field in which the to-be-inspected information is located comprises a header field; if the file type is a view type, the field in which the to-be-inspected information is located is a remaining field in the file except the header field; A processing module is configured to inspect the to-be-inspected object based on the to-be-inspected information to query table structure information of the data table; the table structure information comprises one or more of a storage engine used for storing the data table, a character set in the data table, column names, column character sets and column annotations in the data table, whether the data table contains a primary key, whether a row format type of the data table comprises a compressed mode, and a table creation statement used for creating the data table; The obtaining module is specifically configured to determine a first to-be-inspected object corresponding to the table type if the file type is the table type; extract a first storage value from a first field in the header field if the first to-be-inspected object is the storage engine, wherein the to-be-inspected information comprises the first storage value; extract a second storage value from a second field in the header field, extract a third storage value from a third field in the header field, and extract a fourth storage value from a fourth field in the header field if the first storage value indicates that the data table is a partition table, wherein the second storage value is used to indicate a byte size of one-time writing of the file, the third storage value is used to indicate storage of an index record, and the fourth storage value is used to indicate storage of a default value; determine a partition field of the file based on the second storage value, the third storage value and the fourth storage value; obtain a plurality of fifth storage values from the partition field, wherein the to-be-inspected information further comprises the second storage value, the third storage value, the fourth storage value and the plurality of fifth storage values, and the fifth storage value is used to indicate a storage engine used for storing the partition table; obtain version information of a database used for running the data table and a character sequence number of the data table from the header field if the first to-be-inspected object is a character set, wherein the to-be-inspected information comprises the version information of the database and the character sequence number of the data table; obtain a character dictionary corresponding to the version information; The processing module is specifically configured to: based on the plurality of fifth storage values, perform a patrol on the storage engine to query a storage engine used to store the partition table, wherein the table structure information comprises the storage engine used to store the partition table; and perform a patrol on the character dictionary according to the character sequence number to query a character set and a character sequence in the data table, wherein the table structure information comprises the character set and the character sequence in the data table.
8. An electronic device, comprising: The method comprises: a memory configured to store executable instructions; a processor configured to execute the executable instructions stored in the memory to implement the method in any one of claims 1 to 6.
Citation Information
Patent Citations
Method and system for checking script
CN104778412A