A method and apparatus for data query
Patent Information
- Application Number
- CN202410171855.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-06
- Publication Date
- 2026-09-15
- Estimated Expiration
- 2044-02-06
AI Technical Summary
[0004]广度优先搜索算法或者深度优先搜索算法的算法复杂度较高,导致数据查询耗时较长,数据查询效率较低
[0057]One embodiment of the above invention has the following advantages or beneficial effects: Based on the data level to which the data vertex belongs and the index relationship between data vertices, determining the target data vertex corresponding to the starting data vertex and obtaining the corresponding data from the target data vertex can improve the efficiency and accuracy of data querying and reduce the response time of data querying; when the starting data level and the target data level are not adjacent, querying from the starting data level to the target data level according to the hierarchical relationship and index relationship, and determining the corresponding target data vertex in the target data level can improve data query efficiency, ignore data vertices and data levels irrelevant to the data query request, and reduce data query steps; when there are multiple starting data vertices, determining the smallest starting data level closest to the target data level can further improve data query efficiency, reduce data query steps, and reduce the response time of data querying; when the same data query request is received multiple times, establishing a direct index relationship between data vertices can further improve data query efficiency, reduce the algorithm complexity of data querying, and save system resources.
Smart Images

Figure CN120448421B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a method and apparatus for data querying. Background Technology
[0002] As business grows and functions become more sophisticated, the amount of data used in business operations increases significantly, and the data relationships become increasingly complex. For example, during user participation in social games, various types of data are continuously generated, including: data on relationships between users, data on the association between users and game scenarios, user behavior data in the game, reward data obtained through user behavior, achievement data, and so on. These data are interconnected. Graphs are typically used to store the data generated in the business process, and breadth-first search or depth-first search algorithms are usually used to query the data.
[0003] In the process of realizing this invention, the inventors discovered that the prior art has at least the following problems:
[0004] Breadth-first search or depth-first search algorithms have high computational complexity, resulting in long data query times and low data query efficiency. Summary of the Invention
[0005] In view of this, embodiments of the present invention provide a method and apparatus for data querying, which can improve the efficiency of data querying and reduce the time consumed by data querying.
[0006] To achieve the above objectives, according to a first aspect of the present invention, a data query method is provided, comprising:
[0007] In response to receiving a data query request, the corresponding data query conditions are obtained, and the starting data vertex corresponding to the data query conditions is determined in a pre-set data relationship graph;
[0008] Determine the target data level corresponding to the data query conditions, and determine the target data vertex that has an index relationship with the starting data vertex in the target data level;
[0009] Based on the target data vertex, obtain the target data that meets the data query conditions.
[0010] Optionally, determining the target data vertex that has an index relationship with the starting data vertex in the target data hierarchy includes:
[0011] Determine whether the starting data level to which the starting data vertex belongs is adjacent to the target data level;
[0012] When the starting data level to which the starting data vertex belongs is adjacent to the target data level, the hierarchical relationship between the starting data level and the target data level is determined, and the corresponding index relationship is determined based on the hierarchical relationship.
[0013] From the target data level, determine the target data vertex that has the index relationship with the starting data vertex.
[0014] Optionally, determining the target data vertex that has the index relationship with the starting data vertex from the target data hierarchy includes:
[0015] Determine the edge indices that conform to the index relationship from the vertex indices of the starting data vertices;
[0016] Based on the edge index, the corresponding target data vertex is determined in the target data level.
[0017] Optionally, if the starting data level to which the starting data vertex belongs is not adjacent to the target data level, the method further includes:
[0018] Determine the hierarchical relationship between the starting data level and the target data level, and determine the corresponding index relationship based on the hierarchical relationship;
[0019] Repeat the following steps until the adjacent data level is the target data level: from the adjacent data levels that are adjacent to the starting data level and conform to the hierarchical relationship, determine the adjacent data vertex that has the index relationship with the starting data vertex; if the adjacent data level is not the target data level, take the adjacent data level as the new starting data level;
[0020] When the adjacent data level is the target data level, the data vertex determined in the target data level is taken as the target data vertex.
[0021] Optionally, there are multiple starting data vertices; before determining the target data vertex that has an index relationship with the starting data vertex in the target data level, the method further includes: determining whether the hierarchical relationship between the multiple starting data levels to which the multiple starting data vertices belong is the same as that of the target data level; if the hierarchical relationship between the multiple starting data levels and the target data level is the same, determining the nearest starting data level with the smallest distance to the target data level from the multiple starting data levels, and determining the nearest starting data vertex belonging to the nearest starting data level;
[0022] Determining a target data vertex that has an index relationship with the starting data vertex in the target data hierarchy includes: determining a target data vertex that has an index relationship with the nearest starting data vertex in the target data hierarchy.
[0023] Optionally, when the hierarchical relationship between multiple starting data levels and the target data level is different, the method further includes: classifying multiple starting data levels according to the hierarchical relationship to obtain multiple sets of starting data levels; determining the nearest starting data level with the smallest distance to the target data level in each set of starting data levels, and determining the nearest starting data vertex belonging to the nearest starting data level;
[0024] Determining the target data vertex that has an index relationship with the starting data vertex in the target data hierarchy includes: determining the target data vertex that has an index relationship with all the nearest starting data vertices in the target data hierarchy.
[0025] Optionally, the method further includes:
[0026] Generate a data query record between the starting data vertex and the target data vertex;
[0027] If the number of data query records is greater than or equal to a preset threshold, a direct index relationship is established between the starting data vertex and the target data vertex.
[0028] In response to receiving the data query request, the target data vertex corresponding to the starting data vertex is determined according to the direct index relationship, and the target data is obtained from the target data vertex.
[0029] According to a second aspect of the present invention, an apparatus for data querying is provided, comprising:
[0030] The first determining module is used to respond to receiving a data query request, obtain the corresponding data query conditions, and determine the starting data vertex corresponding to the data query conditions in a pre-set data relationship graph;
[0031] The second determining module is used to determine the target data level corresponding to the data query conditions, and to determine the target data vertex that has an index relationship with the starting data vertex in the target data level;
[0032] The acquisition module is used to acquire target data that meets the data query conditions based on the target data vertex.
[0033] Optionally, determining the target data vertex that has an index relationship with the starting data vertex in the target data hierarchy includes:
[0034] Determine whether the starting data level to which the starting data vertex belongs is adjacent to the target data level;
[0035] When the starting data level to which the starting data vertex belongs is adjacent to the target data level, the hierarchical relationship between the starting data level and the target data level is determined, and the corresponding index relationship is determined based on the hierarchical relationship.
[0036] From the target data level, determine the target data vertex that has the index relationship with the starting data vertex.
[0037] Optionally, determining the target data vertex that has the index relationship with the starting data vertex from the target data hierarchy includes:
[0038] Determine the edge indices that conform to the index relationship from the vertex indices of the starting data vertices;
[0039] Based on the edge index, the corresponding target data vertex is determined in the target data level.
[0040] Optionally, the device further includes:
[0041] The third determining module is used to determine the hierarchical relationship between the starting data level and the target data level, and to determine the corresponding index relationship based on the hierarchical relationship.
[0042] The repetition determination module is used to repeat the following steps until the adjacent data level is the target data level: from the adjacent data levels that are adjacent to the starting data level and conform to the hierarchical relationship, determine the adjacent data vertex that has the index relationship with the starting data vertex; if the adjacent data level is not the target data level, take the adjacent data level as the new starting data level;
[0043] The fourth determining module is used to, when the adjacent data level is the target data level, take the data vertex determined in the target data level as the target data vertex.
[0044] Optionally, there are multiple starting data vertices; the device further includes: a determination module, used to determine whether the hierarchical relationship between the multiple starting data vertices and the target data level is the same; a fifth determination module, used to determine the nearest starting data level with the smallest distance from the target data level from the multiple starting data levels when the hierarchical relationship between the multiple starting data levels and the target data level is the same, and to determine the nearest starting data vertex belonging to the nearest starting data level;
[0045] Determining a target data vertex that has an index relationship with the starting data vertex in the target data hierarchy includes: determining a target data vertex that has an index relationship with the nearest starting data vertex in the target data hierarchy.
[0046] Optionally, the apparatus further includes: a classification module, configured to classify multiple starting data levels according to hierarchical relationships to obtain multiple sets of starting data levels; and a sixth determination module, configured to determine the nearest starting data level with the smallest distance to the target data level in each set of starting data levels, and determine the nearest starting data vertex belonging to the nearest starting data level.
[0047] Determining the target data vertex that has an index relationship with the starting data vertex in the target data hierarchy includes: determining the target data vertex that has an index relationship with all the nearest starting data vertices in the target data hierarchy.
[0048] Optionally, the device further includes:
[0049] The recording module is used to generate data query records between the starting data vertex and the target data vertex;
[0050] The indexing module is used to establish a direct index relationship between the starting data vertex and the target data vertex when the number of data query records is greater than or equal to a preset threshold.
[0051] The direct acquisition module is used to respond to receiving the data query request, determine the target data vertex corresponding to the starting data vertex according to the direct index relationship, and acquire the target data from the target data vertex.
[0052] According to a third aspect of the present invention, an electronic device is provided, comprising:
[0053] One or more processors;
[0054] Storage device for storing one or more programs.
[0055] When the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any of the above embodiments.
[0056] According to a fourth aspect of the present invention, a computer-readable medium is provided having a computer program stored thereon, which, when executed by a processor, implements the methods described in any of the above embodiments.
[0057] One embodiment of the above invention has the following advantages or beneficial effects: Based on the data level to which the data vertex belongs and the index relationship between data vertices, determining the target data vertex corresponding to the starting data vertex and obtaining the corresponding data from the target data vertex can improve the efficiency and accuracy of data querying and reduce the response time of data querying; when the starting data level and the target data level are not adjacent, querying from the starting data level to the target data level according to the hierarchical relationship and index relationship, and determining the corresponding target data vertex in the target data level can improve data query efficiency, ignore data vertices and data levels irrelevant to the data query request, and reduce data query steps; when there are multiple starting data vertices, determining the smallest starting data level closest to the target data level can further improve data query efficiency, reduce data query steps, and reduce the response time of data querying; when the same data query request is received multiple times, establishing a direct index relationship between data vertices can further improve data query efficiency, reduce the algorithm complexity of data querying, and save system resources.
[0058] The further effects of the aforementioned unconventional alternative methods will be explained below in conjunction with specific implementation methods. Attached Figure Description
[0059] The accompanying drawings are provided to better understand the invention and are not intended to unduly limit the scope of the invention. Wherein:
[0060] Figure 1 This is a schematic diagram of the main flow of a data query method according to an embodiment of the present invention;
[0061] Figure 2 This is a schematic diagram of a data hierarchy according to a possible embodiment of the present invention;
[0062] Figure 3 This is a schematic diagram of a data relationship diagram according to a possible embodiment of the present invention;
[0063] Figure 4 This is a schematic diagram of an index page of data vertices according to a possible embodiment of the present invention;
[0064] Figure 5 This is a schematic diagram of the main flow of a data query method according to a possible embodiment of the present invention;
[0065] Figure 6 This is a schematic diagram of the main flow of a data query method according to another possible embodiment of the present invention;
[0066] Figure 7 This is a schematic diagram of the main modules of a data query device according to an embodiment of the present invention;
[0067] Figure 8 This is an exemplary system architecture diagram in which embodiments of the present invention can be applied;
[0068] Figure 9 This is a schematic diagram of the structure of a computer system suitable for implementing terminal devices or servers of the present invention. Detailed Implementation
[0069] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0070] It should be noted that the collection, use, storage, sharing and transfer of user personal information involved in the technical solution of the present invention all comply with the provisions of relevant laws and regulations, and require notification to users and obtaining their consent or authorization. When applicable, user personal information is subjected to de-identification and / or anonymization and / or encryption technical processing.
[0071] As business grows and functions become more sophisticated, the amount of data used in business operations increases significantly, and the data relationships become increasingly complex. For example, during user participation in social games, various types of data are continuously generated, including: data on relationships between users, data on the association between users and game scenarios, user behavior data in the game, reward data obtained through user behavior, achievement data, and so on. These data are interconnected. Graphs are typically used to store the data generated in the business process, and breadth-first search or depth-first search algorithms are usually used to query the data.
[0072] Breadth-first search or depth-first search algorithms have high computational complexity, resulting in long data query times and low data query efficiency.
[0073] In view of this, according to a first aspect of the present invention, a method for data querying is provided.
[0074] Figure 1 This is a schematic diagram illustrating the main flow of a data query method according to an embodiment of the present invention. Figure 1 As shown, the data query method according to an embodiment of the present invention mainly includes the following steps S101 to S103.
[0075] Step S101: In response to receiving a data query request, obtain the corresponding data query conditions, and determine the starting data vertex corresponding to the data query conditions in a pre-set data relationship graph.
[0076] In this embodiment of the invention, the executing entity uses a graph (a data structure) to store business data generated in the business logic, resulting in a data relationship graph. The data relationship graph includes data vertices and edges. Data vertices represent business data, such as scene data, user behavior data, behavior result data, etc. Different data vertices are connected by edges, which represent the relationships between business data. For example, if user A1 performs action C1 in scene B1, then there is an edge between the user data vertex corresponding to user A1 and the scene data vertex corresponding to scene B1, and an edge between the scene data vertex corresponding to scene B1 and the behavior data vertex corresponding to action C1. The data relationship graph is dynamically generated. In this embodiment of the invention, the executing entity dynamically adjusts the data relationship graph based on the addition, deletion, modification, and query of business data in the business logic, such as adding or deleting data vertices and adding or deleting edges between data vertices.
[0077] In this embodiment of the invention, the executing entity parses the received data query request and determines the corresponding data query conditions. These conditions include vertex information of the starting data vertex. The starting data vertex is the starting point for the data query. Based on the data relationship graph, the executing entity determines the corresponding target data vertex from the starting data vertex and its corresponding index relationship. The vertex information of the starting data vertex includes its vertex code, vertex type, etc. Each data vertex has a corresponding vertex code, and the vertex type is related to the data type of the business data. For example, vertex types include: user data vertex, scene data vertex, behavior data vertex, motivation data vertex, reward data vertex, performance data vertex, etc. Based on the vertex code and order type, the executing entity determines the corresponding data vertex in the data relationship graph and uses this determined data vertex as the starting data vertex. Then, the executing entity will query the data relationship graph from the starting data vertex to find the target data vertex that meets the data query conditions, thereby obtaining the target data to be queried.
[0078] For example, the execution entity of this embodiment parses the data query request to obtain "{'vertexId':'v123'; 'vertexType':'behaviour'}", where "'vertexId':'v123'" indicates that the vertex code of the data vertex is "v123", and "'vertexType':'behaviour'" indicates that the vertex type of the data vertex is a behavioral data vertex, that is, the data corresponding to the data vertex is user behavior data, such as behavioral data generated by actions such as clicking, browsing, querying, and checking in. Based on the vertex code "v123" and the vertex type "behavior data vertex", the execution entity of this embodiment determines the corresponding data vertex in the data relationship graph and uses the determined data vertex as the starting data vertex.
[0079] Determining the starting data vertex based on the data query request can quickly and accurately determine the starting position of the data query, which can improve data query efficiency, reduce the number of data vertices that need to be retrieved, reduce data query steps, and reduce algorithm complexity.
[0080] Step S102: Determine the target data level corresponding to the data query conditions, and determine the target data vertex that has an index relationship with the starting data vertex in the target data level.
[0081] In this embodiment of the invention, the executing entity obtains the corresponding target data level from the data query conditions. The target data level is the level information to which the target data vertex belongs. Specifically, each data vertex has corresponding level information, which indicates the data level to which the data vertex belongs. For example, data vertices are divided into different data levels according to their vertex types. Data levels include: user data level, scene data level, behavior data level, performance data level, reward data level, etc. The data vertices in each data level have the same data type. For example, the data query conditions include: the level code of the target data. The executing entity in this embodiment of the invention determines the corresponding target data level according to the level code. Another example is that the data query conditions include: the data type of the target data. The executing entity in this embodiment of the invention determines the target data level to which the data vertex corresponding to that data type belongs according to the data type of the target data.
[0082] After determining the target data level and the starting data vertex, the execution entity of this embodiment queries the index relationship of the starting data vertex. The index relationship represents the association between data vertices and includes out-degree index relationships and in-degree index relationships. Specifically, the edges used to represent the index relationship between data vertices are directional. When an edge points from other data vertices to the starting data vertex, the index relationship is the in-degree index relationship of the starting data vertex; when an edge points from the starting data vertex to other data vertices, the index relationship is the out-degree index relationship of the starting data vertex. The index relationship between data vertices at different data levels is the same. For example, in a data relationship graph, the user data level is above the scene data level, and the index relationship between user data vertices and scene data vertices always points from the user data vertex to the scene data vertex.
[0083] In this embodiment of the invention, the executing entity determines the starting data level to which the starting data vertex belongs, determines the index relationship (e.g., out-degree index relationship or in-degree index relationship) between the data vertices included in the starting data level and the data vertices included in the target data level according to the positional relationship between the starting data level and the target data level, and then determines the target data vertex in the target data level that has the index relationship with the starting data vertex according to the corresponding index relationship included in the starting data vertex.
[0084] Figure 2 This is a schematic diagram of a data hierarchy according to a possible embodiment of the present invention. Exemplarily, as shown... Figure 2 As shown, in a user's social entertainment scenario, the hierarchy includes: the user data level to which the user data vertex belongs, the scene data level to which the scene data vertex belongs, the behavior data level to which the behavior data vertex belongs, the reward data level to which the reward data vertex belongs, the performance data level to which the performance data vertex belongs, and the motivation data level to which the motivation data vertex belongs. User data includes: user code, user level, user's friends, etc. Scene data includes: planting trees, planting vegetables, raising pets, opening lucky bags, etc. Behavioral data includes: checking in, making up for missed check-ins, drawing prizes, planting trees, watering, buying feed, feeding, etc. Motivation data includes: achieving success, gaining satisfaction, avoiding risk, comparing, etc. Reward data includes: points, vouchers, feed, fertilizer, etc. Performance data includes: consecutive check-in days, total watering amount, total feeding amount, number of trees, number of pets, etc. Each data level includes a corresponding data vertex, and there is an index relationship between data levels (i.e.,...). Figure 2 The "data pointing" arrows in the table, for example, indicate that the edge between the user data level and the scene data level is from the former to the latter. Other index relationships follow the same pattern.
[0085] For another example, the user data level is above the scene data level; therefore, user data vertices always point to scene data vertices. The data query request is parsed to determine that the starting data vertex is a user data vertex, and the target data level is encoded as "scene," indicating the scene data level of the target data level. The target data vertex is a scene data vertex within the scene data level. Since the user data vertex points to the scene data vertex, the index relationship between the scene data vertex (i.e., the target data vertex) and the user data vertex is an out-degree index relationship. The query retrieves the first data vertex that has an out-degree index relationship with the starting data vertex. Within the first data vertex, the query retrieves the second data vertex whose data level is the scene data level, and uses the second data vertex as the target data vertex.
[0086] Identifying target data vertices that have an index relationship with the starting data vertex in the target data level can improve data query efficiency. Only data vertices with an index relationship with the starting data vertex need to be considered, which reduces the algorithm complexity of data query, reduces the number of data query steps, saves system resources, and eliminates the need to search all data vertices.
[0087] According to a possible embodiment of the present invention, different data levels are arranged in a certain order, such that each data vertex in a data level has an out-degree index relationship with a data vertex in an adjacent data level and an in-degree index relationship with a data vertex in another adjacent data level. After arranging the data levels, it is determined whether the starting data level to which the starting data vertex belongs is adjacent to the target data level. For example, pre-set data level configuration information is queried to determine whether the data level adjacent to the starting data level includes the target data level. If the data level adjacent to the starting data level includes the target data level, it is said that the starting data level to which the starting data vertex belongs is adjacent to the target data level. When the starting data level to which the starting data vertex belongs is adjacent to the target data level, when determining the target data vertex in the target data level that has an index relationship with the starting data vertex, the hierarchical relationship between the starting data level and the target data level is determined first. Specifically, the hierarchical relationship represents the order or positional relationship between data levels. Hierarchical relationships include: data level D2 is the next level below data level D1, data level D2 is the upper level above data level D3, and so on.
[0088] The corresponding index relationship is determined based on the hierarchical relationship. Specifically, when the starting data level is above the target data level, and the edges between data vertices in different data levels point from the upper level to the lower level; or when the starting data level is below the target data level, and the edges between data vertices in different data levels point from the lower level to the upper level, the index relationship between the data vertices included in the target data level and the starting data vertex is an out-degree index relationship, meaning that the starting data vertex always points to the data vertices included in the target data level. When the starting data level is below the target data level, and the edges between data vertices in different data levels point from the upper level to the lower level; or when the starting data level is above the target data level, and the edges between data vertices in different data levels point from the lower level to the upper level, the index relationship between the data vertices included in the target data level and the starting data vertex is an in-degree index relationship, meaning that the data vertices included in the target data level always point to the starting data vertex.
[0089] When the index relationship is an out-degree index relationship, the target data vertex that has an out-degree index relationship with the starting data vertex is determined from the target data level; that is, the data vertex in the target data level that is pointed to by the starting data vertex is taken as the target data vertex. When the index relationship is an in-degree index relationship, the target data vertex that has an in-degree index relationship with the starting data vertex is determined from the target data level; that is, the data vertex in the target data level that points to the starting data vertex is taken as the target data vertex.
[0090] Figure 3 This is a schematic diagram of a data relationship diagram according to a possible embodiment of the present invention. For example, as shown... Figure 3As shown, the data relationship graph includes multiple data vertices. Circular data vertices represent user data vertices belonging to the user data level; rectangular data vertices represent scene data vertices belonging to the scene data level; triangular data vertices represent motivation data vertices belonging to the motivation data level; pentagonal data vertices represent behavior data vertices belonging to the behavior data level; rhombus data vertices represent performance data vertices belonging to the performance data level; and rounded-corner rectangular data vertices represent reward data vertices belonging to the reward data level. The edges (solid arrows) between data vertices represent the index relationships between them. For example, if user 1 executes scene 1, it indicates an index relationship between user 1 and scene 1. For scene 1, this index relationship is an in-degree index relationship; for user 1, it is an out-degree index relationship, and so on for other index relationships. For example, if the starting data vertex is data vertex Motivation 1 and the target data level is the behavior data level, then the target data vertex must be a behavior data vertex. The data level to which data vertex Motivation 1 belongs is the Motivation data level. The Motivation data level is adjacent to the Behavior data level and is above the Behavior data level. Data vertices belonging to the Motivation data level always point to data vertices belonging to the Behavior data level. Therefore, for data vertex Motivation 1 (i.e., the starting data vertex), the corresponding index relationship is the out-degree index relationship. Querying the behavior data vertex that has an out-degree index relationship with data vertex Motivation 1 yields data vertex Behavior 1, which is then used as the target data vertex.
[0091] When the starting data level and the target data level are adjacent, the target data vertex with an index relationship with the starting data vertex can be directly determined from the target data level based on the hierarchical relationship and index relationship. This can improve data query efficiency, ignore data vertices and data levels that are irrelevant to the data query request, and reduce data query steps.
[0092] According to another possible embodiment of the present invention, when determining the target data vertex that has an index relationship with the starting data vertex from the target data level, the edge indices that conform to the index relationship are first determined from the vertex indices of the starting data vertex. Specifically, each data vertex has a corresponding vertex index, which includes: vertex code, level code of the data level where the data vertex is located, vertex type, edge index set corresponding to the out-degree index relationship, edge index set corresponding to the in-degree index relationship, number of edges connected to the data vertex, etc. The edge index set is a collection of edge indices, and each edge connected to the data vertex corresponds to one edge index. After determining the index relationship, if the index relationship is an out-degree index relationship, the edge index set corresponding to the out-degree index relationship of the starting data vertex is obtained, and the edges corresponding to this edge index set are all from the starting data vertex to other data vertices; if the index relationship is an in-degree index relationship, the edge index set corresponding to the in-degree index relationship of the starting data vertex is obtained, and the edges corresponding to this edge index set are all from other data vertices to the starting data vertex.
[0093] The edge index includes: the index relationship between data vertices connected by the edge, the vertex code of the data vertices connected by the edge, the level code of the data level to which the data vertices connected by the edge belong, etc. After obtaining the edge index set, the corresponding target data vertex in the target data level is determined according to the vertex code included in each edge index in the edge index set.
[0094] Figure 4 This is a schematic diagram of an index page of data vertices according to a possible embodiment of the present invention. Exemplarily, as shown... Figure 4 As shown, each data vertex corresponds to a vertex index. The vertex index includes: vertex code, vertex type, level code, the set of edge indices corresponding to the out-degree index relationship, the set of edge indices corresponding to the in-degree index relationship, and the number of edges. The out-degree index relationship is associated with multiple edge indices. Figure 4 In the context of vertex indexes, the edge index set corresponding to the out-degree index relationship includes multiple edge indices such as "out-1", where "out" indicates that the index type of the edge index is an out-degree index relationship, and "1" indicates the corresponding edge index number. The edge index set corresponding to the in-degree index relationship of vertex indexes includes multiple edge indices such as "in-1", where "in" indicates that the index type of the edge index is an in-degree index relationship, and "1" indicates the corresponding edge index number. The edge index includes data such as the index relationship, the vertex code of the data vertices connected by the edge, and the level code of the data vertices connected by the edge.
[0095] By determining the corresponding target data vertex based on the vertex index and edge index of the data vertex, and aggregating the data in the vertex index and edge index, the data query efficiency can be improved, the storage space occupied by business data can be reduced, and system resources can be saved.
[0096] According to another possible embodiment of the present invention, when the starting data level to which the starting data vertex belongs is not adjacent to the target data level, when determining the target data vertex in the target data level that has an index relationship with the starting data vertex, the hierarchical relationship between the starting data level and the target data level is first determined, and the corresponding index relationship is determined according to the hierarchical relationship. Then, from the adjacent data levels adjacent to the starting data level and conforming to the hierarchical relationship, adjacent data vertices with an index relationship with the starting data vertex are determined, and it is determined whether the adjacent data level is the target data level. If the adjacent data level is not the target data level, the adjacent data level is taken as the new starting data level, and the corresponding adjacent data vertices are determined again from the adjacent data levels adjacent to the new starting data level according to the hierarchical relationship and the index relationship. This process of determining new adjacent data levels is repeated until the adjacent data level is the target data level. If the adjacent data level is the target data level, the data vertex determined in the adjacent data level is taken as the target data vertex, that is, the data vertex determined in the target data level is taken as the target data vertex.
[0097] For example, such as Figure 3 As shown, when the starting data vertex is user 3 and the target data level is the motivation data level, it means that the target data vertex must be the motivation data vertex. The data level to which user 3 belongs is the user data level. The user data level and the motivation data level are not adjacent. The user data level is the upper level of the motivation data level. Therefore, for user 3 (i.e., the starting data vertex), the corresponding index relationship is the out-degree index relationship. Querying the data vertices with an out-degree index relationship with user 3, we get data vertex scenario 2. The data level to which scenario 2 belongs is the scenario data level, not the motivation data level. Therefore, querying the data vertices with an out-degree index relationship with scenario 2, we get data vertices motivation 2, motivation 3, and motivation 4. The data level to which the above data vertices belong is the motivation data level. Therefore, we take data vertices motivation 2, motivation 3, and motivation 4 as the target data vertices.
[0098] When the starting data level and the target data level are not adjacent, the query can be performed from the starting data level to the target data level based on the hierarchical relationship and index relationship. This can determine the corresponding target data vertex in the target data level, improve data query efficiency, ignore data vertices and data levels that are irrelevant to the data query request, and reduce data query steps.
[0099] According to another possible embodiment of the present invention, a data query request is parsed, and the obtained data query conditions may include one or more sets of vertex information. A starting data vertex is determined based on one set of vertex information, and multiple starting data vertices are determined based on multiple sets of vertex information. When there are multiple starting data vertices, before determining the target data vertex in the target data level that has an index relationship with the starting data vertex, the method further includes: determining whether the hierarchical relationship between the multiple starting data levels to which the multiple starting data vertices belong is the same as that of the target data level. For example, determining whether the relative positions of the multiple starting data levels and the target data level are the same. If the multiple starting data levels are all located above or below the target data level, it indicates that the hierarchical relationship between the multiple starting data levels and the target data level is the same. If some starting data levels are located above the target data level and some starting data levels are located below the target data level, it indicates that the hierarchical relationship between the multiple starting data levels and the target data level is different.
[0100] When multiple starting data levels have the same hierarchical relationship with the target data level, the nearest starting data level with the smallest distance to the target data level is determined from these multiple starting data levels. Then, the nearest starting data vertex belonging to this nearest starting data level is determined. After determining the nearest starting data vertex, the target data vertices with an index relationship to the nearest starting data vertex are determined within the target data level.
[0101] For example, such as Figure 3 As shown, with the initial data vertices being data vertex Scene 1 and data vertex Motivation 2, and the target data level being the behavior data level, data vertex Scene 1 belongs to the scene data level, and data vertex Motivation 2 belongs to the motivation data level. Both the scene data level and the motivation data level are above the behavior data level. Therefore, these two data levels have the same hierarchical relationship with the target data level. Since the motivation data level is closer to the behavior data level, the motivation data level is taken as the nearest starting data level, and data vertex Motivation 2 is taken as the nearest starting data vertex. Based on the out-degree index relationship of the nearest starting data vertex, the corresponding target data vertices are determined to be data vertex Behavior 1 and data vertex Behavior 2.
[0102] When there are multiple starting data vertices, determining the smallest starting data level that is closest to the target data level can further narrow the data query range, improve data query efficiency, reduce data query steps, and lower the data query response time.
[0103] According to another possible embodiment of the present invention, when the hierarchical relationship between multiple starting data levels and target data levels is different, the method further includes: classifying the multiple starting data levels according to the hierarchical relationship to obtain multiple sets of starting data levels. Each set of starting data levels includes one or more starting data levels, and the hierarchical relationship between the starting data levels in each set and the target data level is the same.
[0104] In each starting data level set, determine the nearest starting data level that has the smallest distance to the target data level, and then determine the nearest starting data vertex belonging to that nearest starting data level. After determining the nearest starting data vertex in each starting data level set, determine the target data vertex in the target data level that has an index relationship with all the nearest starting data vertices.
[0105] For example, such as Figure 3 As shown, with the initial data vertices being user 2 and motivation 3, and the target data level being the scene data level, user 2 belongs to the user data level, and motivation 3 belongs to the motivation data level. The user data level is above the scene data level, and the motivation data level is below the scene data level. Therefore, the hierarchical relationship between these two data levels and the target data level is different. Therefore, the user data level and the motivation data level are respectively taken as the nearest starting data levels, and user 2 and motivation 3 are respectively taken as the nearest starting data vertices. Based on the out-degree index relationship of user 2, the corresponding data vertices are determined to be scene 1 and scene 2. Based on the in-degree index relationship of motivation 3, the corresponding data vertex is determined to be scene 2. Taking the intersection of the above two results, the target data vertex is scene 2.
[0106] Preferably, the multiple starting data vertices determined according to the data query request are all part of the data query conditions. The target data vertex to be queried is a data vertex that has an index relationship with all the starting data vertices. Therefore, it should also be ensured that there is an index relationship between the multiple starting data vertices. Specifically, before determining whether the hierarchical relationship between the multiple starting data levels to which the multiple starting data vertices belong is the same as that of the target data level, it is first determined whether the multiple starting data vertices have an index relationship. If there is an index relationship between the multiple starting data vertices, it means that the data query conditions are true, and the subsequent steps can be executed to query the target data node. If there is no index relationship between the multiple starting data vertices, it means that the data query conditions are false, and it is inferred that the corresponding target data node will definitely not be found. Therefore, there is no need to execute the subsequent steps, and the data query result that no target data matching the data query conditions was found is directly given.
[0107] When there are multiple starting data vertices, determining the smallest starting data level that is closest to the target data level can further narrow the data query range, improve data query efficiency, reduce data query steps, and lower the data query response time.
[0108] Step S103: Obtain target data that meets the data query conditions based on the target data vertex.
[0109] After determining the target data vertex, the vertex index of the target data vertex is obtained. The vertex index includes a data field pointer, which represents the storage address of the target data corresponding to the target data vertex. The execution entity of this embodiment retrieves the corresponding data within the storage address indicated by the data field pointer and uses the retrieved data as the target data that meets the data query conditions. For example, if the data field pointer of the target data vertex is "loc001", it means that the target data is stored in the storage address encoded as "loc001". The execution entity of this embodiment uses the data stored in the storage address encoded as "loc001" as the target data and returns the target data to the initiator of the data query request.
[0110] By determining the storage address of the target data based on the data field pointer of the vertex index, and retrieving the corresponding target data from the storage address, the query efficiency of the target data can be improved, the storage space occupied by the data vertices can be reduced, and system resources can be saved.
[0111] According to a possible embodiment of the present invention, the method further includes: generating a data query record between the starting data vertex and the target data vertex, storing the data query record in a database or cache, or storing the data query record in a data query log.
[0112] If the number of data query records for the starting data vertex and the target data vertex is greater than or equal to a pre-set threshold, it indicates that data query requests for querying the target data vertex based on the starting data vertex are frequently received. The frequency and probability of querying the target data vertex based on the starting data vertex are high. Therefore, a direct index relationship is established between the starting data vertex and the target data vertex. The direct index relationship is used to query one data vertex based on another, without needing to consider the data level to which the data vertex belongs. In previous embodiments of this invention, querying the target data vertex required relying on the target data level, querying from the starting data level to the target data level according to the hierarchical relationship, and then querying the target data vertex within the target data level.
[0113] After establishing the direct index relationship, the execution entity of this embodiment parses the received data query request to obtain the data query conditions. Based on the data query conditions, it determines the starting data vertex and then queries whether a direct index relationship exists that matches the data query conditions and corresponds to the starting data vertex. If a corresponding direct index relationship exists, it directly determines the target data vertex corresponding to the starting data vertex based on the direct index relationship and then obtains the target data from the target data vertex. There is no need to determine the target data level level step by step and query the target data vertices level by level.
[0114] For example, such as Figure 3 As shown, User 3 frequently receives Reward 3, and User 3 frequently queries the specific information of the Reward 3 they received. Therefore, the execution entity of this embodiment receives multiple data query requests with User 3 as the starting data vertex and the Reward data level as the target data level. After the number of the above data query requests is greater than or equal to 10, the execution entity of this embodiment establishes a direct index relationship between User 3 and Reward 3, that is... Figure 3 The dashed arrows in the diagram; after establishing the direct index relationship, if the execution entity of this embodiment receives the above-mentioned data query request again, it first queries the corresponding direct index relationship. If the direct index relationship is found, it directly determines the target data vertex as data vertex reward 3 based on the direct index relationship, and then obtains the reward data pointed to by the data field pointer in data vertex reward 3.
[0115] When the same data query request is received multiple times, establishing a direct index relationship between data vertices can further improve data query efficiency, reduce the algorithm complexity of data query, and save system resources.
[0116] Figure 5 This is a schematic diagram illustrating the main flow of a data query method according to a possible embodiment of the present invention. Figure 5 As shown, the data query method may include:
[0117] Step S501: In response to receiving a data query request, obtain the corresponding data query conditions and determine the starting data vertex corresponding to the data query conditions in the pre-set data relationship graph;
[0118] Step S502: Determine the target data level corresponding to the data query conditions, and determine the starting data level to which the starting data vertex belongs;
[0119] Step S503: Determine whether the starting data level and the target data level are adjacent. If yes, proceed to step S504; otherwise, proceed to step S506.
[0120] Step S504: Determine the hierarchical relationship between the starting data level and the target data level, and determine the corresponding index relationship based on the hierarchical relationship;
[0121] Step S505: Determine the target data vertices that have an index relationship with the starting data vertices from the target data hierarchy;
[0122] Step S506: Determine the hierarchical relationship between the starting data level and the target data level, and determine the corresponding index relationship based on the hierarchical relationship;
[0123] Step S507, repeat the following steps until the adjacent data level is the target data level: from the adjacent data levels that are adjacent to the starting data level and conform to the hierarchical relationship, determine the adjacent data vertices that have an index relationship with the starting data vertex;
[0124] Step S508: When the adjacent data level is the target data level, the data vertex determined in the target data level will be used as the target data vertex.
[0125] Step S509: Obtain target data that meets the data query conditions based on the target data vertex.
[0126] The specific implementation details of the data query method of the present invention described above have been explained in detail in the data query method described above, so the details will not be repeated here.
[0127] Figure 6 This is a schematic diagram of the main flow of a data query method according to another applicable embodiment of the present invention. Figure 6 As shown, the data query method may include:
[0128] Step S601: In response to receiving a data query request, obtain the corresponding data query conditions, and determine multiple starting data vertices corresponding to the data query conditions in a pre-set data relationship graph;
[0129] Step S602: Determine the multiple starting data levels to which the multiple starting data vertices belong, and determine the target data level corresponding to the data query conditions;
[0130] Step S603: Determine whether multiple starting data levels are the same as the target data level. If so, proceed to step S604; otherwise, proceed to step S606.
[0131] Step S604: Determine the nearest starting data level with the smallest distance to the target data level from multiple starting data levels, and determine the nearest starting data vertex belonging to the nearest starting data level;
[0132] Step S605: In the target data level, determine the target data vertex that has an index relationship with the nearest starting data vertex;
[0133] Step S606: Classify multiple initial data levels according to the hierarchical relationship to obtain multiple initial data level sets;
[0134] Step S607: In each set of starting data levels, determine the nearest starting data level that is closest to the target data level, and determine the nearest starting data vertex that belongs to the nearest starting data level.
[0135] Step S608: In the target data level, determine the target data vertex that has an index relationship with all the nearest starting data vertices;
[0136] Step S609: Obtain target data that meets the data query conditions based on the target data vertices;
[0137] Step S610: Generate a data query record between the starting data vertex and the target data vertex;
[0138] Step S611: Determine whether the number of data query records is greater than or equal to the number threshold. If yes, proceed to step S612; otherwise, proceed to step S601.
[0139] Step S612: Establish a direct index relationship between the starting data vertex and the target data vertex;
[0140] Step S613: In response to receiving the above data query request, determine the target data vertex corresponding to the starting data vertex according to the direct index relationship, and obtain the target data from the target data vertex.
[0141] The specific implementation details of the data query method of another applicable embodiment of the present invention have been described in detail in the data query method described above, so the details will not be repeated here.
[0142] According to a second aspect of the present invention, an apparatus for data querying is provided.
[0143] Figure 7 This is a schematic diagram of the main modules of a data query apparatus according to an embodiment of the present invention, such as... Figure 7 As shown, the data query device 700 mainly includes:
[0144] The first determining module 701 is used to respond to receiving a data query request, obtain the corresponding data query conditions, and determine the starting data vertex corresponding to the data query conditions in a pre-set data relationship graph;
[0145] The second determining module 702 is used to determine the target data level corresponding to the data query conditions, and to determine the target data vertex that has an index relationship with the starting data vertex in the target data level.
[0146] The acquisition module 703 is used to acquire target data that meets the data query conditions based on the target data vertex.
[0147] According to a possible embodiment of the present invention, determining a target data vertex that has an index relationship with the starting data vertex in the target data level includes:
[0148] Determine whether the starting data level to which the starting data vertex belongs is adjacent to the target data level;
[0149] When the starting data level to which the starting data vertex belongs is adjacent to the target data level, the hierarchical relationship between the starting data level and the target data level is determined, and the corresponding index relationship is determined based on the hierarchical relationship.
[0150] From the target data level, determine the target data vertex that has the index relationship with the starting data vertex.
[0151] According to another possible embodiment of the present invention, determining the target data vertex that has the index relationship with the starting data vertex from the target data level includes:
[0152] Determine the edge indices that conform to the index relationship from the vertex indices of the starting data vertices;
[0153] Based on the edge index, the corresponding target data vertex is determined in the target data level.
[0154] According to yet another possible embodiment of the present invention, the apparatus further includes:
[0155] The third determining module is used to determine the hierarchical relationship between the starting data level and the target data level, and to determine the corresponding index relationship based on the hierarchical relationship.
[0156] The repetition determination module is used to repeat the following steps until the adjacent data level is the target data level: from the adjacent data levels that are adjacent to the starting data level and conform to the hierarchical relationship, determine the adjacent data vertex that has the index relationship with the starting data vertex; if the adjacent data level is not the target data level, take the adjacent data level as the new starting data level;
[0157] The fourth determining module is used to, when the adjacent data level is the target data level, take the data vertex determined in the target data level as the target data vertex.
[0158] According to another possible embodiment of the present invention, there are multiple starting data vertices; the data query device 700 further includes: a determination module, used to determine whether the hierarchical relationship between the multiple starting data vertices and the target data level is the same; a fifth determination module, used to determine the nearest starting data level with the smallest distance from the target data level from the multiple starting data levels when the hierarchical relationship between the multiple starting data levels and the target data level is the same, and to determine the nearest starting data vertex belonging to the nearest starting data level;
[0159] Determining a target data vertex that has an index relationship with the starting data vertex in the target data hierarchy includes: determining a target data vertex that has an index relationship with the nearest starting data vertex in the target data hierarchy.
[0160] According to another possible embodiment of the present invention, the data query device 700 further includes: a classification module, configured to classify multiple starting data levels according to hierarchical relationships to obtain multiple sets of starting data levels; and a sixth determination module, configured to determine the nearest starting data level with the smallest distance to the target data level in each set of starting data levels, and determine the nearest starting data vertex belonging to the nearest starting data level.
[0161] Determining the target data vertex that has an index relationship with the starting data vertex in the target data hierarchy includes: determining the target data vertex that has an index relationship with all the nearest starting data vertices in the target data hierarchy.
[0162] According to a possible embodiment of the present invention, the data querying device 700 further includes:
[0163] The recording module is used to generate data query records between the starting data vertex and the target data vertex;
[0164] The indexing module is used to establish a direct index relationship between the starting data vertex and the target data vertex when the number of data query records is greater than or equal to a preset threshold.
[0165] The direct acquisition module is used to respond to receiving the data query request, determine the target data vertex corresponding to the starting data vertex according to the direct index relationship, and acquire the target data from the target data vertex.
[0166] It should be noted that the specific implementation details of the data query device described in the embodiments of the present invention have been described in detail in the data query method described above, so the details will not be repeated here.
[0167] According to the technical solution of the present invention, based on the data level to which the data vertex belongs and the index relationship between data vertices, the target data vertex corresponding to the starting data vertex is determined, and the corresponding data is obtained from the target data vertex. This can improve the efficiency and accuracy of data query and reduce the response time of data query. When the starting data level and the target data level are not adjacent, the target data level is queried from the starting data level to the target data level according to the hierarchical relationship and the index relationship. The target data vertex corresponding to the target data level is determined, which can improve the efficiency of data query and ignore data vertices and data levels that are irrelevant to the data query request, thus reducing the number of data query steps. When there are multiple starting data vertices, the smallest starting data level that is closest to the target data level is determined, which can further improve the efficiency of data query, reduce the number of data query steps, and reduce the response time of data query. When the same data query request is received multiple times, a direct index relationship between data vertices is established, which can further improve the efficiency of data query, reduce the algorithm complexity of data query, and save system resources.
[0168] According to a third aspect of the present invention, an electronic device is provided, comprising: one or more processors; and a storage device for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors implement the method provided in the first aspect of the present invention.
[0169] According to a fourth aspect of the present invention, a computer-readable medium is provided having a computer program stored thereon, which, when executed by a processor, implements the method provided in the first aspect of the present invention.
[0170] Figure 8 An exemplary system architecture 800 is shown, in which the data query method or data query apparatus of embodiments of the present invention can be applied.
[0171] like Figure 8 As shown, system architecture 800 may include terminal devices 801, 802, and 803, a network 804, and a server 805. Network 804 serves as the medium for providing communication links between terminal devices 801, 802, and 803 and server 805. Network 804 may include various connection types, such as wired or wireless communication links or fiber optic cables, etc.
[0172] Users can use terminal devices 801, 802, and 803 to interact with server 805 via network 804 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 801, 802, and 803, such as data query applications, search applications, instant messaging tools, email clients, social media platform software, etc. (for example only).
[0173] Terminal devices 801, 802, and 803 can be various electronic devices with displays and web browsing capabilities, including but not limited to smartphones, tablets, laptops, and desktop computers.
[0174] Server 805 can be a server providing various services, such as a backend management server supporting data query requests sent from upstream terminal devices 801, 802, and 803 (for example only). Upon receiving a data query request, the backend management server can obtain the corresponding data query conditions, determine the starting data vertex corresponding to the data query conditions in a pre-set data relationship graph; determine the target data level corresponding to the data query conditions, and determine the target data vertex with an index relationship to the starting data vertex in the target data level; obtain the target data that meets the data query conditions based on the target data vertex; and feed back the data query status (for example only) to the terminal devices.
[0175] It should be noted that the data query method provided in this embodiment of the invention is generally executed by server 805, and correspondingly, the data query device is generally set in server 805. The data query method provided in this embodiment of the invention can also be executed by terminal devices 801, 802, and 803, and correspondingly, the data query device can be set in terminal devices 801, 802, and 803.
[0176] It should be understood that Figure 8 The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.
[0177] The following is for reference. Figure 9 It shows a schematic diagram of the structure of a computer system 900 suitable for implementing a terminal device of the present invention. Figure 9 The terminal device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.
[0178] like Figure 9As shown, the computer system 900 includes a central processing unit (CPU) 901, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 902 or programs loaded from storage section 908 into random access memory (RAM) 903. The RAM 903 also stores various programs and data required for the operation of the system 900. The CPU 901, ROM 902, and RAM 903 are interconnected via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0179] The following components are connected to I / O interface 905: an input section 906 including a keyboard, mouse, etc.; an output section 907 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 908 including a hard disk, etc.; and a communication section 909 including a network interface card such as a LAN card, modem, etc. The communication section 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to I / O interface 905 as needed. A removable medium 911, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 910 as needed so that computer programs read from it can be installed into storage section 908 as needed.
[0180] In particular, according to the embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 909, and / or installed from removable medium 911. When the computer program is executed by central processing unit (CPU) 901, it performs the functions defined above in the system of the embodiments of this invention.
[0181] It should be noted that the computer-readable medium shown in the embodiments of the present invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In the embodiments of the present invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the embodiments of the present invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0182] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer programs according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0183] The modules described in the embodiments of the present invention can be implemented in software or in hardware. The described modules can also be housed in a processor. For example, a processor can be described as including a first determining module, a second determining module, and an acquisition module. The names of these modules do not necessarily limit the module itself; for example, the first determining module can also be described as a "module for determining vertices".
[0184] In another aspect, embodiments of the present invention also provide a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs. When the one or more programs are executed by the device, the device implements the following method: in response to receiving a data query request, obtaining corresponding data query conditions, determining the starting data vertex corresponding to the data query conditions in a pre-set data relationship graph; determining the target data level corresponding to the data query conditions, determining target data vertices in the target data level that have an index relationship with the starting data vertex; and obtaining target data that meets the data query conditions based on the target data vertices.
[0185] According to the technical solution of the present invention, based on the data level to which the data vertex belongs and the index relationship between data vertices, the target data vertex corresponding to the starting data vertex is determined, and the corresponding data is obtained from the target data vertex. This can improve the efficiency and accuracy of data query and reduce the response time of data query. When the starting data level and the target data level are not adjacent, the target data level is queried from the starting data level to the target data level according to the hierarchical relationship and the index relationship. The target data vertex corresponding to the target data level is determined, which can improve the efficiency of data query and ignore data vertices and data levels that are irrelevant to the data query request, thus reducing the number of data query steps. When there are multiple starting data vertices, the smallest starting data level that is closest to the target data level is determined, which can further improve the efficiency of data query, reduce the number of data query steps, and reduce the response time of data query. When the same data query request is received multiple times, a direct index relationship between data vertices is established, which can further improve the efficiency of data query, reduce the algorithm complexity of data query, and save system resources.
[0186] The specific embodiments described above do not constitute a limitation on the scope of protection of the embodiments of the present invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the embodiments of the present invention should be included within the scope of protection of the embodiments of the present invention.
Claims
1. A method for data querying, characterized in that, include: In response to receiving a data query request, the corresponding data query conditions are obtained, and the starting data vertex corresponding to the data query conditions is determined in a pre-set data relationship graph; Determine the target data level corresponding to the data query conditions, and determine the target data vertex that has an index relationship with the starting data vertex in the target data level; Based on the target data vertex, obtain the target data that meets the data query conditions; Determining the target data vertex in the target data hierarchy that has an index relationship with the starting data vertex includes: Determine whether the starting data level to which the starting data vertex belongs is adjacent to the target data level; When the starting data level to which the starting data vertex belongs is adjacent to the target data level, the hierarchical relationship between the starting data level and the target data level is determined, and the corresponding index relationship is determined according to the hierarchical relationship; target data vertices that have the index relationship with the starting data vertex are determined from the target data level. If the starting data level to which the starting data vertex belongs is not adjacent to the target data level, determine the hierarchical relationship between the starting data level and the target data level, and determine the corresponding index relationship based on the hierarchical relationship; repeat the following steps until the adjacent data level is the target data level: from the adjacent data levels adjacent to the starting data level and conforming to the hierarchical relationship, determine the adjacent data vertex that has the index relationship with the starting data vertex; if the adjacent data level is not the target data level, take the adjacent data level as the new starting data level; if the adjacent data level is the target data level, take the data vertex determined in the target data level as the target data vertex.
2. The method according to claim 1, characterized in that, Determining the target data vertex from the target data hierarchy that has the index relationship with the starting data vertex includes: Determine the edge indices that conform to the index relationship from the vertex indices of the starting data vertices; Based on the edge index, the corresponding target data vertex is determined in the target data level.
3. The method according to claim 1, characterized in that, There are multiple starting data vertices; before determining the target data vertex that has an index relationship with the starting data vertex in the target data level, the method further includes: determining whether the hierarchical relationship between the multiple starting data levels to which the multiple starting data vertices belong is the same as that of the target data level; if the hierarchical relationship between the multiple starting data levels and the target data level is the same, determining the nearest starting data level with the smallest distance from the target data level from the multiple starting data levels, and determining the nearest starting data vertex belonging to the nearest starting data level; Determining a target data vertex that has an index relationship with the starting data vertex in the target data hierarchy includes: determining a target data vertex that has an index relationship with the nearest starting data vertex in the target data hierarchy.
4. The method according to claim 3, characterized in that, When the hierarchical relationship between multiple starting data levels and the target data level is different, the method further includes: classifying multiple starting data levels according to the hierarchical relationship to obtain multiple sets of starting data levels; determining the nearest starting data level with the smallest distance to the target data level in each set of starting data levels, and determining the nearest starting data vertex belonging to the nearest starting data level; Determining the target data vertex that has an index relationship with the starting data vertex in the target data hierarchy includes: determining the target data vertex that has an index relationship with all the nearest starting data vertices in the target data hierarchy.
5. The method according to claim 3 or 4, characterized in that, The method further includes: Generate a data query record between the starting data vertex and the target data vertex; If the number of data query records is greater than or equal to a preset threshold, a direct index relationship is established between the starting data vertex and the target data vertex. In response to receiving the data query request, the target data vertex corresponding to the starting data vertex is determined according to the direct index relationship, and the target data is obtained from the target data vertex.
6. A data query apparatus, characterized in that, include: The first determining module is used to respond to receiving a data query request, obtain the corresponding data query conditions, and determine the starting data vertex corresponding to the data query conditions in a pre-set data relationship graph; The second determining module is used to determine the target data level corresponding to the data query conditions, and to determine the target data vertex that has an index relationship with the starting data vertex in the target data level; The acquisition module is used to acquire target data that meets the data query conditions based on the target data vertex; Determining the target data vertex in the target data hierarchy that has an index relationship with the starting data vertex includes: Determine whether the starting data level to which the starting data vertex belongs is adjacent to the target data level; When the starting data level to which the starting data vertex belongs is adjacent to the target data level, the hierarchical relationship between the starting data level and the target data level is determined, and the corresponding index relationship is determined according to the hierarchical relationship; target data vertices that have the index relationship with the starting data vertex are determined from the target data level. If the starting data level to which the starting data vertex belongs is not adjacent to the target data level, determine the hierarchical relationship between the starting data level and the target data level, and determine the corresponding index relationship based on the hierarchical relationship; repeat the following steps until the adjacent data level is the target data level: from the adjacent data levels adjacent to the starting data level and conforming to the hierarchical relationship, determine the adjacent data vertex that has the index relationship with the starting data vertex; if the adjacent data level is not the target data level, take the adjacent data level as the new starting data level; if the adjacent data level is the target data level, take the data vertex determined in the target data level as the target data vertex.
7. An electronic device, characterized in that, include: One or more processors; Storage device, used to store one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-5.
8. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-5.
Citation Information
Patent Citations
Directed label graph adaptive index building method based on structure summary model
CN106202167A
Graph-relational database hybrid storage method and device
CN111190904A