CN109558452B - A Synchronous Method for Querying and Creating Tables - Google Patents

A Synchronous Method for Querying and Creating Tables Download PDF

Info

Publication number
CN109558452B
CN109558452B CN201811377399.XA CN201811377399A CN109558452B CN 109558452 B CN109558452 B CN 109558452B CN 201811377399 A CN201811377399 A CN 201811377399A CN 109558452 B CN109558452 B CN 109558452B
Authority
CN
China
Prior art keywords
sql statement
query table
query
building
synchronization
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.)
Active
Application number
CN201811377399.XA
Other languages
Chinese (zh)
Other versions
CN109558452A (en
Inventor
孙峰
付铨
余院兰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Wuhan Dream Database Co ltd
Original Assignee
Wuhan Dameng Database Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Wuhan Dameng Database Co Ltd filed Critical Wuhan Dameng Database Co Ltd
Priority to CN201811377399.XA priority Critical patent/CN109558452B/en
Publication of CN109558452A publication Critical patent/CN109558452A/en
Application granted granted Critical
Publication of CN109558452B publication Critical patent/CN109558452B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明公开一种查询建表操作的同步方法,包括以下步骤:步骤S1、捕获的源端数据库的查询建表操作,并提取所述查询建表操作的查询建表SQL语句;步骤S2、判断所述查询建表SQL语句是否满足以SQL语句进行同步的条件,如果满足则转步骤S3;步骤S3、将所述查询建表SQL语句发送至目标端数据库进行同步,源端数据库继续跟踪所述查询建表SQL语句的事物日志流,将与所述查询建表操作相关的INSERT操作日志直接丢弃,并在捕获到所述事物日志流中的提交日志时通知所述目标端数据库结束所述查询建表SQL语句的同步流程。本发明提供的查询建表操作的同步方法可以有效减少查询建表操作的同步耗时。

Figure 201811377399

The invention discloses a method for synchronizing a query table building operation, comprising the following steps: step S1, capturing the query table building operation of the source database, and extracting the query table building SQL statement of the query table building operation; step S2, judging Whether the query table building SQL statement satisfies the condition for synchronizing with the SQL statement, if so, go to step S3; Step S3, send the query table building SQL statement to the target database for synchronization, and the source database continues to track the Query the transaction log stream of the table-building SQL statement, directly discard the INSERT operation log related to the query table-building operation, and notify the target database to end the query when capturing the commit log in the transaction log stream Synchronization process of creating table SQL statements. The method for synchronizing the query table building operation provided by the present invention can effectively reduce the synchronization time-consuming of the query table building operation.

Figure 201811377399

Description

一种查询建表操作的同步方法A Synchronous Method for Querying and Creating Tables

技术领域technical field

本发明涉及数据库同步中查询建表操作同步技术领域,具体涉及一种查询建表装作的同步方法。The invention relates to the technical field of query table building operation synchronization in database synchronization, in particular to a synchronization method for query table building and pretending.

背景技术Background technique

在基于软件的数据库数据复制技术中,基于分析日志文件的数据实时同步技术,因其具备对源端数据库影响小、支持异构系统复制、复制系统备机可读写等特点,在应急灾备、多业务中心、实时异构资源整合、数据迁移与滚动升级、数据仓库架构改进等多个场景下应用广泛。In the software-based database data replication technology, the real-time data synchronization technology based on analyzing log files has the characteristics of small impact on the source database, supporting heterogeneous system replication, and readable and writable by the backup system of the replication system. , multi-business center, real-time heterogeneous resource integration, data migration and rolling upgrade, data warehouse architecture improvement and other scenarios are widely used.

基于分析日志文件的数据实时同步,主要技术原理是,在源端数据库,数据同步进程实时读取数据库的在线或归档日志文件获取数据库的INSERT、DELETE以及UPDATE的事务操作,然后将这些事务操作转换为内部特定格式的消息,直接通过TCP/IP网络传输到目标端数据库的数据同步进程;目标端数据库的数据同步进程接收到源端发送过来的消息后,进行消息的分析并将源端的事务操作恢复成SQL操作语句,使用数据库本地接口在目标端数据库上执行,实现源端和目标数据库的数据同步。The main technical principle of real-time data synchronization based on analysis log files is that in the source database, the data synchronization process reads the online or archived log files of the database in real time to obtain the transaction operations of INSERT, DELETE and UPDATE of the database, and then converts these transaction operations. It is an internal message in a specific format, which is directly transmitted to the data synchronization process of the target database through the TCP/IP network; after the data synchronization process of the target database receives the message sent by the source, it analyzes the message and operates the transaction of the source. Restore to SQL operation statement, use the database local interface to execute on the target database, realize the data synchronization between the source and the target database.

对于数据库上的DML操作,数据库都会在日志文件中直接记录事务操作信息如操作对象、修改的数据等内容,但是对于DDL操作,并不是所有数据库都会在日志文件中直接记录DDL事务信息。基于此,第三方工具可以通过实时读取物理日志文件中的增量日志数据,并进行解析来实现数据库上的增、删、改操作的实时同步。而对于DDL同步,目前通常的技术方案为利用中间表,采用间接的方式,从日志文件中解析出DDL操作的信息。查询建表操作是一种比较特殊的DDL操作,使用查询建表方式创建目标数据表的同时,会使用查询出的数据来初始化新建表。当待查询的表中数据量非常大时,查询建表操作将会非常耗时,并且日志文件信息流中会包含大量创建表的数据初始化INSERT操作日志。按照常规基于分析日志分析的数据同步方式,需要该DDL事务提交时才能开始同步该DDL操作,包括提取出日志文件中的新建表日志信息以及该表数据的初始化INSERT操作日志,然后发送到目标端进行同步,如果基表数据量非常大,这会造成大量的数据需要从源端发往目标端,目标端同步时将会需要较长时间才能提交完成,同步延时非常大。For DML operations on the database, the database directly records transaction operation information such as operation objects and modified data in the log file. However, for DDL operations, not all databases directly record DDL transaction information in the log file. Based on this, third-party tools can realize real-time synchronization of addition, deletion, and modification operations on the database by reading incremental log data in physical log files in real time and parsing them. For DDL synchronization, the current common technical solution is to use an intermediate table to parse out the information of the DDL operation from the log file in an indirect way. The query table creation operation is a special DDL operation. When the target data table is created using the query table creation method, the new table will be initialized with the queried data. When the amount of data in the table to be queried is very large, the query table creation operation will be very time-consuming, and the log file information stream will contain a large amount of table creation data to initialize the INSERT operation log. According to the conventional data synchronization method based on analysis log analysis, the DDL operation can only be synchronized when the DDL transaction is committed, including extracting the log information of the newly created table in the log file and the initial INSERT operation log of the table data, and then sending it to the target. For synchronization, if the data volume of the base table is very large, this will cause a large amount of data to be sent from the source to the target. When the target is synchronized, it will take a long time to complete the submission, and the synchronization delay will be very large.

发明内容SUMMARY OF THE INVENTION

本发明的目的在于克服上述技术不足,提供一种查询建表操作的同步方法,解决现有技术中查询建表操作同步耗时长、延时大的技术问题。The purpose of the present invention is to overcome the above technical deficiencies, provide a synchronization method for query table building operations, and solve the technical problems in the prior art that query table building operations take a long time to synchronize and have a large delay.

为达到上述技术目的,本发明的技术方案提供一种查询建表操作的同步方法,包括以下步骤:In order to achieve the above technical purpose, the technical solution of the present invention provides a synchronization method for querying table building operations, comprising the following steps:

步骤S1、捕获的源端数据库的查询建表操作,并提取所述查询建表操作的查询建表SQL语句;Step S1, capturing the query table building operation of the source database, and extracting the query table building SQL statement of the query table building operation;

步骤S2、判断所述查询建表SQL语句是否满足以SQL语句进行同步的条件,如果满足则转步骤S3;Step S2, determine whether the query table building SQL statement satisfies the condition for synchronizing with the SQL statement, and if it satisfies, then go to step S3;

步骤S3、将所述查询建表SQL语句发送至目标端数据库进行同步,源端数据库继续跟踪所述查询建表SQL语句的事物日志流,将与所述查询建表操作相关的INSERT操作日志直接丢弃,并在捕获到所述事物日志流中的提交日志时通知所述目标端数据库结束所述查询建表SQL语句的同步流程。Step S3, the query table building SQL statement is sent to the target database for synchronization, the source database continues to track the transaction log stream of the query table building SQL statement, and the INSERT operation log related to the query table building operation is directly discard, and when the commit log in the transaction log stream is captured, the target database is notified to end the synchronization process of the query and table creation SQL statement.

与现有技术相比,本发明的有益效果包括:本发明通过根据事物日志流中提交日志,对事物提交进行标识,实现同步流程的结束,避免缓存和分析查询建表SQL语句产生的大量操作表的INSERT日志,避免投递这些日志的传输操作和这些操作在目标数据库的入库操作,这些操作会严重的拖慢同步速度,优化后的方案可以最大限度的降低同步延时。Compared with the prior art, the beneficial effects of the present invention include: the present invention identifies the transaction submission according to the submission log in the transaction log stream, realizes the end of the synchronization process, and avoids a large number of operations generated by caching and analyzing the query table building SQL statement. The INSERT log of the table avoids the transmission operation of delivering these logs and the warehousing operation of these operations in the target database. These operations will seriously slow down the synchronization speed. The optimized solution can minimize the synchronization delay.

附图说明Description of drawings

图1是本发明提供的查询建表操作的同步方法的流程图。FIG. 1 is a flowchart of a method for synchronizing a query table building operation provided by the present invention.

具体实施方式Detailed ways

为了使本发明的目的、技术方案及优点更加清楚明白,以下结合附图及实施例,对本发明进行进一步详细说明。应当理解,此处所描述的具体实施例仅仅用以解释本发明,并不用于限定本发明。In order to make the objectives, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention, but not to limit the present invention.

实施例1:Example 1:

如图1所示,本发明的实施例1提供了一种查询建表操作的同步方法,包括以下步骤:As shown in FIG. 1 , Embodiment 1 of the present invention provides a synchronization method for querying table building operations, including the following steps:

步骤S1、捕获的源端数据库的查询建表操作,并提取所述查询建表操作的查询建表SQL语句;Step S1, capturing the query table building operation of the source database, and extracting the query table building SQL statement of the query table building operation;

步骤S2、判断所述查询建表SQL语句是否满足以SQL语句进行同步的条件,如果满足则转步骤S3;Step S2, determine whether the query table building SQL statement satisfies the condition for synchronizing with the SQL statement, and if it satisfies, then go to step S3;

步骤S3、将所述查询建表SQL语句发送至目标端数据库进行同步,源端数据库继续跟踪所述查询建表SQL语句的事物日志流,将与所述查询建表操作相关的INSERT操作日志直接丢弃,并在捕获到所述事物日志流中的提交日志时通知所述目标端数据库结束所述查询建表SQL语句的同步流程。Step S3, the query table building SQL statement is sent to the target database for synchronization, the source database continues to track the transaction log stream of the query table building SQL statement, and the INSERT operation log related to the query table building operation is directly discard, and when the commit log in the transaction log stream is captured, the target database is notified to end the synchronization process of the query and table creation SQL statement.

本发明提供的查询建表操作的同步方法,首先捕获查询建表操作,并提取查询建表SQL语句,进而判断查询建表SQL语句是否使用本发明提供的同步方法的条件,即以SQL语句进行同步的条件,如果满足则将查询建表SQL发送至目标端进行同步,并继续跟踪该事务日志流,将归属于该DDL操作表的INSERT操作日志都直接丢弃,直至捕获到提交日志,说明源端查询建表操作正常提交完成,则该事务同步结束,数据同步进程标识该事务同步完成。The method for synchronizing the query table building operation provided by the present invention first captures the query table building operation, extracts the query table building SQL statement, and then judges whether the query table building SQL statement uses the conditions of the synchronization method provided by the present invention, that is, executes the query table building operation using the SQL statement. If the synchronization conditions are met, the query table SQL will be sent to the target for synchronization, and the transaction log stream will continue to be tracked, and the INSERT operation logs belonging to the DDL operation table will be discarded directly until the commit log is captured, indicating the source If the client query table creation operation is normally submitted and completed, the transaction synchronization ends, and the data synchronization process marks the transaction synchronization completion.

本发明提供的查询建表操作的同步方法,可以跳过对于日志文件中大量INSERT日志的解析、传输以及同步,直接通过捕获提交日志标识事物同步结束,极大缩短查询建表操作同步的时间。The synchronization method for query table building operation provided by the present invention can skip the analysis, transmission and synchronization of a large number of INSERT logs in the log file, and directly identify the synchronization end of transactions by capturing and submitting logs, which greatly shortens the synchronization time of query table building operation.

优选的,所述步骤S1具体包括:Preferably, the step S1 specifically includes:

步骤S11、在所述源端数据库创建DDL记录辅助表以及DDL操作触发器;Step S11, create a DDL record auxiliary table and a DDL operation trigger in the source database;

步骤S12、通过所述DDL操作触发器捕获所述源端数据库的DDL操作,并将所述DDL操作写入所述DDL记录辅助表中。Step S12: Capture the DDL operation of the source database through the DDL operation trigger, and write the DDL operation into the DDL record auxiliary table.

步骤S13、通过日志分析捕获所述DDL记录辅助表的插入操作,提取出SQL语句;Step S13, capturing the insertion operation of the DDL record auxiliary table through log analysis, and extracting the SQL statement;

步骤S14、在所述SQL语句中筛选出所述查询建表SQL语句。Step S14: Filter out the query table building SQL statement from the SQL statement.

通过DDL记录辅助表作为中间表,捕获DDL操作的SQL语句,并在SQL语句中筛选出查询建表SQL语句。The DDL record auxiliary table is used as an intermediate table to capture the SQL statements of DDL operations, and filter out the query and table building SQL statements in the SQL statements.

具体的,为了描述的方便,本发明中描述的查询建表SQL语句模板如下:Specifically, for the convenience of description, the query table building SQL statement template described in the present invention is as follows:

CREATE TABLE T1 AS SELECT C1,C2,...,CN FROM T2CREATE TABLE T1 AS SELECT C1,C2,...,CN FROM T2

T1为新建表,T2为查询表。T1 is a new table, and T2 is a query table.

在源端数据库中创建DDL记录辅助表,具体表结构如下:Create a DDL record auxiliary table in the source database. The specific table structure is as follows:

字段名field name 类型type 说明illustrate OBJ_SCHNAMEOBJ_SCHNAME VARchar(128)VARchar(128) 对象模式名object schema name OBJ_NAMEOBJ_NAME VARchar(128)VARchar(128) 对象名称object name OP_SQLOP_SQL CLOBCLOB DDL操作的SQL语句SQL statement for DDL operation OP_TIMEOP_TIME DATETIME(6)DATETIME(6) 操作时间Operation time

在源端数据库中创建DDL操作触发器,当捕获到源端数据库的CREATE、ALTER、DROP、TRUNCATE操作时,进行如下操作:Create a DDL operation trigger in the source database. When the CREATE, ALTER, DROP, and TRUNCATE operations of the source database are captured, perform the following operations:

(1)判断操作的对象是否为DDL记录辅助表如果是,则直接返回;如果不是,则继续进行(2)。(1) Determine whether the object of the operation is the DDL record auxiliary table. If so, return directly; if not, proceed to (2).

(2)如果数据库的操作对象类型为表,则将操作的对象名、对象所属模式名、操作的SQL语句以及操作时间插入DDL记录辅助表中,用于后续通过分析日志文件实现同步时标识DDL操作中的对象。(2) If the operation object type of the database is a table, insert the object name of the operation, the schema name of the object, the SQL statement of the operation, and the operation time into the DDL record auxiliary table, which is used to identify the DDL when the synchronization is realized by analyzing the log file later. object in action.

优选的,所述步骤S14具体为:Preferably, the step S14 is specifically:

对所述SQL语句进行语法解析,筛选出所述查询建表SQL语句。Syntax parsing is performed on the SQL statement, and the query table building SQL statement is filtered out.

根据SQL语句的语法判断是否为查询建表SQL语句,判断方法通过现有技术实现即可,较为简单,在此不再赘述。According to the syntax of the SQL statement, it is judged whether it is an SQL statement for querying and building a table.

优选的,所述步骤S2具体包括:Preferably, the step S2 specifically includes:

步骤S21、提取所述查询建表SQL语句的新建表名、查询表名、查询项以及过滤条件;Step S21, extracting the new table name, query table name, query item and filter condition of the query table building SQL statement;

步骤S22、根据同步规则,判断所述查询建表SQL语句的新建表和查询表是否均需要被同步,如果是则转步骤S23,否则不满足以SQL语句进行同步的条件;Step S22, according to the synchronization rule, determine whether the new table and the query table of the query table building SQL statement both need to be synchronized, and if so, go to step S23, otherwise the condition for the synchronization of the SQL statement is not satisfied;

步骤S23、判断所述查询建表SQL语句是否为单表查询,如果是则转步骤S24,否则不满足以SQL语句进行同步的条件;Step S23, judging whether the query table building SQL statement is a single-table query, if so, go to step S24, otherwise it does not meet the conditions for the SQL statement to synchronize;

步骤S24、判断所述查询建表SQL语句中的查询项是否包含除列名以外的其他项,如果是则不满足以SQL语句进行同步的条件,否则转步骤S25;Step S24, determine whether the query item in the query table building SQL statement contains other items except the column name, if so, the condition for synchronization of the SQL statement is not satisfied, otherwise go to step S25;

步骤S25、判断所述查询建表SQL语句中是否包含过滤条件,如果是则不满足以SQL语句进行同步的条件,否则满足以SQL语句进行同步的条件。Step S25, judging whether the query table-building SQL statement contains a filter condition, if so, it does not satisfy the condition for synchronizing with the SQL statement, otherwise it satisfies the condition for synchronizing with the SQL statement.

根据同步规则,判断查询建表SQL语句中的新建表和查询表是否需要被同步,如果新建表不需要同步,则忽略本次同步操作;如果新建表需要同步,而查询表不需要同步,则不满足以SQL语句进行同步的条件,因为目标端数据库可能不存在查询表定义。进一步判断查询建表SQL语句中的查询是否为单表查询,如果不是,则不满足以SQL语句进行同步的条件,因为多表查询涉及到多张表的处理,在目标端数据库同步时需要判断多张表的执行状态,进行互斥保护等操作,这样会增加目标端数据库同步系统处理复杂度。进一步判断查询建表SQL语句中的查询项是否包含除了列名以外的其它项,例如包含函数,序列等,如果包含,则不满足以SQL语句进行同步的条件,因为源端和目标端的函数计算或者序列值定义可能不一致,从而得出不一致的初始化数据。判断查询建表SQL语句中的查询是否包含过滤条件,如果包含,则不满足以SQL语句进行同步的条件,因为过滤条件可能涉及多种复杂情况,如包含自定义函数等,源端和目标端的实际应用环境可能不一致,导致出现不一致的初始化数据。According to the synchronization rules, it is judged whether the newly created table and the query table in the query table creation SQL statement need to be synchronized. If the newly created table does not need to be synchronized, this synchronization operation is ignored; The conditions for synchronization of the SQL statement are not satisfied, because the query table definition may not exist in the target database. Further determine whether the query in the query table creation SQL statement is a single-table query. If not, it is not sufficient for the SQL statement to synchronize. Because the multi-table query involves the processing of multiple tables, it is necessary to determine the number of tables when synchronizing the target database. The execution state of the table, and mutual exclusion protection are performed, which will increase the processing complexity of the target database synchronization system. Further judge whether the query item in the query table creation SQL statement contains other items other than the column name, such as including functions, sequences, etc. If it does, it does not meet the conditions for the synchronization of the SQL statement, because the function calculation on the source side and the target side or Sequence value definitions may be inconsistent, resulting in inconsistent initialization data. Determines whether the query in the query table creation SQL statement contains filter conditions. If so, it is not sufficient for the synchronization conditions of the SQL statement, because the filter conditions may involve a variety of complex situations, such as including custom functions. The application environment may be inconsistent, resulting in inconsistent initialization data.

优选的,所述步骤S2还包括:Preferably, the step S2 further includes:

如果所述查询建表SQL语句不满足以SQL语句进行同步的条件,则通过分析日志文件实现所述查询建表SQL语句的同步。If the query table building SQL statement does not meet the conditions for synchronization of the SQL statement, the synchronization of the query table building SQL statement is realized by analyzing the log file.

如果查询建表SQL语句不满足以SQL语句进行同步的条件,则通过现有技术中分析日志文件的方式实现所述查询建表SQL语句的同步,现有技术中分析日志文件的同步方式详见背景技术中介绍。If the query table building SQL statement does not meet the conditions for synchronization of the SQL statement, the synchronization of the query table building SQL statement is realized by analyzing the log file in the prior art. For the synchronization method of analyzing the log file in the prior art, please refer to the background. Introduced in technology.

优选的,所述步骤S3具体包括:Preferably, the step S3 specifically includes:

步骤S31、检测所述查询建表SQL语句之前在查询表上执行的事物是否已经提交或回滚完成,如果提交完成,则直接转步骤S32,如果回滚完成,则直接转步骤S33,否则等待提交或回滚完成;Step S31, detect whether the thing executed on the query table before the query table building SQL statement has been submitted or rolled back is completed, if the submission is completed, then directly go to step S32, if the rollback is completed, then directly go to step S33, otherwise wait Commit or rollback is complete;

步骤S32、结束对相应DDL事务的跟踪,并通知目标端数据库完成DDL同步;Step S32, end the tracking of the corresponding DDL transaction, and notify the target database to complete the DDL synchronization;

步骤S33、结速对相应DDL事务的跟踪,并构造所述查询建表SQL操作对应的新建表的删除操作发送给目标端数据库,以清空所述查询建表SQL语句创建的同步的新建表,完成DDL同步。Step S33, ending the tracking of the corresponding DDL transaction, and constructing the delete operation of the new table corresponding to the query table building SQL operation and sending it to the target database, so as to clear the synchronous new table created by the query table building SQL statement, Complete DDL synchronization.

在目标端数据库,数据同步进程接收到所述查询建表SQL语句后,根据事务同步规则,通过目标端数据库的数据访问接口执行该查询建表SQL语句,实现查询建表DDL操作的同步。目标端数据库在执行查询建表SQL语句前,需要等待本次查询建表操作之前的查询表上的所有事务提交完成,这是为了保证查询建表操作中查询到的查询表的数据是完整的;还需要对本次创建的新建表进行互斥保护,防止后续事务操作该表,因为如果查询建表SQL语句的查询表数据量很大,则查询建表SQL语句执行时间可能较长,考虑到源端数据库完成查询建表操作后,会存在继续操作新建表的事务,且该事务信息传输到目标端时,目标端查询建表SQL语句可能尚未提交完成,因此后续对于新建表的事务操作需要进行等待,目标端在执行查询建表SQL语句时,需要对新建表设置互斥保护,直至查询建表SQL操作提交完成。In the target database, after receiving the query table building SQL statement, the data synchronization process executes the query table building SQL statement through the data access interface of the target database according to the transaction synchronization rules, so as to realize the synchronization of the query table building DDL operation. Before executing the query table creation SQL statement, the target database needs to wait for the completion of all transactions on the query table before the query table creation operation. This is to ensure that the data in the query table queried in the query table creation operation is complete. ; It is also necessary to protect the newly created table this time by mutual exclusion to prevent subsequent transactions from operating the table, because if the query table data volume of the query table creation SQL statement is large, the execution time of the query table creation SQL statement may be longer. After the source database completes the query table creation operation, there will be a transaction that continues to operate the newly created table, and when the transaction information is transmitted to the target end, the target end query table creation SQL statement may not be submitted yet, so the subsequent transaction operations for the newly created table It needs to wait. When the target side executes the query table creation SQL statement, it needs to set the mutual exclusion protection for the newly created table until the query table creation SQL operation is submitted.

优选的,所述步骤S3还包括:源端数据库继跟踪所述查询建表SQL语句的事物日志流的同时,停止所述查询建表SQL语句的提取操作以及所述查询建表SQL语句的相关日志的传输操作。Preferably, the step S3 further includes: while tracking the transaction log stream of the query table building SQL statement, the source database stops the extraction operation of the query table building SQL statement and the correlation of the query table building SQL statement Log transfer operations.

由于本发明通过捕获所述事物日志流中的提交日志,实现所述查询建表SQL语句的同步流程的结束,因此不需要再缓存和分析查询建表SQL语句操作产生的对操作表的INSERT日志,不需要再传输查询建表SQL语句产生的其它相关日志,减少查询建表操作的同步耗时,降低查询建表操作的同步延时。Because the present invention realizes the end of the synchronization process of the query table building SQL statement by capturing the commit log in the transaction log stream, there is no need to cache and analyze the INSERT log for the operation table generated by the query table building SQL statement operation. , there is no need to transmit other related logs generated by the query table creation SQL statement, which reduces the synchronization time of the query table creation operation and the synchronization delay of the query table creation operation.

优选的,所述步骤S3还包括:Preferably, the step S3 further includes:

源端数据库继续跟踪所述查询建表SQL语句的事物日志流,并在捕获到所述事物日志流中的回滚日志时通知所述目标端数据库删除所述查询建表SQL语句的目标表。The source-end database continues to track the transaction log stream of the query table-building SQL statement, and notifies the target-end database to delete the target table of the query table-building SQL statement when capturing the rollback log in the transaction log stream.

在源端数据库,数据同步进程将查询建表SQL语句发送到目标端后,日志捕获分析模块根据事务ID值,继续捕获同一查询建表操作中插入数据的日志信息流,直至跟踪到该查询建表事务的提交日志,即COMMIT日志,说明该查询建表事务执行完成;或者跟踪到该查询建表事务的回滚日志,即ROLLBACK日志,说明该查询建表事务执行失败,源端数据库执行了回滚操作。当查询建表事务在日志文件中写入了回滚日志,即查询建表事物执行失败时,源端数据库的数据同步进程根据操作对象名构造DROP TABLE操作发送到目标端数据库,以通知目标端数据库删除所述查询建表SQL语句的目标表,以保持源端与目标端的同步性和一致性。In the source database, after the data synchronization process sends the query table creation SQL statement to the target end, the log capture and analysis module continues to capture the log information flow of data inserted in the same query table creation operation according to the transaction ID value, until the query creation operation is traced. The commit log of the table transaction, that is, the COMMIT log, indicates that the execution of the query table-building transaction is completed; or the rollback log of the query table-building transaction is tracked, that is, the ROLLBACK log, indicating that the query table-building transaction fails to execute, and the source database executes it. Rollback operation. When the query table creation transaction writes the rollback log in the log file, that is, when the query table creation transaction fails to execute, the data synchronization process of the source database constructs a DROP TABLE operation according to the operation object name and sends it to the target database to notify the target end The database deletes the target table of the query table-building SQL statement, so as to maintain the synchronization and consistency between the source end and the target end.

实施例2:Example 2:

本发明的实施例2提供了一种计算机存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时,实现以上任一实施例提供的查询建表操作的同步方法。Embodiment 2 of the present invention provides a computer storage medium on which a computer program is stored, and when the computer program is executed by a processor, implements the synchronization method for query table building operation provided by any of the above embodiments.

本发明提供的计算机存储介质,基于上述查询建表操作的同步方法,因此,上述查询建表操作的同步方法所具备的技术效果,计算机存储介质同样具备,在此不再赘述。The computer storage medium provided by the present invention is based on the above synchronization method for query table building operation. Therefore, the technical effects of the above synchronization method for query table building operation are also provided by the computer storage medium, which will not be repeated here.

以上所述本发明的具体实施方式,并不构成对本发明保护范围的限定。任何根据本发明的技术构思所做出的各种其他相应的改变与变形,均应包含在本发明权利要求的保护范围内。The specific embodiments of the present invention described above do not limit the protection scope of the present invention. Any other corresponding changes and modifications made according to the technical concept of the present invention shall be included in the protection scope of the claims of the present invention.

Claims (8)

1.一种查询建表操作的同步方法,其特征在于,包括以下步骤:1. a synchronizing method of query table building operation, is characterized in that, comprises the following steps: 步骤S1、捕获的源端数据库的查询建表操作,并提取所述查询建表操作的查询建表SQL语句;Step S1, capturing the query table building operation of the source database, and extracting the query table building SQL statement of the query table building operation; 步骤S2、判断所述查询建表SQL语句是否满足以SQL语句进行同步的条件,如果满足则转步骤S3;Step S2, determine whether the query table building SQL statement satisfies the condition for synchronizing with the SQL statement, and if it satisfies, then go to step S3; 步骤S3、将所述查询建表SQL语句发送至目标端数据库进行同步,源端数据库继续跟踪所述查询建表SQL语句的事物日志流,将与所述查询建表操作相关的INSERT操作日志直接丢弃,并在捕获到所述事物日志流中的提交日志时通知所述目标端数据库结束所述查询建表SQL语句的同步流程;Step S3, the query table building SQL statement is sent to the target database for synchronization, the source database continues to track the transaction log stream of the query table building SQL statement, and the INSERT operation log related to the query table building operation is directly Discard, and notify the target database to end the synchronization process of the query table building SQL statement when the commit log in the transaction log stream is captured; 所述步骤S2具体包括:The step S2 specifically includes: 步骤S21、提取所述查询建表SQL语句的新建表名、查询表名、查询项以及过滤条件;Step S21, extracting the new table name, query table name, query item and filter condition of the query table building SQL statement; 步骤S22、根据同步规则,判断所述查询建表SQL语句的新建表和查询表是否均需要被同步,如果是则转步骤S23,否则不满足以SQL语句进行同步的条件;Step S22, according to the synchronization rule, determine whether the new table and the query table of the query table building SQL statement both need to be synchronized, and if so, go to step S23, otherwise the condition for the synchronization of the SQL statement is not satisfied; 步骤S23、判断所述查询建表SQL语句是否为单表查询,如果是则转步骤S24,否则不满足以SQL语句进行同步的条件;Step S23, judging whether the query table building SQL statement is a single-table query, if so, go to step S24, otherwise it does not meet the conditions for the SQL statement to synchronize; 步骤S24、判断所述查询建表SQL语句中的查询项是否包含除列名以外的其他项,如果是则不满足以SQL语句进行同步的条件,否则转步骤S25;Step S24, determine whether the query item in the query table building SQL statement contains other items except the column name, if so, the condition for synchronization of the SQL statement is not satisfied, otherwise go to step S25; 步骤S25、判断所述查询建表SQL语句中是否包含过滤条件,如果是则不满足以SQL语句进行同步的条件,否则满足以SQL语句进行同步的条件。Step S25, judging whether the query table-building SQL statement contains a filter condition, if so, it does not satisfy the condition for synchronizing with the SQL statement, otherwise it satisfies the condition for synchronizing with the SQL statement. 2.根据权利要求1所述的查询建表操作的同步方法,其特征在于,所述步骤S1具体包括:2. The synchronization method of query table building operation according to claim 1, wherein the step S1 specifically comprises: 步骤S11、在所述源端数据库创建DDL记录辅助表以及DDL操作触发器;Step S11, create a DDL record auxiliary table and a DDL operation trigger in the source database; 步骤S12、通过所述DDL操作触发器捕获所述源端数据库的DDL操作,并将所述DDL操作写入所述DDL记录辅助表中;Step S12, capturing the DDL operation of the source database through the DDL operation trigger, and writing the DDL operation into the DDL record auxiliary table; 步骤S13、通过日志分析捕获所述DDL记录辅助表的插入操作,提取出SQL语句;Step S13, capturing the insertion operation of the DDL record auxiliary table through log analysis, and extracting the SQL statement; 步骤S14、在所述SQL语句中筛选出所述查询建表SQL语句。Step S14: Filter out the query table building SQL statement from the SQL statement. 3.根据权利要求2所述的查询建表操作的同步方法,其特征在于,所述步骤S14具体为:3. The synchronization method of query table building operation according to claim 2, wherein the step S14 is specifically: 对所述SQL语句进行语法解析,筛选出所述查询建表SQL语句。Syntax parsing is performed on the SQL statement, and the query table building SQL statement is filtered out. 4.根据权利要求1所述的查询建表操作的同步方法,其特征在于,所述步骤S2还包括:4. The synchronization method of query table building operation according to claim 1, wherein the step S2 further comprises: 如果所述查询建表SQL语句不满足以SQL语句进行同步的条件,则通过分析日志文件实现所述查询建表SQL语句的同步。If the query table building SQL statement does not meet the conditions for synchronization of the SQL statement, the synchronization of the query table building SQL statement is realized by analyzing the log file. 5.根据权利要求1所述的查询建表操作的同步方法,其特征在于,所述步骤S3具体包括:5. The synchronization method of query table building operation according to claim 1, wherein the step S3 specifically comprises: 步骤S31、检测所述查询建表SQL语句之前在查询表上执行的事物是否已经提交或回滚完成,如果提交完成,则直接转步骤S32,如果回滚完成,则直接转步骤S33,否则等待提交或回滚完成;Step S31, detect whether the thing executed on the query table before the query table building SQL statement has been submitted or rolled back is completed, if the submission is completed, then directly go to step S32, if the rollback is completed, then directly go to step S33, otherwise wait Commit or rollback is complete; 步骤S32、结束对相应DDL事务的跟踪,并通知目标端数据库完成DDL同步;Step S32, end the tracking of the corresponding DDL transaction, and notify the target database to complete the DDL synchronization; 步骤S33、结速对相应DDL事务的跟踪,并构造所述查询建表SQL操作对应的新建表的删除操作发送给目标端数据库,以清空所述查询建表SQL语句创建的同步的新建表,完成DDL同步。Step S33, ending the tracking of the corresponding DDL transaction, and constructing the delete operation of the new table corresponding to the query table building SQL operation and sending it to the target database, so as to clear the synchronous new table created by the query table building SQL statement, Complete DDL synchronization. 6.根据权利要求1所述的查询建表操作的同步方法,其特征在于,所述步骤S3还包括:源端数据库继跟踪所述查询建表SQL语句的事物日志流的同时,停止所述查询建表SQL语句的提取操作以及所述查询建表SQL语句的相关日志的传输操作。6. The method for synchronizing query table building operation according to claim 1, wherein said step S3 further comprises: while the source database continues to track the transaction log stream of the query table building SQL statement, it stops the The extraction operation of the query table-building SQL statement and the transmission operation of the relevant log of the query table-building SQL statement. 7.根据权利要求1所述的查询建表操作的同步方法,其特征在于,所述步骤S3还包括:7. The synchronization method of query table building operation according to claim 1, wherein the step S3 further comprises: 源端数据库继续跟踪所述查询建表SQL语句的事物日志流,并在捕获到所述事物日志流中的回滚日志时通知所述目标端数据库删除所述查询建表SQL语句的目标表。The source-end database continues to track the transaction log stream of the query table-building SQL statement, and notifies the target-end database to delete the target table of the query table-building SQL statement when capturing the rollback log in the transaction log stream. 8.一种计算机存储介质,其上存储有计算机程序,其特征在于,所述计算机程序被处理器执行时,实现如权利要求1-6任一所述的查询建表操作的同步方法。8 . A computer storage medium having a computer program stored thereon, characterized in that, when the computer program is executed by a processor, the method for synchronizing a query table building operation according to any one of claims 1 to 6 is implemented.
CN201811377399.XA 2018-11-19 2018-11-19 A Synchronous Method for Querying and Creating Tables Active CN109558452B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811377399.XA CN109558452B (en) 2018-11-19 2018-11-19 A Synchronous Method for Querying and Creating Tables

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811377399.XA CN109558452B (en) 2018-11-19 2018-11-19 A Synchronous Method for Querying and Creating Tables

Publications (2)

Publication Number Publication Date
CN109558452A CN109558452A (en) 2019-04-02
CN109558452B true CN109558452B (en) 2020-12-08

Family

ID=65866818

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811377399.XA Active CN109558452B (en) 2018-11-19 2018-11-19 A Synchronous Method for Querying and Creating Tables

Country Status (1)

Country Link
CN (1) CN109558452B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110688367A (en) * 2019-09-27 2020-01-14 浪潮软件集团有限公司 A general database migration adaptation method and system
CN111241094B (en) * 2019-12-31 2021-06-08 武汉达梦数据库有限公司 A method and device for database deletion column synchronization based on log parsing
CN111221907B (en) * 2019-12-31 2021-03-30 武汉达梦数据库股份有限公司 Database added column synchronization method and device based on log analysis
CN111221909B (en) * 2019-12-31 2021-05-28 武汉达梦数据库股份有限公司 Database modification column synchronization method and device based on log analysis
CN112559626B (en) * 2020-12-11 2022-06-21 武汉达梦数据库股份有限公司 Synchronous method and synchronous system of DDL operation based on log analysis
CN112765180B (en) * 2021-01-27 2023-01-17 上海英方软件股份有限公司 Method and device for analyzing column names of table building logs of DB2 database
CN114253925B (en) * 2021-12-01 2024-08-20 北京人大金仓信息技术股份有限公司 Method, server, terminal and electronic equipment for accessing database logs

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101615199A (en) * 2009-07-31 2009-12-30 深圳市珍爱网信息技术有限公司 Heterogeneous database synchronization method and system
CN103617176A (en) * 2013-11-04 2014-03-05 广东电子工业研究院有限公司 Method for achieving automatic synchronization of multi-source heterogeneous data resources
CN104679841A (en) * 2015-02-11 2015-06-03 北京京东尚科信息技术有限公司 Consumption terminal data flow copying method and system
CN106326376A (en) * 2016-08-15 2017-01-11 东软集团股份有限公司 Method and device for copying information after table structure modification
CN108664659A (en) * 2018-05-21 2018-10-16 四川中电启明星信息技术有限公司 A kind of method of data synchronization and device of Distributed Heterogeneous Database

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8086564B2 (en) * 2007-12-12 2011-12-27 Oracle International Corporation Techniques for the logical replication of high-level procedures

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101615199A (en) * 2009-07-31 2009-12-30 深圳市珍爱网信息技术有限公司 Heterogeneous database synchronization method and system
CN103617176A (en) * 2013-11-04 2014-03-05 广东电子工业研究院有限公司 Method for achieving automatic synchronization of multi-source heterogeneous data resources
CN104679841A (en) * 2015-02-11 2015-06-03 北京京东尚科信息技术有限公司 Consumption terminal data flow copying method and system
CN106326376A (en) * 2016-08-15 2017-01-11 东软集团股份有限公司 Method and device for copying information after table structure modification
CN108664659A (en) * 2018-05-21 2018-10-16 四川中电启明星信息技术有限公司 A kind of method of data synchronization and device of Distributed Heterogeneous Database

Also Published As

Publication number Publication date
CN109558452A (en) 2019-04-02

Similar Documents

Publication Publication Date Title
CN109558452B (en) A Synchronous Method for Querying and Creating Tables
CN106462586B (en) The method and system that the consistency of Multi version concurrency control based on record is read
US11138227B2 (en) Consistent query execution in hybrid DBMS
US9892153B2 (en) Detecting lost writes
CN106462594B (en) A system and method for massively parallel processing of databases
US8352425B2 (en) Parallel apply processing in data replication with preservation of transaction integrity and source ordering of dependent updates
US8560500B2 (en) Method and system for removing rows from directory tables
JP4403068B2 (en) High-performance change capture for data warehousing
US8380663B2 (en) Data integrity in a database environment through background synchronization
CN110175213A (en) A kind of oracle database synchronization system and method based on SCN mode
Yang et al. F1 Lightning: HTAP as a Service
US20220171754A1 (en) Method for indexing data in storage engine and related apparatus
CN112559626B (en) Synchronous method and synchronous system of DDL operation based on log analysis
CN110222121A (en) A kind of SQL Server database increment synchronization realization method and system based on CDC mode
CN115373889A (en) Method and device for data comparison and verification and data restoration in data synchronization
CN115408200A (en) Data backup method, device, electronic equipment and storage medium for multiple storage engines
US7406489B2 (en) Apparatus, system and method for persistently storing data in a data synchronization process
US20210081429A1 (en) Transaction savepoint management apparatus and method for distributed database
CN109669988B (en) A split synchronization method and system for query table creation transaction
CN107038231A (en) A kind of database high concurrent affairs merging method
CN111984715A (en) Heterogeneous data synchronous processing method and system
KR101024494B1 (en) Change Data Extraction Method Using Metadata
CN106407292B (en) The method and device of vector data Geometrical change detection in a kind of spatial database
Zhou et al. An ETL strategy for real-time data warehouse
CN114637762A (en) A method, device and electronic device for generating an operation record

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
CB03 Change of inventor or designer information

Inventor after: Sun Feng

Inventor after: Fu Quan

Inventor after: Yu Yuanlan

Inventor before: Sun Feng

Inventor before: Fu Quan

Inventor before: Yu Yuanlan

Inventor before: Yang Chun

CB03 Change of inventor or designer information
GR01 Patent grant
GR01 Patent grant
CP01 Change in the name or title of a patent holder

Address after: 430000 16-19 / F, building C3, future technology building, 999 Gaoxin Avenue, Donghu New Technology Development Zone, Wuhan, Hubei Province

Patentee after: Wuhan dream database Co.,Ltd.

Address before: 430000 16-19 / F, building C3, future technology building, 999 Gaoxin Avenue, Donghu New Technology Development Zone, Wuhan, Hubei Province

Patentee before: WUHAN DAMENG DATABASE Co.,Ltd.

CP01 Change in the name or title of a patent holder
TR01 Transfer of patent right

Effective date of registration: 20220915

Address after: 430073 16-19 / F, building C3, future science and technology building, 999 Gaoxin Avenue, Donghu New Technology Development Zone, Wuhan City, Hubei Province

Patentee after: Wuhan dream database Co.,Ltd.

Patentee after: HUAZHONG University OF SCIENCE AND TECHNOLOGY

Address before: 430000 16-19 / F, building C3, future technology building, 999 Gaoxin Avenue, Donghu New Technology Development Zone, Wuhan, Hubei Province

Patentee before: Wuhan dream database Co.,Ltd.

TR01 Transfer of patent right
TR01 Transfer of patent right

Effective date of registration: 20230719

Address after: 16-19/F, Building C3, Future Science and Technology Building, No. 999 Gaoxin Avenue, Donghu New Technology Development Zone, Wuhan City, Hubei Province, 430206

Patentee after: Wuhan dream database Co.,Ltd.

Address before: 430073 16-19 / F, building C3, future science and technology building, 999 Gaoxin Avenue, Donghu New Technology Development Zone, Wuhan City, Hubei Province

Patentee before: Wuhan dream database Co.,Ltd.

Patentee before: HUAZHONG University OF SCIENCE AND TECHNOLOGY

TR01 Transfer of patent right