WO2015058499A1 - 执行计划的存储方法、装置及系统 - Google Patents

执行计划的存储方法、装置及系统 Download PDF

Info

Publication number
WO2015058499A1
WO2015058499A1 PCT/CN2014/075520 CN2014075520W WO2015058499A1 WO 2015058499 A1 WO2015058499 A1 WO 2015058499A1 CN 2014075520 W CN2014075520 W CN 2014075520W WO 2015058499 A1 WO2015058499 A1 WO 2015058499A1
Authority
WO
WIPO (PCT)
Prior art keywords
execution plan
client
cache
database server
sql request
Prior art date
Application number
PCT/CN2014/075520
Other languages
English (en)
French (fr)
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 华为技术有限公司
Priority to EP14856211.9A priority Critical patent/EP3054386B1/en
Publication of WO2015058499A1 publication Critical patent/WO2015058499A1/zh
Priority to US15/136,472 priority patent/US20160239542A1/en

Links

Classifications

    • 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/24Querying
    • G06F16/245Query processing
    • G06F16/2453Query optimisation
    • G06F16/24534Query rewriting; Transformation
    • G06F16/24542Plan optimisation
    • 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/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/50Network services
    • H04L67/56Provisioning of proxy services
    • H04L67/568Storing data temporarily at an intermediate stage, e.g. caching

Definitions

  • the present invention relates to the field of databases, and in particular, to a storage method, apparatus and system for executing plans.
  • the execution plan in the database refers to the description of the execution process of the SQL (S t ruc t y ry ry ing ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge ge).
  • SQL SQL
  • the cache area is separately configured for different clients to save the execution plan of different clients.
  • the database server separately configures the cache area for different clients. Since the cache occupied by the low-utilization execution plan is released when the buffer allocated by the client is saturated, the execution plan with high client utilization is cached in the allocated cache area, that is, the above utilization rate. A low execution plan cannot be saved in the cache.
  • the database server needs to re-parse the SQL request and generate a corresponding execution plan, resulting in a lower cache hit rate for the execution plan, increasing the system. Overhead.
  • Embodiments of the present invention provide a storage method, apparatus, and system for executing an plan, which can improve a cache hit ratio of an execution plan and reduce system overhead.
  • an embodiment of the present invention provides a storage method for an execution plan, including:
  • the client receives the structured query language SQL request
  • the client detects whether an execution plan corresponding to the SQL request exists in a cache of the client;
  • the guest The terminal If the execution plan corresponding to the SQL request does not exist in the cache of the client, the guest The terminal generates location information, where the location information is used to indicate a cache location of an execution plan corresponding to the S QL request, where the cache location is a cache of the client and/or a cache of a database server;
  • the method further includes:
  • the client sends the execution plan to the database server, so that the database server executes the execution plan.
  • the client Sending the execution plan to the database server, so that the database server executes the execution plan, specifically:
  • the client selects any one of the multiple execution plans to send to the database server.
  • the execution plan is sent to the client Before the database server, the method further includes:
  • the client displays parameter information of the execution plan through a graphical interface; the client adjusts parameter information of the execution plan according to the parameter information modification instruction, and saves the adjusted execution plan in the cache of the client ;
  • the step of the client transmitting the execution plan to the database server comprises: the client transmitting the adjusted execution plan to the database server.
  • the fourth implementation in the first aspect further includes: after the client sends the location information and the SQL request to the database server, the method further includes:
  • the client receives an execution plan corresponding to the SQL request sent by the database server, and saves it in a cache of the client.
  • an embodiment of the present invention provides a storage device for executing a plan, including:
  • a receiving unit configured to receive a structured query language S QL request
  • a detecting unit configured to detect whether an execution plan corresponding to the S Q L request received by the receiving unit exists in a cache of the client;
  • a generating unit configured to generate location information when the execution plan corresponding to the S QL request detected by the detecting unit is not in the cache of the client, where the location information is used to indicate execution corresponding to the SQL request a cache location of the plan, the cache location being a cache of the client and/or a cache of a database server;
  • a sending unit configured to send the location information and the S QL request to the database server.
  • the sending unit is further configured to send the execution plan to the database server when an execution plan corresponding to the S QL request exists in a cache of the client Soing the database server to execute the execution plan.
  • the sending unit is further configured to: when the cache of the client exists, the SQL request is corresponding to When multiple execution plans are selected, one of the multiple execution plans is selected to execute The plan is sent to the database server.
  • the method further includes:
  • a display unit configured to display, by using a graphical interface, parameter information of the execution plan detected by the detecting unit
  • an adjusting unit configured to adjust parameter information of the execution plan displayed by the display unit according to the parameter information modification instruction
  • a saving unit configured to save the adjusted execution plan in a cache of the client; the sending unit is further configured to send the adjusted execution plan of the adjustment unit to the database server.
  • the receiving unit is further configured to: when the location information specifies that the cache location of the execution plan is the cache of the client, receive an execution plan corresponding to the SQL request sent by the database server;
  • the saving unit is further configured to save the execution plan received by the receiving unit in a cache of the client.
  • the generating unit is further configured to: when the execution plan of the SQL request does not exist in the cache of the client, perform a hash operation to generate the location information according to the S QL request.
  • an embodiment of the present invention provides a storage method for an execution plan, including: receiving, by a database server, location information sent by a client and a structured query language S QL request, where the location information is used to indicate the S QL request a cache location of the corresponding execution plan, where the cache location is a cache of the client and/or a cache of the database server;
  • the database server acquires an execution plan corresponding to the S QL request;
  • the database server acquires a cache location of the execution plan according to the location information; if the location information specifies that the cache location of the execution plan is a cache of the client, the database server sends the execution plan to the location The client saves.
  • the method before the database server receives the location information sent by the client and the structured query language SQL request, the method further includes:
  • the database server receives the execution plan sent by the client, and executes the execution plan.
  • the database Receiving, by the server, the execution plan sent by the client, and executing the execution plan, specifically:
  • the database server receives an execution plan selected by the client from the plurality of execution plans, and executes the Implementation plan.
  • the SQL request corresponding execution plan, the database server receiving the execution plan sent by the client, and executing the execution plan specifically:
  • the database server receives the adjusted sent by the client Execute the plan and execute the execution plan.
  • the method further includes:
  • the database server saves the execution plan in a cache of the database server.
  • the embodiment of the present invention provides a storage device for executing a plan, including: a receiving unit, configured to receive location information sent by a client, and a structured query language S QL request, where the location information is used to indicate S QL requests a cache location of the corresponding execution plan, where the cache location is a cache of the client and/or a cache of the database server;
  • An obtaining unit configured to acquire an execution plan corresponding to the S QL request according to the SQL request received by the receiving unit;
  • the obtaining unit is further configured to acquire a cache location of the execution plan according to the location information;
  • a sending unit configured to: when the location information specifies that the cache location of the execution plan is the cache of the client, the database server sends the execution plan to the client for saving.
  • the receiving unit is further configured to: when the execution plan corresponding to the S QL request exists in a cache of the client, receive the execution plan sent by the client ;
  • the device also includes:
  • an execution unit configured to execute the execution plan received by the receiving unit.
  • the receiving unit is further configured to: when the cache of the client exists, the SQL request is corresponding to Receiving, by the plurality of execution plans, any one of the execution plans selected from the plurality of execution plans sent by the client;
  • the execution unit is further configured to execute the any one of the execution plans received by the receiving unit.
  • the receiving unit is further configured to be used by the client An execution plan corresponding to the S QL request exists in a cache of the end, and the client Receiving, by the graphical interface, parameter adjustment of the execution plan, receiving an adjusted execution plan sent by the client;
  • the execution unit is further configured to execute the adjusted execution plan received by the receiving unit.
  • the device also includes:
  • a saving unit configured to save the execution plan in a cache of the database server when the location information specifies that a cache location of the execution plan is a cache of the database server.
  • an embodiment of the present invention provides a storage system for executing a plan, including: at least one client and a database server;
  • the client is configured to receive a structured query language S QL request, and detect whether an execution plan corresponding to the S QL request exists in a cache of the client;
  • the client is further configured to: when the execution plan corresponding to the S QL request does not exist in the cache of the client, generate location information, and send the location information and the SQL request to the database server,
  • the location information is used to indicate a cache location of an execution plan corresponding to the SQL request, where the cache location is a cache of the client and/or a cache of a database server;
  • the database server is configured to receive the location information sent by the client and the S QL request, and obtain an execution plan corresponding to the S QL request according to the location information and the S QL request;
  • the database server is further configured to acquire, according to the location information, a cache location of the execution plan, and when the location information specifies that the cache location of the execution plan is a cache of the client, send the execution plan to The client saves.
  • the client sends the SQL request and the generated location information to the database server, and the database server receives the received The SQL request and location information, generate and execute an execution plan corresponding to the SQL request, and save the execution plan to the cache indicated by the location information.
  • the embodiment of the present invention by saving the execution plan executed by the client in the cache of the client, it is possible to prevent the partial execution plan from being saved in the cache, thereby improving the cache hit rate of the execution plan. This reduces system overhead.
  • FIG. 1 is a flow chart of a storage method of an execution plan according to a first embodiment of the present invention
  • FIG. 2 is a schematic diagram of a storage structure of an execution plan according to a first embodiment of the present invention
  • FIG. 4 is a flowchart of a storage method of an execution plan according to a second embodiment of the present invention
  • FIG. 5 is a schematic diagram of a storage structure of an execution plan according to a second embodiment of the present invention. Schematic diagram of a base station structure;
  • FIG. 7 is a schematic diagram of a storage system of an execution plan according to Embodiment 3 of the present invention.
  • An embodiment of the present invention provides a storage method of an execution plan, which can be applied to FIG.
  • the system includes at least one client and a database server, and the client can send the SQL request and the generated location information to the database server, and can also receive an execution plan corresponding to the SQL request sent by the database server, and execute the execution plan.
  • the database server Stored in the client's cache; the database server can receive the SQL request and location information sent by the client, and can also send the execution plan corresponding to the generated SQL request to the client.
  • the execution plan corresponding to the S QL request can be saved in both the client cache and the database server cache.
  • the storage method of the execution plan provided by the embodiment of the present invention is applicable to the client side as shown in FIG. 1 , and the method includes:
  • the client receives the structured query language SQL request.
  • the SQL request is a database query language for accessing data in the database system, as well as querying, updating, and managing the database system. Users can enter the SQL statement to be executed through the D0S (Disk Operating System) command or C++ (C wi th Classes, C with class) language.
  • D0S disk Operating System
  • C++ C wi th Classes, C with class
  • the client detects whether an execution plan corresponding to the SQL request exists in the cache of the client.
  • the execution plan corresponding to the SQL request is a specific execution process corresponding to the SQL request in the database system.
  • the above client's cache holds an execution plan that has been executed and designated for saving.
  • the execution plan that is specified to be saved may be specified by the user, or may be pre-configured in the database server, which is not limited in the embodiment of the present invention.
  • the step 102 may include: searching each execution plan saved in the cache of the client one by one until the execution plan corresponding to the SQL request is found.
  • the step 102 may further include: the client first establishes a hash table hash table, and saves the location information of each execution plan in the cache of the client in the hash table, and then searches the hash table for the S QL request correspondingly. Executing the location information in the cache of the client, and finally searching for the execution plan corresponding to the S QL request in the cache of the client by using the location information, thereby improving the search efficiency of the execution plan corresponding to the SQL request.
  • a hash operation is performed to generate location information.
  • the location information is used to indicate a cache location of an execution plan corresponding to the SQL request, and the cache location is a cache of the client and/or a cache of the database server.
  • the location information may specifically be specified by the prompt Hints.
  • the Hints designation is specifically PlanCacheServer
  • the specified execution plan is saved to the database server
  • the Hints designation is specifically PlanCacheClient
  • the specified execution plan is saved to the client
  • the Hints designation is specifically PlanCacheAll
  • the specified execution plan is saved to the database server.
  • the database server default location information is PlanCacheAll, which specifies that the execution plan is saved to the database server and client.
  • the client may perform a hash operation or other operations to generate location information according to the SQL request, which is not limited in the embodiment of the present invention.
  • the cache location of the execution plan can be determined according to the user's needs, and the execution plan that the client has executed is saved on the client, thereby avoiding partial execution due to limited cache space of the database server.
  • the plan cannot be permanently saved in the database server, causing a low cache hit rate for the execution plan.
  • Step 103a further includes a step 104a, the client sends the location information and the SQL request to the database server.
  • the database server After the database server generates an execution plan corresponding to the SQL request, and obtains a cache location of the execution plan according to the location information, the execution plan is saved.
  • the step of the database server generating the execution plan corresponding to the SQL request may include: the database server parsing the SQL request sent by the client, and generating an execution plan corresponding to the SQL request. Since the process of the database server parsing the SQL request and generating the execution plan is time consuming, by saving all executed execution plans in the client's cache and/or the database server's cache, the cache hit rate of the execution plan can be improved, avoiding The current database server cannot save all executed execution plans, causing the database server to re-parse the executed SQL requests and generate a corresponding execution plan, thereby reducing system overhead.
  • the cache location of the execution plan may specifically be a database server. Cache or client cache.
  • the embodiment of the present invention saves all the execution plans or partial execution plans executed by the client in the cache of the client, and does not cause the client's cache and database server. Cache saturation, when the current execution plan of all clients is saved in the cache of the database server, the cache hit rate of the execution plan is improved because the database server's cache is saturated, causing some execution plans to be saved.
  • the execution plan saved in the client's cache will continue to be saved in the client's cache, so that the execution plan saved in the database server is lost when the database server is restarted.
  • the database server may directly execute the execution plan, and the S QL request corresponding to the execution plan need not be parsed again to generate the execution plan, thereby improving The execution efficiency of the S QL request.
  • the client selects any one of the multiple execution plans to send to the database server.
  • the S QL request usually corresponds to one execution plan, but some complex S QL requests will correspond to multiple different execution plans. If the client's cache holds multiple execution plans corresponding to the S QL request, the client randomly selects one execution plan among the multiple execution plans and sends it to the database server. Preferably, the client may send an execution plan that is commonly used or has a short execution time from a plurality of execution plans to the database server.
  • the step 1 0 3 b may further include: the client displays the parameter information of the execution plan through a graphical interface, and then the client adjusts the parameter information of the execution plan according to the parameter information modification instruction, and the adjusted The execution plan is saved in the cache of the client. At this point, the client sends the adjusted execution plan to the database server.
  • the graphical interface is specifically displayed on the screen of the client, and the specific information of the execution plan is displayed through the text box and the arrow, and the parameter information corresponding to the execution plan is displayed, so that the user is more Add parameter changes intuitively and quickly.
  • the process of executing the execution plan by the database server is the default process of the system, which is not an optimal process. Therefore, by adjusting the parameter information of the execution plan, the execution plan can be improved in the database server.
  • the execution speed in The adjusted execution plan is saved in the client's cache as a new execution plan corresponding to the SQL request, and does not replace the pre-adjustment execution plan.
  • Step 104a further includes a step 105a. If the location information specifies that the cache location of the execution plan is the cache of the client, the client receives the execution plan corresponding to the SQL request sent by the database server, and saves it in the cache of the client.
  • the executed execution plan can be saved in the cache of the client
  • the user can implement the operations on the client by copying, importing, and exporting the execution plan saved in the cache of the client. Share the execution plan.
  • the client copies the execution plan in the cache and saves it as a file.
  • other clients can obtain the file of the execution plan and restore the cache in the current client, thereby implementing an execution plan between different clients. .
  • the embodiment of the present invention provides a storage device for executing a plan.
  • the entity of the device may be a client, and the device includes: a receiving unit. 21.
  • the receiving unit 21 is configured to receive a structured query language SQL request.
  • the detecting unit 22 is configured to detect whether there is an execution plan corresponding to the S Q L request received by the receiving unit 21 in the cache of the client.
  • the generating unit 23 is configured to generate location information when there is no execution plan corresponding to the SQL request detected by the detecting unit 22 in the cache of the client.
  • the location information is used to indicate the cache location of the execution plan corresponding to the SQL request, and the cache location is the cache of the client and/or the cache of the database server.
  • the sending unit 24 is configured to send the location information and the SQL request to the database server.
  • the sending unit 24 is further configured to send an execution plan to the database server when there is an execution plan corresponding to the SQL request in the cache of the client.
  • the sending unit 24 is further configured to: when there are multiple execution plans corresponding to the SQL request in the cache of the client, select any one of the multiple execution plans to send to the database server.
  • the device may further include: a display unit 25, an adjustment unit 26, and a storage unit
  • the display unit 25 is configured to display parameter information of the execution plan detected by the detecting unit 22 through the graphical interface.
  • the adjusting unit 26 is configured to adjust parameter information of the execution plan displayed by the display unit 25 according to the parameter information modification instruction.
  • the saving unit 27 is configured to save the adjusted execution plan in the cache of the client.
  • the sending unit 24 is further configured to send the adjusted execution plan of the adjusting unit 26 to the database server.
  • the receiving unit 21 is further configured to: when the location information specifies that the cache location of the execution plan is a cache of the client, receive an execution plan corresponding to the SQL request sent by the database server.
  • the saving unit 27 is further configured to save the execution plan received by the receiving unit 21 in the cache of the client.
  • the generating unit 23 is further configured to: when the execution plan corresponding to the SQL request does not exist in the cache of the client, perform a hash operation to generate the location information according to the SQL request.
  • the entity of the storage device that executes the plan may be a client.
  • the client may include: a receiver 31, a processor 32, and a transmitter 33.
  • Receiver 31 configured to receive a structured query language SQL request.
  • the processor 32 is configured to detect whether there is an execution plan corresponding to the SQL request in the cache of the client.
  • the processor 32 is further configured to generate location information when there is no execution plan corresponding to the SQL request in the cache of the client.
  • the location information is used to indicate a cache location of an execution plan corresponding to the SQL request, and the cache location is a cache of the client and/or a cache of the database server.
  • the sender 33 is configured to send the location information and the SQL request to the database server.
  • the sender 33 is further configured to send an execution plan to the database server when there is an execution plan corresponding to the SQL request in the cache of the client.
  • the sender 33 is further configured to: when there are multiple execution plans corresponding to the SQL request in the cache of the client, select any one of the multiple execution plans to send to the database server.
  • the processor 32 is further configured to display parameter information of the execution plan through the graphical interface.
  • the processor 32 is further configured to adjust parameter information of the execution plan according to the parameter information modification instruction.
  • the processor 32 is further configured to save the adjusted execution plan in a cache of the client.
  • the sender 33 is also used to send an execution plan to the database server.
  • the receiver 31 is configured to receive an execution plan corresponding to the SQL request sent by the database server when the specified information specifies that the cache location of the execution plan is the cache of the client.
  • the processor 32 is also used to save the execution plan in the cache of the client.
  • the processor 32 is further configured to perform a hash operation to generate location information according to the SQL request when there is no execution plan corresponding to the SQL request in the cache of the client.
  • the client sends the SQL request and the generated location information to the database server, and the database server generates and executes the execution plan corresponding to the SQL request according to the received SQL request and the location information. And save the execution plan to the cache indicated by the location information.
  • the embodiment of the present invention by saving the execution plan executed by the client in the cache of the client, it is possible to prevent the partial execution plan from being saved in the cache, thereby improving the cache hit rate of the execution plan. This reduces system overhead.
  • An embodiment of the present invention provides a storage method for an execution plan, which can be applied to a system as shown in FIG. 7.
  • the system includes at least one client and a database server, and the client can send the SQL request and the generated location information to the database.
  • the server may further receive an execution plan corresponding to the SQL request sent by the database server, and save the execution plan in a cache of the client;
  • the database server can receive the S QL request and location information sent by the client, and can also send the execution plan corresponding to the generated S QL request to the client.
  • the execution plan corresponding to the S QL request can be saved in both the client cache and the database server cache.
  • the storage method of the execution plan provided by the embodiment of the present invention is applicable to the database server side as shown in FIG. 4, and the method includes:
  • the database server receives the location information sent by the client and the structured query language S QL request.
  • the method further includes: if the execution plan corresponding to the SQL request sent by the client exists in the cache of the client, the database server directly executes the execution plan after receiving the execution plan sent by the client, and does not need to be performed again.
  • the S QL request corresponding to the execution plan is parsed to generate the execution plan, thereby improving the execution efficiency of the S QL request.
  • the database server receives any one of the execution plans selected from the plurality of execution plans sent by the client, and executes the execution plan.
  • the S QL request usually corresponds to one execution plan, but some complex S QL requests will correspond to multiple different execution plans. If the client's cache holds multiple execution plans corresponding to the S QL request, the client selects any one of the multiple execution plans to send to the database server.
  • the database server receives an execution plan sent by the client, selected from a plurality of execution plans, or executed for a short time.
  • the database server receives the adjusted execution plan sent by the client, and executes the execution plan.
  • the graphical interface specifically displays the specific information of the execution plan through the text box and the arrow on the screen of the client, and displays various parameter information corresponding to the execution plan, so that the user can modify the parameters more intuitively and quickly.
  • the process of executing the execution plan by the database server is the default process of the system, which is not an optimal process. Therefore, by adjusting the parameter information of the execution plan, the execution plan can be improved in the database. Execution speed in the server.
  • the adjusted execution plan is saved in the client's cache as a new execution plan corresponding to the SQL request, and does not replace the pre-adjustment execution plan.
  • the database server in the embodiment of the present invention may specifically be a database database server, and the database database server may provide services such as query, update, and management for the user.
  • the database server obtains an execution plan corresponding to the SQL request.
  • the step 402 may be: the database server searches for the execution plan corresponding to the SQL request in the cache, and if the execution plan corresponding to the SQL request exists in the cache of the database server, the database server directly obtains the execution plan, so that The database server executes an execution plan corresponding to the SQL request; if the execution plan corresponding to the SQL request does not exist in the cache of the database server, the database server parses the SQL request, and generates an execution plan corresponding to the SQL request, so that the database server executes The execution plan corresponding to the SQL request.
  • the database server obtains a cache location of the execution plan according to the location information.
  • the location information is used to indicate the cache location of the execution plan corresponding to the SQL request, and the cache location is the cache of the client and/or the cache of the database server.
  • the location information may specifically be specified by Hints.
  • the execution plan is saved to the cache of the database server.
  • the specific designation is the PlanCacheClient
  • the execution plan is saved to the cache of the client.
  • the Hints specification is specific to PlanCacheAll, the execution is specified.
  • the plan is saved to the cache of the database server and to the client's cache. If the client does not generate the location information that needs to be carried in the SQL request, the default location information of the database server is PlanCacheAll, that is, the specified execution plan is saved in the cache of the database server and in the cache of the client.
  • the client may perform a hash operation or other operations to generate location information according to the SQL request, which is not limited in the embodiment of the present invention.
  • the cache location of the execution plan can be determined according to the user's needs, and the execution plan that the client has executed is saved on the client, thereby avoiding partial execution due to limited cache space of the database server.
  • the plan cannot be permanently saved in the database server, causing a low cache hit rate for the execution plan.
  • the database server sends the execution plan to the client. Saving, can ensure that all execution plans are permanently saved in the client's cache, thereby improving the cache hit rate of the execution plan; meanwhile, since the client's entire execution plan can be permanently stored in the client's cache, the database server receives the SQL request again. When the SQL request is not parsed again and the execution plan corresponding to the SQL request is generated, the system overhead can be reduced.
  • Step 404b along with step 404a. If the location information specifies that the cache location of the execution plan is the cache of the database server, the database server saves the execution plan in the cache of the database server.
  • Step 404c along with step 404a and step 404b. If the location information specifies the cache location of the execution plan as the cache of the client and the cache of the database server, the database server sends the execution plan to the client for saving, and saves the execution plan in the database server. In the cache.
  • the execution plan corresponding to the SQL request of a certain client is simultaneously saved in the cache of the client and the cache of the database server, and the cache hit ratio of the execution plan corresponding to the SQL request can be improved, and at the same time, by using the SQL
  • the execution plan corresponding to the request is saved in the cache of the database server, so that when the other client sends the S QL request to the database server, the database server can directly find the execution plan corresponding to the SQL request and execute it, thereby improving the Execution plan execution efficiency.
  • an embodiment of the present invention provides a storage device for executing a plan.
  • the entity of the device may be a database server, and the device includes: a receiving unit. 51.
  • the receiving unit 51 is configured to receive location information sent by the client and a structured query language SQL request.
  • the location information is used to indicate a cache location of the execution plan corresponding to the SQL request, and the cache location is a cache of the client and/or a cache of the database server.
  • the obtaining unit 52 is configured to obtain an execution plan corresponding to the SQL request according to the SQL request received by the receiving unit 51.
  • the obtaining unit 52 is further configured to acquire a cache location of the execution plan according to the location information.
  • the sending unit 53 is configured to: when the location information specifies that the cache location of the execution plan is a cache of the client, the database server sends the execution plan to the client for saving.
  • the receiving unit 51 is further configured to: when an execution plan corresponding to the SQL request exists in the cache of the client, receive an execution plan sent by the client.
  • the device may further include: an executing unit 54.
  • the executing unit 54 is configured to execute an execution plan received by the receiving unit 51.
  • the receiving unit 51 is further configured to: when there are multiple execution plans corresponding to the SQL request in the cache of the client, receive any one of the execution plans selected from the plurality of execution plans sent by the client.
  • the execution unit 54 is also operative to execute the arbitrary one of the execution plans received by the receiving unit 51.
  • the receiving unit 51 is further configured to: when an execution plan corresponding to the SQL request exists in the cache of the client, and the client performs parameter adjustment on the execution plan through the graphical interface, receiving the adjusted execution plan sent by the client.
  • the execution unit 54 is also operative to execute the adjusted execution plan received by the receiving unit 51.
  • the device may further comprise a saving unit 55.
  • the saving unit 55 is configured to save the execution plan in the cache of the database server when the location information specifies that the cache location of the execution plan is the cache of the database server.
  • the entity of the storage device that executes the plan may be a database server.
  • the database server may include: a receiver 61, a processor 62, and a transmitter 63.
  • the receiver 61 is configured to receive location information sent by the client and a structured query language SQL request.
  • the location information is used to indicate a cache location of the execution plan corresponding to the SQL request,
  • the location is cached by the client and/or cached by the database server.
  • the processor 62 is configured to obtain an execution plan corresponding to the SQL request according to the SQL request.
  • the processor 62 is further configured to acquire a cache location of the execution plan according to the location information.
  • the sender 63 is configured to: when the location information specifies the cache location of the execution plan as the cache of the client, the database server sends the execution plan to the client for saving.
  • the receiver 61 is further configured to: when an execution plan corresponding to the SQL request exists in the cache of the client, receive an execution plan sent by the client.
  • the processor 62 is further configured to execute the execution plan.
  • the receiver 61 is further configured to: when there are multiple execution plans corresponding to the SQL request in the cache of the client, receive any one of the execution plans selected from the plurality of execution plans sent by the client.
  • the processor 62 is further configured to execute the any one of the execution plans.
  • the receiver 61 is further configured to: when an execution plan corresponding to the S Q L request exists in the cache of the client, and the client performs parameter adjustment on the execution plan through the graphical interface, receiving the adjusted execution plan sent by the client.
  • the processor 62 is further configured to execute the adjusted execution plan.
  • the processor 62 is further configured to: when the location information specifies that the cache location of the execution plan is the cache of the database server, the database server saves the execution plan in the cache of the database server.
  • the client sends the SQL request and the generated location information to the database server, and the database server generates and executes the execution plan corresponding to the SQL request according to the received SQL request and the location information. And save the execution plan to the cache indicated by the location information.
  • the embodiment of the present invention by saving the execution plan executed by the client in the cache of the client, it is possible to prevent the partial execution plan from being saved in the cache, thereby improving the cache hit rate of the execution plan. This reduces system overhead.
  • Embodiment 3 An embodiment of the present invention provides a storage system for executing a plan. As shown in FIG. 7, the system includes: at least one client 71 and a database server 72.
  • the client 7 1 is configured to first obtain a structured query language SQL request, and then detect whether there is an execution plan corresponding to the SQL request in the cache, and generate location information when the execution plan corresponding to the S QL request does not exist in the cache, and The location information and the S QL request are sent to the database server 7 2 .
  • the database server 72 is configured to first receive the location information and the SQL request sent by the client 71, and then obtain an execution plan corresponding to the SQL request according to the SQL request, and finally obtain a cache location of the execution plan according to the location information, if the location information is specified
  • the cache location of the execution plan is the cache of the client 7 1 , and the execution plan is sent to the client 7 1 for saving.
  • the client sends the S QL request and the generated location information to the database server, and the database server generates and executes the execution corresponding to the S QL request according to the received S QL request and the location information.
  • Plan and save the execution plan to the cache of the location information indication.
  • the embodiment of the present invention performs the execution performed by the client by separately configuring the cache area in the database server for different clients to save the execution plan corresponding to different clients.
  • the plan is saved in the cache of the client, which can prevent some execution plans from being saved in the cache, thereby improving the cache hit rate of the execution plan, thereby reducing the system overhead.
  • the method, device and system provided by the embodiments of the present invention can also be used to solve some problems existing in a single machine database, a dual machine database, and a cluster database.
  • the cache of the single-server database server is insufficient to store all the execution plans corresponding to the respective clients, and the execution plan that needs to be saved in the cache of the stand-alone database server can be obtained by the method provided by the embodiment of the present invention. It is saved in the cache of each client corresponding to the stand-alone database server, thereby reducing the cache space occupied by the execution plan in the cache of the stand-alone database server.
  • the dual-system database server randomly stores the execution plan in one of the two databases, when the client initiates a certain SQL request, The dual-system database server needs to find all the execution plans in the two databases. Therefore, in the dual-machine database scenario, the search plan corresponding to the SQL request has a high complexity.
  • the execution plan corresponding to the executed SQL request may be saved in the cache of the client by using the method provided by the embodiment of the present invention.
  • the execution plan corresponding to the request may be directly obtained from the cache of the client. In order to avoid the dual-machine database server to find all execution plans in the two databases, thereby reducing the search complexity of the dual-machine database server.
  • the cluster database server randomly stores the execution plan in one of the plurality of databases
  • the cluster database server needs to find each database.
  • the overall execution plan, so the search plan corresponding to the SQL request in the cluster database scenario is highly complex.
  • the execution plan corresponding to the executed SQL request may be saved in the cache of the client by using the method provided by the embodiment of the present invention.
  • the execution plan corresponding to the request may be directly obtained from the cache of the client. In order to avoid the cluster database server to find all execution plans in each database, thereby reducing the search complexity of the cluster database server.
  • the storage device of the execution plan provided by the embodiment of the present invention may implement the foregoing method embodiments.
  • the storage method, apparatus and system of the execution plan provided by the embodiment of the present invention can be applied to improve the cache hit rate of the execution plan and reduce the system overhead, but is not limited thereto.
  • the storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Operations Research (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明实施例公开了一种执行计划的存储方法、装置及系统,涉及数据库领域,可以提高执行计划的缓存命中率,减少系统开销。所述方法包括:客户端将SQL请求及生成的位置信息发送给数据库服务器,数据库服务器根据接收到的SQL请求及位置信息,生成并执行SQL请求对应的执行计划,并且将该执行计划保存至位置信息指示的缓存中。本发明实施例适用于在客户端或数据库服务器的缓存中保存SQL请求对应的执行计划。

Description

执行计划的存储方法、 装置及系统 技术领域
本发明涉及数据库领域, 特别涉及一种执行计划的存储方法、 装置及 系统。
背景技术
数据库中的执行计划是指对 SQL ( S t ruc t u red que ry l angua ge , 结构 化查询语言)请求的执行过程的描述。 数据库服务器每次执行客户端发起 的 SQL请求时, 都需要对 SQL请求进行解析并生成对应的执行计划, 并将执 行计划保存在数据库服务器的内存中。 目前数据库服务器在进行执行计划 的保存时, 会针对不同的客户端分别配置緩存区, 以保存不同的客户端对 应的执行计划。
然而通过目前这种执行计划的存储方式进行执行计划保存时,数据库 服务器为不同的客户端分别配置緩存区。由于当客户端所分配的緩存区饱 和后, 利用率低的执行计划所占用的緩存会被释放, 以使得该客户端利用 率高的执行计划緩存在所分配的緩存区中,即上述利用率低的执行计划无 法被保存在緩存中, 当客户端再次发起该 SQL请求时, 数据库服务器需要 重新解析该 SQL请求并生成对应的执行计划, 从而造成执行计划的緩存命 中率较低, 增加了系统开销。
发明内容
本发明实施例提供一种执行计划的存储方法、 装置及系统, 可以提高 执行计划的緩存命中率, 减少系统开销。 第一方面, 本发明实施例提供一 种执行计划的存储方法, 包括:
客户端接收结构化查询语言 SQL请求;
所述客户端检测在所述客户端的緩存中是否存在所述 SQL请求对应的 执行计划;
若所述客户端的緩存中不存在所述 SQL请求对应的执行计划, 所述客 户端生成位置信息, 所述位置信息用于指示与所述 S QL请求对应的执行计 划的緩存位置, 所述緩存位置为所述客户端的緩存和 /或数据库服务器的 緩存;
所述客户端将所述位置信息及所述 S QL请求发送给所述数据库服务 器, 以使得所述数据库服务器生成所述 SQL请求对应的执行计划, 并将所 述执行计划保存到所述位置信息指示的緩存中。
在第一方面的第一种实现方式中, 还包括:
若所述客户端的緩存中存在所述 S QL请求对应的执行计划, 所述客户 端将所述执行计划发送给所述数据库服务器,以使得所述数据库服务器执 行所述执行计划。
结合第一方面或者第一方面的第一种实现方式,在第一方面的第二种 实现方式中, 所述若所述客户端的緩存中存在所述 S QL请求对应的执行计 划, 所述客户端将所述执行计划发送给所述数据库服务器, 以使得所述数 据库服务器执行所述执行计划, 具体包括:
若所述客户端的緩存中存在所述 S QL请求对应的多个执行计划, 则所 述客户端从所述多个执行计划中选择任意一个执行计划发送给所述数据 库服务器。
结合第一方面或者第一方面的第一种实现方式,或者第一方面的第二 种实现方式, 在第一方面的第三种实现方式中, 在所述客户端将所述执行 计划发送给所述数据库服务器之前, 所述方法还包括:
所述客户端通过图形化界面显示所述执行计划的参数信息; 所述客户端根据参数信息修改指令调整所述执行计划的参数信息,并 将调整后的执行计划保存在所述客户端的緩存中;
所述客户端将所述执行计划发送给所述数据库服务器的步骤包括: 所述客户端将所述调整后的执行计划发送给所述数据库服务器。 结合第一方面或者第一方面的第一种实现方式,或者第一方面的第二 种实现方式, 或者第一方面的第三种实现方式, 在第一方面的第四种实现 方式中, 在所述客户端将所述位置信息及所述 SQL请求发送给所述数据库 服务器之后, 所述方法还包括:
若所述位置信息指定所述执行计划的緩存位置为所述客户端的緩存, 所述客户端接收所述数据库服务器发送的所述 SQL请求对应的执行计划, 并保存在所述客户端的緩存中。
结合第一方面或者第一方面的第一种实现方式,或者第一方面的第二 种实现方式, 或者第一方面的第三种实现方式, 或者第一方面的第四种实 现方式, 在第一方面的第五种实现方式中, 所述若所述客户端的緩存中不 存在所述 S QL请求对应的执行计划, 所述客户端生成位置信息, 具体包括: 若所述客户端的緩存中不存在所述 SQL请求对应的执行计划, 所述客 户端根据所述 S QL请求, 进行哈希运算生成所述位置信息。 第二方面, 本 发明实施例提供一种执行计划的存储装置, 包括:
接收单元, 用于接收结构化查询语言 S QL请求;
检测单元,用于检测在所述客户端的緩存中是否存在所述接收单元接 收的所述 S Q L请求对应的执行计划;
生成单元,用于当所述客户端的緩存中不存在所述检测单元检测的所 述 S QL请求对应的执行计划时, 生成位置信息, 所述位置信息用于指示与 所述 SQL请求对应的执行计划的緩存位置, 所述緩存位置为所述客户端的 緩存和 /或数据库服务器的緩存;
发送单元, 用于将所述位置信息及所述 S QL请求发送给所述数据库服 务器。
在第二方面的第一种实现方式中, 所述发送单元, 还用于当所述客户 端的緩存中存在所述 S QL请求对应的执行计划时, 将所述执行计划发送给 所述数据库服务器, 以使得所述数据库服务器执行所述执行计划。
结合第二方面或者第二方面的第一种实现方式,在第二方面的第二种 实现方式中, 所述发送单元, 还用于当所述客户端的緩存中存在所述 S QL 请求对应的多个执行计划时,则从所述多个执行计划中选择任意一个执行 计划发送给所述数据库服务器。
结合第二方面或者第二方面的第一种实现方式,或者第二方面的第二 种实现方式, 在第二方面的第三种实现方式中, 还包括:
显示单元,用于通过图形化界面显示所述检测单元检测到的所述执行 计划的参数信息;
调整单元,用于根据参数信息修改指令调整所述显示单元显示的所述 执行计划的参数信息;
保存单元, 用于将调整后的执行计划保存在所述客户端的緩存中; 所述发送单元,还用于将所述调整单元调整后的执行计划发送给所述 数据库服务器。
结合第二方面或者第二方面的第一种实现方式,或者第二方面的第二 种实现方式, 或者第二方面的第三种实现方式, 在第二方面的第四种实现 方式中,
所述接收单元,还用于当所述位置信息指定所述执行计划的緩存位置 为所述客户端的緩存时, 接收所述数据库服务器发送的所述 SQL请求对应 的执行计划;
所述保存单元,还用于将所述接收单元接收的所述执行计划保存在所 述客户端的緩存中。
结合第二方面或者第二方面的第一种实现方式,或者第二方面的第二 种实现方式, 或者第二方面的第三种实现方式, 或者第二方面的第四种实 现方式, 在第二方面的第五种实现方式中,
所述生成单元, 还用于当所述客户端的緩存中不存在所述 SQL请求对 应的执行计划时, 根据所述 S QL请求, 进行哈希运算生成所述位置信息。
第三方面, 本发明实施例提供一种执行计划的存储方法, 包括: 数据库服务器接收客户端发送的位置信息及结构化查询语言 S QL请 求, 所述位置信息用于指示与所述 S QL请求对应的执行计划的緩存位置, 所述緩存位置为客户端的緩存和 /或数据库服务器的緩存; 所述数据库服务器获取所述 S QL请求对应的执行计划;
所述数据库服务器根据所述位置信息获取所述执行计划的緩存位置; 若所述位置信息指定所述执行计划的緩存位置为所述客户端的緩存, 所述数据库服务器将所述执行计划发送给所述客户端进行保存。
在第三方面的第一种实现方式中,在所述数据库服务器接收客户端发 送的位置信息及结构化查询语言 SQL请求之前, 所述方法还包括:
若所述客户端的緩存中存在所述 S QL请求对应的执行计划, 所述数据 库服务器接收所述客户端发送的所述执行计划, 并且执行所述执行计划。
结合第三方面或者第三方面的第一种实现方式,在第三方面的第二种 实现方式中, 所述若所述客户端的緩存中存在所述 S QL请求对应的执行计 划, 所述数据库服务器接收所述客户端发送的所述执行计划, 并且执行所 述执行计划, 具体包括:
若所述客户端的緩存中存在所述 S QL请求对应的多个执行计划, 所述 数据库服务器接收所述客户端发送的从所述多个执行计划中选择的任意 一个执行计划, 并且执行所述执行计划。
结合第三方面或者第三方面的第一种实现方式,或者第三方面的第二 种实现方式, 在第三方面的第三种实现方式中, 所述若所述客户端的緩存 中存在所述 SQL请求对应的执行计划, 所述数据库服务器接收所述客户端 发送的所述执行计划, 并且执行所述执行计划, 具体包括:
若所述客户端的緩存中存在所述 S QL请求对应的执行计划, 并且所述 客户端通过图形化界面对所述执行计划进行参数调整,所述数据库服务器 接收所述客户端发送的调整后的执行计划, 并且执行所述执行计划。
结合第三方面或者第三方面的第一种实现方式,或者第三方面的第二 种实现方式, 或者第三方面的第三种实现方式, 在第三方面的第四种实现 方式中,在所述数据库服务器根据所述指定信息获取所述执行计划的緩存 位置之后, 所述方法还包括:
若所述位置信息指定所述执行计划的緩存位置为所述数据库服务器 的緩存,所述数据库服务器将所述执行计划保存在所述数据库服务器的緩 存中。
第四方面, 本发明实施例提供一种执行计划的存储装置, 包括: 接收单元, 用于接收客户端发送的位置信息及结构化查询语言 S QL请 求, 所述位置信息用于指示与所述 S QL请求对应的执行计划的緩存位置, 所述緩存位置为客户端的緩存和 /或数据库服务器的緩存;
获取单元, 用于根据所述接收单元接收的所述 SQL请求, 获取所述 S QL 请求对应的执行计划;
所述获取单元,还用于根据所述位置信息获取所述执行计划的緩存位 置;
发送单元,用于当所述位置信息指定所述执行计划的緩存位置为所述 客户端的緩存时,所述数据库服务器将所述执行计划发送给所述客户端进 行保存。
在第四方面的第一种实现方式中, 所述接收单元, 还用于当所述客户 端的緩存中存在所述 S QL请求对应的执行计划时,接收所述客户端发送的 所述执行计划;
所述装置还包括:
执行单元, 用于执行所述接收单元接收的所述执行计划。
结合第四方面或者第四方面的第一种实现方式,在第四方面的第二种 实现方式中, 所述接收单元, 还用于当所述客户端的緩存中存在所述 S QL 请求对应的多个执行计划时,接收所述客户端发送的从所述多个执行计划 中选择的任意一个执行计划;
所述执行单元,还用于执行所述接收单元接收的所述任意一个执行计 划。
结合第四方面或者第四方面的第一种实现方式,或者第四方面的第二 种实现方式, 在第四方面的第三种实现方式中, 所述接收单元, 还用于当 所述客户端的緩存中存在所述 S QL请求对应的执行计划, 并且所述客户端 通过图形化界面对所述执行计划进行参数调整时,接收所述客户端发送的 调整后的执行计划;
所述执行单元,还用于执行所述接收单元接收的所述调整后的执行计 划。
结合第四方面或者第四方面的第一种实现方式,或者第四方面的第二 种实现方式, 或者第四方面的第三种实现方式, 在第四方面的第四种实现 方式中, 所述装置还包括:
保存单元,用于当所述位置信息指定所述执行计划的緩存位置为所述 数据库服务器的緩存时,所述数据库服务器将所述执行计划保存在所述数 据库服务器的緩存中。
第五方面, 本发明实施例提供一种执行计划的存储系统, 包括: 至少 一个客户端和数据库服务器;
所述客户端, 用于接收结构化查询语言 S QL请求, 检测在所述客户端 的緩存中是否存在所述 S QL请求对应的执行计划;
所述客户端, 还用于当所述客户端的緩存中不存在所述 S QL请求对应 的执行计划时, 生成位置信息, 并且将所述位置信息及所述 SQL请求发送 给所述数据库服务器, 所述位置信息用于指示与所述 SQL请求对应的执行 计划的緩存位置, 所述緩存位置为所述客户端的緩存和 /或数据库服务器 的緩存;
所述数据库服务器, 用于接收客户端发送的所述位置信息及所述 S QL 请求, 并根据所述位置信息及所述 S QL请求, 获取所述 S QL请求对应的执行 计划;
所述数据库服务器,还用于根据所述位置信息获取所述执行计划的緩 存位置,当所述位置信息指定所述执行计划的緩存位置为所述客户端的緩 存时, 将所述执行计划发送给所述客户端进行保存。
本发明实施例提供的执行计划的存储方法、装置及系统,客户端将 SQL 请求及生成的位置信息发送给数据库服务器,数据库服务器根据接收到的 SQL请求及位置信息, 生成并执行 SQL请求对应的执行计划, 并且将该执行 计划保存至位置信息指示的緩存中。 与现有技术相比, 本发明实施例通过 将客户端执行过的执行计划保存在该客户端的緩存中,可以避免部分执行 计划无法被保存在緩存中, 从而提高了执行计划的緩存命中率, 进而降低 了系统开销。
附图说明
为了更清楚地说明本发明实施例中的技术方案,下面将对实施例或现 有技术描述中所需要使用的附图作简单地介绍, 显而易见地, 下面描述中 的附图仅仅是本发明的一些实施例, 对于本领域普通技术人员来讲, 在不 付出创造性劳动的前提下, 还可以根据这些附图获得其它的附图。
图 1为本发明实施例一提供的一种执行计划的存储方法流程图; 图 2为本发明实施例一提供的一种执行计划的存储结构示意图; 图 3为本发明实施例一提供的一种基站结构示意图;
图 4为本发明实施例二提供的一种执行计划的存储方法流程图; 图 5为本发明实施例二提供的一种执行计划的存储结构示意图; 图 6为本发明实施例二提供的一种基站结构示意图;
图 7为本发明实施例三提供的一种执行计划的存储系统示意图。
具体实施方式
下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进 行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例, 而不是全部的实施例。 基于本发明中的实施例, 本领域普通技术人员在没 有做出创造性劳动前提下所获得的所有其它实施例,都属于本发明保护的 范围。
为使本发明技术方案的优点更加清楚,下面结合附图和实施例对本发 明作详细说明。
实施例一
本发明实施例提供一种执行计划的存储方法, 可以应用于如图 7所示 的系统中,该系统包括至少一个客户端和数据库服务器,客户端可以将 SQL 请求与生成的位置信息发送给数据库服务器,还可以接收数据库服务器发 送的 SQL请求对应的执行计划, 并将该执行计划保存在客户端的緩存中; 数据库服务器可以接收客户端发送的 SQL请求与位置信息, 还可以将生成 的 SQL请求对应的执行计划发送给客户端。 其中, 客户端的緩存及数据库 服务器的緩存中均可以保存 S QL请求对应的执行计划。
基于该系统, 本发明实施例提供的执行计划的存储方法, 如图 1所示, 可应用于客户端侧, 所述方法包括:
101、 客户端接收结构化查询语言 SQL请求。
其中, SQL请求为一种数据库查询语言, 用于在数据库系统中存取数 据,以及查询、更新和管理数据库系统。用户可以通过 D0S( Disk Operating System, 磁盘操作系统) 命令或者 C++ ( C wi th Classes , 带类的 C) 语言 输入需要执行的 SQL语句。
102、 客户端检测在客户端的緩存中是否存在 SQL请求对应的执行计 划。
其中, SQL请求对应的执行计划为 SQL请求在数据库系统中对应的具体 执行过程。上述客户端的緩存中保存有已经执行并且指定进行保存的执行 计划。 指定进行保存的执行计划具体可以为用户指定的, 也可以为数据库 服务器中预先配置的, 本发明实施例不做限定。
可选地, 步骤 102具体可以包括: 对客户端的緩存中保存的各个执行 计划进行逐个查找, 直到查找到所述 SQL请求对应的执行计划。 优选地, 步骤 102具体还可以包括: 客户端首先建立哈希表 Hash表, 并在 Hash表中 保存各个执行计划在客户端的緩存中的位置信息,然后在 Hash表中查找所 述 S QL请求对应的执行计划在客户端的緩存中的位置信息, 最后通过所述 位置信息在客户端的緩存中查找所述 S QL请求对应的执行计划, 从而提升 了 S Q L请求对应的执行计划的查找效率。
103a, 若客户端的緩存中不存在 SQL请求对应的执行计划, 客户端根 据 SQL请求, 进行哈希运算生成位置信息。
其中, 位置信息用于指示与 SQL请求对应的执行计划的緩存位置, 所 述緩存位置为客户端的緩存和 /或数据库服务器的緩存。 对于本发明实施 例, 位置信息具体可以为提示 Hints指定。 此时, 当 Hints指定具体为 PlanCacheServer时, 指定执行计划保存到数据库服务器; 当 Hints指定具 体为 PlanCacheClient时, 指定执行计划保存到客户端; 当 Hints指定具体 为 PlanCacheAll时, 指定执行计划保存到数据库服务器和客户端。 若客户 端没有生成位置信息, 则数据库服务器默认位置信息为 PlanCacheAll, 即 指定将执行计划保存到数据库服务器和客户端。
对于本发明实施例, 客户端根据 SQL请求, 可以进行哈希运算或者其 他运算生成位置信息, 本发明实施例不做限定。
通过 S QL请求对应的位置信息, 可以实现根据用户的需求来确定执行 计划的緩存位置, 并且实现了在客户端保存该客户端已经执行的执行计 划, 避免由于数据库服务器的緩存空间有限, 部分执行计划无法永久保存 在数据库服务器中, 从而造成执行计划的緩存命中率较低的问题。
步骤 103a之后还包括步骤 104a、 客户端将位置信息及 SQL请求发送给 数据库服务器。
进一步地, 以使得数据库服务器生成 SQL请求对应的执行计划, 并根 据位置信息获取执行计划的緩存位置后, 保存执行计划。
其中, 数据库服务器生成 SQL请求对应的执行计划的步骤可以包括: 数据库服务器解析客户端发送的 SQL请求, 并生成 SQL请求对应的执行计 划。 由于数据库服务器解析 SQL请求并生成执行计划的过程很耗时, 所以 通过将全部执行过的执行计划保存在客户端的緩存和 /或数据库服务器的 緩存中, 可以提高执行计划的緩存命中率, 避免由于当前数据库服务器无 法对全部执行过的执行计划进行保存, 造成数据库服务器对执行过的 SQL 请求重新解析并生成对应的执行计划, 从而降低系统的开销。
对于本发明实施例,执行计划的緩存位置具体可以为数据库服务器的 緩存或客户端的緩存。 由于客户端执行过的执行计划所占用的緩存较少, 本发明实施例通过将客户端执行过的全部执行计划或者部分执行计划保 存在该客户端的緩存中,不会造成客户端的緩存和数据库服务器的緩存饱 和,与目前将所有客户端执行过的全部执行计划保存在数据库服务器的緩 存时, 由于数据库服务器的緩存饱和, 造成部分执行计划无法进行保存相 比, 提高了执行计划的緩存命中率; 同时, 客户端重启后, 客户端的緩存 中保存的执行计划仍会继续保存在客户端的緩存中,从而避免保存在数据 库服务器中的执行计划在数据库服务器重启时丟失。
与步骤 1 0 3 a并列的步骤 1 0 3 b、 若客户端的緩存中存在 S QL请求对应的 执行计划, 客户端将执行计划发送给数据库服务器。
进一步地, 以使得数据库服务器执行 S QL请求对应的执行计划。 对于 本发明实施例, 当客户端的緩存中保存有已经执行过的执行计划时, 数据 库服务器可以直接执行该执行计划, 不需要再次解析该执行计划对应的 S QL请求以生成该执行计划, 从而提高了 S QL请求的执行效率。
具体地, 若客户端的緩存中存在 S QL请求对应的多个执行计划, 则客 户端从多个执行计划中选择任意一个执行计划发送给数据库服务器。
其中, S QL请求通常对应一个执行计划, 但部分复杂的 S QL请求会对应 有多个不同的执行计划。 若客户端的緩存中保存有 S QL请求对应的多个执 行计划, 此时, 客户端在多个执行计划中任意选择一个执行计划发送给数 据库服务器。 优选地, 客户端可以从多个执行计划中选择常用的或者执行 时间较短的执行计划发送给数据库服务器。
可选地, 步骤 1 0 3 b之前还可以包括: 客户端通过图形化界面显示所述 执行计划的参数信息,然后客户端根据参数信息修改指令调整所述执行计 划的参数信息, 并将调整后的执行计划保存在所述客户端的緩存中。 此时 客户端将所述调整后的执行计划发送给所述数据库服务器。
其中, 图形化界面具体为在客户端的屏幕上, 通过文本框及箭头显示 执行计划的具体信息, 并显示执行计划对应的各个参数信息, 以便用户更 加直观快速地进行参数修改。 对于本发明实施例, 未调整执行计划的参数 信息时, 数据库服务器执行该执行计划的过程为系统默认的过程, 并非最 优过程, 所以通过调整执行计划的参数信息, 可以提高执行计划在数据库 服务器中的执行速度。 调整后的执行计划作为 SQL请求对应的新增的执行 计划保存在客户端的緩存中, 不替换调整前的执行计划。
步骤 104a之后还包括步骤 105a、若位置信息指定执行计划的緩存位置 为客户端的緩存, 客户端接收数据库服务器发送的 SQL请求对应的执行计 划, 并保存在客户端的緩存中。
对于本发明实施例,由于可以将执行过的执行计划保存在客户端的緩 存中, 因此用户可以通过将客户端的緩存中保存的执行计划进行复制、 导 入、 导出等操作, 可以实现在不同的客户端间共享执行计划。 具体地, 客 户端将緩存中的执行计划复制并以文件形式进行保存,此时其他客户端可 以获取该执行计划的文件, 并恢复在当前客户端的緩存中, 从而实现不同 客户端间共享执行计划。
进一步地, 作为图 1所示方法的具体实现, 本发明实施例提供了一种 执行计划的存储装置, 如图 2所示, 所述装置的实体可以为客户端, 所述 装置包括: 接收单元 21、 检测单元 22、 生成单元 23、 发送单元 24。
接收单元 21, 用于接收结构化查询语言 SQL请求。
检测单元 22,用于检测在客户端的緩存中是否存在接收单元 21接收的 S Q L请求对应的执行计划。
生成单元 23, 用于当客户端的緩存中不存在检测单元 22检测的 SQL请 求对应的执行计划时, 生成位置信息。
其中, 位置信息用于指示与 SQL请求对应的执行计划的緩存位置, 緩 存位置为客户端的緩存和 /或数据库服务器的緩存。
发送单元 24, 用于将位置信息及 SQL请求发送给数据库服务器。
发送单元 24, 还用于当客户端的緩存中存在 SQL请求对应的执行计划 时, 将执行计划发送给数据库服务器。 发送单元 24 , 还用于当客户端的緩存中存在 SQL请求对应的多个执行 计划时, 从多个执行计划中选择任意一个执行计划发送给数据库服务器。
可选地, 所述装置还可以包括: 显示单元 25、 调整单元 26、 保存单元
27。
显示单元 25 ,用于通过图形化界面显示检测单元 22检测到的执行计划 的参数信息。
调整单元 26 ,用于根据参数信息修改指令调整显示单元 25显示的执行 计划的参数信息。
保存单元 27 , 用于将调整后的执行计划保存在客户端的緩存中。
发送单元 24 ,还用于将调整单元 26调整后的执行计划发送给数据库服 务器。
接收单元 21 ,还用于当位置信息指定执行计划的緩存位置为客户端的 緩存时, 接收数据库服务器发送的 SQL请求对应的执行计划。
保存单元 27 ,还用于将接收单元 21接收的执行计划保存在客户端的緩 存中。
生成单元 23 , 还用于当客户端的緩存中不存在 SQL请求对应的执行计 划时, 根据 SQL请求, 进行哈希运算生成位置信息。
再进一步地, 所述执行计划的存储装置的实体可以为客户端, 如图 3 所示, 所述客户端可以包括: 接收器 31、 处理器 32、 发送器 33。
接收器 31 , 用于接收结构化查询语言 SQL请求。
处理器 32 , 用于检测在客户端的緩存中是否存在 SQL请求对应的执行 计划。
处理器 32 , 还用于当客户端的緩存中不存在 SQL请求对应的执行计划 时, 生成位置信息。
所述位置信息用于指示与 SQL请求对应的执行计划的緩存位置, 緩存 位置为客户端的緩存和 /或数据库服务器的緩存。
发送器 33 , 用于将位置信息及 SQL请求发送给数据库服务器。 发送器 33 ,还用于当客户端的緩存中存在 SQL请求对应的执行计划时 , 将执行计划发送给数据库服务器。
发送器 33 , 还用于当客户端的緩存中存在 SQL请求对应的多个执行计 划时, 从多个执行计划中选择任意一个执行计划发送给数据库服务器。
处理器 32 , 还用于通过图形化界面显示执行计划的参数信息。
处理器 32 , 还用于根据参数信息修改指令调整执行计划的参数信息。 处理器 32 , 还用于将调整后的执行计划保存在客户端的緩存中。
发送器 33 , 还用于将执行计划发送给数据库服务器。
接收器 31 ,用于当指定信息指定执行计划的緩存位置为客户端的緩存 时, 接收数据库服务器发送的 SQL请求对应的执行计划。
处理器 32 , 还用于将执行计划保存在客户端的緩存中。
处理器 32 , 还用于当客户端的緩存中不存在 SQL请求对应的执行计划 时, 根据 SQL请求, 进行哈希运算生成位置信息。
需要说明的是,本发明实施例中提供的执行计划的存储装置中各功能 单元所对应的其他相应描述, 可以参考图 1中的对应描述, 在此不再赘述。
本发明实施例提供的执行计划的存储方法及装置, 客户端将 SQL请求 及生成的位置信息发送给数据库服务器, 数据库服务器根据接收到的 SQL 请求及位置信息, 生成并执行 SQL请求对应的执行计划, 并且将该执行计 划保存至位置信息指示的緩存中。 与现有技术相比, 本发明实施例通过将 客户端执行过的执行计划保存在该客户端的緩存中,可以避免部分执行计 划无法被保存在緩存中, 从而提高了执行计划的緩存命中率, 进而降低了 系统开销。
实施例二
本发明实施例提供一种执行计划的存储方法, 可以应用于如图 7所示 的系统中,该系统包括至少一个客户端和数据库服务器,客户端可以将 SQL 请求与生成的位置信息发送给数据库服务器,还可以接收数据库服务器发 送的 SQL请求对应的执行计划, 并将该执行计划保存在客户端的緩存中; 数据库服务器可以接收客户端发送的 S QL请求与位置信息, 还可以将生成 的 S QL请求对应的执行计划发送给客户端。 其中, 客户端的緩存及数据库 服务器的緩存中均可以保存 S QL请求对应的执行计划。
基于该系统, 本发明实施例提供的执行计划的存储方法, 如图 4所示, 可应用于数据库服务器侧, 所述方法包括:
4 01、数据库服务器接收客户端发送的位置信息及结构化查询语言 S QL 请求。
可选地, 步骤 4 0 1之前还可以包括: 若客户端的緩存中存在客户端发 送的 SQL请求对应的执行计划, 数据库服务器接收客户端发送的执行计划 后, 直接执行该执行计划, 不需要再次解析该执行计划对应的 S QL请求以 生成该执行计划, 从而提高了 S QL请求的执行效率。
具体地, 若客户端的緩存中存在 S QL请求对应的多个执行计划, 数据 库服务器接收客户端发送的从多个执行计划中选择的任意一个执行计划, 并且执行该执行计划。
其中, S QL请求通常对应一个执行计划, 但部分复杂的 S QL请求会对应 有多个不同的执行计划。 若客户端的緩存中保存有 S QL请求对应的多个执 行计划, 此时, 客户端在多个执行计划中选择任意的一个执行计划发送给 数据库服务器。 优选地, 数据库服务器接收客户端发送的, 从多个执行计 划中选择的常用的或者执行时间较短的一个执行计划。
可替换地, 若客户端的緩存中存在 SQL请求对应的执行计划, 并且客 户端通过图形化界面对执行计划进行参数调整,数据库服务器接收客户端 发送的调整后的执行计划, 并且执行该执行计划。
其中, 图形化界面具体为在客户端的屏幕上, 通过文本框及箭头显示 执行计划的具体信息, 并显示执行计划对应的各个参数信息, 以便用户更 加直观快速地进行参数修改。 对于本发明实施例, 未调整执行计划的参数 信息时, 数据库服务器执行该执行计划的过程为系统默认的过程, 并非最 优过程, 所以通过调整执行计划的参数信息, 可以提高执行计划在数据库 服务器中的执行速度。 调整后的执行计划作为 SQL请求对应的新增的执行 计划保存在客户端的緩存中, 不替换调整前的执行计划。
对于本发明实施例中的数据库服务器具体可以为数据库数据库服务 器, 数据库数据库服务器可以为用户提供查询、 更新和管理等服务。
402、 数据库服务器获取 SQL请求对应的执行计划。
本实施例中, 步骤 402具体可以为, 数据库服务器查找緩存中是否存 在该 SQL请求对应的执行计划,若数据库服务器的緩存中存在该 SQL请求对 应的执行计划, 数据库服务器直接获取该执行计划, 以便数据库服务器执 行该 SQL请求对应的执行计划;若数据库服务器的緩存中不存在该 SQL请求 对应的执行计划, 数据库服务器对该 SQL请求进行解析, 并生成该 SQL请求 对应的执行计划, 以便数据库服务器执行该 SQL请求对应的执行计划。
403、 数据库服务器根据位置信息获取执行计划的緩存位置。
其中, 位置信息用于指示与 SQL请求对应的执行计划的緩存位置, 緩 存位置为客户端的緩存和 /或数据库服务器的緩存。 对于本发明实施例, 位置信息具体可以为 Hints指定。 此时 , 当 Hints指定具体为 PlanCacheServer时, 指定执行计划保存到数据库服务器的緩存中; 当 Hints指定具体为 PlanCacheClient时,指定执行计划保存到客户端的緩存 中; 当 Hints指定具体为 PlanCacheAll时, 指定执行计划保存到数据库服 务器的緩存中和客户端的緩存中。 若客户端没有生成 SQL请求中需要携带 的位置信息, 则数据库服务器默认位置信息为 PlanCacheAll, 即指定执行 计划保存到数据库服务器的緩存中和客户端的緩存中。
对于本发明实施例, 客户端根据 SQL请求, 可以进行哈希运算或者其 他运算生成位置信息, 本发明实施例不做限定。
通过 S QL请求对应的位置信息, 可以实现根据用户的需求来确定执行 计划的緩存位置, 并且实现了在客户端保存该客户端已经执行的执行计 划, 避免由于数据库服务器的緩存空间有限, 部分执行计划无法永久保存 在数据库服务器中, 从而造成执行计划的緩存命中率较低的问题。 404a, 若位置信息指定执行计划的緩存位置为客户端的緩存, 数据库 服务器将执行计划发送给客户端进行保存。
对于本发明实施例,由于客户端的緩存中足够存放该客户端的全部执 行计划,并且客户端的緩存中保存的执行计划不会因为客户端重新启动而 丟失, 数据库服务器通过将该执行计划发送给客户端进行保存, 可以保证 全部执行计划永久保存在该客户端的緩存中,从而提高执行计划的緩存命 中率;同时,由于客户端的全部执行计划能够永久存放在客户端的緩存中, 所以数据库服务器再次接收该 SQL请求时,不需要再次解析 SQL请求并生成 该 SQL请求对应的执行计划, 从而可以降低系统开销。
与步骤 404a并列的步骤 404b、若位置信息指定执行计划的緩存位置为 数据库服务器的緩存,数据库服务器将执行计划保存在数据库服务器的緩 存中。
与步骤 404a和步骤 404b并列的步骤 404c、若位置信息指定执行计划的 緩存位置为客户端的緩存和数据库服务器的緩存,数据库服务器将执行计 划发送给客户端进行保存, 并且将执行计划保存在数据库服务器的緩存 中。
对于本发明实施例, 将某一个客户端的 SQL请求对应的执行计划同时 保存在客户端的緩存和数据库服务器的緩存中, 能够提高该 SQL请求对应 的执行计划的緩存命中率, 同时, 通过将该 SQL请求对应的执行计划保存 在数据库服务器的緩存中, 从而使得当其他客户端发送该 S QL请求给数据 库服务器时, 数据库服务器也能够直接查找到该 SQL请求对应的执行计划 并进行执行, 从而提高了执行计划的执行效率。
进一步地, 作为图 4所示方法的具体实现, 本发明实施例提供了一种 执行计划的存储装置, 如图 5所示, 所述装置的实体可以为数据库服务器, 所述装置包括: 接收单元 51、 获取单元 52、 发送单元 53。
接收单元 51, 用于接收客户端发送的位置信息及结构化查询语言 SQL 请求。 其中, 位置信息用于指示与 SQL请求对应的执行计划的緩存位置, 緩 存位置为客户端的緩存和 /或数据库服务器的緩存。
获取单元 52, 用于根据接收单元 51接收的 SQL请求, 获取 SQL请求对应 的执行计划。
获取单元 52 , 还用于根据位置信息获取执行计划的緩存位置。
发送单元 53 ,用于当位置信息指定执行计划的緩存位置为客户端的緩 存时, 数据库服务器将执行计划发送给客户端进行保存。
接收单元 51, 还用于当客户端的緩存中存在 SQL请求对应的执行计划 时, 接收客户端发送的执行计划。
可选地, 所述装置还可以包括: 执行单元 54。
执行单元 54 , 用于执行接收单元 51接收的执行计划。
接收单元 51 , 还用于当客户端的緩存中存在 SQL请求对应的多个执行 计划时, 接收客户端发送的从多个执行计划中选择的任意一个执行计划。
执行单元 54, 还用于执行接收单元 51接收的该任意一个执行计划。 接收单元 51,还用于当客户端的緩存中存在 SQL请求对应的执行计划, 并且客户端通过图形化界面对执行计划进行参数调整时,接收客户端发送 的调整后的执行计划。
执行单元 54, 还用于执行接收单元 51接收的调整后的执行计划。
可选地, 所述装置还可以包括保存单元 55。
保存单元 55,用于当位置信息指定执行计划的緩存位置为数据库服务 器的緩存时, 数据库服务器将执行计划保存在数据库服务器的緩存中。
再进一步地, 所述执行计划的存储装置的实体可以为数据库服务器, 如图 6所示, 所述数据库服务器可以包括: 接收器 61、 处理器 62、 发送器 63。
接收器 61, 用于接收客户端发送的位置信息及结构化查询语言 SQL请 求。
其中, 位置信息用于指示与 SQL请求对应的执行计划的緩存位置, 緩 存位置为客户端的緩存和 /或数据库服务器的緩存。
处理器 62 , 用于根据 SQL请求, 获取 SQL请求对应的执行计划。
处理器 62 , 还用于根据位置信息获取执行计划的緩存位置。
发送器 63 ,用于当位置信息指定执行计划的緩存位置为客户端的緩存 时, 数据库服务器将执行计划发送给客户端进行保存。
接收器 61 ,还用于当客户端的緩存中存在 SQL请求对应的执行计划时, 接收客户端发送的执行计划。
处理器 62 , 还用于执行该执行计划。
接收器 61 , 还用于当客户端的緩存中存在 SQL请求对应的多个执行计 划时, 接收客户端发送的从多个执行计划中选择的任意一个执行计划。
处理器 62 , 还用于执行该任意一个执行计划。
接收器 61 , 还用于当客户端的緩存中存在 S Q L请求对应的执行计划, 并且客户端通过图形化界面对执行计划进行参数调整时,接收客户端发送 的调整后的执行计划。
处理器 62 , 还用于执行调整后的执行计划。
处理器 62 ,还用于当位置信息指定执行计划的緩存位置为数据库服务 器的緩存时, 数据库服务器将执行计划保存在数据库服务器的緩存中。
需要说明的是,本发明实施例中提供的执行计划的存储装置中各功能 单元所对应的其他相应描述, 可以参考图 4中的对应描述, 在此不再赘述。
本发明实施例提供的执行计划的存储方法及装置, 客户端将 SQL请求 及生成的位置信息发送给数据库服务器, 数据库服务器根据接收到的 SQL 请求及位置信息, 生成并执行 SQL请求对应的执行计划, 并且将该执行计 划保存至位置信息指示的緩存中。 与现有技术相比, 本发明实施例通过将 客户端执行过的执行计划保存在该客户端的緩存中,可以避免部分执行计 划无法被保存在緩存中, 从而提高了执行计划的緩存命中率, 进而降低了 系统开销。
实施例三 本发明实施例提供一种执行计划的存储系统, 如图 7所示, 所述系统 包括: 至少一个客户端 7 1和数据库服务器 72。
客户端 7 1 , 用于首先获取结构化查询语言 SQL请求, 然后在緩存中检 测是否存在 SQL请求对应的执行计划,当緩存中不存在 S QL请求对应的执行 计划时, 生成位置信息, 并且将位置信息及 S QL请求发送给数据库服务器 7 2。
数据库服务器 72 ,用于首先接收客户端 7 1发送的位置信息及 S QL请求, 然后根据 S QL请求, 获取 SQL请求对应的执行计划, 最后根据位置信息获取 执行计划的緩存位置, 若位置信息指定执行计划的緩存位置为客户端 7 1 的緩存, 将执行计划发送给客户端 7 1进行保存。
本发明实施例提供的执行计划的存储系统, 客户端将 S QL请求及生成 的位置信息发送给数据库服务器, 数据库服务器根据接收到的 S QL请求及 位置信息, 生成并执行 S QL请求对应的执行计划, 并且将该执行计划保存 至位置信息指示的緩存中。 与目前数据库服务器进行执行计划的保存时, 通过为不同客户端在数据库服务器中分别配置緩存区,以保存不同的客户 端对应的执行计划相比,本发明实施例通过将客户端执行过的执行计划保 存在该客户端的緩存中, 可以避免部分执行计划无法被保存在緩存中, 从 而提高了执行计划的緩存命中率, 进而降低了系统开销。
本发明实施例提供的方法、 装置及系统还可以用于解决单机数据库、 双机数据库及集群数据库中存在的一些问题。
例如, 在单机数据库的场景下, 单机数据库服务器的緩存中不足以存 放各个客户端对应的全部执行计划, 通过本发明实施例提供的方法, 可以 将需要在单机数据库服务器的緩存中保存的执行计划保存在单机数据库 服务器对应的各个客户端的緩存中,从而减小了单机数据库服务器的緩存 中执行计划所占用的緩存空间。
在双机数据库的场景下,由于双机数据库服务器将执行计划随机的保 存在两个数据库中的某一个数据库中, 当客户端发起某一个 SQL请求时, 双机数据库服务器就需要查找两个数据库中的全部执行计划,因此在双机 数据库场景下, 对 SQL请求对应的执行计划的查找复杂度较高。 通过本发 明实施例提供的方法, 可以将执行过的 S Q L请求对应的执行计划保存在客 户端的緩存中, 当客户端发起一个 SQL请求时, 可以直接从客户端的緩存 中获取该请求对应的执行计划,从而避免双机数据库服务器查找两个数据 库中的全部执行计划, 进而降低双机数据库服务器的查找复杂度。
同样的, 在集群数据库的场景下, 由于集群数据库服务器将执行计划 随机的保存在多个数据库中的某一个数据库中, 当客户端发起某一个 SQL 请求时, 集群数据库服务器就需要查找各个数据库中的全部执行计划, 因 此在集群数据库场景下的 SQL请求对应的执行计划的查找复杂度高。 通过 本发明实施例提供的方法, 可以将执行过的 SQL请求对应的执行计划保存 在客户端的緩存中, 当客户端发起一个 SQL请求时, 可以直接从客户端的 緩存中获取该请求对应的执行计划,从而避免集群数据库服务器查找各个 数据库中的全部执行计划, 进而降低集群数据库服务器的查找复杂度。
本发明实施例提供的执行计划的存储装置可以实现上述提供的方法 实施例, 具体功能实现请参见方法实施例中的说明, 在此不再赘述。 本发 明实施例提供的执行计划的存储方法、装置及系统可以适用于提高执行计 划的緩存命中率, 减少系统开销, 但不仅限于此。
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分 流程, 是可以通过计算机程序来指令相关的硬件来完成, 所述的程序可存 储于一计算机可读取存储介质中, 该程序在执行时, 可包括如上述各方法 的实施例的流程。 其中, 所述的存储介质可为磁碟、 光盘、 只读存储记忆 体 ( Read-Only Memory , ROM ) 或随机存 者 i己忆体 ( Random Access Memory, RAM ) 等。
以上所述, 仅为本发明的具体实施方式, 但本发明的保护范围并不局 限于此, 任何熟悉本技术领域的技术人员在本发明揭露的技术范围内, 可 轻易想到的变化或替换, 都应涵盖在本发明的保护范围之内。 因此, 本发 明的保护范围应该以权利要求的保护范围为准。

Claims

权 利 要 求 书
1、 一种执行计划的存储方法, 其特征在于, 包括:
客户端接收结构化查询语言 S Q L请求;
所述客户端检测在所述客户端的緩存中是否存在所述 SQL请求对应的 执行计划;
若所述客户端的緩存中不存在所述 S QL请求对应的执行计划,所述客户 端生成位置信息,所述位置信息用于指示与所述 SQL请求对应的执行计划的 緩存位置, 所述緩存位置为所述客户端的緩存和 /或数据库服务器的緩存; 所述客户端将所述位置信息及所述 SQL请求发送给所述数据库服务器, 以使得所述数据库服务器生成所述 SQL请求对应的执行计划,并将所述执行 计划保存到所述位置信息指示的緩存中。
2、根据权利要求 1所述的执行计划的存储方法,其特征在于, 还包括: 若所述客户端的緩存中存在所述 SQL请求对应的执行计划,所述客户端 将所述执行计划发送给所述数据库服务器, 以使得所述数据库服务器执行 所述执行计划。
3、 根据权利要求 2所述的执行计划的存储方法, 其特征在于, 所述若 所述客户端的緩存中存在所述 SQL请求对应的执行计划,所述客户端将所述 执行计划发送给所述数据库服务器, 以使得所述数据库服务器执行所述执 行计划, 具体包括:
若所述客户端的緩存中存在所述 SQL请求对应的多个执行计划,则所述 客户端从所述多个执行计划中选择任意一个执行计划发送给所述数据库服 务器。
4、 根据权利要求 2所述的执行计划的存储方法, 其特征在于, 在所述 客户端将所述执行计划发送给所述数据库服务器之前, 所述方法还包括: 所述客户端通过图形化界面显示所述执行计划的参数信息;
所述客户端根据参数信息修改指令调整所述执行计划的参数信息, 并 将调整后的执行计划保存在所述客户端的緩存中; 所述客户端将所述执行计划发送给所述数据库服务器的步骤包括: 所述客户端将所述调整后的执行计划发送给所述数据库服务器。
5、 根据权利要求 1所述的执行计划的存储方法, 其特征在于, 在所述 客户端将所述位置信息及所述 SQL请求发送给所述数据库服务器之后,所述 方法还包括:
若所述位置信息指定所述执行计划的緩存位置为所述客户端的緩存, 所述客户端接收所述数据库服务器发送的所述 SQL请求对应的执行计划,并 保存在所述客户端的緩存中。
6、 根据权利要求 1所述的执行计划的存储方法, 其特征在于, 所述若 所述客户端的緩存中不存在所述 SQL请求对应的执行计划,所述客户端生成 位置信息, 具体包括:
若所述客户端的緩存中不存在所述 S QL请求对应的执行计划,所述客户 端根据所述 S QL请求, 进行哈希运算生成所述位置信息。
7、 一种执行计划的存储方法, 其特征在于, 包括:
数据库服务器接收客户端发送的位置信息及结构化查询语言 S QL请求, 所述位置信息用于指示与所述 SQL请求对应的执行计划的緩存位置,所述緩 存位置为客户端的緩存和 /或所述数据库服务器的緩存;
所述数据库服务器获取所述 SQL请求对应的执行计划;
所述数据库服务器根据所述位置信息获取所述执行计划的緩存位置; 若所述位置信息指定所述执行计划的緩存位置为所述客户端的緩存, 所述数据库服务器将所述执行计划发送给所述客户端进行保存。
8、 根据权利要求 7所述的执行计划的存储方法, 其特征在于, 在所述 数据库服务器接收客户端发送的位置信息及结构化查询语言 S QL 请求之 前, 所述方法还包括:
若所述客户端的緩存中存在所述 SQL请求对应的执行计划,所述数据库 服务器接收所述客户端发送的所述执行计划, 并且执行所述执行计划。
9、 根据权利要求 8所述的执行计划的存储方法, 其特征在于, 所述若 所述客户端的緩存中存在所述 SQL请求对应的执行计划,所述数据库服务器 接收所述客户端发送的所述执行计划, 并且执行所述执行计划, 具体包括: 若所述客户端的緩存中存在所述 SQL请求对应的多个执行计划,所述数 据库服务器接收所述客户端发送的从所述多个执行计划中选择的任意一个 执行计划, 并且执行所述执行计划。
1 0、 根据权利要求 8所述的执行计划的存储方法, 其特征在于, 所述若 所述客户端的緩存中存在所述 SQL请求对应的执行计划,所述数据库服务器 接收所述客户端发送的所述执行计划, 并且执行所述执行计划, 具体包括: 若所述客户端的緩存中存在所述 SQL请求对应的执行计划,并且所述客 户端通过图形化界面对所述执行计划进行参数调整, 所述数据库服务器接 收所述客户端发送的调整后的执行计划, 并且执行所述执行计划。
1 1、 根据权利要求 7所述的执行计划的存储方法, 其特征在于, 在所述 数据库服务器根据所述位置信息获取所述执行计划的緩存位置之后, 所述 方法还包括:
若所述位置信息指定所述执行计划的緩存位置为所述数据库服务器的 緩存, 所述数据库服务器将所述执行计划保存在所述数据库服务器的緩存 中。
1 2、 一种执行计划的存储装置, 其特征在于, 包括:
接收单元, 用于接收结构化查询语言 S QL请求;
检测单元, 用于检测在所述客户端的緩存中是否存在所述接收单元接 收的所述 S Q L请求对应的执行计划;
生成单元, 用于当所述客户端的緩存中不存在所述检测单元检测的所 述 S QL请求对应的执行计划时, 生成位置信息, 所述位置信息用于指示与所 述 S QL请求对应的执行计划的緩存位置,所述緩存位置为所述客户端的緩存 和 /或数据库服务器的緩存;
发送单元,用于将所述位置信息及所述 S QL请求发送给所述数据库服务 器。
1 3、 根据权利要求 1 2所述的执行计划的存储装置, 其特征在于, 所述发送单元,还用于当所述客户端的緩存中存在所述 SQL请求对应的 执行计划时, 将所述执行计划发送给所述数据库服务器。
14、 根据权利要求 1 3所述的执行计划的存储装置, 其特征在于, 所述发送单元,还用于当所述客户端的緩存中存在所述 SQL请求对应的 多个执行计划时, 从所述多个执行计划中选择任意一个执行计划发送给所 述数据库服务器。
1 5、 根据权利要求 1 3所述的执行计划的存储装置, 其特征在于, 所述 装置还包括:
显示单元, 用于通过图形化界面显示所述检测单元检测到的所述执行 计划的参数信息;
调整单元, 用于根据参数信息修改指令调整所述显示单元显示的所述 执行计划的参数信息;
保存单元, 用于将调整后的执行计划保存在所述客户端的緩存中; 所述发送单元, 还用于将所述调整单元调整后的执行计划发送给所述 数据库服务器。
1 6、 根据权利要求 1 2所述的执行计划的存储装置, 其特征在于, 所述接收单元, 还用于当所述位置信息指定所述执行计划的緩存位置 为所述客户端的緩存时,接收所述数据库服务器发送的所述 SQL请求对应的 执行计划;
所述保存单元, 还用于将所述接收单元接收的所述执行计划保存在所 述客户端的緩存中。
1 7、 根据权利要求 1 2所述的执行计划的存储装置, 其特征在于, 所述生成单元,还用于当所述客户端的緩存中不存在所述 SQL请求对应 的执行计划时, 根据所述 SQL请求, 进行哈希运算生成所述位置信息。
1 8、 一种执行计划的存储装置, 其特征在于, 包括:
接收单元, 用于接收客户端发送的位置信息及结构化查询语言 SQL请 求, 所述位置信息用于指示与所述 SQL请求对应的执行计划的緩存位置, 所 述緩存位置为客户端的緩存和 /或数据库服务器的緩存;
获取单元, 用于根据所述接收单元接收的所述 SQL请求, 获取所述 SQL 请求对应的执行计划;
所述获取单元, 还用于根据所述位置信息获取所述执行计划的緩存位 置;
发送单元, 用于当所述位置信息指定所述执行计划的緩存位置为所述 客户端的緩存时, 所述数据库服务器将所述执行计划发送给所述客户端进 行保存。
1 9、 根据权利要求 1 8所述的执行计划的存储装置, 其特征在于, 所述接收单元, 还用于当所述客户端的緩存中存在所述 SQL请求对应 的执行计划时, 接收所述客户端发送的所述执行计划;
所述装置还包括:
执行单元, 用于执行所述接收单元接收的所述执行计划。
2 0、 根据权利要求 1 9所述的执行计划的存储装置, 其特征在于, 所述接收单元,还用于当所述客户端的緩存中存在所述 SQL请求对应的 多个执行计划时, 接收所述客户端发送的从所述多个执行计划中选择的任 意一个执行计划;
所述执行单元, 还用于执行所述接收单元接收的所述任意一个执行计 划。
2 1、 根据权利要求 1 9所述的执行计划的存储装置, 其特征在于, 所述接收单元,还用于当所述客户端的緩存中存在所述 SQL请求对应的 执行计划, 并且所述客户端通过图形化界面对所述执行计划进行参数调整 时, 接收所述客户端发送的调整后的执行计划;
所述执行单元, 还用于执行所述接收单元接收的所述调整后的执行计 划。
22、 根据权利要求 1 8所述的执行计划的存储装置, 其特征在于, 所述 装置还包括:
保存单元, 用于当所述位置信息指定所述执行计划的緩存位置为所述 数据库服务器的緩存时, 所述数据库服务器将所述执行计划保存在所述数 据库服务器的緩存中。
2 3、 一种执行计划的存储系统, 其特征在于, 包括: 至少一个客户端 和数据库服务器;
所述客户端, 用于接收结构化查询语言 S QL请求, 检测在所述客户端的 緩存中是否存在所述 S Q L请求对应的执行计划;
所述客户端,还用于当所述客户端的緩存中不存在所述 S QL请求对应的 执行计划时, 生成位置信息, 并且将所述位置信息及所述 S QL请求发送给所 述数据库服务器,所述位置信息用于指示与所述 S QL请求对应的执行计划的 緩存位置, 所述緩存位置为所述客户端的緩存和 /或数据库服务器的緩存; 所述数据库服务器, 用于接收客户端发送的所述位置信息及所述 S QL 请求, 并根据所述位置信息及所述 S QL请求, 获取所述 S QL请求对应的执行 计划;
所述数据库服务器, 还用于根据所述位置信息获取所述执行计划的緩 存位置, 当所述位置信息指定所述执行计划的緩存位置为所述客户端的緩 存时, 将所述执行计划发送给所述客户端进行保存。
PCT/CN2014/075520 2013-10-24 2014-04-16 执行计划的存储方法、装置及系统 WO2015058499A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP14856211.9A EP3054386B1 (en) 2013-10-24 2014-04-16 Execution plan storage method, device and system
US15/136,472 US20160239542A1 (en) 2013-10-24 2016-04-22 Method, Apparatus, and System for Storing Execution Plan

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201310507367.8A CN103577561B (zh) 2013-10-24 2013-10-24 执行计划的存储方法、装置及系统
CN201310507367.8 2013-10-24

Related Child Applications (1)

Application Number Title Priority Date Filing Date
US15/136,472 Continuation US20160239542A1 (en) 2013-10-24 2016-04-22 Method, Apparatus, and System for Storing Execution Plan

Publications (1)

Publication Number Publication Date
WO2015058499A1 true WO2015058499A1 (zh) 2015-04-30

Family

ID=50049337

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2014/075520 WO2015058499A1 (zh) 2013-10-24 2014-04-16 执行计划的存储方法、装置及系统

Country Status (4)

Country Link
US (1) US20160239542A1 (zh)
EP (1) EP3054386B1 (zh)
CN (1) CN103577561B (zh)
WO (1) WO2015058499A1 (zh)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103577561B (zh) * 2013-10-24 2017-12-01 华为技术有限公司 执行计划的存储方法、装置及系统
CN105590178A (zh) * 2014-10-21 2016-05-18 阿里巴巴集团控股有限公司 一种资源处理方法与设备
CN106294375B (zh) * 2015-05-15 2020-04-10 阿里巴巴集团控股有限公司 一种数据请求实时处理方法和装置
US10459889B2 (en) 2017-06-06 2019-10-29 Sap Se Multi-user database execution plan caching
JP7006013B2 (ja) * 2017-08-22 2022-01-24 富士通株式会社 データ提供プロラム、データ提供方法、及びデータ提供装置
CN110110003A (zh) * 2018-01-26 2019-08-09 广州中国科学院计算机网络信息中心 M2m平台的数据存储控制方法及装置
CN109918392B (zh) * 2018-12-15 2023-08-11 中国平安人寿保险股份有限公司 结构化查询语言定位方法、装置、服务器及存储介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101184106A (zh) * 2007-11-30 2008-05-21 北京航空航天大学 一种移动数据库的关联事务处理方法
CN101567006A (zh) * 2009-05-25 2009-10-28 中兴通讯股份有限公司 一种数据库系统及分布式sql语句执行计划重用方法
CN102081625A (zh) * 2009-11-30 2011-06-01 中国移动通信集团北京有限公司 一种数据查询的方法及查询服务器
CN103577561A (zh) * 2013-10-24 2014-02-12 华为技术有限公司 执行计划的存储方法、装置及系统

Family Cites Families (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6115703A (en) * 1998-05-11 2000-09-05 International Business Machines Corporation Two-level caching system for prepared SQL statements in a relational database management system
US6704724B1 (en) * 1999-12-14 2004-03-09 Ncr Corporation Parallel optimizer hints with a direct manipulation user interface
KR101083563B1 (ko) * 2009-04-24 2011-11-14 엔에이치엔비즈니스플랫폼 주식회사 데이터베이스 관리 방법 및 시스템
US8874547B2 (en) * 2010-01-04 2014-10-28 Microsoft Corporation Parameter-sensitive plans
US8996503B2 (en) * 2010-10-04 2015-03-31 Sybase, Inc. Query plan optimization for prepared SQL statements
US8832143B2 (en) * 2010-12-16 2014-09-09 Sybase, Inc. Client-side statement cache
US9298829B2 (en) * 2012-12-18 2016-03-29 International Business Machines Corporation Performing a function on rows of data determined from transitive relationships between columns

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101184106A (zh) * 2007-11-30 2008-05-21 北京航空航天大学 一种移动数据库的关联事务处理方法
CN101567006A (zh) * 2009-05-25 2009-10-28 中兴通讯股份有限公司 一种数据库系统及分布式sql语句执行计划重用方法
CN102081625A (zh) * 2009-11-30 2011-06-01 中国移动通信集团北京有限公司 一种数据查询的方法及查询服务器
CN103577561A (zh) * 2013-10-24 2014-02-12 华为技术有限公司 执行计划的存储方法、装置及系统

Also Published As

Publication number Publication date
EP3054386B1 (en) 2019-06-19
EP3054386A1 (en) 2016-08-10
EP3054386A4 (en) 2016-08-31
CN103577561B (zh) 2017-12-01
US20160239542A1 (en) 2016-08-18
CN103577561A (zh) 2014-02-12

Similar Documents

Publication Publication Date Title
WO2015058499A1 (zh) 执行计划的存储方法、装置及系统
EP3490224B1 (en) Data synchronization method and system
JP6745884B2 (ja) データ同期方法、装置及びシステム
WO2021042923A1 (zh) 数据分片存储方法、装置、终端及计算机可读存储介质
US10356194B2 (en) Method, system and client for uploading image, network server and computer storage medium
WO2018184491A1 (zh) 资源获取方法、装置及系统
CN107273540B (zh) 分布式搜索及索引更新方法、系统、服务器及计算机设备
US20200021652A1 (en) Method and device for synchronizing data, and electronic device
WO2019153488A1 (zh) 服务配置管理方法、装置、存储介质和服务器
US10534776B2 (en) Proximity grids for an in-memory data grid
KR20210130225A (ko) 서비스 요청 처리 방법 및 관련 디바이스
WO2023087769A1 (zh) 基于分布式流计算引擎Flink的关键字段实时去重方法
AU2017326373A1 (en) Prediction-based instant search
US20150019955A1 (en) Method and system for displaying literal contents, mobile terminal, cloud typesetting server, and storage medium
WO2014183634A1 (zh) 一种终端桌面展现方法、装置、终端及计算机存储介质
CN110764688A (zh) 对数据进行处理的方法和装置
US20130232208A1 (en) Method and device for updating messages
WO2021115485A1 (zh) 一种epg数据管理方法、服务器及可读存储介质
WO2019196225A1 (zh) 一种反馈资源文件的方法和装置
US9570112B2 (en) Multiple views recording
CN102594874A (zh) 一种同步处理方法和装置
US10616291B2 (en) Response caching
US10313469B2 (en) Method, apparatus and system for processing user generated content
US20120331099A1 (en) Information processing apparatus, information processing system, and program
US9374437B2 (en) Schema validation proxy

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: 14856211

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

REEP Request for entry into the european phase

Ref document number: 2014856211

Country of ref document: EP

WWE Wipo information: entry into national phase

Ref document number: 2014856211

Country of ref document: EP