Data query methods, devices, equipment and media
By obtaining the target table object set and the number of global truncations, and combining the index control page and transaction ID information, the problem of inaccurate query results caused by concurrent execution of query statements and TRUNCATE statements in data queries was solved, thus improving both flexibility and accuracy.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-03
- Publication Date
- 2026-03-10
Smart Images

Figure CN116955394B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of database technology, and in particular to data query methods, apparatus, devices and media. Background Technology
[0002] When performing data queries, since the result set of the query statement is large, the results need to be returned to the client in batches. At this time, the query statement may be executed concurrently with the TRUNCATE statement.
[0003] The current concurrent execution scheme stores the corresponding data version number for each table object. When the TRUNCATE statement is executed, each sub-table of the partitioned table maintains its own data version number. The query statement can then distinguish whether a concurrent TRUNCATE operation has occurred by comparing the data version number before the query execution with the latest data version number.
[0004] When a partitioned table has many sub-tables, maintaining the version numbers of all sub-tables can degrade the performance of the TRUNCATE statement. Furthermore, when a query involves multiple partitioned sub-tables, concurrent execution of queries and TRUNCATE statements on these sub-tables may result in unexpected outcomes. For example, if a query can retrieve the first partitioned sub-table, but the TRUNCATE statement truncates all sub-tables after that query, subsequent queries on those sub-tables may return empty results, which is not what is expected. Summary of the Invention
[0005] This invention provides a data query method, apparatus, device, and medium to enable concurrent execution of query statements and truncation statements.
[0006] According to a first aspect of the present invention, a data query method is provided, comprising:
[0007] Obtain the query statement used for data querying, and determine the target table object set corresponding to the query statement and the global truncation number of the target database in the corresponding target database;
[0008] Based on the target table object set and the corresponding index control pages, determine the target transaction ID information and the number of partial truncations for each target table object;
[0009] The query result corresponding to the query statement is determined based on the global truncation count, the target transaction ID information, and the local truncation count.
[0010] According to a second aspect of the present invention, a data query apparatus is provided, comprising:
[0011] The first determining module is used to obtain the query statement for data querying, and determine the target table object set corresponding to the query statement and the global truncation number of the target database in the corresponding target database.
[0012] The second determining module is used to determine the target transaction ID information and the number of partial truncations corresponding to each target table object based on the target table object set and the corresponding index control pages.
[0013] The third determining module is used to determine the query result corresponding to the query statement based on the global truncation count, the target transaction ID information, and the local truncation count.
[0014] According to a third aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0015] At least one processor; and
[0016] A memory communicatively connected to the at least one processor; wherein,
[0017] The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the data query method according to any embodiment of the present invention.
[0018] According to a fourth aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the data query method described in any embodiment of the present invention.
[0019] The technical solution of this invention obtains the query statement used for data querying, determines the target table object set corresponding to the query statement and the global truncation count of the target database in the corresponding target database; determines the target transaction ID information and local truncation count for each target table object based on the target table object set and the corresponding index control pages; and determines the query result corresponding to the query statement based on the global truncation count, the target transaction ID information, and the local truncation count. For concurrent query statements, visibility is judged by the global truncation count, the local truncation count, and the target transaction ID information of each target table object, thereby determining the query result. This ensures the flexibility of processing each target table object individually when truncation statements and query statements are concurrent, as well as the accuracy of the query results.
[0020] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0021] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0022] Figure 1 This is a flowchart of a data query method provided according to Embodiment 1 of the present invention;
[0023] Figure 2 This is a flowchart of a data query method provided according to Embodiment 2 of the present invention;
[0024] Figure 3 This is a schematic diagram of the structure of a data query device according to Embodiment 3 of the present invention;
[0025] Figure 4 This is a schematic diagram of the structure of an electronic device that implements an embodiment of the present invention. Detailed Implementation
[0026] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0027] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0028] Example 1
[0029] Figure 1This is a flowchart of a data query method provided in Embodiment 1 of the present invention. This embodiment is applicable to situations where query statements and truncation statements are executed concurrently. The method can be executed by a data query device, which can be implemented in hardware and / or software and can be configured in an electronic device. Figure 1 As shown, the method includes:
[0030] S110. Obtain the query statement used for data querying, and determine the target table object set corresponding to the query statement and the global truncation count of the target database in the corresponding target database.
[0031] It's important to know that when a query returns a large number of results, the results need to be returned to the client in batches. In this case, the query and truncation statements can be executed concurrently. This is because the query may temporarily release IS locks on tables in the target set when returning a batch of results, and then re-impose IS locks on the tables when retrieving the next batch of results. The truncation statement can then apply X locks to the tables during this interval. Therefore, the query and truncation statements can be executed concurrently without causing conflicts.
[0032] In this embodiment, a query statement can be understood as a statement that queries a table for all records that meet certain conditions and returns the results to the client. The target database can be understood as the database containing the table that the query statement needs to query. The target table object set can be understood as the set of tables that the query statement needs to query. If the query statement needs to query a partitioned table, then the partitioned sub-tables that meet the query conditions are added to the table set. The global truncation count can be understood as the memory value of a global variable, initialized to 0 when the target database starts, and recording the number of times truncation statements are executed in the target database. A partitioned sub-table can be understood as a sub-table of a partitioned table.
[0033] Specifically, the processor can obtain the query statement sent by the client for data querying. Based on the query statement, the processor can determine the target database and the target table object set corresponding to the query statement in the corresponding target database. The processor can also obtain the global truncation count in the form of memory value of the target database.
[0034] S120. Based on the target table object set and the corresponding index control pages, determine the target transaction ID information and the number of partial truncations for each target table object.
[0035] In this embodiment, the index control page can be understood as a data page that maintains and manages index information (such as the number of clusters used by the index, the rowid of the index, etc.), and each index has a corresponding control page. The target transaction ID information can be understood as the transaction ID information recorded in the index control page, which can be in byte format. The partial truncation count can be understood as the number of truncations for each target table object for the current query statement.
[0036] Specifically, the processor can determine the target transaction ID information and the number of partial truncations for each target table object in the target table object set based on the target table object set and the corresponding index control pages.
[0037] S130. Determine the query result corresponding to the query statement based on the global truncation count, the target transaction ID information, and the local truncation count.
[0038] In this embodiment, the query result can be understood as the result of the data query corresponding to the query statement.
[0039] Specifically, when retrieving data from each target table object, the processor can compare the global truncation count with the local truncation count, and determine the transaction visibility based on the target transaction ID information registered in each index control page, thereby determining whether data can continue to be retrieved, and thus obtaining the query results corresponding to the query statement.
[0040] The technical solution of this invention obtains the query statement used for data querying, determines the target table object set corresponding to the query statement and the global truncation count of the target database in the corresponding target database; determines the target transaction ID information and local truncation count for each target table object based on the target table object set and the corresponding index control pages; and determines the query result corresponding to the query statement based on the global truncation count, the target transaction ID information, and the local truncation count. For concurrent query statements, visibility is judged by the global truncation count, the local truncation count, and the target transaction ID information of each target table object, thereby determining the query result. This ensures the flexibility of processing each target table object individually when truncation statements and query statements are concurrent, as well as the accuracy of the query results.
[0041] As a first optional embodiment of this embodiment, based on the above embodiment, it further includes:
[0042] When the data truncation condition is met, the processing result is determined based on the truncation statement obtained for data truncation.
[0043] In this embodiment, the data truncation condition can be understood as the query statement releasing the lock on the table object. The truncation statement can be understood as deleting all records on the table object while preserving the table structure and its index information; a TRUNCATE statement is preferred. The processing result can be understood as the processing result corresponding to the truncation statement, which may include the truncated database and each index control page.
[0044] Specifically, when the data truncation conditions are met, the processor can perform truncation processing on the target database corresponding to the truncation statement based on the obtained truncation statement, and determine the processing result.
[0045] Furthermore, based on the above embodiments, the step of determining the processing result according to the obtained truncation statement used for data truncation can be further optimized to include:
[0046] a1. Based on the truncation statement, determine the set of objects to be truncated, the current index control page corresponding to each object to be truncated, and the historical global truncation count of the target database in the corresponding target database. The set of objects to be truncated includes at least one object to be truncated.
[0047] In this embodiment, the target database can be understood as the database corresponding to the truncation statement. The set of objects to be truncated can be understood as the collection of table objects that need to be truncated. The current index control page can be understood as the index control page before the truncation operation. The historical global truncation count can be understood as the number of global truncations before the truncation operation. The objects to be truncated can be understood as the table objects that need to be truncated.
[0048] Specifically, the processor can determine the target database for which truncation operation needs to be performed based on the truncation statement, and determine the set of objects to be truncated, the current index control page corresponding to each object to be truncated, and the historical global truncation count of the target database in the corresponding target database. The set of objects to be truncated includes at least one object to be truncated.
[0049] b1. Perform truncation processing on the set of objects to be truncated according to the truncation statement to obtain the final database.
[0050] In this embodiment, the final database can be understood as the database after truncation.
[0051] Specifically, the processor can truncate the set of objects to be truncated according to the truncation statement to obtain the final database.
[0052] c1. Based on the truncation statement, determine the current transaction ID and register it in each current index control page, and determine the index control page set.
[0053] In this embodiment, the index control page set can be understood as the set of current index control pages that have been modified.
[0054] Specifically, the processor can determine the current transaction ID corresponding to the truncation operation based on the truncation statement, register the current transaction ID in each current index control page, and use the set of each current index control page as the index control page set.
[0055] d1. Update the historical global truncation count to obtain the current global truncation count.
[0056] In this embodiment, the current global truncation count can be understood as the global truncation count after the truncation operation has been performed.
[0057] Specifically, after the truncation operation, the processor can update the historical global truncation count, such as by increasing the historical global truncation count (by adding one to the original count) to obtain the current global truncation count.
[0058] e1. The final database, index control page set, and current global truncation count are used as the processing result.
[0059] In the first optional embodiment of this embodiment, since the truncation operation will maintain the index information on the table, the operation of recording the current transaction ID on the index control page will not cause performance problems, and the performance will not decrease even when there are many partitioned sub-tables.
[0060] Example 2
[0061] Figure 2 This is a flowchart of a data query method provided in Embodiment 2 of the present invention. This embodiment is a further refinement based on the above embodiments. Figure 2 As shown, the method includes:
[0062] S210. Obtain the query statement used for data querying, and determine the target table object set corresponding to the query statement and the global truncation count of the target database in the corresponding target database.
[0063] S220. For each target table object included in the target table object set, determine the index control page corresponding to the target table object.
[0064] Specifically, for each target table object included in the target table object set, the processor can sequentially determine the index control page corresponding to each target table object.
[0065] S230. Determine the target transaction ID information corresponding to the target table object in the index control page.
[0066] Specifically, the processor can determine the transaction ID information corresponding to the target table object from the data row containing the transaction ID information in the index control page.
[0067] S240. Determine whether the query statement is accessing the target table object for the first time.
[0068] Specifically, the processor can determine whether the query statement is accessing the target table object for the first time based on the cache information when executing the current query statement.
[0069] S250. If so, initialize the number of local truncations.
[0070] Specifically, if the query statement accesses the target table object for the first time, a partial truncation count can be initialized and set to zero.
[0071] S260. If not, directly obtain the number of local truncations.
[0072] Specifically, if the query statement is not accessing the target table object for the first time, the existing partial truncation count can be obtained directly.
[0073] S270. Based on the global truncation count, the target transaction ID information, and the local truncation count, determine the subquery results corresponding to each target table object and form a subquery result set.
[0074] In this embodiment, the subquery result can be understood as the query result for each target table object. The subquery result set can be understood as a collection of multiple subquery results, that is, the collection of subquery results corresponding to all target table objects in the target table object set.
[0075] Specifically, the processor can sequentially compare the global truncation count with the local truncation count of each target table object, combine the target transaction ID information to determine transaction visibility, determine whether the query statement can obtain data in each target table object, and then determine the subquery result. The subquery result set is formed by combining the subquery results of each target table object in the target table object set corresponding to the query statement.
[0076] Furthermore, based on the above embodiments, the step of determining the subquery results corresponding to each target table object and forming a subquery result set according to the global truncation count, the target transaction ID information, and the local truncation count may include:
[0077] a2. For each local truncation count, determine whether the local truncation count is the same as the global truncation count.
[0078] Specifically, for each local truncation count, the processor can determine whether the local truncation count is the same as the global truncation count.
[0079] b2. If so, then determine that the corresponding subquery result is allowed to retrieve data.
[0080] Specifically, if the number of local truncations is the same as the number of global truncations, then the subquery result corresponding to the target table object can be determined as allowing data retrieval.
[0081] c2. If not, then based on the target transaction ID information, perform a transaction visibility judgment on the corresponding target table object to determine the corresponding subquery result.
[0082] In this embodiment, transaction visibility can be understood as whether a statement C in transaction B is allowed to see the modifications made by transaction A.
[0083] Specifically, if the number of local truncations differs from the number of global truncations, the processor can determine the transaction visibility of the corresponding target table object based on the target transaction ID information, and then determine the corresponding subquery result.
[0084] The step of determining the transaction visibility of the corresponding target table object based on the target transaction ID information and determining the corresponding subquery result may include:
[0085] c21. Determine the transaction information corresponding to the transaction ID information.
[0086] In this embodiment, transaction information can be understood as a program execution logic unit consisting of operations that access and update system data.
[0087] Specifically, the processor can determine the corresponding transaction information based on the transaction ID information.
[0088] c22. Determine whether transaction information is visible to the query statement.
[0089] Specifically, users can pre-set the transaction isolation level in the transaction information, and the processor can determine whether the transaction information is visible to the query statement.
[0090] For example, transaction visibility determination is related to the transaction isolation level. The DM database currently supports three transaction isolation levels: Read Uncommitted, Read Committed, and Serializable. Taking Read Committed as an example, statement C is only allowed to see the modifications made by transaction A if transaction A has been fully executed and committed before statement C begins execution; otherwise, transaction A is not visible to statement C. In the scenario discussed in this patent, transaction A is the transaction corresponding to the truncated statement, and statement C is the query statement. When the transaction corresponding to the truncated statement is visible to the query statement, it means that the transaction corresponding to the truncated statement has been completed before the query statement begins execution, thus allowing the query statement to retrieve data. The visibility determination methods for different transaction isolation levels are different. The database has a dedicated module for determining transaction visibility based on the transaction isolation level set by the user. This method is irrelevant to the content of this patent and will not be elaborated here.
[0091] c23. If yes, then determine that the subquery result is allowed to retrieve data, and update the local truncation count based on the global truncation count.
[0092] Specifically, if it is determined that the transaction information is visible to the query statement, then the subquery result is determined to be allowed to retrieve data, and the local truncation count is updated according to the global truncation count. For example, the local truncation count corresponding to the subquery result can be set as the global truncation count.
[0093] c24. If not, then the subquery result is determined to be data that cannot be retrieved.
[0094] Specifically, if it is determined that the transaction information is not visible to the query statement, then the subquery result is determined to be data that cannot be retrieved.
[0095] d2. Based on the results of each subquery, form a subquery result set.
[0096] Specifically, the processor can use the results of each subquery as a subquery result set.
[0097] S280. When all subquery results in the subquery result set are allowed to retrieve data, retrieve the target sub-data corresponding to each subquery result, and determine the query result based on each target sub-data.
[0098] In this embodiment, target sub-data can be understood as the data in the target table object corresponding to the subquery result.
[0099] Specifically, the processor can sequentially poll the results of each subquery in the subquery result set. When all the results of each subquery in the subquery result set are data that can be retrieved, the processor can retrieve the target sub-data corresponding to each subquery result and calculate the query result based on each target sub-data.
[0100] S290. When the result set of a subquery includes any subquery result that is not allowed to retrieve data, report a statement error for the query statement.
[0101] Specifically, the processor can sequentially poll the results of each subquery in the subquery result set. If any subquery result in the subquery result set is not allowed to retrieve data, then further data retrieval is not allowed, and a statement error is reported for the query statement.
[0102] This second embodiment provides a data query method that utilizes the target transaction ID information corresponding to the target table object to check whether a truncation statement has been executed concurrently, improving the flexibility of the check. By using the global truncation count and the local truncation count, the subquery result is first determined. When the two are inconsistent, transaction visibility is judged based on the target transaction ID. The transaction visibility judgment result remains consistent throughout the execution of a single query statement. For truncation operations on partitioned tables, even if multiple partitioned sub-tables are involved, the transaction IDs in the index control pages of the involved sub-tables are consistent. These two points ensure that regardless of how the specific query order for the partitioned sub-tables is adjusted during the execution of the query statement, the check for the truncation operation of the query statement remains consistent, avoiding situations where the query result is not as expected. Then, based on the results of each subquery, the query result corresponding to the query statement is determined. This ensures the flexibility of processing each target table object individually when truncation statements and query statements are executed concurrently, as well as the accuracy of the query results.
[0103] Example 3
[0104] Figure 3 This is a schematic diagram of a data query device provided in Embodiment 3 of the present invention. Figure 3 As shown, the device includes: a first determining module 41, a second determining module 42, and a third determining module 43. Among them,
[0105] The first determining module 41 is used to obtain a query statement for data querying, and to determine the target table object set corresponding to the query statement and the global truncation number of the target database in the corresponding target database.
[0106] The second determining module 42 is used to determine the target transaction ID information and the number of partial truncations corresponding to each target table object based on the target table object set and the corresponding index control pages.
[0107] The third determining module 43 is used to determine the query result corresponding to the query statement based on the global truncation count, the target transaction ID information, and the local truncation count.
[0108] The technical solution of this invention obtains the query statement used for data querying, determines the target table object set corresponding to the query statement and the global truncation count of the target database in the corresponding target database; determines the target transaction ID information and local truncation count for each target table object based on the target table object set and the corresponding index control pages; and determines the query result corresponding to the query statement based on the global truncation count, the target transaction ID information, and the local truncation count. For concurrent query statements, visibility is judged by the global truncation count, the local truncation count, and the target transaction ID information of each target table object, thereby determining the query result. This ensures the flexibility of processing each target table object individually when truncation statements and query statements are concurrent, as well as the accuracy of the query results.
[0109] Furthermore, the second determining module 42 is specifically used for:
[0110] For each target table object included in the target table object set, determine the index control page corresponding to the target table object;
[0111] The target transaction ID information corresponding to the target table object is determined in the index control page;
[0112] If the query statement corresponds to the first access to the target table object, then the number of partial truncations is initialized.
[0113] Otherwise, directly obtain the number of local truncations.
[0114] Optionally, the third determining module 43 includes:
[0115] The first determining unit is used to determine the subquery results corresponding to each target table object based on the global truncation count, the target transaction ID information, and the local truncation count, and form a subquery result set;
[0116] The second determining unit is configured to, when all the sub-query results in the sub-query result set are allowed to obtain data, obtain the target sub-data corresponding to each sub-query result, and determine the query result based on each target sub-data;
[0117] The third determining unit is used to report an error to the query statement when any of the subquery results in the subquery result set is a subquery result that is not allowed to retrieve data.
[0118] Furthermore, the first determining unit includes:
[0119] The determination subunit is used to determine, for each local truncation count, whether the local truncation count is the same as the global truncation count;
[0120] The first determining sub-unit is used to determine that if the result is yes, the corresponding subquery result is allowed to retrieve data.
[0121] The second determining subunit is used to determine the transaction visibility of the corresponding target table object based on the target transaction ID information if no, and to determine the corresponding subquery result.
[0122] Forming sub-units, used to form the sub-query result set based on the results of each sub-query.
[0123] Specifically, the second determining subunit is used for:
[0124] Determine the transaction information corresponding to the transaction ID information;
[0125] Determine whether the transaction information is visible to the query statement;
[0126] If so, the subquery result is determined to be allowed to retrieve data, and the local truncation count is updated according to the global truncation count;
[0127] If not, then the subquery result is determined to be one where data retrieval is not allowed.
[0128] Optionally, the device may also include:
[0129] The truncation module is used to determine the processing result based on the obtained truncation statement when the data truncation conditions are met.
[0130] Furthermore, the truncation module is specifically used for:
[0131] According to the truncation statement, the set of objects to be truncated, the current index control page corresponding to each object to be truncated, and the historical global truncation count of the target database are determined in the corresponding target database, wherein the set of objects to be truncated includes at least one object to be truncated;
[0132] The set of objects to be truncated is truncated according to the truncation statement to obtain the final database.
[0133] Based on the truncation statement, the current transaction ID is determined and registered in each of the current index control pages, thereby determining the index control page set;
[0134] Update the historical global truncation count to obtain the current global truncation count;
[0135] The final database, the index control page set, and the current global truncation count are used as the processing results.
[0136] The data query device provided in this embodiment of the invention can execute the data query method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the method execution.
[0137] Example 4
[0138] Figure 4 A schematic diagram of an electronic device 50 that can be used to implement embodiments of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0139] like Figure 4 As shown, the electronic device 50 includes at least one processor 51 and a memory, such as a read-only memory (ROM) 52 and a random access memory (RAM) 53, communicatively connected to the at least one processor 51. The memory stores computer programs executable by the at least one processor. The processor 51 can perform various appropriate actions and processes based on the computer program stored in the ROM 52 or loaded into the RAM 53 from storage unit 58. The RAM 53 can also store various programs and data required for the operation of the electronic device 50. The processor 51, ROM 52, and RAM 53 are interconnected via a bus 54. An input / output (I / O) interface 55 is also connected to the bus 54.
[0140] Multiple components in electronic device 50 are connected to I / O interface 55, including: input unit 16, such as keyboard, mouse, etc.; output unit 57, such as various types of monitors, speakers, etc.; storage unit 58, such as disk, optical disk, etc.; and communication unit 59, such as network card, modem, wireless transceiver, etc. Communication unit 59 allows electronic device 50 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0141] Processor 51 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 51 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 51 performs the various methods and processes described above, such as data querying methods.
[0142] In some embodiments, the data query method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 58. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 50 via ROM 52 and / or communication unit 59. When the computer program is loaded into RAM 53 and executed by processor 51, one or more steps of the data query method described above may be performed. Alternatively, in other embodiments, processor 51 may be configured to execute the data query method by any other suitable means (e.g., by means of firmware).
[0143] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0144] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0145] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0146] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0147] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0148] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0149] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0150] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A data query method, characterized by, The method comprises the following steps: acquiring a query statement for data query, determining a target table object set corresponding to the query statement and a global truncation number of a corresponding target database in the target database; determining target transaction ID information and a local truncation number corresponding to each target table object according to the target table object set and each corresponding index control page; determining a query result corresponding to the query statement according to the global truncation number, each target transaction ID information and each local truncation number; wherein the step of determining a query result corresponding to the query statement according to the global truncation number, each target transaction ID information and each local truncation number comprises the following steps: determining a sub-query result corresponding to each target table object according to the global truncation number, each target transaction ID information and each local truncation number, and forming a sub-query result set; when each sub-query result in the sub-query result set is allowed to acquire data, acquiring target sub-data corresponding to each sub-query result, and determining the query result according to each target sub-data; when any sub-query result in the sub-query result set is not allowed to acquire data, performing a statement error on the query statement; wherein the step of determining a sub-query result corresponding to each target table object according to the global truncation number, each target transaction ID information and each local truncation number, and forming a sub-query result set comprises the following steps: judging whether the local truncation number is the same as the global truncation number for each local truncation number; if yes, determining that the corresponding sub-query result is allowed to acquire data; if no, performing transaction visibility judgment on the corresponding target table object based on the target transaction ID information to determine the corresponding sub-query result; forming the sub-query result set according to each sub-query result.
2. The method of claim 1, wherein, The step of determining target transaction ID information and a local truncation number corresponding to each target table object according to the target table object set and each corresponding index control page comprises the following steps: determining an index control page corresponding to each target table object included in the target table object set; determining the target transaction ID information corresponding to the target table object in the index control page; if the query statement corresponds to a first access to the target table object, initializing and assigning the local truncation number; otherwise, directly acquiring the local truncation number.
3. The method of claim 1, wherein, The step of performing transaction visibility judgment on the corresponding target table object based on the target transaction ID information to determine the corresponding sub-query result comprises the following steps: determining transaction information corresponding to the transaction ID information; judging whether the transaction information is visible to the query statement; if yes, determining that the sub-query result is allowed to acquire data, and updating the local truncation number according to the global truncation number; if no, determining that the sub-query result is not allowed to acquire data.
4. The method of claim 1, wherein, The method further comprises the following steps: when a data truncation condition is met, determining a processing result according to an acquired truncation statement for data truncation.
5. The method of claim 4, wherein, The step of determining a processing result according to an acquired truncation statement for data truncation comprises the following steps: According to the truncate statement, a set of to-be-truncated objects, a current index control page corresponding to each of the to-be-truncated objects, and a historical global truncation number of the target database are determined in the corresponding target database, wherein the set of to-be-truncated objects includes at least one to-be-truncated object; According to the truncate statement, a set of to-be-truncated objects, a current index control page corresponding to each of the to-be-truncated objects, and a historical global truncation number of the target database are determined in the corresponding target database, wherein the set of to-be-truncated objects includes at least one to-be-truncated object; According to the truncate statement, a current transaction ID is determined and recorded in each of the current index control pages, and a set of index control pages is determined; The historical global truncation number is updated to obtain a current global truncation number; The final database, the set of index control pages, and the current global truncation number are taken as processing results.
6. A data query apparatus, characterized by comprising: Comprise: A first determination module is configured to obtain a query statement used for data query, and determine a set of target table objects corresponding to the query statement and a global truncation number of a target database in the corresponding target database; A second determination module is configured to determine target transaction ID information corresponding to each of the target table objects and a local truncation number according to the set of target table objects and corresponding index control pages; A third determination module is configured to determine a query result corresponding to the query statement according to the global truncation number, the target transaction ID information, and the local truncation number; The third determination module comprises: A first determination unit is configured to determine a sub-query result corresponding to each of the target table objects according to the global truncation number, the target transaction ID information, and the local truncation number, and form a set of sub-query results; A second determination unit is configured to obtain target sub-data corresponding to each of the sub-query results when each of the sub-query results in the set of sub-query results is allowed to obtain data, and determine the query result according to the target sub-data; A third determination unit is configured to perform statement error reporting on the query statement when any of the sub-query results in the set of sub-query results is not allowed to obtain data; The first determination unit comprises: A judgment sub-unit is configured to judge whether the local truncation number is the same as the global truncation number for each of the local truncation numbers; A first determination sub-unit is configured to determine that the corresponding sub-query result is allowed to obtain data if the local truncation number is the same as the global truncation number; A second determination sub-unit is configured to perform transaction visibility judgment on the corresponding target table object based on the target transaction ID information to determine the corresponding sub-query result if the local truncation number is not the same as the global truncation number; A forming sub-unit is configured to form the set of sub-query results according to each of the sub-query results.
7. An electronic device, comprising: The electronic device comprises: At least one processor; and A memory connected in communication with the at least one processor; wherein The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor to enable the at least one processor to execute the data query method in any one of claims 1-5.
8. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer instructions for enabling the processor to execute the data query method in any one of claims 1-5 when executed.
Citation Information
Patent Citations
Data query method and device
CN107346317A
Data visibility judgment method and device, database node and medium
CN114637738A