US 11,734,076 B2
Method and apparatus for traversing graph database based on allocation of threads to operators
Haiping Zhang, Beijing (CN); Yang Wang, Beijing (CN); Xi Chen, Beijing (CN); and Yifei Wang, Beijing (CN)
Assigned to BEIJING BAIDU NETCOM SCIENCE AND TECHNOLOGY CO., LTD., Beijing (CN)
Filed by BEIJING BAIDU NETCOM SCIENCE AND TECHNOLOGY CO., LTD., Beijing (CN)
Filed on Oct. 21, 2020, as Appl. No. 17/76,400.
Claims priority of application No. 202010043990.2 (CN), filed on Jan. 15, 2020.
Prior Publication US 2021/0216373 A1, Jul. 15, 2021
Int. Cl. G06F 9/50 (2006.01); G06F 9/38 (2018.01); G06F 9/54 (2006.01); G06F 16/2455 (2019.01); G06F 16/903 (2019.01); G06F 16/901 (2019.01); G06F 9/30 (2018.01); G06F 16/2453 (2019.01); G06F 9/48 (2006.01)
CPC G06F 9/5038 (2013.01) [G06F 9/3009 (2013.01); G06F 9/3851 (2013.01); G06F 9/4881 (2013.01); G06F 9/544 (2013.01); G06F 9/546 (2013.01); G06F 16/24537 (2019.01); G06F 16/24554 (2019.01); G06F 16/903 (2019.01); G06F 16/9024 (2019.01); G06F 16/90335 (2019.01); G06F 16/24561 (2019.01); G06F 16/24565 (2019.01)] 13 Claims
OG exemplary drawing
 
1. A method for traversing a graph database, comprising:
obtaining, by a computer device, a graph traversal statement;
determining, by the computer device, at least two operators contained in the graph traversal statement and an execution order of the at least two operators;
allocating, by the computer device, respective available threads of the computer device to the at least two operators based on the execution order of the at least two operators;
creating, by the computer device, a buffer queue of the computer device for each two adjacent operators;
for each two adjacent operators,
executing an operation of a former operator by a first available thread of the computer device corresponding to the former operator of the two adjacent operators, in response to receiving, by the first available thread, token data that is transmitted among the respective available threads;
writing, by the first available thread, an execution result of the former operator to the buffer queue and transmitting, by the first available thread, the token data to a second available thread of the computer device corresponding to a latter operator of the two adiacent operators; and
after receiving, by the second available thread, the token data, upon the execution result is available, executing an operation of the latter operator by reading, from the buffer queue, the execution result of the former operator by the second available thread;
wherein while executing, by the second available thread, the operation of the latter operator based on the execution result of the former operator, the operation of the former operator is executed by the first available thread and an additional execution result of the former operator is written by the first available thread to the buffer queue;
wherein the method further comprises:
in response to determining that a number of available threads is less than a number of operators, determining, by the first available thread that has received the token data, whether the second available thread is allocated to the latter operator;
in response to determining, by the first available thread that has received the token data, that the second available thread is not allocated to the latter operator and an allocated thread meets a preset condition, allocating the allocated thread to the latter operator, and transmitting the token data to the allocated thread to trigger the allocated thread to execute the operation of the latter operator;
wherein the preset condition is that the allocated thread has completed the operation of an operator corresponding to the allocated thread.