The present invention relates to a data management technique.
In enterprise activities, utilization of a large amount of generated business data is indispensable. Therefore, a system that analyzes a database (hereinafter, “DB”) that stores a large amount of business data has already been devised.
In this analysis processing, a database management system (hereinafter, “DBMS”) receives a query and issues a data read request to a storage device that stores a DB.
As a technique of reducing latency for a data read in a processing for one query, a technique disclosed in PTL 1 is known. According to PTL 1, a DBMS generates a plan (hereinafter, “query execution plan”) which is a combination of a plurality of database operations (called DB operations or processing steps) necessary for executing a query, dynamically generates tasks for executing the processing steps, and concurrently executes the tasks to multiplex a data read request. For implementation of the task, according to PTL 1, any execution environment such as a process or thread managed by an OS or a pseudo process or pseudo thread implemented by an application or middleware can be used.
[PTL 1] Japanese Patent Application Publication No. 2007-34414
In the case where the number of data stored in a DB is several tens of thousands, there are cases where several tens of thousands of tasks are generated with respect to a processing for one query. When a task in such a case is implemented with a thread (or process), several tens of thousands of threads are generated. Since a thread is executed on an arbitrary processor core in a computer having a plurality of processor cores, an arbitrary processor core updates a management structure of a thread. Therefore, the overhead for management of thread execution increases. As a result, there is a problem that the execution time of the query is increased.
When a task is implemented with a pseudo thread (or pseudo process), the task is supposed to be implemented with one thread (or process). Since a management structure of a pseudo thread is updated by only one thread even if several tens of thousands of pseudo threads are generated, the management overhead is small. However, in the case where a computer has a plurality of processor cores, only one processor core is used, since there is one thread. Therefore, since only one processor core can be used in the case where many processing operations by a processor core are necessary in order to execute a processing step, there is a problem that the execution time of a query is increased.
Thus, an object of the present invention is to use a plurality of processor cores for a DBMS and reduce the management overhead of a thread.
The DBMS is realized by a computer including a processor core and manages a DB. The DBMS includes a query reception unit that receives a query to the DB, a query execution plan generation unit that generates a query execution plan including information representing a processing step necessary for executing the received query and an execution procedure of the processing step, and a query execution unit that executes the received query based on the generated query execution plan and, in an execution of the received query, dynamically generates a task for executing a processing step to execute the dynamically generated task.
The query execution unit, in an execution of the received query, executes a task in a plurality of threads executed by a processor core and executes a plurality of tasks in one thread executed by the processor core. For example, in the execution of a query, the query execution unit may dynamically generate a task for executing a database operation and execute the dynamically generated task. For example, in the execution of a query, the query execution unit may perform (a) generating a task for executing a database operation, (b) executing the generated task to issue a data read request to a database in order to read data necessary in the database operation corresponding to the task, (c) in the case of executing an (N+1)th database operation based on an execution result of an N-th database operation (N is an integer of 1 or greater) corresponding to the task executed in (b) described above, newly generating a task based on the execution result, and (d) performing of (b) and (c) for the newly generated task. In the case where two or more ready tasks exist in (b) and (d), at least two tasks out of the two or more tasks may be executed concurrently.
The query execution unit generates a context when newly generating a task, and executes the generated task based on the generated context. The context is information including first information showing a processing step for starting an execution in the newly generated task is which of one or more processing steps represented by the query execution plan, second information relating to an access destination for data required in a processing step shown by the first information, and third information relating to data necessary for generating a result by the newly generated task.
According to the present invention, a plurality of processor cores is used and the management overhead of a thread is reduced by executing a plurality of tasks by one thread and by executing the query by a plurality of threads As a result, the execution time of a query can be reduced.
First, the outline of Embodiment 1 will be described.
A DBMS 141 includes a client communication control unit 142, a query execution plan 143, a query execution unit 144, an execution task management unit 145, a thread management unit 146, and a DB buffer management unit 147. The query execution unit 144 includes a query execution plan execution unit 151, a context management unit 152, and a context sharing determination unit 153.
In the execution of a query, the DBMS 141 (query execution unit 144) dynamically generates a task for executing a processing step and executes the dynamically generated task. Specifically, in the execution of a query, for example, the DBMS 141 (query execution unit 144) performs (a) generating a task for executing a processing step, (b) executing the generated task to issue a data read request to a DB in order to read data necessary in the processing step corresponding to the task, (c) in the case of executing an (N+1)th processing step based on an execution result of an N-th processing step (N is an integer of 1 or greater) corresponding to the task executed in (b) described above, newly generating a task based on the execution result, and (d) performing of (b) described above and (c) described above for the newly generated task. In the case where two or more ready tasks exist in (b) and (d) described above, at least two tasks out of the two or more tasks can be executed concurrently.
Upon executing a task, the DBMS 141 (query execution unit 144) uses a plurality of threads (kernel threads) provided by an operating system (OS), and the plurality of threads are respectively executed by one or a plurality of processor cores included in one or a plurality of processors. By the processor core executing a thread, a task assigned to the thread is executed. Hereinafter, an expression such as a processor core executes a task or the DBMS 141 executes a task means executing a task assigned to the thread by executing the thread by a processor core.
The DBMS 141 receives a query via the client communication control unit 142. The query execution plan generation unit 143 generates a query execution plan PL for executing the received query. The query execution plan execution unit 151 executes the generated query execution plan PL. The thread management unit 146 manages a plurality of threads executed by a processor core of a processor in a computer in which the DBMS 141 is configured. The execution task management unit 145 manages a task executed with a thread. In this embodiment, the execution task management unit 145 can assign a plurality of tasks to one thread. Accordingly, the overhead required for management of a thread can be reduced.
The context management unit 152 manages a context used upon execution of a task. As a context, there are a context shared between threads that is managed to be usable from a plurality of threads and a context not shared between threads that is managed to be usable from only one thread. A thread that can use a context not shared between threads can use the context preferentially compared to other threads.
In an example in
Whether a context is to be shared between threads or not shared between threads is determined based on the result of determination by the context sharing determination unit 153. For example, the context sharing determination unit 153 may assume a context relating to a processing step at the start of a query execution plan to be a context shared between threads. In the case where a query execution plan is configured of a plurality of processing blocks concurrently executable, the context sharing determination unit 153 may assume a context relating to a first processing step of each processing block to be a context shared between threads. The context sharing determination unit 153 may assume a context relating to a processing step with a predetermined number or greater number of subsequent processing steps in one processing block to be a context shared between threads. A processing block may be configured of one or more processing steps. One example of a query execution plan configured of a plurality of processing blocks concurrently executable will be described later.
First, the thread management unit 146 generates thread #1, thread #2, and thread #3. It is possible to concurrently execute threads #1 to #3 with different processor cores, for example. The query execution plan execution unit 151 (specifically, one processor core) generates context #0 with which execution of a query is started and generates task #1. Context #0 is a context relating to processing step #1 at the start of a query execution plan and therefore is shared between threads. The query execution plan execution unit 151 assigns task #1 to thread #1. Thread #1 uses context #0 to execute task #1. When task #1 is executed, context #1 is generated, and task #2 and task #3 are generated. Context #1 is a context relating to processing step #1 at the start of the query execution plan and therefore is shared between threads. Thread #1 assigns task #2 to thread #2 and assigns task #3 to thread #3. Thread #2 uses context #1 to execute task #2. Thread #3 uses context #1 to execute task #3.
Thread #1 executes task #1 and executes an access processing for a DB. As a result, a new context is generated. For example, context #2 relating to processing step #3 is generated. The processing step of context #2 is not at the start of the query execution plan and therefore is not shared between threads. That is, context #2 is basically used by thread #1. Thread #1 generates and assigns, to thread #1, task #4. Thread #1 uses context #2 to execute task #4.
Thread #2 executes task #2 and executes an access processing for a DB. As a result, a new context is generated. For example, context #3 relating to processing step #3 is generated. The processing step of context #3 is not at the start of the query execution plan and therefore is not shared between threads. That is, context #3 is basically used by thread #2. Thread #2 generates and assigns, to thread #2, task #5 and task #6. Thread #2 uses context #3 to execute task #5. Further, thread #2 uses context #3 to execute task #6.
Thread #3 executes task #3 and executes an access process for a DB. As a result, a new context is generated. For example, context #4 relating to processing step #3 is generated. The processing step of context #4 is not at the start of the query execution plan and therefore is not shared between threads. That is, context #4 is basically used by thread #3. Thread #3 generates and assigns, to thread #3, task #7 and task #8. Thread #3 uses context #4 to execute task #7. Further, thread #3 uses context #4 to execute task #8.
In this manner, one thread executes a plurality of tasks, and a query is executed with a plurality of threads. As a result, the execution time of the query can be reduced, since a plurality of processor cores are used and the management overhead of a thread is reduced.
Embodiment 1 will be described in detail.
The computer system includes a computer 100 and an external storage apparatus 200. The computer 100 and the external storage apparatus 200 are connected via a communication network 300. As a protocol for communication via the communication network 300, FC (Fibre Channel), SCSI (Small Computer System Interface), IB (Infini Band), or TCP/IP (Transmission Control Protocol/Internet Protocol) may be employed, for example.
The computer 100 is, for example, a personal computer, a workstation, or a main frame. The computer 100 includes a network adapter 110, a processor (typically, microprocessor (e.g., CPU (Central Processing Unit)) 120, a local storage device 130, and a memory 140. The processor 120 executes a computer program, e.g., an OS (Operating System) that is not shown or the DBMS 141. One or multiple processors 120 include one or a plurality of processor cores. The respective processor cores are each capable of executing processing independently. A processor core has a cache with shorter access latency than the memory 140. A processor core holds, in a cache, data recorded in the memory 140 to perform processing of the data. In the case where one processor core processes the same data consecutively, the processing time is shorter compared to a case where different processor cores process the same data consecutively, since data held in a cache can be used. Basically, in this embodiment, each processor core can execute one thread (kernel thread) at a given time point. The memory 140 temporarily stores a program executed by the processor 120 and data used by the program. In this embodiment, the memory 140 stores the DBMS 141 as a program that performs management of a DB or a relevant processing sequence and data. The memory 141 may store an AP (Application Program) 148 for issuing a query to the DBMS 141. The local storage device 130 stores a program and data used by the program. The network adapter 110 connects the communication network 300 and the computer 100. The processor 120 may be a component included in a control device coupled to the network adapter 110, the memory 140, and the like. The control device may include, in addition to the processor 120, a dedicated hardware circuit (e.g., circuit that performs encryption and decryption of data).
In terms of performance and redundancy, the computer 100 may include a plurality of components, for at least one of the network adapter 110, the processor 120, the local storage device 130, and the memory 140. The computer 100 may include an input device (e.g., keyboard and pointing device) and a display device (e.g., liquid crystal display) that are not shown. The input device and the display device may be integrated.
In the computer 100, the DBMS 141 executes a query issued with respect to the DBMS 141. The query is issued by the AP 148 executed by the computer 100 or an AP executed by a computer (client) that is not shown and coupled to the communication network 300. The DBMS 141 executes a query issued by the AP 148 and, along with the execution of the query, transmits an I/O request with respect to a DB 206 stored in the external storage apparatus 200 to the external storage apparatus 200 via an OS. The OS may be an OS that runs on a virtual machine created and executed by a virtualization program.
The external storage apparatus 200 stores data used by the computer 100. The external storage apparatus 200 receives an I/O request from the computer 100, executes a processing corresponding to the I/O request, and transmits the processing result to the computer 100.
The external storage apparatus 200 includes a network adapter 201, a storage device group 203, and a controller 202 connected thereto.
The network adapter 201 connects the external storage apparatus 200 to the communication network 300.
The storage device group 203 includes one or more storage devices. A storage device is a non-volatile storage medium, e.g., a magnetic disk, a flash memory, or other semiconductor memories. The storage device group 203 may be a group storing data in a predetermined RAID level, according to RAID (Redundant Array of Independent Disks). A logical storage device (logical volume) based on a storage space in the storage device group 203 may be provided to the computer 100. The storage device group 203 stores the DB 206. The DB 206 includes one or more tables 204 or indexes 205. A table is a set of one or more records, and a record is configured of one or more columns. An index is a data structure that is intended and created for one or more columns within a table to increase the speed of access to a table with a selecting condition including a column for which the index is intended. For example, an index is a data structure holding, for each value of an intended column, information (Row ID) with which a record within a table including the value is identified. A B-tree structure or the like is used. The configuration example of a table of a DB and one example of the relationship of tables will be described later.
The controller 202 includes, for example, a memory and a processor. According to an I/O request from the computer 100, data is input to or output from the storage device group 203 storing the DB 206. For example, the controller 202 stores, in the storage device group 203, data of a write target according to a write request from the computer 100 or reads, from the storage device group 203, data of a read target according to a read request from the computer 100 to transmit the data to the computer 100.
The external storage apparatus 200 may include a plurality of components such as the controllers 202, in terms of ensuring performance and redundancy. Multiple external storage apparatuses 200 may be included.
The DBMS 141 manages the DB 206 including business data. The DBMS 141 includes the client communication control unit 142, the query execution plan generation unit 143, the query execution unit 144, the execution task management unit 145, the thread management unit 146, and the DB buffer management unit 147.
The client communication control unit 142 controls communication with a client coupled to the communication network 300 or the AP 148. Specifically, the client communication control unit 142 receives (accepts) a query issued from a client or the AP 148 and executes a processing of transmitting the processing result of the query to the client or the AP 148. The query is written in SQL (Structure Query Language), for example.
The query execution plan generation unit 143 generates a query execution plan including one or more processing steps necessary for executing a query received by the client communication control unit 142. A query execution plan is, for example, information in which the order of execution of processing steps to be performed upon execution of a query is defined with a tree structure, and is stored in the memory 140. One example of a query execution plan will be described later.
The DB buffer management unit 147 manages a storage area (DB buffer) for temporarily storing data within the DB 206. A DB buffer is configured in the memory 140. A DB buffer may be configured in the local storage device 130.
The query execution unit 144 executes a query according to a query execution plan generated by the query execution plan generation unit 143 and returns the generated result to an issue source of the query. The query execution unit 144 includes the query execution plan execution unit 151, the context management unit 152, and the context sharing determination unit 153.
The query execution plan execution unit 151 dynamically generates a task for executing a processing step within a query execution plan, assigns a task to a thread, and executes a query through execution of the task with the thread.
The context management unit 152 manages a context including information necessary in the execution of a generated task. A context is information including first information showing a processing step for starting execution in a task is which of one or more processing steps represented by a query execution plan, second information relating to an access destination for data required in the processing step shown by the first information, and third information relating to data necessary for generating a result with the task. The structure of the context management information that is information for managing a context will be described later.
The context sharing determination unit 153 determines whether or not a context is to be shared between a plurality of threads.
The execution task management unit 145 manages a task executed by a thread. A task is, for example, a pseudo process or pseudo thread (user-level thread) implemented by a DBMS 412. A task may be a set of pointers (function pointers) to a function in which each processing is summarized as a function. The structure of task management information that is information for managing a task will be described later.
The thread management unit 146 manages a thread for executing a query. A thread is a thread (kernel thread) provided an OS. As described above, a task assigned to a thread is executed by a processor core executing the thread that is assigned. A process may be used instead of a thread.
At least a part of processing performed by at least one processing unit of the client communication control unit 142, the query execution plan generation unit 143, the query execution unit 144, and the DB buffer management unit 147 may be performed with hardware. In the case where the processing unit is a subject in the description in this embodiment, processing is actually performed by the processor 120 that executes the processing unit. However, in the case where at least a part of the processing unit is realized by hardware, the hardware may be a subject instead of or in addition to the processor 120. A computer program that realizes the DBMS 141 may be installed in the computer 100 from a program source. A program source may be a storage medium readable by the computer 100 or may be another computer, for example.
The configuration of the DBMS 141 shown in
The DB 206 includes, for example, as Table 205 a Part table including column c1 and column c2 and a Lineitem table including column c3 and column c4. The DB 206 includes, as the index 204, an index (Part index) relating to the Part table based on the value of column c1 and an index (Lineitem index) relating to the Lineitem table based on the value of column c3.
The Part table of the DB 206 is logically a table in which the value of column c1 and the corresponding value of column c2 are associated, for example.
The Lineitem table of the DB 206 is a table in which the value of column c3 and the corresponding value of column c4 are associated, for example.
The Part index is, for example, in a B-tree structure to search for a page and slot of the Part table storing the corresponding value of column c2 based on the value of column c1. A page is the minimum data unit in the input and output with respect to the DB 206. In this embodiment, the Part index manages page P in a hierarchical structure. In the Part index, there are a leaf page that is a page at the lowest level and a higher-level page that is a page at a higher level than a leaf page. A page at the highest level among the higher-level pages is referred to as a root page.
The root page (page P1) of the Part index is provided with one or more entries in which a pointer with respect to a page on a level immediately below and the maximum value for the value of column c1 as a management target of the page on the level immediately below are associated. For example, page P1 stores a pointer to page P2 managing the correspondence relationship with respect to the value of column c1 that is less than or equal to “100,” a pointer to page P3 managing the correspondence relationship with respect to the value of column c1 that is greater than “100” and less than or equal to “200,” and a pointer to page P4 managing the correspondence relationship with respect to the value of column c1 that is greater than “200” and less than or equal to “300.” In a similar manner, a higher-level page is provided with one or more entries in which a pointer with respect to a page on a level immediately below each page and the maximum value for the value of column c1 managed in the page on the level immediately below are associated.
A leaf page stores one or more rows (records) in which the value of column c1 and the storage location (e.g., a page number of the Part table and a slot number within the page) in the Part table storing the value of column c2 corresponding to the value are associated.
For example, page P8 that is a leaf page stores a row including the number of a page and slot storing the value of column c2 corresponding to the value “110” of column c1 and a row including the number of a page and slot storing the value of column c2 corresponding to the value “130” of column c1. For example, as the row including the number of the page and slot storing the value of column c2 corresponding to the value “130” of column c1, rows showing slot 2 in page P100, slot 1 in page P120, and slot 4 in page P200 are stored. Thus, the values of column c2 corresponding to the value “130” of column c1 are “id131” from a record of slot 2 in page P100 of the Part table, “id132” from a record of slot 1 in page P120 of the Part table, and “id133” from a record of slot 4 in page 200 of the Part table.
The query shown in
The query execution plan shown in the figure shows a query execution plan generated by the query execution plan generation unit 143 in the case where the DBMS 141 has received the query shown in
As shown in
The task management information includes a main data structure 71. The main data structure 71 associates and stores, for each thread, thread identification information (e.g., thread number) with which a plurality of threads are identified and a pointer to a list management structure 72 with which a task executed by a thread is managed.
The list management structure 72 stores a ready list 72a for managing a ready task in a corresponding thread and a waiting list 72b for managing a task in a waiting state in a corresponding thread. The ready list 72a includes a pointer to execution state information (task execution state information) 73 relating to a ready task in a corresponding thread. The task execution state information 73 includes a pointer to the task execution state information 73 relating to another ready task in a correspond thread.
For example, in
In this embodiment, a ready list and a waiting list are managed for each thread. However, a ready list and a waiting list may be shared between a plurality of threads. A ready list and a waiting list may be managed for each processing step.
The task execution state information 73 stores a work area 73a, a processing step 73b, and a processing step execution state 73c. The work area 73a stores a pointer showing a work area. The processing step 73b stores information, e.g., a processing step number, with which a processing step executed by a corresponding task is identified. The processing step execution state 73c stores execution state information (processing step execution state information) 74 of a corresponding processing step. A specific example of the processing step execution state information 74 will be described later.
Processing step execution state information 74A includes a search condition 74a, a page number 74b, and a slot number 74c. The search condition 74a stores a search condition. In the example in the figure, the search condition 74a stores a range “115≦key≦195” for a key value that is a search condition included in a query. The page number 74b stores a number (page number) of a higher-level page used in processing of a task. The slot number 74c stores a number (slot number) of a slot in a page used in processing of a task.
Processing step execution state information 74B includes a search condition 74d, a page number 74e, a slot number 74f, and a processing row ID number 74g. The search condition 74d stores a search condition.
In the example in the figure, the search condition 74d stores a range “115≦key≦195” for a key value that is a search condition. The page number 74e stores a page number of a leaf page used in processing of a task. The slot number 74f stores a slot number of a slot in a page used in processing of a task. The processing row ID number 74g stores an ID number (processing row ID number) of a row within a slot processed with a corresponding task.
Processing step execution state information 74C includes a page number 74h and a slot number 74i. The page number 74h stores a page number of a page used in processing of a task. The slot number 74i stores a slot number of a slot in a page used in processing of a task.
Context management information 80 includes a main structure 81 of a management list and a plurality of contexts 82. The main structure 81 stores a pointer to the context 82. Each context 82 stores a pointer to another context 82. In this embodiment, a thread executing a task performs a lock in units of the respective contexts 82, in the case of using the context 82 in processing of the task. A context in a locked state cannot be used by another thread.
The context management information 80 stores search tables (thread specific search tables) 83, 84, 85, and the like corresponding to a thread executing a query. The thread #1 specific search table 83 manages a pointer to the context 82 available to thread #1. The thread #2 specific search table 84 manages a pointer to the context 82 available to thread #2. The thread #3 specific search table 85 manages a pointer to the context 82 available to thread #3.
The thread #1 specific search table 83 is a table managing a pointer to a context available to thread #1 and manages a list of pointers to contexts relating to respective processing steps. As shown in
The thread #2 specific search table 84 is a table managing a pointer to a context available to thread #2 and manages a list of pointers to contexts relating to respective processing steps. As shown in
The thread #3 specific search table 85 is a table managing a pointer to a context available to thread #3 and manages a list of pointers to contexts relating to respective processing steps. As shown in
According to the thread #1 specific search table 83, the thread #2 specific search table 84, and the thread #3 specific search table 85, context #1 is available to thread #1, thread #2, and thread #3. Context #2 is available to thread #1. Context #3 is available to thread #2, and context #4 is available to thread #3. A state where a pointer to the context 82 is registered in a plurality of thread specific search tables is referred to as the context being shared between threads, and a state where a pointer to a context is registered in one particular thread specific search table is referred to as the context being not shared between threads. A context that is available to a processor core executing a certain thread, through use of a thread specific search table specific to the thread, is referred to as a context available to the thread.
In this state, context #1 is used by thread #1, thread #2, or thread #3, context #2 is used by thread #1, context #3 is used by thread #2, and context #4 is used by thread #3. Since a context not shared between threads is used consecutively by one thread in this state, the processing time for processing along with context use can be reduced with a cache of a processor core.
In this embodiment, a thread specific search table specific to another thread may be referenced for the purpose of equalizing the amount of tasks executed by threads, in the case where available contexts are uneven between threads. Specifically, in the case where a context available to a thread is absent, a thread specific search table specific to another thread is referenced, so that another thread uses a context (context #2, context #3, or context #4) not shared between threads. For example, in the case where a context available to thread #1 has become absent in thread #1, thread #1 references the thread #2 specific search table or thread #3 specific search table, and context #3 or context #4 is used by a task assigned to thread #1.
The context 82 includes a starting step 82a, an intermediate result 82b, an execution state 82c, and a generable number 82d. The starting step 82a stores the number of a corresponding processing step. The intermediate result 82b stores a pointer showing a work area storing an intermediate result necessary for a task that executes a corresponding processing step. An intermediate result is acquired data that is necessary for generating a result of a query. The execution state 82c stores the execution state of a task in a corresponding processing step, e.g., information (e.g., a page number 820, a slot number 821, and a processing row ID number 822) with which the content of processing of a task to be executed next is identified. The page number 820 stores a page number of a leaf page used in processing of the next task. The slot number 821 stores a slot number in a page used in processing of the next task. The processing row ID number 822 stores an ID number (processing row ID number) of a row within a slot used in processing of the next task. The generable number 82d stores the number of tasks (task generable number) that can further be generated in a corresponding processing step. The task generable number is the number of processing operations under which no task generation is implemented within the number of logically branched processing operations. For example, in the case where the key value “130” is the condition for an index search with the Part index shown in
Upon acceptance of a query from the AP 148 (step S1) in the processing at the time of query acceptance, the client communication control unit 142 passes the received query to the query execution plan generation unit 143, and the query execution plan generation unit 143 executes a query execution plan generation processing (see
After execution of the query execution plan generation processing, the thread management unit 146 generates a thread (step S3). The number of threads to be generated may be any number and may be, for example, the same number as the number of processor cores of the processor 120. A processor core that runs a thread may be designated as a particular processor core for each thread. That is, a processor affinity may be set. For example, the setting may be such that the same number of threads as the number of processor cores are generated, and each processor core executes one of the threads. Accordingly, the efficiency of processing by each thread is high. As a method of generating a thread, there is a method of using an interface (function) of thread generation, specifically, pthread_create( ), provided by an OS.
Next, with the query execution plan execution unit 151, a context with which execution of a query is started is generated, and a task that performs processing using the context is generated and assigned to one of the threads (step S4). For example, a task is assigned to a thread created first by the thread management unit 146. Accordingly, thereafter, a processor core of the processor 120 executes the thread, and the task assigned to the thread is executed by the thread.
The query execution plan generation processing is a processing corresponding to step S2 of the processing at the time of query acceptance shown in
The inter-thread sharing flag setting processing is a processing corresponding to step S6 in the query execution plan generation processing shown in
The query execution plan generation unit 143 performs processing while moving a pointer in order to trace the query execution plan having a tree structure. The pointer is set to the first processing step in the query execution plan (step S11). Next, the query execution plan generation unit 143 determines whether or not a processing step pointed by the pointer in the query execution plan is present (step S12). In the case where a processing step pointed by the pointer is absent as a result (“absent” in step S12), it means that processing has been performed for all intended processing steps in the query execution plan. Therefore, the query execution plan generation unit 143 terminates the inter-thread sharing flag setting processing. In the case where a processing step pointed by the pointer is present as a processing step in the query execution plan (“present” in step S12), the query execution plan generation unit 143 determines whether or not the processing step is at the start of a processing block (step S13).
In the case where one or more processing steps that have to be executed sequentially in a query execution plan are divided into sets that can be executed concurrently, a processing block refers to the set. For example, the query execution plan shown in
The query execution plan shown in
Aside from such a query execution plan, a query execution plan corresponding to a query including, for example, a subquery or a derived table also includes a plurality of processing blocks.
Returning to the description of
In the case where the processing step is not at the start of the processing block as a result step S13 (“no” in step S13), the query execution plan generation unit 143 proceeds to a processing of step S15.
In step S15, the query execution plan generation unit 143 moves a pointer to the next processing step and proceeds to a processing of step S12.
In the inter-thread sharing flag setting processing shown in
The result transmission processing is started by the client communication control unit 142 after the client communication control unit 142 has received a query. The client communication control unit 142 checks the presence or absence of a result of the received query in the query execution unit 144 (step S21).
In the case where a result of the query is present as a result (“present” in step S21), the client communication control unit 142 acquires the result of the query from the query execution unit 144 (step S22) and transmits the result of the query with respect to the AP 148 that is the issue source of the query (step S26).
In the case where a result of the query is absent (“absent” in step S21), the client communication control unit 142 determines whether a query termination flag of the query execution unit 144 is “terminated” showing termination of the query or “not terminated” showing that the query is not terminated (step S23). In the case where the query termination flag is “terminated” as a result (“terminated” in step S23), NOROW (no corresponding row) is set in the result (step S24), and the result of the query is transmitted with respect to the AP 148 that is the issue source of the query (step S26).
In the case where the query termination flag of the query execution unit 144 is “not terminated” showing non-termination of the query (“not terminated” in step S23), the client communication control unit 142 waits a predetermined time for the query execution unit 144 to generate a result (step S25) and proceeds to a processing of step S21.
The thread execution processing is realized by a processor core of the processor 120 executing a thread generated in step S3 in
A processor core selects a task to be executed in a corresponding thread (step S31). Specifically, the processor core selects a task included in a ready list of a thread corresponding to task management information managed by the execution task management unit 145.
Next, the processor core determines the presence or absence of a task to be executed (step S32). In the case where a task to be executed is absent (“absent” in step S32), processing proceeds to step S34. In the case where a task to be executed is present (“present” in step S32), the task is started or the task is resumed (step S33). Specifically, the following processing is performed. The processor core selects one task included in the ready list. The processor core checks task execution state information of the selected task and starts the task or resumes the task. In the case where a processing step of the task execution state information is not set, processing of the task is started. Specifically, a task execution processing (see
In step S34, the processor core checks the presence or absence of another thread (step S34). In the case where another thread is absent (“absent” in step S34), termination is set in a query termination flag of the query execution unit 144 (step S35), and the thread execution processing is terminated. Accordingly, the thread is destroyed. In the case where another thread is present (“present” in step S34), the processor core terminates the thread execution processing. Accordingly, the thread is destroyed.
The task execution processing corresponds to a processing in the case where processing of a task is started in step S33 in
The processor core executes a context search processing (see
In the case where a context is present (“present” in step S37), the processor core sets the task execution state information 73 (see
The task execution state information 73 shown in
After step S38, the processor core executes a query execution plan execution processing (see
The context search processing is a processing corresponding to step S36 in
For example, in the case where the context search processing is executed with thread #1, thread #1 searches for a context with the thread #1 specific search table. Search by thread #1 is in order from processing step #4 to processing step #1 in the thread #1 specific search table. In the state of
In the context search processing described above, a thread specific search table specific to another thread is referenced to search for a context, in the case where a context is absent, i.e., in the case where there are zero contexts. However for example, a thread specific search table specific to another thread may be referenced to search for a context, in the case where there are less than or equal to a predetermined number of contexts.
With step S43 of the context search processing described above, unevenness in load between threads can be reduced based on the number of contexts available to respective threads. However, other than such a processing, there may be an adjustment by a light distribution thread shown in a modified example (see
The query execution plan execution processing corresponds to step S39 in
The processor core acquires a page in the DB 206 by executing a DB page fetch processing (see
In the case where data that matches the search condition is present (“true” in step S52), the processor core determines whether one piece or two or more pieces of data that match the search condition are present (step S53). In the case where one data that matches the search condition is present as a result (“one” in step S53), the processor core proceeds to a processing of step S55. In the case where two or more pieces of data that match the search condition are present (“two or more” in step S53), the processor core executes a new task addition processing (see
In step S55, the processor core executes a processing with respect to a page of a DB in a processing step by the task. A processing with respect to a page of a DB is, for example, a processing of reading a page number that matches the search condition for a higher-level page of an index, a processing of reading a row ID that matches the search condition for a leaf page, or a processing of reading a column of a record for page of a table.
Next, the processor core determines the next page of the DB and a processing with respect to the DB page (step S56) and proceeds to a processing of step S57.
In step S57, the processor core releases the acquired DB page. Next, in step S58, the processor core determines whether or not the next processing is present. Specifically, in the case where a processing step currently performed is completed and the next processing step is absent in a processing block including the processing step, it is determined as “absent.” In the case where the next processing step is present as a result (“present” in step S58), the processor core proceeds to a processing of step S51. In the case where the next processing is absent (“absent” in step S58), the processing result is passed to the query execution unit 144 (step S59), and the query execution plan execution processing is terminated.
Determination of the next DB page and the processing with respect to the DB page will be described with an example of a case where an index search of the Part table is performed with c1=130 as the search condition with respect to the DB 206 shown in
In the case where the index search is being started for the first time, the processor core determines a root page (page with the page number “P1”) of an index as the next DB page, determines a search processing within a higher-level page to search for a key of “130” with respect to the page as a processing with respect to the DB page, and starts the processing. The processor core reads page P1 in step S51 and searches for an entry including c1 “130” within the page P1 in step S52. One entry including c1 “200” is to be found. Therefore, in step S55 and step S56, a search processing within a higher-level page with respect to page P3 that is the next processing is determined as a processing with respect to a DB page. In step S51 to step S55, a processing with respect to page P3 is performed. The processor core reads page P3, searches for an entry including c1 “130” in the page P3, and finds a pointer to page P8 in the entry including c1 “130.” As a result, page P8 is determined as the next DB page, and a search processing within a leaf page with respect to the page P8 is determined as a processing with respect to a DB page.
In step S51 to step S53, the processor core reads page P8, searches for an entry including c1 “130” in the page P8, and finds the page “P100” of the Part table and the slot number “2.” Since there are three pieces of data that match the condition, the new task addition processing (step S54) is performed in order to perform processing of two pieces of data other than data processed in the task. In this embodiment, data processed in the task is assumed as first data, page P100 of the Part table is determined as the next DB page in step S56, and a processing of acquiring a record for the slot number 2 with respect to the page P100 is determined as a processing with respect to a DB page.
The DB page fetch processing corresponds to step S51 of the query execution plan execution processing (
The processor core searches for a buffer page (DB buffer page) corresponding to a DB page of a fetch target in the DB buffer management unit 147 (step S61) and checks the presence or absence of the corresponding DB buffer page (step S62).
In the case where the corresponding DB buffer page is present as a result (“present in step S62), the processor core determines whether or not reading of the page from the DB 206 is completed (step S63). In the case where reading is completed (“complete” in step S63), the DB page fetch processing is terminated. In the case where reading is not completed (“not complete” in step S63), processing proceeds to step S66.
In the case where the corresponding DB buffer page is absent (“absent” in step S62), the processor core acquires a free DB buffer page from the DB buffer management unit 147 (step S64), issues a DB page read request with respect to the DB 206 for reading the corresponding page into the free DB buffer page (step S65), and proceeds to a processing of step S66.
In step S66, the processor core waits for reading of the page to be completed. The processor core may employ a scheme of executing another processing even if reading of a page is not completed, i.e., asynchronous I/O, without employing a scheme of waiting until reading of a page is completed, i.e., synchronous I/O. For example, the processor core interrupts processing of a task being executed to cause a waiting state and reattaches task execution state information to a waiting list. Completion of reading of a corresponding page is checked by a different thread (or different task). In the case where the different thread (processor core executing the different thread) has checked completion of reading of the page, the task execution state information of the task may be reattached to a ready list to resume processing of the task.
In this manner, employing asynchronous I/O enables the processor core to perform execution of another task without waiting for completion of reading of the page and allows processing efficiency in the DBMS 141 to be improved. In the case where reading has been completed, the processor core terminates the DB page fetch processing.
The new task addition processing corresponds to step S54 of the query execution plan execution processing (
The processor core creates the context 82 based on data of a processing target (step S71). Next, the processor core executes a context sharing determination processing (see
Next, the processor core determines whether or not generating a new task is possible (step S74). Whether or not generating a new task is possible can be determined by, for example, determining whether or not the number of generated tasks in the DBMS 141 has reached an upper limit value of the number of tasks up to which generation is possible.
In the case where task generation is possible as a result (“possible” in step S74), the processor core executes a task generation processing (see
The context sharing determination processing corresponds to step S72 of the new task addition processing (
The processor core references an inter-thread sharing flag of a processing step relating to the generated context (step S81). In the case where the inter-thread sharing flag is set to the processing step as a result (“flag setting present” in step S81), it is determined by the processor core as inter-thread sharing in which the context is made available to a plurality of threads (step S82) and terminates the context sharing determination processing. In the case where the inter-thread sharing flag is not set to the processing step (“flag setting absent” in step S81), it is determined by the processor core as not inter-thread sharing in which the context is made available to one thread (step S83), and the context sharing determination processing is terminated.
In the context sharing determination processing, whether or not the generated context is to be shared between threads is determined based on the inter-thread sharing flag. However, this is not limiting. For example, the processor core may determine whether or not the generated context is to be shared between threads based on the execution state of the DBMS 141.
For example, as the execution state of the DBMS 141, the number of currently existing tasks of the DBMS 141 is employed. It may be such that the processor core determines the generated context is to be shared between threads in the case where the number of currently existing tasks is less than or equal to a predetermined number and determines the generated context to be not shared between threads in the case where the number of currently existing tasks is not less than or equal to the predetermined number.
It may be such that the intermediate result 82b included in a context is employed as the execution state of a DBMS, and the processor core determines the generated context is to be shared between threads in the case where the data volume of the intermediate result 82b included in the context is less than or equal to a predetermined volume and determines the generated context to be not shared between threads in the case where the data volume of the intermediate result 82b included in the context is not less than or equal to the predetermined volume.
The context registration processing corresponds to step S73 of the new task addition processing (
The processor core registers a created context in a management list of the context management information 80 (step S91). Specifically, the processor core connects the created context behind the last context coupled to the management list.
Next, the processor core checks the result of the context sharing determination processing (see
A case of registering a pointer to the context in a particular thread specific search table will be described. For example, a thread specific search table for registration is specified based on hardware configuration information of a computer. For the hardware configuration information, a processor configuration, a cache configuration, or a memory configuration is conceivable. For example, in a plurality of threads executed by a plurality of processor cores in one processor, registration is performed in a thread specific management table specific to a thread corresponding to the plurality of threads with the smallest total of the task generable number of an available context. In this embodiment, consider a situation where a processor core executing thread #2 and a processor core executing thread #3 are of the same processor, the processor differs from a processor executing thread #1, and a pointer to context #1 is registered in the thread specific search table of thread #2 and the thread specific search table of thread #3. In the case where new context #4 with respect to processing step #1 is generated, registration is performed in a search table specific to a thread thread executed by a processor core of the processor with fewer contexts. In this case, registration is performed in the thread specific search table of thread #1. In this example, registration is performed in one thread specific search table. However, in the case where a processor with a processor core executing thread #1 is also executing a thread that executes the DB access processing, registration is performed in a plurality of thread specific search tables.
Alternatively, registration may be performed in a thread specific management table specific to a thread corresponding to a plurality of threads corresponding to a processor including a processor core that has generated a context. In a plurality of threads executed by a plurality of processor cores in one processor, registration may be performed in a thread specific management table specific to a thread corresponding to the plurality of threads with a small total of available contexts. Registration may be performed in a thread specific management table of a plurality of threads executed by a processor core sharing a cache within a processor. Registration may be performed in a thread specific management table of a plurality of threads executed by a processor core close to a memory in which a context is recorded. Registration may be performed in a thread specific management table of a plurality of threads executed by a processor core close to a memory in which a DB buffer page referenced upon use of a context is recorded.
In the case where the result is not inter-thread sharing (“not shared” in step S92), the processor core registers a pointer to one thread specific search table and terminates the context registration processing. In this embodiment, a pointer to the created context is registered in a thread specific search table specific to a thread (one's own thread) executed by itself (step S94) and terminates the context registration processing. Alternatively, registration may be performed in a thread specific search table with the fewest available contexts, or registration may be performed in a thread specific search table with the smallest total of task generable number of an available context.
The task generation processing corresponds to step S75 of the new task addition processing (
Next, the processor core checks the result of the context sharing determination processing (see
In the case where the result is not inter-thread sharing (“not inter-thread sharing” in step S101), the processor core generates a task and assigns the task to one thread corresponding to a thread specific search table in which a pointer of a context is registered (step S103). The upper limit of the number of tasks to be generated is the generable number for a context. A thread to which a task is assigned may be one's own thread executed by the processor core or may be a thread other than one's own thread. After step S103, the processor core terminates the task generation processing.
Next, a modified example of this embodiment will be described.
In the embodiment described above, the query execution unit 144 may execute a load balance processing shown below.
The load balance processing is executed by the query execution unit 144 and is specifically realized by a processor core executing a thread (light distribution thread) other than a thread for performing a DB processing. The load balance processing is started after the client communication control unit 142 has received a query.
The processor core determines whether or not a query processing has been terminated (step S111). In the case where the query processing has been terminated (“terminated” in step S111), the load balance processing is terminated.
In the case where the query processing has not been terminated (“not terminated” in step S111), the processor core calculates the total of the task generable number in an available context from each thread specific search table (step S112).
Next, the processor core determines whether or not unevenness is present in the total of the task generable number up to which generation is possible by each thread (step S113). The processor core may determine that unevenness is present in the case where the task generable number is less than or equal to a predetermined number (e.g., zero), for example.
In the case where unevenness is absent in the total of the task generable number up to which generation is possible by each thread as a result (“absent” in step S113), processing proceeds to step S115.
In the case where unevenness is present in the total of the task generable number up to which generation is possible by each thread (“present” in step S113), the processor core reduces the unevenness in the total of the task generable number up to which generation is possible by each thread, by changing the position of a context, i.e., changing a thread specific search table storing a pointer with which a context is referenced to a different thread specific search table. Specifically, a pointer of a context made available by a thread specific search table specific to a thread with the largest total of the task generable number is registered in a thread specific search table specific to a thread with a small total of the task generable number. Then, the processor core proceeds to a processing of step S115.
In step S115, the processor core causes the load balance processing to sleep for a predetermined time and proceeds to a processing of step S111.
With the load balance processing, load with respect to respective threads can be distributed appropriately.
In the load balance processing described above, change of a thread that uses a context is performed based on unevenness in the total of the task generable number up to which generation is possible by each thread. However, it may be such that the load of a thread is kept track of and a thread that uses a context is changed based on the execution state relating to a thread, other than unevenness of the total of the task generable number. For example, it may be such that a cost calculation for each thread is performed, and a thread that uses a context is changed based on the cost. As an example of the cost calculation, the following value is conceivable. The cost of a context is assumed from the context as a product of the number of processing steps to be processed and the task generable number, and the total of cost of an available context is assumed from the thread as the cost of the thread.
The load balance processing may be executed by a thread for performing a DB processing. For example, execution may be at the time of termination of a thread (in the case where it is determined as “absent” in step S32) or at the time of termination of a task (in the case where it is determined as “absent” in step S37). In this case, the load balance processing is executed from step S112 to step S114.
Embodiment 2 will be described below. Differences from Embodiment 1 will be mainly described, and description on points common with Embodiment 1 will be omitted or simplified.
An application server (AP server) 3502 is connected, so as to be capable of communication via a communication network 3512, to the computer (hereinafter, DE server) 100 on which the DBMS 141 runs. The DB server 100 is coupled to the external storage apparatus 200 be capable of communication via the communication network 300. A user terminal (client terminal) 3501 is coupled to the AP server 3502 to be capable of communication via a communication network 3511. The DB server 100 executes the DBMS 141 that manages the DB 206. The external storage apparatus 200 stores the DB 206. The AP server 3502 executes an AP that issues a query with respect to the DBMS 141 executed by the DB server 100. The user terminal 3501 makes a request to an AP executed by the AP server 3502. Multiple user terminals 3501 or the AP servers 3502 may exist.
An AP server management terminal 3503 is coupled to the AP server 3502 via a communication network 3514. A DB server management terminal 3504 is coupled to the DB server 100 via a communication network 3515. A storage management terminal 3505 is coupled to the external storage apparatus 200 via a communication network 3516. The AP server management terminal 3503 is a terminal that manages the AP server 3502. The DB server management terminal 3504 is a terminal that manages the DB server 100. The storage management terminal 3505 is a terminal that manages the external storage apparatus 200. A DB server administrator or user may perform setting relating to the DBMS 141 from the DB server management terminal 3504. At least two of the management terminals 3503 to 3505 may be common (integrated). At least two of the communication networks 3511, 3512, 3514, 3515, 3516, and 300 may be common (integrated).
In Embodiment 2, processing is executed in the following manner, for example.
(S121) The user terminal 3501 issues a request (hereinafter, user request) to the AP server 3502.
(S122) The AP server 3502 generates a query according to the user request received in S121. The generated query is issued to the DB server 100.
(S123) The DB server 100 accepts the query from the AP server 3502 and executes the received query. The DB server 100 issues a data input-output request (e.g., data read request) necessary in the execution of the received query to the external storage apparatus 200. In the execution of one query, the DB server 100 may concurrently issue a plurality of data input-output requests. Therefore, the DB server 100 may concurrently perform a request of S123 a plurality of times in the execution of one query.
(S124) The external storage apparatus 200 responds to the DB server 100 regarding the data input-output request issued in S123. The external storage apparatus 200 may concurrently perform a response of S124 a plurality of times.
(S125) The DB server 100 generates and transmits, to the AP server 3502, an execution result of the query.
(S126) The AP server 3502 transmits the execution result of the query. A reply with respect to the user request received in S121 according to the execution result is transmitted to the user terminal 3501.
There may be a plurality of simultaneous user requests issued to the AP server 3502 or queries issued to the DB server.
The descriptions above are based on the embodiments. However, the present invention is not limited to the embodiments described above, and applications to other various forms are possible.
Filing Document | Filing Date | Country | Kind | 371c Date |
---|---|---|---|---|
PCT/JP2012/061436 | 4/27/2012 | WO | 00 | 11/7/2014 |