Method, device and system for acquiring statistical information

By using query statements in a distributed database to randomly sample global secondary indexes and dynamically adjust the sampling rate, the problem of difficulty in balancing statistical information collection performance and accuracy in the existing technology is solved, and query performance is improved.

CN118733639APending Publication Date: 2024-10-01HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310356027.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-03-29
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

The existing method of collecting global secondary index statistical information in distributed databases cannot guarantee the accuracy of statistical information and collection performance at the same time, resulting in reduced query performance.

Method used

By passing messages between data nodes and coordination nodes, query statements are used to randomly sample global secondary indexes, and the sampling rate is dynamically adjusted according to the statistical information of the base table to ensure the accuracy and rapid collection of statistical information.

Benefits of technology

It achieves rapid collection of global secondary index statistical information while ensuring the accuracy of statistical information, improves query performance, and reduces the time-consuming collection process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118733639A_ABST
    Figure CN118733639A_ABST
Patent Text Reader

Abstract

The invention provides a method, equipment and system for acquiring statistical information, relates to the technical field of databases, and can ensure the accuracy and collection performance of collected statistical information at the same time. The method comprises the following steps: receiving a first message from a coordination node, sampling a first global secondary index in a data node by adopting a query statement to obtain statistical information of the first global secondary index, and sending the statistical information of the first global secondary index to the coordination node. Wherein the first message is used for indicating to obtain statistical information of the first global secondary index in the distributed database, and the query statement is determined according to the sampling rate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of database technology, and in particular to a method, device and system for obtaining statistical information. Background Art

[0002] In a distributed database, querying non-distributed keys in the base table through global secondary indexes can improve query performance. The query plan of the global secondary index is generated based on the statistical information of the global secondary index. If the collected statistical information of the global secondary index is inaccurate, it may not be possible to generate a better query plan, resulting in reduced query performance.

[0003] However, the existing solutions for collecting statistical information of global secondary indexes cannot guarantee both the accuracy and collection performance of the statistical information. For example, the process of collecting statistical information of global secondary indexes takes too long. Summary of the invention

[0004] The present application provides a method, device and system for obtaining statistical information, which can simultaneously ensure the accuracy and collection performance of the collected statistical information.

[0005] In order to achieve the above objectives, this application adopts the following technical solutions:

[0006] In a first aspect, a method for obtaining statistical information is provided, which is applied to a data node. The method can be executed by a data node, or by a component of a data node, such as a processor, a chip, or a chip system of the data node, or can be implemented by a logic module or software that can implement all or part of the data node function. The method includes: receiving a first message from a coordination node, sampling a first global secondary index in the data node using a query statement, obtaining statistical information of the first global secondary index, and sending the statistical information of the first global secondary index to the coordination node. The first message is used to indicate the acquisition of statistical information of the first global secondary index in a distributed database, and the query statement is determined according to the sampling rate.

[0007] Based on the method provided in the first aspect, the data node uses a query statement to implement random sampling of the global secondary index. The query statement is determined according to the sampling rate. It can quickly determine the statistical information of the global secondary index while ensuring accuracy. It takes very little time and has good performance.

[0008] In a possible design, the query statement is used to count the number of first data in the first global secondary index, and the random number corresponding to the first data is less than the sampling rate.

[0009] Exemplarily, the query statement can be "select count(*) from (select * from idx_gsi where random() < sample_rate)". "select * from idx_gsi where random() < sample_rate" means obtaining the data corresponding when the random number is less than the sampling rate when acquiring the data of the first global secondary index, and "select count(*) from ()" is used to count the number of data obtained in the subquery.

[0010] In a possible design manner, after receiving the first message from the coordinator node, the method provided by the first aspect further includes: receiving the statistical information of the first base table from the coordinator node, and determining the sampling rate according to the statistical information of the first base table. Wherein, the first global secondary index is one of at least one global secondary index established based on the first base table. For example, the statistical information of the first base table is determined by the coordinator node.

[0011] In this way, the data node determines the sampling rate according to the statistical information of the base table, which can realize dynamically and adaptively adjusting the sampling rate according to the statistical information of the base table. For example, automatically adjusting the sampling rate according to the size of the data volume in the base table can ensure the accuracy of obtaining the statistical information of the global secondary index.

[0012] In a possible design manner, the statistical information of the first base table includes but is not limited to one or more of the following: the number of data included in the first base table, the number of pages included in the first base table, the most common values (MCV) of the first base table, and the histogram of the first base table.

[0013] In a possible design manner, the statistical information of the first base table includes the number of data included in the first base table, and the sampling rate satisfies the following relationship: S = min(D / T, 1). Wherein, S represents the sampling rate, D represents the number of samples, and T represents the number of data included in the first base table.

[0014] In a possible design manner, the statistical information of the first global secondary index includes but is not limited to one or more of the following: the number of data included in the first global secondary index, the number of pages included in the first global secondary index, the MCV of the first global secondary index, and the histogram of the first global secondary index.

[0015] In a possible design manner, the distributed database is deployed in at least N data nodes and at least one coordinator node, where N is an integer greater than or equal to 1.

[0016] In a second aspect, a method for obtaining statistical information is provided, which is applied to a coordination node. The method can be executed by the coordination node, or by a component of the coordination node, such as a processor, a chip, or a chip system of the coordination node, or can be implemented by a logic module or software that can implement all or part of the functions of the coordination node. The method includes: detecting a first instruction. The first instruction is used to indicate the acquisition of statistical information of a first global secondary index in a distributed database. A first message is sent to each of N data nodes. N is an integer greater than or equal to 1, and the first message is used to indicate the acquisition of statistical information of a first global secondary index in a distributed database. Receive N statistical information of the first global secondary index. Based on the N statistical information of the first global secondary index, determine the total statistical information of the first global secondary index.

[0017] In a possible design, after sending the first message to the data node, the method provided in the second aspect may further include: sending statistical information of the first base table to the data node. The first global secondary index is one of at least one global secondary index established based on the first base table.

[0018] In a possible design, the statistical information of the first base table includes one or more of the following: the number of data items included in the first base table, the number of pages included in the first base table, the MCV of the first base table, and the histogram of the first base table.

[0019] In one possible design, the statistical information of the first global secondary index includes one or more of the following: the number of data items included in the first global secondary index, the number of pages included in the first global secondary index, the MCV of the first global secondary index, and the histogram of the first global secondary index.

[0020] In a possible design, the distributed database is deployed in at least N data nodes and at least one coordination node.

[0021] In addition, the technical effects of the method described in the second aspect can refer to the technical effects of the method described in any possible implementation method of the first aspect, and will not be repeated here.

[0022] According to a third aspect, a first electronic device is provided. The first electronic device includes: a processing unit and a transceiver unit.

[0023] The transceiver unit is used to receive a first message from the coordination node. The processing unit is used to sample the first global secondary index in the data node using a query statement to obtain statistical information of the first global secondary index. The transceiver unit is also used to send the statistical information of the first global secondary index to the coordination node. The first message is used to indicate the acquisition of statistical information of the first global secondary index in the distributed database, and the query statement is determined according to the sampling rate.

[0024] In a possible design, the query statement is used to count the number of first data in the first global secondary index, and the random number corresponding to the first data is less than the sampling rate.

[0025] In a possible design, the transceiver unit is further used to receive statistical information of the first base table from the coordination node. The processing unit is further used to determine the sampling rate according to the statistical information of the first base table. The first global secondary index is one of at least one global secondary index established based on the first base table.

[0026] In a possible design, the statistical information of the first base table includes one or more of the following: the number of data items included in the first base table, the number of pages included in the first base table, the MCV of the first base table, and the histogram of the first base table.

[0027] In a possible design, the statistical information of the first base table includes the number of data included in the first base table, and the sampling rate satisfies the following relationship: S=min(D / T,1), where S represents the sampling rate, D represents the number of samples, and T represents the number of data included in the first base table.

[0028] In one possible design, the statistical information of the first global secondary index includes one or more of the following: the number of data items included in the first global secondary index, the number of pages included in the first global secondary index, the MCV of the first global secondary index, and the histogram of the first global secondary index.

[0029] In one possible design, the distributed database is deployed in at least N first electronic devices and at least one coordination node.

[0030] It should be noted that the transceiver unit can be provided separately (eg, a receiving unit and a sending unit), or can be integrated into one module, namely, the transceiver unit. The present application does not specifically limit the specific implementation of the transceiver unit.

[0031] Optionally, the first electronic device described in the third aspect may further include a storage unit, wherein the storage unit stores a program or an instruction. When the processing unit executes the program or the instruction, the first electronic device described in the third aspect may execute the method described in the first aspect.

[0032] It should be noted that the first electronic device described in the third aspect may be a coordination node, etc., or may be a chip (system) or other parts or components that can be set in the first electronic device and other devices, and this application does not limit this.

[0033] In addition, the technical effects of the first electronic device described in the third aspect can refer to the technical effects of the method described in any possible implementation method of the first aspect, and will not be repeated here.

[0034] In a fourth aspect, a second electronic device is provided, and the second electronic device includes: a transceiver unit and a processing unit.

[0035] Wherein, the processing unit is used to detect the first instruction. Wherein, the first instruction is used to indicate the acquisition of statistical information of the first global secondary index in the distributed database. The transceiver unit is used to send a first message to N data nodes respectively. Wherein, N is an integer greater than or equal to 1, and the first message is used to indicate the acquisition of statistical information of the first global secondary index in the distributed database. The transceiver unit is also used to receive N statistical information of the first global secondary index. The processing unit is also used to determine the total statistical information of the first global secondary index based on the N statistical information of the first global secondary index.

[0036] In a possible design, the transceiver unit is further configured to send statistical information of the first base table to the data node, wherein the first global secondary index is one of at least one global secondary index established based on the first base table.

[0037] In a possible design, the statistical information of the first base table includes one or more of the following: the number of data items included in the first base table, the number of pages included in the first base table, the MCV of the first base table, and the histogram of the first base table.

[0038] In one possible design, the statistical information of the first global secondary index includes one or more of the following: the number of data items included in the first global secondary index, the number of pages included in the first global secondary index, the MCV of the first global secondary index, and the histogram of the first global secondary index.

[0039] In one possible design, the distributed database is deployed in at least N data nodes and at least one second electronic device.

[0040] It should be noted that the transceiver unit can be separately provided (e.g., a receiving unit and a transmitting unit), or can be integrated into one module, namely, the transceiver unit. The transceiver unit and the transmission unit can be the same unit (or the same module) or different units, and the present application does not specifically limit the specific implementation of the transceiver unit and the transmission unit.

[0041] Optionally, the second electronic device described in the fourth aspect may further include a storage unit, wherein the storage unit stores a program or an instruction. When the processing unit executes the program or the instruction, the second electronic device described in the fourth aspect may execute the method described in the second aspect.

[0042] It should be noted that the second electronic device described in the fourth aspect may be a coordination node, etc., or may be a chip (system) or other parts or components that can be set in a second electronic device or other device, and this application does not limit this.

[0043] In addition, the technical effects of the second electronic device described in the fourth aspect can refer to the technical effects of the method described in any possible implementation method of the second aspect, and will not be repeated here.

[0044] In a fifth aspect, a first electronic device is provided, the first electronic device comprising: one or more processors; one or more memories; the memories storing one or more programs, when the one or more programs are executed by the one or more processors, the first electronic device executes the method in any possible implementation manner of the first aspect. Optionally, the first electronic device may also include a display screen.

[0045] In a sixth aspect, a second electronic device is provided, the second electronic device comprising: one or more processors; one or more memories; the memories storing one or more programs, when the one or more programs are executed by the one or more processors, the second electronic device executes the method in any possible implementation of the second aspect. Optionally, the second electronic device may further include a display screen.

[0046] In the seventh aspect, an embodiment of the present application provides a circuit system, the circuit system includes a processing circuit, and the processing circuit is configured to execute a method as any one of the embodiments in the first aspect; or, the processing circuit is configured to execute a method as any one of the embodiments in the second aspect.

[0047] In an eighth aspect, a communication system is provided, the communication system comprising the first electronic device as described in the third aspect, and the second electronic device as described in the fourth aspect. Alternatively, the communication system comprises the data node for implementing the method as described in the first aspect as described in the third aspect, and the coordination node for implementing the method as described in the second aspect as described in the fourth aspect. Optionally, the number of secondary screens may be one or more.

[0048] In a ninth aspect, a readable storage medium is provided, which includes a program. When the program runs on a device, the device executes a method in any possible implementation of the first aspect or the second aspect.

[0049] In a tenth aspect, a chip system is provided, the chip system comprising a processor and a memory, wherein a program is stored in the memory; when the program is executed by the processor, the processor implements the method in any possible implementation of the first aspect or the second aspect. The chip system may be composed of a chip, or may include a chip and other discrete devices.

[0050] In an eleventh aspect, a program product is provided. When the program product is run on a computer or a device, the computer or the device implements the method in any possible implementation manner of the first aspect or the second aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] Figure 1A A schematic diagram of a system architecture provided for an embodiment of the present application;

[0052] Figure 1B A schematic diagram of a process for obtaining statistical information of a local index provided in an embodiment of the present application;

[0053] Figure 1C A schematic diagram of a system architecture provided for an embodiment of the present application;

[0054] Figure 1D A schematic diagram of a flow chart of statistical information of a global secondary index provided in an embodiment of the present application;

[0055] Figure 1E A schematic diagram of a communication system to which a method for obtaining statistical information provided in an embodiment of the present application is applied;

[0056] Figure 2 A schematic diagram of the hardware structure of a coordination node and a data node provided in an embodiment of the present application;

[0057] Figure 3 A software structure diagram of a coordination node and a data node provided in an embodiment of the present application;

[0058] Figure 4 A flowchart of a method for obtaining statistical information provided in an embodiment of the present application;

[0059] Figures 5A-8B Some schematic diagrams of scenarios provided for embodiments of the present application;

[0060] Fig. 9 A schematic diagram of the structure of a device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0061] The technical solutions in the embodiments of the present application are described below in conjunction with the accompanying drawings in the embodiments of the present application. Wherein, in the description of the embodiments of the present application, the terms used in the following embodiments are only for the purpose of describing specific embodiments, and are not intended to be used as limitations on the present application. As used in the specification and the appended claims of the present application, the singular expressions "one", "a kind of", "said", "above", "the" and "this" are intended to include expressions such as "one or more", unless there is a clear indication to the contrary in the context. It should also be understood that in the following embodiments of the present application, "at least one", "one or more" refer to one or more (including two).

[0062] References to "one embodiment" or "some embodiments" etc. described in this specification mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Thus, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways. The term "connection" includes direct connection and indirect connection, unless otherwise specified. "First" and "second" are used for descriptive purposes only and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated.

[0063] In the embodiments of the present application, the words "exemplarily" or "for example" are used to indicate examples, illustrations or explanations. Any embodiment or design described as "exemplarily" or "for example" in the embodiments of the present application should not be interpreted as being more preferred or more advantageous than other embodiments or designs. Specifically, the use of words such as "exemplarily" or "for example" is intended to present related concepts in a specific way.

[0064] In some embodiments, the base table and local index of the distributed database can be stored in at least one data node (DN), for example, in combination with Figure 1A , base table data 1, base table data 2 to base table data n are stored in data node 1, data node 2 to data node n respectively, local index data 1, local index data 2 to local index data n are stored in data node 1, data node 2 to data node n respectively, and n is an integer.

[0065] and Figure 1A Combined with the process of obtaining local index statistics, Figure 1B shown.

[0066] Step 1: The coordinator node (CN) detects a command to collect statistics of the base table.

[0067] For example, the coordinating node detects an operation performed by a user to collect statistics on a base table.

[0068] Step 2: The coordinating node obtains the statistical information of the base table.

[0069] Step 3: The coordinating node uses the statistics of the base table to update the statistics of the local index.

[0070] Exemplarily, the above step three includes: the node directly uses the statistical information of the base table as the statistical information of the local index, that is, the statistical information of the local index directly reuses the statistical information of the base table.

[0071] Figure 1B The method shown can quickly collect statistics of local indexes. However, when this method is used to obtain statistics of global secondary indexes, due to the inconsistency between the distribution key of the global secondary index and the distribution key of the base table, the statistics of the global secondary index and the base table on each data node may be different. If the base table statistics are directly used to update the statistics of the global secondary index, the statistics of the global secondary index will be inaccurate, which will further lead to the inability to generate a better query plan (also called an execution plan), thereby reducing query performance.

[0072] In some other embodiments, the base table and the global secondary index of the distributed database may be stored in at least one data node, for example, in combination with Figure 1C , base table data 1, base table data 2 to base table data n are stored in data node 1, data node 2 to data node n respectively, global secondary index data 1, global secondary index data 2 to global secondary index data n are stored in data node 1, data node 2 to data node n respectively, and n is an integer.

[0073] and Figure 1C Combined with the process of obtaining statistical information of global secondary indexes, Figure 1D shown.

[0074] In step a, the coordinating node detects a command to collect statistics of a global secondary index.

[0075] Step b: the coordinating node generates a first statement in the distributed database.

[0076] Exemplarily, the first statement is used to query information of a global secondary index.

[0077] Step c: The coordinating node executes the first statement in the distributed database, traverses each data node, and obtains statistical information of the global secondary index of each data node.

[0078] Step d: The coordinating node updates the statistical information of the global secondary index based on the obtained statistical information of the global secondary index of each data node.

[0079] Figure 1D The method shown traverses the entire global secondary index through each global secondary index data in each data node, calculates and updates the statistical information of the global secondary index of each data node. Although accurate statistical information of the global secondary index can be obtained, the collection process is time-consuming and the collection performance is poor.

[0080] Therefore, an embodiment of the present application provides a method for obtaining statistical information, which implements random sampling of the global secondary index based on the sampling rate and query statement. It can quickly determine the statistical information of the global secondary index while ensuring accuracy, with short time consumption and good performance.

[0081] In order to make the embodiments of the present application clearer, some contents and concepts related to the embodiments of the present application are uniformly introduced below.

[0082] First, distributed database:

[0083] A distributed database is a logically unified database formed by connecting multiple physically dispersed database units using a computer network. Each connected database unit is called a site or node.

[0084] Second, the base table:

[0085] A base table is an object used to store data in a database. It is a collection of structured data and the foundation of the entire database management system. A table is a database object that contains all the data in the database. A table is defined as a collection of columns.

[0086] Third, global secondary indexes and local indexes:

[0087] An index is a sorted data structure in a database management system to assist in quickly querying and updating data in a database table. A global secondary index is a type of index that is global and effective on all data nodes. A local index is a type of index that is local and effective on the current data node.

[0088] Fourth, distribution key and index key:

[0089] Distribution key: In a distributed database, a column (or combination of columns) that is used to determine the database partition where a specific row of data is stored.

[0090] Index key: A column (or combination of columns) that identifies an index entry.

[0091] Fifth, statistical information:

[0092] Statistics: refers to the information that describes the characteristics of table or index data in the database. Common information includes the number of data records and pages in the table (such as the base table) that describes the scale of the base table, as well as the most common value MCV (high frequency non-null value) and histogram that describes the data distribution characteristics of the database.

[0093] For example, Figure 1E A schematic diagram of a communication system applied to a method for obtaining statistical information provided in an embodiment of the present application.

[0094] The method for obtaining statistical information provided in the embodiment of the present application is applied to a communication system. The communication system includes at least one first device 100 and at least one second device 200. The number of the first devices 100 can be one or more, and the number of the second devices 200 can be one or more. The first device can be called a coordination node, and the second device can be called a data node. Figure 1E A coordination node and multiple data nodes are used as an example.

[0095] Optionally, the data stored between multiple first devices 100 (for example, metadata in a distributed database) is different, and each first device 100 can support multiple different data distribution modes. The data stored between multiple second devices 200 (for example, real data in metadata in a distributed database) is different, and each second device 200 can support multiple different data distribution modes. For example, the role of the coordination node assumed by the first device 100 in the distributed database can be set through a configuration file, and the coordination node can be selected through an election algorithm to set the role of the data node assumed by the second device 200 in the distributed database. This application is explained by taking the statistical information of the global secondary index in the distributed database as an example.

[0096] The first device 100 includes but is not limited to devices such as servers, and the first device can be called a coordination node. The second device 200 includes but is not limited to devices such as servers, and the second device can be called a data node. The embodiment of the present application does not impose any special restrictions on the specific forms of the first device 100 and the second device 200. The operating systems installed in the first device 100 and the second device 200 include but are not limited to Or other operating systems. This application does not limit the specific types of the first device 100 and the second device 200, or the installed operating systems.

[0097] Optionally, the first device 100 and the second device 200 establish a wired or wireless communication connection through a local area network or a remote direct memory access (RDMA) network. Optionally, the first device 100 and the second device 200 may also establish a communication connection through a third-party device in the local area network, such as a router, a gateway, a wireless access point (AP) device, etc.

[0098] It should be noted that the method for obtaining statistical information provided in the embodiment of the present application can be applied to Figure 1E In the communication system or network architecture shown, the specific implementation can refer to the following method embodiment, which will not be repeated here.

[0099] It should be understood that Figure 1E This is a simplified schematic diagram for ease of understanding only. The communication system or network architecture may also include other network devices. Figure 1E Not drawn in.

[0100] Exemplarily, the first device is called a coordinating node, and the second device is called a data node. Figure 2 A schematic diagram of the hardware structure of the coordination node and data node provided in an embodiment of the present application.

[0101] The coordination node includes one or more processors 201. Optionally, the coordination node may also include a communication line 202 and at least one communication interface ( Figure 2 The description is merely illustrative, taking as an example a communication interface 204 and a processor 201), and / or a memory 203.

[0102] The data node includes one or more processors 201. Optionally, the data node may also include a communication line 202 and at least one communication interface ( Figure 2 The description is merely illustrative, taking as an example a communication interface 204 and a processor 201), and / or a memory 203.

[0103] The processor 201 may be a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the present application.

[0104] The communication line 202 may include a path for connecting different components.

[0105] The communication interface 204 may be a transceiver module for communicating with other devices or communication networks, such as Ethernet, wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), RDMA networks and other wireless communications. For example, the transceiver module may be a device such as a transceiver or a transceiver. Optionally, the communication interface 204 may also be a transceiver circuit located in the processor 201 to implement signal input and signal output of the processor.

[0106] The memory 203 may be a device with a storage function. For example, it may be a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM) or other types of dynamic storage devices that can store information and instructions, or an electrically erasable programmable read-only memory (EEPROM), a compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical disc, laser disc, optical disc, digital versatile disc, Blu-ray disc, etc.), a magnetic disk storage medium or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory may exist independently and be connected to the processor via a communication line 202. The memory may also be integrated with the processor.

[0107] The memory 203 is used to store computer-executable instructions for executing the solution of the present application, and the execution is controlled by the processor 201. The processor 201 is used to execute the computer-executable instructions stored in the memory 203, thereby implementing the method provided in the embodiment of the present application.

[0108] Alternatively, in the embodiment of the present application, the processor 201 may also perform functions related to the processing of the method provided in the following embodiments of the present application, and the communication interface 204 is responsible for communicating with other devices or communication networks, which is not specifically limited in the embodiment of the present application.

[0109] Optionally, the memory 203 in the embodiment of the present application may also be used to store information or parameters described in the following embodiments.

[0110] The computer-executable instructions in the embodiments of the present application may also be referred to as application program codes, which is not specifically limited in the embodiments of the present application.

[0111] In a specific implementation, as an embodiment, the processor 201 may include one or more CPUs, such as Figure 2 CPU0 and CPU1 in.

[0112] In a specific implementation, as an embodiment, the coordination node and the data node may include multiple processors, such as Figure 2 201 and processor 207 in the embodiment of the present invention. Each of these processors may be a single-CPU processor or a multi-CPU processor. The processor herein may refer to one or more devices, circuits, and / or processing cores for processing data (e.g., computer program instructions).

[0113] In a specific implementation, as an embodiment, the coordination node and the data node may further include an output device 205 and an input device 206. The output device 205 communicates with the processor 201 and may display information in a variety of ways.

[0114] It can be understood that the structure illustrated in the embodiment of the present application does not constitute a specific limitation on the structure and form of the coordination node and the data node, and the embodiment of the present application does not limit the structure and form of the coordination node and the data node.

[0115] In other embodiments of the present application, the coordination node and the data node may include more or fewer components than shown in the figure, or combine some components, or split some components, or arrange the components differently. The components shown in the figure may be implemented in hardware, software, or a combination of software and hardware.

[0116] in addition, Figure 2 The interface connection relationship between the modules shown is only a schematic illustration and does not constitute a structural limitation on the coordination node and the data node. Figure 2 Different interface connection methods, or a combination of multiple interface connection methods.

[0117] Exemplarily, the software architecture of the terminal may adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservice architecture, or a cloud architecture, etc. Figure 3 A software structure block diagram of a first device 100 (such as a coordination node) and a second device 200 (such as a data node) provided in an embodiment of the present application is shown.

[0118] like Figure 3 As shown in (a), the coordination node includes but is not limited to one or more of the following software modules: a parsing module 301a, an optimization module 302a, and an execution module 303a.

[0119] like Figure 3As shown in (b), the data node includes but is not limited to one or more of the following software modules: a parsing module 301b, an optimization module 302b, and an execution module 303b.

[0120] The parsing module 301a is used to implement the parsing statement (or instruction) function of the coordination node, such as the parsing module 301a, which is used to parse the statistical information collection instruction of the global secondary index.

[0121] The parsing module 301b is used to implement the parsing statement function of the data node, such as the parsing module 301b is used to parse query statements and the like.

[0122] The optimization module 302a is used to optimize statements (or instructions) to improve the execution efficiency of the execution plan. For example, the optimization module 302a is used to optimize the statistics information collection instruction of the global secondary index.

[0123] The optimization module 302b is used to optimize statements (or instructions) to improve the execution efficiency of the execution plan. For example, the optimization module 302b is used to optimize query statements to improve the query efficiency based on the query statements.

[0124] The execution module 303a is used to enable the coordination node to determine the statistical information of the total global secondary index according to the statistical information of the global secondary index from N data nodes.

[0125] The execution module 303b is used to obtain the statistical information of the base table, determine the sampling rate, use the query statement to sample the global secondary index, and send the estimated statistical information of the global secondary index to the coordination node.

[0126] Understandably, Figure 3 The software modules included in the coordination node and data node shown are only used as a possible division method. They may also include more or fewer modules, or there may be other division methods, which are not limited in this application.

[0127] The technical solutions involved in the following embodiments can all be implemented in Figure 2 , and / or Figure 3 The invention is implemented in the device of the structure shown.

[0128] It is understandable that in the embodiment of the present application, the first device 100 and / or the second device 200 can perform some or all of the steps in the embodiment of the present application, and these steps or operations are only examples. The embodiment of the present application can also perform other operations or variations of various operations. In addition, the various steps can be performed in different orders presented in the embodiment of the present application, and it is possible that not all operations in the embodiment of the present application need to be performed.

[0129] The following will be combined Figure 4-8BThe method for obtaining statistical information provided by the embodiment of the present application is specifically described. The method provided by the embodiment of the present application is described below by taking the first device as a coordination node and the second device as a data node as an example.

[0130] For example, Figure 4 A flowchart of a method for obtaining statistical information provided in an embodiment of the present application. Figure 4 The method shown is described by taking the acquisition of statistical information of a global secondary index in a distributed database as an example. The number of coordination nodes may be one or more, and the number of data nodes may be one or more.

[0131] S401, the coordinating node detects a statistical information collection instruction for a global secondary index.

[0132] Exemplarily, the coordinating node detects a statistical information collection statement (or instruction) of a global secondary index input by a user on a first interface of the coordinating node.

[0133] Optionally, the statistical information collection instruction of the global secondary index may be referred to as a first instruction, and the first instruction is used to instruct obtaining statistical information of a first global secondary index in a distributed database.

[0134] Combination Figure 3 (a) in which the parsing module 301a is used to parse the statistical information collection instruction of the global secondary index. The above S401 may include: the parsing module 301a of the coordination node parses the statistical information collection instruction of the global secondary index.

[0135] S402: The coordinating node sends a first message to the data node.

[0136] Exemplarily, the first message is used to instruct to obtain statistical information of the global secondary index.

[0137] S403: The data node obtains statistical information of the base table.

[0138] Exemplarily, a distributed database may include one or more base tables, one or more global secondary indexes may be established for a base table, and a data node may obtain statistical information of the one or more base tables.

[0139] Optionally, the data node specifically obtains the statistical information of which base table or tables and the statistical information of which global secondary index or indexes the coordination node wants to obtain. For example, if you want to obtain the statistical information of a certain global secondary index, the data node can only obtain the statistical information of the base table corresponding to the global secondary index in the distributed database (for the sake of ease of description, this example is used to illustrate in the embodiments of the present application). For another example, if you want to obtain the statistical information of all global secondary indexes corresponding to a certain base table, the data node can obtain the statistical information of the base table. For another example, if you want to obtain the statistical information of all global secondary indexes in the distributed database, the data node can obtain the statistical information of all base tables in the distributed database.

[0140] Exemplarily, the statistical information of the base table includes but is not limited to one or more of the following: the number of data records, the number of pages, MCV and histogram. The number of data records may be the number of data records (or the number of rows) included in the base table of the distributed database. The number of pages may be the number of pages (or the number of included pages) of the data included in the base table of the distributed database. The MCV is used to describe the data distribution characteristics of the base table in the distributed database. The histogram is used to describe the data distribution characteristics of the base table in the distributed database.

[0141] In some embodiments, the above S403 may include: the data node receives statistical information of the base table from the coordination node.

[0142] Exemplarily, the coordination node determines the statistical information of the base table and sends it to the data node. For example, the coordination node may determine a sampling rate of the statistical information of the base table, and determine the statistical information of the base table according to the sampling rate.

[0143] Combination Figure 1E Each data node that receives the first message executes S403 to obtain the number of data records in the base table.

[0144] Combination Figure 5A , Figure 5A Taking the hash distribution scenario with small data volume as an example, base table 1 is as follows Figure 5A As shown in (a) in FIG. 1 , the global secondary index 1 established for the base table 1 is as follows: Figure 5A As shown in (b), the data volume of base table 1 is 6 records (or rows), and the data volume of global secondary index 1 is 6 records.

[0145] like Figure 5A As shown in (a), base table 1 includes two columns, column a and column b. Column a is the distribution key of base table 1, and column b is the data of base table 1. Base table 1 may include multiple columns of data. Figure 5A (a) in the figure only shows one column of data as an example.

[0146] like Figure 5AAs shown in (b), column b is the distribution key and index key, column b is the distribution key of global secondary index 1, column Xc_ha is the hash value of column a in base table 1, and column Xc_ha can also be called column xc_node_hash. Column ctid identifies the location of column b data in base table 1, and column xmin and column xmax are used to record transaction information, for example, transaction information includes user operations on the database, such as insert, update, delete, etc. Figure 5A (b) in Figure 1 shows only one global secondary index of base table 1. Figure 5A When the base table 1 shown in (a) includes multiple columns of data, the base table 1 can correspond to multiple global secondary indexes. Figure 5A The global secondary index 1 shown in (b) is only an example. The global secondary index 1 may include more or fewer columns than shown in the figure, and this application is not limited to this.

[0147] According to the distribution key of base table 1 (distribution algorithm can also be used), the data of base table 1 is stored in data node 1 (DN1) and data node 2 (DN2). According to the distribution key of global secondary index 1 (distribution algorithm can also be used), the data of global secondary index 1 is stored in data node 1 (DN1) and data node 2 (DN2). For example, when the value of distribution key a of base table 1 is an odd number, the corresponding data is stored on DN1, and when the value of distribution key a of base table 1 is an even number, the corresponding data is stored on DN 2. When the value of distribution key b of global secondary index 1 is an odd number, the corresponding data is stored on DN1, and when the value of distribution key b of global secondary index 1 is an even number, the corresponding data is stored on DN 2. The distribution results are as follows: Figure 5B Shown are examples only.

[0148] Combination Figure 5A and Figure 5B , assuming that the coordinating node wants to obtain the statistical information of global secondary index 1, the number of data records sent to DN1 corresponding to base table 1 of global secondary index 1 is 6, and the number of data records sent to DN2 corresponding to base table 1 of global secondary index 1 is 6.

[0149] It should be noted that this application uses the number of data records included in the statistical information as an example to illustrate the method provided by this application. The number of pages, MCV and histogram included in the statistical information can be used to obtain the statistical information of the global secondary index in a similar manner to the number of data records, which is not elaborated one by one in this application.

[0150] Fig. 6A Taking the large data volume scenario of hash distribution as an example, Figure 5A Similarly, base table 2 is Fig. 6A As shown in (a) in FIG. 1 , the global secondary index 2 established for the base table 1 is as follows: Fig. 6AAs shown in (b), the data volume of base table 2 is 10 million records (or rows), and the data volume of global secondary index 2 is 10 million records. Fig. 6A The meanings of columns a, b, Xc_ha, ctid, xmin, and xmax can be found in Figure 5A The corresponding explanation in will not be repeated here.

[0151] The data volume of base table 2 and the data of global secondary index 2 are distributed in DN1 and DN2. The specific distribution method is not limited. The distribution results are as follows: Figure 6B As shown, the amount of data in the base table stored on DN1 is 5,009,882 rows, and the amount of data in the GSI stored on DN1 is 4,997,168 rows. The amount of data in the base table stored on DN2 is 4,990,118 rows, and the amount of data in the GSI stored on DN2 is 5,002,832 rows.

[0152] Combination Fig. 6A and Figure 6B , assuming that the coordinating node wants to obtain the statistical information of global secondary index 2, the number of data records sent to DN1 corresponding to base table 2 of global secondary index 2 is 10 million, and the number of data records sent to DN2 corresponding to base table 2 of global secondary index 2 is 10 million.

[0153] Fig. 7A Taking the small data volume scenario with range distribution as an example, Figure 5A Similarly, base table 3 is Fig. 7A As shown in (a) in FIG. 1 , the global secondary index 3 established for the base table 3 is as follows: Fig. 7A As shown in (b), the data volume of base table 3 is 6 entries (or rows), and the data volume of global secondary index 3 is 6 entries. Fig. 7A The meanings of columns a, b, ctid, xmin, and xmax can be found in Figure 5A The corresponding explanation in will not be repeated here. The Xc_ra column represents the range of the a column in the base table. The Xc_ra column can also be called the xc_node_range column.

[0154] According to the distribution key of base table 3 (distribution algorithm can also be used), the data of base table 3 is stored in data node 1DN1 and DN2, and according to the distribution key of global secondary index 3 (distribution algorithm can also be used), the data of global secondary index 3 is stored in DN1 and DN2. For example, when the distribution key a of base table 3 is less than or equal to 3, the corresponding data is stored in DN1, and when the distribution key a of base table 3 is greater than 3, the corresponding data is stored in DN2. When the distribution key b of global secondary index 3 is less than or equal to 3, the corresponding data is stored on DN1, and when the distribution key b of global secondary index 3 is greater than 3, the corresponding data is stored on DN 2. The distribution result is as follows: Figure 7BShown are examples only.

[0155] Combination Fig. 7A and Figure 7B When the coordinating node wants to obtain the statistical information of the global secondary index 3, the number of data records of the base table 3 corresponding to the global secondary index 3 sent to DN1 is 6, and the number of data records of the base table 3 corresponding to the global secondary index 3 sent to DN2 is 6.

[0156] Fig. 8A Taking the large amount of data distributed in a range as an example, Fig. 6A Similarly, base table 4 is Fig. 8A As shown in (a) in FIG. 4 , the global secondary index 4 established for the base table 4 is as follows: Fig. 8A As shown in (b), the data volume of base table 4 is 10 million records (or rows), and the data volume of global secondary index 4 is 10 million records. Fig. 8A The meanings of columns a, b, ctid, xmin, and xmax can be found in Figure 5A The corresponding explanation in will not be repeated here. The Xc_ra column represents the range of column a in the base table.

[0157] Distribute the data volume of base table 4 and the data of global secondary index 4 in DN1 and DN2. For example, store the corresponding data when the distribution key a of base table 4 is less than or equal to 5 million in DN1, and store the corresponding data when the distribution key a of base table 4 is greater than 5 million in DN2. Store the corresponding data when the distribution key a of global secondary index 4 is less than or equal to 4 million in DN1, and store the corresponding data when the distribution key a of global secondary index 4 is greater than 4 million in DN2. The distribution results are as follows: Figure 8B As shown in the figure, the amount of data in the base table stored on DN1 is 5 million rows, and the amount of data in the GSI stored on DN1 is 4 million rows. The amount of data in the base table stored on DN2 is 5 million rows, and the amount of data in the GSI stored on DN2 is 6 million rows.

[0158] Combination Fig. 8A and Figure 8B , assuming that the coordinating node wants to obtain the statistical information of global secondary index 4, the number of data records sent to DN1 corresponding to base table 4 of global secondary index 4 is 10 million, and the number of data records sent to DN2 corresponding to base table 4 of global secondary index 4 is 10 million.

[0159] S404: The data node determines a sampling rate according to statistical information of the base table.

[0160] Exemplarily, the sampling rate sample_rate (the sampling rate can also be represented by S) can satisfy the following relationship: sample_rate = min (default_sample_size / total_rows, 1). Wherein, default_sample_size represents the number of samples (such as a data node samples at most default_sample_size samples), the number of samples can also be represented by D, the number of samples can be preset or default, and can be adjusted manually. total_rows represents the number of data records in the base table (or the number of data included in the first base table), the number of data records in the base table can also be represented by T, and the mathematical symbol min represents the minimum value.

[0161] Optionally, the above S404, the data node determines the sampling rate according to the statistical information of the base table, may include: the data node determines the sampling rate according to the statistical information of the base table using a dynamic adaptive algorithm.

[0162] Combination Figure 5B DN1 determines the sampling rate according to the number of data records in base table 1, total_rows = 6. Assuming the number of samples, default_sample_size = 30000, the sampling rate is sample_rate = min(30000 / 6, 1) = 1. Similarly, DN2 determines the sampling rate, sample_rate = min(30000 / 6, 1) = 1.

[0163] Combination Figure 6B DN1 determines the sampling rate based on the number of data records in base table 2, which is 10 million rows (or records). Assuming the number of samples default_sample_size = 30,000, the sampling rate sample_rate = min(30,000 / 10 million, 1) = 0.003. Similarly, DN2 determines the sampling rate sample_rate = min(30,000 / 10 million, 1) = 0.003.

[0164] Combination Figure 7B ,and Figure 5B Similar to the example shown, DN1 determines the sampling rate according to the number of data records in base table 3, total_rows=6, and assuming that the number of samples, default_sample_size=30000, the sampling rate, sample_rate=min(30000 / 6,1)=1. Similarly, DN2 determines the sampling rate, sample_rate=min(30000 / 6,1)=1.

[0165] Combination Figure 8B ,and Figure 6BSimilar to the example shown, DN1 determines the sampling rate based on the number of data records in base table 4, which is 10 million rows (or entries). Assuming the number of samples default_sample_size = 30,000 entries, then the sampling rate sample_rate = min(30,000 / 10 million, 1) = 0.003. Similarly, DN2 determines the sampling rate sample_rate = min(30,000 / 10 million, 1) = 0.003.

[0166] In this way, the data node determines the sampling rate according to the statistical information of the base table, which can achieve dynamic adaptive adjustment of the sampling rate according to the statistical information of the base table. For example, automatically adjusting the sampling rate according to the size of the data volume in the base table can ensure the accuracy of obtaining the statistical information of the global secondary index.

[0167] S405, the data node samples the global secondary index using a query statement to obtain the estimated statistical information of the global secondary index.

[0168] Optionally, the query statement can be determined according to the sampling rate.

[0169] Optionally, the query statement is used to count the number of the first data in the global secondary index, and the random number corresponding to the first data is less than the sampling rate.

[0170] Exemplarily, the query statement can be select count(*) from (select * from idx_gsi where random() < sample_rate). Among them, select * from idx_gsi where random() < sample_rate can be called a subquery, and select count(*) from () can be called a parent query. idx_gsi represents the global secondary index, and select * from idx_gsi means obtaining all columns in the global secondary index. random() represents a random number, which is generated by the data node. The data node generates a random number every time it samples a row (entry) of data. The value of the random number is greater than 0 and less than 1, and the random number is not the data in the global secondary index. sample_rate represents the sampling rate, and where random() < sample_rate means filtering out the data corresponding to when the random number is less than the sampling rate. To sum up, select * from idx_gsi where random() < sample_rate means obtaining the data in the global secondary index idx_gsi corresponding to when the random number is less than the sampling rate, and select count(*) from () is used to count the number of data obtained in the subquery.

[0171] For example, the data node uses the query statement "select count(*) from (select * from idx_gsi where random() < sample_rate)" to sample the global secondary index and obtain the estimated number of data records in the global secondary index.

[0172] Optionally, the data node can record the statistical information of the estimated global secondary index on the data node.

[0173] For example, the data node records (such as adding, updating, or replacing) the estimated number of data records in the global secondary index on the data node. Optionally, before the data node records the estimated number of data records in the global secondary index, the data records of the global secondary index may or may not be stored in the data node.

[0174] Combined with Figure 5B , DN1 constructs the query statement "select count(*) from (select * from idx_gsi where random() < 1)" according to the sampling rate sample_rate = 1. DN1 uses this query statement to sample the global secondary index on DN1, and the intermediate result obtained is 2. Further, the number of data records in the global secondary index on DN1 is 2 / 1 = 2, that is, the estimated number of data records in the global secondary index obtained by DN1 is 2.

[0175] Similar to DN1, combined with Figure 5B , DN2 uses this query statement to sample the global secondary index on DN2, and the intermediate result obtained is 4. Further, the number of data records in the global secondary index on DN2 is 4 / 1 = 4, that is, the estimated number of data records in the global secondary index obtained by DN2 is 4.

[0176] Since the value of random() is between 0 and 1 and must be less than 1, the estimated number of data records in the global secondary index obtained by DN1 is the actual number of data records on DN1. Then the error of the number of data records in the global secondary index obtained by DN1 is 2 / 2 - 1 = 0%. Similar to DN1, the error of the number of data records in the global secondary index obtained by DN2 is 4 / 4 - 1 = 0%.

[0177] Combined with Figure 6BDN1 constructs the query statement select count(*)from(select*from idx_gsi where random()<0.003) based on the sampling rate sample_rate=0.003. DN1 uses this query statement to sample the global secondary index on DN1 and obtains an intermediate result of 14937. Furthermore, the number of data records in the global secondary index on DN1 is 14937 / 0.003=4979011, that is, the estimated number of data records in the global secondary index obtained by DN1 is 4979011. Similar to DN1, DN2 uses this query statement to sample the global secondary index on DN2 and obtains an intermediate result of 14953. Therefore, the number of data records in the global secondary index on DN2 is 14953 / 0.003=4984655, that is, the estimated number of data records in the global secondary index obtained by DN2 is 4984655.

[0178] like Figure 6B As shown, the actual number of data records in the global secondary index on DN1 is 4997168, so the error of the number of data records in the global secondary index obtained by DN1 is 4997168 / 4979011-1=0.4%. The actual number of data records in the global secondary index on DN2 is 5002832, so the error of the number of data records in the global secondary index obtained by DN2 is 5002832 / 4984655-1=0.4%.

[0179] Figure 7B In the scenario shown, the specific implementation method for DN1 and DN2 to obtain the number of data records in the global secondary index can be referred to above. Figure 5B The corresponding explanation in will not be repeated here.

[0180] Combination Figure 8BDN1 constructs the query statement select count(*)from(select*from idx_gsi where random()<0.003) based on the sampling rate sample_rate=0.003. DN1 uses this query statement to sample the global secondary index on DN1 and obtains an intermediate result of 11926. Furthermore, the number of data records in the global secondary index on DN1 is 11926 / 0.003=3975333, that is, the estimated number of data records in the global secondary index obtained by DN1 is 3975333. Similar to DN1, DN2 uses this query statement to sample the global secondary index on DN2 and obtains an intermediate result of 18035. Therefore, the number of data records in the global secondary index on DN2 is 18035 / 0.003=6011666, that is, the estimated number of data records in the global secondary index obtained by DN2 is 6011666.

[0181] like Figure 8B As shown, the actual number of data records in the global secondary index on DN1 is 4 million, so the error of the number of data records in the global secondary index obtained by DN1 is 4000000 / 3975333-1=0.6%. The actual number of data records in the global secondary index on DN2 is 5 million, so the error of the number of data records in the global secondary index obtained by DN2 is 6011666 / 6000000-1=0.1%.

[0182] In this way, the data node can realize random sampling of the global secondary index by constructing a query statement, and can quickly determine the statistical information of the global secondary index while ensuring accuracy, with short time consumption and good performance. When the amount of data reaches 10 million, the sampling method provided by this application can obtain the statistical information of the global secondary index in milliseconds.

[0183] FIG. 5A to FIG. 8A The method provided by the present application is described by taking the example of obtaining statistical information of a global secondary index. Similar operations can be used when obtaining statistical information of multiple global secondary indexes, and the present application will not repeat them. FIG. 5A to FIG. 8A The method provided in this application is explained by taking the example of obtaining the number of data records of the global secondary index. The number of pages, MCV and histogram of the global secondary index can all be obtained based on the sampling rate and query statement, which will not be repeated in this application.

[0184] S406: The data node sends the estimated statistical information of the global secondary index to the coordinating node.

[0185] Combination Figure 5B or Figure 7BDN1 sends an estimated number of 2 data records of the global secondary index to the coordinating node, and DN2 sends an estimated number of 4 data records of the global secondary index to the coordinating node.

[0186] Combination Figure 6B DN1 sends an estimated number of 4,979,011 data records of the global secondary index 2 to the coordinating node, and DN2 sends an estimated number of 4,984,655 data records of the global secondary index 2 to the coordinating node.

[0187] Combination Figure 8B DN1 sends an estimated number of 3,975,333 data records of the global secondary index 3 to the coordinating node, and DN2 sends an estimated number of 6,011,666 data records of the global secondary index 3 to the coordinating node.

[0188] S407: The coordination node determines statistical information of the total global secondary index based on statistical information of the N estimated global secondary indexes.

[0189] Exemplarily, the statistical information of the global secondary index includes, but is not limited to, one or more of the following: the number of data items included in the global secondary index, the number of pages included in the global secondary index, the MCV of the global secondary index, and the histogram of the global secondary index.

[0190] Exemplarily, taking the number of data records as an example, the coordinating node adds the estimated number of data records of the global secondary index from N data nodes to obtain the total number of data records of the global secondary index, and records (adds, updates, or replaces, etc.) the total number of data records of the global secondary index on the coordinating node, where N is an integer greater than or equal to 1.

[0191] Combination Figure 5B or Figure 7B , the total number of data records of the global secondary index obtained by the coordination node is 2+4=6, and the error is 0.

[0192] Combination Figure 6B , the total number of data records of the global secondary index obtained by the coordination node is 4979011+4984655=9963666, and the error is 10000000 / 9963666-1=0.4%.

[0193] Combination Figure 8B , the total number of data records of the global secondary index obtained by the coordination node is 3975333+6011666=9986999, and the error is 10000000 / 9986999-1=0.1%.

[0194] It can be seen that when the data volume reaches 10 million, the error of obtaining the statistical information of the global secondary index by sampling the method provided in this application can be within 1%, which can ensure the accuracy of the obtained statistical information of the global secondary index.

[0195] The above contents are only some descriptions of the method for obtaining statistical information provided by the embodiment of the present application. It should be noted that in each example or each optional method described above, any content can be freely combined, and the combined content is also within the scope of the present application.

[0196] In this application, unless otherwise specified, the same or similar parts between the various embodiments can refer to each other. In each embodiment of this application, and each implementation method / implementation method / implementation method in each embodiment, if there is no special description and logical conflict, the terms and / or descriptions between different embodiments and each implementation method / implementation method / implementation method in each embodiment are consistent and can be referenced to each other. The technical features in different embodiments and each implementation method / implementation method / implementation method in each embodiment can be combined to form new embodiments, implementation methods, implementation methods, or implementation methods according to their inherent logical relationships. In each example or each optional method described in the above embodiments, any content can be freely combined, and the combined content is also within the scope of this application. The above-described implementation methods of this application do not constitute a limitation on the scope of protection of this application.

[0197] Combination of the above Figure 1E-Figure 8B The method for obtaining statistical information provided by the embodiment of the present application is described in detail. Fig. 9 The first device and the second device provided in the embodiments of the present application are described in detail.

[0198] Fig. 9 A schematic diagram of a device provided in an embodiment of the present application. For example, the device may be a first device or a second device. Fig. 9 As shown, the device 900 may include: a transceiver unit 901 and a processing unit 902, and may also include a display unit 903 ( Fig. 9 not shown).

[0199] In one possible design, device 900 is a first device, and device 900 can be used to implement the functions of the coordination node involved in the above method embodiment.

[0200] Optionally, the transceiver unit 901 is used to support the coordination node to execute Figure 1E-Figure 8B Any of the sending and receiving functions.

[0201] Optionally, the processing unit 902 is used to support the coordination node to execute Figure 1E-Figure 8B Any processing function in .

[0202] Optionally, the display unit 903 is used to support the coordination node to execute Figure 1E-Figure 8B Any display function and / or touch function.

[0203] Among them, the transceiver unit 901 may include a receiving unit and a sending unit, and may be implemented by a transceiver or a transceiver-related circuit component, and may be a transceiver or a transceiver module. The operations and / or functions of each unit in the device 900 are respectively to implement the corresponding processes of the method described in the above method embodiment. All relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional unit, and for the sake of brevity, they will not be repeated here.

[0204] Optional, Fig. 9 The device 900 shown may also include a storage unit ( Fig. 9 (not shown), the storage unit stores a program or instruction. When the transceiver unit 901, the processing unit 902 and the display unit 903 execute the program or instruction, Fig. 9 The device 900 shown can execute the method described in the above method embodiments.

[0205] Fig. 9 The technical effects of the device 900 shown can refer to the technical effects of the methods described in the above method embodiments, which will not be repeated here.

[0206] In addition to being in the form of device 900, the technical solution provided by the present application may also be a functional unit or chip in a coordination node, or a device used in conjunction with the coordination node.

[0207] In another possible design, device 900 is a second device, and device 900 can be used to implement the functions of the data node involved in the above method embodiment.

[0208] Optionally, the transceiver unit 901 is used to support the data node to execute Figure 1E-Figure 8B Any of the sending and receiving functions.

[0209] Optionally, the processing unit 902 is used to support the data node to execute Figure 1E-Figure 8B Any processing function in .

[0210] Optionally, the display unit 903 is used to support the data node to execute Figure 1E-Figure 8B Any display function in .

[0211] Among them, the transceiver unit 901 may include a receiving unit and a sending unit, and may be implemented by a transceiver or a transceiver-related circuit component, and may be a transceiver or a transceiver module. The operations and / or functions of each unit in the device 900 are respectively to implement the corresponding processes of the method described in the above method embodiment. All relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional unit, and for the sake of brevity, they will not be repeated here.

[0212] Optional, Fig. 9 The device 900 shown may also include a storage unit ( Fig. 9 (not shown), the storage unit stores a program or instruction. When the transceiver unit 901, the processing unit 902 and the display unit 903 execute the program or instruction, Fig. 9 The device 900 shown can execute the method described in the above method embodiments.

[0213] Fig. 9 The technical effects of the device 900 shown can refer to the technical effects of the methods described in the above method embodiments, which will not be repeated here.

[0214] In addition to being in the form of device 900, the technical solution provided by the present application may also be a functional unit or chip in a data node, or a device used in conjunction with a data node.

[0215] An embodiment of the present application also provides a communication system, including: at least one first device and at least one second device.

[0216] Optionally, each device in the communication system provided in the embodiment of the present application may execute the method described in the above method embodiment. The technical effect of the communication system may refer to the technical effect of the method described in the above method embodiment, which will not be described in detail here.

[0217] An embodiment of the present application also provides a chip system, including: a processor, the processor is coupled to a memory, the memory is used to store programs or instructions, when the program or instructions are executed by the processor, the chip system implements the method in any of the above method embodiments.

[0218] Optionally, the processor in the chip system may be one or more. The processor may be implemented by hardware or by software. When implemented by hardware, the processor may be a logic circuit, an integrated circuit, etc. When implemented by software, the processor may be a general-purpose processor implemented by reading software code stored in a memory.

[0219] Optionally, the memory in the chip system may also be one or more. The memory may be integrated with the processor or may be separately arranged with the processor, which is not limited in the embodiments of the present application. Exemplarily, the memory may be a non-transient processor, such as a read-only memory ROM, which may be integrated with the processor on the same chip or may be arranged on different chips respectively. The embodiments of the present application do not specifically limit the type of memory and the arrangement of the memory and the processor.

[0220] Exemplarily, the chip system can be a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on chip (SoC), a central processor unit (CPU), a network processor (NP), a digital signal processor (DSP), a microcontroller unit (MCU), a programmable logic device (PLD) or other integrated chips.

[0221] It should be understood that each step in the above method embodiment can be completed by an integrated logic circuit of hardware in a processor or by instructions in the form of software. The method steps disclosed in the embodiments of the present application can be directly embodied as being executed by a hardware processor, or by a combination of hardware and software modules in a processor.

[0222] An embodiment of the present application also provides a readable storage medium, in which a program is stored. When the program is run on a computer or a device, the computer or the device executes the above-mentioned related steps to implement the method in the above-mentioned embodiment.

[0223] The embodiments of the present application also provide a program product. When the program product is run on a computer or a device, the computer or the device executes the above-mentioned related steps to implement the method in the above-mentioned embodiments.

[0224] In addition, an embodiment of the present application further provides a device. The device may be a component or a module, and the device may include one or more processors and a memory connected to each other. The memory is used to store a program. When the program is executed by one or more processors, the device executes the method in each of the above method embodiments.

[0225] Among them, the device, readable storage medium, program product or chip provided in the embodiments of the present application are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above, and will not be repeated here.

[0226] The steps of the method or algorithm described in conjunction with the disclosed content of the embodiments of the present application can be implemented in hardware or by a processor executing software instructions. The software instructions can be composed of corresponding software modules, and the software modules can be stored in random access memory (RAM), flash memory, read only memory (ROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), registers, hard disks, mobile hard disks, read-only compact disks (CD-ROMs) or any other form of storage medium known in the art. An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an application specific integrated circuit (ASIC).

[0227] Through the description of the above implementation methods, those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above functional modules is used as an example. In practical applications, the above functions can be assigned to different functional modules as needed; that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device and unit described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0228] In the several embodiments provided in the present application, it should be understood that the disclosed method can be implemented in other ways. The device embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division, and there may be other division methods in actual implementation; for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of modules or units, which can be electrical, mechanical or other forms.

[0229] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0230] The readable storage medium includes but is not limited to any of the following: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.

[0231] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any changes or substitutions within the technical scope disclosed in the present application should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A method for obtaining statistical information, characterized in that: Applied to data nodes, including: Receive a first message from a coordinating node; wherein the first message is used to instruct to obtain statistical information of a first global secondary index in a distributed database; Using a query statement to sample the first global secondary index in the data node to obtain statistical information of the first global secondary index; wherein the query statement is determined according to a sampling rate; Send statistical information of the first global secondary index to the coordinating node.

2. The method according to claim 1, characterized in that The query statement is used to count the number of first data in the first global secondary index, and the random number corresponding to the first data is less than the sampling rate.

3. The method according to claim 1 or 2, characterized in that: After receiving the first message from the coordination node, the method further includes: Receiving statistical information of a first base table from the coordination node; wherein the first global secondary index is one of at least one global secondary index established based on the first base table; The sampling rate is determined according to statistical information of the first base table.

4. The method according to claim 3, characterized in that The statistical information of the first base table includes one or more of the following: the number of data items included in the first base table, the number of pages included in the first base table, the most common value MCV of the first base table, and a histogram of the first base table.

5. The method according to claim 3 or 4, characterized in that: The statistical information of the first base table includes the number of data included in the first base table, and the sampling rate satisfies the following relationship: S=min(D / T,1); wherein S represents the sampling rate, the mathematical symbol min represents the minimum value, D represents the number of samples, and T represents the number of data included in the first base table.

6. The method according to any one of claims 1 to 5, characterized in that The statistical information of the first global secondary index includes one or more of the following: the number of data items included in the first global secondary index, the number of pages included in the first global secondary index, the MCV of the first global secondary index, and the histogram of the first global secondary index.

7. The method according to any one of claims 1 to 6, characterized in that The distributed database is deployed in at least N of the data nodes and at least one of the coordination nodes, where N is an integer greater than or equal to 1.

8. A method for obtaining statistical information, characterized in that: Applied to the coordination node, including: A first instruction is detected; wherein the first instruction is used to instruct to obtain statistical information of a first global secondary index in a distributed database; Sending a first message to each of the N data nodes; wherein N is an integer greater than or equal to 1, and the first message is used to instruct to obtain statistical information of the first global secondary index in the distributed database; Receive N statistics information of the first global secondary index; According to the N statistical information of the first global secondary index, total statistical information of the first global secondary index is determined.

9. The method according to claim 8, characterized in that After sending the first message to the data node, the method further includes: Sending statistical information of a first base table to the data node; wherein the first global secondary index is one of at least one global secondary index established based on the first base table.

10. The method according to claim 9, characterized in that The statistical information of the first base table includes one or more of the following: the number of data items included in the first base table, the number of pages included in the first base table, the most common value MCV of the first base table, and a histogram of the first base table.

11. The method according to any one of claims 8 to 10, characterized in that: The statistical information of the first global secondary index includes one or more of the following: the number of data items included in the first global secondary index, the number of pages included in the first global secondary index, the MCV of the first global secondary index, and the histogram of the first global secondary index.

12. The method according to any one of claims 8 to 11, characterized in that The distributed database is deployed in at least N data nodes and at least one coordination node.

13. A first electronic device, characterized in that: The first electronic device comprises: one or more processors; one or more memories; The memory stores one or more programs, and when the one or more programs are executed by the one or more processors, the first electronic device executes the method according to any one of claims 1 to 7.

14. A second electronic device, characterized in that: The second electronic device comprises: one or more processors; one or more memories; The memory stores one or more programs, and when the one or more programs are executed by the one or more processors, the second electronic device executes the method according to any one of claims 8 to 12.

15. A communication system, characterized in that: The communication system comprises: The first electronic device as claimed in claim 13; and The second electronic device as claimed in claim 14.

16. A readable storage medium, characterized in that: The readable storage medium includes a program, and when the program is executed on a device, the device is caused to execute the method according to any one of claims 1 to 12.