Relational database for streaming data and electronic device
By introducing execution modules and storage modules into relational databases, parsing execution statements and generating execution plan trees to process stream data, the complexity and stability problems of the stream data processing system are solved, and efficient stream data processing and storage are achieved. Reduces learning and usage costs.
Patent Information
- Application Number
- CN202410730002.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-06
- Publication Date
- 2024-10-01
AI Technical Summary
Existing stream data processing systems need to be paired with multiple data storage components, resulting in complex structures, poor stability, high usage costs, and high learning and usage thresholds.
Provides a relational database that includes an execution module and a storage module. It generates an execution plan tree by parsing execution statements, processes stream data, and supports stream object storage and query, simplifying the stream data processing process and reducing learning and usage costs.
It achieves efficient processing and storage of streaming data, simplifies the streaming data processing process, reduces learning and usage costs, and improves the stability and ease of use of the system.
Smart Images

Figure CN118733625A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of stream data, and in particular to a relational database and electronic device for stream data. Background Art
[0002] Streaming data is an ever-growing, possibly disordered (but valid) but essentially infinite data set. Streaming data processing is becoming increasingly popular in the field of big data. The main reasons are as follows: 1. Enterprises are eager to gain more timely insights into their data, so switching to streaming data processing is a good way to achieve lower latency. 2. The increasingly common massive amounts of data in modern business require streaming data processing to absorb massive amounts of data. 3. Processing data as it arrives can spread the workload more evenly over the timeline, resulting in expected resource consumption.
[0003] In order to realize stream data processing, a large number of stream processing systems (such as Storm, Flink and other systems) have emerged in the big data field in recent years. However, these stream processing systems are different from traditional relational databases used for batch data processing. They need to use external databases or big data components such as Hadoop to save batch data and stream processing results. Multiple components need to be added to meet business needs, resulting in complex system structure and poor stability. Moreover, the access interface provided cannot be fully processed by SQL. When encountering complex stream processing, Java / Scala / Python programs need to be written, resulting in a high threshold for learning and using stream data processing. Summary of the invention
[0004] The embodiment of the present application provides a relational database and electronic device for stream data, which can solve the problem that current stream data processing needs to be matched with other data storage components, has a complex structure, poor stability, cumbersome operation, and high cost. To achieve this purpose, the embodiment of the present application provides the following solutions.
[0005] According to one aspect of an embodiment of the present application, there is provided a relational database for stream data, including: an execution module, a storage module;
[0006] The storage module is connected to the execution module, and is used to receive the stream data transmitted by the execution module, and establish a stream object storage for storing the stream data, wherein the stream object storage is established based on the storage of the table object in the relational database;
[0007] The execution module is used to parse the execution statement, establish an execution plan tree corresponding to the execution statement, and process the stream data based on the execution plan tree.
[0008] In a possible implementation, the relational database also includes a connection management module with a preset driver, and the connection management module is configured to connect with the access object through the preset driver, establish a data processing process corresponding to the access object, send the execution statement transmitted by the access object through the preset driver to the execution module through the data processing process, and use the data processing process to push the execution result fed back by the execution module in real time.
[0009] In a possible implementation, the execution module includes a parser, a rule replacer, an optimizer, and an executor connected in sequence. The execution module is used to parse the execution statement and establish the execution plan tree corresponding to the execution statement, specifically for:
[0010] Parsing the execution statement by the parser to generate a query tree, and transmitting the query tree to the rule replacer;
[0011] Perform rule replacement on the query tree by the rule replacer;
[0012] Obtaining, by the optimizer, an execution plan tree corresponding to the query tree after rule replacement;
[0013] The executor calls the operator corresponding to the execution plan tree to store or query the stream data.
[0014] In a possible implementation, the execution statement includes a stream data storage statement, and the executor calls an operator corresponding to the execution plan tree to store the stream data, including:
[0015] Calling the operator through the executor to perform corresponding processing on the stream data corresponding to the execution statement, and storing the stream data into the stream object storage unit using a preset operator, wherein the corresponding processing includes at least one of setting a timestamp corresponding to the stream data, constraint checking, and indexing;
[0016] If it is determined that there is a query process corresponding to the stream data, the data is pushed to the memory message queue corresponding to the query process.
[0017] In a possible implementation, the execution statement includes a streaming query statement, and the executor calls an operator corresponding to the execution plan tree to query streaming data, including:
[0018] The execution plan tree is traversed by the executor, and the operator corresponding to each node on the execution plan tree is called to filter the stream data that meets the query condition in the memory message queue corresponding to the execution statement in real time, where the query condition is determined based on the execution statement;
[0019] The stream data is pushed to the data processing process in real time.
[0020] In a possible implementation, when the connection management module is used to execute the query result fed back by the execution module in real time by using the data processing process and the preset driver, it is specifically used to:
[0021] If the query result is not received, the data processing process waits for the execution module to feedback the query result, and after determining that the query result is received, the query result is fed back to the preset driver, and the query result does not include a command completion instruction;
[0022] The preset driver waits for the data processing process to transmit the action, and after receiving the query result, sends the query result to the access object.
[0023] In a possible implementation, the execution statement includes a flow table associated query statement, and the execution plan tree corresponding to the query tree after rule replacement obtained by the optimizer includes:
[0024] Obtaining the object corresponding to the execution statement through the optimizer, and determining the position and type of the node corresponding to the object in the execution plan tree according to the type of the object, wherein the object includes stream data and table data;
[0025] The query of stream data is performed by calling the operator corresponding to the execution plan tree through the executor, including:
[0026] The execution plan tree is traversed by the executor and the calculation results of the nodes are associated. The traversal is achieved according to the type and position of each node in the execution plan tree.
[0027] In a possible implementation, the execution statement includes a multi-stream query statement, and the executor calls the operator corresponding to the execution plan tree to query the stream data, including:
[0028] The executor corresponds the preset operator for reading the memory message queue in the execution plan tree to the same memory message queue, traverses the execution plan tree according to the type and position of each node in the execution plan tree, and associates the calculation results of the nodes.
[0029] In a possible implementation, the execution statement includes a window statistics statement, and the execution module, when used to parse the execution statement, is specifically used to:
[0030] Parse the execution statement to obtain calculation parameters corresponding to a preset operator, where the calculation parameters include at least one of a window type, a window length, a sliding step, a watermark, and a delay flag;
[0031] When the execution module is used to process the stream data based on the execution plan tree, it is specifically used to:
[0032] The preset operator and the calculation parameters are used to perform window grouping on the stream data transmitted into the relational database, incremental calculation is performed according to the result of the window grouping, the calculation result is output, and the next cycle of the execution plan tree is executed.
[0033] In one possible implementation, the storage module also includes an extension plug-in with multiple streaming read and write external sources. The relational database determines the target extension plug-in and target object to be called based on the acquired external source read and write instructions, and calls the target extension plug-in to read and write the target object in the external source, wherein the target object includes a streaming external data source object using streaming data.
[0034] According to one aspect of the present application, an electronic device is provided, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the relational database as described above.
[0035] The beneficial effects of the technical solution provided by the embodiment of the present application are:
[0036] The present application provides a relational database for streaming data. Specifically, the relational database of the embodiment of the present application includes an execution module and a storage module. The storage module is connected to the execution module, and is used to receive data transmitted by the execution module and establish a stream object storage for storing streaming data; the execution module is used to parse the execution statement, establish an execution plan tree corresponding to the execution statement, and process the streaming data based on the execution plan tree. The embodiment of the present application can utilize the storage module and execution module of the relational database to realize the processing and storage of streaming data, configure the corresponding stream processing function for the relational database, effectively solve the current problem that streaming data processing needs to be matched with other data storage components, has a complex structure, and has poor stability, and can use the instructions related to the relational database to process streaming data, greatly reducing the learning and use costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following is a brief introduction to the drawings required for use in describing the embodiments of the present application.
[0038] Figure 1 A structural diagram of a relational database provided in an embodiment of the present application;
[0039] Figure 2 A functional architecture diagram of a relational database provided in an embodiment of the present application;
[0040] Figure 3 A flow chart of stream data storage and query provided in an embodiment of the present application;
[0041] Figure 4 A schematic diagram of a rolling window provided in an embodiment of the present application;
[0042] Figure 5 A schematic diagram of a sliding window provided in an embodiment of the present application;
[0043] Figure 6 A schematic diagram of a session window provided in an embodiment of the present application;
[0044] Figure 7 A flowchart of streaming window statistics provided in an embodiment of the present application;
[0045] Figure 8 A schematic diagram of an execution plan tree for a flow table join query provided in an embodiment of the present application;
[0046] Fig. 9 A flow chart of a flow table join query provided in an embodiment of the present application;
[0047] Fig.10 A schematic diagram of an execution plan tree for a multi-stream join query provided in an embodiment of the present application;
[0048] Fig.11 A flowchart of a multi-stream join query provided in an embodiment of the present application;
[0049] Fig.12 A schematic diagram of an execution plan tree for a multi-stream multi-table join query provided in an embodiment of the present application;
[0050] Fig.13 A flowchart of a multi-stream multi-table join query provided in an embodiment of the present application;
[0051] Fig.14 A structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0052] The embodiments of the present application are described below in conjunction with the drawings in the present application. It should be understood that the implementation methods described below in conjunction with the drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions of the embodiments of the present application.
[0053] It will be understood by those skilled in the art that, unless specifically stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the terms "including" and "comprising" used in the embodiments of the present application refer to that the corresponding features can be implemented as the presented features, information, data, steps, operations, elements and / or components, but do not exclude the implementation of other features, information, data, steps, operations, elements, components and / or combinations thereof supported by the present technical field. It should be understood that when we say that an element is "connected" or "coupled" to another element, the one element may be directly connected or coupled to the other element, or it may refer to that the one element and the other element establish a connection relationship through an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein indicates at least one of the items defined by the term, for example, "A and / or B" indicates that it is implemented as "A", or is implemented as "A", or is implemented as "A and B".
[0054] In order to make the objectives, technical solutions and advantages of the present invention more clear, the embodiments of the present invention will be further described in detail below with reference to the accompanying drawings.
[0055] The following describes several exemplary embodiments to illustrate the technical solutions of the embodiments of the present invention and the technical effects produced by the technical solutions of the present invention. It should be noted that the following embodiments can refer to, draw on or combine with each other, and the same terms, similar features and similar implementation steps in different embodiments will not be described repeatedly.
[0056] The relational database, device, equipment, medium and program product provided in this application are intended to solve at least one technical problem existing in the prior art.
[0057] A relational database is provided in an embodiment of the present application. The relational database can be applied to servers, mobile phones, laptops, desktops, and other devices that can be used for stream data processing.
[0058] Combine the following Figure 1-Figure 13 The relational database used for stream data processing in the embodiment of the present application is described. Specifically, Figure 1 As shown, the relational database includes an execution module and a storage module. The execution module and the storage module are connected and perform data transmission with each other. The connection includes at least one of a wired connection and a wireless connection.
[0059] Optionally, the storage module is connected to the execution module, and is used to receive the stream data transmitted by the execution module, and establish a stream object storage for storing the stream data, the stream object storage is established based on the storage of table objects in the relational database; the execution module is used to parse the execution statement, establish an execution plan tree corresponding to the execution statement, and process the stream data based on the execution plan tree. Among them, the storage module adds a storage format (stream object storage) corresponding to the stream data in the database, and stores the stream data in real time based on the storage format.
[0060] Optionally, the execution statement may be a statement for stream data processing or a statement for batch data processing. The execution module identifies the execution statement according to the content, identification information and other information of the execution statement, and processes the data in the relational database based on the identification result.
[0061] Alternatively, if Figure 2 As shown, the relational database also includes a connection management module with a preset driver. The connection management module is configured to connect with the access object through the preset driver, establish a data processing process corresponding to the access object, send the execution statement transmitted by the access object through the preset driver to the execution module through the data processing process, and use the data processing process to push the execution result fed back by the execution module in real time.
[0062] Optionally, the preset driver can be a series of database access interfaces, through which the access object accesses the relational database, and through which the execution statement is input into the relational database to drive the relational database to work. The interface can include jdbc (for accessing the database using the java language), odbc (for accessing the database using the C / C++ language), libpq (for accessing the database using languages such as C / C++ / python), psql (a command line tool), and other types of interfaces. The access object selects the corresponding interface to connect to the relational database according to the language type it uses.
[0063] Optionally, the data processing process can be run in the background. When the stream data is stored in the database, the data processing process can be a storage background process (which can be called insert backend); when the stream data is queried, it can be a query background process (which can be called query backend). The type of the data processing process can be set accordingly according to the type of execution statement received by the relational database and the type of operation it performs.
[0064] Optionally, the system controller can establish a data processing process for each access object connected. For example, the system controller generates a query background process for each access object connection, and uses the process to process requests sent by the client, such as insert, query and other execution statements.
[0065] Alternatively, if Figure 2 As shown, the connection management module may also include a system controller, which is used to accept requests for external operations (such as access operations to access objects) to the relational database, pre-process and distribute the requests. For example: the upper limit of the connection of the relational database is 10,000 clients. If there are more than 10,000 clients, the system controller will not allow any more connections. The specific upper limit of connections can be set according to the configuration and business conditions of the database; or in a distributed situation, the system controller allows some clients to connect to the A node of the database and other clients to connect to the B node of the database, and so on.
[0066] Optionally, the execution statement received by the relational database may be a SQL (Structured Query Language) statement. In order to parse the statements in the SQL statement for creating tables and stream objects (i.e., stream data) and modifying the structure of tables and stream objects (such statements may be referred to as DDL (Data Definition Language) statements), the execution module further includes a DDL compiler, through which the DDL statements of the transmission execution module are parsed.
[0067] The execution module also includes a parser, a rule replacer, an optimizer, and an executor connected in sequence. The execution module is used to parse the execution statement and establish the execution plan tree corresponding to the execution statement. Specifically, the execution module is used to: parse the execution statement through the parser to generate a query tree, and transmit it to the rule replacer; replace the query tree with rules through the rule replacer; obtain the execution plan tree corresponding to the query tree after the rule replacement through the optimizer; and call the operator corresponding to the execution plan tree through the executor to store or query the stream data.
[0068] Optionally, to implement streaming data query, the execution statement for streaming data query includes a keyword, which may be an emit changes keyword. The execution module starts the operation mode for streaming data query based on the keyword (the mode may be preset as a push mode). Specifically, when the parser encounters a query statement with the emit changes keyword, it parses it into an abstract syntax tree with an emit changes identifier. After semantic analysis, the emit changes identifier of the abstract syntax tree is brought to the query tree, and the optimizer brings the emit changes identifier of the query tree to the execution plan tree. When the executor traverses the execution plan tree and executes the Scan operator (each node of the execution plan tree is an operator, and the scan operator is one of them), the scan operator is used to scan the memory message queue corresponding to the current push query in real time. When the memory message queue is empty, the Scan operator is in a waiting state instead of the execution being completed.
[0069] In one embodiment, the system controller distributes the received execution statements to the parser and the DDL compiler. The execution statement is a query statement in the SQL statement (which can be any one of a filtering query, an aggregation query, and an associated query). The parser parses the SQL statement, generates a query tree after parsing, and transmits the query tree to the rule replacer. The database pre-stores rules and views for rule replacement. The rule replacer rewrites the query tree according to the pre-stored rules and views, and transmits the rewritten query tree to the optimizer. The optimizer performs rule optimization (logical optimization such as: lifting subqueries, lifting sublinks, predicate pushdown, etc.) and cost optimization (physical optimization such as: scanning paths of ordinary tables, connection paths of associated tables, etc.) on the rewritten query tree, generates a plan tree with the best execution speed, and determines the plan tree as the execution plan tree. For example, the filtering query is implemented in the form of index scanning or sequential scanning, which table is in front and which table is in the back when multiple tables are associated, whether it is a nested association, a merge association or a hash association, and the data processing performance caused by each operation is different, so the optimizer is required to generate the optimal execution plan tree. The executor performs specific operations (such as querying or storing data) according to the execution plan tree generated by the optimizer.
[0070] Specifically, the syntax example of the SQL statement used to drive the relational database to process stream data is as follows:
[0071] The syntax of the SQL statement used to create a stream object can be:
[0072] CREATE STREAM stream_name([
[0073] {column_name data_types[column_constraint[...]}
[0074] [,... ]])
[0076] where column_constraint is:
[0077] {NOT NULL|
[0078] NULL|
[0079] CHECK(expression)[NO INHERIT]|
[0080] DEFAULT default_expr
[0081] This syntax is used to create a stream object in the database. After the database receives an SQL statement using this syntax, it automatically creates a data file for the stream object corresponding to the statement to store the data of the stream object. Among them, the keyword CREATESTREAM indicates the creation of a stream object, stream_name indicates the name of the stream object, column_name in parentheses indicates the field name, data_types indicates the field type, column_constraint indicates the constraint, ... indicates that multiple fields can be created, and each field has a corresponding field name, field type and constraint. "where column_constraint is:" means that the constraint of the field can be specified as the non-empty "NOT NULL" below, can be empty "NULL", can be a check constraint "CHECK", and DEFAULT indicates that the default value of the field is the value of default_expr).
[0082] An example of a stream object creation statement obtained based on the grammar may be:
[0083] The SQL statement used to create a stream object without storage time is:
[0084] mydb=#CREATE STREAM instructor(ID text,name text,dept_name text,salary float);
[0085] The stream object created in this statement is instructor, the field ID type is string type (text), the field name type is string type, the field dept_name type is string type, and the field salary type is floating point type (float).
[0086] The SQL statement used to create a stream object with storage time is:
[0087] mydb=#CREATE STREAM instructor1(intime bigint not nulldefaulthlcnextval(),ID text,name text,dept_name text,salary float);
[0088] The stream object created in this statement is instructor1. The intime field is specified as the storage time field, and the type is big integer (bigint represents a 64-bit integer). default hlcnextval() means that the current hlc timestamp of the system is used by default.
[0089] Optionally, the stream object can also be used as a materialized object of the stream processing result. Its SQL syntax can be:
[0090] CREATE STREAM stream_name[(column_name[,...])]AS push query
[0091] Among them, push query represents the streaming query statement in active push mode, which can be simple streaming filter query, streaming window statistics query, stream table join and multi-stream join.
[0092] The SQL statement used to materialize the stream object as the result of stream processing can be:
[0093] CREATE STREAM super_instructor AS SELECT*frominstructor WHERE salary>=80000EMIT CHANGES;
[0094] The purpose of this statement is to filter out the stream data in the stream object instructor that satisfies the salary greater than or equal to 80,000 and materialize it into the super_instructor stream object in real time.
[0095] Optionally, in order to speed up the reading and writing of data, the storage module also includes a shared memory, and the storage module caches data blocks that meet predetermined conditions (such as frequently used in the recent period) into the memory for multiple processes to read and write.
[0096] Optionally, in order to facilitate the processing of streaming data, the storage module sets a memory message queue based on the shared memory, and the memory message queue stores messages in a first-in-first-out manner. The objects in the storage module include tables, indexes, streaming data, and external source read-write units. Among them, tables, indexes, and external source read-write units are objects already existing in the relational database, and streaming data is a newly added object in the streaming database. The relational database reads and writes other databases or storage systems except itself through the external source read-write unit.
[0097] Optionally, in order to stream read and write data in an external data source, the external source read and write unit is further provided with a plurality of extension plug-ins, and the relational database determines the target extension plug-in and target object to be called based on the acquired external source read and write instructions, and calls the target extension plug-in to read and write the target object in the external source. The target object includes a stream external data source object.
[0098] In one embodiment, the name of the extension plug-in may be kafka_stream_fdw, the external data source for reading and writing is kafka, and the relational database performs streaming reading and writing through the extension plug-in, including: the relational database enables the extension plug-in kafka_stream_fdw based on the received execution statement for enabling the extension plug-in (which may be CREATE EXTENSION kafka_stream_fdw;), and creates a streaming read and write service according to the received execution statement (the execution statement used to indicate that the service is created in the database may be: CREATE SERVER kafka_stream_server TYPE'stream' FOREIGN DATA WRAPPER kafka_stream_fdw OPTIONS(brokers'localhost:9092');), and further creates a streaming external data source object based on the execution statement for creating the external source (the execution statement may be: CREATE FOREIGN STREAM kafka_test (used to indicate the mapping relationship between fields and kafka messages...) SERVER kafka_stream_server OPTIONS(format'csv',topic'test');), and then use the extension plug-in to stream query the messages whose Kafka topic is test according to the received execution statement (the execution statement can be: SELECT * FROM kafka_test emit changes;).
[0099] Optionally, the relational database also has a system table (which may be called a data dictionary), which not only stores descriptive information of various objects, but also stores detailed information of various objects required for database management, including descriptive information of all objects and their attributes in the database system, descriptive information of the relationships between objects, the natural language meaning of object attributes, and the history of changes in the data dictionary.
[0100] Optionally, because the stream object is added to the storage module, the system table should also add metadata information related to the stream object (metadata information refers to the field description information of the stream object, including the data file name of the stream object. If the stream data has an index, it also includes the index file name of the index, etc.). The table in the storage module is separated from the index. The index can be created for the stream object or not, and the files and formats stored in the two are also different. The execution module can be a SQL engine, which involves stream-related semantic analysis, optimization and execution. The execution module must access the metadata information related to the stream object in the system table to determine whether the execution statement is meaningful based on the metadata information. For example, the execution statement is: select fa,fb,fcfrom sa where name='aaa'emit changes; the execution module parser determines whether sa in the statement is a stream object based on the metadata information when performing semantic analysis. If it is a stream object, it continues to determine whether the sa stream object has fa, fb, and fc fields. If sa is not a stream object or the sa stream object does not have at least one of the fa, fb, and fc fields, the database prompts a syntax error. In addition, when optimizing the cost, the optimizer determines whether the stream object sa has an index based on the metadata information. If it has an index, it obtains the cost of the index query and the cost of the query without the index, and selects the path with the least cost to create the index. When executing the query plan, the executor searches for the corresponding data file or index file based on the metadata information, and then performs data scanning based on the found data file or index search based on the found index file.
[0101] Optionally, the relational database further includes a transaction manager, a log manager, a concurrency control and a lock manager. The atomicity, consistency, isolation and persistence of data processing (these four characteristics can be called ACID characteristics) are realized through the transaction manager, the log manager and the transaction manager are used to maintain transaction persistence, and the concurrency control and the lock manager are used to maintain consistency and isolation.
[0102] Optionally, the execution statement includes a stream data storage statement, and the stream data is stored by calling the operator corresponding to the execution plan tree by the executor, including: performing corresponding processing on the stream data corresponding to the execution statement by calling the operator, storing the stream data in the stream object storage unit using the preset operator, and the corresponding processing includes setting the timestamp corresponding to the stream data, constraint checking, and indexing at least one; if it is determined that there is a query process corresponding to the stream data, then pushing data to the memory message queue corresponding to the query process. Among them, the operator called by the executor and the preset operator constitute the node of the execution plan tree. The executor implements the storage of stream data through the node.
[0103] Optionally, the stream data enters the storage module through the executor, and the executor timestamps the stream data and detects whether the constraint condition is satisfied (i.e., constraint check), wherein the constraint condition includes at least one of a check constraint, a non-null constraint, a primary key constraint, a foreign key constraint, and other constraints, and the constraint condition is used to ensure the integrity, consistency, and correctness of the stream data. And when the stream data is indexed, the corresponding index data is generated, and the index data is stored in the stream object and the index object storage (wherein the file and format for storing the index object data is called the index object storage).
[0104] In one embodiment, the executor automatically stamps each stream data with a global monotonically increasing timestamp to ensure that the stream data is exactly unique (exactly-once) during streaming computing and failover. The timing of the timestamp can choose strategies such as TSO (full name Timestamp Oracle, which can be called timestamp oracle, God's perspective timestamp or global timestamp) or HLC (Hybrid Logic Clock, a distributed clock distribution method that integrates logical clocks and physical clocks) according to the situation. Since the stream object storage is determined based on the table object storage (the file and format for storing table object data is called table object storage), the stream objects in the database can also support the modification, deletion, indexing, etc. of the stream data, and have the ACID characteristics of transactions.
[0105] Optionally, the preset operator is a preset operator for storing stream data in a storage module, wherein the preset operator may be a modification operator (Modify Table).
[0106] Optionally, the execution statement includes a streaming query statement, and the executor calls the operator corresponding to the execution plan tree to query the streaming data, including: traversing the execution plan tree through the executor, calling the operator corresponding to each node on the execution plan tree to filter in real time the streaming data that meets the query conditions in the memory message queue corresponding to the execution statement, and the query conditions are determined based on the execution statement; and pushing the streaming data to the data processing process in real time.
[0107] Optionally, in order to facilitate the database to identify the streaming query statement, the streaming query statement may also include a preset keyword. When the execution module of the database identifies the preset keyword, it determines to perform a streaming data query and starts a preset mode for the streaming data query.
[0108] Specifically, the query of a traditional relational database belongs to the pull mode. The client initiates an SQL query through the driver program. The database generates a query plan through SQL parsing optimization, and then executes the query plan through the executor. The tuple of the table object is iteratively scanned (the metadata information saves the field description, data file name, index file name, etc. of a stream object or table object. The tuple is the data of the table object or stream object, and the specific data is stored in the form of a tuple in the data file) to perform subsequent operator operations, and the processing result data is returned to the driver program, which is cached by the driver program. After the table object data is scanned, a command completion instruction (such as CommandComplete) message is returned to the driver program. After receiving the CommandComplete message, the driver program outputs the previously cached result data to the client at one time, and the query ends. Therefore, the query of the traditional relational database is batch processing. In view of the real-time nature of streaming data processing, this application adds an active push (PUSH) mode to the relational database. The driver program is changed to output the received result data in real time without waiting for the command completion instruction for streaming query statements.
[0109] On the database server side, when the connection management module is used to execute the query results fed back by the execution module in real time by using the data processing process and the preset driver, it is specifically used for: if the query result is not received, the data processing process waits for the execution module to feedback the query result, and after determining that the query result is received, the query result is fed back to the preset driver, and the query result does not include the command completion instruction; the preset driver waits for the action transmitted by the data processing process, and after receiving the query result, sends the query result to the access object.
[0110] In one embodiment, the syntax example of a streaming query is as follows:
[0111] SELECT[*|expression[[AS]output_name][,...]]
[0112] FROM stream_name[[AS]alias]
[0113] [WHERE condition][EMIT CHANGES]
[0114] This syntax is the filter query syntax of the push query in the SQL syntax, where stream_name[[AS]alias] indicates the stream object for which the streaming filter query is performed, [*|expression[[AS]output_name][,...]] indicates the selected field or expression, [WHERE condition] indicates the filter condition, and EMIT CHANGES indicates the PUSH mode.
[0115] For example, the SQL statement for streaming query is: SELECT * from instructor WHERE salary>=80000 EMIT CHANGES; This statement indicates filtering the real-time data of the stream object instructor, and pushing the data with the salary field value greater than or equal to 80000 to the client in real time. Since the streaming data is unbounded, the filtering query keeps running and waiting for new data to arrive. If there is data, it will continue to be processed, and if there is no data, it will continue to wait. EMIT CHANGES indicates active push mode, which is a keyword added to the standard SQL syntax to indicate streaming query.
[0116] In one embodiment, Figure 3 As shown, the connection management module participates in the storage of stream data and the query of stream data through the storage background process and the query background process respectively. When the stream data is stored, the preset driver of the connection management module receives the insert statement for indicating the storage of the stream data, and transmits the insert statement to the storage background process. The storage background process transmits the insert statement to the parser of the execution module. The parser parses the insert statement to generate a query tree. The rewriter replaces the rules of the parsed query tree. The optimizer performs logical optimization (including rule-based optimization) and physical optimization (including cost-based optimization) on the rewritten query tree to generate an execution plan tree. The executor performs related operations (timestamping the stored stream data, performing constraint checks, building indexes, etc.) according to the execution plan tree, and then the executor executes the modification operator to store the stream data, and then checks whether there is a push query for the current stream object (i.e., the current stored stream data). If there is a push query, the data is pushed to the memory message queue corresponding to the push query.
[0117] The access object inputs an execution statement (which may be called a push query statement) for stream data query to the relational database through the preset driver. After the relational database receives the execution statement, it executes the push query for stream data query. Specifically, the query background process (which may be called backend) of the connection management module is connected to the preset driver, receives the push query statement, and sends the push query statement to the parser. The parser parses the push query statement to generate a query tree. The rewriter replaces the rules of the parsed query tree. The optimizer performs logical optimization and physical optimization on the rewritten query tree to generate an execution plan tree. The executor performs relevant operator operations according to the execution plan tree. The operator operation may include using the scanning operator on the execution plan tree to read the stream data of the memory message queue, using the filtering operator to filter it out of the stream data that does not meet the conditions, and then using the projection operator to perform a projection operation to select the value of the specified field in the query statement, and pushing the query result to the preset driver in real time through the query background process, so that the access object can obtain the query result in real time through the preset driver.
[0118] Specifically, the client accessing the object connects to the database through the preset driver of the connection management module, initiates a streaming query (which may be called a push query), and generates an execution plan tree through the parser (the creation and destruction of tables or streams and the addition, deletion, modification and query operations of data in the database are all executed through SQL statements, and the parser may be an SQL parser), the rule replacer, and the optimizer. The executor executes the plan tree, and the executor processes the streaming data in real time and pushes the processing results in real time in a preset push mode). The Scan operator of the execution plan tree (the operator is part of the execution plan tree, and each node of the execution plan tree is an operator. The executor may traverse the execution plan tree in the order of left first and right later to execute each operator operation) is matched with the memory message queue (which may be called a memqueue), and the operator is used to detect the data and data changes in the memory message queue. If there is data or new data entering the memqueue, the filter operator (Filter) and the projection (Project) operator are executed for the real-time data for processing to obtain the query result.
[0119] Here is an example:
[0120] A stream object sa has three fields: fa, fb, and fc. The related push query statements are as follows:
[0121] select fa,fc from sa emit changes;
[0122] When executing the projection operator, the projection operator takes the values of the fa and fc fields in the data that meets the conditions in the stream object sa as the query result according to the query statement.
[0123] The query results of streaming data are pushed to the preset driver in real time. The executor traverses the execution plan tree in the order of left to right, calls the operator operation of each node on the execution plan tree, and the return result of the top-level node of the execution plan tree is the query result of the executor. The query result is processed by the query background process, and the query background process pushes the result to the preset driver in real time. In addition, unlike batch data processing, the preset driver does not wait for the CommandComplete message to be received, and directly outputs the received processing result data. If the memory message queue is empty, the backend waits for new data and does not send a message to the preset driver that does not wait for Command Complete. The preset driver automatically waits to receive the processing result data transmitted by the query process. The data of the memory message queue (memqueue) comes from the background process of warehousing the stream object. When the execution module performs the warehousing operation on the new data, it pushes the data to the memory message queue corresponding to the streaming query related to the new data (each stream object's push query process corresponds to a memory message queue. If there are multiple push query processes for a stream object, there are multiple corresponding memory message queues. If there are n stream objects and each stream object has m push query processes, there will be n*m memory message queues).
[0124] For example, the execution statement is:
[0125] insert into sa values(1,'aaa'),(2,'bbb');
[0126] Based on the execution statement, the stream data is stored. The stream data contained in the statement is (1, 'aaa') and (2, 'bbb'). If the stream data is pushed to the memory message queue, the Scan operator related to the query background process on the memory message queue will wait for the new data to be obtained in real time, and then the subsequent operators will be executed to push the calculation results to the preset driver in real time.
[0127] Optionally, the execution statement includes a streaming window statistics statement, and when the execution module is used to parse the execution statement, it is specifically used to: parse the execution statement, obtain the calculation parameters corresponding to the preset operator, and the calculation parameters include at least one of the window type, window length, sliding step, water level, and delay flag; when the execution module is used to process the streaming data based on the execution plan tree, it is specifically used to: use the preset operator and calculation parameters to perform window grouping on the streaming data passed into the relational database, perform incremental calculation according to the result of the window grouping, output the calculation result, and execute the next cycle of the plan tree. Split the streaming data into many "buckets" of limited size by window grouping, and then perform incremental calculation on these buckets.
[0128] Optionally, the relational database of the present application provides four types of window definitions: rolling window (slicing in time, if the window size of the rolling window definition is 10s, then the time period from [0,10) is window 1, the time period from [10,20) is window 2, and so on. The data coming in during the period [0,10) is counted into the result set of window 1, and the data coming in during the period [10,20) is counted into the result set of window 2), sliding window, session window and global window.
[0129] Specifically, the scroll window is as follows Figure 4 As shown in the figure, assuming that the window size is 1 second (s=1), window 1 (w1 in the figure) represents the time period [0,1), window 2 (w2 in the figure) represents the time period [1,2), and the points on the line represent the time points when the stream data arrives. When the data is generated relatively quickly, there may be at least one piece of data coming in every microsecond. In the time dimension, the unbounded data stream is sliced according to a fixed length, and appears adjacent to each other without crossing. For an incoming data, its timestamp is obtained according to the time attribute, so that its corresponding time window can be calculated.
[0130] Sliding window Figure 5 As shown in the figure, it also uses fixed equal intervals to allocate windows, but there is overlap between each window. The sliding window has two parameters, namely the window size and the sliding step size. The latter determines the distance the window slides forward each time. When the sliding step size is smaller than the window size, multiple windows will overlap, that is, one data may be allocated to multiple windows. When the sliding step size is equal to the window size, it becomes a rolling window. When the sliding step size is larger than the window size, the window will be discontinuous and the data may not belong to any window.
[0131] The session window is Figure 6 As shown in Figure 1, different windows are divided according to the session gap. When a window is larger than the session gap ( Figure 6Each point on the middle line represents a time point when a data arrives. If the time gap of the session window is 0.5 seconds (s=0.5), the time gap between the second point and the first point is less than 0.5 seconds, so they belong to the same window W1. The time gap between the third point and the second point is less than 0.5 seconds, so the third point also belongs to window W1. The time gap between the fourth point and the third point is greater than 0.5 seconds, so the fourth point and the previous three points do not belong to the same window W1. The fourth point is taken as the start time of the W2 window. The time gap between the fifth point and the fourth point is less than 0.5 seconds, so the fifth point belongs to the W2 window. The time gap between the sixth point and the fifth point is more than 0.5 seconds, so the sixth point does not belong to the W2 window. The sixth point is taken as the start time of the W3 window. The same goes for the following). If no new data is received within a certain period of time, the window will be closed. In this mode, the length of the window is variable, and the start and end time of each window is not fixed.
[0132] The global window has only one window and the window size is infinite, that is, there is no window definition. Because there is no window end time, the statistical results cannot be output after the window ends. The output results are calculated immediately as soon as there is data.
[0133] In one embodiment, the syntax related to the window statistics statement may be:
[0134]
[0135] Generates window statistics statements based on this syntax.
[0136] The window statistics statement that uses this syntax can be:
[0137] SELECT count(ID),sum(salary),avg(salary),dept_name,window_begin(*),window_end(*)FROM instructor WHERE salary>50000GROUP BY dept_name TUMBLE(evt_time,INTERVAL'10s')WATERMARK INTERVAL'1s'EMIT CHANGES;
[0138] This window statistics statement executes rolling window statistics. In this statement, count(ID), sum(salary), avg(salary), and dept_name correspond to expression in the syntax. WindowBegin(*) indicates the window start time, WindowEnd(*) indicates the window end time, instructor corresponds to stream_name in the syntax, WHERE salary>50000 corresponds to WHERE condition in the syntax, TUMBLE(evt_time,INTERVAL'10s') indicates slicing the value of the time field evt_time in the stream data at 10-second intervals, WATERMARK INTERVAL'1s' indicates that the watermark is 1 second, and EMIT CHANGES indicates a push query.
[0139] Among them, global window statistics do not need to specify the window type, and do not use WindowBegin(), WindowEnd(), WATERMARK, and ALLOWEDLATENESS in the syntax. The syntax for specifying the use of global windows for statistics can be:
[0140] SELECT expression[[AS]output_name][,...]FROM stream_name[WHEREcondition]GROUP BY grouping_element EMIT CHANGES].
[0141] In one embodiment, Figure 7As shown in the figure, when executing the window statistics statement, the query background process transmits the window statistics statement with emit changes to the parser through the preset driver transmission parsing process. When parsing the window statistics statement, the parser attaches the emit changes flag to the query tree and sends the window type, window length, sliding step, watermark (in actual applications, due to external factors such as the network or system, streaming data often cannot reach the database in time, resulting in problems such as out-of-order or delayed data arrival. The watermark mechanism is used to deal with these two problems. After a specific time, normal delayed data has arrived, triggering the window calculation to output the window aggregation result. If the previous data arrives after the watermark time, it means that these data are late data exceeding the watermark), and the delay flag (allowedLateness) to the Agg operator in the query tree (the agg operator is used to calculate the aggregation expression, such as executing count, sum, avg, etc.). Among them, the late data exceeding the watermark is processed according to the delay flag. allowedLateness means that after exceeding the watermark, a period of time is allowed to wait for the previous data to arrive so that the late data can be processed again. Data that arrives after the time corresponding to allowedLateness is output to the log as abnormal data. And when allowedLateness is set to 0, data that exceeds the watermark is directly discarded. When allowedLateness is not explicitly specified, the default time corresponding to allowedLateness is 24 hours.
[0142] During the execution phase, the executor calls the Agg operator. The Agg operator function performs grouping statistics based on the window type, window length, and sliding step size. Each tuple that is stored is assigned to the corresponding window group for calculation based on time (this time is determined by the execution statement. In the window statistics statement, the time field of the streaming window grouping is determined by the event_time_field in the TUMBLE and HOP clauses. If the field is the event time field, it is determined to be an event time grouping. If the field is the storage time field, it is determined to be grouped by the storage time). Among them, the executor executes the agg operator for calculation. Once streaming data arrives, the agg operator will be executed. Since agg is an incremental calculation, the calculation speed is very fast. If it is a global window statistics, window grouping is not required.
[0143] Because data is streamed in, the statistical function must be made into incremental calculation to ensure optimal performance. During incremental calculation, the initial value of the aggregate calculation is initialized first and recorded in the intermediate result. Then, the iterative aggregate function is used to iteratively calculate each input tuple to obtain the latest intermediate result. Finally, the end function is used for processing according to actual needs. After obtaining the final result, the projection operator is used to return the calculation result. Among them, the projection operator returns the start time and end time of each window when executing the WindowBegin and WindowEnd functions. If the current processing time exceeds the window end time plus the watermark, the calculation result is output. The global window statistics do not need to be watermarked and directly output the calculation result. The calculation result is pushed to the preset driver through the query background process, and the next cycle continues to be executed according to the execution plan tree.
[0144] Optionally, the execution statement includes a stream-table association query statement (i.e., a stream-table join statement, wherein a query on multiple streams may be referred to as a multi-stream join, a query on multiple tables may be referred to as a multi-table join, and a mixed query on streams and tables may be referred to as a stream-table join), and an execution plan tree corresponding to the query tree after rule replacement is obtained through the optimizer, including: obtaining an object corresponding to the execution statement through the optimizer, and determining a position and a type of a node corresponding to the object in the execution plan tree according to the type of the object, wherein the object includes stream data and table data; and querying the stream data by calling an operator corresponding to the execution plan tree through the executor, including: traversing the execution plan tree through the executor and associating the calculation results of the nodes, wherein the traversal is achieved according to the type and position of each node in the execution plan tree.
[0145] Optionally, the stream corresponding to the stream table join query is a stream object or another stream object materialized after a stream query on a stream object. Table refers to a table object, and the query result corresponding to the stream table join is stream data. The syntax of the execution statement corresponding to the stream table join can be:
[0146] SELECT[*|expression[[AS]output_name][,...]]
[0147] FROM{stream_name|table_name}[[AS]alias]
[0148] [INNER|LEFT|RIGHT]JOIN{stream_name|table_name}[[AS]alias]
[0149] [ON join_condition|USING(join_column[,...])]
[0150] [WHERE condition][EMIT CHANGES]
[0151] In the syntax, SELECT[*|expression[[AS]output_name][,...]] indicates selecting certain fields or expressions from the {stream_name|table_name} table or stream specified by FROM, [INNER|LEFT|RIGHT]JOIN indicates whether the association is inner join, left join, or right join. {stream_name|table_name} indicates another associated stream or table, [ON join_condition|USING(join_column[,...])] indicates which field the two streams or tables are associated with, [WHERE condition] specifies the filter condition, and [EMIT CHANGES] indicates stream processing, and the results are returned in push mode.
[0152] In one embodiment, the query corresponding to the flow table join is executed as follows Figure 8 , Fig. 9 As shown in the figure, in a relational database, stream data obtains incremental data through push mode, and tables obtain historical data through pull mode. The execution statement generates a query tree through the parser, a rewritten query tree through the rewriter, and an execution plan tree through the optimizer. When the optimizer generates the execution plan tree, the operator used to process stream data is set at the leftmost leaf node of the execution plan tree, and the root node type of the execution plan tree corresponding to the stream table join is NestLoop. Each node of the execution plan tree is a subtree and an operator node. NestLoopJoin in the execution plan tree represents a nested query association operator, Seq Scan sa represents a sequential scan of a stream object sa, HashJoin represents a Hash association operator, Seq Scan ta represents a sequential scan of a table object ta, and Seq Scan tb represents a sequential scan of a table object tb. The scan of a table object can be a sequential scan or an index scan.
[0153] During the execution process, the executor first obtains the left subtree of the execution plan tree and then the right subtree. When implementing the effect of stream table join, a tuple is obtained from the stream (tuple is a tuple, and records in the database are stored and returned in the form of tuples), and the corresponding tuple that meets the conditions is searched in the table and the associated result is returned to the upstream node (for the executor, the upstream node is the query background process, and for the query background process, the upstream node is the preset driver), and is pushed to the client in real time through the upstream node.
[0154] Optionally, in a stream-table join, when the optimizer constructs all possible connection paths between two basic objects (representing the stream object or table object specified in the execution statement), if it encounters operators related to streams and tables, it ensures that the operator corresponding to the stream object is on the left side of the execution plan tree and creates a NestLoop Join path. The processing operations taken by the executor for the join operator in the execution plan tree are as follows: Fig. 9 As shown, it includes: first obtaining the calculation result of the left child node, then obtaining the calculation result of the right child node for association, and continuously iterating. If new stream data is generated, the data in the memory message queue record is obtained, and the obtained data is associated with the table record obtained by the right subtree. If the memory message queue is empty, wait.
[0155] Optionally, the relational database of the present application can also implement multi-stream association query (multi-stream join) and multi-stream multi-table association query (multi-stream multi-table join). The corresponding execution statement includes a multi-stream query statement, and the executor calls the operator corresponding to the execution plan tree to query the stream data, including: through the executor, the preset operator for reading the memory message queue in the execution plan tree is matched with the same memory message queue, and the execution plan tree is traversed according to the type and position of each node in the execution plan tree, and the calculation results of the nodes are associated.
[0156] Optionally, there are three types of multi-stream joins: regular join, interval join, and window join.
[0157] Among them, in multi-stream join, the general join syntax is as follows:
[0158] SELECT[*|expression[[AS]output_name][,...]]
[0159] FROM {stream_name}[[AS]alias]
[0160] [INNER|LEFT|RIGHT|FULL OUTER]JOIN{stream_name}[[AS]alias]
[0161] [ON join_condition|USING(join_column[,...])]
[0162] [WHERE condition][EMIT CHANGES]
[0163] Based on the above syntax, we can know that the position of the stream object to be queried is set, and it is divided into left stream and right stream according to its position. When the executor executes the execution plan tree corresponding to the execution statement, the newly added records of the left stream of the execution plan tree (newly acquired stream data) will be associated with the historical records and newly added records of the right stream, and the newly added records of the right stream will also be associated with the historical records and newly added records of the left stream.
[0164] When the execution plan tree corresponding to the interval join is executed, the newly added records of the left stream are associated with the records of the right stream within the specified time range before and after.
[0165] The syntax of the execution statement related to window join is as follows:
[0166] SELECT[*|expression[[AS]output_name][,...]]
[0167] [,WindowBegin()[[AS]output_name]
[0168] [,WindowEnd()[[AS]output_name]]]
[0169] FROM {stream_name}[[AS]alias]
[0170] [INNER|LEFT|RIGHT|FULL OUTER]JOIN{stream_name}[[AS]alias]
[0171] [ON join_condition|USING(join_column[,...])]
[0172] [WHERE condition]
[0173] [[{TUMBLE(event_time_field,<window_size> )|
[0174] HOP(event_time_field,<window_size> ,<slide_size> )}
[0175] [EMIT CHANGES]
[0176] <window_size> <slide><watermark_size>are interval'quantity unit'
[0177] In window join, when the executor executes a stream data query, within the time window specified by the execution statement, it associates the newly added records of the left stream with the historical and newly added records of the right stream, and associates the newly added records of the right stream with the historical and newly added records of the left stream.
[0178] In one embodiment, a conventional join query is performed on stream objects sa and sb. The optimizer generates an execution plan tree based on the query, and the executor executes the process based on the plan tree as follows: Fig.10 , Fig.11 As shown. The top operator of the double stream join is MultiStreamJoin (which stands for multi-stream join). Its left and right subtrees are both NestLoopJoin operators. The left subtree represents a stream-table join with sa as the stream and sb as the table, and the right subtree represents a stream-table join with sb as the stream and sa as the table. The result of the left and right subtrees NestLoopJoin is the result of MultiStreamJoin. Among them, sb storage represents the storage of stream object sb, and sa storage represents the storage of stream object sa.
[0179] When the executor executes the MultiStreamJoin operator, it performs the following processing:
[0180] (1) When executing the first operation, the Seq Scan operators of the two lower streams are called and registered on the same message queue (i.e., Memqueue sa, sb in the figure); (2) The top-level MultiStreamJoin node of the dual-stream join waits for the record of the message queue. If there is no record, it will keep waiting. If the record of the message queue is obtained, it will be saved in the Estate (execution status structure) of the current execution plan. Then, according to whether the object to which the message belongs is the scan object of the left sub-operator (SeqScan sa) of the left sub-operator (NestLoopJoin) or the scan object of the left sub-operator (Seq Scan sb) of the right sub-operator (NestLoopJoin), it is decided to execute the left sub-operator NestLoopJoin or the right sub-operator NestLoopJoin; (3) The scan result of the left sub-operator of NestLoopJoin directly takes the current message queue record saved in the Estate. The right sub-operator of NestLoopJoin treats the corresponding stream object as a table scan. If there is an index, it will perform index scan (the optimizer may generate Index based on cost estimation). Scan operator), the result of NestLoopJoin is the result of this MultiStreamJoin; (4) Repeat steps (2) to (3).
[0181] Optionally, the multi-stream multi-table join is a combination of the stream table join and the multi-stream join, and the multi-stream multi-table join is implemented based on the query operation of the stream table join and the multi-stream join.
[0182] In one embodiment, the execution plan tree generated by executing the statement of double-stream double-table join for stream sa, stream sb, table tba, and table tbb is as follows: Fig.12 As shown, the executor executes the following according to the execution plan tree: Fig.13 The operation shown. The top-level operator of the dual-stream dual-table join is still MultiStreamJoin, and its left and right subtrees are both NestLoopJoin operators. Since multiple objects are involved in the join, multiple join operators are nested. The left subtree represents the stream-table join with sa as the stream, sb, tba, and tbb as the tables (the optimizer may generate MergeJoin or HashJoin based on cost estimation), and the right subtree represents the stream-table join with sb as the stream, and tba, tbb as the tables (the optimizer may generate MergeJoin or HashJoin based on cost estimation). The result of joining a stream and multiple tables is also a stream, and the result of their merging is the result of MultiStreamJoin. Among them, Seq Scantba represents the sequential scan of table tba, Seq Scan tbb represents the sequential scan of table tbb, tba storagesb represents the storage of table object tba, and tbb storage represents the storage of table object tbb.
[0183] The execution process of dual-stream dual-table join is similar to that of dual-stream join. The specific execution process includes: (1) When executing the first operation, the Seq Scan operators of the two lower streams are called and registered on the same message queue (i.e., Memqueue sa, sb in the figure); (2) The top-level MultiStreamJoin operator node waits for the record of the message queue. If there is no record, it will keep waiting. If the record of the message queue is obtained, it will be saved in the Estate (execution status structure) of the current execution plan. Then, the message is forwarded to the leftmost leaf operator (Seq Scan sa) of the left child operator (NestLoopJoin) or the leftmost leaf operator (Seq Scan sa) of the right child operator (NestLoop Join). sb) to determine whether to execute the left child operator NestLoopJoin or the right child operator NestLoopJoin; (3) The scan result of the leftmost leaf operator of NestLoopJoin directly takes the current message queue record saved in the Estate. The right child operator of NestLoopJoin treats the corresponding stream object as a table scan. If there is an index, it performs index scan (the optimizer may generate MergeJoin or HashJoin based on cost estimation). The executor recursively performs stream table Join along the execution plan tree. The result of the top-level NestLoopJoin is the result of this MultiStreamJoin; (4) Repeat steps (2) to (3).
[0184] The relational database of this application has the following advantages over the existing stream processing system:
[0185] 1. The technology stack is simple and stable.
[0186] Stream processing systems such as Flink require multiple technical components such as Kafka, database, and Hadoop. If any one of the components fails, the entire system will become unusable. The database in this application only requires one technical component, so it is more stable.
[0187] 2. Low learning and maintenance costs.
[0188] Stream processing systems such as Flink need to be used with multiple technical components such as Kafka, database, and Hadoop. Development and operation personnel need to learn multiple technical components, and it is troublesome to analyze and locate problems with multiple components. This application only needs to master the use and maintenance of the database. After decades of development, the use of the database is a basic skill for development and operation personnel. In addition, there are standard routines for database problem location and analysis methods.
[0189] 3. It can perform pure SQL operations, is simple and convenient to use, and can quickly respond to the complexity and variability of the business.
[0190] The main stream processing functions of Flink and other stream processing systems are implemented by writing java / scala / python programs. Although Flink later added the Flink SQL function, it is OK to use SQL to operate simple stream processing functions, but you still have to write java / scala / python programs when you encounter complex stream processing such as stream table JOIN. This application adds stream processing capabilities to the original SQL engine of the database. The SQL engine (execution module) of the database itself is very powerful. After adding stream processing capabilities, the SQL engine can not only do batch processing and stream processing, but also mixed processing such as stream table JOIN.
[0191] 4. Naturally supports modification and deletion of stream data and transaction ACID.
[0192] At present, streaming data modification and deletion in streaming processing systems such as Flink can only be achieved through the means of realization: the deletion operation is to add a stream data that is exactly the same as the original one and mark it with a deletion mark; if it is a modification operation, it is to add a stream data that is exactly the same as the original one and mark it with a deletion mark, and then add a modified stream data; these operations can only be implemented programmatically. The relational data of this application can directly use UPDATE and DELETE statements through standard SQL to implement streaming data modification and deletion operations, and it is to add streaming processing capabilities in the database kernel. Transaction ACID is a basic capability of the database, so it naturally supports transaction ACID for streaming data processing.
[0193] In an optional embodiment, an electronic device is provided, such as Fig.14 As shown, Fig.14 The electronic device 4000 shown includes: a processor 4001 and a memory 4003. The processor 4001 and the memory 4003 are connected, such as through a bus 4002. Optionally, the electronic device 4000 may also include a transceiver 4004, which may be used for data interaction between the electronic device and other electronic devices, such as data transmission and / or data reception. It should be noted that in actual applications, the transceiver 4004 is not limited to one, and the structure of the electronic device 4000 does not constitute a limitation on the embodiments of the present application.
[0194] Processor 4001 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It may implement or execute various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 4001 may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and the like.
[0195] The bus 4002 may include a path to transmit information between the above components. The bus 4002 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The bus 4002 may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0196] Memory 4003 can be ROM (Read Only Memory) or other types of static storage devices that can store static information and instructions, RAM (Random Access Memory) or other types of dynamic storage devices that can store information and instructions, or it can be EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disk storage, optical disk storage (including compressed optical disk, laser disc, optical disk, digital versatile disc, Blu-ray disc, etc.), magnetic disk storage medium, other magnetic storage devices or any other medium that can be used to carry or store computer programs and can be read by a computer, without limitation here.
[0197] The memory 4003 is used to store the computer program for executing the embodiment of the present application, and the execution is controlled by the processor 4001. The processor 4001 is used to execute the computer program stored in the memory 4003 to implement the relational database described in the above embodiment.
[0198] Among them, the electronic device can be any electronic product that can interact with an object, such as a personal computer, a tablet computer, a smart phone, a personal digital assistant (PDA), a game console, an interactive network television (IPTV), a smart wearable device, etc.
[0199] The electronic device may also include a network device and / or an object device, wherein the network device includes, but is not limited to, a single network server, a server group consisting of multiple network servers, or a cloud consisting of a large number of hosts or network servers based on cloud computing.
[0200] The network where the electronic device is located includes but is not limited to the Internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (Virtual Private Network, VPN), etc.
[0201] The terms "first", "second", "third", "fourth", "1", "2", etc. (if any) in the specification and claims of this application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than that shown or described in the drawings.
[0202] It should be understood that, although each operation step is indicated by arrows in the flowchart of the embodiment of the present application, the implementation order of these steps is not limited to the order indicated by the arrows. Unless clearly stated herein, in some implementation scenarios of the embodiment of the present application, the implementation steps in each flowchart can be performed in other orders according to demand. In addition, some or all of the steps in each flowchart may include multiple sub-steps or multiple stages based on actual implementation scenarios. Some or all of these sub-steps or stages may be executed at the same time, and each sub-step or stage in these sub-steps or stages may also be executed at different times respectively. In different scenarios of execution time, the execution order of these sub-steps or stages may be flexibly configured according to demand, and the embodiment of the present application does not limit this.
[0203] The above is only an optional implementation method for some implementation scenarios of the present application. It should be pointed out that for ordinary technicians in this technical field, without departing from the technical concept of the solution of the present application, other similar implementation methods based on the technical ideas of the present application are also within the protection scope of the embodiments of the present application.< / slide>
Claims
1. A relational database for streaming data, It is characterized in that include: Execution module, storage module; The storage module is connected to the execution module, and is used to receive the stream data transmitted by the execution module, and establish a stream object storage for storing the stream data, wherein the stream object storage is established based on the storage of the table object in the relational database; The execution module is used to parse the execution statement, establish an execution plan tree corresponding to the execution statement, and process the stream data based on the execution plan tree.
2. The relational database according to claim 1, It is characterized in that The relational database also includes a connection management module with a preset driver, and the connection management module is configured to connect with the access object through the preset driver, establish a data processing process corresponding to the access object, send the execution statement transmitted by the access object through the preset driver to the execution module through the data processing process, and use the data processing process to push the execution result fed back by the execution module in real time.
3. The relational database according to claim 2, It is characterized in that The execution module includes a parser, a rule replacer, an optimizer, and an executor connected in sequence. The execution module is used to parse the execution statement and establish the execution plan tree corresponding to the execution statement, specifically for: Parsing the execution statement by the parser to generate a query tree, and transmitting the query tree to the rule replacer; Perform rule replacement on the query tree by the rule replacer; Obtaining, by the optimizer, an execution plan tree corresponding to the query tree after rule replacement; The executor calls the operator corresponding to the execution plan tree to store or query the stream data.
4. The relational database according to claim 3, It is characterized in that The execution statement includes a stream data storage statement, and the executor calls the operator corresponding to the execution plan tree to store the stream data, including: The executor calls the operator to perform corresponding processing on the stream data corresponding to the execution statement, and uses the preset operator to store the stream data into the stream object storage unit. The corresponding processing includes setting a timestamp corresponding to the stream data, constraint checking, and indexing. If it is determined that there is a query process corresponding to the stream data, the data is pushed to the memory message queue corresponding to the query process.
5. The relational database according to claim 3, It is characterized in that The execution statement includes a streaming query statement, and the executor calls the operator corresponding to the execution plan tree to query the streaming data, including: The execution plan tree is traversed by the executor, and the operator corresponding to each node on the execution plan tree is called to filter the stream data that meets the query condition in the memory message queue corresponding to the execution statement in real time, where the query condition is determined based on the execution statement; The stream data is pushed to the data processing process in real time.
6. The relational database according to claim 3, It is characterized in that When the connection management module is used to execute the query result fed back by the execution module by using the data processing process and the preset driver to be pushed in real time, it is specifically used to: If the query result is not received, the data processing process waits for the execution module to feedback the query result, and after determining that the query result is received, the query result is fed back to the preset driver, and the query result does not include a command completion instruction; The preset driver waits for the data processing process to transmit the action, and after receiving the query result, sends the query result to the access object.
7. The relational database according to claim 3, It is characterized in that The execution statement includes a flow table associated query statement, and the execution plan tree corresponding to the query tree after rule replacement obtained by the optimizer includes: Obtaining the object corresponding to the execution statement through the optimizer, and determining the position and type of the node corresponding to the object in the execution plan tree according to the type of the object, wherein the object includes stream data and table data; The query of stream data is performed by calling the operator corresponding to the execution plan tree through the executor, including: The execution plan tree is traversed by the executor and the calculation results of the nodes are associated. The traversal is achieved according to the type and position of each node in the execution plan tree.
8. The relational database according to claim 3, It is characterized in that The execution statement includes a multi-stream query statement, and the executor calls the operator corresponding to the execution plan tree to query the stream data, including: The executor corresponds the preset operator for reading the memory message queue in the execution plan tree to the same memory message queue, traverses the execution plan tree according to the type and position of each node in the execution plan tree, and associates the calculation results of the nodes.
9. The relational database according to claim 3, It is characterized in that The execution statement includes a window statistics statement, and the execution module, when used to parse the execution statement, is specifically used to: Parse the execution statement to obtain calculation parameters corresponding to the preset operator, where the calculation parameters include at least one of a window type, a window length, a sliding step, a watermark, and a delay flag; When the execution module is used to process the stream data based on the execution plan tree, it is specifically used to: The preset operator and the calculation parameters are used to perform window grouping on the stream data transmitted into the relational database, incremental calculation is performed according to the result of the window grouping, the calculation result is output, and the next cycle of the execution plan tree is executed.
10. The relational database according to claim 1, It is characterized in that The storage module also includes an extension plug-in with multiple streaming read and write external sources. The relational database determines the target extension plug-in and the target object called in the extension plug-in based on the external source read and write instructions obtained, and calls the target extension plug-in to read and write the target object in the external source, wherein the target object includes a streaming external data source object using streaming data.
11. An electronic device comprising a memory, a processor and a computer program stored in the memory, It is characterized in that The processor executes the computer program to implement the relational database for stream data according to any one of claims 1 to 10.
Citation Information
Patent Citations
Memory stream computing platform system
CN109614413A
Database query processing method and device, equipment and storage medium
CN115757477A
Data processing system and method
CN117931847A
Cited By
Database execution engine self-adaptive push-pull model combination method and assembly
CN118939687A
Preparative statement execution method and device, electronic equipment and readable storage medium
CN119782362A
Multi-line insertion method and device in distributed database system, computer equipment, readable storage medium and program product
CN121542278A
