A method and apparatus for processing a database transaction
By compiling database transactions and dynamically adjusting processor resources, the problem of low processor utilization in database management systems is solved, thereby improving processing efficiency and resource utilization.
Patent Information
- Application Number
- CN202210053151.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-18
- Publication Date
- 2025-12-09
- Estimated Expiration
- 2042-01-18
AI Technical Summary
Existing database management systems suffer from performance bottlenecks when processing database transactions, resulting in low processor utilization and difficulty in fully leveraging the processor's powerful processing capabilities.
The database transactions to be processed are compiled to generate executable code or intermediate code, and the compilation results are executed directly during execution. Computational resources are allocated to dynamically adjust the number of processor cores, compilation results are stored in a cache queue, and compilation templates are used to improve compilation efficiency.
It improves the processing efficiency of the database management system, increases processor utilization, optimizes the dynamic balance of computing resources, and reduces data access conflicts and compilation costs.
Smart Images

Figure CN114721786B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of database, and in particular, to a database transaction processing method and device. BACKGROUND
[0002] The database transaction processing can be implemented by a processor. With the development of computer architecture and processor manufacturing process, the processing capability of the processor is rapidly increasing, mainly reflected in the increase of the number of processor cores and hardware threads of the processor. Obviously, the ability of the processor to process database transactions is also increasing.
[0003] However, when the database management system processes the database transaction, a performance bottleneck often occurs. Although the processor provides strong processing capability, it is difficult to fully utilize. Therefore, the current utilization rate of the processor is low, which is a problem to be solved. SUMMARY
[0004] The present application provides a database transaction processing method and device for improving the utilization rate of the processor.
[0005] In a first aspect, the present application provides a database transaction processing method, which can be executed by a database transaction processing device provided by the present application. The database transaction processing device can be an electronic device provided by the present application. The method comprises:
[0006] Obtaining a database transaction to be processed; compiling the database transaction to be processed to obtain a compilation result of the database transaction to be processed, wherein the compilation result comprises executable code or intermediate code, and the intermediate code is used for compiling the executable code; and executing the compilation result of the database transaction to be processed.
[0007] In the above manner, the database transaction to be processed can be pre-compiled based on the compilation of the database transaction to be processed to obtain the compilation result of the database transaction to be processed, and the compilation result comprises executable code or intermediate code, and the intermediate code is used for compiling the executable code. Therefore, the database transaction to be processed does not need to be tightly coupled with the execution of the database transaction, and the compilation result of the database transaction to be processed can be directly executed when the database transaction to be processed is executed. Thus, the processing efficiency of the database management system for the transaction is improved, and the utilization rate of the processor is improved.
[0008] In a possible design, the execution of the compilation result of the database transaction to be processed comprises:
[0009] The execution of the compilation result of the database transaction to be processed is based on a transaction compilation engine (such as a main memory OLTP engine) of the database management system.
[0010] In a possible design, if the estimated execution duration of the to-be-processed database transaction is greater than a preset duration and / or the frequency at which database transactions of the same type as the to-be-processed database transaction have been compiled is greater than a preset frequency, the compilation result of the to-be-processed database transaction is the executable code; otherwise, the compilation result of the to-be-processed database transaction is the intermediate code.
[0011] In a possible design, the compiling the to-be-processed database transaction comprises:
[0012] The plurality of to-be-processed database transactions are compiled into executable code, or are compiled into intermediate code, or part of the plurality of to-be-processed database transactions are compiled into executable code and part of the plurality of to-be-processed database transactions are compiled into intermediate code.
[0013] In the above manner, for the plurality of to-be-processed database transactions, all the to-be-processed database transactions can be compiled into executable code or into intermediate code, or part of the to-be-processed database transactions are compiled into executable code and part of the to-be-processed database transactions are compiled into intermediate code, thereby increasing the flexibility of compiling the plurality of database transactions.
[0014] In a possible design, the plurality of to-be-processed database transactions include a first database transaction and a second database transaction, and the first database transaction and the second database transaction require access to the same data access information, and the method further comprises:
[0015] The data access information required by the first database transaction and the second database transaction for access is duplicated to obtain first data access information and second data access information;
[0016] The plurality of to-be-processed database transactions are compiled in parallel, comprising:
[0017] The first database transaction is compiled according to the first data access information, and the second database transaction is compiled in parallel according to the second data access information.
[0018] In the above manner, by duplicating the data access information required by the first database transaction and the second database transaction for access, and then compiling the two database transactions according to the two pieces of data access information respectively, the access conflict of the data access information is avoided, and complex operations such as data locking are not required.
[0019] In a possible design, the compiling of the to-be-processed database transaction comprises: compiling the to-be-processed database transaction based on a first computing resource; and the executing of the compiled result of the to-be-processed database transaction comprises: executing the compiled result of the to-be-processed database transaction based on a second computing resource; wherein the first computing resource and the second computing resource each comprise at least one processor core, and the processor cores comprised by the first computing resource and the second computing resource belong to a same processor.
[0020] In the above manner, by allocating computing resources to the transaction compiling stage and the transaction executing stage respectively, dynamic utilization of computing resources can be implemented, so that computing resources can be independently utilized in the case of separation of the transaction compiling and the transaction executing.
[0021] In a possible design, the operations of compiling are counted to obtain transaction compiling statistical information; the number of processor cores comprised in the first computing resource and / or the second computing resource is adjusted according to the transaction compiling statistical information; or the operations of executing are counted to obtain transaction executing statistical information; the number of processor cores comprised in the first computing resource and / or the second computing resource is adjusted according to the transaction executing statistical information; or the operations of compiling are counted to obtain transaction compiling statistical information, the operations of executing are counted to obtain transaction executing statistical information; and the number of processor cores comprised in the first computing resource and / or the second computing resource is adjusted according to the transaction compiling statistical information and the transaction executing statistical information.
[0022] In the above manner, by counting the operations of compiling to obtain transaction compiling statistical information and / or counting the operations of executing to obtain transaction executing statistical information, the number of processor cores comprised in the first computing resource and / or the second computing resource can be adjusted according to the transaction compiling statistical information and / or the transaction executing statistical information, so that the first computing resource and the second computing resource can be coordinated with each other, and the processor cores can be more reasonably utilized.
[0023] In a possible design, the transaction compiling statistical information comprises a compiling frequency of the operations of compiling, and the transaction executing statistical information comprises a frequency of occurrence of conflicts of the operations of executing; and the adjusting of the number of processor cores comprised in the first computing resource and / or the second computing resource according to the transaction compiling statistical information comprises:
[0024] if the compiling frequency of the operations of compiling in the transaction compiling statistical information is greater than a first threshold value, the number of processor cores in the first computing resource is reduced and / or the number of processor cores in the second computing resource is increased;
[0025] The adjusting the number of processor cores included in the first computing resource and / or the second computing resource according to the transaction execution statistical information comprises:
[0026] If the frequency of the executed operations in the transaction execution statistical information is greater than the second threshold value, the number of processor cores in the first computing resource is reduced, and / or the number of processor cores in the second computing resource is reduced.
[0027] The adjusting the number of processor cores included in the first computing resource and / or the second computing resource according to the transaction compilation statistical information and the transaction execution statistical information comprises:
[0028] If the compilation frequency of the compiled operations in the transaction compilation statistical information is greater than the first threshold value, and the frequency of the executed operations in the transaction execution statistical information is less than the second threshold value, the number of processor cores in the first computing resource is reduced, and / or the number of processor cores in the second computing resource is increased.
[0029] In the above manner, if the compilation frequency of the compiled operations in the transaction compilation statistical information is greater than the first threshold value, it indicates that there are more compilation results, which may cause the execution load of the database transaction to be larger, and if the frequency of the executed operations in the transaction execution statistical information is less than the second threshold value, it indicates that there are fewer compilation results, and the upper limit of the database transaction execution has not been fully utilized, so the number of processor cores in the first computing resource can be reduced, and / or the number of processor cores in the second computing resource can be increased, thereby further more reasonably maintaining the dynamic balance of the computing resources.
[0030] In a possible design, after the compiling the to-be-processed database transaction to obtain the compilation result of the to-be-processed database transaction, the method further comprises: storing the compilation result of the to-be-processed database transaction in a cache queue.
[0031] The executing the compilation result of the to-be-processed database transaction comprises:
[0032] The method further comprises: obtaining the compilation result of the to-be-processed database transaction from the cache queue, and executing the obtained compilation result of the to-be-processed database transaction.
[0033] In the above manner, the compilation result of the to-be-processed database transaction is stored in the cache queue, and the compilation result of the to-be-processed database transaction is obtained from the cache queue and executed, so that the compilation results of multiple to-be-processed database transactions can be cached, thereby enabling the compilation results of the multiple to-be-processed database transactions to be uniformly waited for execution through the cache queue.
[0034] In a possible design, the method further includes:
[0035] statistics are collected on the number and / or latency of the compiled results of the database transactions in the cache queue, to obtain queuing statistics; and the number of processor cores included in the first computing resource and / or the second computing resource is adjusted according to the queuing statistics.
[0036] In the above manner, because the queuing statistics can represent the situation of the compiled results of the database transactions, the number of processor cores included in the first computing resource and / or the second computing resource can be adjusted based on the queuing statistics, so that the computing resources are kept in dynamic balance.
[0037] In a possible design, the adjusting includes:
[0038] If the number of the compiled results of the database transactions in the cache queue is greater than a third threshold, and / or the latency of the database transactions in the cache queue is greater than a fourth threshold, the number of processor cores included in the first computing resource is reduced, and / or the number of processor cores included in the second computing resource is increased.
[0039] In the above manner, if the number of the compiled results of the database transactions in the cache queue is greater than the third threshold, and / or the latency of the database transactions in the cache queue is greater than the fourth threshold, it means that the compiled results of the database transactions increase too fast, so the number of processor cores included in the first computing resource can be reduced, and / or the number of processor cores included in the second computing resource can be increased, to keep the first computing resource and the second computing resource in dynamic balance.
[0040] In a possible design, the compiling includes:
[0041] A compiling template matching the database transaction to be processed is obtained according to an SQL (Structured Query Language) statement included in the database transaction to be processed, and the database transaction to be processed is compiled according to the compiling template.
[0042] In the above manner, the database transaction to be processed can be compiled based on the existing compiling template by preconfiguring the compiling template for the database transaction to be processed, so that the compiling efficiency of the database transaction to be processed is improved.
[0043] In a possible design, the obtaining includes:
[0044] If the type of all SQL statements included in the database transaction to be processed is the same as the type of all SQL statements corresponding to the first transaction type template, the first transaction type template is determined as the compiled template matched with the database transaction to be processed; otherwise, if the type of the first SQL statement included in the database transaction to be processed is the same as the type of the SQL statement corresponding to the first SQL statement template, the first SQL statement template is determined as the compiled template matched with the database transaction to be processed; wherein the first SQL statement is any one of all SQL statements included in the database transaction to be processed.
[0045] In the above manner, when the type of all SQL statements included in the database transaction to be processed is the same as the type of all SQL statements in the first transaction type template, the database transaction to be processed is compiled according to the SQL statement template of the same type, so that the cost of database transaction compilation can be minimized and the compilation efficiency of the database transaction can be improved.
[0046] The compiling the database transaction to be processed according to the compiled template comprises:
[0047] The executable code corresponding to the compiled template is obtained, the executable code corresponding to the compiled template includes a variable to be replaced; a parameter matching the variable in the database transaction to be processed is obtained, and the variable in the executable code corresponding to the compiled template is replaced with the parameter.
[0048] In the above manner, the code of the non-common language element in the database transaction to be processed is filled into the executable code corresponding to the compiled template to form the compilation result of the database transaction to be processed, so that only the non-common language element needs to be compiled, the compilation of the code of the common language element is avoided, and the compilation efficiency of the database transaction to be processed is improved.
[0049] In a possible design, the compiled template that is not matched with the database transaction within a set period of time is released; and / or the compiled template is stored in a processor, and if the memory occupied by the compiled templates in the processor is greater than a memory threshold, the compiled templates in the processor are released.
[0050] In a second aspect, the present application provides a database transaction processing apparatus, comprising:
[0051] The compiling module is configured to obtain a database transaction to be processed.
[0052] The compiling module is further configured to compile the to-be-processed database transaction, to obtain a compiling result of the to-be-processed database transaction, wherein the compiling result comprises executable code or intermediate code, and the intermediate code is used for compiling the executable code.
[0053] The execution module is configured to execute the compiling result of the to-be-processed database transaction.
[0054] In a possible design, the compiling module is specifically configured to:
[0055] compile the plurality of to-be-processed database transactions in parallel, wherein the plurality of to-be-processed database transactions are compiled into executable code, or are compiled into intermediate code, or part of the plurality of to-be-processed database transactions are compiled into executable code, and part of the plurality of to-be-processed database transactions are compiled into intermediate code.
[0056] In a possible design, the plurality of to-be-processed database transactions comprise a first database transaction and a second database transaction, the first database transaction and the second database transaction have the same data access information required for compiling, and the apparatus further comprises a scheduling module, which is configured to:
[0057] copy the data access information required for compiling the first database transaction and the second database transaction into two copies, to obtain first data access information and second data access information;
[0058] The compiling module is specifically configured to:
[0059] compile the first database transaction according to the first data access information, and compile the second database transaction according to the second data access information in parallel.
[0060] In a possible design, the compiling module is specifically configured to:
[0061] compile the to-be-processed database transaction based on a first computing resource;
[0062] The execution module is specifically configured to:
[0063] execute the compiling result of the to-be-processed database transaction based on a second computing resource.
[0064] The first computing resource and the second computing resource each comprise at least one processor core, and the processor cores comprised by the first computing resource and the second computing resource belong to a same processor.
[0065] In a possible design, the apparatus further comprises a scheduling module, which is further configured to:
[0066] counting the compiled operations to obtain transaction compilation statistics information; adjusting the number of processor cores included in the first computing resource and / or the second computing resource according to the transaction compilation statistics information; or
[0067] counting the executed operations to obtain transaction execution statistics information; adjusting the number of processor cores included in the first computing resource and / or the second computing resource according to the transaction execution statistics information; or
[0068] counting the compiled operations to obtain transaction compilation statistics information, and counting the executed operations to obtain transaction execution statistics information; adjusting the number of processor cores included in the first computing resource and / or the second computing resource according to the transaction compilation statistics information and the transaction execution statistics information.
[0069] In a possible design, the transaction compilation statistics information includes a compilation frequency of the compiled operations, and the transaction execution statistics information includes a conflict frequency of the executed operations; and the scheduling module is specifically configured to:
[0070] if the compilation frequency of the compiled operations in the transaction compilation statistics information is greater than a first threshold, reducing the number of processor cores in the first computing resource and / or increasing the number of processor cores in the second computing resource;
[0071] if the conflict frequency of the executed operations in the transaction execution statistics information is greater than a second threshold, reducing the number of processor cores in the first computing resource and / or reducing the number of processor cores in the second computing resource;
[0072] if the compilation frequency of the compiled operations in the transaction compilation statistics information is greater than the first threshold and the conflict frequency of the executed operations in the transaction execution statistics information is less than the second threshold, reducing the number of processor cores in the first computing resource and / or increasing the number of processor cores in the second computing resource.
[0073] In a possible design, the apparatus further includes a scheduling module, where the scheduling module is configured to:
[0074] storing the compilation result of the to-be-processed database transaction into a cache queue;
[0075] The execution module is specifically configured to:
[0076] obtain the compilation result of the to-be-processed database transaction from the cache queue, and execute the obtained compilation result of the to-be-processed database transaction.
[0077] In a possible design, the scheduling module is further configured to:
[0078] statistic the number and / or latency of the compilation results of the database transactions in the cache queue to obtain queuing statistic information; and adjust the number of processor cores included in the first computing resource and / or the second computing resource according to the queuing statistic information.
[0079] In a possible design, the scheduling module is specifically configured to:
[0080] If the number of the compilation results of the database transactions in the cache queue is greater than a third threshold value and / or the latency of the database transactions in the cache queue is greater than a fourth threshold value, the number of processor cores included in the first computing resource is reduced and / or the number of processor cores included in the second computing resource is increased.
[0081] In a possible design, the compiling module is specifically configured to:
[0082] obtain a compilation template matched with the database transaction to be processed according to a structured query language (SQL) statement included in the database transaction to be processed; and compile the database transaction to be processed according to the compilation template.
[0083] In a possible design, the compiling module is specifically configured to:
[0084] If the type of all SQL statements included in the database transaction to be processed is the same as the type of all SQL statements corresponding to a first transaction type template, the first transaction type template is determined as the compilation template matched with the database transaction to be processed.
[0085] Otherwise, if the type of a first SQL statement included in the database transaction to be processed is the same as the type of a first SQL statement template, the first SQL statement template is determined as the compilation template matched with the database transaction to be processed, where the first SQL statement is any one of all SQL statements included in the database transaction to be processed.
[0086] In a possible design, the compiling module is specifically configured to:
[0087] obtain executable code corresponding to the compilation template, where the executable code corresponding to the compilation template includes a variable to be replaced;
[0088] obtain a parameter included in the database transaction to be processed and matched with the variable, and replace the variable in the executable code corresponding to the compilation template with the parameter.
[0089] In a third aspect, an electronic device is provided, and the electronic device includes one or more processors, one or more memories, wherein the one or more memories store one or more computer instructions, and when the one or more computer instructions are executed by the one or more processors, the electronic device is caused to perform the method according to any one of the first aspect.
[0090] In a fourth aspect, a computer-readable storage medium is provided, and the computer-readable storage medium includes computer instructions, and when the computer instructions are run on a computer, the computer is caused to perform the method according to any one of the first aspect.
[0091] The beneficial effects of the second aspect to the fourth aspect above can refer to the beneficial effects of the first aspect, and will not be repeated. BRIEF DESCRIPTION OF DRAWINGS
[0092] Figure 1 An architecture schematic diagram of a single-machine database system to which a database transaction processing method provided by an embodiment of the present application can be applied;
[0093] Figures 2a-2b An architecture schematic diagram to which a database transaction processing method provided by an embodiment of the present application can be applied;
[0094] Figure 3 A structure schematic diagram of an execution plan in a database transaction processing method provided by an embodiment of the present application;
[0095] Figure 4 A flow schematic diagram of a database transaction processing method provided by an embodiment of the present application;
[0096] Figure 5 A structure schematic diagram of a database transaction processing device provided by an embodiment of the present application;
[0097] Figure 6 A structure schematic diagram of an electronic device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0098] The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application.
[0099] The terminology used in the following description merely for the purpose of describing particular embodiments and is not intended to limit the application. As used in this description and the appended claims, the singular forms "a," "an" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will also be understood that the term "or" as used herein refers to a non-exclusive "or," unless otherwise indicated. Also, the use of "about" to modify a citation in the description means that the citation is accurate to within ±10% of the given value, unless otherwise indicated.
[0100] Reference throughout this specification to "one embodiment" or "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment is included in at least one embodiment of the application. Thus, the appearances of the phrases "in one embodiment" or "in an embodiment" or "in other embodiments" or "in still other embodiments" or "in yet other embodiments" in various places throughout this specification are not necessarily all referring to the same embodiment, unless otherwise indicated. The terms "including," "containing," "having," and variations thereof, are meant to encompass the terms "including but not limited to," unless otherwise indicated.
[0101] The term "plurality" in the embodiments of the present application means two or more, and in view of this, "plurality" in the embodiments of the present application can also be understood as "at least two". "At least one" can be understood as one or more, for example, as one, two or more. For example, including at least one means including one, two or more, and does not limit which ones are included. For example, including at least one of A, B and C means that A, B, C, A and B, A and C, B and C, or A and B and C can be included. Similarly, the understanding of "at least one" and the like descriptions is also similar. "And / or" describes the association relationship of the associated objects, and means that there can be three relationships, for example, A and / or B can mean that A exists alone, A and B exist together, and B exists alone. In addition, the character " / ", unless otherwise specified, generally represents that the associated objects before and after are in an "or" relationship.
[0102] Unless otherwise indicated, the ordinal numbers "first", "second", etc. used in the embodiments of the present application are used to distinguish a plurality of objects, and are not used to limit the order, time sequence, priority or importance of the plurality of objects.
[0103] For the convenience of understanding, the terms related to the embodiments of the present application are explained and described, and the explanation and description of the terms are also part of the content of the embodiments of the present application.
[0104] Application scenarios
[0105] The database transaction processing method provided by the embodiments of the present application can be applied to a single-database system or a cluster database system. A database system is a relatively ideal data processing system developed to meet the needs of data processing. The database system generally consists of the following three parts: (1) a database (database, DB), which refers to a collection of organized and shareable data stored in a computer for a long time. The data in the database is organized, described and stored according to a certain mathematical model, has a small redundancy, a high data independence and an easy scalability, and can be shared by various users. (2) hardware, including data storage devices required for storing data, such as memory and / or disk. (3) software, including a database management system (DBMS), which is the core software of the database system, is a system software for scientifically organizing and storing data, and efficiently obtaining and maintaining data, and the database engine is the core content of the DBMS.
[0106] Specifically, taking a single-database system as an example, as shown in Figure 1As shown, a single-machine database system includes a DBMS and a data store. The DBMS provides services such as database querying and modification, and stores data in the data store. In a single-machine database system, the DBMS and data store typically reside on a single database server, which includes one or more processors. For example, the database server can be a symmetric multi-processor (SMP) server. This SMP server includes multiple processors, all of which share resources such as the bus, memory, and I / O system. The functions of the database management system can be implemented by one or more processors executing programs in memory. Alternatively, the DBMS and data store can reside on a uniprocessor server. The functions of the DBMS can be implemented by only one processor executing programs in memory. It should be noted that the processor used to implement the DBMS functions can be either a single-core processor or a multi-core processor. For example, a multi-core processor can be a many-core processor. A multi-core processor includes multiple cores, which can be referred to as processor cores in this application.
[0107] In embodiments of this application, the data storage of the database system includes, but is not limited to, solid-state drives (SSDs), disk arrays, or other types of non-transient computer-readable media. Figure 1 Although a database is not shown, it should be understood that the database is stored in a data storage device. Those skilled in the art will understand that a database system may include more than […]. Figure 1 The components shown are fewer or more components, or include those with Figure 1 The components shown are different components. Figure 1 Only components more relevant to the implementation disclosed in the embodiments of the present invention are shown.
[0108] For ease of understanding and description, and as an example rather than a limitation, the following description uses a database server in a single-machine database system as an example to illustrate the solution of the embodiments of the present invention. Those skilled in the art will clearly understand from the embodiments of this application that the methods of the embodiments of the present invention can also be applied to clustered database systems, as well as any type of relational database system.
[0109] like Figure 2a As shown in the diagram, an architecture diagram of a database transaction processing method provided in this application embodiment is applicable. The architecture includes a database client 10, a database server 20, and a data storage 30, which can be specifically as follows:
[0110] The database client 10 is configured to generate database transactions, and send the database transactions to the database management system 23, and obtain the processing results of the database transactions returned by the database management system 23. The database client 10 can include any type of device or application configured to interact with the database server 20. In some examples, the database client 10 includes one or more application servers.
[0111] The database server 20 can include at least one processor 21, a non-transitory computer-readable medium 22 storing executable code, and a database management system 23. The executable code, when executed by the at least one processor 21, is configured to implement components and functions of the database management system 23. The non-transitory computer-readable medium 22 can include one or more non-volatile memories, which can include, as examples, semiconductor memories, such as erasable programmable read only memory (EPROM), electrically erasable programmable read only memory (EEPROM), and flash memory; non-volatile memories, which can include magnetic disks, such as internal hard disks or removable disks, magneto optical disks, and CD ROM and DVD-ROM. In addition, the non-transitory computer-readable medium 22 can also include any device configured to function as a main memory. The at least one processor 21 can include any type of general purpose computing circuit or special purpose logic circuit, such as a field programmable gate array (FPGA) or an application specific integrated circuit (ASIC). The at least one processor 21 can be one or more processors coupled to one or more semiconductor substrates, such as a central processing unit (CPU). It should be noted that the at least one processor 21 has a core (which can also be referred to as a processor core), and the core can form a core set to provide computing resources for the database management system 23 to process database transactions.
[0112] The database management system 23 can be a relational database management system (RDBMS), and the data processing type of the database management system 23 can be on-line transaction processing (OLTP). The database management system 23 supports structured query language (SQL), and a database transaction processed by the database management system 23 can include one SQL statement or multiple SQL statements. Generally, SQL refers to a special-purpose programming language that is specifically used to manage data saved in a relational database. SQL can refer to various types of data-related languages, including, for example, data definition languages and data manipulation languages, where the scope of SQL can include data insertion, query, update, and deletion, schema creation and modification, and data access control. Taking an SQL query as an example, in some examples, SQL can include descriptions related to various language elements, such as language elements can be clauses, expressions, predicates, queries, and statements. For example, a clause can refer to various components of a statement and a query, and in some cases, a clause can be considered optional. In addition, an expression can be configured to produce a scalar value and / or a table including data columns and / or rows. Further, a predicate can be configured to specify a condition for regulating the effect of a statement and a query.
[0113] Taking a database transaction as an example of an SQL query statement, a query is a request to view, access, and / or manipulate data stored in a database. The database management system 23 can receive a query in SQL format (referred to as an SQL query statement) from the database client 10. Generally, the database management system 23 generates a query result corresponding to the query by accessing relevant data from the database and manipulating the relevant data, and returns the query result to the database client 10. A database is a collection of data organized, described, and stored in a certain mathematical model, and the database can include one or more database structures or formats, such as row storage and column storage. The database can be stored in a data storage, such as an external data storage 30 or a non-transitory computer readable medium 22. When the database is stored in the non-transitory computer readable medium 22, the database management system 23 is a memory database management system. Figure 2a
[0114] The database management system 23 includes a transaction compiling engine 231, a cache queue 232, a transaction executing engine 233, a storage engine 234, and a core scheduler 235. The transaction compiling engine 231 can be a main memory OLTP engine.
[0115] The transaction compiling engine 231 can specifically include a parser 2311, an optimizer 2312, and a compiler 2313.
[0116] The parser 2311 is configured to perform syntax and semantic analysis on a database transaction to obtain an operation tree (hereinafter referred to as an operation tree) that can be executed. The operation tree describes the operators required to access target data and the execution order of the operators. The optimizer 2312 is configured to generate a set of possible execution plans for the operation tree output by the parser 2311, estimate the cost of each execution plan, compare the cost of the plans, and finally select an execution plan with the minimum cost. The execution plan also describes the operators required to access target data and the execution order of the operators, but is further optimized from the operation tree of the parser 2311. The execution plan can be an optimized operation tree.
[0117] Regardless of the operation tree output by the parser 2311 or the execution plan output by the optimizer 2312, each operator in either of them represents a processing method for data. Different databases support different operators, and even operators that perform the same function can have different specific execution methods. For example, both MySQL and PostgreSQL support a scan operator, which indicates extracting some or all data from a data table. However, the scan operator in MySQL uses a single-threaded method to extract data, i.e., only one thread is used to extract data. The scan operator in PostgreSQL uses a multi-threaded method to extract data, i.e., multiple threads are used to extract data in parallel.
[0118] Taking the execution plan as an example, when describing the operator used, the name of the operator, the data to be processed by the operator, and the constraint condition for processing the data by the operator can be described. Taking MySQL as an example, when a filter operator is included in the execution plan, the filter operator is marked as the name of the operator when the filter operator is described in the execution plan, and it is recorded that the operator needs to process data table A, and the operator needs to select data with a value of row B in data table A greater than 10, which can be understood as the constraint condition for processing the data by the operator.
[0119] For example, a database transaction instructs the database management system 23 to combine data of column A from data table A and data of column B with value greater than 10. As shown in Figure 3 FIG. 1 shows a schematic diagram of an execution plan provided by an embodiment of the present application. For ease of understanding, the form of the execution plan is exemplified as an operation tree in a tree structure.
[0120] The execution plan is divided into two branches. Branch 1 includes a scan operator 1 for extracting column A from data table A. Branch 2 includes a scan operator 2 for extracting column B from data table A and a filter operator for filtering data of column B with value greater than 10. The junction of the two branches is a join operator. The join operator is used to combine data of column A and data of column B with value greater than 10.
[0121] The compiler 2313 is used to compile the execution plan to obtain intermediate code or executable code. The compilation process of the compiler 2313 is to first compile the execution plan to intermediate code, and then compile the IR code to executable code. For example, the compiler 2313 can specifically be a low level virtual machine (LLVM) compiler. The LLVM compiler can first compile the execution plan to intermediate representation (IR) code, and then compile the IR code to executable code. Therefore, the compiler 2313 can directly output the execution plan after compiling it to intermediate code, or can output after compiling the intermediate code to executable code.
[0122] Obviously, since the transaction compiling engine 231 can compile the database transaction into the intermediate code and the executable code, different compiling results can be selected by certain strategy to further optimize the execution of the database transaction. For example, if the estimated execution time of the database transaction to be processed is greater than a preset time length, the estimated execution time can be an average value of the execution time of the database transaction and / or the frequency of the database transaction of the same type as the database transaction to be processed being compiled is greater than a preset frequency, the database transaction to be processed is compiled into the executable code; otherwise, the database transaction to be processed is compiled into the intermediate code. In this way, the database transaction of the type with high compiling frequency and the database transaction with long execution time can reduce the execution cost in the transaction execution engine 233, so that the execution cost of the database transaction is obviously shortened, and for the database transaction whose execution cost cannot be obviously shortened, the database transaction is compiled into the intermediate code, and more database transactions can be compiled. In this way, the execution time of the database transaction is not greatly affected, and the computing resources for compiling are saved, so that the dynamic balance between the generation of the compiling result and the execution is promoted.
[0123] The compiler 2313 can also be configured to output the compiling result of the database transaction to the cache queue 232, or can also be configured to directly output the compiling result of the database transaction to the transaction execution engine 233.
[0124] It should be noted that the modules shown in the transaction compiling engine 231 are only exemplary descriptions, and the embodiments of the present application do not limit the specific modules of the transaction compiling engine 231. For example, the transaction compiling engine 231 can also not include the optimizer 2312, and the operation tree output by the parser 2311 can be directly input to the compiler 2313.
[0125] The cache queue 232 is configured to store the compiling result of the database transaction, and the compiling result of the database transaction stored in the cache queue 232 can be used for execution by the transaction execution engine 233. The setting in the cache queue 232 is not limited here, for example, the cache queue 232 can have multiple queues, and different priorities can be set, or the same priority can be set; the queuing rule in the cache queue 232 can be "first come first served" and the like; the database transaction in the cache queue 232 can be executed in parallel by the transaction execution engine 233, so that concurrent access of multiple producers and multiple consumers can be supported.
[0126] For example, for OLTP database, since the compilation time of database transaction is generally much longer than the execution time, the number of parallel execution of database transactions (i.e. the maximum number of database transactions served at a time in the cache queue 232) can be set to be less than the number of queues. For example, 10 queues of the same priority can be set in the cache queue 232, and the queuing rule is "first come first served", and the number of database transactions served at a time can be 4.
[0127] The cache queue 232 can be a cache on the at least one processor 21, such as a Level 1 cache (L1 cache), a Level 2 cache (L2 cache) and a Level 3 cache (L3 cache) on a CPU; or a piece of cache on the non-transitory computer readable medium 22, such as a piece of main memory.
[0128] The transaction execution engine 233 is configured to obtain the compilation result of the database transaction from the transaction compilation engine 231. Obviously, the compilation result of the database transaction obtained by the transaction execution engine 233 can be executable code or intermediate code. If it is executable code, the transaction execution engine 233 can directly load and run the executable code; if it is intermediate code, the transaction execution engine 233 can also compile the intermediate code into executable code, and then load and run the executable code.
[0129] The storage engine 234 is configured to manage the actual content of the table data and index on the file system, and also manage the cache, log and other data during the runtime of the database management system 23. For example, the storage engine 234 can write the execution result of the transaction execution engine 233 to the data storage 30 through physical I / O.
[0130] Obviously, the transaction compilation engine 231, the cache queue 232, the transaction execution engine 233 and the storage engine 234 all need certain computing resources when implementing their respective functions, and the computing resources can be processor cores of a processor. The core scheduler 235 is configured to allocate the processor cores to the transaction compilation engine 231, the cache queue 232, the transaction execution engine 233 and the storage engine 234, so that the transaction compilation engine 231, the cache queue 232, the transaction execution engine 233 and the storage engine 234 implement their respective functions, and the implementation of the core scheduler 235 itself also needs certain computing resources. Under the scheduling of the core scheduler 235, the transaction compilation engine 231, the cache queue 232, the transaction execution engine 233 and the storage engine 234 can complete cooperation, for example, the cooperation process can be applied to Figure 2b The architecture shown, and the cooperation process is as follows:
[0131] Taking a query as an example, the transaction compilation engine 231 compiles a database transaction (an SQL query statement) submitted by the database client 10 into executable code, sends the executable code to the cache queue 232, the transaction execution engine 233 obtains the executable code from the cache queue 232 to generate a query result, and the storage engine 234 writes a log of the query result to the data storage 30.
[0132] In the prior art, since the compilation and execution of a database transaction are both performed in the transaction execution engine 233, the transaction compilation and the transaction execution process are tightly coupled. From the start of the database transaction compilation to the end of the database transaction execution, one processor core needs to be bound to the database transaction all the time, and the following database transaction can only wait for the signed database transaction to be processed. Therefore, although the iteration of the processor core is fast, the ability of the processor to process transaction requests is subject to the processing of the database management system itself. In the embodiment of the present application, the transaction compilation engine 231, the cache queue 232, the transaction execution engine 233, and the storage engine 234 are scheduled by the core scheduler 235, so that the processing of a database transaction can be divided into a compilation phase and an execution phase. Since the transaction compilation engine 231 can pre-compile a database transaction, the transaction execution engine 233 can focus on the execution of the database transaction. Even if concurrent execution is performed, the execution rate will not be slowed down due to the database transaction compilation. Therefore, more database transactions can be processed in a unit of time, and the processing capacity of the database management system 23 can be fully utilized. Therefore, more processor cores can be involved in the calculation, and the utilization rate of the processor is improved.
[0133] The embodiment of the present application will be described in detail below in combination with Figure 4 a database transaction processing method provided by the embodiment of the present application. Figure 4 The steps shown can be implemented by Figure 2a the architecture shown. The specific steps of the database transaction processing method will be described in detail below taking Figure 2a the architecture shown as an example:
[0134] Step 401: The transaction compilation engine 231 obtains a database transaction to be processed.
[0135] Step 402: The transaction compilation engine 231 compiles the database transaction to be processed to obtain a compilation result of the database transaction to be processed.
[0136] The compilation result includes executable code or intermediate code, and the intermediate code is used to compile the executable code.
[0137] Step 403: The transaction execution engine 233 executes the compilation result of the database transaction to be processed.
[0138] From the perspective of the number of database transactions compiled, the database transaction in step 402 can be one or multiple. Taking multiple database transactions as an example, the steps in step 402 can be as follows:
[0139] The transaction compilation engine 231 compiles multiple to-be-processed database transactions in parallel, and the multiple to-be-processed database transactions are compiled into executable code, or are compiled into intermediate code, or part of the multiple to-be-processed database transactions are compiled into executable code, and part of the multiple to-be-processed database transactions are compiled into intermediate code.
[0140] For example, there are 10 to-be-processed database transactions in total, which are T1, T2, …, and T10. The estimated execution duration of T1-T3 is greater than the preset duration, T4-T6 are all data records indicating the column value lookup table A, and the frequency at which the database transaction of the data record type of the column value lookup table A has been compiled is greater than the preset frequency. Therefore, the compilation results of T1-T6 are executable code, and T7-T10 are compiled into intermediate code.
[0141] It should be noted that the transaction compilation engine 231 may need to access data access information during the compilation of the database transaction. The data access information can include the storage location of the data record to be accessed, the user access permission corresponding to the database transaction, the number of database connections, and the like. For the case of parallel compilation of multiple database transactions, the case that the data access information required by multiple database transactions is the same can occur. For example, the multiple to-be-processed database transactions include a first database transaction and a second database transaction, and the data access information required for the compilation of the first database transaction and the second database transaction is the same. The following steps can be performed:
[0142] The data access information required for the compilation of the first database transaction and the second database transaction is copied into two copies to obtain first data access information and second data access information; the first database transaction is compiled according to the first data access information, and the second database transaction is compiled in parallel according to the second data access information.
[0143] For example, the first database transaction and the second database transaction both need to access the table information of data table A. Therefore, the table information of data table A can be copied into two copies, i.e., first data table information and second data table information. Then, the first database transaction can be compiled according to the first data table information, and the second database transaction can be compiled in parallel according to the second data table information.
[0144] In a possible implementation, the compiling process in step 402 can be completed by means of a compiling template, which can be stored in the at least one processor 21, and the steps can be as follows:
[0145] The transaction compiling engine 231 obtains a compiling template matched with the database transaction to be processed according to a structured query language (SQL) statement included in the database transaction to be processed, and compiles the database transaction to be processed according to the compiling template.
[0146] For example, the database transaction to be processed includes a first SQL statement and a second SQL statement. Wherein,
[0147] The first SQL statement is:
[0148] SELECT * FROM student WHERE age = 15, that is, querying data records of students with an age of 15 from a data table student.
[0149] The second SQL statement is:
[0150] SELECT * FROM exam_results WHERE math > 60, that is, querying data records with a math score greater than 60 from a data table exam_results.
[0151] The compiling template can be a template of part or all of the SQL statements, for example, the compiling template can be a template of the first SQL statement, or a template of the first SQL statement and the second SQL statement.
[0152] The compiling template can be determined in the following manner:
[0153] If the types of all SQL statements included in the database transaction to be processed are the same as the types of all SQL statements corresponding to the first transaction type template, the first transaction type template is determined as the compiling template matched with the database transaction to be processed.
[0154] Otherwise, if the type of the first SQL statement included in the database transaction to be processed is the same as the type of the first SQL statement corresponding to the first SQL statement template, the first SQL statement template is determined as the compiling template matched with the database transaction to be processed, wherein the first SQL statement is any one of all SQL statements included in the database transaction to be processed.
[0155] For the database transaction matched with the compiling template, the specific compiling process can be as follows:
[0156] obtaining executable code corresponding to the compiling template, the executable code corresponding to the compiling template including variables to be replaced; and obtaining a parameter matching the variables from the database transaction to be processed, and replacing the variables in the executable code corresponding to the compiling template with the parameter.
[0157] For example, the types of SQL statements corresponding to the first transaction type template include SELECT * FROM student WHERE age=x and SELECT * FROM exam_results WHERE math>y, and the first transaction type template is executable code corresponding to the two SQL statements, and the non-general language elements "x" and "y" in the executable code can be marked with special characters. After obtaining the language elements (scalar values of data columns and / or rows, x=15, y=60) in the specific SQL statements in the database transaction, the code of the non-general language elements can be generated according to the scalar values of the data columns and / or rows, and the code of the non-general language elements is filled into the executable code corresponding to the compiling template (i.e., the executable code corresponding to the non-general language elements "x" and "y" is replaced), to form the compiling result of the database transaction to be processed.
[0158] It should be noted that the compiling templates can also be managed, for example, the compiling templates that are not matched to the database transactions within a set period of time are released; and / or, the compiling templates are stored in the processor, and if the memory occupied by the compiling templates in the processor is greater than a memory threshold, the compiling templates in the processor are released.
[0159] Obviously, the execution of steps 402-403 needs to be based on computing resources, and step 402 can be specifically:
[0160] Based on the first computing resource, the transaction compiling engine 231 compiles the database transaction to be processed.
[0161] And step 403 can be specifically:
[0162] Based on the second computing resource, the transaction execution engine 233 executes the compiling result of the database transaction to be processed.
[0163] The first computing resource and the second computing resource each include at least one processor core. The processor cores included in the first computing resource and the second computing resource can belong to the same processor, and can be processor cores in at least one processor 21. The number of processor cores included in the first computing resource and the number of processor cores included in the second computing resource can be fixed or variable. The number of processor cores included in the first computing resource and the number of processor cores included in the second computing resource can be designed according to a specific scenario. For example, for an OLTP database, because the duration of database transaction compilation is much longer than the duration of database transaction execution, the number of processor cores included in the first computing resource can be set to 10 times the number of processor cores included in the second computing resource.
[0164] Obviously, by appropriately adjusting the first computing resource and the second computing resource, the core scheduler 235 can make the compilation and execution of database transactions more balanced, and make the overall processing efficiency of database transactions higher. The core scheduler 235 can adjust in the following manner:
[0165] The first way: The core scheduler 235 counts the compiled operations to obtain transaction compilation statistical information; and adjusts the number of processor cores included in the first computing resource and / or the second computing resource according to the transaction compilation statistical information.
[0166] For example, the transaction compilation statistical information can include the compilation frequency of the compiled operations. The specific adjustment process can be as follows:
[0167] If the compilation frequency of the compiled operations in the transaction compilation statistical information is greater than a first threshold, the core scheduler 235 reduces the number of processor cores in the first computing resource and / or increases the number of processor cores in the second computing resource.
[0168] The second way: The core scheduler 235 counts the executed operations to obtain transaction execution statistical information; and adjusts the number of processor cores included in the first computing resource and / or the second computing resource according to the transaction execution statistical information.
[0169] For example, the transaction execution statistical information can include the frequency of conflicts of the executed operations. The specific adjustment process can be as follows:
[0170] If the frequency of conflicts of the executed operations in the transaction execution statistical information is greater than a second threshold, the core scheduler 235 reduces the number of processor cores in the first computing resource and / or reduces the number of processor cores in the second computing resource.
[0171] The third way:
[0172] The core scheduler 235 counts the compiled operations to obtain transaction compilation statistics, counts the executed operations to obtain transaction execution statistics, and adjusts the number of processor cores included in the first computing resource and / or the second computing resource according to the transaction compilation statistics and the transaction execution statistics. The specific adjustment process can be as follows:
[0173] If the compilation frequency of the compiled operations in the transaction compilation statistics is greater than the first threshold value, and the frequency of the occurrence of conflicts of the executed operations in the transaction execution statistics is less than the second threshold value, the core scheduler 235 reduces the number of processor cores in the first computing resource and / or increases the number of processor cores in the second computing resource.
[0174] It should be noted that after step 402, the core scheduler 235 can also store the compilation results of the database transactions to be processed in the cache queue 232. In this case, step 403 can be:
[0175] The core scheduler 235 obtains the compilation results of the database transactions to be processed from the cache queue 232, and executes the obtained compilation results of the database transactions to be processed.
[0176] The number of processor cores included in the first computing resource and / or the second computing resource can be adjusted according to the following process:
[0177] The core scheduler 235 counts the number and / or latency of the compilation results of the database transactions in the cache queue 232 to obtain queuing statistics, and adjusts the number of processor cores included in the first computing resource and / or the second computing resource according to the queuing statistics.
[0178] Specifically, the adjustment strategy can be as follows:
[0179] If the number of the compilation results of the database transactions in the cache queue 232 is greater than a third threshold value, and / or the latency of the database transactions in the cache queue 232 is greater than a fourth threshold value, the core scheduler 235 reduces the number of processor cores included in the first computing resource and / or increases the number of processor cores included in the second computing resource.
[0180] For example, the number of processor cores included in the first computing resource is 90, the number of processor cores included in the second computing resource is 10, the number of compilation results of the database transactions in the cache queue 232 is 1000, the third threshold is 900, and the waiting time of the database transactions in the cache queue 232 is 10 ms, and the fourth threshold is 8 ms, then the number of processor cores included in the first computing resource can be reduced to 80 (for example, the single processor core reduction amount is set to 10), and the number of processor cores included in the second computing resource can be increased to 9 (for example, the single processor core increase amount is set to 1).
[0181] As shown in Figure 5 a database transaction processing apparatus is provided in the present application, and the apparatus comprises:
[0182] a compiling module 501, configured to acquire a database transaction to be processed;
[0183] The compiling module 501 is further configured to compile the database transaction to be processed to obtain a compilation result of the database transaction to be processed, wherein the compilation result comprises executable code or intermediate code, and the intermediate code is used for compiling the executable code.
[0184] an executing module 502, configured to execute the compilation result of the database transaction to be processed.
[0185] In a possible design, the compiling module 501 is specifically configured to:
[0186] compile a plurality of database transactions to be processed in parallel, wherein the plurality of database transactions to be processed are compiled into executable code, or are compiled into intermediate code, or part of the plurality of database transactions to be processed are compiled into executable code, and part of the plurality of database transactions to be processed are compiled into intermediate code.
[0187] In a possible design, the plurality of database transactions to be processed comprises a first database transaction and a second database transaction, the first database transaction and the second database transaction have the same data access information required for compilation, and the apparatus further comprises a scheduling module 503, configured to:
[0188] copy the data access information required for compilation of the first database transaction and the second database transaction into two copies to obtain first data access information and second data access information;
[0189] The compiling module 501 is specifically configured to:
[0190] compile the first database transaction according to the first data access information, and compile the second database transaction according to the second data access information in parallel.
[0191] In a possible design, the compiling module 501 is specifically configured to:
[0192] compile the to-be-processed database transaction based on first computing resources;
[0193] The execution module 502 is specifically configured to:
[0194] execute the compilation result of the to-be-processed database transaction based on second computing resources.
[0195] The first computing resources and the second computing resources each include at least one processor core, and the first computing resources and the second computing resources include processor cores of the same processor.
[0196] In a possible design, the apparatus further includes a scheduling module 503, and the scheduling module 503 is further configured to:
[0197] count the compiling operation to obtain transaction compiling statistical information, and adjust the number of processor cores included in the first computing resources and / or the second computing resources according to the transaction compiling statistical information; or
[0198] count the executing operation to obtain transaction executing statistical information, and adjust the number of processor cores included in the first computing resources and / or the second computing resources according to the transaction executing statistical information; or
[0199] count the compiling operation to obtain transaction compiling statistical information, count the executing operation to obtain transaction executing statistical information, and adjust the number of processor cores included in the first computing resources and / or the second computing resources according to the transaction compiling statistical information and the transaction executing statistical information.
[0200] In a possible design, the transaction compiling statistical information includes a compiling frequency of the compiling operation, and the transaction executing statistical information includes a conflict frequency of the executing operation; and the scheduling module 503 is specifically configured to:
[0201] if the compiling frequency of the compiling operation in the transaction compiling statistical information is greater than a first threshold, reduce the number of processor cores in the first computing resources and / or increase the number of processor cores in the second computing resources;
[0202] if the conflict frequency of the executing operation in the transaction executing statistical information is greater than a second threshold, reduce the number of processor cores in the first computing resources and / or reduce the number of processor cores in the second computing resources;
[0203] If the compilation frequency of the compiled operation in the transaction compilation statistics information is greater than the first threshold value, and the conflict frequency of the executed operation in the transaction execution statistics information is less than the second threshold value, the number of processor cores in the first computing resource is reduced, and / or the number of processor cores in the second computing resource is increased.
[0204] In a possible design, the apparatus further includes a scheduling module 503, where the scheduling module 503 is configured to:
[0205] store the compilation result of the to-be-processed database transaction in a cache queue;
[0206] The execution module 502 is specifically configured to:
[0207] obtain the compilation result of the to-be-processed database transaction from the cache queue, and execute the obtained compilation result of the to-be-processed database transaction.
[0208] In a possible design, the scheduling module 503 is further configured to:
[0209] statistically obtain queuing statistics information of the number and / or latency of the compilation result of the database transaction in the cache queue, and adjust the number of processor cores included in the first computing resource and / or the second computing resource according to the queuing statistics information.
[0210] In a possible design, the scheduling module 503 is specifically configured to:
[0211] If the number of the compilation result of the database transaction in the cache queue is greater than a third threshold value, and / or the latency of the database transaction in the cache queue is greater than a fourth threshold value, the number of processor cores included in the first computing resource is reduced, and / or the number of processor cores included in the second computing resource is increased.
[0212] In a possible design, the compiling module 501 is specifically configured to:
[0213] obtain a compilation template matched with the to-be-processed database transaction according to a structured query language (SQL) statement included in the to-be-processed transaction, and compile the to-be-processed database transaction according to the compilation template.
[0214] In a possible design, the compiling module 501 is specifically configured to:
[0215] If the type of all SQL statements included in the to-be-processed database transaction is the same as the type of all SQL statements corresponding to a first transaction type template, the first transaction type template is determined as the compilation template matched with the to-be-processed database transaction.
[0216] Otherwise, if the first SQL statement included in the database transaction to be processed is of the same type as the type of the first SQL statement template, the first SQL statement template is determined as a compiled template matched with the database transaction to be processed; wherein the first SQL statement is any one of all SQL statements included in the database transaction to be processed.
[0217] In a possible design, the compiling module 501 is specifically configured to:
[0218] obtain executable code corresponding to the compiled template, wherein the executable code corresponding to the compiled template includes a variable to be replaced;
[0219] obtain a parameter matched with the variable from the database transaction to be processed, and replace the variable in the executable code corresponding to the compiled template with the parameter.
[0220] The embodiment of the present application further provides an electronic device, which can have a structure as shown in Figure 6 The electronic device can be a computer device, or a chip or a chip system capable of supporting the computer device to implement the method.
[0221] The electronic device as shown in Figure 6 may include at least one processor 601 configured to be coupled with a memory, read and execute instructions in the memory to implement the steps of the video frame interpolation provided by the embodiment of the present application. Optionally, the electronic device can further include a communication interface 602 configured to support the electronic device to receive or send signaling or data. The communication interface 602 in the electronic device can be used to implement the interaction with other electronic devices. The processor 601 can be used to implement the steps of the electronic device to perform the video frame interpolation. Optionally, the electronic device can further include a memory 603 having computer instructions stored therein, the memory 603 can be coupled with the processor 601 and / or the communication interface 602, and be configured to support the processor 601 to invoke the computer instructions in the memory 603 to implement the steps of the video frame interpolation; in addition, the memory 603 can also be used to store the data related to the method embodiment of the present application, for example, used to store the data and instructions necessary for the communication interface 602 to implement the interaction, and / or used to store the configuration information necessary for the electronic device to perform the method described in the embodiment of the present application.
[0222] The embodiment of the present application further provides a computer readable storage medium, and computer instructions are stored on the computer readable storage medium. When the computer instructions are invoked and executed by a computer, the computer can complete the method involved in the above method embodiment and any possible design of the method embodiment. In the embodiment of the present application, the computer readable storage medium is not limited, for example, can be a RAM (random-access memory), a ROM (read-only memory) and the like.
[0223] The present application further provides a chip, which can include a processor and an interface circuit, and is used for completing the method involved in the above method embodiment and any possible implementation manner of the method embodiment, wherein, the coupling means that two components are directly or indirectly combined with each other, and the combination can be fixed or movable.
[0224] In the above embodiment, the implementation can be realized by software, hardware, firmware or any combination thereof, in whole or in part. When the implementation is realized by software, the implementation can be realized by computer instructions in whole or in part. When the computer instructions are loaded and executed on a computer, the flow or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable devices. The computer instructions can be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another computer readable storage medium, for example, the computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center through a wired (for example, coaxial cable, optical fiber) or wireless (for example, infrared, wireless, microwave and the like) manner. The computer readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, data center and the like integrated with one or more available medium sets. The available medium can be a magnetic medium (for example, floppy disk, hard disk, magnetic tape), an optical medium (for example, DVD) or a semiconductor medium (for example, solid state disk (SSD)) and the like.
[0225] The steps of a method or algorithm described in connection with the embodiments disclosed herein can be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module can reside in RAM memory, flash memory, ROM memory, EPROM memory, EEPROM memory, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art. An exemplary storage medium is tangible. In addition, the storage medium can be connected to the processor, so that the processor can read information from, and write information to, the storage medium. In the alternative, the storage medium can be integral to the processor. The processor and the storage medium can reside in an ASIC. The ASIC can reside in a terminal device. In the alternative, the processor and the storage medium can reside as discrete components in a terminal device. Thus, the numerous objects and advantages of the embodiments can be obtained by means of the methods, instrumentalities, and combinations particularly described herein.
[0226] These computer program instructions can also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart block or blocks. Figure 1 The flowchart blocks or blocks in the flowcharts represent steps in a process or algorithms and / or functions. The steps of the process or algorithms and / or functions can be embodied in computer program instructions, which can be executed on a computer or other programmable apparatus. Figure 1 The flowchart blocks or blocks in the flowcharts represent steps in a process or algorithms and / or functions. The steps of the process or algorithms and / or functions can be embodied in computer program instructions, which can be executed on a computer or other programmable apparatus.
[0227] Although the present application has been described in connection with specific features thereof, it will be evident to those skilled in the art that various modifications and combinations can be made therein without departing from the scope of the application. Accordingly, it is intended to embrace all such alternatives, modifications and variations as can be included within the scope of the present application. It will be apparent to those skilled in the art that various modifications and variations can be made in the present application without departing from the spirit or scope of the application. Thus, it is intended that the present application cover modifications and variations of this application provided they come within the scope of the appended claims and their equivalents.
Claims
1. A method of processing a database transaction, characterized by, The method comprises: acquiring a database transaction to be processed; compiling the database transaction to be processed to obtain a compilation result of the database transaction to be processed, the compilation result comprising executable code or intermediate code, the intermediate code being used for compiling the executable code; executing the compilation result of the database transaction to be processed; the compiling the database transaction to be processed comprises compiling the database transaction to be processed based on a first computing resource; the executing the compilation result of the database transaction to be processed comprises executing the compilation result of the database transaction to be processed based on a second computing resource; wherein the first computing resource and the second computing resource each comprise at least one processor core, and the processor cores comprised by the first computing resource and the second computing resource belong to the same processor.
2. The method of claim 1, wherein, The method further comprises: compiling a plurality of database transactions to be processed in parallel, wherein the plurality of database transactions to be processed are compiled into executable code, or are compiled into intermediate code, or part of the plurality of database transactions to be processed are compiled into executable code and part of the plurality of database transactions to be processed are compiled into intermediate code.
3. The method of claim 2, wherein, The plurality of database transactions to be processed comprise a first database transaction and a second database transaction, the first database transaction and the second database transaction require access to the same data access information during compilation, and the method further comprises: copying the data access information required for the first database transaction and the second database transaction to obtain first data access information and second data access information; The method further comprises: compiling the first database transaction according to the first data access information and compiling the second database transaction according to the second data access information in parallel.
4. The method of claim 1, wherein, The method further comprises: statistically analyzing the compilation operations to obtain transaction compilation statistical information, and adjusting the number of processor cores comprised in the first computing resource and / or the second computing resource according to the transaction compilation statistical information; or statistically analyzing the execution operations to obtain transaction execution statistical information, and adjusting the number of processor cores comprised in the first computing resource and / or the second computing resource according to the transaction execution statistical information; or statistically analyzing the compilation operations to obtain transaction compilation statistical information, statistically analyzing the execution operations to obtain transaction execution statistical information, and adjusting the number of processor cores comprised in the first computing resource and / or the second computing resource according to the transaction compilation statistical information and the transaction execution statistical information.
5. The method of claim 4, wherein, The transaction compilation statistical information comprises a compilation frequency of the compilation operations, and the transaction execution statistical information comprises a frequency of occurrence of conflicts of the execution operations; the adjusting the number of processor cores comprised in the first computing resource and / or the second computing resource according to the transaction compilation statistical information comprises: if the compilation frequency of the compiled operation in the transaction compilation statistic information is greater than a first threshold, then reducing the number of processor cores in the first computing resource, and / or increasing the number of processor cores in the second computing resource; the adjusting the number of processor cores included in the first computing resource and / or the second computing resource according to the transaction execution statistic information comprises: if the frequency of operation conflict in the transaction execution statistic information is greater than a second threshold, then reducing the number of processor cores in the first computing resource, and / or reducing the number of processor cores in the second computing resource; the adjusting the number of processor cores included in the first computing resource and / or the second computing resource according to the transaction compilation statistic information and the transaction execution statistic information comprises: if the compilation frequency of the compiled operation in the transaction compilation statistic information is greater than the first threshold, and the frequency of operation conflict in the transaction execution statistic information is less than the second threshold, then reducing the number of processor cores in the first computing resource, and / or increasing the number of processor cores in the second computing resource.
6. The method of claim 1, wherein, after the compiling the to-be-processed database transaction to obtain a compilation result of the to-be-processed database transaction, the method further comprises: storing the compilation result of the to-be-processed database transaction into a cache queue; the executing the compilation result of the to-be-processed database transaction comprises: obtaining the compilation result of the to-be-processed database transaction from the cache queue, and executing the obtained compilation result of the to-be-processed database transaction.
7. The method of claim 6, wherein, the method further comprises: statistically obtaining queuing statistic information of the number and / or waiting time of the compilation result of the database transaction in the cache queue; adjusting the number of processor cores included in the first computing resource and / or the second computing resource according to the queuing statistic information.
8. The method of claim 7, wherein, the adjusting the number of processor cores included in the first computing resource and / or the second computing resource according to the queuing statistic information comprises: if the number of the compilation result of the database transaction in the cache queue is greater than a third threshold, and / or the waiting time of the database transaction in the cache queue is greater than a fourth threshold, then reducing the number of processor cores included in the first computing resource, and / or increasing the number of processor cores included in the second computing resource.
9. The method according to any one of claims 1 to 8, characterized in that, the compiling the to-be-processed database transaction comprises: obtaining a compilation template matched with the to-be-processed database transaction according to a structured query language (SQL) statement included in the to-be-processed transaction; compiling the to-be-processed database transaction according to the compilation template.
10. The method of claim 9, wherein, the obtaining a compilation template matched with the to-be-processed database transaction according to a structured query language (SQL) statement included in the to-be-processed transaction comprises: if the type of all SQL statements included in the to-be-processed database transaction is the same as the type of all SQL statements corresponding to a first transaction type template, then determining the first transaction type template as the compilation template matched with the to-be-processed database transaction; Otherwise, if the first SQL statement included in the database transaction to be processed is of the same type as the type of the first SQL statement template, the first SQL statement template is determined as a compilation template matched with the database transaction to be processed; wherein the first SQL statement is any one of all SQL statements included in the database transaction to be processed.
11. The method of claim 9, wherein, The compiling the database transaction to be processed according to the compilation template comprises: obtaining executable code corresponding to the compilation template, wherein the executable code corresponding to the compilation template includes a variable to be replaced; obtaining a parameter matching the variable in the database transaction to be processed, and replacing the variable in the executable code corresponding to the compilation template with the parameter.
12. An apparatus for processing of database transactions, characterized by comprises: a compiling module configured to obtain a database transaction to be processed; a compiling module configured to compile the database transaction to be processed to obtain a compilation result of the database transaction to be processed, wherein the compilation result comprises executable code or intermediate code, and the intermediate code is used to compile the executable code; an executing module configured to execute the compilation result of the database transaction to be processed; the compiling module is specifically configured to compile the database transaction to be processed based on first computing resources; the executing module is specifically configured to execute the compilation result of the database transaction to be processed based on second computing resources; wherein the first computing resources and the second computing resources each comprise at least one processor core, and the processor cores included in the first computing resources and the second computing resources belong to the same processor.
13. The apparatus of claim 12, wherein, the compiling module is specifically configured to: compile a plurality of database transactions to be processed in parallel, wherein the plurality of database transactions to be processed are compiled into executable code, or are compiled into intermediate code, or part of the plurality of database transactions to be processed are compiled into executable code and part of the plurality of database transactions to be processed are compiled into intermediate code.
14. The apparatus of claim 13, wherein, The plurality of database transactions to be processed include a first database transaction and a second database transaction, and the first database transaction and the second database transaction require access to the same data access information, and the apparatus further comprises a scheduling module configured to: copy the data access information required for compiling the first database transaction and the second database transaction into two copies to obtain first data access information and second data access information; the compiling module is specifically configured to: compile the first database transaction according to the first data access information, and compile the second database transaction according to the second data access information in parallel.
15. The apparatus of claim 12, wherein, the scheduling module is further configured to: statistically analyze the operations of compiling to obtain transaction compilation statistical information, and adjust the number of processor cores included in the first computing resources and / or the second computing resources according to the transaction compilation statistical information; or counting the executed operations to obtain transaction execution statistics information, and adjusting the number of processor cores included in the first computing resource and / or the second computing resource according to the transaction execution statistics information; or counting the compiled operations to obtain transaction compilation statistics information, and counting the executed operations to obtain transaction execution statistics information; adjusting the number of processor cores included in the first computing resource and / or the second computing resource according to the transaction compilation statistics information and the transaction execution statistics information.
16. The apparatus of claim 15, wherein, The transaction compilation statistics information includes the compilation frequency of the compiled operations, and the transaction execution statistics information includes the frequency of conflicts of the executed operations; and the scheduling module is specifically configured to: if the compilation frequency of the compiled operations in the transaction compilation statistics information is greater than a first threshold, then reducing the number of processor cores in the first computing resource and / or increasing the number of processor cores in the second computing resource; if the frequency of conflicts of the executed operations in the transaction execution statistics information is greater than a second threshold, then reducing the number of processor cores in the first computing resource and / or reducing the number of processor cores in the second computing resource; if the compilation frequency of the compiled operations in the transaction compilation statistics information is greater than the first threshold, and the frequency of conflicts of the executed operations in the transaction execution statistics information is less than the second threshold, then reducing the number of processor cores in the first computing resource and / or increasing the number of processor cores in the second computing resource.
17. The apparatus of claim 12, wherein, The apparatus further includes a scheduling module configured to: store the compilation result of the to-be-processed database transaction in a cache queue; The execution module is specifically configured to: obtain the compilation result of the to-be-processed database transaction from the cache queue, and execute the obtained compilation result of the to-be-processed database transaction.
18. The apparatus of claim 17, wherein, The scheduling module is further configured to: count the number and / or waiting time of the compilation results of the database transactions in the cache queue to obtain queuing statistics information; adjust the number of processor cores included in the first computing resource and / or the second computing resource according to the queuing statistics information.
19. The apparatus of claim 18, wherein, The scheduling module is specifically configured to: if the number of the compilation results of the database transactions in the cache queue is greater than a third threshold, and / or the waiting time of the database transactions in the cache queue is greater than a fourth threshold, then reducing the number of processor cores included in the first computing resource and / or increasing the number of processor cores included in the second computing resource.
20. The apparatus of any one of claims 12 to 19, wherein, The compiling module is specifically configured to: obtain a compilation template matched with the to-be-processed database transaction according to the structured query language (SQL) statement included in the to-be-processed transaction; compile the to-be-processed database transaction according to the compilation template.
21. The apparatus of claim 20, wherein, The compiling module is specifically configured to: if the types of all the SQL statements included in the to-be-processed database transaction are the same as the types of all the SQL statements corresponding to a first transaction type template, then determining the first transaction type template as the compilation template matched with the to-be-processed database transaction. Otherwise, if the first SQL statement included in the database transaction to be processed is of the same type as the type of the first SQL statement template, the first SQL statement template is determined as a compiled template matched with the database transaction to be processed; wherein the first SQL statement is any one of all SQL statements included in the database transaction to be processed.
22. The apparatus of claim 20, wherein, The compiling module is specifically configured to: obtain executable code corresponding to the compiled template, wherein the executable code corresponding to the compiled template includes a variable to be replaced; obtain a parameter matched with the variable from the database transaction to be processed, and replace the variable in the executable code corresponding to the compiled template with the parameter.
23. An electronic device, comprising: The electronic device includes one or more processors, one or more memories, wherein the one or more memories store one or more computer instructions, and when the one or more computer instructions are executed by the one or more processors, the electronic device performs the method of any one of claims 1 to 11.
24. A computer-readable storage medium, characterized in that, The computer readable storage medium includes computer instructions, and when the computer instructions run on a computer, the computer executes the method of any one of claims 1 to 11.
Citation Information
Patent Citations
Deeply parallel source code compilation
CN105308565A
Method and system for parallel processing of database queries
US20040098359A1