Search

US-20260127146-A1 - ONLINE EVOLUTION METHOD AND APPARATUS FOR EXECUTION PLAN, DEVICE, AND STORAGE MEDIUM

US20260127146A1US 20260127146 A1US20260127146 A1US 20260127146A1US-20260127146-A1

Abstract

This specification provides an online evolution method and apparatus for an execution plan, a device, and a storage medium. The method includes: In response to a received current database request including a target database statement, an evolution task is obtained from a plan cache corresponding to the target database statement. A type of an execution plan actually used by the database request is selected, so that an accumulative quantity of execution times of each type of execution plan in an implementation process of the evolution task is positively correlated with performance of each type of execution plan. After the evolution task ends, if it is determined that performance of a current execution plan of an evolution type is better than performance of an execution plan of a baseline type, the execution plan of the evolution type is changed into an execution plan of the baseline type corresponding to the target database statement.

Inventors

  • Yifei TIAN
  • Guoping Wang
  • Yi Xiao
  • Peng Zeng

Assignees

  • Beijing Oceanbase Technology Co., Ltd.

Dates

Publication Date
20260507
Application Date
20251230
Priority Date
20230818

Claims (20)

  1. 1 . A method for database operation, comprising: in response to a received database request including a target database statement, obtaining an evolution task from a plan cache corresponding to the target database statement, wherein the evolution task is configured to compare performance of a first execution plan of a first type with performance of a second execution plan of a second type; selecting a type of an execution plan actually used by the received database request based on that an accumulative quantity of execution times of each type of execution plan in an implementation process of the evolution task is positively correlated with performance of the type of execution plan; and in response to it is determined that the performance of the first execution plan of the first type is better than the performance of the second execution plan of the second type, changing the first execution plan of the first type into an execution plan of the second type corresponding to the target database statement.
  2. 2 . The method according to claim 1 , further comprising: in response to a received historical database request comprising the target database statement, querying a plan cache corresponding to the target database statement, and in response to the plan cache does not include a corresponding evolution task or a generated execution plan, generating a database statement execution plan corresponding to the target database statement; and in response to the database statement execution plan is of the first type, generating the evolution task and caching the evolution task into the plan cache corresponding to the target database statement.
  3. 3 . The method according to claim 1 , further comprising: in response to the received database request including the target database statement, querying a plan cache corresponding to the target database statement, and in response to the plan cache does not include a corresponding evolution task or a generated execution plan, generating a database statement execution plan corresponding to the target database statement; and in response to the second execution plan of the second type corresponding to the target database statement exists, comparing the database statement execution plan with the second execution plan of the second type, and in response to a result of the comparison is that the database statement execution plan is consistent with the second execution plan of the second type, executing the database statement execution plan, and caching the database statement execution plan into the plan cache corresponding to the target database statement; and in response to the second execution plan of the second type corresponding to the target database statement does not exist, classifying the database statement execution plan as an execution plan of the second type, executing the database statement execution plan, and caching the database statement execution plan into the plan cache corresponding to the target database statement.
  4. 4 . The method according to claim 1 , wherein the evolution task includes a plurality of stages, wherein: in an initial stage of the plurality of stages, a quantity of execution times of the first execution plan of the first type is a same as a quantity of execution times of the second execution plan of the second type; and in another stage of the plurality of stages other than the initial stage, a quantity of execution times of each type of execution plan is negatively correlated with a proportion of an average execution duration of the type of execution plan in at least one stage before the another stage.
  5. 5 . The method according to claim 1 , further comprises: after implementation of the execution plan selected for the current database request is completed, determining whether the evolution task meets a evolution end condition, wherein the evolution end condition includes one or more of that a quantity of evolution times reaches a first threshold or an evolution duration reaches a second threshold; and in response to the evolution end condition is met, terminating the evolution task.
  6. 6 . The method according to claim 1 , further comprising: separately determining an average execution duration of the first execution plan of the first type and an average execution duration of the second execution plan of the second type based on an execution status of the evolution task; and determining a relative performance between the first execution plan of the first type and the second execution plan of the second type based on their respective average execution durations.
  7. 7 . The method according to claim 1 , further comprising: in response to an execution plan of the first type corresponding to the target database statement has not been used for a duration that reaches a duration threshold, deleting the execution plan of the first type.
  8. 8 . An electronic device, comprising: one or more processors; and one or more memory devices, the one or more memory devices, individually or collectively, having processor-executable instructions stored thereon, the processor-executable instructions, when executed by the one or more processors, enabling the one or more processors to, individually or collectively, conduct actions including: in response to a received database request including a target database statement, obtaining an evolution task from a plan cache corresponding to the target database statement, wherein the evolution task is configured to compare performance of a first execution plan of a first type with performance of a second execution plan of a second type; selecting a type of an execution plan actually used by the received database request based on that an accumulative quantity of execution times of each type of execution plan in an implementation process of the evolution task is positively correlated with performance of the type of execution plan; and in response to it is determined that the performance of the first execution plan of the first type is better than the performance of the second execution plan of the second type, changing the first execution plan of the first type into an execution plan of the second type corresponding to the target database statement.
  9. 9 . The electronic device according to claim 8 , wherein the actions further include: in response to a received historical database request comprising the target database statement, querying a plan cache corresponding to the target database statement, and in response to the plan cache does not include a corresponding evolution task or a generated execution plan, generating a database statement execution plan corresponding to the target database statement; and in response to the database statement execution plan is of the first type, generating the evolution task and caching the evolution task into the plan cache corresponding to the target database statement.
  10. 10 . The electronic device according to claim 8 , wherein the actions further include: in response to the received database request including the target database statement, querying a plan cache corresponding to the target database statement, and in response to the plan cache does not include a corresponding evolution task or a generated execution plan, generating a database statement execution plan corresponding to the target database statement; and in response to the second execution plan of the second type corresponding to the target database statement exists, comparing the database statement execution plan with the second execution plan of the second type, and in response to a result of the comparison is that the database statement execution plan is consistent with the second execution plan of the second type, executing the database statement execution plan, and caching the database statement execution plan into the plan cache corresponding to the target database statement; and in response to the second execution plan of the second type corresponding to the target database statement does not exist, classifying the database statement execution plan as an execution plan of the second type, executing the database statement execution plan, and caching the database statement execution plan into the plan cache corresponding to the target database statement.
  11. 11 . The electronic device according to claim 8 , wherein the evolution task includes a plurality of stages, wherein: in an initial stage of the plurality of stages, a quantity of execution times of the first execution plan of the first type is a same as a quantity of execution times of the second execution plan of the second type; and in another stage of the plurality of stages other than the initial stage, a quantity of execution times of each type of execution plan is negatively correlated with a proportion of an average execution duration of the type of execution plan in at least one stage before the another stage.
  12. 12 . The electronic device according to claim 8 , wherein the actions further include: after implementation of the execution plan selected for the current database request is completed, determining whether the evolution task meets a evolution end condition, wherein the evolution end condition includes one or more of that a quantity of evolution times reaches a first threshold or an evolution duration reaches a second threshold; and in response to the evolution end condition is met, terminating the evolution task.
  13. 13 . The electronic device according to claim 8 , wherein the actions further include: separately determining an average execution duration of the first execution plan of the first type and an average execution duration of the second execution plan of the second type based on an execution status of the evolution task; and determining a relative performance between the first execution plan of the first type and the second execution plan of the second type based on their respective average execution durations.
  14. 14 . The electronic device according to claim 8 , wherein the actions further include: in response to an execution plan of the first type corresponding to the target database statement has not been used for a duration that reaches a duration threshold, deleting the execution plan of the first type.
  15. 15 . A computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, the instructions, when executed by one or more processors, enabling the one or more processors to, individually or collectively, implement actions comprising: in response to a received database request including a target database statement, obtaining an evolution task from a plan cache corresponding to the target database statement, wherein the evolution task is configured to compare performance of a first execution plan of a first type with performance of a second execution plan of a second type; selecting a type of an execution plan actually used by the received database request based on that an accumulative quantity of execution times of each type of execution plan in an implementation process of the evolution task is positively correlated with performance of the type of execution plan; and in response to it is determined that the performance of the first execution plan of the first type is better than the performance of the second execution plan of the second type, changing the first execution plan of the first type into an execution plan of the second type corresponding to the target database statement.
  16. 16 . The computer-readable storage medium according to claim 15 , wherein the actions further comprise: in response to a received historical database request comprising the target database statement, querying a plan cache corresponding to the target database statement, and in response to the plan cache does not include a corresponding evolution task or a generated execution plan, generating a database statement execution plan corresponding to the target database statement; and in response to the database statement execution plan is of the first type, generating the evolution task and caching the evolution task into the plan cache corresponding to the target database statement.
  17. 17 . The computer-readable storage medium according to claim 15 , wherein the actions further comprise: in response to the received database request including the target database statement, querying a plan cache corresponding to the target database statement, and in response to the plan cache does not include a corresponding evolution task or a generated execution plan, generating a database statement execution plan corresponding to the target database statement; and in response to the second execution plan of the second type corresponding to the target database statement exists, comparing the database statement execution plan with the second execution plan of the second type, and in response to a result of the comparison is that the database statement execution plan is consistent with the second execution plan of the second type, executing the database statement execution plan, and caching the database statement execution plan into the plan cache corresponding to the target database statement; and in response to the second execution plan of the second type corresponding to the target database statement does not exist, classifying the database statement execution plan as an execution plan of the second type, executing the database statement execution plan, and caching the database statement execution plan into the plan cache corresponding to the target database statement.
  18. 18 . The computer-readable storage medium according to claim 15 , wherein the evolution task includes a plurality of stages, wherein: in an initial stage of the plurality of stages, a quantity of execution times of the first execution plan of the first type is a same as a quantity of execution times of the second execution plan of the second type; and in another stage of the plurality of stages other than the initial stage, a quantity of execution times of each type of execution plan is negatively correlated with a proportion of an average execution duration of the type of execution plan in at least one stage before the another stage.
  19. 19 . The computer-readable storage medium according to claim 15 , wherein the actions further comprise: after implementation of the execution plan selected for the current database request is completed, determining whether the evolution task meets a evolution end condition, wherein the evolution end condition includes one or more of that a quantity of evolution times reaches a first threshold or an evolution duration reaches a second threshold; and in response to the evolution end condition is met, terminating the evolution task.
  20. 20 . The computer-readable storage medium according to claim 15 , wherein the actions further comprise: separately determining an average execution duration of the first execution plan of the first type and an average execution duration of the second execution plan of the second type based on an execution status of the evolution task; and determining a relative performance between the first execution plan of the first type and the second execution plan of the second type based on their respective average execution durations.

Description

TECHNICAL FIELD This specification relates to the field of database processing technologies, and in particular, to an online evolution method and apparatus for an execution plan, a device, and a storage medium. BACKGROUND During execution of a database statement, a typical process includes: generating an execution plan corresponding to the database statement, and executing the generated execution plan. The same database statement may have different execution plans, and there are performance differences between different execution plans. To prevent an execution plan with a good performance from being replaced by an execution plan with a poor performance, in a related technology, a database plan management function is introduced into some databases to resolve a problem of plan rollback. A core idea of the database plan management function is to always execute an execution plan used in the past instead of executing a new execution plan. SUMMARY The applicants recognize that the database plan management function of the existing database only records a new execution plan when the new execution plan appears. If a user does not actively trigger an evolution task to verify performance of the new execution plan, the database will never use the new execution plan, even if the performance of the new execution plan is better than that of the execution plan that has been executed previously. This specification provides an online evolution method and apparatus for an execution plan, a device, and a storage medium. According to a first aspect of implementations of this specification, an online evolution method for an execution plan is provided. The method includes: in response to a received current database request including a target database statement, obtaining an evolution task from a plan cache corresponding to the target database statement, where the evolution task is used to compare performance of an execution plan of an evolution type with performance of an execution plan of a baseline type, the execution plan of the evolution type is an unverified execution plan corresponding to the target database statement, and the execution plan of the baseline type is a verified execution plan corresponding to the target database statement; selecting a type of an execution plan actually used by the current database request, so that an accumulative quantity of execution times of each type of execution plan in an implementation process of the evolution task is positively correlated with performance of each type of execution plan; and after the evolution task ends, if it is determined that the performance of the execution plan of the evolution type is better than the performance of the execution plan of the baseline type, changing the execution plan of the evolution type into an execution plan of the baseline type corresponding to the target database statement. According to a second aspect of implementations of this specification, an online evolution apparatus for an execution plan is provided. The apparatus includes: an obtaining module, configured to: in response to a received current database request including a target database statement, obtain an evolution task from a plan cache corresponding to the target database statement, where the evolution task is used to compare performance of an execution plan of an evolution type with performance of an execution plan of a baseline type, the execution plan of the evolution type is an unverified execution plan corresponding to the target database statement, and the execution plan of the baseline type is a verified execution plan corresponding to the target database statement; a selection module, configured to select a type of an execution plan actually used by the current database request, so that an accumulative quantity of execution times of each type of execution plan in an implementation process of the evolution task is positively correlated with performance of each type of execution plan; and a determining module, configured to: after the evolution task ends, if it is determined that the performance of the execution plan of the evolution type is better than the performance of the execution plan of the baseline type, change the execution plan of the evolution type into an execution plan of the baseline type corresponding to the target database statement. According to a third aspect of implementations of this specification, an electronic device is provided. The electronic device includes: a processor; and a memory configured to store a processor-executable instruction, where the processor runs the executable instruction to implement the online evolution method for an execution plan according to any one of the foregoing aspects. According to a fourth aspect of one or more implementations of this specification, a computer-readable storage medium is provided, where the computer-readable storage medium stores a computer instruction, and the instruction is executed by a processor to imp