Memory table query method and system based on distributed database with decentralized architecture
By using the memory table metadata manager and query status recorder in the non-centralized architecture distributed database, the memory table query is optimized, the problem of low memory table query efficiency is solved, the performance is improved and resource preemption is avoided, and the memory table is realized Consistency with data node memory.
Patent Information
- Application Number
- CN202111579001.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-22
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2041-12-22
AI Technical Summary
In a stand-alone database, the memory table is easily lost because the data is stored in the memory and the performance is degraded when modified frequently, resulting in poor query efficiency. Moreover, the storage structure of different databases results in little improvement in query efficiency.
Using a memory table query method based on a centralized architecture distributed database, by defining a memory table on the database client, creating a memory table metadata manager, managing memory data pull and lock information, real-time monitoring and offloading of queries, and optimizing locks and unlocks operation to avoid concurrent read resource preemption and ensure the consistency between the memory table and the data node memory.
It significantly improves the query performance of frequently used tables, reduces disk consumption, optimizes the performance defects of memory tables in distributed databases, improves user experience, and solves the problem of low query efficiency of memory tables.
Smart Images

Figure CN114238339B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of database query, and in particular to a memory table query method and system based on a decentralized distributed database. Background Art
[0002] A memory table is a data table in memory state in a database. In some stand-alone databases, most memory tables have the following characteristics: data is stored in RAM in an uncompressed form, and data is stored completely in the form obtained when it is read. In other words, reading from this table is very easy because there is no disk read and no need to decompress or deserialize data.
[0003] Memory tables also have some limitations. For example, data is stored in memory, and data will be lost if the database crashes or restarts. Memory tables use table locks. When data is frequently modified, frequent locking and unlocking will lead to performance degradation. Due to the different data structures stored in memory tables of different databases, the efficiency of some queries is not significantly improved.
[0004] How to achieve fast access and fast query of memory tables is a technical problem that needs to be solved. Summary of the invention
[0005] The technical task of the present invention is to address the above shortcomings and provide a memory table query method and system based on a decentralized distributed database to solve the problem of how to achieve fast access and fast query of the memory table.
[0006] In a first aspect, the memory table query method based on a decentralized distributed database of the present invention comprises the following steps:
[0007] Define a memory table on the database client and specify the original database table as a memory-capable state in the CREATE TABLE phase as a memory table.
[0008] Creating a corresponding memory table metadata manager based on the memory table, wherein the memory table metadata manager stores memory table attribute information, wherein the memory table attribute information includes a memory data pull completion flag and lock information of table data corresponding to the memory table;
[0009] If the original table of the database stores table data, the table data in the original table of the database is pulled into the memory of the data node currently operating, and the memory data pulling completion mark of the memory table metadata manager is updated;
[0010] Create and execute a query plan. If the original table of the database is specified as a memory table and the table data of the memory table already exists in the memory of the data node, a query status recorder of the current query is created based on the properties of the metadata manager. The query status recorder is used for real-time status information of the memory table query process, and the current query is divided into a memory table query or a database original query based on the query status recorder. If the original table of the database is an ordinary table, or the original table of the database is specified as a memory table but the table data of the memory table does not exist in the memory of the data node, the current query executes the database original query.
[0011] Preferably, the memory table query includes the following steps:
[0012] Lock, unlock and read memory data in cooperation with the metadata manager and query status recorder;
[0013] Each time a piece of data is read, the real-time status information of the query status recorder is updated. The status includes the column information of the memory table query, query conditions, sorting conditions, data volume, data index, and current query data offset. After the data that meets the query conditions is queried, the query data operation is completed and returned to the database client.
[0014] Preferably, the original table of the database is specified as a memory table, but the table data of the memory table does not exist in the memory of the data node. The current query executes the original query of the database, and pulls the table data in the original table of the database into the memory of the data node of the current operation, and updates the memory data pulling completion flag of the memory table metadata manager.
[0015] Preferably, pulling the table data in the original table of the database into the memory of the data node of the current operation includes the following steps:
[0016] Start an asynchronous task. Based on the task, the data node creates a query plan and executes the query operation, pulls the full data of the memory table, and stores the result set in the memory data structure of the data node.
[0017] If an error occurs during the pull process, the error is reported to the user on the database client and the log is recorded.
[0018] Preferably, when concurrently reading the memory table, the memory table metadata manager is used to lock the memory table query based on the lock information to solve the resource preemption problem caused by concurrently reading the memory table;
[0019] The memory table metadata manager is used to monitor data changes in the original table of the database in real time. When the data in the original table of the database changes, it is used to lock the memory table query based on lock information, and unlock the memory table query after the original table of the database is synchronized with the data node memory data.
[0020] Preferably, a user authority check is performed before creating a memory table metadata manager and creating a query plan.
[0021] In a second aspect, a memory table query system based on a decentralized distributed database of the present invention is used to execute a memory table query method based on a decentralized distributed database as described in any one of the first aspects, and the system includes:
[0022] A memory table creation module, which is used to define a memory table on a database client and to specify an original database table as a memory-capable state as a memory table in the CREATE TABLE phase;
[0023] A memory table metadata manager creation module, wherein the memory table metadata manager creation module is used to create a corresponding memory table metadata manager based on the memory table, wherein the memory table metadata manager stores memory table attribute information, wherein the memory table attribute information includes a memory data pull completion flag and lock information of table data corresponding to the memory table;
[0024] A user checking module, which is used to perform user authority checking on the internal memory table;
[0025] A data pulling module, which acts on the original table of the database storing the table data, and is used to pull the table data in the original table of the database into the memory of the data node currently operating, and update the memory data pulling completion mark of the memory table metadata manager;
[0026] A query module, the query module is used to create and execute a query plan. If the original table of the database is specified as a memory table and the table data of the memory table already exists in the memory of the data node, a query status recorder of the current query is created based on the attributes of the metadata manager. The query status recorder is used for real-time status information of the memory table query process, and the current query is divided into a memory table query or a database original query based on the query status recorder; if the original table of the database is an ordinary table, the current query executes the database original query; if the original table of the database is specified as a memory table but the table data of the memory table does not exist in the memory of the data node, the current query executes the database original query, and pulls the table data in the original table of the database into the memory of the data node of the current operation, and updates the memory data pulling completion mark of the memory table metadata manager.
[0027] Preferably, the query module is used to query the memory table through the following steps:
[0028] Lock, unlock and read memory data in cooperation with the metadata manager and query status recorder;
[0029] Each time a piece of data is read, the real-time status information of the query status recorder is updated. The status includes the column information of the memory table query, query conditions, sorting conditions, data volume, data index, and current query data offset. After the data that meets the query conditions is queried, the query data operation is completed and returned to the database client.
[0030] Preferably, the data pulling module is used to pull the table data in the original table of the database into the memory of the data node of the current operation through the following steps:
[0031] Start an asynchronous task. Based on the task, the data node creates a query plan and executes the query operation, pulls the full data of the memory table, and stores the result set in the memory data structure of the data node.
[0032] If an error occurs during the pull process, the error is reported to the user on the database client and the log is recorded.
[0033] Preferably, when concurrently reading the memory table, the memory table metadata manager is used to lock the memory table query based on the lock information to solve the resource preemption problem caused by concurrently reading the memory table;
[0034] The memory table metadata manager is used to monitor data changes in the original table of the database in real time. When the data in the original table of the database changes, it is used to lock the memory table query based on lock information, and unlock the memory table query after the original table of the database is synchronized with the data node memory data.
[0035] The memory table query method and system based on a decentralized distributed database of the present invention have the following advantages:
[0036] 1. While being compatible with the original query syntax of the database, it significantly improves the query performance of frequently used tables, rationally uses the server memory, which is no longer a performance bottleneck, reduces disk loss, improves the defects of memory tables in the field of decentralized distributed databases, optimizes performance, improves user experience, and achieves the expected purpose;
[0037] 2. Lock information is recorded in the memory table metadata manager. When the memory table is read concurrently, the query of the memory table can be locked through the lock information, thereby avoiding the problem of resource preemption caused by concurrent reading;
[0038] 3. The memory table metadata manager can monitor the changes of data in the original table of the database in real time. When the data in the original table of the database changes, the memory table query is locked based on the lock information. After the data in the original table of the database is synchronized with the data node memory, the internal table query is unlocked, thereby maintaining the consistency of the memory table and the data node memory. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0040] The present invention is further described below in conjunction with the accompanying drawings.
[0041] Figure 1 This is a flowchart of a memory table query method based on a decentralized distributed database in Example 1;
[0042] Figure 2 A flowchart of creating a memory table in a memory table query method based on a decentralized distributed database in Example 1;
[0043] Figure 3 This is a flowchart of querying memory table data in the memory table query method based on a decentralized distributed database in Example 1. DETAILED DESCRIPTION
[0044] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it. However, the embodiments are not intended to limit the present invention. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments may be combined with each other.
[0045] The embodiments of the present invention provide a memory table query method and system based on a decentralized distributed database, which are used to solve the technical problem of how to achieve fast access and fast query of the memory table.
[0046] Embodiment 1:
[0047] The present invention is based on a memory table query method of a distributed database with a decentralized architecture, comprising the following steps:
[0048] S100, define a memory table on the database client, and specify the original database table as a memory-enabled state in the CREATE TABLE phase as a memory table;
[0049] S200: Create a corresponding memory table metadata manager based on the memory table, where the memory table metadata manager stores memory table attribute information, including a memory data pull completion flag and lock information of table data corresponding to the memory table;
[0050] S300: If table data is stored in the original table of the database, the table data in the original table of the database is pulled into the memory of the data node currently operating, and the memory data pulling completion flag of the memory table metadata manager is updated;
[0051] S400. Create and execute a query plan. If the original table of the database is specified as a memory table and the table data of the memory table already exists in the memory of the data node, a query status recorder of the current query is created based on the properties of the metadata manager, and the current query is divided into a memory table query or a database original query based on the query status recorder; if the original table of the database is a common table, or the original table of the database is specified as a memory table but the table data of the memory table does not exist in the memory of the data node, the current query executes the database original query.
[0052] When defining the memory table in step S100, a new database original table may be designated as the memory table in the CREATE TABLE stage, or an original database table storing data may be represented as a table in memory state as the memory table.
[0053] In step S200, a memory table metadata manager is created, which records other table attributes such as the column information, primary key information, lock information, and memory data pull completion flag of the memory table. When the memory table is read concurrently, the memory table metadata manager locks the memory table query based on the lock information to avoid the problem of resource preemption caused by concurrent reading of the memory table. The memory table metadata manager monitors the original table of the database in real time. When the data in the original table of the database changes, the memory table query is locked based on the lock information, and the memory table query is unlocked after the original table of the database is synchronized with the memory data of the data node to ensure consistency as much as possible.
[0054] In step S300, after the metadata manager is created, if the table already exists, then the data in the current table is pulled into the memory of the data node. The structure in the metadata manager and the storage structure of the table data are determined by the different distributed database codes themselves. The process of pulling data is to start a new asynchronous task, build a query plan within the task, execute the query plan, pull the full amount of data, store the result set in the memory table data structure, and update the memory data pulling completion flag of the memory table metadata manager to indicate that the data pulling is complete. If an error occurs in the process, it will be reported to the operating user in the Client and the log will be recorded. Each node of the decentralized distributed database can accept user connection requests, create query plans, and execute query operations. When the node is not a user-created or modified memory table instruction node, or when the node is restarted due to a failure, the memory table data in the memory of the node is lost. The solution will be given in the following query steps.
[0055] If the process of pulling the data in the current table to the memory of the data node fails, the memory table metadata manager is destroyed.
[0056] Step S400 creates a query plan, detects whether the table is a memory table, and if it is not a memory table, executes the original query process of the database, and the query ends; if it is a memory table, reads the memory table metadata manager, and continues to detect whether the node has completed the pulling of the memory table data in the memory. If the memory data has been pulled, a query status recorder for this query is created according to the attributes of the metadata manager. The query status recorder is used for the real-time status information of the memory table query process. With the assistance of the query status recorder, the query is divided into a memory query or an original storage query. If it is a memory query, the memory data is locked, unlocked, and read with the help of the metadata manager and the query status recorder. At the same time, the real-time status information of the query status recorder is updated every time a piece of data is read until the data that meets the query conditions is queried, the query data operation is completed and returned to the client; if there is no memory table data in the memory (the data node is down, restarted, or the node is querying the memory table for the first time), then this query still executes the original query process of the database. At the same time, the same asynchronous task as in step 3 is started in the background to pull data. After the data is pulled, the memory data pulling completion flag of the memory table metadata manager is updated to indicate that the data pulling is completed so that the next query can be performed in memory.
[0057] Among them, the query status recorder is used to record real-time status information such as the query column information, query conditions, sorting conditions, data volume, data index, and data offset of the query during the query process of the memory table. Based on these attributes, it is determined whether the query should be performed as a memory query or the original query process to assist in the completion of the query.
[0058] In this embodiment, before creating a memory table metadata manager and creating a query plan, a user authority check is performed on the memory table, and the query plan is executed only after the check passes.
[0059] The method in this embodiment supports memory table syntax, that is, supports specifying a memory table when creating a table, and supports specifying an existing table as a memory table.
[0060] The method of this embodiment supports multi-node memory tables. When a table is converted to a memory table, data is only pulled into the memory of the current node, not all nodes at the same time. If it is a large cluster, the query pressure inside the cluster will increase instantly. Instead, a node will pull data from the memory when it receives a user query request. And when the data of the original table corresponding to the memory table changes, it can be updated in real time through the detection of the metadata manager to ensure consistency.
[0061] The method of this embodiment supports re-pulling memory data after a node crashes or restarts: if a node crashes or restarts and memory data is lost, when the memory table data is queried again, it will be processed according to the situation in (2), assuming that the node is querying the memory table for the first time, and restarting the asynchronous task to pull data into the memory.
[0062] The method of this embodiment supports automatic optimization of memory table query efficiency: according to different attributes in the query status recorder, the query statement is optimized to determine whether to perform memory query or original storage query, thereby saving database query resource consumption.
[0063] After the method of this embodiment is set as a memory table, the efficiency of specific queries is greatly improved.
[0064] Embodiment 2:
[0065] The present invention is based on a memory table query system of a distributed database with a decentralized architecture, comprising a memory table creation module, a memory table metadata manager creation module, a user checking module, a data pulling module, and a query module. The memory table creation module is used to define a memory table on a database client, and in the CREATE TABLE stage, the database original table is designated as a memory-enabled state as a memory table; the memory table metadata manager creation module is used to create a corresponding memory table metadata manager based on the memory table, and the memory table metadata manager stores memory table attribute information, and the memory table attribute information includes a memory data pulling completion mark and lock information of table data corresponding to the memory table; the user checking module is used to perform user authority checks on the internal memory table; the data pulling module acts on the database original table storing table data, and is used to pull the table data in the database original table into the memory of the data node currently being operated, and update the memory data pulling completion mark of the memory table metadata manager; the query module is used to create and execute a query plan, and if the database original table stores table data, the memory table metadata manager stores the memory table attribute information, and ... If the table is specified as a memory table and the table data of the memory table already exists in the data node memory, a query status recorder for the current query is created based on the attributes of the metadata manager. The query status recorder is used for real-time status information of the memory table query process, and the current query is diverted into a memory table query or a database original query based on the query status recorder; if the database original table is an ordinary table, the current query executes the database original query; if the database original table is specified as a memory table but the table data of the memory table does not exist in the data node memory, the current query executes the database original query, and pulls the table data in the database original table into the data node memory of the current operation, and updates the memory data pulling completion flag of the memory table metadata manager.
[0066] The memory table metadata manager records the memory table's column information, primary key information, lock information, and other table attributes such as the memory data pull completion flag. When the memory table is read concurrently, the memory table metadata manager locks the memory table query based on the lock information to avoid resource preemption caused by concurrent reading of the memory table. The memory table metadata manager monitors the database original table in real time. When the data in the database original table changes, the memory table query is locked based on the lock information, and the memory table query is unlocked after the database original table is synchronized with the data node memory data to ensure consistency as much as possible.
[0067] Among them, the query module is used to query the memory table through the following steps: lock, unlock and read the memory data with the cooperation of the metadata manager and the query status recorder; update the real-time status information of the query status recorder after reading each piece of data. The status includes the column information, query conditions, sorting conditions, data volume, data index, and current query data offset of the memory table query, until the data that meets the query conditions is queried. After the query data operation is completed, it is returned to the database client.
[0068] The data pulling module is used to pull the table data in the original table of the database into the memory of the data node currently operating through the following steps: start an asynchronous task, based on which the data node creates a query plan and executes the query operation, pulls the full amount of data in the memory table, and stores the result set in the memory data structure of the data node; if an error occurs during the pulling process, the database client reports the error to the user and records the log. If the process of pulling the data in the current table into the memory of the data node fails, the memory table metadata manager is destroyed.
[0069] The query module is used to perform the following operations: detect whether the table is a memory table. If it is not a memory table, execute the original query process of the database and the query ends; if it is a memory table, read the memory table metadata manager and continue to detect whether the node has completed the pulling of the memory table data in the memory. If the memory data has been pulled, create a query status recorder for this query according to the properties of the metadata manager. The query status recorder is used for the real-time status information of the memory table query process. With the assistance of the query status recorder, the query is divided into a memory query or an original storage query. If it is a memory query, the memory data is locked, unlocked, and read with the help of the metadata manager and the query status recorder. At the same time, the real-time status information of the query status recorder is updated every time a piece of data is read until the data that meets the query conditions is queried, the query data operation is completed and returned to the client; if there is no memory table data in the memory (the data node is down, restarted, or the node is querying the memory table for the first time), then this query still executes the original query process of the database. At the same time, the same asynchronous task as in step 3 is started in the background to pull data. After the data is pulled, the memory data pulling completion flag of the memory table metadata manager is updated to indicate that the data pulling is completed so that the next query can be performed in memory.
[0070] The memory table query system of the distributed database based on the decentralized architecture in this embodiment can execute the method disclosed in Example 1.
[0071] The present invention is shown and described in detail above through the accompanying drawings and preferred embodiments. However, the present invention is not limited to these disclosed embodiments. Based on the above multiple embodiments, those skilled in the art can know that the code review methods in the above different embodiments can be combined to obtain more embodiments of the present invention, and these embodiments are also within the protection scope of the present invention.
Claims
1. A memory table query method based on a distributed database with a decentralized architecture, characterized in that The steps include: Define a memory table on the database client and specify the original database table as a memory-capable state in the CREATE TABLE phase as a memory table. Creating a corresponding memory table metadata manager based on the memory table, wherein the memory table metadata manager stores memory table attribute information, wherein the memory table attribute information includes a memory data pull completion flag and lock information of table data corresponding to the memory table; If the original table of the database stores table data, the table data in the original table of the database is pulled into the memory of the data node currently operating, and the memory data pulling completion mark of the memory table metadata manager is updated; Create and execute a query plan. If the original table of the database is specified as a memory table and the table data of the memory table already exists in the memory of the data node, a query status recorder of the current query is created based on the properties of the metadata manager. The query status recorder is used for real-time status information of the memory table query process, and the current query is divided into a memory table query or a database original query based on the query status recorder. If the original table of the database is an ordinary table, or the original table of the database is specified as a memory table but the table data of the memory table does not exist in the memory of the data node, the current query executes the database original query.
2. The memory table query method based on a decentralized distributed database according to claim 1 is characterized in that Memory table query includes the following steps: Lock, unlock and read memory data in cooperation with the metadata manager and query status recorder; Each time a piece of data is read, the real-time status information of the query status recorder is updated. The status includes the column information of the memory table query, query conditions, sorting conditions, data volume, data index, and current query data offset. After the data that meets the query conditions is queried, the query data operation is completed and returned to the database client.
3. The memory table query method based on a decentralized distributed database according to claim 1 is characterized in that The original table of the database is specified as a memory table, but the table data of the memory table does not exist in the memory of the data node. The current query executes the original query of the database, pulls the table data in the original table of the database into the memory of the data node of the current operation, and updates the memory data pulling completion flag of the memory table metadata manager.
4. The memory table query method based on a decentralized distributed database according to any one of claims 1 to 3, characterized in that Pulling the table data from the original table of the database into the memory of the data node of the current operation includes the following steps: Start an asynchronous task. Based on the task, the data node creates a query plan and executes the query operation, pulls the full data of the memory table, and stores the result set in the memory data structure of the data node. If an error occurs during the pull process, the error is reported to the user on the database client and the log is recorded.
5. The memory table query method based on a decentralized distributed database according to claim 1 is characterized in that When concurrently reading the memory table, the memory table metadata manager is used to lock the memory table query based on the lock information to solve the resource preemption problem caused by concurrent reading of the memory table; The memory table metadata manager is used to monitor data changes in the original table of the database in real time. When the data in the original table of the database changes, it is used to lock the memory table query based on lock information, and unlock the memory table query after the original table of the database is synchronized with the data node memory data.
6. The memory table query method based on a decentralized distributed database according to claim 1, 2, 3 or 5, characterized in that Before creating a memory table metadata manager and a query plan, check the user permissions.
7. A memory table query system based on a decentralized distributed database, characterized by The system is used to execute the memory table query method based on a decentralized distributed database according to any one of claims 1 to 6, the system comprising: A memory table creation module, which is used to define a memory table on a database client and to specify an original database table as a memory-capable state as a memory table in a CREATE TABLE phase; A memory table metadata manager creation module, wherein the memory table metadata manager creation module is used to create a corresponding memory table metadata manager based on the memory table, wherein the memory table metadata manager stores memory table attribute information, wherein the memory table attribute information includes a memory data pull completion flag and lock information of table data corresponding to the memory table; A user checking module, which is used to perform user authority checking on the internal memory table; A data pulling module, which acts on the original table of the database storing the table data, and is used to pull the table data in the original table of the database into the memory of the data node currently operating, and update the memory data pulling completion mark of the memory table metadata manager; A query module, the query module is used to create and execute a query plan. If the original table of the database is specified as a memory table and the table data of the memory table already exists in the memory of the data node, a query status recorder of the current query is created based on the attributes of the metadata manager. The query status recorder is used for real-time status information of the memory table query process, and the current query is divided into a memory table query or a database original query based on the query status recorder; if the original table of the database is an ordinary table, the current query executes the database original query; if the original table of the database is specified as a memory table but the table data of the memory table does not exist in the memory of the data node, the current query executes the database original query, and pulls the table data in the original table of the database into the memory of the data node of the current operation, and updates the memory data pulling completion mark of the memory table metadata manager.
8. The memory table query system based on a decentralized distributed database according to claim 7 is characterized in that The query module is used to query the memory table through the following steps: Lock, unlock and read memory data in cooperation with the metadata manager and query status recorder; Each time a piece of data is read, the real-time status information of the query status recorder is updated. The status includes the column information of the memory table query, query conditions, sorting conditions, data volume, data index, and current query data offset. After the data that meets the query conditions is queried, the query data operation is completed and returned to the database client.
9. The memory table query system based on a decentralized distributed database according to claim 7 or 8, characterized in that The data pulling module is used to pull the table data in the original table of the database into the memory of the data node of the current operation through the following steps: Start an asynchronous task. Based on the task, the data node creates a query plan and executes the query operation, pulls the full data of the memory table, and stores the result set in the memory data structure of the data node. If an error occurs during the pull process, the error is reported to the user on the database client and the log is recorded.
10. The memory table query system based on a decentralized distributed database according to claim 7 is characterized in that When concurrently reading the memory table, the memory table metadata manager is used to lock the memory table query based on the lock information to solve the resource preemption problem caused by concurrent reading of the memory table; The memory table metadata manager is used to monitor data changes in the original table of the database in real time. When the data in the original table of the database changes, it is used to lock the memory table query based on lock information, and unlock the memory table query after the original table of the database is synchronized with the data node memory data.
Citation Information
Patent Citations
Metadata-based information resource distributed query method
CN108108456A
Database query method and system
CN112783927A
