Database instance processing method and apparatus, electronic device, computer-readable storage medium and computer program product
By building and filtering database execution templates, customized database instances are generated in response to query statements, the inefficiency and resource waste caused by dynamic compilation in the existing technology is solved, and more efficient resource utilization and query efficiency is achieved.
Patent Information
- Application Number
- PCT/CN2024/098689
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-08-17
- Filing Date
- 2024-06-12
- Publication Date
- 2025-02-20
AI Technical Summary
In existing database query technology, dynamic compilation leads to low query efficiency, and a full number of standard database instances need to be executed each time, resulting in low resource utilization.
By obtaining multiple sample query statements and their corresponding calculation elements, a database execution template is built, and multiple templates are filtered to generate a target database execution template, and then a corresponding database instance is generated in response to the target query statement.
It realizes streamlined processing of multiple database execution templates, avoids redundant resource occupation, improves database resource utilization, and improves query efficiency of query statements by executing customized database instances.
Smart Images

Figure CN2024098689_20022025_PF_FP_ABST
Abstract
Description
Database instance processing method, device, electronic device, computer-readable storage medium, and computer program product
[0001] CROSS-REFERENCE TO RELATED APPLICATIONS
[0002] This application is based on the Chinese patent application with application number 2023110360464 and application date of August 17, 2023, and claims the priority of the Chinese patent application. The entire content of the Chinese patent application is hereby incorporated into this application by reference. Technical Field
[0003] The present application relates to database technology, and in particular to a database instance processing method, device, electronic device, computer-readable storage medium, and computer program product. Background Art
[0004] Database query refers to selecting the data fields required by the user from a defined database. It is generally a direct query operation on the database table in the data source. When using query statements to query, the query statements need to be compiled. The dynamic compilation technology of the database in related technologies is to judge and compile during the execution of the data set instance corresponding to the query statement, resulting in very low query efficiency. In addition, each compilation executes the full amount of standard database instances, resulting in low instance resource utilization of the database during the query.
[0005] Summary of the Invention
[0006] Embodiments of the present application provide a database instance processing method, apparatus, electronic device, computer-readable storage medium, and computer program product, which can improve the query efficiency of query statements and the resource utilization of the database.
[0007] The technical solution of the embodiment of the present application is implemented as follows:
[0008] An embodiment of the present application provides a database instance processing method, which is executed by an electronic device and includes:
[0009] Obtaining multiple sample query statements for a database, and obtaining at least one computational element corresponding to the database for each of the sample query statements;
[0010] For each of the sample query statements, forming a database execution template of the sample query statement by corresponding at least one computing element of the database to the sample query statement;
[0011] Screening the plurality of database execution templates corresponding to the plurality of sample query statements to obtain a target database execution template;
[0012] A database instance corresponding to each target database execution template is generated, wherein any database instance is used to respond to a target query statement corresponding to any database instance when executed.
[0013] An embodiment of the present application provides a database instance processing device, including:
[0014] an acquisition module configured to acquire a plurality of sample query statements for a database, and acquire at least one computational element of the database corresponding to each of the sample query statements;
[0015] a template module configured to, for each of the sample query statements, transform the sample query statement into a database execution template corresponding to at least one computing element of the database;
[0016] a screening module configured to screen the plurality of database execution templates corresponding to the plurality of sample query statements to obtain a target database execution template;
[0017] A generation module is configured to generate a database instance corresponding to each target database execution template, wherein any database instance is used to respond to a target query statement corresponding to any database instance when executed.
[0018] An embodiment of the present application provides an electronic device, including:
[0019] a memory for storing computer-executable instructions;
[0020] The processor is used to implement the database instance processing method provided in the embodiment of the present application when executing the computer executable instructions stored in the memory.
[0021] An embodiment of the present application provides a computer-readable storage medium storing computer-executable instructions for causing a processor to execute the instructions to implement the database instance processing method provided in the embodiment of the present application.
[0022] An embodiment of the present application provides a computer program product, including computer-executable instructions. When the computer-executable instructions are executed by a processor, the database instance processing method provided in the embodiment of the present application is implemented.
[0023] The embodiments of the present application have the following beneficial effects:
[0024] Based on at least one computing element of the database corresponding to each sample query statement, a database execution template corresponding to each sample query statement is constructed, and multiple database execution templates corresponding to multiple sample query statements are screened and processed to obtain a target database execution template, thereby realizing streamlined processing of multiple database execution templates, avoiding the resource occupation of the database by redundant or low-utilization database execution templates, and improving the resource utilization of the database; based on each target database execution template, a corresponding database instance is generated to respond to the target query statement of the corresponding database instance, so that by executing customized database instances, only part of the database instances need to be executed to respond to the query statement. Compared with the method in which the related technology needs to execute a full amount of standard database instances to respond to the query statement, the volume of database instances required to be executed to respond to the query statement can be reduced, thereby improving the query efficiency of the query statement. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] FIG1 is a schematic diagram of the structure of a database instance processing system provided in an embodiment of the present application;
[0026] FIG2 is a schematic structural diagram of an electronic device provided in an embodiment of the present application;
[0027] FIG3A is a schematic diagram of a first flow chart of a database instance processing method provided in an embodiment of the present application;
[0028] FIG3B is a schematic diagram of a second flow chart of the database instance processing method provided in an embodiment of the present application;
[0029] FIG3C is a schematic diagram of a third flow chart of the database instance processing method provided in an embodiment of the present application;
[0030] FIG3D is a schematic diagram of a fourth flow chart of the database instance processing method provided in an embodiment of the present application;
[0031] FIG4 is a schematic diagram of a first information structure of a database instance processing method provided in an embodiment of the present application;
[0032] FIG5 is a schematic diagram of a second information structure of the database instance processing method provided in an embodiment of the present application;
[0033] FIG6 is a schematic diagram of a third information structure of the database instance processing method provided in an embodiment of the present application;
[0034] 7 is a fourth information structure diagram of the database instance processing method provided in an embodiment of the present application;
[0035] FIG8 is a schematic diagram of a database structure of a database instance processing method provided in an embodiment of the present application;
[0036] FIG9 is a schematic diagram of the database module structure of the database instance processing method provided in an embodiment of the present application;
[0037] 10 is a schematic diagram of the database module structure of a query statement of a database instance processing method provided in an embodiment of the present application;
[0038] FIG11 is a schematic diagram of a template structure of a database instance processing method provided in an embodiment of the present application;
[0039] FIG12 is a schematic diagram of template screening of a database instance processing method provided in an embodiment of the present application;
[0040] FIG13 is a schematic diagram of calling a database instance of the database instance processing method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solutions and advantages of this application clearer, the application will be further described in detail below with reference to the accompanying drawings. The described embodiments should not be regarded as limiting this application. All other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0042] In the following description, reference is made to “some embodiments”, which describes a subset of all possible embodiments, but it will be understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.
[0043] In the following description, the terms "first\second\third" involved are merely used to distinguish similar objects and do not represent a specific ordering of the objects. It can be understood that "first\second\third" can be interchanged with a specific order or sequence where permitted, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein.
[0044] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or a part of a computer program that has a predetermined function and works together with other related parts to achieve a predetermined goal, and can be implemented in whole or in part by using software, hardware (such as processing circuits or memories) or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the function of the module or unit.
[0045] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only and are not intended to limit this application.
[0046] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.
[0047] 1) Database: A repository for data. A database is essentially a collection of data files (usually binary files). These files record data in a specific format and are stored in a directory on a server. Collectively, these files form a database. A database is a collection of files, organized according to a data model and stored in secondary storage.
[0048] 2) Database instance: A database instance is a database program that accesses a database. It is impossible and not allowed for users to directly operate database files through the file system to add, delete, check, modify, or perform any operations on files (data) in the database, including data definition, data query, data maintenance, and database operation control. This requires the help of a database instance, that is, these operations are all performed under a database instance. The database instance is the channel for users (programmers) to access the database. Only through a database instance can they interact with the database. The database instance implements the encapsulation of database operations and the parsing of Structured Query Language (SQL), allowing users to operate database contents in a simple and direct way using SQL.
[0049] 3) Execution Plan: This refers to the execution process or access path of a query statement in the database. An execution plan consists of multiple sequential steps, each of which includes multiple operators. Operators are the specific actions performed in each step. For example, step A in the execution plan of a query statement includes the SELECT operator, step B includes the WHERE operator, and step C includes the GROUP BY operator.
[0050] 4) Computational Elements: These are database modules within the database layer that perform different functions. They are used to execute each operator in a query statement and carry the specific database code for the computational logic corresponding to each operator. Examples include the cluster node module, selection node module, and insertion node module within the compiler layer.
[0051] 5) Database execution template: A template composed of at least one computational element (database module) of the database corresponding to the query statement, in the hierarchical order of the computational elements, used to respond to the corresponding query statement. For example, query statement 1 involves the cluster node module and the selection node module in the compiler layer, forming the computational element set A {cluster node module, selection node module}; involves the transitive closure module in the query rewrite layer, forming the computational element set B {transitive closure module}; involves the hop index and the connection computation module in the query path selection layer, forming the computational element set C {hop index, connection computation module}; computational element sets A to G are sorted in hierarchical order, with the sorting result being A→B→C. Finally, based on the sorted computational element sets, a database execution template is formed, namely {cluster node module, selection node module}→{transitive closure module}→{hop index, connection computation module}.
[0052] 6) Sample query statements: During the database instance construction phase, query statements generated by an application running on an electronic device are used to perform specific operations on the database. For example, if the application is an instant messaging client, the query statement can be used to query a user's current social relationships or to query messages received or sent by a user within a specific time period.
[0053] 7) Target query statements: After constructing the database instance, the query statements generated when the application is running in the electronic device can be responded to using the database instance first.
[0054] The dynamic compilation technology of the database in the related art is to judge and compile during the execution process. Taking Just-in-Time (JIT) compilation as an example, JIT compilation is the process of converting an interpreted program into a native program at runtime. JIT compilation is mainly beneficial for long-running CPU-intensive queries. These are usually analytical queries. For short queries, the cost of executing JIT compilation is often higher than the time it can save. First, if the evaluation cost is greater than the JIT estimate setting, short functions and operators in the query will be inlined. Second, if the evaluation cost is greater than the JIT estimate setting, an expensive cost is used to improve the generated code. These options all increase the cost of JIT compilation.
[0055] Embodiments of the present application provide a database instance processing method, apparatus, electronic device, computer-readable storage medium, and computer program product, which can improve the query efficiency of query statements and the resource utilization of the database.
[0056] The following describes exemplary applications of electronic devices provided by embodiments of the present application. The electronic devices provided by embodiments of the present application can be implemented as various types of user terminals, such as laptop computers, tablet computers, desktop computers, set-top boxes, mobile devices (e.g., mobile phones, portable music players, personal digital assistants, dedicated messaging devices, portable gaming devices), and can also be implemented as servers. The following describes exemplary applications of electronic devices implemented as servers.
[0057] Refer to Figure 1, which is a structural diagram of the database instance processing system provided in an embodiment of the present application. The terminal 400 is connected to the server 200 through the network 300. The network 300 can be a wide area network or a local area network, or a combination of the two.
[0058] In some embodiments, the database instance processing method provided by the embodiments of the present application can be implemented collaboratively by a terminal and a server. The terminal 400 receives an operation of a user using an application in an electronic device, and the terminal 400 sends the operation data to the server 200. The server 200 detects sample query statements generated by the user for the database 500 during the use of the application from the operation data, and obtains at least one computational element of the database corresponding to each sample query statement; for each sample query statement, based on the at least one computational element of the database corresponding to the sample query statement, a database execution template corresponding to the sample query statement is constructed; multiple database execution templates corresponding to the multiple sample query statements are screened to obtain a target database execution template; a database instance corresponding to each target database execution template is generated, and any database instance is executed to respond to the target query statement corresponding to any database instance. The terminal 400 receives the target operation of the user using the application and sends the target operation data to the server 200. The server 200 detects the target query statement generated by the user during the use of the application from the target operation data, and the target query statement has a corresponding database instance. The server 200 executes the database instance corresponding to the target query statement to obtain a response result from the database 500, and returns the response result to the terminal 400 for presentation.
[0059] In some embodiments, the database instance processing method provided in the embodiments of the present application can also be implemented independently by a terminal or a server. Taking the terminal alone as an example, the terminal 400 receives an operation of a user using an application in an electronic device, detects a sample query statement generated by the user for the database 500 during the use of the application from the operation data, and obtains at least one computational element of the database corresponding to each sample query statement; for each sample query statement, the database code of the at least one computational element of the database corresponding to the sample query statement is used to form a database execution template for the sample query statement; multiple database execution templates corresponding to the multiple sample query statements are filtered and processed to obtain a target database execution template; a database instance corresponding to each target database execution template is generated, and any database instance is used to be executed to respond to the target query statement corresponding to any database instance. The terminal 400 receives a target operation of the user using the application, detects a target query statement generated by the user during the use of the application from the target operation data, and the target query statement has a corresponding database instance. The terminal 400 executes the database instance corresponding to the target query statement to obtain a response result from the database 500, and presents the response result on the terminal 400.
[0060] In some embodiments, the server 200 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The terminal 400 can be a smart phone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, smart voice interaction device, smart home appliance, vehicle-mounted terminal, aircraft, etc., but is not limited to this. The terminal and the server can be directly or indirectly connected via wired or wireless communication, which is not limited in the embodiments of the present application.
[0061] Cloud technology is a general term for network technologies, information technologies, integration technologies, management platform technologies, and application technologies based on the cloud computing business model. It can form a resource pool that can be used flexibly and conveniently on demand. Cloud computing technology will become a crucial support. Backend services for technical network systems, such as video websites, image websites, and more portals, require extensive computing and storage resources. With the rapid development and application of the internet industry, every item will likely have its own unique identifier, requiring transmission to backend systems for logical processing. Different levels of data will be processed separately, and data from various industries will require a strong system backend, which can only be achieved through cloud computing.
[0062] In some embodiments, the terminal or server can implement the database instance processing method provided in the embodiments of the present application by running a computer program. For example, the computer program can be a native program or software module in the operating system; it can be a native application (APP, Application), that is, a program that needs to be installed in the operating system to run, that is, a program that can be run by simply downloading it to a browser environment. In short, the above-mentioned computer program can be any form of application, module or plug-in.
[0063] Referring to Figure 2, Figure 2 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Taking the electronic device as a terminal as an example, the terminal 400 shown in Figure 2 includes: at least one processor 410, a memory 450, at least one network interface 420 and a user interface 430. The various components in the terminal 400 are coupled together via a bus system 440. It will be understood that the bus system 440 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 440 also includes a power bus, a control bus and a status signal bus. However, for the sake of clarity, various buses are labeled as bus system 440 in Figure 2.
[0064] The processor 410 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, a digital signal processor (DSP), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc., where the general-purpose processor can be a microprocessor or any conventional processor, etc.
[0065] The user interface 430 includes one or more output devices 431 that enable presentation of media content, including at least one of the following: one or more speakers, one or more visual display screens. The user interface 430 also includes one or more input devices 432, including user interface components that facilitate user input, such as a keyboard, mouse, microphone, touch screen display, camera, other input buttons and controls.
[0066] The memory 450 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state memory, hard drives, optical drives, etc. The memory 450 may optionally include one or more storage devices that are physically remote from the processor 410.
[0067] The memory 450 includes volatile memory or non-volatile memory, or may include both volatile and non-volatile memory. The non-volatile memory may be a read-only memory (ROM), and the volatile memory may be a random access memory (RAM). The memory 450 described in the embodiments of the present application is intended to include any suitable type of memory.
[0068] In some embodiments, the memory 450 can store data to support various operations, examples of which include programs, modules, and data structures, or a subset or superset thereof, as exemplified below.
[0069] Operating system 451, including system programs for processing various basic system services and performing hardware-related tasks, such as the framework layer, core library layer, and driver layer, which are used to implement various basic services and process hardware-based tasks;
[0070] A network communication module 452 is used to reach other electronic devices via one or more (wired or wireless) network interfaces 420. Exemplary network interfaces 420 include Bluetooth, Wi-Fi, and Universal Serial Bus (USB).
[0071] a presentation module 453 for enabling presentation of information via one or more output devices 431 (e.g., a display screen, a speaker, etc.) associated with the user interface 430 (e.g., a user interface for operating peripheral devices and displaying content and information);
[0072] The input processing module 454 is configured to detect one or more user inputs or interactions from one of the one or more input devices 432 and to translate the detected inputs or interactions.
[0073] In some embodiments, the database instance processing device provided in embodiments of the present application can be implemented using software. FIG2 shows a database instance processing device 455 stored in memory 450. This device can be software in the form of a program or plug-in, and includes the following software modules: an acquisition module 4551, a template module 4552, a screening module 4553, a generation module 4554, and a query module 4555. These modules are logical and can be arbitrarily combined or further separated according to the functions they implement. The functions of each module will be described below.
[0074] The database instance processing method provided in the embodiment of the present application will be explained in combination with the exemplary application and implementation of the electronic device provided in the embodiment of the present application.
[0075] As mentioned above, the electronic device that implements the database instance processing method of the embodiment of the present application can be a terminal or a server, or a combination of the two. Therefore, the execution subject of each step will not be repeatedly described below.
[0076] 3A , the database instance processing method provided in the embodiment of the present application can be applied to a terminal or a server, and will be described in conjunction with steps 101 to 104 shown in FIG. 3A .
[0077] In step 101, a plurality of sample query statements for a database are obtained, and at least one computational element of the database corresponding to each sample query statement is obtained.
[0078] As an example, a full query statement for the database can be obtained as a sample query statement, that is, whenever a query statement for a target object is received, the query statement for the target object is recorded. The target object here can be a single target object or multiple target objects.
[0079] In some embodiments, referring to FIG. 3B , obtaining multiple sample query statements for a database in step 101 may be implemented through steps 1011 to 1012 shown in FIG. 3B .
[0080] In step 1011, the application programs that have been run in the electronic device are detected.
[0081] As an example, one or more target objects may be detected to have run applications in the electronic device in the recent period (e.g., one month). The applications here may be all used applications or applications whose usage frequency exceeds an application frequency threshold.
[0082] In step 1012, a plurality of sample query statements for a database generated by the application during the running of the application are obtained.
[0083] As an example, the application here may be any application that needs to use a database, such as a social APP, and the sample query statement may be a sample query statement used by a user when using the social APP.
[0084] For example, the sample query statement may be used to obtain a social relationship, or may be used to obtain conversation content within a specific time period.
[0085] The database may refer to a single database, for example, detecting multiple query statements against database A during a user's use of a social APP. Since different databases have different hierarchical frameworks, if there are multiple databases, the data processing method provided in the embodiments of the present application may be executed separately for each database.
[0086] For example, sample database queries are extracted from the target user's application usage data, and the sample query statements involved in the application are labeled. Labeling can be done by using identifiers to characterize the sample query statements, such as labeling query statement 1 with identifier A and query statement 2 with identifier B. This allows for differentiation during subsequent query processing. This is specifically used to analyze the applications used by users and record the query statements involved in those applications.
[0087] Since the embodiment of the present application detects multiple query statements against the database during the process of the target object using the application, that is, the multiple query statements obtained are all query statements that will be used during actual use, the query statements obtained through the embodiment of the present application are more targeted in meeting user needs, thereby providing an effective basis for subsequent database instance generation and improving the generation value of the database instance.
[0088] In some embodiments, obtaining at least one computing element of the database corresponding to each sample query statement in step 101 can be achieved through the following technical solutions: hierarchically dividing the database to obtain multiple database layer structures of the database, wherein each database layer structure includes at least one candidate computing element; performing the following processing on each sample query statement: obtaining an execution plan of the sample query statement, and decomposing the execution plan to obtain at least one operator required for the execution plan; obtaining a computing element for executing the operator from multiple candidate computing elements of multiple database layer structures.
[0089] Through the embodiments of the present application, the computing elements necessary for executing the sample query statement can be obtained from the execution plan level of the sample query statement, thereby realizing modular customization of the query statement.
[0090] As an example, an execution plan is a description of the execution process or access path of a query statement in a database. Since these query statements are query statements generated for the database when users use the application, these query statements have actually been used. The database of related technologies can provide the function of downloading the execution plan, and the execution plan of the query statement can be obtained by direct download.
[0091] For example, an operator refers to the specific actions of each step in the execution plan corresponding to a query statement. Since an execution plan represents the execution process of a query statement in the database, it can include multiple steps arranged in sequence and the specific actions of each step. For example, step A in the execution plan, "SELECT T1.C1 FROM T1, T2," includes the SELECT operator, step B in the execution plan, "WHERE T1.C2 = T2.C2 AND T2.C2 = 1," includes the WHERE operator, and step C in the execution plan, "GROUP BY T1.C1," includes the GROUP BY operator. Decomposing the execution plan by step reveals the multiple steps it includes and the operators included in each step. An operator represents computational logic, and a computational element represents the database module used to execute that computational logic. The database module contains the specific database code corresponding to that computational logic.
[0092] In some embodiments, hierarchical division of the database to obtain multiple database layer structures of the database can be achieved through the following technical solutions: obtaining multiple types of functions involved in the database; and dividing the database into multiple database layer structures according to the multiple types of functions.
[0093] As an example, referring to FIG8 , a database can generally be divided into the following hierarchical levels, resulting in the following multiple database layer structures: compiler layer, query rewriting layer, query path selection layer, query execution layer, index management layer, data management layer, and buffer management layer. Each database layer structure includes multiple candidate computing elements. The computing elements here can be understood as database modules used to perform different functions in the layer structure.
[0094] Here, the compiler layer is used to parse query statements, detect syntax errors, and convert query statements into internal representations, such as abstract syntax trees. The query rewriting layer is used to parse the abstract syntax tree and perform syntax checking on many query statements involving rewriting rules, such as constraint-based rules. For example, this optimizes selection statements based on specific conditions and combines multiple conditions into a single conditional expression. However, some syntax does not require checking, such as exchange order rules and renaming rules. The query path selection layer is used to evaluate the execution time, resource consumption, and error rate of the query path, calculate the query path overhead, and select the execution path with the lowest overhead as the optimal execution plan. The query execution layer: executes user queries based on the generated query plan. The index management layer is used to support database indexing. Databases have multiple index types and operations, and user queries often only use a portion of these functions. The data management layer is used to support database data page management. There are also many types and operations of data pages. The data management layer is similar to the index management layer. The buffer management layer is used to manage database buffers, including database buffer allocation, recycling, and replacement strategies.
[0095] Referring to FIG9 , each database level can be further divided into different database modules according to the specific work of each level. The compiler layer includes the Group Node module, the Select Node module, the Insert Node module, etc.; the query rewrite layer includes the Push Down module, the Bubble Up module, and the Transitive Closure module; the query path selection layer includes the Index Skipping module and the Join Calculation module; the query execution layer includes the Join Exec Factor module, the Sort Exec Factor module, and the Subquery Exec Factor module; the index management layer includes the Index Scan module, the Index Tree Update module, and the Index Insert Buffer module; the data management layer includes the Insert Engine module, the Update Engine module, and the Workfile Engine module; and the buffer management layer includes the Buffer Pool Cache module, the Simulation Buffer module, and the Page Fix Buffer module.
[0096] Here, the cluster node module in the compiler layer is used to handle query compilation and optimization in a distributed environment; the node selection module is used to determine the database node that executes the query statement; the node insertion module is used to execute the operation of inserting the database node; the push-down module in the query rewrite layer is used to optimize the execution plan corresponding to the query statement, and can rewrite some complex query statements into simpler query statements so that the database engine can execute them faster; the bubbling module is used to iteratively process the expressions in the query statement, compare adjacent calculation elements and exchange them to better meet the optimization goals of the query statement, such as reducing nested queries, using indexes, etc.; the transitive closure module is used to In scenarios such as optimization and data integrity checking, additional association information and supplementary data are generated by calculating transitive closure; the hop index in the query path selection layer is used to indicate the number of hops of each node corresponding to the query statement in the path selection; the connection calculation module is used to calculate the overhead of the query path involved in the query statement; the connection execution factor module in the query execution layer is used to calculate and determine the connection relationship between two or more calculation elements; the classification execution factor module is used to classify the calculation elements involved in the query statement; the subquery execution factor module is used to execute the subquery statement and process its result as part of the main query statement, where the subquery statement is nested inside the main query statement Query statements can be nested in query statements of the select, update, delete or insert types; the index scan module in the index management layer is used to locate and obtain data that meets the query conditions in the index structure; the index tree update module is used to maintain and update the index tree structure in the database, where the index tree is a data structure used to speed up database queries. When the data in the database changes, such as insert, update or delete operations, the index tree update module will modify the index tree accordingly to reflect these changes; the index insert cache module is used; the insert engine module in the data management layer is used to process index insert operations; the update engine module is used to receive, parse and execute insert, update and delete operations. It is used to handle transaction commit and rollback, ensure data consistency and integrity, and process concurrent update operations to ensure that multiple simultaneous update operations do not interfere with each other or conflict with each other; the folder engine module is used to manage operations such as creation, deletion, movement, and search during the execution of query statements; the cache pool cache module in the buffer management layer is used to manage the cache of database pages in the database system, where the database page is the basic unit of data storage; the simulation cache module is used to provide cache access to data in the database; the page lock cache module is used to manage and maintain the lock status of database pages.
[0097] As an example, each query statement only uses some database modules in the database hierarchy. Take the following query statement as an example:
[0098] SELECT T1.C1 FROM T1, T2
[0099] WHERE T1.C2=T2.C2
[0100] AND T2.C2=1
[0101] GROUP BY T1.C1;
[0102] The execution plan corresponding to the above query statement is decomposed to obtain at least one operator required for the execution plan, including the SELECT operator, the GROUP BY operator, and the JOIN operator. Among them, the SELECT operator and the GROUP BY operator can be directly reflected in the query statement. Although the JOIN operator is not directly reflected in the query statement, the calculation logic represented by the JOIN operator needs to be used in the execution plan in actual application. Subsequently, the database modules (computing elements) involved in executing each layer of the above operators can be obtained.
[0103] Here, the SELECT operator is used to select columns or expressions to be retrieved from the database. For example, "SELECT T1.C1 FROM T1, T2" in the above example means querying tables T1 and T2 and selecting column C1 in table T1. The Group By operator is used to group the query results by specified columns. For example, "GROUP BY T1.C1" in the above example means grouping the query results according to column T1.C1, grouping data with the same value. The JOIN operator is used to retrieve related data from multiple tables for joint analysis or operations. For example, the above example uses the JOIN operator to retrieve data from tables T1 and T2 that meets the query condition "WHERE T1.C2 = T2.C2 AND T2.C2 = 1" so that the queried data can be subsequently grouped using the Group By operator.
[0104] As shown in Figure 10, the database modules within the dotted boxes are the database modules involved in each layer. These modules include the cluster node module and node selection module in the compiler layer; the transitive closure module in the query rewrite layer; the hop index and join calculation module in the query path selection layer; the join execution factor module and classification execution factor module in the query execution layer; the index scan module in the index management layer; the folder engine module in the data management layer; and the cache pool cache module in the buffer management layer.
[0105] As an example, executing the SELECT operator requires the use of the selection node module in the compiler layer, the transitive closure module in the query rewriting layer, the hop index in the query path selection layer, the index scanning module in the index management layer, the folder engine module in the data management layer, and the cache pool cache module in the buffer management layer.
[0106] As an example, executing the Group By operator requires the use of the cluster node module in the compiler layer, the transitive closure module in the query rewriting layer, and the classification execution factor module in the query execution layer.
[0107] As an example, executing a JOIN operator requires using the join calculation module in the query path selection layer and the join execution factor module in the query execution layer.
[0108] In step 102 , for each sample query statement, at least one computational element of the database corresponding to the sample query statement is used to form a database execution template for the sample query statement.
[0109] In some embodiments, referring to FIG3C , in step 102 , forming a database execution template of the sample query statement by corresponding at least one computing element of the database to the sample query statement can be achieved by executing steps 1021 to 1024 shown in FIG3C .
[0110] In step 1021 , the following processing is performed for each computing element: obtaining the database layer structure to which the computing element belongs in the database, and obtaining the hierarchical order of the database layer structure in the database.
[0111] As an example, the overall database structure includes multiple sequentially connected database layer structures, each of which includes multiple candidate computing elements. These candidate computing elements are at least one section of database code corresponding to different computing logic. The query statement is executed by executing each database code in the database hierarchy order. That is, each candidate computing element has a corresponding database layer structure in the overall database structure. Therefore, the database layer structure to which the candidate computing element belongs can be directly queried from the overall database structure. Here, the hierarchical order of each database layer structure in the database can be stored in a table, using a mapping relationship between the database layer structure and the hierarchical order, or the hierarchical order corresponding to each database layer structure can be stored as attribute information of the database layer structure.
[0112] As an example, the computational elements obtained in step 101 do not necessarily come from all database hierarchies. That is, only a portion of the database hierarchies may be used when executing a portion of a query statement. Therefore, step 1021 can be used to obtain the database hierarchies to which each computational element belongs, as well as the hierarchical order of the hierarchies within the database. As shown in Figure 8 , the compiler hierarchies are ranked first, and the buffer management layer is ranked last.
[0113] In step 1022, computing elements belonging to the same database layer structure are grouped into a computing element set.
[0114] As an example, referring to Figure 10, the cluster node module and the selection node module in the compiler layer are combined into a computational element combination; the transitive closure module is combined into a computational element combination. Here, the cluster node module, the selection node module, and the transitive closure module are all computational elements.
[0115] In step 1023 , when the number of the calculation element set is one, the calculation element set is used as a database execution template.
[0116] As an example, when there is only one computing element set, which indicates that all computing elements are from one database layer structure, the computing element set is used as a database execution template.
[0117] In step 1024 , when there are multiple computing element sets, the computing element sets corresponding to different database layer structures are sorted in hierarchical order, and the sorted multiple computing element sets are used to form a database execution template.
[0118] As an example, referring to Figure 11, query statement 1 involves the cluster node module and the selection node module in the compiler layer, forming computation element set A; the transitive closure module in the query rewrite layer, forming computation element set B; the hop index and join computation modules in the query path selection layer, forming computation element set C; the join execution factor module and the classification execution factor module in the query execution layer, forming computation element set D; the index scan module in the index management layer, forming computation element set E; the folder engine module in the data management layer, forming computation element set F; and the cache pool cache module in the buffer management layer, forming computation element set G. Computation element sets A through G are sorted hierarchically, and the sorted computation element sets form a database execution template. This means that the database execution template can also represent the calling order of the computation elements.
[0119] In step 103, a plurality of database execution templates corresponding to the plurality of sample query statements are screened to obtain a target database execution template.
[0120] In some embodiments, referring to FIG. 3D , in step 103 , the plurality of database execution templates corresponding to the plurality of sample query statements are screened to obtain the target database execution template, which can be achieved through steps 1031 to 1032 shown in FIG. 3D .
[0121] In step 1031 , duplicate database execution templates are filtered from multiple database execution templates to obtain at least one intermediate database execution template.
[0122] In some embodiments, if there are two or more identical database execution templates among the multiple database execution templates, redundancy filtering is performed on the duplicate database execution templates, and only one of the identical database execution templates is retained to obtain at least one intermediate database execution template.
[0123] As an example, if there are two identical database execution templates A and B, then any one of the database execution templates is deleted, so that the remaining database execution templates are different.
[0124] In step 1032, at least one intermediate database execution template is deleted, and the remaining intermediate database execution templates are used as target database execution templates.
[0125] In some embodiments, the above-mentioned deletion processing of at least one intermediate database execution template and using the remaining intermediate database execution templates as target database execution templates can be achieved through the following technical solution: performing the following processing for each intermediate database execution template: obtaining a sample query statement corresponding to the intermediate database execution template; when the sample query statement corresponding to the intermediate database execution template meets the deletion condition, deleting the intermediate database execution template; and using the intermediate database execution templates remaining after the deletion as the target database execution template.
[0126] The embodiments of the present application can streamline the number of target database execution templates, thereby avoiding the occupation of database resources by redundant or low-utilization database execution templates, thereby improving the resource utilization of the database.
[0127] In some embodiments, the deletion condition includes at least one of the following: the number of times the sample query statement corresponding to the intermediate database execution template is executed is less than a number threshold; the number of calculation elements involved in the sample query statement corresponding to the intermediate database execution template is greater than a calculation element number threshold.
[0128] Here, the number threshold and the calculation element number threshold can be flexibly set according to different user needs and actual conditions.
[0129] This embodiment of the application evaluates the importance of a database execution template based on the number of executions of the sample query statements corresponding to the intermediate database execution template and the number of computational elements involved in the sample query statements, thereby making a decision on whether to delete or retain the template. This dynamically customized database management method can improve database efficiency and resource utilization, adapting to different application scenarios and business needs.
[0130] By screening the database execution templates, the embodiment of the present application can tilt database resources to query statements with higher frequency of use, thereby improving query efficiency. If the number of computing elements of the intermediate data execution template is relatively high, or even close to the full standard database instance, then the cost of generating the database instance is too high, so these database execution templates are deleted to improve the resource utilization of the database.
[0131] As an example, the number of times a database execution template is used is determined based on the number of times sample query statements are executed. If the usage ratio of some database execution templates is too low, these database execution templates are deleted, and the sample query statements corresponding to these database execution templates are executed using standard database instances.
[0132] In step 104, a database instance corresponding to each target database execution template is generated, wherein any database instance is used to respond to a target query statement corresponding to any database instance when executed.
[0133] In some embodiments, the database includes multiple database layer structures, and any computing element belongs to a database layer structure. The database instance corresponding to each target database execution template is generated in step 104, which can be achieved through the following technical solution: the following processing is performed for each target database execution template: at least one computing element of the target database execution template is obtained, and the database code of each computing element is obtained; the database code of the computing elements belonging to the same database layer structure is encapsulated to obtain the database code of the corresponding database layer structure; the database codes of multiple database layer structures are encapsulated according to the hierarchical order of the database layer structure to obtain the database instance corresponding to the target database execution template.
[0134] The embodiment of the present application can ensure the isolation between computing elements by encapsulating the database codes corresponding to multiple computing elements in the hierarchical order of the database layer structure, so that the computing elements do not interfere with each other, improve the stability of the database codes corresponding to the computing elements during execution, and ultimately ensure the normal execution of the database instance.
[0135] As an example, each computing element carries a piece of database code. Based on the obtained database execution template, it can be encapsulated according to the calling relationship between the computing elements. That is, the database code of the computing elements with the same database layer structure is first encapsulated, and the different computing elements in the same database layer structure are isolated from each other. Then, the database code of different database layer structures is encapsulated in hierarchical order to achieve isolation between database layer structures.
[0136] In some embodiments, after executing step 104, the following technical solutions may also be executed: obtaining a target query statement; when the first database execution template corresponding to the target query statement belongs to the target database execution template, obtaining a database instance corresponding to the first database execution template; executing the database instance corresponding to the first database execution template to obtain a query result for responding to the target query statement.
[0137] By obtaining the target query statement through the embodiment of the present application, when the first database execution template corresponding to the target query statement belongs to the target database execution template, the database instance of the first database execution template can be directly executed to respond to the target query statement, avoiding executing all database instances in the database.
[0138] As an example, the target query statement is a query statement obtained in real time when the user uses an application in an electronic device. The target query statement is parsed to obtain an execution plan of the target query statement, and the execution plan is parsed to obtain an operator. Based on the operator obtained by parsing, the corresponding first database execution template is determined. Through steps 101 to 104, a database instance of the target database execution template has been generated. When the first database execution template belongs to the above-mentioned target database execution template, the database instance corresponding to the first database execution template can be obtained, and the obtained database instance can be executed to obtain a query result for responding to the target query statement.
[0139] In some embodiments, when the first database execution template corresponding to the target query statement does not belong to the target database execution template, a full database instance is obtained; wherein the full database instance includes candidate computing elements of all database layer structures in the database; the full database instance corresponding to the target query statement is executed to obtain a query result for responding to the target query statement.
[0140] As an example, the target query statement is a query statement obtained in real time when the user uses the application. The target query statement is parsed to obtain an execution plan of the target query statement, and the execution plan is parsed to obtain an operator. Based on the operator obtained by parsing, the corresponding first database execution template is determined. Through steps 101 to 104, a database instance of the target database execution template has been generated. When the first database execution template does not belong to the above-mentioned target database execution template, the full database instance is directly obtained, and the obtained full database instance is executed to obtain a query result for responding to the target query statement.
[0141] The embodiment of the present application obtains multiple sample query statements for a database, and at least one computing element of the database corresponding to each sample query statement; for each sample query statement, the at least one computing element of the database corresponding to the sample query statement is used to form a database execution template of the sample query statement, so that the database execution template corresponding to each sample query statement can be obtained, and the multiple database execution templates corresponding to the multiple sample query statements are screened and processed to obtain a target database execution template, which is equivalent to streamlining the multiple database execution templates, avoiding redundant or low-utilization database execution templates from occupying database resources, thereby improving database resource utilization; based on each target database execution template, a corresponding database instance is generated, and any database instance is used to be executed to respond to the target query statement corresponding to any database instance, so that by executing customized database instances, only part of the database instances need to be executed to respond to the query statement. Compared with the method of related technologies that require the execution of a full amount of standard database instances, the number of database instances required to be executed to respond to the query statement can be reduced, thereby improving the query efficiency of the query statement.
[0142] The following describes an exemplary application of the embodiments of the present application in a practical application scenario.
[0143] The terminal receives historical query operations of a user when using an instant messaging client, such as querying friend information, conversation content with friends, or comment information, and sends the operation data to a server. The server obtains sample query statements for querying friend information, conversation content with friends, or comment information respectively for a database from the data generated by the query operation, and obtains at least one computing element of the database corresponding to each sample query statement; for each sample query statement, the server constructs a database execution template of the sample query statement with the at least one computing element of the database corresponding to the sample query statement; screens and processes multiple database execution templates corresponding to multiple sample query statements one by one to obtain a target database execution template; generates a database instance corresponding to each target database execution template, and any database instance is used to be executed in response to the target query statement corresponding to any database instance.
[0144] The terminal receives the target operation of the user when using the instant messaging client, such as querying the number of friends, and sends the target operation data to the server. The server obtains the target query statement corresponding to the target operation data, and the target query statement has a corresponding database instance. The server executes the database instance corresponding to the target query statement to obtain a response result about the number of friends from the database, and returns the response result to the terminal for presentation.
[0145] The embodiment of the present application decomposes the user's query statement into the database modules required for database execution, and compiles the corresponding database instance according to the database modules. The embodiment of the present application modularizes the database to meet the database query requirements with the lowest resource consumption. The embodiment of the present application dynamically starts different database instances according to the different query statements executed by the user, and the size of the database instance started each time is also different, so there is no need to start the full standard database instance every time.
[0146] In some embodiments, query statements involved in an application are analyzed and marked. Specifically, this is used to analyze the applications used by a user and record the query statements involved in the application. The query statements are parsed and the database modules corresponding to the query statements are recorded. Based on the database modules involved in the query, the corresponding database modules are marked to obtain a set of database execution templates.
[0147] As an example, obtain the application involving database query of the database user, and obtain the query statement involved in the database user, and detect the query statement through the detection module, which specifically includes the following processing: First, parse the user's query statement to generate an execution plan, and then parse the execution plan to obtain the operators required for the execution plan. The execution plan of the database is composed of different operators, such as full table scan, etc. The operators involved in the execution plan can be obtained through parsing; second, according to the specific work of different levels of the database, each level of the database can be further divided into database modules with different sub-functions; third, based on the operators involved in the execution plan and the sub-functions of each database module, record the database modules involved in each query statement; fourth, according to the database modules involved in the query statement, mark the corresponding database modules to obtain a set of database execution templates.
[0148] In some embodiments, referring to FIG4 , a user uses application 1, application 2, and application 3. When using application 1, the user uses query statements 1, 2, and 3; when using application 2, the user uses query statements 1, 2, 3, and 4; and when using application 3, the user uses query statements 1 and 2. Application 1 shown in FIG4 involves three query statements, each corresponding to a different database module. Parsing the query statements of the applications yields the information structure shown in FIG4 . Referring to FIG5 , based on FIG4 , at least one database module corresponding to each query statement constitutes a database execution template corresponding to each query statement.
[0149] In some embodiments, after obtaining a database execution template for each query statement, a template set for a database instance is generated. As previously described, a database module analysis is performed based on the query statement to obtain the database modules involved in the query statement, and the set of database modules involved in the query statement is combined to form a template for the database instance. The generated database execution template is added to the database execution template set, and the set is compared to see if there are identical database execution templates to merge the identical database execution templates. The number of times the database execution template corresponding to each query statement is used is determined based on the number of times multiple query statements are executed within a preset time period. If the usage percentage of certain database execution templates is too low (e.g., less than a percentage threshold), these database execution templates are deleted, and the query statements corresponding to these database execution templates are executed using standard database instances.
[0150] As an example, referring to FIG. 6 , based on FIG. 5 , FIG. 6 further illustrates a process of merging 9 database execution templates (ie, deleting duplicate database execution templates) to obtain a database execution template set including 4 database execution templates.
[0151] As an example, based on the final generated database execution template set, a relationship is established between query statements and the database execution template set. The query statements involved in a user's application usage over a period of time are detected to obtain the usage percentage of various database execution templates. This is primarily to prevent infrequently used database execution templates from occupying database system resources. Database execution templates with a usage percentage below a threshold are removed, and the corresponding query statements use the standard database instance. Referring to Figure 7, a user uses Application 1, Application 2, and Application 3. When using Application 1, the user uses Query Statements 1, 2, 3, and 4. When using Application 2, the user uses Query Statements 1, 2, 3, and 4. When using Application 3, the user uses Query Statements 1 and 2. Each query statement has a corresponding database execution template. After merging and deleting, four database execution templates remain: Database Execution Template 1, Database Execution Template 2, Database Execution Template 3, and Database Execution Template 4. Each database execution template has its own usage percentage. Since Database Execution Template 4 has the smallest usage percentage, it is removed, and the corresponding query statement 4 is executed using the standard database instance.
[0152] The database is modularized through the embodiments of the present application. When compiling a database program, it is compiled according to the database modules involved to generate a corresponding database instance. Subsequently, different database instances are used for execution according to different query statements. The database instance only contains the database code that can support the database modules involved in the database execution template. For example, if the query statement only contains a full table scan and a comparison operation, a database program corresponding to the full table scan and comparison operation is generated. This database program is much smaller than a complete standard database instance, thus having high execution efficiency.
[0153] In some embodiments, referring to FIG8 , the database can generally be divided into the following layers: Compiler layer: Parse the query statement. The query statement must first be parsed before it can be recognized by the database. The query statement is parsed into an abstract syntax tree. Since all syntaxes need to be supported, the parsing of all syntaxes will be included; Query rewriting layer: Parse the abstract syntax tree. For many rewriting rules, syntax checking is required, such as constraint-based rules, such as optimizing the selection statement according to specific conditions, and merging multiple conditions into a conditional expression. However, some syntax does not need to be checked, such as exchange order rules and renaming rules, which do not involve specific syntax rules; Query path selection layer : By evaluating the execution time, resource consumption and error rate of the query path, the query path overhead is calculated, and the execution path with the lowest overhead is selected as the optimal execution plan; Query execution layer: Execute the user's query according to the generated query plan; Index management layer: Supports database indexes. The database has a variety of index types and operations, and often user queries only use a part of the functions; Data management layer: Supports database data page management. There are also many types and operations of data pages. The data management layer is similar to the index management layer; Buffer management layer: Manages the database buffer. There are many different buffer management methods, but the user's application may only use a part of them.
[0154] In some embodiments, referring to FIG9 , each database layer can be further divided into different database modules based on the specific tasks at each layer. The compiler layer includes a cluster node module, a selection node module, an insertion node module, and the like; the query rewrite layer includes a pushdown module, a bubbling module, and a transitive closure module; the query path selection layer includes a hop count index and a join calculation module; the query execution layer includes a join execution factor module, a classification execution factor module, and a subquery execution factor module; the index management layer includes an index scan module, an index tree update module, and an index insert cache module; the data management layer includes an insert engine module, an update engine module, and a folder engine module; and the buffer management layer includes a buffer pool cache module, a simulation cache module, and a page lock cache module.
[0155] In some embodiments, each user query statement only uses some database modules in the database hierarchy. Take the following query statement as an example:
[0156] SELECT T1.C1 FROM T1, T2
[0157] WHERE T1.C2=T2.C2
[0158] AND T2.C2=1
[0159] GROUP BY T1.C1;
[0160] The query statement contains operators such as Select, Group By, and Join. After parsing, the database modules involved in each layer can be obtained, as shown in Figure 10. The database modules in the dotted box in Figure 10 are the database modules involved in each layer. These involve the cluster node module and selection node module in the compiler layer; the transitive closure module in the query rewrite layer; the hop index module and join calculation module in the query path selection layer; the join execution factor module and classification execution factor module in the query execution layer; the index scan module in the index management layer; the folder engine module in the data management layer; and the cache pool cache module in the buffer management layer.
[0161] In some embodiments, referring to FIG11 , FIG11 shows more detailed information based on FIG5 . A user uses application 1 and uses query statements 1, 2, and 3. Query statement 1 involves a seven-layer structure of the database, namely, a compiler layer, a query rewrite layer, a query path selection layer, a query execution layer, an index management layer, a data management layer, and a buffer management layer. Specifically, it includes a cluster node module and a selection node module in the compiler layer, a transitive closure module in the query rewrite layer, a hop index and a join calculation module in the query path selection layer, a join execution factor module and a classification execution factor module in the query execution layer, an index scanning module in the index management layer, a folder engine module in the data management layer, and a cache pool cache module in the buffer management layer.
[0162] In some embodiments, referring to FIG12 , FIG12 shows richer detailed information based on FIG6 . Query statement 1, query statement 2, and query statement 3 all involve the seven-layer structure of the database. Query statement 1 involves the cluster node module and the selection node module in the compiler layer; it involves the cache pool cache module in the buffer management layer. These modules constitute a database execution template. Query statement 2 involves the cluster node module and the selection node module in the compiler layer; it involves the cache pool cache module in the buffer management layer. These modules constitute a database execution template. Query statement 3 involves the cluster node module, the selection node module, and the joining node module in the compiler layer; it involves the simulation cache module and the page lock cache module in the buffer management layer. These modules constitute a database execution template. Since two of the above three database execution templates are the same, two different database execution templates are retained by merging.
[0163] Finally, a non-standard database instance is generated based on the database modules included in the database execution template. Since database instances are implemented in a sequential, layered manner, generating the corresponding non-standard database instance only requires isolating each database layer accordingly. See Figure 13, which shows the five-layer database structure and execution order involved in a query statement: the compiler layer, the query rewriting layer, the query path selection layer, the plan generation layer, and the query execution layer. The query statement involves the cluster node module and node selection module of the compiler layer, the transitive closure module of the query rewriting layer, the hop index module and join calculation module of the query path selection layer, the hop generation module and join generation module of the plan generation layer, and the join execution factor module and classification execution factor module of the query execution layer. The compiler layer generates a parse tree, which is input to the query rewriting layer. The query rewriting layer generates a rewritten parse tree, which is input to the query path selection layer. The query path is generated by the query path selection layer and input to the plan generation layer. The plan generation layer generates the runtime structure. Figure 13 also shows the data structures of the parse tree, the rewritten parse tree, the query path, and the runtime structure.
[0164] Through the embodiments of the present application, efficient database instances are generated based on the database functions involved in the query, improving database execution efficiency. For simple queries, smaller database instances can be used, improving the hit rate of instructions, reducing context switching and system resource usage. Furthermore, when the load exceeds the specified load, a smaller database instance can be called to respond to the query statement.
[0165] It is understandable that in the embodiments of the present application, when user information and other related data are involved, when the embodiments of the present application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0166] The following continues to describe an exemplary structure of the database instance processing device 455 provided in an embodiment of the present application implemented as a software module. In some embodiments, as shown in Figure 2, the software modules stored in the database instance processing device 455 of the memory 450 may include: an acquisition module 4551, configured to acquire multiple sample query statements for a database, and acquire at least one computing element of the database corresponding to each sample query statement; a template module 4552, configured to, for each sample query statement, form a database execution template of the sample query statement by converting at least one computing element of the database corresponding to the sample query statement; a screening module 4553, configured to screen multiple database execution templates corresponding to the multiple sample query statements to obtain a target database execution template; a generation module 4554, configured to generate a database instance corresponding to each target database execution template, wherein any database instance is used to respond to the target query statement corresponding to any database instance when executed.
[0167] In some embodiments, the acquisition module 4551 is further configured to: detect an application that has been run in the electronic device; and acquire a plurality of sample query statements for a database generated by the application during the running of the application.
[0168] In some embodiments, the acquisition module 4551 is further configured to: perform hierarchical division processing on the database to obtain multiple database layer structures of the database, wherein each database layer structure includes at least one candidate computing element; perform the following processing for each sample query statement: obtain the execution plan of the sample query statement, and decompose the execution plan to obtain at least one operator required for the execution plan; for each database layer structure, obtain the computing element for executing the operator from at least one candidate computing element of the database layer structure.
[0169] In some embodiments, the acquisition module 4551 is further configured to: acquire multiple types of functions involved in the database; divide the database into multiple levels according to the multiple types of functions, and obtain multiple database layer structures of the database.
[0170] In some embodiments, the multiple database layer structures include: a compiler layer, a query rewriting layer, a query path selection layer, a query execution layer, an index management layer, a data management layer, and a buffer management layer.
[0171] In some embodiments, the template module 4552 is further configured to: perform the following processing for each computing element: obtain the database layer structure to which the computing element belongs in the database, and obtain the hierarchical order of the database layer structure in the database; group the computing elements belonging to the same database layer structure into a computing element set; when the number of computing element sets is one, use the computing element set as a database execution template; when the number of computing element sets is multiple, sort the computing element sets corresponding to different database layer structures in hierarchical order, and use the sorted multiple computing element sets as database execution templates.
[0172] In some embodiments, the screening module 4553 is further configured to: filter duplicate database execution templates from multiple database execution templates to obtain at least one intermediate database execution template; perform deletion processing on at least one intermediate database execution template, and use the remaining intermediate database execution templates as target database execution templates.
[0173] In some embodiments, the screening module 4553 is further configured to: perform the following processing for each intermediate database execution template: obtain a sample query statement corresponding to the intermediate database execution template; when the sample query statement corresponding to the intermediate database execution template meets the deletion condition, delete the intermediate database execution template, and use the intermediate database execution template remaining after the deletion as the target database execution template.
[0174] In some embodiments, the deletion condition includes at least one of the following: the number of times the sample query statement corresponding to the intermediate database execution template is executed is less than a number threshold; the number of calculation elements involved in the sample query statement corresponding to the intermediate database execution template is greater than a calculation element number threshold.
[0175] In some embodiments, the database includes multiple database layer structures, and any computing element belongs to a database layer structure. The generation module 4554 is also configured to: perform the following processing for each target database execution template: obtain at least one computing element of the target database execution template, and obtain the database code of each computing element; encapsulate the database code of the computing elements belonging to the same database layer structure to obtain the database code of the corresponding database layer structure; encapsulate the database codes of multiple database layer structures according to the hierarchical order of the database layer structure to obtain the database instance of the corresponding target database execution template.
[0176] In some embodiments, the device also includes: a query module 4555, configured to: obtain a target query statement; when the first database execution template corresponding to the target query statement belongs to the target database execution template, obtain a database instance corresponding to the first database execution template; execute the database instance corresponding to the first database execution template to obtain a query result for responding to the target query statement.
[0177] In some embodiments, the query module 4555 is further configured to: when the first database execution template corresponding to the target query statement does not belong to the target database execution template, obtain a full database instance; wherein the full database instance includes candidate computing elements of all database layer structures in the database; execute the corresponding full database instance to obtain a query result for responding to the target query statement.
[0178] An embodiment of the present application provides a computer program product comprising computer-executable instructions stored in a computer-readable storage medium. A processor of an electronic device reads the computer-executable instructions from the computer-readable storage medium and executes the computer-executable instructions, causing the electronic device to perform the database instance processing method described above in the embodiment of the present application.
[0179] An embodiment of the present application provides a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, the processor will execute the database instance processing method provided by the embodiment of the present application, for example, the database instance processing method shown in Figures 3A-3D.
[0180] In some embodiments, the computer-readable storage medium may be a memory such as FRAM, ROM, PROM, EPROM, EEPROM, flash memory, magnetic surface storage, optical disk, or CD-ROM; or various devices including one or any combination of the above memories.
[0181] In some embodiments, computer-executable instructions may be in the form of a program, software, software module, script, or code, written in any form of programming language (including compiled or interpreted languages, or declarative or procedural languages), and may be deployed in any form, including as a stand-alone program or as a module, component, subroutine, or other unit suitable for use in a computing environment.
[0182] As an example, computer-executable instructions may, but need not, correspond to a file in a file system, may be stored as part of a file that stores other programs or data, such as in one or more scripts in a HyperText Markup Language (HTML) document, in a single file dedicated to the program in question, or in multiple coordinating files (e.g., files storing one or more modules, subroutines, or code portions).
[0183] By way of example, computer-executable instructions may be deployed to be executed on one electronic device, or on multiple electronic devices located at one site, or on multiple electronic devices distributed across multiple sites and interconnected by a communication network.
[0184] To summarize, through the embodiments of the present application, multiple sample query statements for a database are obtained, and at least one computing element of the database corresponding to each sample query statement is obtained; for each sample query statement, at least one computing element of the database corresponding to the sample query statement is used to form a database execution template of the sample query statement, so that a database execution template corresponding to each sample query statement can be obtained, and multiple database execution templates corresponding to multiple sample query statements are screened and processed to obtain a target database execution template, which is equivalent to streamlining multiple database execution templates to avoid redundant or low-utilization database execution templates from occupying database resources, thereby improving database resource utilization; a database instance corresponding to each target database execution template is generated, and any database instance is used to be executed to respond to the target query statement corresponding to any database instance, so that the target query statement can be responded to by executing a customized database instance. Compared with the method of executing a full set of standard database instances, the volume of database instances required to execute in response to the query statement can be reduced, and the query efficiency of the query statement can be improved.
[0185] The above description is merely an embodiment of the present application and is not intended to limit the scope of protection of the present application. Any modifications, equivalent replacements, and improvements made within the spirit and scope of the present application are included in the scope of protection of the present application.
Claims
1. A method for processing a database instance, the method being executed by an electronic device, the method comprising: Acquire multiple sample query statements for a database, and acquire at least one computing element of the database corresponding to each of the sample query statements; For each of the sample query statements, forming a database execution template of the sample query statement by corresponding at least one computing element of the database to the sample query statement; Screening the plurality of database execution templates corresponding to the plurality of sample query statements to obtain a target database execution template; A database instance corresponding to each of the target database execution templates is generated, wherein any database instance is used to respond to a target query statement corresponding to any of the database instances when executed.
2. The method according to claim 1, wherein: The obtaining of multiple sample query statements for a database includes: Detecting an application that has been run in the electronic device; A plurality of sample query statements for the database generated by the application program during the running of the application program are obtained.
3. The method according to claim 1 or 2, wherein: The obtaining at least one computing element of the database corresponding to each of the sample query statements includes: Performing hierarchical division processing on the database to obtain a plurality of database layer structures of the database, wherein each of the database layer structures includes at least one candidate computing element; The following processing is performed for each sample query statement: Obtaining an execution plan of the sample query statement, and decomposing the execution plan to obtain at least one operator required by the execution plan; A computing element for executing the operator is obtained from a plurality of candidate computing elements of the plurality of database layer structures.
4. The method according to claim 3, wherein: The step of performing hierarchical division processing on the database to obtain multiple database layer structures of the database includes: Acquire multiple types of functions involved in the database; According to the multiple types of functions, the database is divided into multiple database layer structures.
5. The method according to claim 3 or 4, wherein: The multiple database layer structures include: a compiler layer, a query rewriting layer, a query path selection layer, a query execution layer, an index management layer, a data management layer and a buffer management layer.
6. The method according to any one of claims 1 to 5, wherein: The step of forming a database execution template of the sample query statement by corresponding the sample query statement to at least one computing element of the database includes: The following processing is performed for each of the computing elements: obtaining a database layer structure to which the computing element belongs in the database, and obtaining a hierarchical order of the database layer structure to which the computing element belongs in the database; The computing elements belonging to the same database layer structure are grouped into a computing element set; When the number of the computing element set is one, using the computing element set as the database execution template; When there are multiple computing element sets, the computing element sets corresponding to different database layer structures are sorted according to the hierarchical order, and the sorted multiple computing element sets constitute a database execution template.
7. The method according to any one of claims 1 to 6, wherein: The screening process of the plurality of database execution templates corresponding to the plurality of sample query statements to obtain a target database execution template includes: Filtering duplicate database execution templates from the plurality of database execution templates to obtain at least one intermediate database execution template; A deletion process is performed on the at least one intermediate database execution template, and the remaining intermediate database execution template is used as the target database execution template.
8. The method according to claim 7, wherein: The performing of the deletion process on the at least one intermediate database execution template and using the remaining intermediate database execution template as the target database execution template comprises: The following processing is performed for each intermediate database execution template: Obtaining a sample query statement corresponding to the intermediate database execution template; When the sample query statement corresponding to the intermediate database execution template meets the deletion condition, deleting the intermediate database execution template; The intermediate database execution template remaining after the deletion is used as the target database execution template.
9. The method according to claim 8, wherein: The deletion condition includes at least one of the following: The number of times the sample query statement corresponding to the intermediate database execution template is executed is less than a number threshold; The number of calculation elements involved in the sample query statement corresponding to the intermediate database execution template is greater than a calculation element number threshold.
10. The method according to any one of claims 1 to 9, wherein: The database includes a plurality of database layer structures, any one of the computing elements belongs to one of the database layer structures, and the generating of a database instance corresponding to each of the target database execution templates includes: The following processing is performed for each target database execution template: Obtain at least one computing element of the target database execution template, and obtain a database code of each computing element; Encapsulating database codes of computing elements belonging to the same database layer structure to obtain database codes corresponding to the database layer structure; The database codes of the plurality of database layer structures are encapsulated according to the hierarchical order of the database layer structure to obtain a database instance corresponding to the target database execution template.
11. The method according to any one of claims 1 to 10, wherein: After generating a database instance corresponding to each target database execution template, the method further includes: Get the target query statement; When the first database execution template corresponding to the target query statement belongs to the target database execution template, obtaining a database instance corresponding to the first database execution template; Execute the database instance corresponding to the first database execution template to obtain a query result for responding to the target query statement.
12. The method according to claim 11, wherein: The method further comprises: When the first database execution template corresponding to the target query statement does not belong to the target database execution template, obtaining a full database instance; The full database instance includes candidate computing elements of all database layer structures in the database; Execute the corresponding full database instance to obtain a query result for responding to the target query statement.
13. A database instance processing device, the device comprising: An acquisition module, configured to acquire a plurality of sample query statements for a database, and acquire at least one computing element of the database corresponding to each of the sample query statements; A template module is configured to, for each of the sample query statements, form a database execution template of the sample query statement by corresponding at least one computing element of the database to the sample query statement; A screening module configured to screen the plurality of database execution templates corresponding to the plurality of sample query statements to obtain a target database execution template; A generation module is configured to generate a database instance corresponding to each of the target database execution templates, wherein any database instance is used to respond to a sample query statement corresponding to any database instance when executed.
14. An electronic device, comprising: A memory for storing computer executable instructions; The processor is configured to implement the database instance processing method according to any one of claims 1 to 12 when executing the computer executable instructions stored in the memory.
15. A computer-readable storage medium storing computer-executable instructions, wherein: When the computer executable instructions are executed by a processor, the database instance processing method according to any one of claims 1 to 12 is implemented.
16. A computer program product comprising computer executable instructions, wherein: When the computer executable instructions are executed by a processor, the database instance processing method according to any one of claims 1 to 12 is implemented.
Citation Information
Patent Citations
Cloud database testing method and device, equipment and storage medium
CN109271326A
Method and device for data query
CN110678854A
Database instance processing method and device, equipment, storage medium and program product
CN116756184A
Using a rowset as a query parameter
US20060010112A1
System and method for efficiently handling queries
US20180357282A1