CN118796805A - Method, device, electronic device and storage medium for realizing data row identification function - Google Patents
Method, device, electronic device and storage medium for realizing data row identification function Download PDFInfo
- Publication number
- CN118796805A CN118796805A CN202311307541.4A CN202311307541A CN118796805A CN 118796805 A CN118796805 A CN 118796805A CN 202311307541 A CN202311307541 A CN 202311307541A CN 118796805 A CN118796805 A CN 118796805A
- Authority
- CN
- China
- Prior art keywords
- rowid
- next value
- auto
- increment sequence
- log file
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/21—Design, administration or maintenance of databases
- G06F16/215—Improving data quality; Data cleansing, e.g. de-duplication, removing invalid entries or correcting typographical errors
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/22—Indexing; Data structures therefor; Storage structures
- G06F16/2282—Tablespace storage structures; Management thereof
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/23—Updating
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Computing Systems (AREA)
- Software Systems (AREA)
- Quality & Reliability (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
Description
技术领域Technical Field
本发明涉及计算机技术领域,尤其涉及一种数据行标识功能的实现方法、装置、电子设备及存储介质。The present invention relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for implementing a data row identification function.
背景技术Background Art
随着科技的不断发展,互联网技术(Internet Technology,IT)系统自主可控受到越来越广泛的关注。数据库自主可控是IT系统自主可控的一个关键环节,当前各行各业应用的数据库以Oracle数据库占比最大,正在逐步向国产数据库、开源数据库切换。With the continuous development of science and technology, the autonomy and controllability of Internet technology (IT) systems have received more and more attention. The autonomy and controllability of databases is a key link in the autonomy and controllability of IT systems. Currently, Oracle databases account for the largest proportion of databases used in various industries, and are gradually switching to domestic databases and open source databases.
目前最主流的开源数据库为PostgreSQL数据库和MySQL数据库,当前各行各业的Oracle数据库主要是切换到基于PostgreSQL或MySQL的国产数据库、PostgreSQL开源数据库、MySQL开源数据库。数据行标识ROWID是Oracle数据库的系统字段,可以用于唯一标识数据库表中一条记录的物理位置,且全局唯一,因此业务应用系统中广泛使用ROWID进行数据表记录更新或删除,以提升效率。The most mainstream open source databases are PostgreSQL and MySQL. Currently, Oracle databases in various industries are mainly switched to domestic databases based on PostgreSQL or MySQL, PostgreSQL open source databases, and MySQL open source databases. The row identifier ROWID is a system field in the Oracle database. It can be used to uniquely identify the physical location of a record in the database table and is globally unique. Therefore, ROWID is widely used in business application systems to update or delete data table records to improve efficiency.
然而,PostgreSQL数据库不提供ROWID系统字段,仅提供功能相近的ctid系统字段,因此当应用系统从Oracle数据库切换到PostgreSQL数据库时,若应用代码中使用到了Oracle数据库的ROWID功能,由于Oracle数据库与PostgreSQL数据库多版本并发控制机制(Multiversion Concurrency Control,MVCC)的差异,在更新PostgreSQL数据库的数据行后,数据行的ctid会发生变化;并且若事务中多次依据ctid更新,将导致产业业务逻辑错误。However, the PostgreSQL database does not provide a ROWID system field, but only a ctid system field with similar functions. Therefore, when the application system is switched from an Oracle database to a PostgreSQL database, if the ROWID function of the Oracle database is used in the application code, due to the difference in the multiversion concurrency control mechanism (Multiversion Concurrency Control, MVCC) between the Oracle database and the PostgreSQL database, the ctid of the data row will change after the data row in the PostgreSQL database is updated; and if the ctid is updated multiple times in a transaction, it will cause industrial business logic errors.
因此,如何实现PostgreSQL数据库的数据行标识ROWID功能是目前亟待解决的问题。Therefore, how to implement the data row identification ROWID function of the PostgreSQL database is a problem that needs to be solved urgently.
发明内容Summary of the invention
针对现有技术存在的问题,本发明提供一种数据行标识功能的实现方法,应用于PostgreSQL数据库服务器,包括:In view of the problems existing in the prior art, the present invention provides a method for implementing a data row identification function, which is applied to a PostgreSQL database server, comprising:
在接收到业务应用系统发起的数据行标识ROWID申请的情况下,从共享内存拉取ROWID中的自增序列的下一个值;When receiving a data row ID ROWID request initiated by the business application system, pull the next value in the auto-increment sequence of ROWID from the shared memory;
将所述ROWID中的自增序列的下一个值返回所述业务应用系统,以使所述业务应用系统根据所述ROWID中的自增序列的下一个值进行数据表记录更新或删除。The next value of the self-increment sequence in the ROWID is returned to the business application system, so that the business application system updates or deletes the data table record according to the next value of the self-increment sequence in the ROWID.
根据本发明提供的一种数据行标识功能的实现方法,在所述从共享内存拉取ROWID中的自增序列的下一个值后,还包括:According to a method for implementing a data row identification function provided by the present invention, after pulling the next value of the auto-increment sequence in the ROWID from the shared memory, the method further includes:
在当前事务未提交的情况下,将所述ROWID中的自增序列的下一个值写入日志文件和磁盘;If the current transaction is not committed, write the next value of the auto-increment sequence in the ROWID to the log file and disk;
在数据库重启的情况下,从所述日志文件加载所述ROWID中的自增序列的下一个值至所述共享内存中。When the database is restarted, the next value of the auto-increment sequence in the ROWID is loaded from the log file into the shared memory.
根据本发明提供的一种数据行标识功能的实现方法,所述将所述ROWID中的自增序列的下一个值写入日志文件和磁盘,包括:According to a method for implementing a data row identification function provided by the present invention, the step of writing the next value of the auto-increment sequence in the ROWID into a log file and a disk comprises:
将所述ROWID中的自增序列的下一个值持久化至日志文件,并判断是否执行数据持久化操作;Persist the next value of the auto-increment sequence in the ROWID to the log file, and determine whether to perform a data persistence operation;
在执行数据持久化操作的情况下,将所述ROWID中的自增序列的下一个值持久化至磁盘。When performing a data persistence operation, the next value of the auto-increment sequence in the ROWID is persisted to the disk.
根据本发明提供的一种数据行标识功能的实现方法,所述将所述ROWID中的自增序列的下一个值持久化至日志文件,包括:According to a method for implementing a data row identification function provided by the present invention, persisting the next value of the auto-increment sequence in the ROWID to a log file includes:
在正在写入日志文件的所述ROWID中的自增序列的下一个值大于当前事务申请的最大ROWID值的情况下,不将所述ROWID中的自增序列的下一个值再次写入所述日志文件;If the next value of the auto-increment sequence in the ROWID being written to the log file is greater than the maximum ROWID value applied by the current transaction, the next value of the auto-increment sequence in the ROWID is not written to the log file again;
在正在写入日志文件的所述ROWID中的自增序列的下一个值小于等于当前事务申请的最大值的情况下,将所述ROWID中的自增序列的下一个值写入所述日志文件,并在所述共享内存中记录正在写日志状态。When the next value of the auto-increment sequence in the ROWID being written to the log file is less than or equal to the maximum value applied by the current transaction, the next value of the auto-increment sequence in the ROWID is written to the log file, and the log writing status is recorded in the shared memory.
根据本发明提供的一种数据行标识功能的实现方法,在所述在当前事务未提交的情况下,将所述ROWID中的自增序列的下一个值写入日志文件和磁盘之后,还包括:According to a method for implementing a data row identification function provided by the present invention, after writing the next value of the auto-increment sequence in the ROWID to a log file and a disk when the current transaction is not committed, the method further includes:
在当前事务已提交的情况下,在共享内存中记录已写入所述日志文件中的所述ROWID中的自增序列的下一个值。When the current transaction has been committed, the next value of the auto-increment sequence in the ROWID that has been written into the log file is recorded in the shared memory.
根据本发明提供的一种数据行标识功能的实现方法,所述从共享内存拉取ROWID中的自增序列的下一个值,包括:According to a method for implementing a data row identification function provided by the present invention, the step of pulling the next value of the auto-increment sequence in the ROWID from the shared memory includes:
采用原子操作或自旋锁模式,从共享内存拉取ROWID中的自增序列的下一个值。Use atomic operations or spin lock mode to pull the next value in the self-increment sequence in ROWID from shared memory.
根据本发明提供的一种数据行标识功能的实现方法,所述将所述ROWID中的自增序列的下一个值返回所述业务应用系统,包括:According to a method for implementing a data row identification function provided by the present invention, returning the next value of the auto-increment sequence in the ROWID to the business application system includes:
采用加密算法对所述ROWID中的自增序列的下一个值进行加密,得到加密数据;Using an encryption algorithm to encrypt the next value of the self-increment sequence in the ROWID to obtain encrypted data;
将所述加密数据返回所述业务应用系统。The encrypted data is returned to the business application system.
本发明还提供一种数据行标识功能的实现装置,应用于PostgreSQL数据库服务器,包括:The present invention also provides a device for implementing a data row identification function, which is applied to a PostgreSQL database server and includes:
拉取模块,用于在接收到业务应用系统发起的数据行标识ROWID申请的情况下,从共享内存拉取ROWID中的自增序列的下一个值;The pull module is used to pull the next value of the auto-increment sequence in the ROWID from the shared memory when receiving the data row identifier ROWID request initiated by the business application system;
返回模块,用于将所述ROWID中的自增序列的下一个值返回所述业务应用系统,以使所述业务应用系统根据所述ROWID中的自增序列的下一个值进行数据表记录更新或删除。The return module is used to return the next value of the auto-increment sequence in the ROWID to the business application system, so that the business application system updates or deletes the data table record according to the next value of the auto-increment sequence in the ROWID.
本发明还提供一种电子设备,包括存储器、处理器及存储在所述存储器上并可在所述处理器上运行的计算机程序,所述处理器执行所述程序时实现如上述任一项所述的数据行标识功能的实现方法的步骤。The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the method for implementing the data row identification function as described in any one of the above items are implemented.
本发明还提供一种非暂态计算机可读存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现如上述任一项所述的数据行标识功能的实现方法的步骤。The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the method for implementing the data row identification function as described in any one of the above items are implemented.
本发明实施例通过PostgreSQL数据库服务器在接收到业务应用系统发起的数据行标识ROWID申请的情况下,从共享内存拉取ROWID中的自增序列的下一个值;将ROWID中的自增序列的下一个值返回业务应用系统,以使业务应用系统根据ROWID中的自增序列的下一个值进行数据表记录更新或删除,从而可以实现在PostgreSQL数据库中基于自增序列实现类似Oracle数据库的ROWID功能,使得PostgreSQL数据库的ROWID与Oracle数据库的ROWID完全兼容。与已有的ctid方案相比,一方面,解决了应用系统从Oracle数据库切换到PostgreSQL数据库时,应用代码改造工作量大的问题;另一方面,在数据表记录进行更新后,表记录的ROWID依然保持不变,不会造成事务内的第二次基于ROWID的更新失败,对业务无影响,从而解决了表记录的citd随更新后发生变更的问题。In the embodiment of the present invention, when a PostgreSQL database server receives a data row identifier ROWID application initiated by a business application system, the server pulls the next value of the auto-increment sequence in the ROWID from the shared memory; returns the next value of the auto-increment sequence in the ROWID to the business application system, so that the business application system updates or deletes the data table record according to the next value of the auto-increment sequence in the ROWID, thereby realizing a ROWID function similar to that of the Oracle database based on the auto-increment sequence in the PostgreSQL database, so that the ROWID of the PostgreSQL database is fully compatible with the ROWID of the Oracle database. Compared with the existing ctid solution, on the one hand, it solves the problem of large workload of application code transformation when the application system switches from the Oracle database to the PostgreSQL database; on the other hand, after the data table record is updated, the ROWID of the table record remains unchanged, which will not cause the failure of the second ROWID-based update in the transaction and has no impact on the business, thereby solving the problem of the citd of the table record changing after the update.
附图说明BRIEF DESCRIPTION OF THE DRAWINGS
为了更清楚地说明本发明或现有技术中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作一简单地介绍,显而易见地,下面描述中的附图是本发明的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
图1是现有技术中的事务内基于ctid第二次更新失败的示意图;FIG1 is a schematic diagram of a second ctid-based update failure in a transaction in the prior art;
图2是本发明实施例提供的数据行标识功能的实现方法的流程示意图;2 is a schematic flow chart of a method for implementing a data row identification function provided by an embodiment of the present invention;
图3是本发明实施例提供的数据行标识ROWID的物理结构示意图;3 is a schematic diagram of the physical structure of a data row identifier ROWID provided in an embodiment of the present invention;
图4是本发明实施例提供的ROWID生成流程示意图;FIG4 is a schematic diagram of a ROWID generation process according to an embodiment of the present invention;
图5是本发明实施例提供的ROWID申请的整体架构图;FIG5 is an overall architecture diagram of a ROWID application provided in an embodiment of the present invention;
图6是本发明实施例提供的数据行标识功能的实现装置的结构示意图;6 is a schematic diagram of the structure of a device for implementing a data row identification function provided by an embodiment of the present invention;
图7是本发明实施例提供的电子设备的结构示意图。FIG. 7 is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention.
具体实施方式DETAILED DESCRIPTION
为使本发明的目的、技术方案和优点更加清楚,下面将结合本发明中的附图,对本发明中的技术方案进行清楚、完整地描述,显然,所描述的实施例是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人员在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
PostgreSQL数据库的ctid系统字段和ROWID系统字段类似,都是用来定位数据库一条记录的的物理位置,但表数据的ctid系统字段会随表数据更新(update)后发生变化,造成ctid系统字段变化的根本原因是PostgreSQL数据库和Oracle数据库的多版本并发控制机制(MVCC)存在差异,Oracle数据库的MVCC机制通过undo表空间实现,当update表数据时,老版本的数据会存储在undo表空间,PostgreSQL数据库的MVCC机制没有undo表空间,当update表数据时,老版本的数据依然存在老的数据块上,只是将这条老版本的记录标记为不可用,再向数据块的另外一个位置插入update后的新版本数据,造成了表数据物理位置的变更,ctid系统字段随之发生改变。The ctid system field of the PostgreSQL database is similar to the ROWID system field. Both are used to locate the physical location of a record in the database. However, the ctid system field of the table data will change after the table data is updated. The fundamental reason for the change in the ctid system field is the difference in the multi-version concurrency control mechanism (MVCC) between the PostgreSQL database and the Oracle database. The MVCC mechanism of the Oracle database is implemented through the undo tablespace. When the table data is updated, the old version of the data will be stored in the undo tablespace. The MVCC mechanism of the PostgreSQL database does not have an undo tablespace. When the table data is updated, the old version of the data still exists on the old data block, but the old version of the record is marked as unavailable, and then the updated new version of the data is inserted into another position of the data block, resulting in a change in the physical location of the table data, and the ctid system field changes accordingly.
然而,通过ctid系统字段实现的ROWID功能,存在以下两个问题:However, the ROWID function implemented through the ctid system field has the following two problems:
(1)应用需要进行代码改造,改造工作量大:PostgreSQL数据库不提供ROWID功能,当应用系统从Oracle数据库切换到PostgreSQL数据库时,需要对应用代码进行改造,将应用代码中根据ROWID检索的SQL代码改造成根据ctid检索,大幅增加了应用系统改造工作量。(1) Application code needs to be modified, which requires a lot of work: The PostgreSQL database does not provide the ROWID function. When the application system is switched from the Oracle database to the PostgreSQL database, the application code needs to be modified. The SQL code that searches based on ROWID in the application code needs to be modified to search based on ctid, which greatly increases the workload of the application system modification.
(2)事务内基于ctid第二次更新失败:图1是现有技术中的事务内基于ctid第二次更新失败的示意图。参照图1,同一个事务内根据同一个ctid系统字段多次update表数据时,由于PostgreSQL数据库的MVCC机制,第一次更新后表数据的ctid会发生变更,导致后续再次根据该ctid进行更新时找不到对应记录,从而产生业务逻辑异常,对业务有影响。(2) The second update based on ctid in a transaction fails: Figure 1 is a schematic diagram of the second update based on ctid in a transaction in the prior art. Referring to Figure 1, when the table data is updated multiple times based on the same ctid system field in the same transaction, due to the MVCC mechanism of the PostgreSQL database, the ctid of the table data will change after the first update, resulting in the failure to find the corresponding record when the ctid is subsequently updated again, thereby causing business logic anomalies and affecting the business.
本发明实施例的核心构思在于,在PostgreSQL数据库中基于自增序列实现类似Oracle数据库的ROWID功能,使得PostgreSQL数据库的ROWID与Oracle数据库的ROWID完全兼容。与已有的ctid方案相比,一方面,解决了应用系统从Oracle数据库切换到PostgreSQL数据库时,应用代码改造工作量大的问题;另一方面,在数据表记录进行更新后,表记录的ROWID依然保持不变,不会造成事务内的第二次基于ROWID的更新失败,对业务无影响,从而解决了表记录的citd随更新后发生变更的问题。The core concept of the embodiment of the present invention is to implement a ROWID function similar to that of an Oracle database based on an auto-increment sequence in a PostgreSQL database, so that the ROWID of the PostgreSQL database is fully compatible with the ROWID of the Oracle database. Compared with the existing ctid solution, on the one hand, it solves the problem of heavy workload of application code transformation when the application system switches from an Oracle database to a PostgreSQL database; on the other hand, after the data table record is updated, the ROWID of the table record remains unchanged, which will not cause the second ROWID-based update failure in the transaction and has no impact on the business, thereby solving the problem of the citd of the table record changing after the update.
图2是本发明实施例提供的数据行标识功能的实现方法的流程示意图。参照图2,本发明实施例提供一种数据行标识功能的实现方法,应用于PostgreSQL数据库服务器,所述方法具体可以包括如下步骤:Fig. 2 is a flow chart of a method for implementing a data row identification function provided by an embodiment of the present invention. Referring to Fig. 2, an embodiment of the present invention provides a method for implementing a data row identification function, which is applied to a PostgreSQL database server. The method may specifically include the following steps:
步骤201,在接收到业务应用系统发起的数据行标识ROWID申请的情况下,从共享内存拉取ROWID中的自增序列的下一个值。Step 201, when receiving a data row identifier ROWID request initiated by a business application system, pull the next value of the auto-increment sequence in the ROWID from the shared memory.
本发明实施例提供的数据行标识功能的实现方法可以应用于PostgreSQL数据库服务器,业务应用系统可以发起ROWID申请,PostgreSQL数据库服务器可以从共享内存拉取ROWID中的自增序列的下一个值,将自增序列的下一个值返回业务应用系统,从而实现PostgreSQL数据库的数据行标识ROWID功能。The implementation method of the data row identification function provided by the embodiment of the present invention can be applied to a PostgreSQL database server. The business application system can initiate a ROWID request. The PostgreSQL database server can pull the next value of the auto-increment sequence in the ROWID from the shared memory and return the next value of the auto-increment sequence to the business application system, thereby implementing the data row identification ROWID function of the PostgreSQL database.
当业务应用系统发起结构化查询语言(Structured Query Language,SQL)操作时,PostgreSQL数据库引擎可以发起SQL解析,在解析结果为数据插入操作,即为数据行标识ROWID申请的情况下,可以从共享内存拉取最新ROWID。When the business application system initiates a Structured Query Language (SQL) operation, the PostgreSQL database engine can initiate SQL parsing. When the parsing result is a data insertion operation, that is, a data row identifier ROWID application, the latest ROWID can be pulled from the shared memory.
图3是本发明实施例提供的数据行标识ROWID的物理结构示意图。参照图3,ROWID可以采用64位无符号整型数字进行表示,ROWID可以由“高N位”和“低N位”组成,“高N位”可以表示对象ID(Identity Document,身份标识),“低N位”可以表示自增序列。Fig. 3 is a schematic diagram of the physical structure of a data row identifier ROWID provided by an embodiment of the present invention. Referring to Fig. 3, ROWID can be represented by a 64-bit unsigned integer, and ROWID can be composed of "high N bits" and "low N bits", "high N bits" can represent an object ID (Identity Document, identity identification), and "low N bits" can represent a self-incrementing sequence.
具体的,在调用ROWID中的自增序列时,可以采用nextval方法来获取序列的下一个值。每次调用nextval方法,序列可以自动递增并返回生成的下一个值。在本发明实施例中,ROWID中的自增序列的下一个值可以采用next ROWID进行表示。Specifically, when calling the auto-increment sequence in ROWID, the nextval method can be used to obtain the next value of the sequence. Each time the nextval method is called, the sequence can be automatically incremented and return the next value generated. In an embodiment of the present invention, the next value of the auto-increment sequence in ROWID can be represented by next ROWID.
数据行标识ROWID的“低N位”可以使用全局会话变量(Global UnifiedConfiguration variable,GUC)default_with_rowid_id,数据位每次可以加1并保存在共享内存中。在业务应用系统每次申请新的ROWID值时,可以更新共享内存中的next ROWID值(使用自旋锁保护),从而保证服务重启后不会生成以前重复的值。The "low N bits" of the row ID ROWID can use the global session variable (Global Unified Configuration variable, GUC) default_with_rowid_id, and the data bit can be increased by 1 each time and saved in the shared memory. Each time the business application system requests a new ROWID value, the next ROWID value in the shared memory can be updated (using a spin lock for protection), thereby ensuring that the previous duplicate value will not be generated after the service is restarted.
在本发明实施例中,ROWID字段可以设置为虚拟列,用户不可更改,不可指定。In the embodiment of the present invention, the ROWID field can be set as a virtual column, which cannot be changed or specified by the user.
步骤202,将所述ROWID中的自增序列的下一个值返回所述业务应用系统,以使所述业务应用系统根据所述ROWID中的自增序列的下一个值进行数据表记录更新或删除。Step 202: Return the next value of the auto-increment sequence in the ROWID to the business application system, so that the business application system updates or deletes the data table record according to the next value of the auto-increment sequence in the ROWID.
PostgreSQL数据库服务器从共享内存拉取ROWID中的自增序列的下一个值后,可以将ROWID中的自增序列的下一个值返回至发起ROWID申请的业务应用系统,使得业务应用系统可以根据自增序列的下一个值进行数据表记录更新或删除。After the PostgreSQL database server pulls the next value of the auto-increment sequence in the ROWID from the shared memory, it can return the next value of the auto-increment sequence in the ROWID to the business application system that initiated the ROWID request, so that the business application system can update or delete data table records according to the next value of the auto-increment sequence.
本发明实施例通过PostgreSQL数据库服务器在接收到业务应用系统发起的数据行标识ROWID申请的情况下,从共享内存拉取ROWID中的自增序列的下一个值;将ROWID中的自增序列的下一个值返回业务应用系统,以使业务应用系统根据ROWID中的自增序列的下一个值进行数据表记录更新或删除,从而可以实现在PostgreSQL数据库中基于自增序列实现类似Oracle数据库的ROWID功能,使得PostgreSQL数据库的ROWID与Oracle数据库的ROWID完全兼容。与已有的ctid方案相比,一方面,解决了应用系统从Oracle数据库切换到PostgreSQL数据库时,应用代码改造工作量大的问题;另一方面,在数据表记录进行更新后,表记录的ROWID依然保持不变,不会造成事务内的第二次基于ROWID的更新失败,对业务无影响,从而解决了表记录的citd随更新后发生变更的问题。In the embodiment of the present invention, when a PostgreSQL database server receives a data row identifier ROWID application initiated by a business application system, the server pulls the next value of the auto-increment sequence in the ROWID from the shared memory; returns the next value of the auto-increment sequence in the ROWID to the business application system, so that the business application system updates or deletes the data table record according to the next value of the auto-increment sequence in the ROWID, thereby realizing a ROWID function similar to that of the Oracle database based on the auto-increment sequence in the PostgreSQL database, so that the ROWID of the PostgreSQL database is fully compatible with the ROWID of the Oracle database. Compared with the existing ctid solution, on the one hand, it solves the problem of large workload of application code transformation when the application system switches from the Oracle database to the PostgreSQL database; on the other hand, after the data table record is updated, the ROWID of the table record remains unchanged, which will not cause the failure of the second ROWID-based update in the transaction and has no impact on the business, thereby solving the problem of the citd of the table record changing after the update.
在一种可选的实施例中在所述从共享内存拉取ROWID中的自增序列的下一个值后,还包括:在当前事务未提交的情况下,将所述ROWID中的自增序列的下一个值写入日志文件和磁盘;在数据库重启的情况下,从所述日志文件加载所述ROWID中的自增序列的下一个值至所述共享内存中。In an optional embodiment, after pulling the next value of the auto-increment sequence in the ROWID from the shared memory, it also includes: when the current transaction is not committed, writing the next value of the auto-increment sequence in the ROWID to the log file and disk; when the database is restarted, loading the next value of the auto-increment sequence in the ROWID from the log file to the shared memory.
图4是本发明实施例提供的ROWID生成流程示意图。参照图4,业务应用系统中,业务A可以发起ROWID申请,业务B可以发起ROWID申请,业务X可以发起ROWID申请。可以调用nextval方法,从共享内存获取ROWID中的自增序列的下一个值,并判断当前事务是否已提交。如果当前事务未提交,可以将从共享内存获取的ROWID中的自增序列的下一个值写入预写式日志(Write-Ahead Logging,WAL)和磁盘。FIG4 is a schematic diagram of a ROWID generation process provided by an embodiment of the present invention. Referring to FIG4, in a business application system, business A can initiate a ROWID application, business B can initiate a ROWID application, and business X can initiate a ROWID application. The nextval method can be called to obtain the next value of the auto-increment sequence in the ROWID from the shared memory, and determine whether the current transaction has been committed. If the current transaction is not committed, the next value of the auto-increment sequence in the ROWID obtained from the shared memory can be written to the write-ahead log (WAL) and the disk.
在数据库异常宕机或数据库重启的情况下,PostgreSQL数据库可以依据WAL日志文件进行恢复,并加载最新ROWID信息(即最新的ROWID中的自增序列的下一个值)到共享内存,从而保证获取到的ROWID是最新的。每次重启可以从日志文件中获取最大的next ROWID值(即ROWID中的自增序列的下一个值),替换共享内存中的值。In the case of abnormal database downtime or database restart, the PostgreSQL database can be restored based on the WAL log file and load the latest ROWID information (that is, the next value in the auto-increment sequence of the latest ROWID) into the shared memory to ensure that the obtained ROWID is the latest. Each restart can obtain the largest next ROWID value (that is, the next value in the auto-increment sequence of ROWID) from the log file and replace the value in the shared memory.
在一种可选的实施例中,所述将所述ROWID中的自增序列的下一个值写入日志文件和磁盘,包括:将所述ROWID中的自增序列的下一个值持久化至日志文件,并判断是否执行数据持久化操作;在执行数据持久化操作的情况下,将所述ROWID中的自增序列的下一个值持久化至磁盘。In an optional embodiment, writing the next value of the auto-increment sequence in the ROWID to a log file and a disk includes: persisting the next value of the auto-increment sequence in the ROWID to a log file, and determining whether to perform a data persistence operation; and if performing a data persistence operation, persisting the next value of the auto-increment sequence in the ROWID to a disk.
请继续参照图4,在实际应用中,数据持久化操作可以是指checkpoint操作。如果当前事务未提交,可以将自增序列的下一个值持久化至日志文件,并判断是否执行checkpoint操作。如果执行checkpoint操作,可以将自增序列的下一个值持久化至磁盘。Please continue to refer to FIG. 4. In actual applications, the data persistence operation may refer to a checkpoint operation. If the current transaction is not committed, the next value of the auto-increment sequence may be persisted to a log file, and it is determined whether to perform a checkpoint operation. If a checkpoint operation is performed, the next value of the auto-increment sequence may be persisted to a disk.
在本发明实施例中,每次checkpoint时可以保存next ROWID,以便服务重启后恢复下一个值。In the embodiment of the present invention, the next ROWID may be saved each time a checkpoint is performed so that the next value can be restored after the service is restarted.
在一种可选的实施例中,所述将所述ROWID中的自增序列的下一个值持久化至日志文件,包括:在正在写入日志文件的所述ROWID中的自增序列的下一个值大于当前事务申请的最大ROWID值的情况下,不将所述ROWID中的自增序列的下一个值再次写入所述日志文件;在正在写入日志文件的所述ROWID中的自增序列的下一个值小于等于当前事务申请的最大值的情况下,将所述ROWID中的自增序列的下一个值写入所述日志文件,并在所述共享内存中记录正在写日志状态。In an optional embodiment, persisting the next value of the auto-increment sequence in the ROWID to the log file includes: when the next value of the auto-increment sequence in the ROWID being written to the log file is greater than the maximum ROWID value applied for the current transaction, not writing the next value of the auto-increment sequence in the ROWID to the log file again; when the next value of the auto-increment sequence in the ROWID being written to the log file is less than or equal to the maximum value applied for the current transaction, writing the next value of the auto-increment sequence in the ROWID to the log file, and recording the log writing status in the shared memory.
在本发明实施例中,可以进行ROWID的日志优化。具体的,为了减少写日志的次数,单个进程可以记录本身最后申请的ROWID,写日志前可以比较正在写或已写入WAL日志文件的next ROWID(即ROWID中的自增序列的下一个值)是否大于本事务申请的最大ROWID值。In the embodiment of the present invention, ROWID log optimization can be performed. Specifically, in order to reduce the number of log writing, a single process can record the ROWID it applied for last, and before writing the log, it can compare whether the next ROWID being written or written to the WAL log file (i.e., the next value in the auto-increment sequence in the ROWID) is greater than the maximum ROWID value applied for by the current transaction.
如果正在写或已写入WAL日志文件的next ROWID大于本事务申请的最大ROWID值,可以无需再次写入WAL日志文件。If the next ROWID that is being written or has been written to the WAL log file is greater than the maximum ROWID value requested by this transaction, there is no need to write to the WAL log file again.
如果正在写或已写入WAL日志文件的next ROWID小于等于本事务申请的最大ROWID值,可以取共享内存中的next ROWID写入WAL日志文件,并在共享内存中记录正在写WAL日志文件。If the next ROWID being written or already written to the WAL log file is less than or equal to the maximum ROWID value requested by this transaction, the next ROWID in the shared memory can be taken and written to the WAL log file, and the shared memory is recorded as being written to the WAL log file.
在本发明实施例中,ROWID序列每次写入WAL日志文件,但可以不执行强制写盘,因为事务提交时会强制写盘,即便回滚重用也不会冲突,重启后可以保留WAL日志文件中最大ROWID值恢复共享内存中。In an embodiment of the present invention, the ROWID sequence is written to the WAL log file each time, but forced writing to disk may not be performed because the disk is forced to be written when the transaction is committed, and there will be no conflict even if it is rolled back and reused. After restarting, the maximum ROWID value in the WAL log file can be retained and restored to the shared memory.
在一种可选的实施例中,在所述在当前事务未提交的情况下,将所述ROWID中的自增序列的下一个值写入日志文件和磁盘之后,还包括:在当前事务已提交的情况下,在共享内存中记录已写入所述日志文件中的所述ROWID中的自增序列的下一个值。In an optional embodiment, after writing the next value of the auto-increment sequence in the ROWID to the log file and the disk when the current transaction is not committed, it also includes: when the current transaction is committed, recording in the shared memory the next value of the auto-increment sequence in the ROWID that has been written to the log file.
请继续参照图4,在当前事务未提交时将ROWID中的自增序列的下一个值写入日志文件和磁盘,并在共享内存中记录正在写WAL日志文件之后,如果当前事务已提交,可以在共享内存中记录已写入WAL日志文件中的next ROWID(即ROWID中的自增序列的下一个值)。Please continue to refer to Figure 4. When the current transaction is not committed, the next value of the auto-increment sequence in ROWID is written to the log file and disk, and the WAL log file is recorded in the shared memory. If the current transaction is committed, the next ROWID (that is, the next value of the auto-increment sequence in ROWID) written to the WAL log file can be recorded in the shared memory.
在一种可选的实施例中,所述从共享内存拉取ROWID中的自增序列的下一个值,包括:采用原子操作或自旋锁模式,从共享内存拉取ROWID中的自增序列的下一个值。In an optional embodiment, pulling the next value of the self-increment sequence in the ROWID from the shared memory includes: using an atomic operation or a spin lock mode to pull the next value of the self-increment sequence in the ROWID from the shared memory.
在本发明实施例中,数据行标识ROWID序列保存在共享内存中,可在从共享内存拉取ROWID的过程中,可以使用原子操作或自旋锁解决冲突,从而避免并发申请ROWID时资源争用的问题。In an embodiment of the present invention, a data row identifier ROWID sequence is stored in a shared memory. In the process of pulling ROWID from the shared memory, atomic operations or spin locks can be used to resolve conflicts, thereby avoiding the problem of resource contention when concurrently applying for ROWID.
在一种可选的实施例中,所述将所述ROWID中的自增序列的下一个值返回所述业务应用系统,包括:采用加密算法对所述ROWID中的自增序列的下一个值进行加密,得到加密数据;将所述加密数据返回所述业务应用系统。In an optional embodiment, returning the next value of the self-increment sequence in the ROWID to the business application system includes: encrypting the next value of the self-increment sequence in the ROWID using an encryption algorithm to obtain encrypted data; and returning the encrypted data to the business application system.
在本发明实施例中,ROWID由对象ID+自增序列组成,每次从共享内存中获取自增序列的下一个值后,可以采用加密算法进行加密,得到加密数据并将加密数据返回业务应用。In the embodiment of the present invention, ROWID is composed of object ID + auto-increment sequence. Each time after the next value of the auto-increment sequence is obtained from the shared memory, an encryption algorithm can be used to encrypt it to obtain encrypted data and return the encrypted data to the business application.
图5是本发明实施例提供的ROWID申请的整体架构图。参照图5,可以设置ROWID生成中心虚拟模块,ROWID生成虚拟模块可以由ROWID生成单元和ROWID持久化单元组成。当业务应用系统发起SQL操作时,数据库引擎可以进行SQL解析及判断。Fig. 5 is an overall architecture diagram of the ROWID application provided by an embodiment of the present invention. Referring to Fig. 5, a ROWID generation center virtual module may be set, and the ROWID generation virtual module may be composed of a ROWID generation unit and a ROWID persistence unit. When the business application system initiates an SQL operation, the database engine may perform SQL parsing and judgment.
当涉及数据插入的场景时,可以向ROWID生成中心虚拟模块申请ROWID。其中,ROWID生成单元可以向共享内存拉取最新ROWID,拉取ROWID过程中可以通过自旋锁模式避免并发申请ROWID时资源争用;ROWID持久化单元可以将共享内存的最新ROWID写入WAL日志文件和磁盘,当事务提交或执行checkpoint时发起。When data insertion is involved, you can apply for ROWID from the ROWID generation center virtual module. The ROWID generation unit can pull the latest ROWID from the shared memory. During the ROWID pulling process, the spin lock mode can be used to avoid resource contention when concurrently applying for ROWID; the ROWID persistence unit can write the latest ROWID in the shared memory to the WAL log file and disk, which is initiated when the transaction is committed or the checkpoint is executed.
当数据库异常宕机或数据库重启时,PostgreSQL数据库可以依据WAL日志文件进行恢复及加载最新ROWID信息到共享内存,从而保证获取到的ROWID是最新的。When the database crashes abnormally or is restarted, the PostgreSQL database can recover based on the WAL log file and load the latest ROWID information into the shared memory, thus ensuring that the obtained ROWID is the latest.
本发明实施例通过PostgreSQL数据库服务器在接收到业务应用系统发起的数据行标识ROWID申请的情况下,从共享内存拉取ROWID中的自增序列的下一个值;将ROWID中的自增序列的下一个值返回业务应用系统,以使业务应用系统根据ROWID中的自增序列的下一个值进行数据表记录更新或删除,从而可以实现在PostgreSQL数据库中基于自增序列实现类似Oracle数据库的ROWID功能,使得PostgreSQL数据库的ROWID与Oracle数据库的ROWID完全兼容。与已有的ctid方案相比,一方面,解决了应用系统从Oracle数据库切换到PostgreSQL数据库时,应用代码改造工作量大的问题;另一方面,在数据表记录进行更新后,表记录的ROWID依然保持不变,不会造成事务内的第二次基于ROWID的更新失败,对业务无影响,从而解决了表记录的citd随更新后发生变更的问题。In the embodiment of the present invention, when a PostgreSQL database server receives a data row identifier ROWID application initiated by a business application system, the server pulls the next value of the auto-increment sequence in the ROWID from the shared memory; returns the next value of the auto-increment sequence in the ROWID to the business application system, so that the business application system updates or deletes the data table record according to the next value of the auto-increment sequence in the ROWID, thereby realizing a ROWID function similar to that of the Oracle database based on the auto-increment sequence in the PostgreSQL database, so that the ROWID of the PostgreSQL database is fully compatible with the ROWID of the Oracle database. Compared with the existing ctid solution, on the one hand, it solves the problem of large workload of application code transformation when the application system switches from the Oracle database to the PostgreSQL database; on the other hand, after the data table record is updated, the ROWID of the table record remains unchanged, which will not cause the failure of the second ROWID-based update in the transaction and has no impact on the business, thereby solving the problem of the citd of the table record changing after the update.
下面对本发明提供的数据行标识功能的实现装置进行描述,下文描述的数据行标识功能的实现装置与上文描述的数据行标识功能的实现方法可相互对应参照。The following describes an implementation device for the data row identification function provided by the present invention. The implementation device for the data row identification function described below and the implementation method for the data row identification function described above can refer to each other.
图6是本发明实施例提供的数据行标识功能的实现装置的结构示意图。参照图6,本发明实施例提供一种数据行标识功能的实现装置,所述装置具体可以包括如下模块:FIG6 is a schematic diagram of the structure of a device for implementing a data row identification function provided by an embodiment of the present invention. Referring to FIG6 , an embodiment of the present invention provides a device for implementing a data row identification function, and the device may specifically include the following modules:
拉取模块601,用于在接收到业务应用系统发起的数据行标识ROWID申请的情况下,从共享内存拉取ROWID中的自增序列的下一个值;The pulling module 601 is used to pull the next value of the auto-increment sequence in the ROWID from the shared memory when receiving a data row identifier ROWID request initiated by the business application system;
返回模块602,用于将所述ROWID中的自增序列的下一个值返回所述业务应用系统,以使所述业务应用系统根据所述ROWID中的自增序列的下一个值进行数据表记录更新或删除。The return module 602 is used to return the next value of the auto-increment sequence in the ROWID to the business application system, so that the business application system updates or deletes the data table record according to the next value of the auto-increment sequence in the ROWID.
在一种可选的实施例中,在所述从共享内存拉取ROWID中的自增序列的下一个值后,还包括:In an optional embodiment, after pulling the next value of the auto-increment sequence in the ROWID from the shared memory, the method further includes:
写入模块,用于在当前事务未提交的情况下,将所述ROWID中的自增序列的下一个值写入日志文件和磁盘;A writing module, used for writing the next value of the auto-increment sequence in the ROWID into a log file and a disk when the current transaction is not committed;
加载模块,用于在数据库重启的情况下,从所述日志文件加载所述ROWID中的自增序列的下一个值至所述共享内存中。A loading module is used to load the next value of the auto-increment sequence in the ROWID from the log file into the shared memory when the database is restarted.
在一种可选的实施例中,所述写入模块,包括:In an optional embodiment, the writing module includes:
日志写入子模块,用于将所述ROWID中的自增序列的下一个值持久化至日志文件,并判断是否执行数据持久化操作;The log writing submodule is used to persist the next value of the auto-increment sequence in the ROWID to the log file and determine whether to perform the data persistence operation;
磁盘写入子模块,用于在执行数据持久化操作的情况下,将所述ROWID中的自增序列的下一个值持久化至磁盘。The disk writing submodule is used to persist the next value of the auto-increment sequence in the ROWID to the disk when performing a data persistence operation.
在一种可选的实施例中,所述日志写入子模块,包括:In an optional embodiment, the log writing submodule includes:
不写入单元,用于在正在写入日志文件的所述ROWID中的自增序列的下一个值大于当前事务申请的最大ROWID值的情况下,不将所述ROWID中的自增序列的下一个值再次写入所述日志文件;a non-writing unit, configured to not write the next value of the self-increment sequence in the ROWID being written into the log file again if the next value of the self-increment sequence in the ROWID being written into the log file is greater than the maximum ROWID value applied by the current transaction;
状态记录单元,用于在正在写入日志文件的所述ROWID中的自增序列的下一个值小于等于当前事务申请的最大值的情况下,将所述ROWID中的自增序列的下一个值写入所述日志文件,并在所述共享内存中记录正在写日志状态。A status recording unit is used to write the next value of the self-increment sequence in the ROWID being written to the log file and record the log writing status in the shared memory when the next value of the self-increment sequence in the ROWID being written to the log file is less than or equal to the maximum value applied by the current transaction.
在一种可选的实施例中,在所述在当前事务未提交的情况下,将所述ROWID中的自增序列的下一个值写入日志文件和磁盘之后,还包括:In an optional embodiment, after writing the next value of the auto-increment sequence in the ROWID to the log file and the disk when the current transaction is not committed, the method further includes:
内存记录模块,用于在当前事务已提交的情况下,在共享内存中记录已写入所述日志文件中的所述ROWID中的自增序列的下一个值。The memory recording module is used to record in the shared memory the next value of the auto-increment sequence in the ROWID that has been written into the log file when the current transaction has been committed.
在一种可选的实施例中,所述拉取模块,包括:In an optional embodiment, the pulling module includes:
自旋锁拉取子模块,用于采用原子操作或自旋锁模式,从共享内存拉取ROWID中的自增序列的下一个值。The spin lock pull submodule is used to pull the next value of the self-increment sequence in ROWID from the shared memory using atomic operations or spin lock mode.
在一种可选的实施例中,所述加载模块,包括:In an optional embodiment, the loading module includes:
加密子模块,用于采用加密算法对所述ROWID中的自增序列的下一个值进行加密,得到加密数据;An encryption submodule, used for encrypting the next value of the self-increment sequence in the ROWID using an encryption algorithm to obtain encrypted data;
数据返回子模块,用于将所述加密数据返回所述业务应用系统。The data return submodule is used to return the encrypted data to the business application system.
本发明实施例通过PostgreSQL数据库服务器在接收到业务应用系统发起的数据行标识ROWID申请的情况下,从共享内存拉取ROWID中的自增序列的下一个值;将ROWID中的自增序列的下一个值返回业务应用系统,以使业务应用系统根据ROWID中的自增序列的下一个值进行数据表记录更新或删除,从而可以实现在PostgreSQL数据库中基于自增序列实现类似Oracle数据库的ROWID功能,使得PostgreSQL数据库的ROWID与Oracle数据库的ROWID完全兼容。与已有的ctid方案相比,一方面,解决了应用系统从Oracle数据库切换到PostgreSQL数据库时,应用代码改造工作量大的问题;另一方面,在数据表记录进行更新后,表记录的ROWID依然保持不变,不会造成事务内的第二次基于ROWID的更新失败,对业务无影响,从而解决了表记录的citd随更新后发生变更的问题。In the embodiment of the present invention, when a PostgreSQL database server receives a data row identifier ROWID application initiated by a business application system, the server pulls the next value of the auto-increment sequence in the ROWID from the shared memory; returns the next value of the auto-increment sequence in the ROWID to the business application system, so that the business application system updates or deletes the data table record according to the next value of the auto-increment sequence in the ROWID, thereby realizing a ROWID function similar to that of the Oracle database based on the auto-increment sequence in the PostgreSQL database, so that the ROWID of the PostgreSQL database is fully compatible with the ROWID of the Oracle database. Compared with the existing ctid solution, on the one hand, it solves the problem of large workload of application code transformation when the application system switches from the Oracle database to the PostgreSQL database; on the other hand, after the data table record is updated, the ROWID of the table record remains unchanged, which will not cause the failure of the second ROWID-based update in the transaction and has no impact on the business, thereby solving the problem of the citd of the table record changing after the update.
图7示例了一种电子设备的实体结构示意图,如图7所示,该电子设备可以包括:处理器(processor)710、通信接口(Communications Interface)720、存储器(memory)730和通信总线740,其中,处理器710,通信接口720,存储器730通过通信总线740完成相互间的通信。处理器710可以调用存储器730中的逻辑指令,以执行数据行标识功能的实现方法,所述方法包括:FIG7 illustrates a schematic diagram of the physical structure of an electronic device. As shown in FIG7 , the electronic device may include: a processor 710, a communications interface 720, a memory 730, and a communication bus 740, wherein the processor 710, the communications interface 720, and the memory 730 communicate with each other through the communication bus 740. The processor 710 may call the logic instructions in the memory 730 to execute a method for implementing a data row identification function, and the method includes:
在接收到业务应用系统发起的数据行标识ROWID申请的情况下,从共享内存拉取ROWID中的自增序列的下一个值;When receiving a data row ID ROWID request initiated by the business application system, pull the next value in the auto-increment sequence of ROWID from the shared memory;
将所述ROWID中的自增序列的下一个值返回所述业务应用系统,以使所述业务应用系统根据所述ROWID中的自增序列的下一个值进行数据表记录更新或删除。The next value of the self-increment sequence in the ROWID is returned to the business application system, so that the business application system updates or deletes the data table record according to the next value of the self-increment sequence in the ROWID.
此外,上述的存储器730中的逻辑指令可以通过软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行本发明各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:U盘、移动硬盘、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、磁碟或者光盘等各种可以存储程序代码的介质。In addition, the logic instructions in the above-mentioned memory 730 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
又一方面,本发明还提供一种非暂态计算机可读存储介质,其上存储有计算机程序,该计算机程序被处理器执行时实现以执行上述各方法提供的数据行标识功能的实现方法,所述方法包括:In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements a method for implementing the data row identification function provided by the above methods, the method comprising:
在接收到业务应用系统发起的数据行标识ROWID申请的情况下,从共享内存拉取ROWID中的自增序列的下一个值;When receiving a data row ID ROWID request initiated by the business application system, pull the next value in the auto-increment sequence of ROWID from the shared memory;
将所述ROWID中的自增序列的下一个值返回所述业务应用系统,以使所述业务应用系统根据所述ROWID中的自增序列的下一个值进行数据表记录更新或删除。The next value of the self-increment sequence in the ROWID is returned to the business application system, so that the business application system updates or deletes the data table record according to the next value of the self-increment sequence in the ROWID.
以上所描述的装置实施例仅仅是示意性的,其中所述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。本领域普通技术人员在不付出创造性的劳动的情况下,即可以理解并实施。The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到各实施方式可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件。基于这样的理解,上述技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品可以存储在计算机可读存储介质中,如ROM/RAM、磁碟、光盘等,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)执行各个实施例或者实施例的某些部分所述的方法。Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM/RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
最后应说明的是:以上实施例仅用以说明本发明的技术方案,而非对其限制;尽管参照前述实施例对本发明进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本发明各实施例技术方案的精神和范围。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims (10)
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311307541.4A CN118796805A (en) | 2023-10-08 | 2023-10-08 | Method, device, electronic device and storage medium for realizing data row identification function |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311307541.4A CN118796805A (en) | 2023-10-08 | 2023-10-08 | Method, device, electronic device and storage medium for realizing data row identification function |
Publications (1)
Publication Number | Publication Date |
---|---|
CN118796805A true CN118796805A (en) | 2024-10-18 |
Family
ID=93022305
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202311307541.4A Pending CN118796805A (en) | 2023-10-08 | 2023-10-08 | Method, device, electronic device and storage medium for realizing data row identification function |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN118796805A (en) |
-
2023
- 2023-10-08 CN CN202311307541.4A patent/CN118796805A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN111143389B (en) | Transaction execution method and device, computer equipment and storage medium | |
US11429641B2 (en) | Copying data changes to a target database | |
JP7438603B2 (en) | Transaction processing methods, apparatus, computer devices and computer programs | |
EP1915668B1 (en) | Database fragment cloning and management | |
CN104793988B (en) | The implementation method and device of integration across database distributed transaction | |
US11132350B2 (en) | Replicable differential store data structure | |
US6772155B1 (en) | Looking data in a database system | |
CN111522631B (en) | Distributed transaction processing method, device, server and medium | |
CN108509462B (en) | Method and device for synchronizing activity transaction table | |
WO2021046750A1 (en) | Data redistribution method, device, and system | |
EP2746971A2 (en) | Replication mechanisms for database environments | |
US20070288537A1 (en) | Method and apparatus for replicating data across multiple copies of a table in a database system | |
CN113168371B (en) | Write-write conflict detection in multi-master shared storage databases | |
CN111753013A (en) | Distributed transaction processing method and device | |
US11061889B2 (en) | Systems and methods of managing manifest refresh in a database | |
CN117234670B (en) | Distributed transaction processing method, system, computer equipment and storage medium | |
CN111240891A (en) | Data recovery method and device based on data consistency among multiple tables of database | |
US7051051B1 (en) | Recovering from failed operations in a database system | |
CN114595224A (en) | Data storage method and device and data query method and device | |
CN113971079A (en) | Parallel processing of changes in distributed systems | |
CN102193987B (en) | Method and system for increasing node data relationship based on OLTP (online transaction processing) | |
CN112631741A (en) | Transaction processing method, device and storage medium | |
CN118796805A (en) | Method, device, electronic device and storage medium for realizing data row identification function | |
CN112286992B (en) | A query method, distributed system, device and storage medium | |
CN115221145A (en) | Method and system for solving PostgreSQL database table expansion based on Undo table space |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |