Processing user queries
By using a method of parallel compilation of unoptimized and optimized machine code, the problem of time-consuming machine code compilation in database management systems is solved, enabling rapid query processing and improving execution efficiency, while reducing user query latency.
Patent Information
- Application Number
- CN202280082720.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2021-12-21
- Filing Date
- 2022-12-12
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2042-12-12
AI Technical Summary
Existing database management systems suffer from time-consuming compilation processes when processing user queries into machine code, leading to query delays, especially when handling large or complex queries. The slow interpretation and execution of bytecode after compilation further impacts query response time.
By employing a parallel compilation method, unoptimized machine code is first generated and executed quickly, while optimized machine code is compiled in parallel. Once the optimized code is completed, execution is switched to the optimized code, thereby reducing compilation time and improving execution efficiency.
By optimizing machine code through parallel compilation, the overall response time for user queries was reduced, query processing speed and result return speed were improved by an average of 33%, and resource consumption was reduced.
Smart Images

Figure CN118401931B_ABST
Abstract
Description
background Technical Field
[0002] This application relates to processing and executing user search queries related to data in a database.
[0003] Related technical specifications
[0004] With technological advancements, the amount of information stored electronically and the need for the ability to search, organize, and / or manipulate such information in real-time or pseudo-real-time are constantly increasing. Database management systems (sometimes also called databases and data warehouses) are designed to organize data in a form that facilitates efficient searching, retrieval, or manipulation of selected information. A typical database management system allows users to submit "queries" or invoke one or more functions in a query language to search, organize, retrieve, and / or manipulate information that satisfies specific function parameters.
[0005] In a typical database management system, a user query consists of one or more Structured Query Language (SQL) statements, which are parsed by the optimizer and transformed into an execution plan. The execution plan is then compiled into code for execution to process the query and return an answer. The execution plan can be compiled into a runtime operator tree, bytecode, or a combination of both, and then interpreted by an interpreter. Alternatively, the execution plan can be directly compiled into machine or assembly code and executed. Attached Figure Description
[0006] Various features of this disclosure will become apparent from the following detailed description taken in conjunction with the accompanying drawings, which... Figure 1 The features of this disclosure are illustrated in the accompanying drawings:
[0007] Figure 1 This is a schematic diagram based on an example database management system.
[0008] Figure 2 This is a schematic diagram illustrating the processing of a user query based on an example.
[0009] Figure 3 This is pseudocode showing the updated machine code based on an example.
[0010] Figure 4 This is a flowchart illustrating a method for processing user queries, based on an example.
[0011] Figure 5 This is a flowchart illustrating a method for processing user queries, based on an example.
[0012] Figure 6 This is a schematic diagram illustrating the processing of a user query based on an example. Detailed Implementation
[0013] Figure 1 A database management system 100 is illustrated, which manages a database 130, including processing user queries related to data stored in the database. Database 130 can be distributed across multiple nodes 105, 105x as part of a database cluster. Database 130 can be distributed in any suitable manner, such as horizontal sharding using sharding keys. Alternatively, database 130 can be implemented on a single node.
[0014] Some details of a representative node 105x are shown, which may include volatile memory 110 (such as RAM), storage device 115 (such as a disk), and processor 120. A database or database shard may be stored in one or both of volatile memory 110 and storage device 115, and may be stored in any suitable format, such as column-stored and / or row-stored. For example, a database or database shard may be stored in disk-based column-stored data and row-stored data in memory, backed up by snapshots on storage device 115. Volatile memory 110 may be used to temporarily store and manipulate data from the database, and may include a buffer cache (where portions of column-stored data from disk are cached) and query execution memory (for storing temporary hashes, sorting runs, and other data used during processing user queries). Modified data from the buffer cache can then be used to update data stored in storage device 115. Non-volatile memory may store computer programs for controlling caches and database elements stored in memory 110 and storage device 115. Non-volatile memory may also permanently store query plans or store query plans long-term across restarts. Non-volatile memory may include a code library for storing compiled functions that can be reused for later user queries.
[0015] The processor 120 is used to load and execute programs stored in the storage device 115 to generate query plans for user queries and execute those query plans, as well as control input / output (I / O) operations associated with the storage device 115.
[0016] The database management system 100 also includes a user interface 150, which may include a monitor, keyboard, mouse, or other components to allow users to enter user queries and receive responses to those queries. For example, user queries may be entered as SQL statements, and responses may be data from the database that has been arranged into a new table. The user interface may be implemented by one of the database storage nodes 105 or by different nodes.
[0017] The database management system 100 may also include a controller 140, which can be used to control how the database is distributed and to distribute the execution tasks of the database management system 100 to different nodes 105, for example, to achieve load balancing. The controller 140 may be implemented by one of the database storage nodes 105 or by different nodes.
[0018] Figure 2 The processing and execution of a sample SQL user query are illustrated. SQL query 205 is parsed and optimized to generate execution plan 210. This can be achieved by a query engine that includes parsing functions, such as syntax checking, semantic checking, and shared pool checking, for reusing portions of previously generated execution plans where appropriate. Syntax checking ensures that the SQL statements are formatted according to SQL language rules. Semantic checking determines the meaning of each statement, including the required operations and the specified data resources from the database. Shared pool checking determines whether the expected set of operations on the specified data has been processed into an executable format, in which case the executable format can be reused rather than being processed again. The optimization process generates multiple execution plans capable of performing the required operations and determines which of these plans has the lowest cost. The lowest-cost plan corresponds to the optimal execution plan 210 to be executed. The execution plan includes multiple operators 215 arranged sequentially and in parallel for execution. Example operators include TABLESCAN, MERGE JOIN, COMPUTE SCALAR, CLUSTERED INDEXSCAN, SORT, and many others.
[0019] An execution plan can be translated into bytecode, such as bytecode generated from Java source code, and submitted to the Java runtime, where each operator is compiled into a block of bytecode, which is then called and interpreted by the interpreter to execute the execution plan. Various other bytecodes can be used, such as memSQL bytecode. While such methods compile quickly into bytecode blocks, execution can be slow because the interpreter executes the operations specified in the bytecode line by line. In alternative approaches, the execution plan can be compiled directly into machine code, which can then be executed by the processing system. This is much faster than executing bytecode, which requires an intermediate interpreter. However, compiling to machine code (so-called code generation) takes more time than compiling to bytecode, and therefore, while the routing is generally faster overall, especially when dealing with large or complex queries, it can be slower to start returning results to the user, and for some queries, it can be slower overall. Therefore, users may notice a perceptible delay when returning results using either method.
[0020] Figure 2The user query processing uses a modified method to execute execution plan 210, where operators are converted to bytecode 220, which is then compiled into unoptimized machine code and subsequently compiled in parallel into optimized machine code. Compiling unoptimized machine code is fast but slow to execute, while compiling optimized machine code is slower but fast to execute. This method provides an initial fast compilation of the machine code, allowing execution to begin quickly. In parallel, the optimized machine code is compiled, and once complete, execution of the execution plan switches from the unoptimized machine code to the optimized machine code, further improving execution speed. Therefore, overall, the user sees query processing start quickly, results begin returning quickly, and query processing complete quickly overall.
[0021] Bytecode 220 can be any suitable bytecode, such as Java or other formats, such as memSQL. The bytecode can be constructed as a high-level instruction sequence (Main) that calls various functions (F1, F2), and each function can be arranged with its own corresponding bytecode instruction sequence.
[0022] Unoptimized machine code compilation function 225 can be used to compile unoptimized machine code 235 corresponding to bytecode 220 by replacing each part of bytecode (e.g., instructions) with corresponding machine code parts (e.g., instructions). For example, a bytecode instruction including an opcode and arguments is compiled into one or more machine code instructions. Compilation function 225 can utilize machine code lookup table LUT 230 to retrieve parts of the compiled machine code to implement the bytecode instructions in the machine code. For example, each bytecode instruction can be replaced with a corresponding machine code instruction. Simply replacing bytecode instructions with machine code instructions is fast because the optimization process that is usually performed when compiling machine code is not employed at this stage. In some examples, some optimizations with low processing or compilation overhead, such as inlining and register allocation, can be employed.
[0023] Unoptimized machine code 235 can have a structure similar to bytecode, with a high-level instruction sequence (Main) that calls various functions, each of which can be arranged with its own corresponding machine code instruction sequence. Unoptimized bytecode functions in... Figure 2 They are shown as F1' and F2' to distinguish them from their corresponding bytecode functions F1 and F2.
[0024] Compiling function 225 can be done using tools such as ASMJIT ( https: / / asmjit.com / Alternatively, other machine code libraries can be used to compile bytecode into corresponding machine code instructions one instruction at a time. However, alternative compilation methods can be used, such as using a compiler with minimal lightweight (low processor overhead) optimizations.
[0025] The generation function 225 also includes adding a switching mechanism (omc?) 250 to the unoptimized machine code 235. The switching mechanism is configured to check if optimized machine code is available, and when available, switch to using the optimized machine code to execute the query plan.
[0026] Compiler 240 can be used to compile bytecode 220 into optimized machine code 245. Optimized machine code 245 may have a structure similar to bytecode 220 and unoptimized machine code 235, with a high-level instruction sequence (Main) that calls various functions (F1”, F2”), each of which can be arranged as a corresponding optimized machine code sequence.
[0027] These different parts of the optimized machine code 245 will have associated memory locations or addresses that the switching mechanism 250 in the unoptimized machine code 235 can use to point to the corresponding optimized machine code part when these parts have finished compiling. For example, before executing the body of the Main or F1 instruction sequence of the unoptimized machine code 235, the switching mechanism 250 checks whether the optimized machine code 245 has finished compiling. If it has, it uses pointers to the locations of the corresponding Main and F1 instruction sequences of the optimized machine code 245 to continue executing the execution plan using the optimized machine code 245, instead of continuing to use the unoptimized machine code 235. This can be achieved by including the switching mechanism ocm? as the first instruction in the Main or one or more functions of the unoptimized machine code 235. Then, when these are called, the first instruction is to check whether the corresponding optimized machine code has finished compiling.
[0028] In some examples, compiler 240 may merge or remove some functions from bytecode 220 when compiling to optimized machine code 245. For example, bytecode functions F1 and F2 may be combined into optimized machine code function F1', while remaining separately as F1' and F2' in unoptimized machine code. Another bytecode function F3 (not shown) may not be represented in the optimized machine code, but may be merged into unoptimized machine code 235 as function F3'. In these cases, switching mechanism 250 is deployed in unoptimized machine code 235 at locations where jumps to corresponding positions in optimized machine code are possible. For example, switching mechanism 250 may be provided before machine code function F1', which can jump to the corresponding optimized machine code function F1', but not before unoptimized machine code function F2', because there is no corresponding optimized machine code function F2'. Depending on the configuration, some parts of bytecode 220 may be forced to have corresponding parts in optimized machine code, such as Main.
[0029] Figure 3 An example switching mechanism 250 is shown. Two pseudocode blocks 300 are shown to illustrate the changes in unoptimized machine code. The first pseudocode block 310 corresponds to the unoptimized machine code generated by generator function 225 and includes a Main section that calls various functions and an example function X section. Each section includes multiple machine code instructions, some of which are shown for illustrative purposes only. Each section also includes a nop, or "no operation," that the processor ignores and moves to the next instruction. This nop serves as a placeholder for a pointer to the optimized machine code in the future.
[0030] A separate thread checks if the compilation of the optimized machine code has finished. When this happens, the thread finds the memory address for each section of the unoptimized machine code (e.g., Main', F1', F2', etc.) and replaces the nop instructions in the unoptimized machine code with jmp instructions (pointer or jump instructions) to reach the beginning of the corresponding optimized machine code section (e.g., Main', F1', F2'). Thus, instead of the processor executing the unoptimized machine code instructions, the processor executes the instructions that jump to the corresponding optimized machine code. Since nop instructions are only replaced when the optimized machine code has finished compiling, execution can continue using the unoptimized machine code until that point.
[0031] The optimized machine code 245 can be compiled directly from bytecode 220, or using several intermediate steps described in more detail below. Various optimizations can be performed to make the optimized machine code execute more efficiently, faster, with lower resource intensity, and to achieve other performance enhancements. Some example optimizations that can be applied include: replacing some function calls with inline function instructions; loop unrolling; dead code elimination; and constant folding. Examples of LLVM optimizations are available in [link to LLVM optimizations]. https: / / llvm.org / docs / Passes.html Optimizations from other compiler providers can be found, however, and may be used alternatively. Even if unoptimized machine code employs some optimizations during its compilation, optimized machine code uses more optimizations, including those that are likely processor-intensive. In some examples, compiling optimized machine code uses the first set of optimizations, while compiling unoptimized machine code uses the second set. The first set of optimizations requires more processing resources, such as processor cycles and memory usage. The second set of optimizations used to compile unoptimized machine code will be implemented quickly but provides significant runtime improvements. In contrast, optimizations employed when compiling optimized machine code may require multiple passes of bytecode (and any intermediate representations) and may not scale linearly with the number of lines of bytecode. Figure 4 A method for executing an execution plan is illustrated. This method 400 can be performed by... Figure 1The processor 120 executes the query. At 405, method 400 receives the user query, for example, at user interface 150. At 410, the user query is parsed to determine the query shape and parameters.
[0032] At 415, execution plan 210 is generated. The execution plan can be generated by any known process and includes multiple operators 215. At 420, the method transforms execution plan 220 into bytecode 220, which is a sequence of bytecode instructions or opcodes. Bytecode 220 can be constructed into a Main section and multiple function parts called by the Main section. Various operators 215 of the execution plan can be implemented by calling specific sequences of functions with appropriate argument parameters. An example function is the COMPARISON function, but many other functions exist.
[0033] At 430, this method compiles bytecode into unoptimized machine code. Compilation transforms individual lines of bytecode or opcodes into corresponding machine code by looking up appropriate code reuse lookup tables, such as the ASMJIT machine code library. Such methods typically do not allow for machine code optimization; however, this type of compilation is fast to implement and quickly produces usable (unoptimized) machine code.
[0034] At 435, the method begins execution of the generated execution plan by executing unoptimized machine code. This allows processing of user queries to begin quickly before the optimized machine code for the query is compiled. Compiling machine code for new user queries is typically the most time- and resource-intensive aspect of processing user queries, and relying solely on this can result in significant delays for users.
[0035] At 440, this method compiles optimized machine code. This can be achieved using the LLVM compiler, but alternatively, other compilers such as, for example, the GNU C compiler and the Green Hills compiler can be used. The compilation of optimized machine code can occur after the execution of unoptimized machine code has begun, or the compilation of optimized machine code can begin before this time, and can run in parallel with the compilation of unoptimized machine code.
[0036] At 445, the method determines whether the optimized machine code has been compiled. This can be implemented using a separate thread that periodically checks the compiler's completion status, for example, by setting a flag while the optimized machine code is being compiled. The method can then simply check the flag—which is shown by the dashed line.
[0037] At 450, once the optimized machine code has finished compiling, the method switches to executing the execution plan using the optimized machine code. This can be achieved using a switching mechanism in the unoptimized code that instructs a jump to the corresponding part of the optimized machine code, as described earlier. For example, jump instructions can be inserted into the unoptimized machine code, replacing nop instructions, so that when they are executed, execution jumps to the corresponding part of the optimized machine code. If the optimized machine code is still compiling, the method returns to 435 and continues executing the execution plan by executing the unoptimized machine code.
[0038] The runtime of a new query is a combination of the time spent compiling the query plan and the time spent executing the compiled query plan. The method described above significantly reduces the runtime of new user queries because when switching to optimized machine code, a portion of the query plan has already been executed using unoptimized machine code, thus slowing down the overall processing speed of user queries. Furthermore, when the unoptimized machine code is compiled quickly, this method can quickly begin processing, allowing query results to start returning rapidly. It has been found that while this method is slightly slower (~10%) to compile the query plan than to convert it to bytecode, it is approximately 2.5 times faster to execute than to interpret bytecode, resulting in an average improvement of approximately 33% in the runtime of new queries.
[0039] While in the example above all bytecode was compiled into optimized machine code, in other examples only some bytecode can be compiled into optimized machine code. For example, some execution plan operators may involve significant processing resources, while others may not. Therefore, in some cases, it may be decided to compile optimized machine code for resource-intensive operators or functions (such as "hot" functions that may be called multiple times). Unoptimized machine code can rely on less resource-intensive operators, such as functions that are only called relatively infrequently. This can be configured by the user according to their preferences. In this example, with optimized machine code compiled, execution jumps from the unoptimized machine code section to the corresponding optimized machine code section, but then returns to the unoptimized machine code. In this way, the execution plan switches between compiled unoptimized machine code and compiled optimized machine code. In summary, this is still faster than using only unoptimized machine code and starts returning results faster than using only optimized machine code.
[0040] Figure 5 This illustrates a method for processing user queries based on an example. This can be achieved by... Figure 1The method is implemented using processor 120. At 505, the method receives a user query, such as a query to search database 130. At 510, the method generates a corresponding query execution plan. At 515, the method converts the execution plan into corresponding bytecode. These processes can be as described previously. In some examples, the method may check for matching user queries that have already been compiled into machine code. If a match is found, the compiled machine code can be reused. If this is not the case, for example, if this is the first time a particular user query has been received, the method proceeds to the next step.
[0041] At 520, the method optionally generates unoptimized machine code as described above. This can be achieved, for example, using a machine code reuse lookup table LUT1, which replaces bytecode portions row by row with machine code portions. LUT1 may correspond to... Figure 2 The machine code lookup table is located at 230. At 525, the method begins executing unoptimized machine code. In an alternative example, these two procedures 520 and 525 are not implemented.
[0042] At 530, the method converts bytecode into an unoptimized LLVM IR. The LLVM intermediate representation (IR) is a language-independent intermediate representation of bytecode. The intermediate representation (IR) is similar to text or pseudocode and effectively explains the intent of the code. Many different source code or bytecode languages can be converted to LLVM IR, which can then be converted into many different types of machine code, such as x86. LLVM is an open-source tool (…). https: / / llvm.org / ) is used to manipulate and / or compile various types of bytecode and source code into machine code. For example, bytecode can be converted to LLVM IR using the LLVM library, but other converters and libraries can also be used.
[0043] At position 535, the method hashes the LLVM IR and compares the resulting hash value with a hash value stored in the machine code reuse lookup table LUT2. The LUT contains the hash value and a pair of pre-compiled optimized machine code. An example hash function is md5sum(), which has a 128-bit output regardless of how many input bits the LLVM IR uses. However, other hash functions can be used alternatively.
[0044] The machine code reuse lookup table (LUT2) can include compiled, optimized machine code corresponding to multiple different language-independent intermediate representations. These may correspond to previously processed user queries that are the same as or have the same language-independent intermediate representation as the current user query. For example, `user_query_x` may have previously been processed into `LLVM_IR_x`, producing compiled machine code `mc_x`. When `user_query_x` is received again and converted to `LLVM_IR_x`, LUT2 will contain the corresponding pre-compiled machine code that can be reused. In another case, the wording of the user query may be different, i.e., `user_query_y`, but it is essentially the same query and produces the same execution plan. In this case, the execution plan will be converted to the same bytecode and the same language-independent intermediate representation `LLVM_IR_x`. In this case, the pre-compiled machine code `mc_x` can also be used for `user_query_y`.
[0045] In another scenario, when the underlying database management system (DBMS) software is upgraded, all existing query plans may be marked as obsolete because, in some cases, their pre-compiled machine code may no longer be compatible with the changed underlying code of the DBMS. However, in many cases, the pre-compiled machine code can still work on the upgraded DBMS. To avoid redundant recompilation of all compiled user queries, their language-independent intermediate representations can be checked for matching. For example, before the DBMS upgrade, user_query_x produces a generated execution plan e_p_x, which is translated into bytecode bc_x, which is then translated into LLVM_IR_x. After the DBMS upgrade, the same user query user_query_x may produce a modified execution plan e_p_x' and / or modified bytecode bc_x', but this is ultimately translated into the same language-independent intermediate representation LLVM_IR_x because it is a simpler pseudocode for setting up the user query's implementation. Since the language-independent intermediate representation of the user query `user_query_x` is the same before and after the DBMS upgrade, its hash value will be identical, and the pre-compiled machine code can be reused. In some cases, the language-independent intermediate representation of a particular user query `user_query_z` will not match – `LLVM_IR_z` relative to `LLVM_IR_z'` – in which case the user query will need to be recompiled. However, overall, this approach reduces the amount of user query recompilation required. This method saves the time spent optimizing the intermediate representation and compiling the optimized intermediate representation into optimized machine code.
[0046] At 540, the method checks if the hash value of the LLVM IR matches the hash value in the lookup table. If it matches, the method moves to 545, where the pre-compiled machine code corresponding to the matching hash value is reused. Then, the method moves to 560.
[0047] If a match is not found at 540, the method moves to 550, where it generates an optimized LLVM IR. This can also happen if the lookup process fails and no stored compiled machine code is found. LLVM tools can perform various optimizations, and this can be determined in advance and then applied to all subsequent query processing. Optimizations can be chosen based on the user, query, or other factors, or they can be fixed for all users and queries. At 555, the method compiles the optimized LLVM IR into optimized machine code. Again, this functionality can be provided by LLVM tools or similar compiler providers. The LLVM IR optimization and compilation process is computationally intensive; however, the LLVM IR hash matching at 540 and code reuse at 545 described above reduces the number of these processes required.
[0048] At 560, the method executes the compiled optimized machine code. The optimized machine code can be received from reuse path 545, or from LLVM IR optimization and compilation paths 550 and 555. If unoptimized machine code has already been generated and executed from 525, the execution plan is switched to the optimized machine code as described above.
[0049] At point 565, this method adds the compiled optimized machine code to the LUT2 for reuse in matching LLVMIR. The compiled optimized machine code can also be stored for reuse in matching user queries.
[0050] When a user queries an LLVM IR hash value that matches a value stored in the cache, the LUT2 or cache of the pre-compiled machine code persists during the upgrade process to enable subsequent optimization and machine code reuse.
[0051] This method enables the reuse of machine code even when queries are identical but the generated execution plans or bytecode differ. This can occur, for example, when the underlying software of a database management system is updated, resulting in some queries having different query plans and / or bytecode. For these queries, the machine code also needs to be updated, which is costly in terms of time and system resources. This method avoids some of this recompilation by checking for matches at the LLVM IR level, as this should be the same for the same query, even if the execution plan or bytecode differs after a system upgrade. Therefore, this method reduces redundant compilation and thus reduces query latency.
[0052] This approach can be further enhanced by configuring the bytecode transformed from the query plan to call generic helper functions, rather than inlining the helper functions within the query plan bytecode. With the generic helper functions external, the unoptimized LLVM IR will only contain calls to the helper functions, not their bodies. In this case, even if an upgrade affects the helper functions, the LLVM IR of the query will not change after the upgrade. In other words, the hash value of the LLVM IR will be the same, and therefore the pre-compiled machine code can be reused.
[0053] This method can also be used to warn database developers that changes to their databases will invalidate the compiled machine code because the resulting LLVM IR hash value will no longer match anything contained in the lookup table.
[0054] Figure 5 The method can be with Figure 4 The methods can be used in combination, or they can be used independently.
[0055] Figure 6 This illustrates the distribution of optimization and compilation across the nodes in the node cluster. As mentioned earlier, compiling (including optimizing) machine code requires considerable processor, memory, and time resources. Distributing these tasks across the nodes prevents any single node from becoming overloaded, which could impact the performance of other user query processing, such as causing query latency.
[0056] A database management system 600 is illustrated, comprising multiple nodes 655. Two user queries are shown: query 1 605 and query 2 615. Each query is translated into a language-independent intermediate representation, such as the LLVM IR described previously. Query 1 is translated in LLVM IR1 610, and query 2 is translated in LLVM IR2 620. The system includes a hash function 630 that hashes each LLVM IR to generate a corresponding hash value—for example, 111 for LLVM IR1 and 333 for LLVM IR2. These specific hash values are shown for illustrative purposes only.
[0057] Each hash value is examined against the lookup table LUT2 640. LUT2 consists of pairs of hash values and pre-compiled machine code. In the case of hash value 111, the corresponding pre-compiled machine code entry exists in LUT2 640. The machine code paired with hash value 111 can then be reused for query 1. Pre-compiled machine code reuse 645 can be performed as previously discussed. Figure 5 This can be implemented as described above, but other implementation methods are also possible. In the case of hash value 333, there is no corresponding entry in lookup table 640, therefore the machine code for query 2 needs to be compiled. Similarly, this can be done as previously discussed... Figure 5This can be achieved using the method described above, but other implementation methods can also be used.
[0058] System 600 includes a distribution function 650 that distributes the task of compiling the machine code for query 2 to one of the nodes in a node cluster. In this example, the node cluster consists of ten nodes 655, and the distribution function assigns compilation to node 3 655-3 by using the modulo10 function on the hash value of the language-independent intermediate representation LLVM IR2 of query 2. For example, mod10(333) = 3, corresponding to node 3 to which the compilation of query 2 is assigned. The distribution function 650 then sends the unoptimized LLVM IR to node 3 for optimization and compilation. Once completed, node 3 adds the optimized machine code for query 2 to its local LUT2 table and then returns the optimized machine code.
[0059] The modulus of the distribution function can vary depending on the number of nodes in the cluster. In other examples, different mathematical functions can be used to distribute compilation tasks to nodes within the cluster. The distribution function 650 can be arranged to distribute the compilation overhead evenly across the nodes in a deterministic manner, such that the same LLVM IR is always sent to the same node for compilation (or inspection of compiled machine code). This will occur even when the number of nodes changes.
[0060] Initial user query processing, including generating execution plans, converting to bytecode, and converting to LLVM IR, can be performed on the first node, and LLVM IR optimization and / or compilation to machine code can be performed on the second node within the cluster.
[0061] The distribution function also ensures that optimizations / compilations for a specific LLVM IR are always sent to the same node. This means that if an LLVM IR has already been locally compiled and cached at that node, it is readily available for reuse by that node. Similarly, because LLVM IRs with the same hash value are sent to the same node, that node can quickly recover pre-compiled machine code.
[0062] This means that instead of compiling the query individually on each node, if the same query is launched on different nodes, this method assigns the compilation of the query to a single node based on the hash value and a mathematical function, allowing for the reuse of already compiled machine code. This avoids the repeated compilation of the same user query, which often occurs when users run the same query on different aggregator nodes. Since optimization and compilation are time-consuming and processor-intensive, avoiding this type of redundant processing reduces query latency and increases query throughput by freeing up additional processor resources.
[0063] Once the assigned node has compiled the machine code for user queries, it can send it back to the node receiving the user queries, so that the compiled machine code can be cached locally and at the assigned node where the compilation was performed.
[0064] This method avoids redundant compilation and distributes the compilation workload across different nodes in the cluster. Since the output of a hash function is typically evenly distributed, the workload is evenly distributed across all nodes. Therefore, no single node is overwhelmed by compilation work. Increasing the number of nodes in the cluster reduces the compilation work done by each node—for example, expanding the number of nodes from 10 to 20 can halve the number of queries that each node must compile.
[0065] Figure 6 The method can be with Figure 4 and / or Figure 5 The methods can be used in combination or independently of them.
[0066] In one aspect, a computer-implemented method is provided, comprising: generating an execution plan for a received user query; converting the execution plan into bytecode; converting the bytecode into a language-independent intermediate representation; determining that the language-independent intermediate representation corresponds to previously compiled machine code; and, in response, executing the previously compiled machine code to execute the execution plan.
[0067] In some implementations, the language-independent intermediate representation is hashed to determine a hash value, which is then compared with other hash values corresponding to pre-compiled machine code.
[0068] The language-independent intermediate representation is LLVM IR. Other hash values can be stored in lookup tables, each with corresponding pre-compiled machine code. When no matching hash value is found, LLVM IR is optimized and compiled into machine code, which is then added to the lookup table along with the LLVM IR hash.
[0069] This aspect can be combined with the previously described approach of generating unoptimized and optimized machine code in parallel and switching to optimized machine code upon completion of compilation.
[0070] On the other hand, a computer-implemented method is provided, comprising: generating an execution plan for a received user query; converting the execution plan into bytecode; converting the bytecode into a language-independent intermediate representation; and distributing the compilation of machine code for the user query to nodes in a node cluster that depends on the user query.
[0071] In some implementations, the method includes compiling machine code using bytecode. The bytecode can be converted into a language-independent intermediate representation, such as LLVM IR, and then compiled to obtain machine code.
[0072] The allocation of compiled machine code can depend on a language-independent intermediate representation. The allocation of compiled machine code can depend on the hash value of the language-independent intermediate representation. The allocation of compiled machine code can depend on a mathematical function applied to the hash value. This mathematical function can be modulo, which depends on the number of nodes in the cluster.
[0073] The hash values of the language-independent intermediate representations for different queries can be stored in the lookup table along with the pre-compiled machine code used for these queries.
[0074] At least some aspects of the examples described herein include computer processes executed in a processing system or processor. However, in some examples, this extends to computer programs, particularly those on or within a carrier that puts the examples into practice. The program can be in the form of non-transitory source code, object code, intermediate source code, and object code (such as partially compiled forms), or any other non-transitory form suitable for implementing the processes according to the invention. The carrier can be any entity or device capable of carrying a program. For example, the carrier can include storage media such as solid-state drives (SSDs) or other semiconductor-based RAM; ROMs such as CD ROMs or semiconductor ROMs; magnetic recording media such as floppy disks or hard disks; general optical storage devices; etc.
[0075] In the preceding description, for illustrative purposes, numerous specific details of certain examples have been presented. References to "example" or similar language in the specification mean that a particular feature, structure, or characteristic described in connection with that example is included in at least one example, but not necessarily in other examples.
[0076] The examples above should be understood as illustrative. It should be understood that any feature described with respect to any example may be used alone or in combination with other features described, and may also be used in combination with one or more features of any other example, or in any combination of any other example. Furthermore, equivalents and modifications not described above may be employed.
Claims
1. A computer-implemented method, comprising: Generate an execution plan for the received user query. The execution plan is converted into bytecode; The bytecode is compiled into unoptimized machine code, and the execution plan is started by executing the unoptimized machine code, wherein the compilation includes adding a switching mechanism to the unoptimized machine code; The bytecode is compiled into optimized machine code, while the unoptimized machine code is executed. When the optimized machine code has been compiled, the execution is switched to the optimized machine code in order to execute the execution plan. The switching is performed using the switching mechanism, which instructs a jump from a portion of the unoptimized machine code to a corresponding portion of the optimized machine code.
2. The computer-implemented method of claim 1, wherein the bytecode comprises a plurality of bytecode instructions, and the unoptimized machine code is compiled using lookup tables for pre-compiled machine code portions corresponding to the bytecode instructions.
3. The computer-implemented method of claim 2, wherein compiling the optimized machine code includes compiling optimized machine code for at least one of the operators in the execution plan.
4. The computer-implemented method of claim 1, wherein the unoptimized machine code comprises a plurality of functions, each function being associated with a machine code inspection section, the machine code inspection section being configured to check the completion of the compilation of the optimized machine code before invoking the function.
5. The computer-implemented method of claim 4, wherein each function of the unoptimized machine code has an operation-free instruction, which is replaced by a jump instruction pointing to the corresponding function in the optimized machine code.
6. The computer-implemented method of claim 1, further comprising executing a jump instruction to the unoptimized machine code during the compilation of the optimized machine code, the jump instruction pointing to the optimized machine code.
7. The computer-implemented method of claim 1, wherein when the same user query is received again, the optimized machine code is directly stored and executed.
8. The computer-implemented method of claim 1, further comprising converting the bytecode into a language-independent intermediate representation, and wherein compiling the optimized machine code using the bytecode comprises compiling the language-independent intermediate representation.
9. The computer-implemented method of claim 8, further comprising determining that the language-independent intermediate representation corresponds to previously compiled optimized machine code, and in response, executing the previously compiled optimized machine code.
10. The computer-implemented method of claim 9, wherein determining that the language-independent intermediate representation corresponds to previously compiled optimized machine code comprises: A lookup table is provided having previously compiled optimized machine code for multiple language-independent intermediate representations, each language-independent intermediate representation corresponding to a corresponding hash code; Hash the language-independent intermediate representation to compute the hash value; Check the lookup table for hash codes that match the hash value.
11. The computer-implemented method as described in claim 1, wherein Generate an execution plan for the received user query. The execution plan is converted into bytecode; The unoptimized machine code is compiled using the bytecode, and the execution plan is initiated by executing the unoptimized machine code; When the optimized machine code has been compiled, the optimized machine code is executed; It is executed on the first node; Furthermore, the compilation of the optimized machine code using the bytecode while simultaneously executing the unoptimized machine code is performed on the second node.
12. The computer-implemented method of claim 11, further comprising selecting a node from a plurality of nodes as the second node depending on the user query.
13. The computer-implemented method of claim 12, wherein the selection node comprises: The bytecode is converted into a language-independent intermediate representation; The language-independent intermediate representation is hashed to compute a hash value; as well as A mathematical function is performed on the hash value to select the second node.
14. The computer-implemented method of claim 1, wherein compiling the optimized machine code uses processor and memory resources to implement a first set of optimizations, and compiling the unoptimized machine code uses processor and memory resources to implement a second set of optimizations, wherein the first set of optimizations uses more processor and memory resources than the second set of optimizations.
15. A database system for performing queries on data stored in the database system, the database system comprising: One or more processors; A storage device includes computer-executable instructions that, when executed by the one or more processors, cause the database system to perform the method as described in any one of claims 1 to 14.
16. A non-transitory computer-readable storage medium comprising computer-executable instructions that, when executed by one or more processors, cause the one or more processors to perform the method as described in any one of claims 1 to 14.
Citation Information
Patent Citations
Recipient-driven traffic optimizing overlay systems and methods
US20160182409A1
Dynamic query optimization
US20210133193A1
