Method, product and device for cross-transaction real-time sharing of cursors in autonomous transactions

By using a shared hash table to store cursor metadata and generate a unique identifier in the database system, the resource overhead and data consistency issues between autonomous transactions and the main transaction are resolved, enabling real-time sharing and efficient transmission of cursor status, which is suitable for complex multi-level transaction collaboration scenarios.

CN123137801APending Publication Date: 2026-11-20CETC JINCANG (BEIJING) TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611390765.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-08
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

In database systems, when transferring cursor data between autonomous transactions and main transactions, existing technologies suffer from problems such as high system resource overhead, inability to connect cursor states, and poor data consistency. Especially in scenarios with massive query results, the traditional static data copy transfer method leads to resource waste and data inconsistency.

Method used

A shared hash table is used to store cursor metadata. By generating unique identifiers and cross-transaction pointer positions, real-time sharing of cursors is achieved, avoiding data copying and serialization operations. Snapshots and lock information are used to ensure data consistency and concurrency safety.

Benefits of technology

It reduces system resource overhead, achieves seamless connection of cursor traversal states, improves processing efficiency and data consistency, and is suitable for multi-level transaction collaboration scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123137801A_ABST
    Figure CN123137801A_ABST
Patent Text Reader

Abstract

The application provides a cross-transaction real-time sharing method, product and equipment of a cursor in an autonomous transaction. The method comprises the following steps: storing metadata related to a target cursor corresponding to a main transaction into a shared hash table, and generating a unique identifier of the target cursor; when the main transaction calls an autonomous transaction, the unique identifier is transmitted to the autonomous transaction; the metadata is obtained by querying the shared hash table according to the unique identifier; the target cursor is operated in real time according to the metadata, and a cross-transaction pointer position is updated in real time; when the autonomous transaction is committed or rolled back, the metadata in the shared hash table is locked, so that the metadata is not reset with the end of the autonomous transaction; the corresponding metadata is obtained by the main transaction according to the unique identifier, the target cursor is continuously operated based on the metadata, and the cross-transaction pointer position is updated in real time, so that the cross-transaction real-time sharing is realized. This method can reduce resource consumption, realize seamless connection of cursor traversal states across transactions, and guarantee data stability and concurrent safety.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database technology, and in particular to a method, product, and device for real-time cross-transaction sharing of cursors in autonomous transactions. Background Technology

[0002] In database systems, autonomous transactions, which can be committed or rolled back independently of the main transaction, are often used in scenarios requiring independent verification, such as logging and data auditing. Cursors, as the core tool for traversing and querying database result sets, typically have their lifecycle strongly bound to the transaction they belong to. When the main transaction and autonomous transactions collaborate in processing data, they often need to exchange query results or hand over traversal tasks.

[0003] Cross-transaction transfer of cursor data typically requires an external intermediary. For example, the query results corresponding to the cursor might be written to a temporary table one by one, then read by the target transaction; or the query results might be serialized and written to a disk file, with the file path passed before being deserialized and read by the target transaction. Both methods involve multiple steps, including cursor traversal, data copying / serialization, target transaction reading, and parsing, significantly increasing system processor and input / output resource overhead. More importantly, this static data copy transfer method only transfers the data itself, failing to retain dynamic state information such as cursor pointer position and traversal progress. If the main transaction and autonomous transactions need to traverse the same result set, the target transaction often cannot directly continue from the original cursor position, forcing it to relocate the traversal starting point or even repeatedly traverse already processed data, severely impacting the efficiency of cross-transaction collaborative processing. Furthermore, for massive amounts of query results, static copy storage consumes significant storage resources, and the time difference between copying and reading can easily lead to data inconsistencies, making it difficult to meet the application requirements of complex, multi-level transaction collaboration scenarios. Summary of the Invention

[0004] In view of the above problems, the present invention proposes a method, product and device for real-time cross-transaction sharing of cursors in autonomous transactions to overcome the above problems or at least partially solve the above problems.

[0005] One objective of this invention is to reduce the system overhead of cursor interactions across transactions.

[0006] A further objective of this invention is to improve the state continuity and scenario adaptability of cursors during cross-transaction interactions.

[0007] Specifically, the present invention provides a method for real-time cross-transaction sharing of cursors in autonomous transactions, comprising: Before the main transaction calls the autonomous transaction, the cursor shared preprocessing process is triggered. The cursor shared preprocessing process is used to store the metadata involved in the target cursor corresponding to the main transaction into a shared hash table and generate a unique identifier for the target cursor. The metadata includes execution status, cross-transaction pointer position, snapshot of the cursor associated result set, and lock information. The cross-transaction pointer position is used to record the position of the cursor in the snapshot. When the main transaction invokes the autonomous transaction, a unique identifier is passed to the autonomous transaction; The autonomous transaction retrieves the metadata corresponding to the target cursor by querying the shared hash table based on the unique identifier. The target cursor is manipulated in real time based on snapshot and lock information in the metadata, and the cross-transaction pointer position of the target cursor is updated to the shared hash table in real time. When an autonomous transaction is committed or rolled back, the metadata in the shared hash table is locked so that the metadata is not reset when the autonomous transaction ends; The main transaction retrieves the metadata corresponding to the target cursor from the shared hash table based on the unique identifier, continues to operate on the target cursor based on the snapshot in the metadata, and updates the cross-transaction pointer position of the target cursor to the shared hash table in real time, thereby achieving real-time sharing across transactions.

[0008] Optionally, it also includes: After an autonomous transaction is completed, before returning the target cursor to the main transaction or the upper-level autonomous transaction, a lower-level return preprocessing process is triggered. The lower-level return preprocessing process is used to store the metadata of the target cursor into a shared hash table and mark the resource owner field corresponding to the metadata in the shared hash table as the identifier of the autonomous transaction. Change the owner of the snapshot and lock information to the main transaction or the upper-level autonomous transaction, and update the resource owner field synchronously; Verify whether the owner has been successfully changed. If the change is successful, return the unique identifier to the main transaction or the upper-level autonomous transaction. Metadata is retrieved from the shared hash table by the main transaction or the upper-level autonomous transaction based on a unique identifier; The target cursor is manipulated in real time based on the snapshot and lock information in the metadata, and the cross-transaction pointer position of the target cursor is updated to the shared hash table in real time, thereby achieving real-time sharing across transactions.

[0009] Optionally, the step of verifying whether the owner has been successfully changed also includes: If the ownership change fails, terminate the step of returning the unique identifier to the main transaction or the upper-level autonomous transaction and throw an exception message.

[0010] Optionally, it also includes: When a higher-level autonomous transaction passes a target cursor to a lower-level autonomous transaction, it only passes a unique identifier and does not perform any owner change operations for snapshot and lock information; the owner remains the higher-level autonomous transaction. When the lower-level autonomous transaction completes the cursor operation and returns the target cursor to the upper-level autonomous transaction, the snapshot and lock information owner change operation is performed.

[0011] Optionally, the change of ownership of snapshot and lock information can be performed through the database system resource permission change interface, or through a custom resource management service interface in a service-oriented manner. The custom resource management service interface is used to adapt to multiple database compatibility scenarios.

[0012] Optionally, the storage steps of the shared hash table include: A distributed cache is used as the storage medium for the shared hash table to enable the sharing of metadata among multiple nodes.

[0013] Optionally, the step of operating the target cursor in real time based on snapshot and lock information in the metadata also includes: Get the snapshot status flag corresponding to the snapshot. The snapshot status flag is used to indicate whether the snapshot is valid at present, and the snapshot status flag is set to invalid when the database resource corresponding to the snapshot is deleted. While the snapshot status is marked as valid, continue executing the steps of operating the target cursor in real time based on the snapshot and lock information in the metadata; When a snapshot is marked as invalid, a snapshot invalidation message is returned.

[0014] Optionally, the steps of passing a unique identifier to an autonomous transaction include: passing the unique identifier via a function or stored procedure parameter; In asynchronous transaction collaboration scenarios, the steps to pass a unique identifier to an autonomous transaction also include: passing the unique identifier through a message queue.

[0015] According to another aspect of the invention, a computer program product is also provided, comprising a computer program that, when executed by a processor, implements the steps of the method for real-time cross-transaction sharing of cursors in any of the above-described autonomous transactions.

[0016] According to another aspect of the present invention, a computer device is also provided, including a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor executes the computer program to implement the steps of the method for real-time sharing of cursors across transactions in any of the above-described autonomous transactions.

[0017] The method for real-time cross-transaction sharing of cursors in autonomous transactions of the present invention triggers a cursor sharing preprocessing process before the main transaction calls the autonomous transaction. This preprocessing process stores the metadata related to the target cursor corresponding to the main transaction in a shared hash table and generates a unique identifier for the target cursor. The metadata includes execution status, cross-transaction pointer position, a snapshot of the cursor's associated result set, and lock information. The cross-transaction pointer position records the cursor's position in the snapshot. When the main transaction calls the autonomous transaction, the unique identifier is passed to the autonomous transaction. The autonomous transaction retrieves the metadata corresponding to the target cursor from the shared hash table based on the unique identifier. It then operates on the target cursor in real-time based on the snapshot and lock information in the metadata, and updates the cross-transaction pointer position of the target cursor to the shared hash table in real-time. When the autonomous transaction commits or rolls back, the metadata in the shared hash table is locked so that the metadata is not reset when the autonomous transaction ends. The main transaction retrieves the metadata corresponding to the target cursor from the shared hash table based on the unique identifier, continues to operate on the target cursor based on the snapshot in the metadata, and updates the cross-transaction pointer position of the target cursor to the shared hash table in real-time, thereby achieving real-time cross-transaction sharing. This method eliminates the need for intermediate media such as temporary tables and files to copy the complete result set; cursor sharing can be achieved simply by passing the unique identifier of the target cursor. By relying on a shared hash table to uniformly maintain execution status, cross-transaction pointer positions, snapshots, and lock information, the main transaction and autonomous transactions can synchronize cursor traversal progress in real time. Committing or rolling back an autonomous transaction will not cause the loss of cursor metadata, effectively reducing IO and CPU overhead. It enables seamless continuation of cursor traversal status across transactions, while using snapshots and lock information to ensure data stability and concurrency security for cross-transaction access.

[0018] Furthermore, the cross-transaction real-time sharing method for cursors in autonomous transactions of the present invention, after the completion of the autonomous transaction and before returning the target cursor to the main transaction or the upper-level autonomous transaction, triggers a lower-level return preprocessing process. The lower-level return preprocessing process is used to store the metadata of the target cursor into a shared hash table and mark the resource owner field corresponding to the metadata in the shared hash table as the identifier of the autonomous transaction; change the owner of the snapshot and lock information to the main transaction or the upper-level autonomous transaction, and synchronously update the resource owner field; verify whether the owner change is successful. If the change is successful, return the unique identifier to the main transaction or the upper-level autonomous transaction; the main transaction or the upper-level autonomous transaction retrieves the metadata from the shared hash table based on the unique identifier; and operates the target cursor in real time according to the snapshot and lock information in the metadata, and updates the cross-transaction pointer position of the target cursor to the shared hash table in real time, thereby realizing cross-transaction real-time sharing. This method completes the transfer of resource ownership for snapshot and lock information when the cursor returns upward, ensuring that the lifecycle of snapshot and lock resources follows the target upper-level transaction and preventing resources from being released when the autonomous transaction ends. Combined with the resource transfer verification mechanism, it ensures the reliability of resource ownership changes. After the upper-level transaction obtains a unique identifier, it can continue to complete the cursor operation, adapting to the scenario of downstream cursor return flow in multi-level nested autonomous transactions and improving the reliability of downstream cursor sharing in complex nested transaction scenarios.

[0019] The above and other objects, advantages and features of the present invention will become more apparent to those skilled in the art from the following detailed description of specific embodiments of the invention in conjunction with the accompanying drawings. Attached Figure Description

[0020] The following sections will describe some specific embodiments of the invention in a detailed manner by way of example and not limitation, with reference to the accompanying drawings. The same reference numerals in the drawings denote the same or similar parts or portions. Those skilled in the art should understand that these drawings are not necessarily drawn to scale. In the drawings: Figure 1 This is a flowchart illustrating a method for real-time cross-transaction sharing of cursors in an autonomous transaction according to an embodiment of the present invention. Figure 2 This is a flowchart illustrating a method for real-time cross-transaction sharing of cursors in an autonomous transaction according to another embodiment of the present invention; Figure 3 This is a schematic diagram of a computer program product according to an embodiment of the present invention; Figure 4 This is a schematic diagram of a computer-readable storage medium according to an embodiment of the present invention; and Figure 5 This is a schematic diagram of a computer device according to an embodiment of the present invention. Detailed Implementation

[0021] Those skilled in the art should understand that the embodiments described below are merely a part of the embodiments of the present invention, and not all of the embodiments of the present invention. These partial embodiments are intended to explain the technical principles of the present invention and are not intended to limit the scope of protection of the present invention. Based on the embodiments provided by the present invention, all other embodiments obtained by those skilled in the art without creative effort should still fall within the scope of protection of the present invention.

[0022] It should be noted that the logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus or device (such as a computer-based system, a processor-included system or other system that can fetch and execute instructions from, an instruction execution system, apparatus or device).

[0023] In the current database technology field, the following drawbacks generally exist in the scenario of cursor sharing between autonomous transactions and main transactions, and these drawbacks stem from the design limitations of the technical solutions themselves: 1. The data transfer process is cumbersome and the system overhead is high: It generally requires multiple steps of "cursor traversal → data writing to temporary table / file → target transaction reading → data parsing". Compared with directly sharing the cursor, it adds extra operations such as data copying and serialization / deserialization, which significantly increases the system resource consumption (CPU, IO).

[0024] 2. Inability to connect cursor states, resulting in low processing efficiency: Current processing methods generally only transmit the data itself, without retaining state information such as cursor pointer position and traversal progress. If the main transaction and autonomous transactions need to connect and traverse the same result set (e.g., the main transaction traverses part of the data and then the autonomous transaction continues traversing), the target transaction needs to relocate the traversal starting point, or even repeatedly traverse the processed data, leading to a decrease in processing efficiency.

[0025] 3. Wasted storage resources and poor consistency in scenarios with large amounts of data: For massive query results, temporary tables / file storage requires a lot of storage resources; at the same time, there is a time difference between writing and reading data. If the source data changes (such as modifications that have not been committed by the main transaction), the data read by the target transaction will be inconsistent with the source cursor result set.

[0026] To address the aforementioned issues, this invention proposes a method for real-time cross-transaction sharing of cursors within autonomous transactions. Figure 1This is a flowchart illustrating a method for real-time cross-transaction sharing of cursors within an autonomous transaction according to an embodiment of the present invention. The method of the present invention abandons the traditional data transfer method using temporary tables or files as intermediate carriers, instead utilizing a shared hash table to store cursor metadata, using the cursor name as the access credential, and achieving direct and seamless connection of cursor states between the main transaction and the autonomous transaction through real-time synchronization of pointer positions across transactions and a resource owner transfer mechanism. Figure 1 As shown, the method for real-time cross-transaction sharing of cursors in this autonomous transaction includes at least the following steps S101 to S108.

[0027] Step S101: The main transaction opens the target cursor and generates a unique identifier for the target cursor. Before the main transaction calls the autonomous transaction, a cursor shared preprocessing process is triggered. The cursor shared preprocessing process is used to store the metadata related to the target cursor corresponding to the main transaction into a shared hash table and generate a unique identifier for the target cursor. The metadata includes the execution status, cross-transaction pointer position, snapshot of the cursor's associated result set, and lock information. The cross-transaction pointer position is used to record the cursor's position in the snapshot.

[0028] The core function of this cursor shared preprocessing flow is to generate a globally unique identifier (i.e., cursor name) for the target cursor corresponding to the main transaction and store the complete metadata related to the target cursor in a shared hash table. The metadata includes execution status, cross-transaction pointer position, a snapshot of the cursor's associated result set, and lock information. The execution status indicates the current working state of the target cursor, such as whether it is open or has completed traversal. The cross-transaction pointer position records the cursor's current position in the snapshot and is a key field for connecting traversal progress. The snapshot of the cursor's associated result set is a static copy generated when the main transaction opens the cursor, and this snapshot is not updated with real-time changes to the source data, thus ensuring that subsequent autonomous transactions or the main transaction always see the stable state when the cursor was opened when accessing the result set. The lock information includes the lock type and locking range, used to ensure concurrency safety during cross-transaction operations and prevent conflicting operations between the main transaction and autonomous transactions on the same data.

[0029] By using the aforementioned metadata, the core state of the cursor can be separated from the private context of the main transaction and managed uniformly by a shared hash table, thereby breaking the transaction's lifecycle binding constraint on the cursor. The generated unique identifier serves as the credential for accessing the metadata. Cursor sharing can be completed by transmitting only a lightweight identifier, eliminating the need to transmit large result sets of data, thus effectively reducing CPU and I / O overhead.

[0030] In step S102, the main transaction stores the metadata of the target cursor into a shared hash table.

[0031] After generating the unique identifier and corresponding metadata of the target cursor in step S101, the main transaction stores the metadata in a shared hash table. Optionally, the storage medium for the shared hash table can be flexibly selected according to the actual deployment scenario. In a single-machine deployment scenario, memory or disk can be used to store the shared hash table. When the database is deployed in a multi-node distributed environment, the storage steps of the shared hash table generally include: using a distributed cache as the storage medium for the shared hash table to achieve metadata sharing among multiple nodes. When the database system is deployed in a multi-node distributed environment, the shared hash table in local memory or disk cannot be accessed by autonomous transactions on other nodes. Using a distributed cache can leverage its real-time synchronization characteristics, allowing transactions on different database nodes to read consistent metadata from the distributed cache using the same cursor name, thereby achieving real-time sharing of cursors across nodes and transactions, expanding the application scenarios of this invention.

[0032] In step S103, the main transaction calls the autonomous transaction, passing a unique identifier as a parameter through a function or stored procedure. After storing the target cursor's metadata in a shared hash table, the main transaction begins calling the autonomous transaction. During the call, the main transaction only needs to pass the unique identifier generated in step S101 as a parameter to the autonomous transaction, without needing to copy or transfer the cursor itself or the result set data.

[0033] Specifically, a unique identifier can be passed through interfaces such as function or stored procedure parameters. This method is extremely lightweight, passing only a string or identifier, avoiding the input / output operations required in traditional solutions to write query results to temporary tables or serialize them to disk files one by one. This fundamentally eliminates the system resource overhead (such as CPU usage and disk I / O) caused by data copying and serialization / deserialization.

[0034] In synchronous call scenarios, the main transaction and autonomous transactions share a call stack context. A lightweight unique identifier can be directly passed to the autonomous transaction using function or stored procedure parameters, without involving large-scale data copying. However, in asynchronous transaction collaboration scenarios, there is no synchronous call relationship between the main transaction and autonomous transactions. Therefore, in asynchronous transaction collaboration scenarios, the step of passing the unique identifier to the autonomous transaction can also include: passing the unique identifier via a message queue. The message queue allows asynchronously triggered autonomous transactions to also obtain credentials to access the cursor. This thus accommodates both synchronous and asynchronous business scenarios.

[0035] In step S104, the autonomous transaction receives a unique identifier and retrieves the metadata corresponding to the target cursor by querying the shared hash table based on the unique identifier.

[0036] After receiving the unique identifier from the main transaction, the autonomous transaction uses this unique identifier as the key to look up the complete metadata corresponding to the unique identifier in the shared hash table. This step does not require re-executing the query statement corresponding to the cursor, nor does it require relocating the data source. Instead, it directly parses the execution status, cross-transaction pointer position, snapshot, and lock information based on the cursor metadata already stored in the shared hash table.

[0037] In step S105, the autonomous transaction operates the target cursor in real time based on the snapshot and lock information in the metadata, and updates the cross-transaction pointer position of the target cursor to the shared hash table. After obtaining the metadata, the autonomous transaction performs cursor movement, reading, and other operations based on the snapshot in the metadata. Since the snapshot is a static copy, the data read by the autonomous transaction is completely consistent with the data when the cursor was opened, and is not affected by subsequent uncommitted modifications to the source data by the main transaction, thus avoiding the data inconsistency problem caused by time difference in traditional temporary tables or file transfer schemes.

[0038] More importantly, after executing cursor operations, the autonomous transaction will synchronously write the updated cross-transaction pointer position to the shared hash table in real time. This pointer position is the current traversal progress of the cursor in the snapshot result set. Every time the autonomous transaction moves the cursor or reads a piece of data, it will update the latest pointer position to the shared hash table, ensuring that the main transaction or other transactions can obtain the latest traversal status through the shared hash table at any time, achieving seamless connection of traversal progress.

[0039] In some optional embodiments, the step of real-time operation of the target cursor based on snapshot and lock information in the metadata may generally include: obtaining a snapshot status flag corresponding to the snapshot, whereby the snapshot status flag indicates whether the snapshot is currently valid, and the snapshot status flag is set to invalid when the database resource corresponding to the snapshot is deleted; if the snapshot status flag is valid, continuing to execute the step of real-time operation of the target cursor based on snapshot and lock information in the metadata; and if the snapshot status flag is invalid, returning a snapshot invalidation message. By introducing a snapshot status flag mechanism, the system can effectively identify and handle abnormal situations of snapshot invalidation, avoiding the continued reading of invalid data when the source data has been deleted, thus improving the robustness of the system.

[0040] Step S106: When an autonomous transaction is committed or rolled back, the metadata in the shared hash table is locked to prevent the metadata from being reset upon the end of the autonomous transaction. After the autonomous transaction is completed, whether it is committed or rolled back, the system will lock the metadata corresponding to the target cursor in the shared hash table. This locking operation is not a transaction-level lock, but rather an access control measure for metadata entries in the shared hash table.

[0041] Because autonomous transactions have independent commit and rollback capabilities, they automatically release all resources held by the transaction, including cursor resources, when their lifecycle ends. If relying solely on traditional cursor mechanisms, the cursor would automatically close upon the end of the autonomous transaction, preventing the main transaction from continuing its iterations. However, this solution locks the metadata in a shared hash table, ensuring that this metadata is not reset or deleted upon the end of the autonomous transaction during commit or rollback. The metadata in the shared hash table, as an independent storage entity, no longer has its lifecycle tied to the autonomous transaction but persists, allowing the main transaction to query and manipulate it again.

[0042] In step S107, the main transaction retrieves the metadata corresponding to the target cursor from the shared hash table using the unique identifier. After the autonomous transaction completes its processing, the execution flow returns to the main transaction. The main transaction then uses the previously obtained unique identifier to read the shared hash table again, thus obtaining the latest metadata modified by the autonomous transaction. This metadata includes the updated cross-transaction pointer position after the autonomous transaction's processing is complete, without needing to relocate the traversal starting point.

[0043] Step S108: Continue operating on the target cursor based on the snapshot in the metadata, and update the cross-transaction pointer position of the target cursor to the shared hash table in real time.

[0044] After obtaining the latest metadata, the main transaction continues to operate on the target cursor based on the snapshot. Since the snapshot is a static copy, subsequent operations of the main transaction are not affected by the lifecycle of the autonomous transaction, nor will they read inconsistent data due to changes in the source data. The main transaction continues reading from the current traversal progress indicated by the cross-transaction pointer position, without needing to relocate the traversal starting point or repeatedly traverse already processed data. Simultaneously, the main transaction also updates the cross-transaction pointer position to the shared hash table in real time during operations, ensuring that if cross-transaction propagation occurs again (e.g., propagation to the next level of autonomous transaction), the new target transaction can seamlessly continue traversal based on the latest pointer position, achieving consistency and continuity of cursor states across multiple transaction levels.

[0045] In summary, the method in this embodiment does not require temporary tables or disk files as intermediate carriers to copy the complete result set. It relies on a shared hash table to uniformly maintain the cursor metadata and only transmits a lightweight unique identifier to complete cursor sharing. This reduces the CPU and IO overhead caused by data copying, serialization and deserialization, and enables seamless connection of cursor traversal progress across transactions. At the same time, it relies on snapshot and lock information to ensure data consistency and concurrency security for cross-transaction access.

[0046] Figure 2 This is a flowchart illustrating a method for real-time cross-transaction sharing of cursors in an autonomous transaction according to another embodiment of the present invention, as shown below. Figure 2As shown, this method is for scenarios where an autonomous transaction actively returns a cursor to the main transaction or a higher-level autonomous transaction. The method for real-time cross-transaction sharing of cursors within this autonomous transaction includes at least the following steps S201 to S208.

[0047] Step S201: The autonomous transaction opens the target cursor and generates a unique identifier for the target cursor. In a database system, an autonomous transaction has the characteristic of being independent of the main transaction's commit or rollback. During execution, it can open its own target cursor to traverse the query result set. However, since autonomous transactions do not share resources with the main transaction, when the autonomous transaction finishes execution, its opened target cursor will be automatically closed, causing the main transaction to be unable to continue using the cursor. To solve the above problem, in this embodiment, after the autonomous transaction opens the target cursor, the database generates a globally unique identifier for the target cursor so that the cursor can be shared across transactions in the future through this unique identifier.

[0048] Step S202: Trigger the next-level return preprocessing process; store the metadata of the target cursor into a shared hash table, and mark the resource owner field corresponding to the metadata in the shared hash table as the identifier of the autonomous transaction.

[0049] After an autonomous transaction completes but before returning the target cursor to the main transaction or a higher-level autonomous transaction, the autonomous transaction triggers a lower-level return preprocessing procedure. This preprocessing procedure stores the metadata related to the target cursor in a shared hash table. Simultaneously, it marks the resource owner field corresponding to the metadata as the identifier of the current autonomous transaction to clarify the ownership of the current resource. Metadata typically includes execution status, cross-transaction pointer positions, snapshots of the cursor's associated result set, and lock information.

[0050] By stripping cursor metadata (especially snapshot and lock information) from the local context of autonomous transactions and storing it in a globally accessible shared hash table, a foundation can be laid for subsequent resource transfers and cross-transaction access. The marker in the resource owner field provides a baseline for subsequent explicit changes in resource ownership.

[0051] Step S203: Change the owner of the snapshot and lock information to the main transaction or the upper-level autonomous transaction, and synchronously update the resource owner field. After storing the metadata in the shared hash table, the autonomous transaction needs to perform a resource owner transfer operation, that is, change the owner of the snapshot and lock information from the current autonomous transaction to the target transaction (main transaction or upper-level autonomous transaction), and synchronously update the resource owner field in the shared hash table.

[0052] It should be noted that in multi-level autonomous transaction scenarios, resource ownership changes follow differentiated rules. Specifically: when an upper-level autonomous transaction passes a target cursor to a lower-level autonomous transaction, only the unique identifier is passed; no snapshot or lock information ownership change operations are performed, and the owner remains the upper-level autonomous transaction. This is because in a downward passing scenario, the execution flow inevitably returns to the upper level, and the lower-level autonomous transaction only temporarily accesses the cursor, thus avoiding the need to transfer resource ownership and unnecessary resource transfer overhead.

[0053] When the lower-level autonomous transaction completes its cursor operation and returns the target cursor to the upper-level autonomous transaction, an owner change operation for the snapshot and lock information is performed. At this point, the lower-level autonomous transaction no longer needs to hold the resource. If ownership is not transferred, the resource will be lost when the lower-level autonomous transaction ends. Therefore, a transfer operation must be performed to ensure that the resource's lifecycle follows the upper-level transaction.

[0054] In some optional embodiments, the change of ownership of snapshot and lock information can generally be performed through the database system resource permission change interface, adapting to the native database environment. Alternatively, it can be performed in a service-oriented manner through a custom resource management service interface, which is used to adapt to scenarios compatible with multiple database types. After the change is completed, the resource owner field in the shared hash table is synchronously refreshed to ensure that the ownership information in the metadata record is consistent with the actual resource holding status.

[0055] Step S204: Verify whether the owner change was successful. The resource owner change operation involves adjusting underlying database resource permissions, and may fail due to factors such as concurrency and internal database anomalies. Therefore, after completing the change operation, a verification step is needed to check whether the actual holding transaction identifier of the snapshot and lock resources matches the identifier of the target transaction, confirming that the resource transfer has truly taken effect, avoiding inconsistency issues, and ensuring the reliability of the entire process.

[0056] In step S205, if the determination in step S204 is negative, the return step is terminated and an exception message is thrown.

[0057] If the verification finds that the snapshot or lock resource ownership change has failed, the cursor return process will not be executed further down the line. Instead, the operation of sending the unique identifier back to the upper-layer transaction will be terminated directly, and an exception message will be thrown outwards. This failure interception mechanism prevents the upper-layer transaction from continuing to execute cursor operations after obtaining an invalid unique identifier, avoiding data corruption caused by the upper-layer transaction performing read / write operations based on incorrect resource states. This facilitates the upper-layer business in capturing exceptions and handling faults.

[0058] Step S206: If the determination in step S204 is yes, the unique identifier is returned to the main transaction or the upper-level autonomous transaction.

[0059] After verifying that the snapshot and lock resources have been successfully assigned to the main transaction or the upper-level autonomous transaction, only a lightweight unique identifier is sent back. The upper-level transaction can then access all cursor metadata in the shared hash table using this unique identifier, without needing to transfer massive amounts of result set data, thus reducing data transfer overhead.

[0060] In step S207, the main transaction or the upper-level autonomous transaction retrieves the metadata from the shared hash table based on the unique identifier. After receiving the unique identifier, the main transaction or the upper-level autonomous transaction uses this unique identifier as an index to read the shared hash table and directly obtain the complete metadata of the cursor, including the execution status, the positions of the cross-transaction pointers that have been traversed, snapshots, lock information, and the latest resource owner field. There is no need to reopen the cursor or re-execute the query to generate a result set; the cursor's running state, already processed by the autonomous transaction, is directly reused.

[0061] Step S208: Operate the target cursor in real time based on the snapshot and lock information in the metadata, and update the cross-transaction pointer position of the target cursor to the shared hash table in real time, thereby realizing real-time sharing across transactions.

[0062] The upper-level transaction obtains a stable view of the result set based on snapshots within the metadata. Concurrent operations are constrained by lock information, and cursor read and move operations directly continue from the cross-transaction pointer positions recorded in the metadata. This eliminates the need to relocate the traversal starting point and avoids reprocessing already traversed data. Each time the upper-level transaction modifies the cursor traversal position, the updated cross-transaction pointer position is written back to the shared hash table in real time, ensuring real-time cursor state synchronization. Furthermore, since the ownership of the snapshot and lock resources has changed to the upper-level transaction, their lifecycle follows the upper-level transaction and is not released or destroyed upon the original autonomous transaction that created the cursor, ensuring the cursor can continue to be used normally by the upper-level transaction.

[0063] Figure 2 The illustrated embodiment implements the complete process of returning the cursor to the main transaction or the upper-level autonomous transaction after the autonomous transaction creates the cursor. It solves the problem of cursor resource destruction caused by the end of the autonomous transaction through the resource owner transfer mechanism. With the addition of locking protection, change verification and failure exception throwing during the transfer process, the resource handover process is guaranteed to be safe and reliable. At the same time, by using the differentiated resource ownership rules of multi-level autonomous transactions, invalid resource switching operations are reduced, the processing efficiency in multi-level nested business scenarios is improved, and the applicable scenarios of the method of the present invention are expanded.

[0064] In summary, the technical effects achieved by the cross-transaction real-time sharing method for cursors in autonomous transactions of the present invention mainly include: 1. Significantly reduced system overhead and improved real-time performance: Replacing traditional persistence with real-time cursor snapshot storage eliminates the need for I / O operations to write result sets to disk / memory, storing only static snapshots (which occupy less space); simultaneously, only the cursor's unique identifier is transmitted, avoiding data copying and parsing overhead. In actual testing, in a scenario with a shared result set of 100,000 records, I / O overhead is reduced by more than 70% compared to temporary table solutions, CPU utilization is reduced by more than 40%, and state synchronization latency is controlled within 1ms.

[0065] 2. Real-time status synchronization and improved processing efficiency: By synchronizing pointer positions in real time through a shared hash table, the target transaction can directly continue the traversal progress without repositioning. Specifically, in scenarios where "the main transaction is traversed to 50% and then resumed by an autonomous transaction" and "the autonomous transaction is traversed to 60% and then returned to the main transaction to resume," the traversal completion time is reduced by 75% and 80% respectively compared to the file storage solution, and the data processing accuracy reaches 100%.

[0066] 3. Enhanced concurrency security and improved resource stability: Real-time synchronization of lock information via shared hash table avoids cross-transaction data conflicts; Resource owner transfer mechanism ensures that snapshots and lock resources are not closed when autonomous transactions end; Static snapshots guarantee that the result set does not change with the source data, achieving 100% data consistency, thereby solving the core defects of "resource loss", "data inconsistency" and "sharing delay" in the current database field.

[0067] 4. Enhanced Scenario Adaptability: By reducing ineffective overhead through differentiated resource ownership rules, it supports real-time cursor flow between multi-level autonomous transactions and can adapt to complex scenarios such as real-time processing of distributed audit logs and real-time collaboration of multi-level data verification.

[0068] The flowchart provided in this embodiment is not intended to indicate that the operations of the method will be performed in any particular order, or that all operations of the method are included in every case. Furthermore, the method may include additional operations. Within the scope of the technical concept provided by the method in this embodiment, additional variations can be made to the above method.

[0069] It should be understood that in some embodiments, the components may be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods may be implemented using software or firmware stored in memory and executed by a suitable instruction execution system.

[0070] This embodiment also provides a computer program product 10, a computer-readable storage medium 20, and a computer device 30. Figure 3 This is a schematic diagram of a computer program product 10 according to an embodiment of the present invention. Figure 4 This is a schematic diagram of a computer-readable storage medium 20 according to an embodiment of the present invention. Figure 5This is a schematic diagram of a computer device 30 according to an embodiment of the present invention. The computer program product 10 includes a computer program 11, which, when executed by the processor 32, implements the steps of the cross-transaction real-time sharing method for cursors in any of the above-described autonomous transactions. A computer-readable storage medium 20 stores the computer program 11 thereon, which, when executed by the processor 32, implements the steps of the cross-transaction real-time sharing method for cursors in any of the above-described autonomous transactions. The computer device 30 may include a memory 31, a processor 32, and the computer program 11 stored in the memory 31 and running on the processor 32.

[0071] The computer program 11 used to perform the operations of this invention may be assembly instructions, Instruction Set Architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state setting data, integrated circuit configuration data, or source code or object code written in any combination of one or more programming languages ​​and procedural programming languages. The computer program 11 may execute entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the latter case, the remote computer may be connected to the user's computer via any type of network, including a Local Area Network (LAN) or Wide Area Network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider). In some embodiments, to perform aspects of this invention, electronic circuits, including, for example, programmable logic circuits, Field-Programmable Gate Arrays (FPGAs), or Programmable Logic Arrays (PLAs), may execute computer-readable program instructions to personalize the electronic circuits by utilizing state information from computer-readable program instructions.

[0072] For the purposes of this embodiment, computer program product 10 is a related product containing computer program 11. For the purposes of this embodiment, computer-readable storage medium 20 is a tangible device capable of holding and storing computer program 11, and can be any device capable of containing, storing, communicating, propagating, or transmitting program 11 for use by or in conjunction with an instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of computer-readable storage medium 20 include: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), static random access memory (SRAM), portable optical disc read-only memory (CD-ROM), digital versatile disc (DVD), memory stick, floppy disk, mechanical encoding device, and any suitable combination thereof.

[0073] Computer device 30 can be, for example, a server, desktop computer, laptop computer, tablet computer, or smartphone. In some examples, computer device 30 can be a cloud computing node. Computer device 30 can be described in the general context of computer system executable instructions (such as program modules) executed by a computer system. Typically, program modules can include routines, programs, object programs, components, logic, data structures, etc., that perform specific tasks or implement specific abstract data types. Computer device 30 can be implemented in a distributed cloud computing environment where tasks are performed by remote processing devices linked through a communication network. In a distributed cloud computing environment, program modules can reside on local or remote computing system storage media, including storage devices.

[0074] Computer device 30 may include a processor 32 adapted to execute stored instructions and a memory 31 that provides temporary storage space for the operation of said instructions during operation. The processor 32 may be a single-core processor, a multi-core processor, a computing cluster, or any other configuration. The memory 31 may include random access memory (RAM), read-only memory, flash memory, or any other suitable storage system.

[0075] Computer device 30 may also include a network adapter / interface and an input / output (I / O) interface. The I / O interface allows external devices that can be connected to the computer device to input and output data. The network adapter / interface provides communication between the computer device and a network, typically represented as a communication network.

[0076] Therefore, those skilled in the art should recognize that although numerous exemplary embodiments of the present invention have been shown and described in detail herein, many other variations or modifications conforming to the principles of the present invention can be directly determined or derived from the disclosure of the present invention without departing from the spirit and scope of the invention. Thus, the scope of the present invention should be understood and construed as covering all such other variations or modifications.

Claims

1. A method for real-time cross-transaction sharing of cursors in an autonomous transaction, comprising: Before the main transaction calls the autonomous transaction, a cursor shared preprocessing process is triggered. The cursor shared preprocessing process is used to store the metadata involved in the target cursor corresponding to the main transaction into a shared hash table and generate a unique identifier for the target cursor. The metadata includes execution status, cross-transaction pointer position, snapshot of cursor associated result set, and lock information. The cross-transaction pointer position is used to record the position of the cursor in the snapshot. When the main transaction invokes the autonomous transaction, the unique identifier is passed to the autonomous transaction; The autonomous transaction retrieves the metadata corresponding to the target cursor by querying the shared hash table based on the unique identifier; The target cursor is operated in real time based on the snapshot and lock information in the metadata, and the cross-transaction pointer position of the target cursor is updated to the shared hash table in real time. When the autonomous transaction is committed or rolled back, the metadata in the shared hash table is locked so that the metadata is not reset when the autonomous transaction ends; The main transaction retrieves the metadata corresponding to the target cursor from the shared hash table based on the unique identifier, continues to operate on the target cursor based on the snapshot in the metadata, and updates the cross-transaction pointer position of the target cursor to the shared hash table in real time, thereby realizing real-time sharing across transactions.

2. The method for real-time cross-transaction sharing of cursors in autonomous transactions according to claim 1, wherein, Also includes: After the autonomous transaction is completed, before returning the target cursor to the main transaction or the upper-level autonomous transaction, a lower-level return preprocessing process is triggered. The lower-level return preprocessing process is used to store the metadata of the target cursor into the shared hash table and mark the resource owner field corresponding to the metadata in the shared hash table as the identifier of the autonomous transaction. Change the owner of the snapshot and the lock information to the main transaction or the upper-level autonomous transaction, and synchronously update the resource owner field; Verify whether the owner has been successfully changed. If the change is successful, return the unique identifier to the main transaction or the upper-level autonomous transaction. The metadata is obtained by the main transaction or the upper-level autonomous transaction by querying the shared hash table based on the unique identifier; The target cursor is operated in real time based on the snapshot and lock information in the metadata, and the cross-transaction pointer position of the target cursor is updated to the shared hash table in real time, thereby realizing real-time sharing across transactions.

3. The method for real-time cross-transaction sharing of cursors in autonomous transactions according to claim 2, wherein, The step of verifying whether the owner change was successful also includes: If the owner change fails, terminate the step of returning the unique identifier to the main transaction or the upper-level autonomous transaction and throw an exception message.

4. The method for real-time cross-transaction sharing of cursors in autonomous transactions according to claim 2, wherein, Also includes: When the upper-level autonomous transaction passes the target cursor to the lower-level autonomous transaction, only the unique identifier is passed, and the owner change operation of the snapshot and the lock information is not performed. The owner remains the upper-level autonomous transaction. When the lower-level autonomous transaction completes the cursor operation and returns the target cursor to the upper-level autonomous transaction, the snapshot and the lock information owner change operation are executed.

5. The method for real-time cross-transaction sharing of cursors in autonomous transactions according to claim 2, wherein, The operation of changing the owner of the snapshot and the lock information is executed through the database system resource permission change interface, or through a custom resource management service interface in a service-oriented manner. The custom resource management service interface is used to adapt to multiple database compatibility scenarios.

6. The method for real-time cross-transaction sharing of cursors in autonomous transactions according to claim 1, wherein, The storage steps of the shared hash table include: A distributed cache is used as the storage medium for the shared hash table to enable the sharing of metadata among multiple nodes.

7. The method for real-time cross-transaction sharing of cursors in autonomous transactions according to claim 1, wherein, Prior to the step of operating the target cursor in real time based on the snapshot and the lock information in the metadata, the method further includes: Obtain the snapshot status flag corresponding to the snapshot. The snapshot status flag is used to indicate whether the snapshot is currently valid, and the snapshot status flag is set to invalid when the database resource corresponding to the snapshot is deleted. When the snapshot status is marked as valid, continue to execute the step of operating the target cursor in real time based on the snapshot and the lock information in the metadata; When the snapshot status is marked as invalid, a snapshot invalidation message is returned.

8. The method for real-time cross-transaction sharing of cursors in autonomous transactions according to claim 1, wherein, The step of passing the unique identifier to the autonomous transaction includes: passing the unique identifier through a function or stored procedure parameter; In an asynchronous transaction collaboration scenario, the step of transmitting the unique identifier to the autonomous transaction further includes: transmitting the unique identifier through a message queue.

9. A computer program product comprising a computer program that, when executed by a processor, implements the steps of the method for real-time cross-transaction sharing of cursors in an autonomous transaction as described in any one of claims 1 to 8.

10. A computer device comprising a memory, a processor, and a computer program stored in the memory and running on the processor, wherein the processor, when executing the computer program, implements the steps of the method for cross-transaction real-time sharing of cursors in an autonomous transaction according to any one of claims 1 to 8.