WO2016197870A1 - Method and device for processing ddl statement in relational database - Google Patents

Method and device for processing ddl statement in relational database Download PDF

Info

Publication number
WO2016197870A1
WO2016197870A1 PCT/CN2016/084624 CN2016084624W WO2016197870A1 WO 2016197870 A1 WO2016197870 A1 WO 2016197870A1 CN 2016084624 W CN2016084624 W CN 2016084624W WO 2016197870 A1 WO2016197870 A1 WO 2016197870A1
Authority
WO
WIPO (PCT)
Prior art keywords
lock
mdl
statement
waiting
queue
Prior art date
Application number
PCT/CN2016/084624
Other languages
French (fr)
Chinese (zh)
Inventor
赵建伟
Original Assignee
阿里巴巴集团控股有限公司
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 阿里巴巴集团控股有限公司 filed Critical 阿里巴巴集团控股有限公司
Publication of WO2016197870A1 publication Critical patent/WO2016197870A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases

Definitions

  • the present invention relates to the field of computers, and in particular, to a technique for processing DDL statements in a relational database.
  • the incompatibility problems caused by the different types of MDL locks applied for each other cause the two statements to be generated during execution. Blocked, blocking the execution of subsequent statements.
  • the DDL statement can be set to make the DDL statement fail quickly when the statement conflict occurs concurrently, thereby solving the statement concurrent execution blocking.
  • the DDL statement can only be set at the paragraph or global level, and the flexible operation of the statement level cannot be performed.
  • the operation and maintenance personnel may cause the application access to be blocked due to the excessive blocking time of the statement concurrent execution. Business disruption.
  • a method for processing a DDL statement in a relational database comprising:
  • an apparatus for processing a DDL statement in a relational database comprising:
  • a first device configured to acquire a DDL statement submitted by the user about the target table, where the DDL statement includes corresponding waiting setting information
  • a second device configured to apply for an exclusive MDL lock corresponding to the target table
  • a third device configured to perform an exit process on the DDL statement according to the waiting setting information if the application for the exclusive MDL lock fails.
  • the present application requests the exclusive MDL lock corresponding to the target table by acquiring the DDL statement submitted by the user about the target table and the corresponding waiting information set in the target table, and if the application fails, according to the set waiting
  • the DDL statement in the information performs the exit processing, solves the data definition language DDL in the system database and the data manipulation language DML concurrently executes the blocking problem, thereby avoiding the blocked access or business interruption of the database associated application, improving the execution efficiency of the database language, and improving the database. reliability.
  • FIG. 1 shows a schematic diagram of an apparatus for processing DDL statements in a relational database, in accordance with an aspect of the present application
  • FIG. 2 shows a flow chart of a method for processing DDL statements in a relational database in accordance with another aspect of the present application.
  • the terminal, the device of the service network, and the trusted party each include one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
  • processors CPUs
  • input/output interfaces network interfaces
  • memory volatile and non-volatile memory
  • the memory may include non-persistent memory, random access memory (RAM), and/or non-volatile memory in a computer readable medium, such as read only memory (ROM) or flash memory.
  • RAM random access memory
  • ROM read only memory
  • Memory is an example of a computer readable medium.
  • Computer readable media includes both permanent and non-persistent, removable and non-removable media.
  • Information storage can be implemented by any method or technology.
  • the information can be computer readable instructions, data structures, modules of programs, or other data.
  • Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory. (ROM), electrically erasable programmable read only memory (EEPROM), flash memory or other memory technology, CD-ROM, digital versatile disc (DVD) or other optical storage, magnetic tape cartridge, magnetic tape storage or other magnetic storage device or any other non-transportable media that can be used for storage can be calculated Information accessed by the device.
  • computer readable media does not include non-transitory computer readable media, such as modulated data signals and carrier waves.
  • the device 1 shows a schematic diagram of an apparatus 1 for processing DDL statements in a relational database, in accordance with an aspect of the present application.
  • the device 1 comprises a first device 11, a second device 12 and a third device 13.
  • the first device 11 of the device 1 is configured to acquire a DDL statement submitted by a user about a target table, where the DDL statement includes corresponding waiting setting information; and the second device 12 is configured to apply for the target table.
  • the exclusive MDL lock; the third device is configured to perform an exit process on the DDL statement according to the waiting setting information if the application for the exclusive MDL lock fails.
  • the first device 11 is configured to acquire a DDL statement submitted by the user about the target table, where the DDL statement includes corresponding waiting setting information.
  • the manner of obtaining the DDL statement submitted by the user about the target table may be performed by a database management system, and the DDL statement is a database definition language, and the DDL statement about the target table is executed before the execution in order to provide a concurrent access to the dictionary object cache in the memory.
  • the protection, as well as the mutual exclusion of some database language operations, need to apply for MDL locks to protect the data in the table when the statement is executed.
  • the waiting setting information is setting information of a corresponding execution action when the DDL statement requests the MDL lock to be blocked, and includes an action performed after the user desires that the DDL statement is blocked, and the action includes continuing to wait or immediately exit waiting for related operations. For example, when a DDL statement requests an exclusive MDL lock, an execution conflict occurs with a DML statement that previously applied for a shared-level MDL lock. Therefore, after entering the lock waiting queue and waiting for the DML statement to execute, the MDL lock application is performed, and the subsequent DML statements are all due to The DDL statement waits and enters the lock waiting queue to cause blocking.
  • the DDL statement includes the corresponding waiting setting information
  • the example DDL statement enters the lock waiting queue, it waits for a certain time to exit or immediately exit according to the waiting setting information. In order to avoid the blocking or interruption of the database business caused by the blocking of the application MDL lock statement.
  • the waiting setting information includes at least one of the following: a set waiting time; zero waiting.
  • the set waiting time is set in the DDL statement to wait for the set time. If the set time is exceeded, the execution task of the DDL statement fails to be exited immediately.
  • the DDL statement is set to Alter table test wait 1 add col1 number, that is, Waiting for 1 second after failing to apply for the MDL lock, so that it is deleted in the MDL lock waiting queue, the blocked application sharing level DML language can therefore reduce the waiting time or the current statement when the current MDL lock is the sharing level carried out.
  • Zero wait that is, the DDL statement execution task fails to exit immediately after setting the feedback of the failed application for the MDL lock in the DDL statement.
  • the DDL statement is set to Alter table test no_wait add col1 Number also enables subsequent DML languages in the MDL lock wait queue to reduce latency or co-execute with the current statement when the current MDL lock is shared, reducing the time that database-related services are unavailable.
  • the second device 12 is configured to apply for an exclusive MDL lock corresponding to the target table.
  • the exclusive MDL lock is a conflict that the DDL statement conflicts when the target table that is the object of the statement execution is not executed concurrently with other database languages (for example, the database manipulation language DML) before being executed, for example,
  • the DDL statement performs an insert operation on the same target table when the entire table delete of the target table is performed, and the concurrent execution conflict is generated at this time.
  • the DDL statement in the relational database will be executed before the execution. Applying an exclusive MDL lock makes it impossible for DDL statements to be executed outside the target table at the time of execution, thereby improving the execution efficiency of the database language and protecting the data in the table.
  • the third device 13 is configured to perform an exit process on the DDL statement according to the waiting setting information if the application for the exclusive MDL lock fails. Because the DDL statement applies for an exclusive MDL lock, when the statement in the corresponding lock holding queue of the target table operation corresponds to the shared-level MDL lock, the application for the shared DDL statement fails for the exclusive MDL lock, and the DDL statement enters the lock waiting queue. At this time, the waiting setting information in the DDL statement is triggered, and the triggering method includes setting the feedback information after the acquisition of the MDL lock application fails, starting the setting information corresponding program, reading the setting information, and performing the setting action accordingly.
  • the waiting setting information includes an action performed by the user after the DDL statement is blocked, and the action includes continuing to wait or immediately exiting waiting and other related operations.
  • the waiting information is waited according to the waiting setting information.
  • the lock holding queue described above is a relational database, and the database language is in the queue after the application for the MDL lock is successful. Accordingly, the lock waiting queue applies for the MDL lock for the database language because the applied lock type is mutually exclusive and fails. Wait for the MDL lock to hold the statement and continue to apply for the MDL lock queue.
  • the third device is configured to: execute the DDL statement if the application for the exclusive MDL lock is successful.
  • the DDL statement applies for an exclusive MDL lock, there are no other statements that hold the MDL with the exclusive MDL mutually exclusive type.
  • the lock the DDL statement acquires the exclusive MDL lock, enters the lock holding queue and then executes the statement content, and performs corresponding operations on the target table.
  • the waiting setting information includes a set waiting time, wherein the third device is configured to: if the application for the exclusive MDL lock fails, wait for the waiting time to wait for the exclusive MDL lock again. If the application for the exclusive MDL lock fails, the execution of the DDL statement is exited. That is, before the set waiting time starts to execute, immediately before the DDL statement execution task fails to exit, the setting information of re-applying the MDL lock may be added, that is, after waiting for the set time, for example, after waiting for 1 second, after waiting for 1 second, Continue to initiate the application for the MDL lock. If the MDL lock is not held at this time, the application can be successfully applied and executed with the exclusive MDL lock.
  • the execution immediately causes the DDL statement execution task to fail to exit, thereby increasing the probability that the DDL applies for the MDL lock, and improving the application efficiency of the MDL lock.
  • the waiting setting information includes zero waiting
  • the third device is configured to: quit the execution processing of the DDL statement if the exclusive MDL lock fails to be applied. That is, after the DDL statement obtains the feedback of applying for the exclusive MDL lock failure, according to the zero waiting setting, the DDL statement execution task is immediately defeated, so that the DDL statement is deleted in the MDL lock waiting queue, so the MDL lock waiting queue can be reduced. Waiting time for other statements to avoid database related business interruption or application access blocked due to long waiting time.
  • the device 1 comprises a first device, a second device and a third device, wherein both the first device and the second device add a data manipulation language DML to the first device 11 and the second device 12 shown in FIG.
  • the third device includes a first unit, the first unit is configured to: after exiting execution processing on the DDL statement, add at least one of the DML statements to a lock holding queue of the MDL lock or The lock waits for the queue.
  • the first device is further configured to acquire a DML statement submitted by the user about the target table, where the third device further includes a first unit, after exiting execution processing on the DDL statement, Adding at least one of the DML statements to a lock holding queue or a lock waiting queue of the MDL lock.
  • the acquired database language of the target table includes DML in addition to the DDL. Therefore, after exiting the execution process of the DDL statement, the DDL statement is deleted from the MDL lock waiting queue, and subsequently in the MDL lock waiting queue.
  • the DML statements in the order will be processed in the order in which they are arranged. At least one DML statement is added to the MDL lock hold or lock wait queue according to the type requirements of the MDL lock in the queue.
  • the current MDL lock holds the database language in the queue.
  • the MDL lock type held by the statement is not mutually exclusive and shareable with the DML statement in the lock wait queue. Then, the DML statement is added to the lock holding queue according to the order until the database statement with mutual exclusion needs appears, and the statement is excluded. MDL lock Outside the holding queue, it still remains in the MDL lock waiting queue. If the MDL lock type held by the database language statement in the current MDL lock holding queue is mutually exclusive with the DML statement in the lock waiting queue, the obtained DML statement is added. Go to the MDL lock wait queue to wake up blocked DML statements, making database-related application access efficient or faster.
  • the first unit is configured to: after exiting execution processing on the DDL statement, when the lock holding queue and the statement in the lock waiting queue all correspond to the sharing level MDL lock, At least one of the DML statements is added to the lock holding queue.
  • the DML statement includes the DML statement processed again and processed for the first time, that is, the statement executed before the lock waiting queue position where the DML statement is located after exiting the execution of the DDL statement, and the statement in the currently held queue.
  • the DML statement can be added to the lock holding queue together with the statement in the lock waiting queue before the lock waiting queue position.
  • dml1 and dml2 refer to two DML statements.
  • dml3, dml4, and dml5 refer to the DML statements in the lock wait queue, which need to apply for the shared-level MDL lock.
  • dml6 refers to the DML that the newly acquired user needs to apply for the shared-level MDL lock.
  • dml3 to dm16 can be added to the lock holding queue, so that the DML statement is executed after the DDL statement is executed, and the DML statement is executed because the same is the application for the shared-level MDL lock. accelerate.
  • the second device is further configured to add the DML statement to a lock waiting queue of the MDL lock
  • the first unit is configured to: after exiting execution processing on the DDL statement, when When the lock holding queue and the statement in the lock waiting queue all correspond to the MDL lock of the sharing level, at least one of the DML statements is added from the lock waiting queue to the lock holding queue.
  • the DML statement acquired at this time is added to the lock waiting queue of the MDL.
  • the DML statement added to the MDL lock wait queue may be added to the lock holding queue by the lock waiting queue, and if there is a DML statement in the subsequent lock waiting queue, since Apply for a shared-level MDL lock, so they are added to the lock holding queue until the statement that requests the mutual exclusion level MDL lock appears to stop adding.
  • the first unit is configured to: after exiting execution processing on the DDL statement, when the lock holding queue or the lock waiting queue has a statement corresponding to the exclusive MDL lock, the DML is At least one of the statements is added to the lock wait queue.
  • the DML statement acquired at this time needs to apply for the shared-level MDL lock and DDL.
  • the exclusive MDL locks applied by the statement are mutually exclusive, that is, the DML statement cannot share the MDL lock with the DML statement even if the application is successful.
  • the DML statement acquired at this time is added to the MDL lock waiting queue, and the same MDL lock waiting queue is also There are other DDL statements for applying for exclusive MDL locks.
  • the DML statement added to the MDL lock wait queue has an exclusive MDL lock in the previous queue, or the current MDL lock holding queue statement holds an exclusive MDL lock. At least one of the MDL statements obtained at this time is added to the lock waiting queue.
  • step S1 shows a flow chart of a method for processing DDL statements in a relational database in accordance with another aspect of the present application. Wherein, step S1, step S2 and step S3 are included.
  • the device 1 acquires a DDL statement submitted by the user about the target table, where the DDL statement includes corresponding waiting setting information; in step S2, the device 1 applies for the exclusive MDL lock corresponding to the target table; In step S3, if the device 1 fails to apply for the exclusive MDL lock, the device 1 performs an exit process on the DDL statement according to the waiting setting information.
  • the device 1 acquires a DDL statement submitted by the user regarding the target table in step S1, wherein the DDL statement includes corresponding waiting setting information.
  • the manner of obtaining the DDL statement submitted by the user about the target table may be performed by a database management system, and the DDL statement is a database definition language, and the DDL statement about the target table is executed before the execution in order to provide a concurrent access to the dictionary object cache in the memory.
  • the protection, as well as the mutual exclusion of some database language operations, need to apply for MDL locks to protect the data in the table when the statement is executed.
  • the waiting setting information is setting information of a corresponding execution action when the DDL statement requests the MDL lock to be blocked, and includes an action performed after the user desires that the DDL statement is blocked, and the action includes continuing to wait or immediately exit waiting for related operations. For example, when a DDL statement requests an exclusive MDL lock, an execution conflict occurs with a DML statement that previously applied for a shared-level MDL lock. Therefore, after entering the lock waiting queue and waiting for the DML statement to execute, the MDL lock application is performed, and the subsequent DML statements are all due to The DDL statement waits and enters the lock waiting queue to cause blocking.
  • the DDL statement includes the corresponding waiting setting information
  • the example DDL statement enters the lock waiting queue, it waits for a certain time to exit or immediately exit according to the waiting setting information. In order to avoid the blocking or interruption of the database business caused by the blocking of the application MDL lock statement.
  • the waiting setting information includes at least one of the following: a set waiting time; zero waiting.
  • the set waiting time is set in the DDL statement to wait for the set time. If the set time is exceeded, the execution task of the DDL statement fails to be exited immediately.
  • the DDL statement is set to Alter table test wait 1 add col1 number, that is, Waiting for 1 second after failing to apply for the MDL lock, so that it is deleted in the MDL lock waiting queue, the blocked application sharing level DML language can therefore reduce the waiting time or the current language when the current MDL lock is shared The sentences are executed together.
  • Zero wait that is, the DDL statement execution task fails to be exited immediately after the feedback of the application MDL lock failure is set in the DDL statement.
  • the DDL statement is set to Alter table test no_wait add col1 number, and the subsequent DDL statement waits in the MDL lock waiting queue.
  • the DML language can reduce latency or co-execute with the current statement when the current MDL lock is shared, reducing the time that database-related services are unavailable.
  • the device 1 applies for an exclusive MDL lock corresponding to the target table.
  • the exclusive MDL lock is a conflict that the DDL statement conflicts when the target table that is the object of the statement execution is not executed concurrently with other database languages (for example, the database manipulation language DML) before being executed, for example,
  • the DDL statement performs an insert operation on the same target table when the entire table delete of the target table is performed, and the concurrent execution conflict is generated at this time.
  • the DDL statement in the relational database will be executed before the execution. Applying an exclusive MDL lock makes it impossible for DDL statements to be executed outside the target table at the time of execution, thereby improving the execution efficiency of the database language and protecting the data in the table.
  • step S3 if the device 1 fails to apply for the exclusive MDL lock, the device 1 performs an exit process on the DDL statement according to the waiting setting information. Because the DDL statement applies for an exclusive MDL lock, when the statement in the corresponding lock holding queue of the target table operation corresponds to the shared-level MDL lock, the application for the shared DDL statement fails for the exclusive MDL lock, and the DDL statement enters the lock waiting queue. At this time, the waiting setting information in the DDL statement is triggered, and the triggering method includes setting the feedback information after the acquisition of the MDL lock application fails, starting the setting information corresponding program, reading the setting information, and performing the setting action accordingly.
  • the waiting setting information includes an action performed by the user after the DDL statement is blocked, and the action includes continuing to wait or immediately exiting waiting and other related operations.
  • the waiting information is waited according to the waiting setting information.
  • the lock holding queue described above is a relational database, and the database language is in the queue after the application for the MDL lock is successful. Accordingly, the lock waiting queue applies for the MDL lock for the database language because the applied lock type is mutually exclusive and fails. Wait for the MDL lock to hold the statement and continue to apply for the MDL lock queue.
  • step S3 if the device 1 successfully requests the exclusive MDL lock, the DDL statement is executed. That is, when the DDL statement applies for the exclusive MDL lock, no other statement holds the MDL lock with the exclusive MDL mutual exclusion type.
  • the DDL statement acquires the exclusive MDL lock, enters the lock holding queue and then executes the statement content, and performs corresponding operations on the target table.
  • the waiting setting information includes a set waiting time, wherein, in step S3, if the device 1 fails to apply for the exclusive MDL lock, and waits for the waiting time, the application further requests the exclusive MDL lock; Still applying for the exclusive MDL lock fails, exiting the execution processing of the DDL statement. That is, before the set waiting time starts to execute, immediately before the DDL statement execution task fails to exit, the setting information of re-applying the MDL lock may be added, that is, after waiting for the set time, for example, after waiting for 1 second, after waiting for 1 second, Continue to initiate the application for the MDL lock. If the MDL lock is not held at this time, the application can be successfully applied and executed with the exclusive MDL lock.
  • the execution immediately causes the DDL statement execution task to fail to exit, thereby increasing the probability that the DDL applies for the MDL lock, and improving the application efficiency of the MDL lock.
  • the waiting setting information includes zero waiting, wherein, in step S3, if the device 1 fails to apply for the exclusive MDL lock, the execution processing of the DDL statement is exited. That is, after the DDL statement obtains the feedback of applying for the exclusive MDL lock failure, according to the zero waiting setting, the DDL statement execution task is immediately defeated, so that the DDL statement is deleted in the MDL lock waiting queue, so the MDL lock waiting queue can be reduced. Waiting time for other statements to avoid database related business interruption or application access blocked due to long waiting time.
  • a method flow (not shown) for processing DDL statements in a relational database in accordance with a preferred embodiment of the present application.
  • the process includes a step S1, a step S2, and a step S3, wherein the steps S1 and S2 both increase the processing of the data manipulation language DML based on the steps S1 and S2 shown in FIG. 2, and the step S3 includes the step S31.
  • the device 1 exits the execution processing of the DDL statement in step S31, at least one of the DML statements is added to the lock holding queue or the lock waiting queue of the MDL lock.
  • the device 1 further acquires a DML statement submitted by the user about the target table in step S1, wherein step S3 further includes step S31, in which the device 1 exits execution processing on the DDL statement. Thereafter, at least one of the DML statements is added to a lock holding queue or a lock waiting queue of the MDL lock.
  • the acquired database language of the target table includes DML in addition to the DDL. Therefore, after exiting the execution process of the DDL statement, the DDL statement is deleted from the MDL lock waiting queue, and subsequently in the MDL lock waiting queue.
  • the DML statements in the order will be processed in the order in which they are arranged.
  • At least one DML statement is added to the MDL lock hold or the lock wait queue according to the type requirements of the MDL lock in the queue, for example, if the current MDL lock holds the queue.
  • the MDL lock type held by the database language statement is not mutually exclusive and shareable with the DML statement in the lock wait queue, then the DML statement is added to the lock holding queue according to the order until a database statement with mutually exclusive requirements appears, and the The statement is excluded from the MDL lock holding queue and remains in the MDL lock waiting queue.
  • the statement will be The obtained DML statement is added to the MDL lock waiting queue, thereby awakening the blocked DML statement, so that the database related application access efficiency is improved or the business speed is accelerated.
  • the At least one of the DML statements is added to the lock holding queue.
  • the DML statement includes the DML statement processed again and processed for the first time, that is, the statement executed before the lock waiting queue position where the DML statement is located after exiting the execution of the DDL statement, and the statement in the currently held queue.
  • the DML statement can be added to the lock holding queue together with the statement in the lock waiting queue before the lock waiting queue position.
  • dml1 and dml2 refer to two DML statements.
  • dml3, dml4, and dml5 refer to the DML statements in the lock wait queue, which need to apply for the shared-level MDL lock.
  • dml6 refers to the DML that the newly acquired user needs to apply for the shared-level MDL lock.
  • dml3 to dm16 can be added to the lock holding queue, so that the DML statement is executed after the DDL statement is executed, and the DML statement is executed because the same is the application for the shared-level MDL lock. accelerate.
  • the device 1 also adds the DML statement to the lock waiting queue of the MDL lock in step S2, wherein after the device 1 exits the execution processing of the DDL statement in step S31, when When the lock holding queue and the statement in the lock waiting queue all correspond to the MDL lock of the sharing level, at least one of the DML statements is added from the lock waiting queue to the lock holding queue.
  • a DDL statement is applied to an MDL lock
  • the DML statement acquired at this time needs to apply for the shared-level MDL lock and the exclusive MDL lock applied by the DDL statement to be mutually exclusive. That is, even if the application is successful, the DML statement cannot share the MDL lock with the DML statement.
  • the DML statement acquired at this time is added to the lock waiting queue of the MDL.
  • the DML statement added to the MDL lock wait queue may be added to the lock holding queue by the lock waiting queue, and if there is a DML statement in the subsequent lock waiting queue, since Apply for a shared-level MDL lock, so they are added to the lock holding queue until the statement that requests the mutual exclusion level MDL lock appears to stop adding.
  • the DML statement is at least One is added to the lock wait queue.
  • the DML statement acquired at this time needs to apply for the shared-level MDL lock and the exclusive MDL lock applied by the DDL statement to be mutually exclusive. That is, even if the DDL statement is successful, the DML statement cannot share the MDL lock with it. Therefore, the DML statement obtained at this time is added to the MDL lock waiting queue.
  • the DML statement added to the MDL lock wait queue has an exclusive MDL lock in the previous queue, or the current MDL lock holding queue statement holds an exclusive MDL lock. At least one of the MDL statements obtained at this time is added to the lock waiting queue.

Abstract

Provided are a method and device for processing a DDL statement in a relational database. Specifically, the method comprises: acquiring a DDL statement regarding a target table submitted by a user, wherein the DDL statement comprises a corresponding item of information waiting to be set (S1); requesting an exclusive MDL lock corresponding to the target table (S2); if requesting the exclusive MDL lock fails, exiting from the DDL statement according to the information (S3). Compared with the conventional art, the method addresses a block that arises when concurrently executing data definition language (DDL) and data manipulation language (DML) statements in a relational database, thereby avoiding database-related application access blockage or service interruption, enhancing execution efficiency of database language statements, and improving reliability of the database.

Description

一种处理关系型数据库中DDL语句的方法与设备Method and device for processing DDL statement in relational database
本申请要求2015年06月11日递交的申请号为201510318978.7、发明名称为“一种处理关系型数据库中DDL语句的方法与设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。The present application claims priority to Chinese Patent Application No. 201510318978.7, entitled "Method and Apparatus for Handling DDL Statements in Relational Databases", filed on June 11, 2015, the entire contents of which are incorporated herein by reference. In the application.
技术领域Technical field
本发明涉及计算机领域,尤其涉及一种用于处理关系型数据库中DDL语句的技术。The present invention relates to the field of computers, and in particular, to a technique for processing DDL statements in a relational database.
背景技术Background technique
在关系型数据库的运维过程中,数据定义语言DDL以及数据操纵语言DML在并发执行时,会因为各自所申请的MDL锁的类型不同所致的无法兼容问题使两种语句在执行过程中产生阻塞,从而阻塞后续语句的执行。现有技术,可以通过对DDL语句进行设置,使得并发执行发生语句冲突时DDL语句快速失败,从而解决语句并发执行阻塞。In the operation and maintenance process of the relational database, when the data definition language DDL and the data manipulation language DML are executed concurrently, the incompatibility problems caused by the different types of MDL locks applied for each other cause the two statements to be generated during execution. Blocked, blocking the execution of subsequent statements. In the prior art, the DDL statement can be set to make the DDL statement fail quickly when the statement conflict occurs concurrently, thereby solving the statement concurrent execution blocking.
然而,在现有技术仅可在段落或全局级别对DDL语句进行设置,无法做到语句级别的灵活操作,运维人员在操作过程中,会因语句并发执行阻塞时间过长引发应用访问受阻或业务中断。However, in the prior art, the DDL statement can only be set at the paragraph or global level, and the flexible operation of the statement level cannot be performed. In the operation process, the operation and maintenance personnel may cause the application access to be blocked due to the excessive blocking time of the statement concurrent execution. Business disruption.
发明内容Summary of the invention
本申请的目的是提供一种用于处理关系型数据库中DDL语句的方法与设备。It is an object of the present application to provide a method and apparatus for processing DDL statements in a relational database.
根据本申请的一个方面,提供了一种用于处理关系型数据库中DDL语句的方法,包括:According to an aspect of the present application, a method for processing a DDL statement in a relational database is provided, comprising:
获取用户提交的关于目标表的DDL语句,其中,所述DDL语句包括对应的等待设置信息;Obtaining a DDL statement submitted by the user about the target table, where the DDL statement includes corresponding waiting setting information;
申请所述目标表所对应的排他性MDL锁;Applying an exclusive MDL lock corresponding to the target table;
若申请所述排他性MDL锁失败,根据所述等待设置信息对所述DDL语句执行退出处理。If the application for the exclusive MDL lock fails, the exit processing is performed on the DDL statement according to the waiting setting information.
根据本申请的另一方面,还提供了一种用于处理关系型数据库中DDL语句的设备,包括:According to another aspect of the present application, there is also provided an apparatus for processing a DDL statement in a relational database, comprising:
第一装置,用于获取用户提交的关于目标表的DDL语句,其中,所述DDL语句包括对应的等待设置信息; a first device, configured to acquire a DDL statement submitted by the user about the target table, where the DDL statement includes corresponding waiting setting information;
第二装置,用于申请所述目标表所对应的排他性MDL锁;a second device, configured to apply for an exclusive MDL lock corresponding to the target table;
第三装置,用于若申请所述排他性MDL锁失败,根据所述等待设置信息对所述DDL语句执行退出处理。And a third device, configured to perform an exit process on the DDL statement according to the waiting setting information if the application for the exclusive MDL lock fails.
与现有技术相比,本申请通过获取用户提交的关于目标表的DDL语句及其中所设置对应的等待信息,申请所述目标表所对应的排他性MDL锁,若申请失败则根据所设置的等待信息中的DDL语句执行退出处理,解决系型数据库中数据定义语言DDL以及数据操纵语言DML并发执行阻塞问题,从而避免发生数据库关联应用访问受阻或业务中断,提高数据库语言的执行效率,提升数据库的可靠性。Compared with the prior art, the present application requests the exclusive MDL lock corresponding to the target table by acquiring the DDL statement submitted by the user about the target table and the corresponding waiting information set in the target table, and if the application fails, according to the set waiting The DDL statement in the information performs the exit processing, solves the data definition language DDL in the system database and the data manipulation language DML concurrently executes the blocking problem, thereby avoiding the blocked access or business interruption of the database associated application, improving the execution efficiency of the database language, and improving the database. reliability.
附图说明DRAWINGS
通过阅读参照以下附图所作的对非限制性实施例所作的详细描述,本发明的其它特征、目的和优点将会变得更明显:Other features, objects, and advantages of the present invention will become more apparent from the Detailed Description of Description
图1示出根据本申请一个方面的一种用于处理关系型数据库中DDL语句的设备示意图;1 shows a schematic diagram of an apparatus for processing DDL statements in a relational database, in accordance with an aspect of the present application;
图2示出根据本申请另一个方面的一种用于处理关系型数据库中DDL语句的方法流程图。2 shows a flow chart of a method for processing DDL statements in a relational database in accordance with another aspect of the present application.
附图中相同或相似的附图标记代表相同或相似的部件。The same or similar reference numerals in the drawings denote the same or similar components.
具体实施方式detailed description
下面结合附图对本发明作进一步详细描述。The invention is further described in detail below with reference to the accompanying drawings.
在本申请一个典型的配置中,终端、服务网络的设备和可信方均包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。In a typical configuration of the present application, the terminal, the device of the service network, and the trusted party each include one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。The memory may include non-persistent memory, random access memory (RAM), and/or non-volatile memory in a computer readable medium, such as read only memory (ROM) or flash memory. Memory is an example of a computer readable medium.
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、 只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括非暂存电脑可读媒体(transitory media),如调制的数据信号和载波。Computer readable media includes both permanent and non-persistent, removable and non-removable media. Information storage can be implemented by any method or technology. The information can be computer readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read only memory. (ROM), electrically erasable programmable read only memory (EEPROM), flash memory or other memory technology, CD-ROM, digital versatile disc (DVD) or other optical storage, magnetic tape cartridge, magnetic tape storage or other magnetic storage device or any other non-transportable media that can be used for storage can be calculated Information accessed by the device. As defined herein, computer readable media does not include non-transitory computer readable media, such as modulated data signals and carrier waves.
图1示出根据本申请一个方面的一种用于处理关系型数据库中DDL语句的设备1的示意图。其中,所述设备1包括第一装置11、第二装置12和第三装置13。1 shows a schematic diagram of an apparatus 1 for processing DDL statements in a relational database, in accordance with an aspect of the present application. The device 1 comprises a first device 11, a second device 12 and a third device 13.
其中,所述设备1的第一装置11用于获取用户提交的关于目标表的DDL语句,其中,所述DDL语句包括对应的等待设置信息;第二装置12用于申请所述目标表所对应的排他性MDL锁;第三装置用于若申请所述排他性MDL锁失败,根据所述等待设置信息对所述DDL语句执行退出处理。The first device 11 of the device 1 is configured to acquire a DDL statement submitted by a user about a target table, where the DDL statement includes corresponding waiting setting information; and the second device 12 is configured to apply for the target table. The exclusive MDL lock; the third device is configured to perform an exit process on the DDL statement according to the waiting setting information if the application for the exclusive MDL lock fails.
具体地,第一装置11用于获取用户提交的关于目标表的DDL语句,其中,所述DDL语句包括对应的等待设置信息。其中,获取用户提交所述关于目标表的DDL语句的方式可以通过数据库管理系统进行,DDL语句是数据库定义语言,关于目标表的DDL语句在执行前出于为了提供对并发访问内存中字典对象缓存的保护,以及确保一些数据库语言操作的互斥性等目的,需要申请MDL锁对表中数据在执行语句的时候进行保护。所述等待设置信息是在DDL语句申请MDL锁被阻塞时的相应执行动作的设置信息,包括用户希望DDL语句被阻塞后所进行的动作,所述动作包括继续等待或立即退出等待等相关操作。例如,在DDL语句申请排他性MDL锁时与之前申请共享级MDL锁的DML语句发生执行冲突,因此进入锁等待队列等待DML语句执行完再进行MDL锁申请,此时后续的DML的语句均会因为DDL语句在等待而同样进入锁等待队列从而造成阻塞,若DDL语句包括对应的等待设置信息,则在所举例DDL语句进入锁等待队列时,会依据所述等待设置信息等待一定时间退出或立即退出,从而避免造成申请MDL锁语句阻塞而所致的数据库业务受阻或中断。Specifically, the first device 11 is configured to acquire a DDL statement submitted by the user about the target table, where the DDL statement includes corresponding waiting setting information. Wherein, the manner of obtaining the DDL statement submitted by the user about the target table may be performed by a database management system, and the DDL statement is a database definition language, and the DDL statement about the target table is executed before the execution in order to provide a concurrent access to the dictionary object cache in the memory. The protection, as well as the mutual exclusion of some database language operations, need to apply for MDL locks to protect the data in the table when the statement is executed. The waiting setting information is setting information of a corresponding execution action when the DDL statement requests the MDL lock to be blocked, and includes an action performed after the user desires that the DDL statement is blocked, and the action includes continuing to wait or immediately exit waiting for related operations. For example, when a DDL statement requests an exclusive MDL lock, an execution conflict occurs with a DML statement that previously applied for a shared-level MDL lock. Therefore, after entering the lock waiting queue and waiting for the DML statement to execute, the MDL lock application is performed, and the subsequent DML statements are all due to The DDL statement waits and enters the lock waiting queue to cause blocking. If the DDL statement includes the corresponding waiting setting information, when the example DDL statement enters the lock waiting queue, it waits for a certain time to exit or immediately exit according to the waiting setting information. In order to avoid the blocking or interruption of the database business caused by the blocking of the application MDL lock statement.
优选地,所述等待设置信息包括以下至少任一项:设定的等待时间;零等待。其中,设定的等待时间即在DDL语句中设置等待设定的时间,超过设定时间即立即使得DDL语句的执行任务失败退出,例如,DDL语句设置为Alter table test wait 1 add col1 number,即在申请MDL锁失败后等待1秒钟,从而使得其在MDL锁等待队列中被删除,被阻塞的申请共享级的DML语言因此可以减少等待时间或在当前MDL锁为共享级时与当前语句共同执行。零等待,即在DDL语句中设置得到申请MDL锁失败的反馈之后立即使得DDL语句的执行任务失败退出,例如,DDL语句设置为Alter table test no_wait add col1  number,同样使得后续在MDL锁等待队列中的DML语言能够减少等待时间或在当前MDL锁为共享级时与当前语句共同执行,减少数据库相关业务不可用的时间。Preferably, the waiting setting information includes at least one of the following: a set waiting time; zero waiting. The set waiting time is set in the DDL statement to wait for the set time. If the set time is exceeded, the execution task of the DDL statement fails to be exited immediately. For example, the DDL statement is set to Alter table test wait 1 add col1 number, that is, Waiting for 1 second after failing to apply for the MDL lock, so that it is deleted in the MDL lock waiting queue, the blocked application sharing level DML language can therefore reduce the waiting time or the current statement when the current MDL lock is the sharing level carried out. Zero wait, that is, the DDL statement execution task fails to exit immediately after setting the feedback of the failed application for the MDL lock in the DDL statement. For example, the DDL statement is set to Alter table test no_wait add col1 Number also enables subsequent DML languages in the MDL lock wait queue to reduce latency or co-execute with the current statement when the current MDL lock is shared, reducing the time that database-related services are unavailable.
本领域技术人员应能理解上述设置设定的等待时间以及零等待的方式仅为举例,其他现有的或今后可能出现的根据所述设置设定的等待时间以及零等待的方式如可适用于本发明,也应包含在本发明保护范围以内,并在此以引用方式包含于此。Those skilled in the art should be able to understand that the waiting time of the above setting and the manner of zero waiting are only examples, and other existing or future possible waiting times according to the setting and zero waiting mode may be applied to The invention is also intended to be included within the scope of the invention, and is hereby incorporated by reference.
接着,第二装置12用于申请所述目标表所对应的排他性MDL锁。其中,所述排他性MDL锁是DDL语句在执行之前出于保护作为语句执行对象的目标表在被改变的时候不会与其它数据库语言(例如数据库操纵语言DML)并发执行的时候产生冲突,例如,DDL语句在执行对目标表的整表删除时DML语句执行对同一目标表的插入操作,此时即产生所述并发执行冲突,为了避免这种情况,在关系型数据库中DDL语句会在执行前申请排他性MDL锁,使得DDL在执行时DML语句被排斥在目标表外无法同时执行,从而提升数据库语言的执行效率,保护表中的数据。Next, the second device 12 is configured to apply for an exclusive MDL lock corresponding to the target table. Wherein, the exclusive MDL lock is a conflict that the DDL statement conflicts when the target table that is the object of the statement execution is not executed concurrently with other database languages (for example, the database manipulation language DML) before being executed, for example, The DDL statement performs an insert operation on the same target table when the entire table delete of the target table is performed, and the concurrent execution conflict is generated at this time. To avoid this, the DDL statement in the relational database will be executed before the execution. Applying an exclusive MDL lock makes it impossible for DDL statements to be executed outside the target table at the time of execution, thereby improving the execution efficiency of the database language and protecting the data in the table.
接着,第三装置13用于若申请所述排他性MDL锁失败,根据所述等待设置信息对所述DDL语句执行退出处理。因为DDL语句申请排他性MDL锁,因此当对目标表操作的对应锁持有队列中的语句对应共享级的MDL锁时,出于排他性MDL锁无法进行共享DDL语句申请失败,DDL语句进入锁等待队列,此时,会触发DDL语句中等待设置信息,触发方法包括设置获取MDL锁申请失败后的反馈信息后启动设置信息对应程序,读取设置信息,并据此执行设置动作。其中,所述等待设置信息包括用户希望DDL语句被阻塞后所进行的动作,所述动作包括继续等待或立即退出等待等相关操作,在等待设置信息被触发后会依据所述等待设置信息等待一定时间退出或立即退出DDL语句的执行,从而避免DDL语句在锁等待队列中等待时间过长而阻塞之后可使用共享级MDL锁的DML语句。上文所述锁持有队列为关系型数据库中,数据库语言在申请MDL锁成功后所在的队列,相应地,所述锁等待队列为数据库语言申请MDL锁因为所申请锁类型互斥而失败后,等待MDL锁持有语句操作完毕继续申请MDL锁的队列。Next, the third device 13 is configured to perform an exit process on the DDL statement according to the waiting setting information if the application for the exclusive MDL lock fails. Because the DDL statement applies for an exclusive MDL lock, when the statement in the corresponding lock holding queue of the target table operation corresponds to the shared-level MDL lock, the application for the shared DDL statement fails for the exclusive MDL lock, and the DDL statement enters the lock waiting queue. At this time, the waiting setting information in the DDL statement is triggered, and the triggering method includes setting the feedback information after the acquisition of the MDL lock application fails, starting the setting information corresponding program, reading the setting information, and performing the setting action accordingly. The waiting setting information includes an action performed by the user after the DDL statement is blocked, and the action includes continuing to wait or immediately exiting waiting and other related operations. After waiting for the setting information to be triggered, the waiting information is waited according to the waiting setting information. The time exits or immediately exits the execution of the DDL statement, thereby avoiding the DML statement that the DDL statement can use the shared-level MDL lock after waiting too long in the lock wait queue. The lock holding queue described above is a relational database, and the database language is in the queue after the application for the MDL lock is successful. Accordingly, the lock waiting queue applies for the MDL lock for the database language because the applied lock type is mutually exclusive and fails. Wait for the MDL lock to hold the statement and continue to apply for the MDL lock queue.
本领域技术人员应能理解上述根据所述等待设置信息对所述DDL语句执行退出处理的方式仅为举例,其他现有的或今后可能出现的根据所述等待设置信息对所述DDL语句执行退出处理的方式如可适用于本发明,也应包含在本发明保护范围以内,并在此以引用方式包含于此。Those skilled in the art should understand that the manner of performing the exit processing on the DDL statement according to the waiting setting information is only an example, and other existing or future possible executions may be performed to exit the DDL statement according to the waiting setting information. The manner of treatment, as applicable to the present invention, is also intended to be included within the scope of the present invention and is hereby incorporated by reference.
优选地,所述第三装置用于:若申请所述排他性MDL锁成功,执行所述DDL语句。即DDL语句申请排他性MDL锁时,未有其它语句持有与排他性MDL互斥类型的MDL 锁,DDL语句获取排他性MDL锁,进入锁持有队列继而执行语句内容,对目标表进行相应的操作。Preferably, the third device is configured to: execute the DDL statement if the application for the exclusive MDL lock is successful. When the DDL statement applies for an exclusive MDL lock, there are no other statements that hold the MDL with the exclusive MDL mutually exclusive type. The lock, the DDL statement acquires the exclusive MDL lock, enters the lock holding queue and then executes the statement content, and performs corresponding operations on the target table.
更优选地,所述等待设置信息包括设定的等待时间,其中,所述第三装置用于:若申请所述排他性MDL锁失败,按所述等待时间等待后,再次申请所述排他性MDL锁;若仍申请所述排他性MDL锁失败,退出对所述DDL语句的执行处理。即在设定的等待时间开始执行立即使得DDL语句执行任务失败退出之前,可以加入重新申请MDL锁的设置信息,即在等待所设置时间后,例如接上文举例,在等待1秒中后,继续发起申请MDL锁,若此时MDL锁不被持有,即可申请成功并在持有排它性MDL锁的情况下被执行,若此时MDL锁仍被持有,且与DDL所申请的MDL锁冲突,则执行立即使得DDL语句执行任务失败退出,从而使得DDL申请MDL锁的几率增加,提高对MDL锁的申请效率。More preferably, the waiting setting information includes a set waiting time, wherein the third device is configured to: if the application for the exclusive MDL lock fails, wait for the waiting time to wait for the exclusive MDL lock again. If the application for the exclusive MDL lock fails, the execution of the DDL statement is exited. That is, before the set waiting time starts to execute, immediately before the DDL statement execution task fails to exit, the setting information of re-applying the MDL lock may be added, that is, after waiting for the set time, for example, after waiting for 1 second, after waiting for 1 second, Continue to initiate the application for the MDL lock. If the MDL lock is not held at this time, the application can be successfully applied and executed with the exclusive MDL lock. If the MDL lock is still held, and the application is with DDL. If the MDL lock conflicts, the execution immediately causes the DDL statement execution task to fail to exit, thereby increasing the probability that the DDL applies for the MDL lock, and improving the application efficiency of the MDL lock.
进一步地,所述等待设置信息包括零等待,其中,所述第三装置用于:若申请所述排他性MDL锁失败,退出对所述DDL语句的执行处理。即在DDL语句获取申请排他性MDL锁失败的反馈之后,根据零等待的设置,立即使得DDL语句执行任务失败退,从而使得DDL语句在MDL锁等待队列中被删除,因此可以减少MDL锁等待队列中其它语句的等待时间,避免因等待时间过长造成数据库相关业务中断或应用访问受阻。Further, the waiting setting information includes zero waiting, wherein the third device is configured to: quit the execution processing of the DDL statement if the exclusive MDL lock fails to be applied. That is, after the DDL statement obtains the feedback of applying for the exclusive MDL lock failure, according to the zero waiting setting, the DDL statement execution task is immediately defeated, so that the DDL statement is deleted in the MDL lock waiting queue, so the MDL lock waiting queue can be reduced. Waiting time for other statements to avoid database related business interruption or application access blocked due to long waiting time.
根据本申请一个优选实施例的一种用于处理关系型数据库中DDL语句的设备1(未示出)。所述设备1包括第一装置、第二装置和第三装置,其中,第一装置和第二装置均在图1所示的第一装置11和第二装置12的基础上增加数据操纵语言DML的处理情况,第三装置包括第一单元,所述第一单元用于退出对所述DDL语句的执行处理后,将所述DML语句中至少一个添加至所述MDL锁的锁持有队列或锁等待队列。An apparatus 1 (not shown) for processing DDL statements in a relational database in accordance with a preferred embodiment of the present application. The device 1 comprises a first device, a second device and a third device, wherein both the first device and the second device add a data manipulation language DML to the first device 11 and the second device 12 shown in FIG. Processing, the third device includes a first unit, the first unit is configured to: after exiting execution processing on the DDL statement, add at least one of the DML statements to a lock holding queue of the MDL lock or The lock waits for the queue.
具体地,所述第一装置还用于获取用户提交的关于所述目标表的DML语句,其中,所述第三装置还包括第一单元,用于在退出对所述DDL语句的执行处理后,将所述DML语句中至少一个添加至所述MDL锁的锁持有队列或锁等待队列。其中,所获取的用户提交关于所述目标表的数据库语言除DDL外还包括DML,因此,在退出DDL语句的执行处理后,DDL语句从MDL锁等待队列中被删除,后续在MDL锁等待队列中的DML语句将按照排列的顺序进行处理,根据队列中对MDL锁的类型需求,至少将一个DML语句添加至MDL锁持有或锁等待队列,例如,若当前MDL锁持有队列中数据库语言语句的所持有的MDL锁类型与锁等待队列中的DML语句不互斥可共享,则依照次序添加DML语句至锁持有队列直至有互斥需求的数据库语句出现,并将该语句排除在MDL锁 持有队列外,仍然留在MDL锁等待队列,若当前MDL锁持有队列中数据库语言语句的所持有的MDL锁类型与锁等待队列中的DML语句互斥,则将获取的DML语句添加至MDL锁等待队列,从而唤醒被阻塞的DML语句,使得数据库相关应用访问效率提升或业务速度加快。Specifically, the first device is further configured to acquire a DML statement submitted by the user about the target table, where the third device further includes a first unit, after exiting execution processing on the DDL statement, Adding at least one of the DML statements to a lock holding queue or a lock waiting queue of the MDL lock. The acquired database language of the target table includes DML in addition to the DDL. Therefore, after exiting the execution process of the DDL statement, the DDL statement is deleted from the MDL lock waiting queue, and subsequently in the MDL lock waiting queue. The DML statements in the order will be processed in the order in which they are arranged. At least one DML statement is added to the MDL lock hold or lock wait queue according to the type requirements of the MDL lock in the queue. For example, if the current MDL lock holds the database language in the queue. The MDL lock type held by the statement is not mutually exclusive and shareable with the DML statement in the lock wait queue. Then, the DML statement is added to the lock holding queue according to the order until the database statement with mutual exclusion needs appears, and the statement is excluded. MDL lock Outside the holding queue, it still remains in the MDL lock waiting queue. If the MDL lock type held by the database language statement in the current MDL lock holding queue is mutually exclusive with the DML statement in the lock waiting queue, the obtained DML statement is added. Go to the MDL lock wait queue to wake up blocked DML statements, making database-related application access efficient or faster.
优选地,所述第一单元用于在退出对所述DDL语句的执行处理后,当所述锁持有队列及所述锁等待队列中的语句均对应共享级所述MDL锁时,将所述DML语句中至少一个添加至所述锁持有队列。其中,DML语句包括再次处理以及首次处理的DML语句,即退出对所述DDL语句的执行处理后,在所述DML语句所在的锁等待队列位置之前使的语句以及当前所持有队列中的语句均对应共享及MDL锁,则DML语句可与其所在锁等待队列位置之前的所述锁等待队列中语句一同被添加至所述锁持有队列,例如,dml1与dml2指代两个DML语句其持有共享级的MDL锁,dml3、dml4、dml5指代在锁等待队列中的DML语句其需要申请共享级的MDL锁,dml6是指代刚获取的用户提交的需要申请共享级的MDL锁的DML英语剧,在排列在dml3之前的DDL语句被删除后,dml3至dm16均可被添加至所述锁持有队列,使得DDL语句退出执行处理后,DML语句执行因为同为申请共享级MDL锁而加快。Preferably, the first unit is configured to: after exiting execution processing on the DDL statement, when the lock holding queue and the statement in the lock waiting queue all correspond to the sharing level MDL lock, At least one of the DML statements is added to the lock holding queue. The DML statement includes the DML statement processed again and processed for the first time, that is, the statement executed before the lock waiting queue position where the DML statement is located after exiting the execution of the DDL statement, and the statement in the currently held queue. Corresponding to the shared and MDL locks, the DML statement can be added to the lock holding queue together with the statement in the lock waiting queue before the lock waiting queue position. For example, dml1 and dml2 refer to two DML statements. There are shared-level MDL locks, dml3, dml4, and dml5 refer to the DML statements in the lock wait queue, which need to apply for the shared-level MDL lock. dml6 refers to the DML that the newly acquired user needs to apply for the shared-level MDL lock. In the English drama, after the DDL statement arranged before dml3 is deleted, dml3 to dm16 can be added to the lock holding queue, so that the DML statement is executed after the DDL statement is executed, and the DML statement is executed because the same is the application for the shared-level MDL lock. accelerate.
更优选地,所述第二装置还用于将所述DML语句添加至所述MDL锁的锁等待队列,其中,所述第一单元用于在退出对所述DDL语句的执行处理后,当所述锁持有队列及所述锁等待队列中的语句均对应共享级所述MDL锁时,将所述DML语句中至少一个从所述锁等待队列添加至所述锁持有队列。在有DDL语句在对MDL锁进行申请时,因为DDL语句所申请的是排他性的MDL锁,此时获取的DML语句需要申请的共享级的MDL锁与DDL语句所申请的排他性MDL锁互斥,即DDL语句即使申请成功,DML语句也无法与其共享MDL锁,因此,此时获取的DML语句被添加至MDL的锁等待队列。当所述DDL语句被执行退出处理后,被添加至MDL锁等待队列的DML语句可由锁等待队列中被添加至锁持有队列,若其后的锁等待队列中还有DML语句,因为均为申请共享级MDL锁,所以均添加至锁持有队列直至有申请互斥级别MDL锁的语句出现停止添加。More preferably, the second device is further configured to add the DML statement to a lock waiting queue of the MDL lock, wherein the first unit is configured to: after exiting execution processing on the DDL statement, when When the lock holding queue and the statement in the lock waiting queue all correspond to the MDL lock of the sharing level, at least one of the DML statements is added from the lock waiting queue to the lock holding queue. When a DDL statement is applied to an MDL lock, because the DDL statement is applied for an exclusive MDL lock, the DML statement acquired at this time needs to apply for the shared-level MDL lock and the exclusive MDL lock applied by the DDL statement to be mutually exclusive. That is, even if the application is successful, the DML statement cannot share the MDL lock with the DML statement. Therefore, the DML statement acquired at this time is added to the lock waiting queue of the MDL. When the DDL statement is executed and exited, the DML statement added to the MDL lock wait queue may be added to the lock holding queue by the lock waiting queue, and if there is a DML statement in the subsequent lock waiting queue, since Apply for a shared-level MDL lock, so they are added to the lock holding queue until the statement that requests the mutual exclusion level MDL lock appears to stop adding.
进一步地,所述第一单元用于在退出对所述DDL语句的执行处理后,当所述锁持有队列或所述锁等待队列中存在语句对应排他性所述MDL锁时,将所述DML语句中至少一个添加至所述锁等待队列。在有DDL语句在对MDL锁进行申请时,因为DDL语句所申请的是排他性的MDL锁,此时获取的DML语句需要申请的共享级的MDL锁与DDL 语句所申请的排他性MDL锁互斥,即DDL语句即使申请成功,DML语句也无法与其共享MDL锁,因此,此时获取的DML语句被添加至MDL的锁等待队列,同样MDL锁等待队列里还有其它因申请排他性MDL锁的DDL语句。当所述DDL语句被执行退出处理后,被添加至MDL锁等待队列的DML语句若之前的队列中存在申请排他性MDL锁的语句或当前MDL锁持有队列语句持有的是排他性MDL锁,则此时获取的MDL语句至少有一个添加至所述锁等待队列。Further, the first unit is configured to: after exiting execution processing on the DDL statement, when the lock holding queue or the lock waiting queue has a statement corresponding to the exclusive MDL lock, the DML is At least one of the statements is added to the lock wait queue. When there is a DDL statement in the application for the MDL lock, because the DDL statement is applied for an exclusive MDL lock, the DML statement acquired at this time needs to apply for the shared-level MDL lock and DDL. The exclusive MDL locks applied by the statement are mutually exclusive, that is, the DML statement cannot share the MDL lock with the DML statement even if the application is successful. Therefore, the DML statement acquired at this time is added to the MDL lock waiting queue, and the same MDL lock waiting queue is also There are other DDL statements for applying for exclusive MDL locks. When the DDL statement is executed and exited, the DML statement added to the MDL lock wait queue has an exclusive MDL lock in the previous queue, or the current MDL lock holding queue statement holds an exclusive MDL lock. At least one of the MDL statements obtained at this time is added to the lock waiting queue.
图2示出根据本申请另一个方面的一种用于处理关系型数据库中DDL语句的方法流程图。其中,包括步骤S1、步骤S2和步骤S3。2 shows a flow chart of a method for processing DDL statements in a relational database in accordance with another aspect of the present application. Wherein, step S1, step S2 and step S3 are included.
其中,在步骤S1中设备1获取用户提交的关于目标表的DDL语句,其中,所述DDL语句包括对应的等待设置信息;在步骤S2中设备1申请所述目标表所对应的排他性MDL锁;在步骤S3中设备1若申请所述排他性MDL锁失败,根据所述等待设置信息对所述DDL语句执行退出处理。In the step S1, the device 1 acquires a DDL statement submitted by the user about the target table, where the DDL statement includes corresponding waiting setting information; in step S2, the device 1 applies for the exclusive MDL lock corresponding to the target table; In step S3, if the device 1 fails to apply for the exclusive MDL lock, the device 1 performs an exit process on the DDL statement according to the waiting setting information.
具体地,在步骤S1中设备1获取用户提交的关于目标表的DDL语句,其中,所述DDL语句包括对应的等待设置信息。其中,获取用户提交所述关于目标表的DDL语句的方式可以通过数据库管理系统进行,DDL语句是数据库定义语言,关于目标表的DDL语句在执行前出于为了提供对并发访问内存中字典对象缓存的保护,以及确保一些数据库语言操作的互斥性等目的,需要申请MDL锁对表中数据在执行语句的时候进行保护。所述等待设置信息是在DDL语句申请MDL锁被阻塞时的相应执行动作的设置信息,包括用户希望DDL语句被阻塞后所进行的动作,所述动作包括继续等待或立即退出等待等相关操作。例如,在DDL语句申请排他性MDL锁时与之前申请共享级MDL锁的DML语句发生执行冲突,因此进入锁等待队列等待DML语句执行完再进行MDL锁申请,此时后续的DML的语句均会因为DDL语句在等待而同样进入锁等待队列从而造成阻塞,若DDL语句包括对应的等待设置信息,则在所举例DDL语句进入锁等待队列时,会依据所述等待设置信息等待一定时间退出或立即退出,从而避免造成申请MDL锁语句阻塞而所致的数据库业务受阻或中断。Specifically, the device 1 acquires a DDL statement submitted by the user regarding the target table in step S1, wherein the DDL statement includes corresponding waiting setting information. Wherein, the manner of obtaining the DDL statement submitted by the user about the target table may be performed by a database management system, and the DDL statement is a database definition language, and the DDL statement about the target table is executed before the execution in order to provide a concurrent access to the dictionary object cache in the memory. The protection, as well as the mutual exclusion of some database language operations, need to apply for MDL locks to protect the data in the table when the statement is executed. The waiting setting information is setting information of a corresponding execution action when the DDL statement requests the MDL lock to be blocked, and includes an action performed after the user desires that the DDL statement is blocked, and the action includes continuing to wait or immediately exit waiting for related operations. For example, when a DDL statement requests an exclusive MDL lock, an execution conflict occurs with a DML statement that previously applied for a shared-level MDL lock. Therefore, after entering the lock waiting queue and waiting for the DML statement to execute, the MDL lock application is performed, and the subsequent DML statements are all due to The DDL statement waits and enters the lock waiting queue to cause blocking. If the DDL statement includes the corresponding waiting setting information, when the example DDL statement enters the lock waiting queue, it waits for a certain time to exit or immediately exit according to the waiting setting information. In order to avoid the blocking or interruption of the database business caused by the blocking of the application MDL lock statement.
优选地,所述等待设置信息包括以下至少任一项:设定的等待时间;零等待。其中,设定的等待时间即在DDL语句中设置等待设定的时间,超过设定时间即立即使得DDL语句的执行任务失败退出,例如,DDL语句设置为Alter table test wait 1 add col1 number,即在申请MDL锁失败后等待1秒钟,从而使得其在MDL锁等待队列中被删除,被阻塞的申请共享级的DML语言因此可以减少等待时间或在当前MDL锁为共享级时与当前语 句共同执行。零等待,即在DDL语句中设置得到申请MDL锁失败的反馈之后立即使得DDL语句的执行任务失败退出,例如,DDL语句设置为Alter table test no_wait add col1 number,同样使得后续在MDL锁等待队列中的DML语言能够减少等待时间或在当前MDL锁为共享级时与当前语句共同执行,减少数据库相关业务不可用的时间。Preferably, the waiting setting information includes at least one of the following: a set waiting time; zero waiting. The set waiting time is set in the DDL statement to wait for the set time. If the set time is exceeded, the execution task of the DDL statement fails to be exited immediately. For example, the DDL statement is set to Alter table test wait 1 add col1 number, that is, Waiting for 1 second after failing to apply for the MDL lock, so that it is deleted in the MDL lock waiting queue, the blocked application sharing level DML language can therefore reduce the waiting time or the current language when the current MDL lock is shared The sentences are executed together. Zero wait, that is, the DDL statement execution task fails to be exited immediately after the feedback of the application MDL lock failure is set in the DDL statement. For example, the DDL statement is set to Alter table test no_wait add col1 number, and the subsequent DDL statement waits in the MDL lock waiting queue. The DML language can reduce latency or co-execute with the current statement when the current MDL lock is shared, reducing the time that database-related services are unavailable.
本领域技术人员应能理解上述设置设定的等待时间以及零等待的方式仅为举例,其他现有的或今后可能出现的根据所述设置设定的等待时间以及零等待的方式如可适用于本发明,也应包含在本发明保护范围以内,并在此以引用方式包含于此。Those skilled in the art should be able to understand that the waiting time of the above setting and the manner of zero waiting are only examples, and other existing or future possible waiting times according to the setting and zero waiting mode may be applied to The invention is also intended to be included within the scope of the invention, and is hereby incorporated by reference.
接着,在步骤S2中设备1申请所述目标表所对应的排他性MDL锁。其中,所述排他性MDL锁是DDL语句在执行之前出于保护作为语句执行对象的目标表在被改变的时候不会与其它数据库语言(例如数据库操纵语言DML)并发执行的时候产生冲突,例如,DDL语句在执行对目标表的整表删除时DML语句执行对同一目标表的插入操作,此时即产生所述并发执行冲突,为了避免这种情况,在关系型数据库中DDL语句会在执行前申请排他性MDL锁,使得DDL在执行时DML语句被排斥在目标表外无法同时执行,从而提升数据库语言的执行效率,保护表中的数据。Next, in step S2, the device 1 applies for an exclusive MDL lock corresponding to the target table. Wherein, the exclusive MDL lock is a conflict that the DDL statement conflicts when the target table that is the object of the statement execution is not executed concurrently with other database languages (for example, the database manipulation language DML) before being executed, for example, The DDL statement performs an insert operation on the same target table when the entire table delete of the target table is performed, and the concurrent execution conflict is generated at this time. To avoid this, the DDL statement in the relational database will be executed before the execution. Applying an exclusive MDL lock makes it impossible for DDL statements to be executed outside the target table at the time of execution, thereby improving the execution efficiency of the database language and protecting the data in the table.
接着,在步骤S3中设备1若申请所述排他性MDL锁失败,根据所述等待设置信息对所述DDL语句执行退出处理。因为DDL语句申请排他性MDL锁,因此当对目标表操作的对应锁持有队列中的语句对应共享级的MDL锁时,出于排他性MDL锁无法进行共享DDL语句申请失败,DDL语句进入锁等待队列,此时,会触发DDL语句中等待设置信息,触发方法包括设置获取MDL锁申请失败后的反馈信息后启动设置信息对应程序,读取设置信息,并据此执行设置动作。其中,所述等待设置信息包括用户希望DDL语句被阻塞后所进行的动作,所述动作包括继续等待或立即退出等待等相关操作,在等待设置信息被触发后会依据所述等待设置信息等待一定时间退出或立即退出DDL语句的执行,从而避免DDL语句在锁等待队列中等待时间过长而阻塞之后可使用共享级MDL锁的DML语句。上文所述锁持有队列为关系型数据库中,数据库语言在申请MDL锁成功后所在的队列,相应地,所述锁等待队列为数据库语言申请MDL锁因为所申请锁类型互斥而失败后,等待MDL锁持有语句操作完毕继续申请MDL锁的队列。Next, in step S3, if the device 1 fails to apply for the exclusive MDL lock, the device 1 performs an exit process on the DDL statement according to the waiting setting information. Because the DDL statement applies for an exclusive MDL lock, when the statement in the corresponding lock holding queue of the target table operation corresponds to the shared-level MDL lock, the application for the shared DDL statement fails for the exclusive MDL lock, and the DDL statement enters the lock waiting queue. At this time, the waiting setting information in the DDL statement is triggered, and the triggering method includes setting the feedback information after the acquisition of the MDL lock application fails, starting the setting information corresponding program, reading the setting information, and performing the setting action accordingly. The waiting setting information includes an action performed by the user after the DDL statement is blocked, and the action includes continuing to wait or immediately exiting waiting and other related operations. After waiting for the setting information to be triggered, the waiting information is waited according to the waiting setting information. The time exits or immediately exits the execution of the DDL statement, thereby avoiding the DML statement that the DDL statement can use the shared-level MDL lock after waiting too long in the lock wait queue. The lock holding queue described above is a relational database, and the database language is in the queue after the application for the MDL lock is successful. Accordingly, the lock waiting queue applies for the MDL lock for the database language because the applied lock type is mutually exclusive and fails. Wait for the MDL lock to hold the statement and continue to apply for the MDL lock queue.
本领域技术人员应能理解上述根据所述等待设置信息对所述DDL语句执行退出处理的方式仅为举例,其他现有的或今后可能出现的根据所述等待设置信息对所述DDL语句执行退出处理的方式如可适用于本发明,也应包含在本发明保护范围以内,并在此以引用方式包含于此。 Those skilled in the art should understand that the manner of performing the exit processing on the DDL statement according to the waiting setting information is only an example, and other existing or future possible executions may be performed to exit the DDL statement according to the waiting setting information. The manner of treatment, as applicable to the present invention, is also intended to be included within the scope of the present invention and is hereby incorporated by reference.
优选地,在步骤S3中设备1若申请所述排他性MDL锁成功,执行所述DDL语句。即DDL语句申请排他性MDL锁时,未有其它语句持有与排他性MDL互斥类型的MDL锁,DDL语句获取排他性MDL锁,进入锁持有队列继而执行语句内容,对目标表进行相应的操作。Preferably, in step S3, if the device 1 successfully requests the exclusive MDL lock, the DDL statement is executed. That is, when the DDL statement applies for the exclusive MDL lock, no other statement holds the MDL lock with the exclusive MDL mutual exclusion type. The DDL statement acquires the exclusive MDL lock, enters the lock holding queue and then executes the statement content, and performs corresponding operations on the target table.
更优选地,所述等待设置信息包括设定的等待时间,其中,在步骤S3中设备1若申请所述排他性MDL锁失败,按所述等待时间等待后,再次申请所述排他性MDL锁;若仍申请所述排他性MDL锁失败,退出对所述DDL语句的执行处理。即在设定的等待时间开始执行立即使得DDL语句执行任务失败退出之前,可以加入重新申请MDL锁的设置信息,即在等待所设置时间后,例如接上文举例,在等待1秒中后,继续发起申请MDL锁,若此时MDL锁不被持有,即可申请成功并在持有排它性MDL锁的情况下被执行,若此时MDL锁仍被持有,且与DDL所申请的MDL锁冲突,则执行立即使得DDL语句执行任务失败退出,从而使得DDL申请MDL锁的几率增加,提高对MDL锁的申请效率。More preferably, the waiting setting information includes a set waiting time, wherein, in step S3, if the device 1 fails to apply for the exclusive MDL lock, and waits for the waiting time, the application further requests the exclusive MDL lock; Still applying for the exclusive MDL lock fails, exiting the execution processing of the DDL statement. That is, before the set waiting time starts to execute, immediately before the DDL statement execution task fails to exit, the setting information of re-applying the MDL lock may be added, that is, after waiting for the set time, for example, after waiting for 1 second, after waiting for 1 second, Continue to initiate the application for the MDL lock. If the MDL lock is not held at this time, the application can be successfully applied and executed with the exclusive MDL lock. If the MDL lock is still held, and the application is with DDL. If the MDL lock conflicts, the execution immediately causes the DDL statement execution task to fail to exit, thereby increasing the probability that the DDL applies for the MDL lock, and improving the application efficiency of the MDL lock.
进一步地,所述等待设置信息包括零等待,其中,在步骤S3中设备1若申请所述排他性MDL锁失败,退出对所述DDL语句的执行处理。即在DDL语句获取申请排他性MDL锁失败的反馈之后,根据零等待的设置,立即使得DDL语句执行任务失败退,从而使得DDL语句在MDL锁等待队列中被删除,因此可以减少MDL锁等待队列中其它语句的等待时间,避免因等待时间过长造成数据库相关业务中断或应用访问受阻。Further, the waiting setting information includes zero waiting, wherein, in step S3, if the device 1 fails to apply for the exclusive MDL lock, the execution processing of the DDL statement is exited. That is, after the DDL statement obtains the feedback of applying for the exclusive MDL lock failure, according to the zero waiting setting, the DDL statement execution task is immediately defeated, so that the DDL statement is deleted in the MDL lock waiting queue, so the MDL lock waiting queue can be reduced. Waiting time for other statements to avoid database related business interruption or application access blocked due to long waiting time.
根据本申请一个优选实施例的一种用于处理关系型数据库中DDL语句的方法流程(未示出)。所述流程包括步骤S1、步骤S2和步骤S3,其中,步骤S1和步骤S2均在图2所示的步骤S1和步骤S2的基础上增加数据操纵语言DML的处理情况,步骤S3包括步骤S31,在步骤S31中设备1退出对所述DDL语句的执行处理后,将所述DML语句中至少一个添加至所述MDL锁的锁持有队列或锁等待队列。A method flow (not shown) for processing DDL statements in a relational database in accordance with a preferred embodiment of the present application. The process includes a step S1, a step S2, and a step S3, wherein the steps S1 and S2 both increase the processing of the data manipulation language DML based on the steps S1 and S2 shown in FIG. 2, and the step S3 includes the step S31. After the device 1 exits the execution processing of the DDL statement in step S31, at least one of the DML statements is added to the lock holding queue or the lock waiting queue of the MDL lock.
具体地,在步骤S1中设备1还获取用户提交的关于所述目标表的DML语句,其中,在步骤S3中还包括步骤S31,在步骤S31中设备1在退出对所述DDL语句的执行处理后,将所述DML语句中至少一个添加至所述MDL锁的锁持有队列或锁等待队列。其中,所获取的用户提交关于所述目标表的数据库语言除DDL外还包括DML,因此,在退出DDL语句的执行处理后,DDL语句从MDL锁等待队列中被删除,后续在MDL锁等待队列中的DML语句将按照排列的顺序进行处理,根据队列中对MDL锁的类型需求,至少将一个DML语句添加至MDL锁持有或锁等待队列,例如,若当前MDL锁持有队列 中数据库语言语句的所持有的MDL锁类型与锁等待队列中的DML语句不互斥可共享,则依照次序添加DML语句至锁持有队列直至有互斥需求的数据库语句出现,并将该语句排除在MDL锁持有队列外,仍然留在MDL锁等待队列,若当前MDL锁持有队列中数据库语言语句的所持有的MDL锁类型与锁等待队列中的DML语句互斥,则将获取的DML语句添加至MDL锁等待队列,从而唤醒被阻塞的DML语句,使得数据库相关应用访问效率提升或业务速度加快。Specifically, the device 1 further acquires a DML statement submitted by the user about the target table in step S1, wherein step S3 further includes step S31, in which the device 1 exits execution processing on the DDL statement. Thereafter, at least one of the DML statements is added to a lock holding queue or a lock waiting queue of the MDL lock. The acquired database language of the target table includes DML in addition to the DDL. Therefore, after exiting the execution process of the DDL statement, the DDL statement is deleted from the MDL lock waiting queue, and subsequently in the MDL lock waiting queue. The DML statements in the order will be processed in the order in which they are arranged. At least one DML statement is added to the MDL lock hold or the lock wait queue according to the type requirements of the MDL lock in the queue, for example, if the current MDL lock holds the queue. The MDL lock type held by the database language statement is not mutually exclusive and shareable with the DML statement in the lock wait queue, then the DML statement is added to the lock holding queue according to the order until a database statement with mutually exclusive requirements appears, and the The statement is excluded from the MDL lock holding queue and remains in the MDL lock waiting queue. If the MDL lock type held by the database language statement in the current MDL lock holding queue is mutually exclusive with the DML statement in the lock waiting queue, then the statement will be The obtained DML statement is added to the MDL lock waiting queue, thereby awakening the blocked DML statement, so that the database related application access efficiency is improved or the business speed is accelerated.
优选地,在步骤S31中设备1在退出对所述DDL语句的执行处理后,当所述锁持有队列及所述锁等待队列中的语句均对应共享级所述MDL锁时,将所述DML语句中至少一个添加至所述锁持有队列。其中,DML语句包括再次处理以及首次处理的DML语句,即退出对所述DDL语句的执行处理后,在所述DML语句所在的锁等待队列位置之前使的语句以及当前所持有队列中的语句均对应共享及MDL锁,则DML语句可与其所在锁等待队列位置之前的所述锁等待队列中语句一同被添加至所述锁持有队列,例如,dml1与dml2指代两个DML语句其持有共享级的MDL锁,dml3、dml4、dml5指代在锁等待队列中的DML语句其需要申请共享级的MDL锁,dml6是指代刚获取的用户提交的需要申请共享级的MDL锁的DML英语剧,在排列在dml3之前的DDL语句被删除后,dml3至dm16均可被添加至所述锁持有队列,使得DDL语句退出执行处理后,DML语句执行因为同为申请共享级MDL锁而加快。Preferably, after the device 1 exits the execution processing of the DDL statement in step S31, when the lock holding queue and the statement in the lock waiting queue all correspond to the sharing level MDL lock, the At least one of the DML statements is added to the lock holding queue. The DML statement includes the DML statement processed again and processed for the first time, that is, the statement executed before the lock waiting queue position where the DML statement is located after exiting the execution of the DDL statement, and the statement in the currently held queue. Corresponding to the shared and MDL locks, the DML statement can be added to the lock holding queue together with the statement in the lock waiting queue before the lock waiting queue position. For example, dml1 and dml2 refer to two DML statements. There are shared-level MDL locks, dml3, dml4, and dml5 refer to the DML statements in the lock wait queue, which need to apply for the shared-level MDL lock. dml6 refers to the DML that the newly acquired user needs to apply for the shared-level MDL lock. In the English drama, after the DDL statement arranged before dml3 is deleted, dml3 to dm16 can be added to the lock holding queue, so that the DML statement is executed after the DDL statement is executed, and the DML statement is executed because the same is the application for the shared-level MDL lock. accelerate.
更优选地,在步骤S2中设备1还将所述DML语句添加至所述MDL锁的锁等待队列,其中,在步骤S31中设备1在退出对所述DDL语句的执行处理后,当所述锁持有队列及所述锁等待队列中的语句均对应共享级所述MDL锁时,将所述DML语句中至少一个从所述锁等待队列添加至所述锁持有队列。在有DDL语句在对MDL锁进行申请时,因为DDL语句所申请的是排他性的MDL锁,此时获取的DML语句需要申请的共享级的MDL锁与DDL语句所申请的排他性MDL锁互斥,即DDL语句即使申请成功,DML语句也无法与其共享MDL锁,因此,此时获取的DML语句被添加至MDL的锁等待队列。当所述DDL语句被执行退出处理后,被添加至MDL锁等待队列的DML语句可由锁等待队列中被添加至锁持有队列,若其后的锁等待队列中还有DML语句,因为均为申请共享级MDL锁,所以均添加至锁持有队列直至有申请互斥级别MDL锁的语句出现停止添加。More preferably, the device 1 also adds the DML statement to the lock waiting queue of the MDL lock in step S2, wherein after the device 1 exits the execution processing of the DDL statement in step S31, when When the lock holding queue and the statement in the lock waiting queue all correspond to the MDL lock of the sharing level, at least one of the DML statements is added from the lock waiting queue to the lock holding queue. When a DDL statement is applied to an MDL lock, because the DDL statement is applied for an exclusive MDL lock, the DML statement acquired at this time needs to apply for the shared-level MDL lock and the exclusive MDL lock applied by the DDL statement to be mutually exclusive. That is, even if the application is successful, the DML statement cannot share the MDL lock with the DML statement. Therefore, the DML statement acquired at this time is added to the lock waiting queue of the MDL. When the DDL statement is executed and exited, the DML statement added to the MDL lock wait queue may be added to the lock holding queue by the lock waiting queue, and if there is a DML statement in the subsequent lock waiting queue, since Apply for a shared-level MDL lock, so they are added to the lock holding queue until the statement that requests the mutual exclusion level MDL lock appears to stop adding.
进一步地,在步骤S31中设备1退出对所述DDL语句的执行处理后,当所述锁持有队列或所述锁等待队列中存在语句对应排他性所述MDL锁时,将所述DML语句中至少 一个添加至所述锁等待队列。在有DDL语句在对MDL锁进行申请时,因为DDL语句所申请的是排他性的MDL锁,此时获取的DML语句需要申请的共享级的MDL锁与DDL语句所申请的排他性MDL锁互斥,即DDL语句即使申请成功,DML语句也无法与其共享MDL锁,因此,此时获取的DML语句被添加至MDL的锁等待队列,同样MDL锁等待队列里还有其它因申请排他性MDL锁的DDL语句。当所述DDL语句被执行退出处理后,被添加至MDL锁等待队列的DML语句若之前的队列中存在申请排他性MDL锁的语句或当前MDL锁持有队列语句持有的是排他性MDL锁,则此时获取的MDL语句至少有一个添加至所述锁等待队列。Further, after the device 1 exits the execution processing of the DDL statement in step S31, when the lock holding queue or the lock waiting queue has a statement corresponding to the exclusive MDL lock, the DML statement is at least One is added to the lock wait queue. When a DDL statement is applied to an MDL lock, because the DDL statement is applied for an exclusive MDL lock, the DML statement acquired at this time needs to apply for the shared-level MDL lock and the exclusive MDL lock applied by the DDL statement to be mutually exclusive. That is, even if the DDL statement is successful, the DML statement cannot share the MDL lock with it. Therefore, the DML statement obtained at this time is added to the MDL lock waiting queue. In the same MDL lock waiting queue, there are other DDL statements for applying the exclusive MDL lock. . When the DDL statement is executed and exited, the DML statement added to the MDL lock wait queue has an exclusive MDL lock in the previous queue, or the current MDL lock holding queue statement holds an exclusive MDL lock. At least one of the MDL statements obtained at this time is added to the lock waiting queue.
对于本领域技术人员而言,显然本发明不限于上述示范性实施例的细节,而且在不背离本发明的精神或基本特征的情况下,能够以其他的具体形式实现本发明。因此,无论从哪一点来看,均应将实施例看作是示范性的,而且是非限制性的,本发明的范围由所附权利要求而不是上述说明限定,因此旨在将落在权利要求的等同要件的含义和范围内的所有变化涵括在本发明内。不应将权利要求中的任何附图标记视为限制所涉及的权利要求。此外,显然“包括”一词不排除其他单元或步骤,单数不排除复数。装置权利要求中陈述的多个单元或装置也可以由一个单元或装置通过软件或者硬件来实现。第一,第二等词语用来表示名称,而并不表示任何特定的顺序。 It is apparent to those skilled in the art that the present invention is not limited to the details of the above-described exemplary embodiments, and the present invention can be embodied in other specific forms without departing from the spirit or essential characteristics of the invention. Therefore, the present embodiments are to be considered as illustrative and not restrictive, and the scope of the invention is defined by the appended claims instead All changes in the meaning and scope of equivalent elements are included in the present invention. Any reference signs in the claims should not be construed as limiting the claim. In addition, it is to be understood that the word "comprising" does not exclude other elements or steps. A plurality of units or devices recited in the device claims may also be implemented by a unit or device by software or hardware. The first, second, etc. words are used to denote names and do not denote any particular order.

Claims (18)

  1. 一种用于处理关系型数据库中DDL语句的方法,其中,该方法包括:A method for processing a DDL statement in a relational database, wherein the method comprises:
    获取用户提交的关于目标表的DDL语句,其中,所述DDL语句包括对应的等待设置信息;Obtaining a DDL statement submitted by the user about the target table, where the DDL statement includes corresponding waiting setting information;
    申请所述目标表所对应的排他性MDL锁;Applying an exclusive MDL lock corresponding to the target table;
    若申请所述排他性MDL锁失败,根据所述等待设置信息对所述DDL语句执行退出处理。If the application for the exclusive MDL lock fails, the exit processing is performed on the DDL statement according to the waiting setting information.
  2. 根据权利要求1所述的方法,其中,所述等待设置信息包括以下至少任一项:The method of claim 1, wherein the waiting setting information comprises at least one of the following:
    设定的等待时间;Set waiting time;
    零等待。Zero wait.
  3. 根据权利要求2所述的方法,其中,所述等待设置信息包括设定的等待时间;The method of claim 2, wherein the wait setting information comprises a set waiting time;
    其中,所述步骤若申请所述排他性MDL锁失败,根据所述等待设置信息对所述DDL语句执行退出处理包括:If the step of applying the exclusive MDL lock fails, performing the exit processing on the DDL statement according to the waiting setting information includes:
    若申请所述排他性MDL锁失败,按所述等待时间等待后,再次申请所述排他性MDL锁;If the application for the exclusive MDL lock fails, after the waiting time is waited, the exclusive MDL lock is applied again;
    若仍申请所述排他性MDL锁失败,退出对所述DDL语句的执行处理。If the application for the exclusive MDL lock fails, the execution of the DDL statement is exited.
  4. 根据权利要求2或3所述的方法,其中,所述等待设置信息包括零等待;The method according to claim 2 or 3, wherein said waiting setting information includes zero waiting;
    其中,所述步骤若申请所述排他性MDL锁失败,根据所述等待设置信息对所述DDL语句执行退出处理包括:If the step of applying the exclusive MDL lock fails, performing the exit processing on the DDL statement according to the waiting setting information includes:
    若申请所述排他性MDL锁失败,退出对所述DDL语句的执行处理。If the application of the exclusive MDL lock fails, the execution of the DDL statement is exited.
  5. 根据权利要求1至4中任一项所述的方法,其中,所述步骤若申请所述排他性MDL锁失败,根据所述等待设置信息对所述DDL语句执行退出处理包括:The method according to any one of claims 1 to 4, wherein, if the step of applying the exclusive MDL lock fails, performing the exit processing on the DDL statement according to the waiting setting information comprises:
    若申请所述排他性MDL锁成功,执行所述DDL语句。If the application for the exclusive MDL lock is successful, the DDL statement is executed.
  6. 根据权利要求1至5中任一项所述的方法,其中,所述步骤获取用户提交的关于目标表的DDL语句,其中,所述DDL语句包括对应的等待设置信息还包括:The method according to any one of claims 1 to 5, wherein the step of acquiring a DDL statement submitted by a user regarding a target table, wherein the DDL statement includes corresponding waiting setting information further includes:
    获取用户提交的关于所述目标表的DML语句;Obtaining a DML statement submitted by the user about the target table;
    其中,所述步骤若申请所述排他性MDL锁失败,根据所述等待设置信息对所述DDL语句执行退出处理还包括:If the step of applying the exclusive MDL lock fails, performing the exit processing on the DDL statement according to the waiting setting information further includes:
    在退出对所述DDL语句的执行处理后,将所述DML语句中至少一个添加至所述MDL锁的锁持有队列或锁等待队列。 After exiting the execution processing of the DDL statement, at least one of the DML statements is added to the lock holding queue or the lock waiting queue of the MDL lock.
  7. 根据权利要求6所述的方法,其中,所述步骤在退出对所述DDL语句的执行处理后,将所述DML语句中至少一个添加至所述MDL锁的锁持有队列或锁等待队列包括:The method according to claim 6, wherein said step of adding at least one of said DML statements to said lock holding queue or lock waiting queue of said MDL lock after exiting execution processing of said DDL statement comprises :
    在退出对所述DDL语句的执行处理后,当所述锁持有队列及所述锁等待队列中的语句均对应共享级所述MDL锁时,将所述DML语句中至少一个添加至所述锁持有队列。After exiting the execution processing of the DDL statement, when the lock holding queue and the statement in the lock waiting queue all correspond to the MDL lock of the sharing level, at least one of the DML statements is added to the The lock holds the queue.
  8. 根据权利要求7所述的方法,其中,所述步骤申请所述目标表所对应的排他性MDL锁还包括:The method according to claim 7, wherein the step of applying for the exclusive MDL lock corresponding to the target table further comprises:
    将所述DML语句添加至所述MDL锁的锁等待队列;Adding the DML statement to a lock waiting queue of the MDL lock;
    其中,所述步骤在退出对所述DDL语句的执行处理后,将所述DML语句中至少一个添加至所述MDL锁的锁持有队列或锁等待队列包括:The step of adding the at least one of the DML statements to the lock holding queue or the lock waiting queue of the MDL lock after exiting the execution processing of the DDL statement includes:
    在退出对所述DDL语句的执行处理后,当所述锁持有队列及所述锁等待队列中的语句均对应共享级所述MDL锁时,将所述DML语句中至少一个从所述锁等待队列添加至所述锁持有队列。After exiting the execution processing of the DDL statement, when the lock holding queue and the statement in the lock waiting queue all correspond to the MDL lock of the sharing level, at least one of the DML statements is from the lock A wait queue is added to the lock holding queue.
  9. 根据权利要求6至8中任一项所述的方法,其中,所述步骤在退出对所述DDL语句的执行处理后,将所述DML语句中至少一个添加至所述MDL锁的锁持有队列或锁等待队列包括:The method according to any one of claims 6 to 8, wherein said step adds at least one of said DML statements to a lock holding of said MDL lock after exiting execution processing of said DDL statement The queue or lock wait queue includes:
    在退出对所述DDL语句的执行处理后,当所述锁持有队列或所述锁等待队列中存在语句对应排他性所述MDL锁时,将所述DML语句中至少一个添加至所述锁等待队列。After exiting the execution processing of the DDL statement, when there is a statement corresponding to the exclusive MDL lock in the lock holding queue or the lock waiting queue, at least one of the DML statements is added to the lock waiting queue.
  10. 一种用于处理关系型数据库中DDL语句的设备,其中,该设备包括:A device for processing DDL statements in a relational database, wherein the device comprises:
    第一装置,用于获取用户提交的关于目标表的DDL语句,其中,所述DDL语句包括对应的等待设置信息;a first device, configured to acquire a DDL statement submitted by the user about the target table, where the DDL statement includes corresponding waiting setting information;
    第二装置,用于申请所述目标表所对应的排他性MDL锁;a second device, configured to apply for an exclusive MDL lock corresponding to the target table;
    第三装置,用于若申请所述排他性MDL锁失败,根据所述等待设置信息对所述DDL语句执行退出处理。And a third device, configured to perform an exit process on the DDL statement according to the waiting setting information if the application for the exclusive MDL lock fails.
  11. 根据权利要求10所述的设备,其中,所述等待设置信息包括以下至少任一项:The device according to claim 10, wherein said waiting setting information comprises at least one of the following:
    设定的等待时间;Set waiting time;
    零等待。Zero wait.
  12. 根据权利要求11所述的设备,其中,所述等待设置信息包括设定的等待时间; The device according to claim 11, wherein said waiting setting information comprises a set waiting time;
    其中,所述第三装置用于:Wherein the third device is used to:
    若申请所述排他性MDL锁失败,按所述等待时间等待后,再次申请所述排他性MDL锁;If the application for the exclusive MDL lock fails, after the waiting time is waited, the exclusive MDL lock is applied again;
    若仍申请所述排他性MDL锁失败,退出对所述DDL语句的执行处理。If the application for the exclusive MDL lock fails, the execution of the DDL statement is exited.
  13. 根据权利要求11或12所述的设备,其中,所述等待设置信息包括零等待;The device according to claim 11 or 12, wherein said waiting setting information comprises zero waiting;
    其中,所述第三装置用于:Wherein the third device is used to:
    若申请所述排他性MDL锁失败,退出对所述DDL语句的执行处理。If the application of the exclusive MDL lock fails, the execution of the DDL statement is exited.
  14. 根据权利要求10至13中任一项所述的设备,其中,所述第三装置用于:Apparatus according to any one of claims 10 to 13 wherein said third means is for:
    若申请所述排他性MDL锁成功,执行所述DDL语句。If the application for the exclusive MDL lock is successful, the DDL statement is executed.
  15. 根据权利要求10至14中任一项所述的设备,其中,所述第一装置还用于:The apparatus according to any one of claims 10 to 14, wherein the first device is further configured to:
    获取用户提交的关于所述目标表的DML语句;Obtaining a DML statement submitted by the user about the target table;
    其中,所述第三装置还包括:The third device further includes:
    第一单元,用于在退出对所述DDL语句的执行处理后,将所述DML语句中至少一个添加至所述MDL锁的锁持有队列或锁等待队列。And a first unit, configured to add at least one of the DML statements to a lock holding queue or a lock waiting queue of the MDL lock after exiting execution processing on the DDL statement.
  16. 根据权利要求15所述的设备,其中,所述第一单元用于:The apparatus of claim 15 wherein said first unit is for:
    在退出对所述DDL语句的执行处理后,当所述锁持有队列及所述锁等待队列中的语句均对应共享级所述MDL锁时,将所述DML语句中至少一个添加至所述锁持有队列。After exiting the execution processing of the DDL statement, when the lock holding queue and the statement in the lock waiting queue all correspond to the MDL lock of the sharing level, at least one of the DML statements is added to the The lock holds the queue.
  17. 根据权利要求16所述的设备,其中,所述第二装置还用于:The apparatus of claim 16 wherein said second means is further for:
    将所述DML语句添加至所述MDL锁的锁等待队列;Adding the DML statement to a lock waiting queue of the MDL lock;
    其中,所述第一单元用于:Wherein the first unit is used for:
    在退出对所述DDL语句的执行处理后,当所述锁持有队列及所述锁等待队列中的语句均对应共享级所述MDL锁时,将所述DML语句中至少一个从所述锁等待队列添加至所述锁持有队列。After exiting the execution processing of the DDL statement, when the lock holding queue and the statement in the lock waiting queue all correspond to the MDL lock of the sharing level, at least one of the DML statements is from the lock A wait queue is added to the lock holding queue.
  18. 根据权利要求15至17中任一项所述的设备,其中,所述第一单元用于:The apparatus according to any one of claims 15 to 17, wherein the first unit is for:
    在退出对所述DDL语句的执行处理后,当所述锁持有队列或所述锁等待队列中存在语句对应排他性所述MDL锁时,将所述DML语句中至少一个添加至所述锁等待队列。 After exiting the execution processing of the DDL statement, when there is a statement corresponding to the exclusive MDL lock in the lock holding queue or the lock waiting queue, at least one of the DML statements is added to the lock waiting queue.
PCT/CN2016/084624 2015-06-11 2016-06-03 Method and device for processing ddl statement in relational database WO2016197870A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201510318978.7A CN106294512A (en) 2015-06-11 2015-06-11 The method and apparatus of DDL statement in a kind of type data base that deals with relationship
CN201510318978.7 2015-06-11

Publications (1)

Publication Number Publication Date
WO2016197870A1 true WO2016197870A1 (en) 2016-12-15

Family

ID=57502996

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2016/084624 WO2016197870A1 (en) 2015-06-11 2016-06-03 Method and device for processing ddl statement in relational database

Country Status (2)

Country Link
CN (1) CN106294512A (en)
WO (1) WO2016197870A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108287835B (en) * 2017-01-09 2022-06-21 腾讯科技(深圳)有限公司 Data cleaning method and device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090037416A1 (en) * 2007-07-30 2009-02-05 Oracle International Corporation Method for acquiring locks in wait mode in a deadlock free manner
CN101714167A (en) * 2009-11-03 2010-05-26 北京高信达网络科技有限公司 Method and device for accessing monofile database
CN103064898A (en) * 2012-12-17 2013-04-24 华为技术有限公司 Business locking and unlocking method and device
CN103761260A (en) * 2013-12-31 2014-04-30 北京京东尚科信息技术有限公司 Method and device for processing mutually-exclusive lock of database, and distributed system

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7644106B2 (en) * 2007-07-30 2010-01-05 Oracle International Corporation Avoiding lock contention by using a wait for completion mechanism
EP2323047B1 (en) * 2009-10-09 2020-02-19 Software AG Primary database system, replication database system and method for replicating data of a primary database system
CN102831156B (en) * 2012-06-29 2014-12-31 浙江大学 Distributed transaction processing method on cloud computing platform
CN104679881B (en) * 2015-03-13 2019-03-08 华为技术有限公司 A kind of concurrency control method and device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090037416A1 (en) * 2007-07-30 2009-02-05 Oracle International Corporation Method for acquiring locks in wait mode in a deadlock free manner
CN101714167A (en) * 2009-11-03 2010-05-26 北京高信达网络科技有限公司 Method and device for accessing monofile database
CN103064898A (en) * 2012-12-17 2013-04-24 华为技术有限公司 Business locking and unlocking method and device
CN103761260A (en) * 2013-12-31 2014-04-30 北京京东尚科信息技术有限公司 Method and device for processing mutually-exclusive lock of database, and distributed system

Also Published As

Publication number Publication date
CN106294512A (en) 2017-01-04

Similar Documents

Publication Publication Date Title
US9152474B2 (en) Context aware synchronization using context and input parameter objects associated with a mutual exclusion lock
WO2019127916A1 (en) Data read/write method and device implemented on the basis of distributed consensus protocol
WO2015051690A1 (en) Zookeeper-based information configuration method and device
US8843673B2 (en) Offloading input/output (I/O) completion operations
US9747210B2 (en) Managing a lock to a resource shared among a plurality of processors
WO2017181931A1 (en) Method and device for processing distributed transaction
US20170161313A1 (en) Detection and Resolution of Conflicts in Data Synchronization
US11212175B2 (en) Configuration management for cloud storage system and method
US20140279987A1 (en) Workflow design for long-running distributed operations using no sql databases
US9245054B2 (en) Efficiently searching and modifying a variable length queue
RU2597506C2 (en) Unlimited transactional memory with assurances of movement during transfer, using hardware global lock
WO2016101759A1 (en) Data routing method, data management device and distributed storage system
US10831662B1 (en) Systems and methods for maintaining cache coherency
US10372352B2 (en) Concurrent virtual storage management
US20140082293A1 (en) Store Buffer for Transactional Memory
US20150019846A1 (en) System level architecture verification for transaction execution in a multi-processing environment
WO2016197870A1 (en) Method and device for processing ddl statement in relational database
US9053141B2 (en) Serialization of access to data in multi-mainframe computing environments
US11500693B2 (en) Distributed system for distributed lock management and method for operating the same
CN111782614A (en) Data access method, device, equipment and storage medium
US10185587B2 (en) Wait-free process request execution utilizing a dedicated helper thread
US9519592B2 (en) Stale pointer detection with overlapping versioned memory
US10310914B2 (en) Methods and systems for recursively acquiring and releasing a spinlock
US20210191902A1 (en) Predicting and Deleting Idle Remote Sessions in a Distributed File System
US8701124B2 (en) Notification barrier

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 16806768

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 16806768

Country of ref document: EP

Kind code of ref document: A1