Data storage and query method and system, electronic equipment and storage medium
By defining the attributes and indexes of the data table in the configuration file of the NoSQL database, generating query combinations and sorting data, the problem of huge existing NoSQL databases and low query efficiency is solved, and the effect of dynamic modification of primary key information and improving query efficiency is achieved.
Patent Information
- Application Number
- CN202411899519.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-23
- Publication Date
- 2025-04-15
AI Technical Summary
The existing NoSQL database is too large and it is difficult to embed programs as a local in-memory database. The code needs to be modified when the primary key information is changed, so the query efficiency is low.
By defining the properties and index of the data table in the configuration file, the database program loads the configuration file when it starts, generates query combinations, and sorts the data according to the index's priority, dynamically modifying the primary key information and improving query efficiency.
It realizes dynamic modification of the properties and index of the data table through configuration files, reducing the need for code modification, and improving the flexibility and query efficiency of the database.
Smart Images

Figure CN119829581A_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of data processing technology, and in particular to a data storage and query method, system, electronic device and storage medium. Background Art
[0002] With the development of computer and Internet technologies, NoSQL and other databases are being used in more and more scenarios. From a technical perspective, most of the NoSQL and other databases currently on the market are too large to be directly embedded in programs as local memory databases. They also have high requirements for developers and require a lot of time to learn before they can be used.
[0003] In addition, from a business perspective, when the primary key information of the current database on the market changes, the program needs to modify the code, the code needs to be hard-coded, and multiple queries need to be performed to achieve it. Therefore, an effective solution is urgently needed to solve the above problem. Summary of the invention
[0004] The present invention provides a data storage and query method, system, electronic equipment and storage medium.
[0005] The present invention solves the above technical problems through the following technical solutions:
[0006] The present invention provides a data storage and query method, comprising:
[0007] Define the attributes of each data table in the configuration file;
[0008] Based on the attributes corresponding to each data table, one or more corresponding indexes are set for each data table in the configuration file, wherein each index includes one or more dimensions, and each dimension includes the attributes of one or more data tables;
[0009] When the database program is started, the configuration file is loaded, the index corresponding to each data table in the configuration file is read, and at least two query combinations are formed based on the attributes of each dimension in the index, wherein each query combination contains an attribute under each dimension of the corresponding index;
[0010] When adding new data, the database obtains the data table selected by the user and the values assigned by the user to each attribute of at least one piece of data in the data table. The database saves each piece of data in the order in which it is actually written, and sorts each piece of data according to each index;
[0011] The database obtains the user's query information, which includes the user's attribute assignments for each dimension under the index corresponding to the selected data table to be queried; the database obtains the corresponding query combination based on the attribute assignments, and obtains and outputs the corresponding data in the data table to be queried based on the query combination.
[0012] Furthermore, in the above method, the database obtains the data table selected by the user and the user's assignment of each attribute of at least one piece of data in the data table, including:
[0013] The database obtains the data table selected by the user and the values assigned by the user to some attributes of at least one piece of data in the data table.
[0014] Furthermore, in the above method, one or more corresponding indexes are set for each data table in the configuration file, wherein each index includes one or more dimensions, and each dimension includes one or more attributes of the data table, including:
[0015] Different attributes within the same dimension are set with different priorities.
[0016] Furthermore, in the above method, after the attributes of each dimension in the index are combined into at least two query combinations, the method may further include: prioritizing each query combination according to the priority of the attribute.
[0017] Furthermore, in the above method, obtaining and outputting corresponding data in the data table to be queried based on the query combination includes:
[0018] The query combination to be queried is sequentially queried from the highest priority query combination to the lowest priority query combination until the corresponding data is found and output; or the query combination based on the lowest priority stops when no data is found.
[0019] Furthermore, in the above method, after the attributes of each dimension in the index are combined into at least two query combinations, at least one of the following items may also be included:
[0020] The database obtains the user's modification of the attributes contained in the data table and the corresponding indexes, stores the modified attributes in the configuration file, updates the corresponding query combination based on the modified index, and re-sorts each piece of data in the data table based on the modified index;
[0021] The database obtains the modification made by the user to the index corresponding to the data table, updates the corresponding query combination based on the modified index, and re-sorts each piece of data in the data table based on the modified index.
[0022] According to another aspect of the present invention, there is also provided a data storage and query system, the system comprising:
[0023] Configuration attribute module, used to define the attributes contained in each data table in the configuration file;
[0024] The configuration index module is used to set one or more corresponding indexes for each data table in the configuration file based on the attributes corresponding to each data table, wherein each index includes one or more dimensions, and each dimension includes the attributes of one or more data tables;
[0025] A query combination module is configured to load the configuration file when the database program is started, read the index corresponding to each data table in the configuration file, and combine the attributes of each dimension in the index into at least two query combinations, wherein each query combination contains an attribute under each dimension of the corresponding index;
[0026] The sorting module is used to provide the database with the data table selected by the user and the values assigned by the user to each attribute of at least one piece of data in the data table when adding new data. The database saves each piece of data in the order in which it is actually written, and sorts each piece of data according to each index;
[0027] The query module is used for the database to obtain the user's query information, which includes the attribute values assigned by the user to each dimension under the index corresponding to the data table to be queried; the database obtains the corresponding query combination based on the attribute assignment, and obtains and outputs the corresponding data in the data table to be queried based on the query combination.
[0028] Furthermore, in the above system, the sorting module is used for the database to obtain the data table selected by the user and the user's assignment of partial attributes to at least one data in the data table.
[0029] Furthermore, in the above system, the configuration index module is used to set different priorities for different attributes in the same dimension.
[0030] Furthermore, in the above system, the configuration query combination module is used to prioritize each query combination according to the priority of the attribute.
[0031] Furthermore, in the above system, the query module is used to query the data table to be queried in sequence from high-priority query combinations to low-priority query combinations, until the corresponding data are found and then stopped and output; or stop after the query combination based on the lowest priority fails to find data.
[0032] Furthermore, the above system further includes a configuration modification module, which is used for at least one of the following:
[0033] The database obtains the user's modification of the attributes and corresponding indexes contained in the data table, stores the modified attributes in the configuration file, updates the corresponding query combination based on the modified index, and re-sorts each piece of data in the data table based on the modified index;
[0034] The database obtains the user's modification of the index corresponding to the data table, updates the corresponding query combination based on the modified index, and re-sorts each data in the data table based on the modified index.
[0035] According to another aspect of the present invention, there is also provided an electronic device, comprising a memory, a processor, and a computer program stored in the memory and used to run on the processor, wherein when the processor executes the computer program, the data storage and query method described in any one of the above items is implemented.
[0036] According to another aspect of the present invention, there is further provided a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the data storage and query method described in any one of the above items is implemented.
[0037] The positive and progressive effects of the present invention are:
[0038] The present invention defines the attributes contained in each data table in a configuration file, and based on the attributes corresponding to each data table, sets one or more corresponding indexes for each data table in the configuration file. When the database program is started, the configuration file is loaded, and the index corresponding to each data table in the configuration file is read. At least two query combinations are formed based on the attributes of each dimension in the index. This allows the user to modify the configuration file if he needs to modify the index or add or modify the attributes of the data table after the database is started. The database will periodically check the configuration information, and if any changes are found, the changed index will be checked, and the data will be re-maintained based on the changed index, so that the primary key information, i.e., the attribute information, can be dynamically added or modified through the configuration file.
[0039] In addition, the present invention combines at least two query combinations based on the attributes of each dimension in the index, and can set different levels of query methods for the same data according to the attribute priority, thereby improving query efficiency and accuracy. Users can also assign values to some attributes in the data table, which greatly reduces the amount of data storage and improves the efficiency of index sorting.
[0040] In addition, the present invention queries the data table to be queried by sequentially going from a high-priority query combination to a low-priority query combination until the corresponding data are found and then stopped and output. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 This is a first flow chart of the data storage and query method of embodiment 1 of the present disclosure;
[0042] Figure 2 A second flow chart of the data storage and query method of embodiment 1 of the present disclosure;
[0043] Figure 3 This is a schematic diagram of the first module of the data storage and query system of Embodiment 2 of the present disclosure;
[0044] Figure 4 This is a schematic diagram of a second module of the data storage and query system of Embodiment 2 of the present disclosure;
[0045] Figure 5 This is a schematic diagram of the structure of an electronic device according to Embodiment 3 of the present disclosure. DETAILED DESCRIPTION
[0046] The present disclosure is further described below by way of examples, but the present disclosure is not limited to the scope of the examples.
[0047] Example 1
[0048] like Figure 1 As shown, this embodiment provides a data storage and query method, the method comprising:
[0049] Step S1, defining the attributes contained in each data table in the configuration file;
[0050] Here, you can define the structure of the data table, that is, define the attributes contained in the data table;
[0051] The data table may be, for example, a margin rate table, a handling fee rate table, or a contract table;
[0052] Each data table contains multiple attributes. For example, the margin rate table may contain the following attributes: account number, exchange number, product number, contract number, and specific margin rate.
[0053] Specifically, each attribute corresponds to a unique number. Each attribute under the same data table can be set with a unique number. For example, the attribute numbers of account number, exchange number, product number, contract number and specific margin rate are 0, 1, 2, 3 and 4 respectively.
[0054] Step S2, based on the attributes corresponding to each data table, one or more corresponding indexes are set for each data table in the configuration file, wherein each index includes one or more dimensions, and each dimension includes the attributes of one or more data tables;
[0055] For example, one or more indexes may be set for the margin rate table, the handling fee rate table, and the contract table, respectively, wherein each index contains one or more dimension data, and each dimension data may contain one or more attributes;
[0056] For example, the first index of the margin rate table can include three dimensions: account, exchange, and contract, among which,
[0057] The account dimension includes one attribute: account number;
[0058] The exchange dimension includes one attribute: exchange number;
[0059] The contract dimension includes two attributes: the contract number and the contract type number (with priority);
[0060] For example, the first index of the margin rate table may include two dimensions: exchange and contract. The exchange dimension includes two attributes: exchange number and default exchange number.
[0061] The contract dimension includes two attributes: the contract number and the product number to which the contract belongs.
[0062] Preferably, different attributes in the same dimension are respectively set with different priorities; for example, among the two attributes of the contract dimension of the first index, the priority of the contract number is higher than the priority of the variety number to which the contract belongs;
[0063] Step S3, when the database program is started, the configuration file is loaded, the index corresponding to each data table in the configuration file is read, and at least two query combinations are formed based on the attributes of each dimension in the index, wherein each query combination contains an attribute under each dimension of the corresponding index;
[0064] For example, based on the attributes of each dimension in the first index of the above margin rate table, the following query combination can be generated:
[0065] The first query combination: account number + exchange number + contract number;
[0066] Second query combination: account number + exchange number + contract type number;
[0067] Preferably, after the attributes of each dimension in the index are combined into at least two query combinations, the method may further include: prioritizing each query combination according to the priority of the attribute;
[0068] For example, since the priority of the contract number is higher than the priority of the product number to which the contract belongs among the two attributes of the contract dimension of the first index, the priority of the first query combination is higher than that of the second query combination;
[0069] The present invention can realize that after the database is started, if the user needs to modify the index or add or modify the attributes of the data table, the modification can be achieved by modifying the configuration file. The database will check the configuration information regularly. If any change is found, the index of the change will be changed, and the data will be re-maintained based on the changed index, so that the primary key information, that is, the attribute information, can be dynamically added or modified through the configuration file.
[0070] Step S4, when adding new data, the database obtains the data table selected by the user and the values assigned by the user to each attribute of at least one data in the data table, and the database saves each data in the order in which it is actually written, and sorts each data according to each index, so as to speed up the search when querying the data later;
[0071] Here, users can select a data table with the following attributes: account number, exchange number, product number, contract number, and specific margin rate. Users can assign values to each attribute in the data table.
[0072] Preferably, users can also assign values to some attributes in the data table, which greatly reduces the amount of data storage and improves index sorting efficiency;
[0073] For example, in the margin rate table above, since most of the contracts under the same product have the same margin rate, only a few individual contracts have special margin rates. Therefore, when setting, not all attributes need to be assigned. Ordinary contracts only need to set the product number, and some special contracts need to set the contract number. That is, you can choose to assign either the contract number or the product number. Specifically, you can set the following two data:
[0074] Ordinary contract: Account number: test, Exchange number: SHFE, Product number: rb, Specific margin rate: 0.2;
[0075] Special contract: Account number: test, Exchange number: SHFE, Contract number: rb2501, Specific margin rate: 0.1.
[0076] Step S5, the database obtains the user's query information, which includes the user's attribute assignments for each dimension under the index corresponding to the selected data table to be queried; the database obtains the corresponding query combination based on the attribute assignments, and obtains and outputs the corresponding data in the data table to be queried based on the query combination.
[0077] Preferably, obtaining and outputting corresponding data in the data table to be queried based on the query combination includes:
[0078] The query combination to be queried is sequentially queried from the highest priority query combination to the lowest priority query combination until the corresponding data is found and output; or the query combination based on the lowest priority stops when no data is found.
[0079] Here, when querying, the user needs to specify the data table and the corresponding index information, and assign values to all the attributes contained in the index. The database will query according to the pre-processed query combination sorted by priority. That is, first query the data in the data table according to the query combination with high priority. If the query combination with high priority finds the data, stop searching for data; if no data is found, search for data according to the query combination with lower priority at the next level until the data is found, then stop searching for data, or stop returning empty if the query combination with the lowest priority does not find the data. In this way, different levels of query methods can be set according to the attribute priority for the same data, improving query efficiency and accuracy.
[0080] For example, the first query combination has a higher priority than the second query combination:
[0081] The first query combination: account number + exchange number + contract number;
[0082] The second query combination: account number + exchange number + contract type number.
[0083] For example, there are currently two pieces of data in the data table:
[0084] 1. Account number: test, exchange number: SHFE, contract number: rb2501, specific margin rate: 0.1;
[0085] 2. Account number: test, exchange number: SHFE, product number: rb, specific margin rate: 0.2;
[0086] Among them, rb2501 is a specific contract, rb is the product number, and there are multiple contracts under the rb product number, such as rb2501, rb2502, etc.;
[0087] If the user assigns the following values to the attributes of each dimension under the index corresponding to the selected data table to be queried: Account Number: test, Exchange Number: SHFE, Contract Number: rb2501, Product Number: rb, then according to the first query combination: Account Number + Exchange Number + Contract Number, the margin rate of the first data item can be queried to be 0.1;
[0088] If the user assigns the following values to the attributes of each dimension under the index corresponding to the selected data table to be queried: Account Number: test, Exchange Number: SHFE, Contract Number: rb2502, Product Number: rb, in this case, there is no rb2502 in the above two pieces of data in the database, and the query according to the first query combination with a higher priority will not find any data; then the query can be performed according to the second query combination with a lower priority, and the margin rate in the second piece of data queried is 0.2;
[0089] If the user assigns the following values to the attributes of each dimension under the index corresponding to the selected data table to be queried: Account Number: test, Exchange Number: DCE, Contract Number: a2501, Product Number: a, then both the first query combination with a higher priority and the second query combination with a lower priority will fail to find any data and the query will stop and return empty.
[0090] like Figure 2 As shown, preferably, in step S3, the configuration file is loaded when the database program is started, the index corresponding to each data table in the configuration file is read, and at least two query combinations are formed based on the attributes of each dimension in the index, wherein each query combination contains an attribute under each dimension of the corresponding index and may also include at least one of the following:
[0091] Step S61, the database obtains the user's modification of the attributes contained in the data table and the corresponding indexes, stores the modified attributes in the configuration file, updates the corresponding query combination based on the modified index, and re-sorts each piece of data in the data table based on the modified index;
[0092] Step S62, the database obtains the modification of the index corresponding to the data table by the user, updates the corresponding query combination based on the modified index, and re-sorts each data in the data table based on the modified index.
[0093] Here, after the database is started, if the user needs to modify the index or add or modify the properties of the data table, the modification can be achieved by modifying the configuration file. The database will check the configuration information regularly. If any changes are found, the index of the change will be changed and the data will be re-maintained based on the changed index. In this way, the primary key information, that is, the property information, can be dynamically added or modified through the configuration file.
[0094] Example 2
[0095] like Figure 3 According to another aspect of the present invention, a data storage and query system is also provided, the system comprising: a configuration attribute module, a configuration index module, a configuration query combination module, a sorting module, and a query module, wherein:
[0096] Configuration attribute module, used to define the attributes contained in each data table in the configuration file;
[0097] Here, you can define the structure of the data table, that is, define the attributes contained in the data table;
[0098] The data table may be, for example, a margin rate table, a handling fee rate table, or a contract table;
[0099] Each data table contains multiple attributes. For example, the margin rate table may contain the following attributes: account number, exchange number, product number, contract number, and specific margin rate.
[0100] Specifically, each attribute corresponds to a unique number. Each attribute under the same data table can be set with a unique number. For example, the attribute numbers of account number, exchange number, product number, contract number and specific margin rate are 0, 1, 2, 3 and 4 respectively.
[0101] The configuration index module is used to set one or more corresponding indexes for each data table in the configuration file based on the attributes corresponding to each data table, wherein each index includes one or more dimensions, and each dimension includes the attributes of one or more data tables;
[0102] For example, one or more indexes may be set for the margin rate table, the handling fee rate table, and the contract table, respectively, wherein each index contains one or more dimension data, and each dimension data may contain one or more attributes;
[0103] For example, the first index of the margin rate table can include three dimensions: account, exchange, and contract, among which,
[0104] The account dimension includes one attribute: account number;
[0105] The exchange dimension includes one attribute: exchange number;
[0106] The contract dimension includes two attributes: the contract number and the contract type number (with priority);
[0107] For example, the first index of the margin rate table may include two dimensions: exchange and contract. The exchange dimension includes two attributes: exchange number and default exchange number.
[0108] The contract dimension includes two attributes: the contract number and the product number to which the contract belongs.
[0109] Preferably, different attributes within the same dimension are respectively set with different priorities; for example, among the two attributes of the contract dimension of the first index, the priority of the contract number is higher than the priority of the variety number to which the contract belongs.
[0110] A query combination module is configured to load the configuration file when the database program is started, read the index corresponding to each data table in the configuration file, and combine the attributes of each dimension in the index into at least two query combinations, wherein each query combination contains an attribute under each dimension of the corresponding index;
[0111] For example, based on the attributes of each dimension in the first index of the above margin rate table, the following query combination can be generated:
[0112] The first query combination: account number + exchange number + contract number;
[0113] Second query combination: account number + exchange number + contract type number;
[0114] Preferably, after the attributes of each dimension in the index are combined into at least two query combinations, the method may further include: prioritizing each query combination according to the priority of the attribute;
[0115] For example, since the priority of the contract number is higher than the priority of the product number to which the contract belongs among the two attributes of the contract dimension of the first index, the priority of the first query combination is higher than that of the second query combination;
[0116] The present invention can realize that after the database is started, if the user needs to modify the index or add or modify the attributes of the data table, the modification can be achieved by modifying the configuration file. The database will check the configuration information regularly. If any change is found, the index of the change will be changed, and the data will be re-maintained based on the changed index, so that the primary key information, that is, the attribute information, can be dynamically added or modified through the configuration file.
[0117] The sorting module is used to provide the database with the data table selected by the user and the values assigned by the user to each attribute of at least one piece of data in the data table when adding new data. The database saves each piece of data in the order in which it is actually written, and sorts each piece of data according to each index;
[0118] Here, users can select a data table with the following attributes: account number, exchange number, product number, contract number, and specific margin rate. Users can assign values to each attribute in the data table.
[0119] Preferably, users can also assign values to some attributes in the data table, which greatly reduces the amount of data storage and improves index sorting efficiency;
[0120] For example, in the margin rate table above, since most of the contracts under the same product have the same margin rate, only a few individual contracts have special margin rates. Therefore, when setting, not all attributes need to be assigned. Ordinary contracts only need to set the product number, and some special contracts need to set the contract number. That is, you can choose to assign either the contract number or the product number. Specifically, you can set the following two data:
[0121] Ordinary contract: Account number: test, Exchange number: SHFE, Product number: rb, Specific margin rate: 0.2;
[0122] Special contract: Account number: test, Exchange number: SHFE, Contract number: rb2501, Specific margin rate: 0.1.
[0123] The query module is used for the database to obtain the user's query information, which includes the attribute values assigned by the user to each dimension under the index corresponding to the data table to be queried; the database obtains the corresponding query combination based on the attribute assignment, and obtains and outputs the corresponding data in the data table to be queried based on the query combination.
[0124] Preferably, obtaining and outputting corresponding data in the data table to be queried based on the query combination includes:
[0125] The query combination to be queried is sequentially queried from the highest priority query combination to the lowest priority query combination until the corresponding data is found and output; or the query combination based on the lowest priority stops when no data is found.
[0126] Here, when querying, the user needs to specify the data table and the corresponding index information, and assign values to all the attributes contained in the index. The database will query according to the pre-processed query combination sorted by priority. That is, first query the data in the data table according to the query combination with high priority. If the query combination with high priority finds the data, stop searching for data; if no data is found, search for data according to the query combination with lower priority at the next level until the data is found, then stop searching for data, or stop returning empty if the query combination with the lowest priority does not find the data. In this way, different levels of query methods can be set according to the attribute priority for the same data, improving query efficiency and accuracy.
[0127] For example, the first query combination has a higher priority than the second query combination:
[0128] The first query combination: account number + exchange number + contract number;
[0129] The second query combination: account number + exchange number + contract type number.
[0130] For example, there are currently two pieces of data in the data table:
[0131] 1. Account number: test, exchange number: SHFE, contract number: rb2501, specific margin rate: 0.1;
[0132] 2. Account number: test, exchange number: SHFE, product number: rb, specific margin rate: 0.2;
[0133] Among them, rb2501 is a specific contract, rb is the product number, and there are multiple contracts under the rb product number, such as rb2501, rb2502, etc.;
[0134] If the user assigns the following values to the attributes of each dimension under the index corresponding to the selected data table to be queried: Account Number: test, Exchange Number: SHFE, Contract Number: rb2501, Product Number: rb, then according to the first query combination: Account Number + Exchange Number + Contract Number, the margin rate of the first data item can be queried to be 0.1;
[0135] If the user assigns the following values to the attributes of each dimension under the index corresponding to the selected data table to be queried: Account Number: test, Exchange Number: SHFE, Contract Number: rb2502, Product Number: rb, in this case, there is no rb2502 in the above two pieces of data in the database, and the query according to the first query combination with a higher priority will not find any data; then the query can be performed according to the second query combination with a lower priority, and the margin rate in the second piece of data queried is 0.2;
[0136] If the user assigns the following values to the attributes of each dimension under the index corresponding to the selected data table to be queried: Account Number: test, Exchange Number: DCE, Contract Number: a2501, Product Number: a, then both the first query combination with a higher priority and the second query combination with a lower priority will fail to find any data and the query will stop and return empty.
[0137] like Figure 4 As shown, preferably, the above system may also include a configuration modification module for at least one of the following:
[0138] The database obtains the user's modification of the attributes and corresponding indexes contained in the data table, stores the modified attributes in the configuration file, updates the corresponding query combination based on the modified index, and re-sorts each piece of data in the data table based on the modified index;
[0139] The database obtains the user's modification of the index corresponding to the data table, updates the corresponding query combination based on the modified index, and re-sorts each data in the data table based on the modified index.
[0140] Here, after the database is started, if the user needs to modify the index or add or modify the properties of the data table, the modification can be achieved by modifying the configuration file. The database will check the configuration information regularly. If any changes are found, the index of the change will be changed and the data will be re-maintained based on the changed index. In this way, the primary key information, that is, the property information, can be dynamically added or modified through the configuration file.
[0141] Example 3
[0142] Figure 5 This is a schematic diagram of the structure of an electronic device provided in Embodiment 3 of the present disclosure. The electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and the processor implements the data storage and query method provided in Embodiment 1 when executing the program. Figure 5 The electronic device 50 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0143] like Figure 5 As shown, the electronic device 50 may be in the form of a general-purpose computing device, for example, it may be a server device. The components of the electronic device 50 may include, but are not limited to: at least one processor 51, at least one memory 52, and a bus 53 connecting different system components (including the memory 52 and the processor 51).
[0144] The bus 53 includes a data bus, an address bus, and a control bus.
[0145] The memory 52 may include a volatile memory, such as a random access memory (RAM) 521 and / or a cache memory 522 , and may further include a read-only memory (ROM) 523 .
[0146] The memory 52 may also include a program / utility 525 having a set (at least one) of program modules 524, such program modules 524 including but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment.
[0147] The processor 51 executes various functional applications and data processing by running the computer programs stored in the memory 52, such as the data storage and query method provided in Embodiment 1 of the present disclosure.
[0148] The electronic device 50 may also communicate with one or more external devices 54 (e.g., keyboards, pointing devices, etc.). Such communication may be performed via an input / output (I / O) interface 55. Furthermore, the model-generated device 50 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) via a network adapter 56. As shown, the network adapter 56 communicates with other modules of the model-generated device 50 via a bus 53. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the model-generated device 50, including but not limited to: microcode, device drivers, redundant processors, external disk drive arrays, RAID (RAID) systems, tape drives, and data backup storage systems, etc.
[0149] It should be noted that although several units / modules or sub-units / modules of the electronic device are mentioned in the above detailed description, this division is merely exemplary and not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of two or more units / modules described above can be embodied in one unit / module. Conversely, the features and functions of one unit / module described above can be further divided into multiple units / modules to be embodied.
[0150] Example 4
[0151] This embodiment provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the above-mentioned data storage and query method is implemented.
[0152] The readable storage medium may include but is not limited to: a portable disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory, an optical storage device, a magnetic storage device or any suitable combination of the above.
[0153] In a possible implementation manner, the present disclosure may also be implemented in the form of a program product, which includes a program code. When the program product is run on a terminal device, the program code is used to enable the terminal device to execute the data interaction method.
[0154] Among them, the program code for executing the present disclosure can be written in any combination of one or more programming languages, and the program code can be executed completely on the user device, partially on the user device, as an independent software package, partially on the user device and partially on a remote device, or completely on the remote device.
[0155] Although the specific embodiments of the present disclosure are described above, those skilled in the art should understand that this is only an example, and the protection scope of the present disclosure is defined by the appended claims. Those skilled in the art may make various changes or modifications to these embodiments without departing from the principles and essence of the present disclosure, but these changes and modifications all fall within the protection scope of the present disclosure.
Claims
1. A method for storing and querying data, characterized in that: The method comprises: Define the attributes of each data table in the configuration file; Based on the attributes corresponding to each data table, one or more corresponding indexes are set for each data table in the configuration file, wherein each index includes one or more dimensions, and each dimension includes the attributes of one or more data tables; When the database program is started, the configuration file is loaded, the index corresponding to each data table in the configuration file is read, and at least two query combinations are formed based on the attributes of each dimension in the index, wherein each query combination contains an attribute under each dimension of the corresponding index; When adding new data, the database obtains the data table selected by the user and the values assigned by the user to each attribute of at least one piece of data in the data table. The database saves each piece of data in the order in which it is actually written, and sorts each piece of data according to each index; The database obtains the user's query information, which includes the user's attribute assignments for each dimension under the index corresponding to the selected data table to be queried; the database obtains the corresponding query combination based on the attribute assignments, and obtains and outputs the corresponding data in the data table to be queried based on the query combination.
2. The data storage and query method according to claim 1, characterized in that: The database obtains the data table selected by the user and the values assigned by the user to various attributes of at least one piece of data in the data table, including: The database obtains the data table selected by the user and the values assigned by the user to some attributes of at least one piece of data in the data table.
3. The data storage and query method according to claim 1, characterized in that: In the configuration file, one or more corresponding indexes are set for each data table, where each index includes one or more dimensions, and each dimension includes one or more attributes of the data table, including: Different attributes within the same dimension are set with different priorities; Preferably, after the attributes of each dimension in the index are combined into at least two query combinations, the method may further include: prioritizing each query combination according to the priority of the attribute; More preferably, acquiring and outputting corresponding pieces of data in the data table to be queried based on the query combination includes: The query combination to be queried is sequentially queried from the highest priority query combination to the lowest priority query combination until the corresponding data is found and output; or the query combination based on the lowest priority stops when no data is found.
4. The data storage and query method according to claim 1, characterized in that: After the attributes of each dimension in the index are combined into at least two query combinations, at least one of the following items is also included: The database obtains the user's modification of the attributes contained in the data table and the corresponding indexes, stores the modified attributes in the configuration file, updates the corresponding query combination based on the modified index, and re-sorts each piece of data in the data table based on the modified index; The database obtains the modification made by the user to the index corresponding to the data table, updates the corresponding query combination based on the modified index, and re-sorts each piece of data in the data table based on the modified index.
5. A data storage and query system, characterized in that: The system comprises: Configuration attribute module, used to define the attributes contained in each data table in the configuration file; The configuration index module is used to set one or more corresponding indexes for each data table in the configuration file based on the attributes corresponding to each data table, wherein each index includes one or more dimensions, and each dimension includes the attributes of one or more data tables; A query combination module is configured to load the configuration file when the database program is started, read the index corresponding to each data table in the configuration file, and combine the attributes of each dimension in the index into at least two query combinations, wherein each query combination contains an attribute under each dimension of the corresponding index; The sorting module is used to provide the database with the data table selected by the user and the values assigned by the user to each attribute of at least one piece of data in the data table when adding new data. The database saves each piece of data in the order in which it is actually written, and sorts each piece of data according to each index; The query module is used for the database to obtain the user's query information, which includes the attribute values assigned by the user to each dimension under the index corresponding to the data table to be queried; the database obtains the corresponding query combination based on the attribute assignment, and obtains and outputs the corresponding data in the data table to be queried based on the query combination.
6. The data storage and query system according to claim 5, characterized in that: The sorting module is used for the database to obtain the data table selected by the user and the user's assignment of partial attributes to at least one piece of data in the data table; Preferably, the configuration index module is used to set different priorities for different attributes in the same dimension.
7. The data storage and query system according to claim 5, characterized in that: The configuration query combination module is used to prioritize each query combination according to the priority of the attribute; Preferably, the query module is used to query the data table to be queried in sequence from high-priority query combinations to low-priority query combinations, until the corresponding data are found and then stopped and output; or stopped after the query combination based on the lowest priority fails to find data.
8. The data storage and query system according to claim 5, characterized in that: Also included is a configuration modification module for at least one of the following: The database obtains the user's modification of the attributes and corresponding indexes contained in the data table, stores the modified attributes in the configuration file, updates the corresponding query combination based on the modified index, and re-sorts each piece of data in the data table based on the modified index; The database obtains the user's modification of the index corresponding to the data table, updates the corresponding query combination based on the modified index, and re-sorts each data in the data table based on the modified index.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and used to run on the processor, characterized in that: When the processor executes the computer program, the data storage and query method according to any one of claims 1 to 4 is implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the data storage and query method according to any one of claims 1 to 4 is implemented.