CN111143326A - Method and device for reducing database operation, computer equipment and storage medium - Google Patents
Method and device for reducing database operation, computer equipment and storage medium Download PDFInfo
- Publication number
- CN111143326A CN111143326A CN201911365788.5A CN201911365788A CN111143326A CN 111143326 A CN111143326 A CN 111143326A CN 201911365788 A CN201911365788 A CN 201911365788A CN 111143326 A CN111143326 A CN 111143326A
- Authority
- CN
- China
- Prior art keywords
- state
- data
- cache array
- database
- change
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/21—Design, administration or maintenance of databases
- G06F16/217—Database tuning
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/24—Querying
- G06F16/245—Query processing
- G06F16/2455—Query execution
- G06F16/24552—Database cache management
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Landscapes
- Engineering & Computer Science (AREA)
- Databases & Information Systems (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computational Linguistics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The invention discloses a method, a device, computer equipment and a storage medium for reducing database operation, wherein the method comprises the following steps: dividing the state of data in a database into a plurality of normal states in advance, wherein at least one normal state comprises a plurality of specified states; creating a plurality of cache arrays in a memory, wherein each cache array corresponds to a specified state; when the state of the data changes, acquiring the states before and after the data changes, and judging whether the states before and after the data changes belong to the same normal state and whether the states before and after the data changes are in a specified state; if the data belong to the same normal state, the state of the data in the database is not updated; otherwise, updating the state of the data in the database; and if the state before the change is the designated state, deleting the ID of the data in the corresponding cache array, and if the state after the change is the designated state, inserting the ID of the data in the corresponding cache array. The method achieves the advantage of reducing database operations.
Description
Technical Field
The present invention relates to the field of databases, and in particular, to a method and an apparatus for reducing database operations using a cache array, a computer device, and a storage medium.
Background
At present, in the process of continuous development of services, the data state of a database changes constantly, so that the data state in the database needs to be updated continuously, and under the condition of high-frequency change of the state and large data volume, or during concurrent operation of multiple parties, the updating speed of the database is too slow. In order to solve the above problems, it is usually necessary to continuously expand the server to increase the speed, but the expansion of the server not only requires a great cost, but also increases the maintenance cost.
Disclosure of Invention
The invention aims to provide a method, a device, computer equipment and a storage medium for reducing database operation by using a cache array, and aims to solve the problems of high input cost and high maintenance cost for improving the speed of a database in the prior art.
In a first aspect, an embodiment of the present invention provides a method for reducing database operations by using a cache array, where the method includes:
dividing the state of data in a database into a plurality of normal states in advance, wherein at least one normal state comprises a plurality of specified states;
creating a plurality of cache arrays in a memory, wherein each cache array corresponds to a specified state;
when the state of the data changes, acquiring the state before the data changes and the state after the data changes, judging whether the state before the data changes and the state after the data changes belong to the same normal state, and judging whether the state before the data changes and the state after the data changes are in a specified state;
if the data belong to the same normal state, the state of the data in the database is not updated; deleting the ID of the data in the cache array corresponding to the state before the change, and inserting the ID of the data in the cache array corresponding to the state after the change;
if the data do not belong to the same normal state, updating the state of the data in the database; and meanwhile, if the state before the change is the designated state, deleting the ID of the data in the corresponding cache array, and if the state after the change is the designated state, inserting the ID of the data in the corresponding cache array.
In a second aspect, an embodiment of the present invention provides an apparatus for reducing database operations by using a cache array, including:
the dividing unit is used for dividing the state of the data in the database into a plurality of normal states in advance, wherein at least one normal state comprises a plurality of specified states;
the device comprises a creating unit, a storage unit and a control unit, wherein the creating unit is used for creating a plurality of cache arrays in a memory, and each cache array corresponds to a specified state;
the judging unit is used for acquiring the state before the data change and the state after the data change when the state of the data changes, judging whether the state before the data change and the state after the data change belong to the same normal state, and judging whether the state before the data change and the state after the data change are in a specified state;
the first processing unit is used for not updating the state of the data in the database if the data belong to the same normal state; deleting the ID of the data in the cache array corresponding to the state before the change, and inserting the ID of the data in the cache array corresponding to the state after the change;
the second processing unit is used for updating the state of the data in the database if the data do not belong to the same normal state; and meanwhile, if the state before the change is the designated state, deleting the ID of the data in the corresponding cache array, and if the state after the change is the designated state, inserting the ID of the data in the corresponding cache array.
In a third aspect, an embodiment of the present invention further provides a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor, when executing the computer program, implements the method for reducing database operations by using a cache array according to the first aspect.
In a fourth aspect, the embodiments of the present invention further provide a computer-readable storage medium, where the computer-readable storage medium stores a computer program, and the computer program, when executed by a processor, causes the processor to execute the method for reducing database operations by using a cache array according to the first aspect.
The invention discloses a method for reducing database operation by using a cache array, wherein the method comprises the following steps: dividing the state of data in a database into a plurality of normal states in advance, wherein at least one normal state comprises a plurality of specified states; creating a plurality of cache arrays in a memory, wherein each cache array corresponds to a specified state; when the state of the data changes, acquiring the state before the data changes and the state after the data changes, judging whether the state before the data changes and the state after the data changes belong to the same normal state, and judging whether the state before the data changes and the state after the data changes are in a specified state; if the data belong to the same normal state, the state of the data in the database is not updated; deleting the ID of the data in the cache array corresponding to the state before the change, and inserting the ID of the data in the cache array corresponding to the state after the change; if the data do not belong to the same normal state, updating the state of the data in the database; and meanwhile, if the state before the change is the designated state, deleting the ID of the data in the corresponding cache array, and if the state after the change is the designated state, inserting the ID of the data in the corresponding cache array. According to the method, the number of times of operating the database is reduced by adding the cache array as a buffer for updating the data state, so that the expense of the database is reduced, and the response speed of the database is improved.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
FIG. 1 is a flowchart illustrating a method for reducing database operations by using a cache array according to an embodiment of the present invention;
FIG. 2 is a schematic block diagram of an apparatus for reducing database operations using a cache array according to an embodiment of the present invention;
FIG. 3 is a schematic block diagram of a computer device provided by an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It is also to be understood that the terminology used in the description of the invention herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used in the specification of the present invention 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 be further understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
Referring to fig. 1, fig. 1 is a schematic flowchart illustrating a method for reducing database operations by using a cache array according to an embodiment of the present invention;
as shown in fig. 1, the method includes steps S101 to S105.
S101, dividing the state of data in the database into a plurality of normal states in advance, wherein at least one normal state comprises a plurality of specified states.
In this embodiment, as time and services develop, the data volume in the database will increase continuously, and for better data sorting and query, the state of the data in the database is divided into a plurality of normal states in advance, and the normal states can be further divided into a plurality of designated states. The data in the database is stored in a corresponding normal form, so that the number of data states in the database can be reduced, and the number of times of updating the data states in the database is reduced.
For example, the state of data in a database may be divided into a first normalcy, a second normalcy, and a third normalcy; obviously, the normal type and number of partitions may be adjusted according to specific scenarios and specific services.
Further, at least one normal state can be divided into a plurality of designated states, for example, the second normal state can be further divided into a first designated state, a second designated state, a third designated state, a fourth designated state and a fifth designated state, that is, the second normal state includes: 5 designated states of a first designated state, a second designated state, a third designated state, a fourth designated state and a fifth designated state; obviously, the types and the number of the specified states divided by the normal state can be adjusted according to a specific scene and a specific service; of course, a normal state may have only one state, i.e., a normal state refers to a specific state.
Further, in order to reduce operations on the database to a greater extent, the states of the data may be divided into normal states as much as possible, so that the number of normal states may be reduced, and thus, when the data state changes, the update operations of the data state in the database may be reduced to a greater extent.
Further, in order to reduce the operations on the database to a greater extent, further optimization can be performed according to the characteristics of the data, and for the case that the change frequency of some data states is large, the data states can be divided into a certain normal state, or for some data with a small data volume, the data states can be divided into a certain normal state, so that the operations on the database can be reduced, and the operation efficiency is improved.
For example, assume that the states of the data are 10 in total: "unused", "normal", "audit not passed", "audit passed", "recheck in", "recheck not passed", "recheck passed", "abnormal", "done".
The 8 states of "normal", "audit in, audit not passed", "audit passed", "double check in, double check not passed", "double check passed" and "abnormal" are changed more frequently and the data amount is smaller. Therefore, the state of the data in the database is now divided into 3 normals: a first normality, a second normality and a third normality, wherein the first normality is in an unused state; the second normality includes: 8 states of ' normal ', ' audit in, ' audit not pass ', ' audit pass ', ' double check in ', ' double check not pass ', ' double check pass ' and ' abnormal ', wherein each state of the 8 states is a designated state; the third norm is the "done" state. In this way, when a data is stored in the database, if the state of the data is any one of "normal", "audit in", "audit not passed", "audit passed", "recheck in", "recheck not passed", "recheck passed" and "abnormal", the storage states of the data in the database are all the second normal state, thereby reducing the number of data states in the database.
S102, creating a plurality of cache arrays in a memory, wherein each cache array corresponds to a specified state;
because the data state in the database needs to be updated according to the change of the data every time the data state changes, and a series of operations such as connection creation, addition of a read-write lock, data updating, lock release, connection closing and the like are needed to update the data state in the database every time, when the data state changes at a high frequency and multi-party concurrent operation occurs, the updating speed of the database is slowed down.
And a plurality of cache arrays are created in the memory, and each designated state (a plurality of designated states in a normal state) corresponds to one cache array. The cache array may contain the ID of the data in the corresponding specified state, and the cache array may be stored in a list. When the state of the data changes, the corresponding cache array in the memory can be modified, and the modification mode can be deleting the ID of a certain data or inserting the ID of a certain data.
By setting the cache array, in the process of updating the data state, particularly under the conditions of high-frequency data change and multi-party concurrence, only the updating operation needs to be carried out in the memory, and the database does not need to be accessed, so that the updating pressure of the database is reduced.
S103, when the state of the data changes, acquiring the state before the data changes and the state after the data changes, judging whether the state before the data changes and the state after the data changes belong to the same normal state, and judging whether the state before the data changes and the state after the data changes are in a specified state.
In this embodiment, when the state of the data changes, it is necessary to determine whether the state of the data in the database needs to be updated and whether the cache array needs to be modified according to the changed condition.
In the database, the update of the data state can only be from one normal state to another, so this step needs to confirm whether the state of the data changes from one normal state to another or still belongs to the same normal state. For example, a state before one data change is a "normal" state, and a state after the change is an "under-audit" state, and since both the two states are specified states in the second normal state, the state before the change and the state after the change belong to the same normal state. Or, a state before one data change is a "normal" state, and a state after the change is a "complete" state, and since one of the two states is a designated state in the second normal state and the other is a third normal state, the state before the change and the state after the change do not belong to the same normal state.
In the cache array, the update of the data state is from the cache array corresponding to a specified state to the cache array corresponding to another specified state, so this step needs to confirm whether the state before the data change and the state after the change are the specified states. For example, the state before one data change is the "normal" state, and the state after the change is the "under-examination" state, and since both the two states are the designated states in the second normal state, both the state before the change and the state after the change are the designated states. Or, the state before one data change is the "normal" state, and the state after the change is the "complete" state, and since one of the two states is the designated state in the second normal state and the other is the third normal state, the state before the change is the designated state, and the state after the change is not the designated state.
S104, if the data belong to the same normal state, the state of the data in the database is not updated; and deleting the ID of the data in the cache array corresponding to the state before the change, and inserting the ID of the data in the cache array corresponding to the state after the change.
If the state before the change of the data and the state after the change belong to the same normal state, the state before the change and the state after the change are necessarily both specified states in the same normal state, that is, the state change of the data is changed from one specified state to another specified state in the same normal state.
Specifically, for example, the state before the data change is the designated state "in the audit" in the second normal state, and the state after the change is the designated state "the audit is not passed" in the second normal state, so that the change of the data state belongs to the change between the designated states in the second normal state, that is, the states before and after the change are confirmed to belong to the same normal state, and therefore, the state of the data does not need to be updated in the database.
Further, the ID of the data is a unique identifier of the data, and the cache array stores the ID of the data.
The premise of this step is that the state before change and the state after change belong to the same normal state, so the state before change and the state after change of this data are necessarily both specified states, so the cache arrays corresponding to these two specified states need to be modified, and the modification mode is: assuming that the state before the change is the first designated state, the corresponding cache array is the first cache array, the state after the change is the second designated state, and the corresponding cache array is the second cache array, the ID of the data needs to be deleted from the first cache array, and the ID of the data needs to be inserted into the second cache array. That is, when a data changes from one specified state to another, it changes between two cache arrays in memory.
S105, if the data do not belong to the same normal state, updating the state of the data in the database; and meanwhile, if the state before the change is the designated state, deleting the ID of the data in the corresponding cache array, and if the state after the change is the designated state, inserting the ID of the data in the corresponding cache array.
If the state before the data change and the state after the data change do not belong to the same normal state, the state before the data change may be a designated state or may not be the designated state; similarly, the changed state may or may not be the designated state. In this case, the state of the data in the database needs to be updated, but the cache array does not necessarily need to be modified, and it is specifically necessary to confirm whether the state before the change of the data and the state after the change are the designated states.
If the state of the data before change is the designated state, the cache array corresponding to the designated state needs to be modified, the modification mode is to delete the ID of the data from the cache array, and it needs to be noted that whether the state of the data after change is the designated state does not affect the modification of the cache array. Similarly, if the changed state of the data is the designated state, the cache array corresponding to the designated state needs to be modified, the modification mode is to insert the ID of the data into the cache array, and it should be noted that whether the state before the change of the data is the designated state does not affect the modification of the cache array.
For example, the state before the data change is the "unused" state, and the state after the change is the "audit passed" state; the state before the data change and the state after the data change do not belong to the same normal state, so that the data state in the database needs to be updated, namely the data state is updated from the first normal state to the second normal state. Since the "audit pass" state is a designated state, the corresponding cache array is stored in the memory, and the "unused" state does not have a corresponding cache array in the memory, the ID of the data needs to be inserted into the cache array corresponding to the "audit pass" state, and the ID in any cache array does not need to be deleted.
Of course, there may be a fourth normal state, and the fourth normal state also has a plurality of designated states, and if the state of one data is updated from the second normal state to the fourth normal state, the state of the data in the database needs to be updated at the same time, and two cache arrays in the memory need to be modified.
In an embodiment, when an instruction of adding new data is received, the state of the data is set to be an initial state, a normal state to which the initial state belongs is acquired, and then the data is stored in the database according to the normal state.
In this embodiment, the normal state to which the initial state belongs is preset, and when data is newly added, the state of the data only needs to be set to the initial state, and then the data is stored in the database according to the normal state to which the initial state belongs.
In an embodiment, when receiving an instruction to add new data, setting the state of the data to an initial state, acquiring a normal state to which the initial state belongs, and then storing the data in the database according to the normal state, further includes:
and judging whether the initial state is a designated state, and if so, storing the ID of the data into a corresponding cache array.
In this embodiment, if the normal state to which the newly added data belongs is divided into a plurality of designated states, the designated states of the initial state are continuously matched in the normal state to which the newly added data belongs, and the ID of the newly added data is inserted into the cache array corresponding to the designated state after the designated state is determined.
In the embodiment of the invention, when the data state changes, the data state can be updated to the cache array, so that the operation of updating the data state in the database can be reduced, the database resource is saved, and the maintenance cost is reduced.
The method for reducing database operations by using the cache array further comprises the following steps:
when a data query instruction is received, querying corresponding data in a database, and matching the ID of the queried data with the ID in each cache array;
and if the matching is successful, replacing the state of the corresponding data with the specified state, and returning the inquired data.
In this embodiment, according to a received query instruction, corresponding data is searched in a database, an ID of the data is obtained, and matching is performed in a memory through the ID of the data, where the matching is performed for the purpose of querying a real state of the data, and a normal state cannot represent the real state of the data, and if the state of the returned data is only a normal state, accurate information cannot be provided to a user. Therefore, in the embodiment of the present invention, the IDs of the data need to be matched in each cache array of the memory, and if the matching is successful, the state of the corresponding data needs to be replaced with the specified state. For example, the state of a data in the database is the second normal state, and the ID of the data is stored in the cache array corresponding to the "check pass" state, so that the state of the data can be replaced from the second normal state to the "check pass" state and returned. Of course, if the state of a data in the database is the first normal state, since the ID of the data is not stored in any cache array in the memory, the state in the database can be directly returned. This is because the first normal state is only in the "unused" state, and the two states have a one-to-one correspondence, so the returned first normal state represents the "unused" state.
In an embodiment, the method for reducing database operations by using a cache array further includes:
when a command for inquiring data is received and the state of the data is a designated state, acquiring the ID of the data in a corresponding cache array;
and inquiring corresponding data in a database according to the ID of the data, and returning.
In this embodiment, when an instruction for querying data is received and it is determined that the state of the data is the designated state, the ID of the data may be directly obtained from the cache array corresponding to the designated state, because all the IDs of the data in the designated state are stored in the cache array, and then the data is queried in the database according to the IDs of the data and returned, so that the data querying efficiency is greatly improved.
In one embodiment, the state of the queried data is replaced with the specified state and returned.
In this embodiment, since the data is in the designated state, the state of the data stored in the database is a normal state, and at this time, it is necessary to replace the normal state with the designated state and return the data.
In one embodiment, the state of the queried data is replaced with the corresponding specified state, and the data for each specified state is sorted back.
In this embodiment, in the process of simultaneously querying data in multiple specified states, in order to make the returned data more orderly and convenient for querying, when multiple data are queried, the state of each data is replaced with the corresponding specified state, and the data in each specified state are returned by classification, so that the queried data will be data in different specified states.
Referring to fig. 2, fig. 2 is a schematic block diagram of an apparatus 200 for reducing database operations by using a cache array according to an embodiment of the present invention, where the apparatus 200 may include: a dividing unit 201, a creating unit 202, a judging unit 203, a first processing unit 204, and a second processing unit 205.
The dividing unit 201 is configured to divide the state of data in the database into a plurality of normals in advance, where at least one normal includes a plurality of designated states;
a creating unit 202, configured to create a plurality of cache arrays in an internal memory, where each cache array corresponds to a designated state;
a determining unit 203, configured to, when a state of data changes, obtain a state before the data changes and a state after the data changes, determine whether the state before the data changes and the state after the data changes belong to the same normal state, and determine whether the state before the data changes and the state after the data changes are in a specified state;
the first processing unit 204 is configured to not update the state of the data in the database if the data belong to the same normal state; and deleting the ID of the data in the cache array corresponding to the state before the change, and inserting the ID of the data in the cache array corresponding to the state after the change.
The second processing unit 205 is configured to update the state of the data in the database if the data do not belong to the same normal state; and meanwhile, if the state before the change is the designated state, deleting the ID of the data in the corresponding cache array, and if the state after the change is the designated state, inserting the ID of the data in the corresponding cache array.
The device establishes a plurality of cache arrays and completes the updating of partial data states in the cache arrays, thereby reducing the operation of updating the database, saving database resources and reducing the maintenance cost.
In one embodiment, the apparatus 200 for reducing database operations using a cache array further comprises:
and the adding unit is used for setting the state of the data into an initial state when receiving an instruction of adding new data, acquiring a normal state of the initial state, and storing the data into the database according to the normal state.
In one embodiment, the apparatus 200 for reducing database operations using a cache array further comprises:
and the cache unit is used for judging whether the initial state is a designated state or not, and if so, storing the ID of the data into a corresponding cache array.
In one embodiment, the apparatus 200 for reducing database operations using a cache array further comprises:
the matching unit is used for querying corresponding data in the database when receiving a data query instruction, and matching the ID of the queried data with the ID in each cache array;
and the replacement returning unit is used for replacing the state of the corresponding data with the specified state and returning the inquired data if the matching is successful.
In one embodiment, the apparatus 200 for reducing database operations using a cache array further comprises:
the data processing device comprises an acquisition unit, a cache array and a processing unit, wherein the acquisition unit is used for acquiring the ID of data in the corresponding cache array when receiving an instruction of inquiring the data and the state of the data is a specified state;
and the direct return unit is used for inquiring corresponding data in the database according to the ID of the data and returning the data.
In one embodiment, the direct return unit comprises:
and the replacing unit is used for replacing the state of the inquired data with the specified state and returning.
In one embodiment, the state of the data to be queried includes a plurality of specified states, and the replacement unit includes:
and the classification unit is used for replacing the state of the inquired data with the corresponding specified state and classifying and returning the data of each specified state.
Since the embodiments of the apparatus portion and the method portion correspond to each other, please refer to the description of the embodiments of the method portion for the embodiments of the apparatus portion, which is not repeated here.
The above-described apparatus for reducing database operations using a cache array may be implemented in the form of a computer program that may be executed on a computer device as shown in fig. 3.
Referring to fig. 3, fig. 3 is a schematic block diagram of a computer device according to an embodiment of the present invention. The computer device 300 includes a processor 302, memory, and a network interface 305 connected by a system bus 301, where the memory may include a non-volatile storage medium 303 and an internal memory 304.
The nonvolatile storage medium 303 may store an operating system 3031 and a computer program 3032. The computer program 3032, when executed, may cause the processor 302 to perform a method for reducing database operations using a cache array.
The processor 302 is used to provide computing and control capabilities that support the operation of the overall computer device 300.
The internal memory 304 provides an environment for the execution of the computer program 3032 on the non-volatile storage medium 303, and when the computer program 3032 is executed by the processor 302, the computer program causes the processor 302 to perform a method for reducing database operations using a cache array.
The network interface 305 is used for network communication, such as providing transmission of data information. It will be appreciated by those skilled in the art that the configuration shown in fig. 3 is a block diagram of only a portion of the configuration associated with the inventive arrangements and is not intended to limit the computing device 300 to which the inventive arrangements may be applied, and that a particular computing device 300 may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
Those skilled in the art will appreciate that the embodiment of a computer device illustrated in fig. 3 does not constitute a limitation on the specific construction of the computer device, and in other embodiments a computer device may include more or fewer components than those illustrated, or some components may be combined, or a different arrangement of components. For example, in some embodiments, the computer device may only include a memory and a processor, and in such embodiments, the structures and functions of the memory and the processor are consistent with those of the embodiment shown in fig. 3, and are not described herein again.
It should be understood that, in the embodiment of the present invention, the Processor 302 may be a Central Processing Unit (CPU), and the Processor 302 may also be other general-purpose processors, Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field-Programmable gate arrays (FPGAs) or other Programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, and the like. Wherein a general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
In another embodiment of the invention, a computer-readable storage medium is provided. The computer readable storage medium may be a non-volatile computer readable storage medium. The computer readable storage medium stores a computer program, wherein the computer program when executed by a processor implements the method for reducing database operations using a cache array of an embodiment of the present invention.
The storage medium is an entity and non-transitory storage medium, and may be various entity storage media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-only memory (ROM), a magnetic disk, or an optical disk.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described apparatuses, devices and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
While the invention has been described with reference to specific embodiments, the invention is not limited thereto, and various equivalent modifications and substitutions can be easily made by those skilled in the art within the technical scope of the invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.
Claims (10)
1. A method for reducing database operations using a cache array, comprising:
dividing the state of data in a database into a plurality of normal states in advance, wherein at least one normal state comprises a plurality of specified states;
creating a plurality of cache arrays in a memory, wherein each cache array corresponds to a specified state;
when the state of the data changes, acquiring the state before the data changes and the state after the data changes, judging whether the state before the data changes and the state after the data changes belong to the same normal state, and judging whether the state before the data changes and the state after the data changes are in a specified state;
if the data belong to the same normal state, the state of the data in the database is not updated; deleting the ID of the data in the cache array corresponding to the state before the change, and inserting the ID of the data in the cache array corresponding to the state after the change;
if the data do not belong to the same normal state, updating the state of the data in the database; and meanwhile, if the state before the change is the designated state, deleting the ID of the data in the corresponding cache array, and if the state after the change is the designated state, inserting the ID of the data in the corresponding cache array.
2. The method for reducing database operations using a cache array of claim 1, further comprising:
when an instruction of adding new data is received, setting the state of the data to be in an initial state, acquiring a normal state to which the initial state belongs, and then storing the data to the database according to the normal state.
3. The method for reducing database operations using a cache array of claim 2, further comprising:
and judging whether the initial state is a designated state, and if so, storing the ID of the data into a corresponding cache array.
4. The method for reducing database operations using a cache array of claim 1, further comprising:
when a data query instruction is received, querying corresponding data in a database, and matching the ID of the queried data with the ID in each cache array;
and if the matching is successful, replacing the state of the corresponding data with the specified state, and returning the inquired data.
5. The method for reducing database operations using a cache array of claim 1, further comprising:
when a command for inquiring data is received and the state of the data is a designated state, acquiring the ID of the data in a corresponding cache array;
and inquiring corresponding data in a database according to the ID of the data, and returning.
6. The method for reducing database operations by using a cache array according to claim 5, wherein the querying the corresponding data in the database according to the ID of the data and returning comprises:
and replacing the state of the inquired data with a specified state and returning.
7. The method for reducing database operations by using a cache array according to claim 6, wherein the state of the data to be queried comprises a plurality of specified states, and the replacing the state of the queried data with the specified state and returning comprises:
and replacing the state of the inquired data with the corresponding specified state, and returning the data of each specified state in a classified manner.
8. An apparatus for reducing database operations using a cache array, comprising:
the dividing unit is used for dividing the state of the data in the database into a plurality of normal states in advance, wherein at least one normal state comprises a plurality of specified states;
the device comprises a creating unit, a storage unit and a control unit, wherein the creating unit is used for creating a plurality of cache arrays in a memory, and each cache array corresponds to a specified state;
the judging unit is used for acquiring the state before the data change and the state after the data change when the state of the data changes, judging whether the state before the data change and the state after the data change belong to the same normal state, and judging whether the state before the data change and the state after the data change are in a specified state;
the first processing unit is used for not updating the state of the data in the database if the data belong to the same normal state; deleting the ID of the data in the cache array corresponding to the state before the change, and inserting the ID of the data in the cache array corresponding to the state after the change;
the second processing unit is used for updating the state of the data in the database if the data do not belong to the same normal state; and meanwhile, if the state before the change is the designated state, deleting the ID of the data in the corresponding cache array, and if the state after the change is the designated state, inserting the ID of the data in the corresponding cache array.
9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor when executing the computer program implements a method of reducing database operations using a cache array as claimed in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that the computer-readable storage medium stores a computer program which, when executed by a processor, causes the processor to carry out the method of reducing database operations with a cache array according to any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201911365788.5A CN111143326B (en) | 2019-12-26 | 2019-12-26 | Method, apparatus, computer device and storage medium for reducing database operations |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201911365788.5A CN111143326B (en) | 2019-12-26 | 2019-12-26 | Method, apparatus, computer device and storage medium for reducing database operations |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111143326A true CN111143326A (en) | 2020-05-12 |
CN111143326B CN111143326B (en) | 2023-08-18 |
Family
ID=70520451
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201911365788.5A Active CN111143326B (en) | 2019-12-26 | 2019-12-26 | Method, apparatus, computer device and storage medium for reducing database operations |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111143326B (en) |
Cited By (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111782667A (en) * | 2020-06-22 | 2020-10-16 | 成都校精灵科技有限公司 | MongoDB updating data driving method, system and storage medium |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7526481B1 (en) * | 1999-04-19 | 2009-04-28 | Oracle International Corporation | Web servers with queryable dynamic caches |
US20140317047A1 (en) * | 2013-04-22 | 2014-10-23 | Sap Ag | Enhanced transactional cache with bulk operation |
CN105354317A (en) * | 2015-11-12 | 2016-02-24 | 携程计算机技术(上海)有限公司 | Hotel database updating method and system |
CN108549704A (en) * | 2018-04-18 | 2018-09-18 | 厦门市美亚柏科信息股份有限公司 | Distributive type preprocess method, device, equipment and the readable medium of data packet |
-
2019
- 2019-12-26 CN CN201911365788.5A patent/CN111143326B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US7526481B1 (en) * | 1999-04-19 | 2009-04-28 | Oracle International Corporation | Web servers with queryable dynamic caches |
US20140317047A1 (en) * | 2013-04-22 | 2014-10-23 | Sap Ag | Enhanced transactional cache with bulk operation |
CN105354317A (en) * | 2015-11-12 | 2016-02-24 | 携程计算机技术(上海)有限公司 | Hotel database updating method and system |
CN108549704A (en) * | 2018-04-18 | 2018-09-18 | 厦门市美亚柏科信息股份有限公司 | Distributive type preprocess method, device, equipment and the readable medium of data packet |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111782667A (en) * | 2020-06-22 | 2020-10-16 | 成都校精灵科技有限公司 | MongoDB updating data driving method, system and storage medium |
CN111782667B (en) * | 2020-06-22 | 2024-05-17 | 成都校精灵科技有限公司 | MongoDB updated data driving method, system and storage medium |
Also Published As
Publication number | Publication date |
---|---|
CN111143326B (en) | 2023-08-18 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN103019960B (en) | Distributed caching method and system | |
CN111221840B (en) | Data processing method and device, data caching method, storage medium and system | |
CN110851474A (en) | Data query method, database middleware, data query device and storage medium | |
CN114020840A (en) | Data processing method, device, server, storage medium and product | |
CN114896641A (en) | Data verification method and device, electronic equipment and computer readable storage medium | |
WO2018205689A1 (en) | File merging method, storage device, storage apparatus, and storage medium | |
US11150993B2 (en) | Method, apparatus and computer program product for improving inline pattern detection | |
US10365850B2 (en) | Method of storing data, information processing apparatus and non-transitory computer-readable storage medium | |
CN111143326B (en) | Method, apparatus, computer device and storage medium for reducing database operations | |
CN114297196A (en) | Metadata storage method and device, electronic equipment and storage medium | |
CN107451154B (en) | Data table processing method, device and system | |
CN110674086A (en) | Data merging method and device, electronic equipment and storage medium | |
CN112395337A (en) | Data export method and device | |
CN115017164A (en) | Index construction method, index construction system and index updating method | |
CN112000698B (en) | Log recording method and device, storage medium and electronic device | |
CN112559547B (en) | Method and device for determining consistency among multiple storage object copies | |
CN115576947A (en) | Data management method and device, combined library, electronic equipment and storage medium | |
CN114385657A (en) | Data storage method, device and storage medium | |
CN114020745A (en) | Index construction method and device, electronic equipment and storage medium | |
CN114416884A (en) | Method and device for connecting partition table | |
CN113868267A (en) | Method for injecting time sequence data, method for inquiring time sequence data and database system | |
CN116578247B (en) | Metadata-based data access method and system | |
CN116186046B (en) | Device data modification method and device, computer device and storage medium | |
CN113051274B (en) | Mass tag storage system and method | |
CN112860694B (en) | Service data processing method, device and equipment |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |