Database implementation method, device and equipment
Technical Field
The present application relates to the field of database technologies, and in particular, to a method, an apparatus, and a device for implementing a database.
Background
A database is a repository that organizes, stores, and manages data according to a data structure. When a database is accessed for the first time, some key information of the database is usually read into a memory, and a series of initialization operations are performed to realize subsequent normal access. How to increase the first access rate of the database and reduce the memory occupation is a problem to be solved urgently.
Disclosure of Invention
In view of this, the present application provides a database implementation method, apparatus and device.
Specifically, the method is realized through the following technical scheme:
a database implementation method, comprising:
determining original columns to be combined;
for each record of the data table, merging the column values of the original columns to be merged according to a merging rule to obtain a merged column value;
and correspondingly inserting a merged column value into the merged column of the data table.
A database implementation method, comprising:
reading column values from a data table of a database;
judging whether the read column value is a combined column value obtained by combining a plurality of original column values;
and if the read column value is the merged column value, reversely analyzing according to the merging rule to obtain the target column value.
A database-implemented apparatus, comprising:
a column determination unit that determines an original column to be merged;
a column value merging unit, configured to merge, according to a merge rule, column values of the original columns to be merged for each record of the data table, to obtain a merged column value;
and a column value insertion unit for correspondingly inserting the merged column value into the merged column of the data table.
A database-implemented apparatus, comprising:
a column value reading unit which reads column values from a data table of the database;
a merging judgment unit which judges whether the read column value is a merged column value obtained by merging a plurality of original column values;
and the column value analysis unit is used for reversely analyzing the read column value to obtain a target column value according to a merging rule if the read column value is a merged column value.
A database-implemented device, comprising:
a processor;
a memory for storing machine executable instructions;
wherein, by reading and executing machine-executable instructions stored by the memory corresponding to database-implemented control logic, the processor is caused to:
determining original columns to be combined;
for each record of the data table, merging the column values of the original columns to be merged according to a merging rule to obtain a merged column value;
and correspondingly inserting a merged column value into the merged column of the data table.
A database-implemented device, comprising:
a processor;
a memory for storing machine executable instructions;
wherein, by reading and executing machine-executable instructions stored by the memory corresponding to database-implemented control logic, the processor is caused to:
reading column values from a data table of a database;
judging whether the read column value is a combined column value obtained by combining a plurality of original column values;
and if the read column value is the merged column value, reversely analyzing according to the merging rule to obtain the target column value.
As can be seen from the above description, when the database is deployed, according to each record of the data table, the column values of the original columns to be merged may be merged according to the merging rule to obtain merged column values, and the merged column values are correspondingly inserted into the merged columns of the data table, so that the number of columns of the data table is reduced, the number of columns of the system main table is further reduced, time consumed for reading and writing the key information when the database is accessed for the first time is reduced, the rate of the first access is improved, and meanwhile, the occupation of the memory is reduced.
Drawings
Fig. 1 is a flowchart illustrating a database implementation method according to an exemplary embodiment of the present application.
Fig. 2 is a flow chart diagram illustrating another database implementation method according to an exemplary embodiment of the present application.
Fig. 3 is a schematic structural diagram of a database implementation apparatus according to an exemplary embodiment of the present application.
Fig. 4 is a block diagram illustrating a database implementation apparatus according to an exemplary embodiment of the present application.
Fig. 5 is a schematic structural diagram of another apparatus for implementing a database according to an exemplary embodiment of the present application.
Fig. 6 is a block diagram of another database implementation apparatus according to an exemplary embodiment of the present application.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. As used in this application and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used herein refers to and encompasses any and all possible combinations of one or more of the associated listed items.
It is to be understood that although the terms first, second, third, etc. may be used herein to describe various information, such information should not be limited to these terms. These terms are only used to distinguish one type of information from another. For example, first information may also be referred to as second information, and similarly, second information may also be referred to as first information, without departing from the scope of the present application. The word "if" as used herein may be interpreted as "at … …" or "when … …" or "in response to a determination", depending on the context.
In the related art, taking the SQLite database as an example, when the SQLite database is accessed for the first time, the create statement stored in the system master table SQLite _ master is subjected to word segmentation, analysis and other operations, so as to generate a resident memory structure. The memory structure is used for storing some summary information of the SQLite database, such as: a manifest, an index name, a trigger name, etc. The more the number of columns of the data table in the SQLite database is, the more the columns of the SQLite _ master are, the more the read-write operation for accessing the SQLite database for the first time is, so that the low rate of the access for the first time is caused, and a large amount of memory is occupied.
In order to solve the above problems, the present application provides a database implementation scheme, which reduces the number of columns in the main table of the system by merging columns in the database data table, thereby improving the first access rate of the database and saving the memory space.
Fig. 1 is a flowchart illustrating a database implementation method according to an exemplary embodiment of the present application.
Referring to fig. 1, the database implementation method may be applied to an electronic device for organizing a database, which is deployed by an organizer of the database, and includes the following steps:
step 101, determining an original column to be merged.
In this embodiment, the original column represents a column that the database organizer plans to deploy when organizing the data table, such as: a column for storing a URL (Uniform Resource Locator), and the like.
In this embodiment, the original column with the smaller number of queries may be determined as the original column to be merged for the subsequent query operation. In an actual implementation, an original column with an access frequency less than a threshold may be determined as the original column to be merged, wherein the access frequency may be set by a developer.
For example, assuming that a database is used to store relevant data of an APP (Application), a data table of the database has an original column for storing a URL of a frequently-used button icon in the APP user interface, and the original column is usually only queried when a user starts up for the first time after downloading the APP, the original column may be determined as the original column to be merged.
Of course, those skilled in the art can also determine the original columns to be merged in other ways, such as: the original columns to be merged and the like are empirically specified, and this application does not specifically limit this.
And 102, merging the column values of the original columns to be merged according to a merging rule aiming at each record of the data table to obtain a merged column value.
In this embodiment, the merge rule may be set by a developer according to a specific type of a column value (the column value represents a value of a certain column in the record). In one example, if the column values of the original columns to be merged are all character strings, the original column values may be directly merged.
Recording
|
Original column 1 to be merged
|
Original column 2 to be merged
|
Original column to be merged 3
|
25
|
Hdfh
|
46
|
Dfh98 |
TABLE 1
For example, assuming that a data table is determined to have 3 original columns to be merged, the column values of the 3 original columns to be merged of the 25 th record of the data table are shown in table 1, and after merging the 3 original column values, the merged column value "Hdfh, 46, Dfh 98" can be obtained.
In another example, if the column values of the original columns to be merged are not all character strings, the original column values to be merged may be first spliced together, and then the splicing result is serialized to convert the splicing result into a binary value, where the binary data is the merged column value obtained after the merging process. The serialization process can be freely implemented, and the application is not particularly limited to this.
In this embodiment, to facilitate the access device to identify the merged column value, a merged flag bit may be added to the merged column value, for example: this may be accomplished by adding a special character before or after the merged column value, etc.
And 103, correspondingly inserting a merged column value into the merged column of the data table.
Based on the foregoing step 102, after merging the column values of the original columns, merged column value correspondences may be inserted into the merged columns. The merged columns are independent of the columns in the data table that the database organizer plans to deploy when organizing the data table.
With reference to the embodiment shown in fig. 1, taking the SQLite database as an example, when a database organizer deploys the database, for each record of the data table, original column values that are not accessed or accessed less frequently, such as URLs and picture information, may be merged, and the merged column values obtained after merging are stored in a pre-specified merged column, so that the number of columns of the data table is reduced, and further the number of columns of the SQLite _ master is reduced. When the SQLite database is accessed for the first time, compared with the SQLite database before combination, the read-write operation is reduced, the access rate is improved, and meanwhile, the occupation of a memory can be reduced.
As can be seen from the above description, when the database is deployed, according to each record of the data table, the column values of the original columns to be merged may be merged according to the merging rule to obtain merged column values, and the merged column values are correspondingly inserted into the merged columns of the data table, so that the number of columns of the data table is reduced, the number of columns of the system main table is further reduced, time consumed for reading and writing the key information when the database is accessed for the first time is reduced, the rate of the first access is improved, and meanwhile, the occupation of the memory is reduced.
Based on the merging scheme shown in fig. 1, the present application further provides a database implementation method for database query. The database implementation method can be applied to access equipment, and the access equipment can be an intelligent terminal, a tablet computer, a PC (personal computer) and the like. Referring to fig. 2, the database implementation method includes the following steps:
at step 201, a column value is read from a data table of a database.
In this embodiment, the accessing of the database by the access device may include: read access and write access, wherein the write access may include: insert, modify, etc. For convenience of description, the read data may be referred to as column values (a column value indicates a value of a certain record in a certain column).
Step 202, determining whether the read column value is a merged column value obtained by merging a plurality of original column values.
Based on the foregoing step 201, after the column value is read, it may be determined whether the column value carries a merge flag bit, and if not, it may be determined that the read column value is not a merge column value, and the processing may be performed according to an implementation manner in the related art. If the read column value carries the merge flag, it can be said that the column value is a merged column value, and step 203 is executed.
In step 203, if the read column value is a merged column value, a target column value is obtained by reverse analysis according to a merging rule.
Based on the determination result in the foregoing step 202, after it is determined that the read column value is the merged column value, the merged column value may be analyzed to obtain the original column value before merging, and then the target column value accessed this time is found in the original column value.
Taking the merging rule as an example of serialization processing, in this step, for a merged column value, deserialization processing may be performed first to restore the serialized merged column value into a plurality of original column values, and then a target column value accessed this time is found in the plurality of original column values.
After the target column value is found, if the target column value is read access, the target column value can be filled into a field corresponding to the Object; and if the write access is performed, performing write operation on the target column value according to the write access, after the write operation is performed, merging a new target column value and a non-target column value in the merged column value according to a merging rule to obtain a new merged column value, and replacing the merged column value stored in the data table with the new merged column value.
For example, still taking the original column values shown in table 1 as an example, for the record, when the database organizing party organizes the database, the original column values of the original columns 1, 2, and 3 to be merged are serialized to obtain a merged column value 1. In this embodiment, the access device reads the merged column value 1 based on the write access, and then performs deserialization on the merged column value, and may restore the merged column value 1 to the original column value shown in table 1. Assuming that the write access needs to modify the original column value 2 to "48", the access device may modify the original column value 2 from "46" to "48", and then the access device may continue to concatenate the column value "Hdfh" of the original column 1, the new column value "48" of the original column 2, and the column value "Dfh 98" of the original column 3, and then perform serialization processing, and assuming that the merged column value 2 is obtained after the serialization processing, the access device updates the merged column value 1 in the data table with the merged column value 2, thereby implementing the write access to the merged column value.
In this embodiment, based on the database after the column value combination, the access device of the present application may still perform read access and write access.
Corresponding to the foregoing embodiment of the database implementation method shown in fig. 1, the present application also provides an embodiment of a database implementation apparatus.
The embodiment of the database implementation device can be applied to electronic equipment. The device embodiments may be implemented by software, or by hardware, or by a combination of hardware and software. Taking a software implementation as an example, as a logical device, the device is formed by reading, by a processor of the electronic device where the device is located, a corresponding computer program instruction in the nonvolatile memory into the memory for operation. From a hardware aspect, as shown in fig. 3, a hardware structure diagram of an electronic device in which the database implementation apparatus of the present application is located is shown, except for the processor, the memory, the network interface, and the nonvolatile memory shown in fig. 3, the electronic device in which the apparatus is located in the embodiment may also include other hardware according to an actual function of the electronic device, which is not described again.
Fig. 4 is a block diagram illustrating a database implementation apparatus according to an exemplary embodiment of the present application.
Referring to fig. 4, the database implementation apparatus 300 can be applied to the electronic device shown in fig. 3, and includes: a column determination unit 301, a column value combining unit 302, and a column value inserting unit 303.
Wherein, the column determining unit 301 determines an original column to be merged;
a column value merging unit 302, configured to merge, according to a merge rule, column values of the original columns to be merged for each record of the data table, to obtain a merged column value;
column value inserting section 303 inserts a merged column value into the merged column of the data table.
Optionally, the column determining unit 301 determines an original column with an access frequency smaller than a threshold as an original column to be merged.
Optionally, the column value merging unit 302 is configured to perform serialization processing on the column value of the original column to be merged for each record in the data table, and determine a binary value obtained after the serialization processing as the merged column value.
Optionally, the column value merging unit 302 further adds a merging flag bit to the merged column value for identification by the access device.
Corresponding to the foregoing embodiment of the database implementation method shown in fig. 2, the present application also provides an embodiment of a database implementation apparatus.
The embodiment of the database implementation device can be applied to the access equipment. The device embodiments may be implemented by software, or by hardware, or by a combination of hardware and software. The software implementation is taken as an example, and is formed by reading corresponding computer program instructions in the nonvolatile memory into the memory for operation through the processor of the access device where the software implementation is located as a logical means. From a hardware aspect, as shown in fig. 5, a hardware structure diagram of an access device where an apparatus for implementing a database is located in the present application is shown, where in addition to the processor, the memory, the network interface, and the nonvolatile memory shown in fig. 5, the access device where the apparatus is located in the embodiment may also include other hardware according to an actual function of the access device, which is not described again.
Fig. 6 is a block diagram illustrating a database implementation apparatus according to an exemplary embodiment of the present application.
Referring to fig. 6, the database implementation apparatus 500 may be applied in the access device shown in fig. 5, and includes: a column value reading unit 501, a merge determination unit 502, a column value analysis unit 503, and a column value writing unit 504.
The column value reading unit 501 reads a column value from a data table of a database;
a merge judgment unit 502 that judges whether the read column value is a merged column value in which a plurality of original column values are merged;
the column value analyzing unit 503 performs reverse analysis according to the merge rule to obtain the target column value if the read column value is the merged column value.
Optionally, the merging judgment unit 502 includes: judging whether the read column values carry merging flag bits or not; and when the read column values carry the merging flag bit, determining the read column values as the merged column values obtained by merging the plurality of original column values.
Optionally, the merge rule includes: for each record of the data table, carrying out serialization processing on column values of a plurality of original columns to be merged;
the column value analysis unit 503 performs deserialization on the parallel values to obtain target column values.
Optionally, the access frequency of the original columns to be merged is less than a threshold.
Optionally, the column value reading unit reads a column value from a data table of a database based on write access;
a column value writing unit 504 that performs a write operation on the target column value according to the write access; after the write operation is finished, combining the new target column value and the non-target column value in the combined column value according to the combination rule to obtain a new combined column value; replacing the merged column value stored by the data table with the new merged column value.
The implementation process of the functions and actions of each unit in the above device is specifically described in the implementation process of the corresponding step in the above method, and is not described herein again.
For the device embodiments, since they substantially correspond to the method embodiments, reference may be made to the partial description of the method embodiments for relevant points. The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules can be selected according to actual needs to achieve the purpose of the scheme of the application. One of ordinary skill in the art can understand and implement it without inventive effort.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. A typical implementation device is a computer, which may take the form of a personal computer, laptop computer, cellular telephone, camera phone, smart phone, personal digital assistant, media player, navigation device, email messaging device, game console, tablet computer, wearable device, or a combination of any of these devices.
Corresponding to the foregoing embodiment of the database implementation method shown in fig. 1, the present application further provides a database implementation device, where the database implementation device includes: a processor and a memory for storing machine executable instructions. Wherein the processor and the memory are typically interconnected by means of an internal bus. In other possible implementations, the device may also include an external interface to enable communication with other devices or components.
In this embodiment, the processor is caused to:
determining original columns to be combined;
for each record of the data table, merging the column values of the original columns to be merged according to a merging rule to obtain a merged column value;
and correspondingly inserting a merged column value into the merged column of the data table.
Optionally, in determining the original columns to be merged, the processor is caused to:
and determining the original column with the access frequency smaller than the threshold value as the original column to be merged.
Optionally, when merging, according to a merging rule, column values of the original columns to be merged for each record of the data table, the processor is caused to:
and for each record of the data table, performing serialization processing on the column value of the original column to be merged, and determining a binary value obtained after the serialization processing as the merged column value.
Optionally, the processor is further caused to:
and adding a merging flag bit in the merging column value for the identification of the access device.
Corresponding to the foregoing embodiment of the database implementation method shown in fig. 1, the present application further provides a computer-readable storage medium, on which a computer program is stored, which when executed by a processor implements the following steps:
determining original columns to be combined;
for each record of the data table, merging the column values of the original columns to be merged according to a merging rule to obtain a merged column value;
and correspondingly inserting a merged column value into the merged column of the data table.
Optionally, the determining the original columns to be merged includes:
and determining the original column with the access frequency smaller than the threshold value as the original column to be merged.
Optionally, the merging, according to a merging rule, the column value of the original column to be merged for each record of the data table includes:
and for each record of the data table, performing serialization processing on the column value of the original column to be merged, and determining a binary value obtained after the serialization processing as the merged column value.
Optionally, the method further includes:
and adding a merging flag bit in the merging column value for the identification of the access device.
Corresponding to the foregoing embodiment of the database implementation method shown in fig. 2, the present application further provides a database implementation device, where the database implementation device includes: a processor and a memory for storing machine executable instructions. Wherein the processor and the memory are typically interconnected by means of an internal bus. In other possible implementations, the device may also include an external interface to enable communication with other devices or components.
In this embodiment, the processor is caused to:
reading column values from a data table of a database;
judging whether the read column value is a combined column value obtained by combining a plurality of original column values;
and if the read column value is the merged column value, reversely analyzing according to the merging rule to obtain the target column value.
Optionally, when determining whether the read column value is a merged column value obtained by merging a plurality of original column values, the processor is caused to:
judging whether the read column values carry merging flag bits or not;
and if the read column values carry the merging flag bit, determining the read column values as the merged column values obtained by merging the plurality of original column values.
Optionally, the merge rule includes: for each record of the data table, carrying out serialization processing on column values of a plurality of original columns to be merged;
upon reverse parsing a target column value according to a merge rule, the processor is caused to:
and performing deserialization processing on the merged column values to obtain target column values.
Optionally, the access frequency of the original columns to be merged is less than a threshold.
Optionally, upon reading a column value from a data table of the database, the processor is caused to:
reading column values from a data table of the database based on the write access;
the processor is further caused to: performing write operation on the target column value according to the write access;
after the write operation is finished, combining the new target column value and the non-target column value in the combined column value according to the combination rule to obtain a new combined column value;
replacing the merged column value stored by the data table with the new merged column value.
Corresponding to the embodiment of the database implementation method shown in the foregoing 2, the present application further provides a computer-readable storage medium, on which a computer program is stored, which when executed by a processor implements the following steps:
reading column values from a data table of a database;
judging whether the read column value is a combined column value obtained by combining a plurality of original column values;
and if the read column value is the merged column value, reversely analyzing according to the merging rule to obtain the target column value.
Optionally, the determining whether the read column value is a merged column value obtained by merging a plurality of original column values includes:
judging whether the read column values carry merging flag bits or not;
and if the read column values carry the merging flag bit, determining the read column values as the merged column values obtained by merging the plurality of original column values.
Optionally, the merge rule includes: for each record of the data table, carrying out serialization processing on column values of a plurality of original columns to be merged;
the obtaining of the target column value through reverse analysis according to the merging rule comprises the following steps:
and performing deserialization processing on the merged column values to obtain target column values.
Optionally, the access frequency of the original columns to be merged is less than a threshold.
Optionally, the reading a column value from a data table of the database includes:
reading column values from a data table of the database based on the write access;
the method further comprises the following steps:
performing write operation on the target column value according to the write access;
after the write operation is finished, combining the new target column value and the non-target column value in the combined column value according to the combination rule to obtain a new combined column value;
replacing the merged column value stored by the data table with the new merged column value.
The above description is only exemplary of the present application and should not be taken as limiting the present application, as any modification, equivalent replacement, or improvement made within the spirit and principle of the present application should be included in the scope of protection of the present application.