Log recording method, electronic equipment and storage medium

By recording and analyzing query logs in the JanusGraph graph database, the problem of low query efficiency of graph database in complex scenarios and large data volumes is solved, and the accurate analysis and optimization of query statements is realized, and resource utilization efficiency is improved.

CN119645947AInactive Publication Date: 2025-03-18ZHEJIANG DAHUA TECH CO LTD

Patent Information

Application Number
CN202510171405.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-17
Publication Date
2025-03-18
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The JanusGraph graph database has low graph query efficiency in complex scenarios and large data volume scenarios, and lacks slow query logging and analysis capabilities, which leads to long resource usage and difficulty in performing accurate analysis and optimization.

Method used

Provides a logging method. The server obtains the query statement of the JanusGraph graph database, executes the query and records the start and completion time, and records the query statement and execution time into the log of the graph database. In the future, the reasons for slow query can be analyzed based on the log and data or index can be adjusted to improve query efficiency.

Benefits of technology

By recording and analyzing query logs, the causes of slow queries can be identified and appropriately adjusted, thereby improving the query efficiency of JanusGraph graph database and optimizing resource utilization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119645947A_ABST
    Figure CN119645947A_ABST
Patent Text Reader

Abstract

The invention discloses a log recording method, electronic equipment and a storage medium. The log recording method comprises the steps that a server obtains a query statement for a target database, wherein the target database comprises a JanusGraph graph database; executing the query statement and determining execution starting time and execution finishing time of the query statement; and recording the query statement and the execution start time and execution completion time of the query statement into a log of the target database. According to the scheme, the query statements and the execution start time and execution completion time of the query statements are recorded to the logs of the target database, so that data stored in the database or data such as indexes can be adjusted after slow query reasons are analyzed according to the logs corresponding to the query statements subsequently, and the query efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a log recording method, an electronic device, and a storage medium. Background Art

[0002] As a graph database, the distributed graph database JanusGraph can effectively support query processing of graph data and support businesses such as knowledge graphs, but it does not have the ability to record and analyze slow query logs. In actual production environments, graph queries of JanusGraph graph databases usually use TinkerPop as their query processing engine. After receiving the user's query statement, JanusGraph converts it into the corresponding ElasticSearch index operator and HBase query operator, and then executes the corresponding operator to obtain the target data and returns it to the user. For graph queries in complex scenarios and scenarios with large amounts of data, it often takes a long time to execute graph queries. The speed of execution directly determines the length of time that resources are occupied. In order to make reasonable use of resources, it is necessary to analyze and optimize the query statements of the JanusGraph graph database. At present, for the JanusGraph graph database, it is necessary to accurately analyze and optimize specific query statements in actual business scenarios, which often relies on re-querying the specific query statement, which takes a long time, and then manually analyzing the specific query statement.

[0003] In view of the existing technical defects, how to provide a solution to improve the query efficiency of query statements in the JanusGraph graph database is a technical problem that needs to be solved urgently by technical personnel in this field. Summary of the invention

[0004] The present application at least provides a log recording method, an electronic device, and a storage medium.

[0005] The present application provides a logging method, comprising: a server obtains a query statement for a target database, the target database comprising a JanusGraph graph database; executes the query statement and determines a start execution time and an execution completion time of the query statement; and records the query statement and the start execution time and the execution completion time of the query statement in a log of the target database.

[0006] The present application provides a log recording device, including: an acquisition module, an execution module and a recording module; the acquisition module is used for a server to obtain a query statement for a target database, and the target database includes a JanusGraph graph database; the execution module is used to execute the query statement and determine the start execution time and execution completion time of the query statement; the recording module is used to record the query statement and the start execution time and execution completion time of the query statement in the log of the target database.

[0007] The present application provides an electronic device, including a memory and a processor, wherein the processor is used to execute program instructions stored in the memory to implement the above-mentioned log recording method.

[0008] The present application provides a computer-readable storage medium on which program instructions are stored. When the program instructions are executed by a processor, the above-mentioned log recording method is implemented.

[0009] In the above scheme, the server obtains the query statement for the JanusGraph graph database, executes the query statement and determines the start execution time and execution completion time of the query statement, and then records the query statement and the start execution time and execution completion time of the query statement in the log of the JanusGraph graph database, so that the data or index stored in the database can be adjusted after analyzing the cause of slow query according to the log corresponding to each query statement, thereby improving the efficiency of the query.

[0010] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] The drawings herein are incorporated into the specification and constitute a part of the specification. These drawings illustrate embodiments consistent with the present application and are used together with the specification to illustrate the technical solution of the present application.

[0012] Figure 1 This is a flow chart of an embodiment of the log recording method of the present application. Figure 1 ; Figure 2 This is a flow chart of an embodiment of the log recording method of the present application. Figure 2 ; Figure 3 This is a flow chart of an embodiment of the log recording method of the present application. Figure 3 ; Figure 4 It is a structural schematic diagram of an embodiment of a log recording device of the present application; Figure 5 It is a structural schematic diagram of an embodiment of the electronic device of the present application; Figure 6 It is a structural diagram of an embodiment of a computer-readable storage medium of the present application. DETAILED DESCRIPTION

[0013] The scheme of the embodiment of the present application is described in detail below in conjunction with the drawings of the specification.

[0014] In the following description, for the purpose of explanation rather than limitation, specific details such as specific system structures, interfaces, and technologies are provided to facilitate a thorough understanding of the present application.

[0015] The term "and / or" in this article is only a description of the association relationship of associated objects, indicating that there may be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the objects associated before and after are in an "or" relationship. In addition, "many" in this article means two or more than two. In addition, the term "at least one" in this article means any combination of at least two of any one or more of a plurality of, for example, including at least one of A, B, and C, can mean including any one or more elements selected from the set consisting of A, B, and C.

[0016] The present application provides some logging methods and logging devices. The application scenarios of the logging method include but are not limited to the JanusGraph graph database logging scenario, or the query statement analysis or optimization scenario of the JanusGraph graph database. The execution subject of the logging method may be a logging device or a server capable of implementing the logging of the JanusGraph graph database. For example, the logging device may be arranged in a terminal device or a server or other processing device, wherein the terminal device may be a device for logging, a user equipment (UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (PDA), a handheld device, a computing device, a vehicle-mounted device, etc. In some possible implementations, the logging method may be implemented by a processor calling a computer-readable instruction stored in a memory.

[0017] See also Figure 1 , Figure 1 This is a flow chart of an embodiment of the log recording method of the present application. Figure 1 Specifically, the logging method may include the following steps: Step S11: The server obtains a query statement for the target database.

[0018] Target databases include the JanusGraph graph database.

[0019] The server may be a server corresponding to a JanusGraph graph database. Specifically, the server may be a JanusGraph server. The JanusGraph graph database may run on multiple servers, which constitute a cluster, each server storing a portion of the data, and each server may process queries in parallel, thereby improving performance and scalability. It is understood that the above step S11 may be any server in the cluster corresponding to the JanusGraph graph database obtaining a query statement for the target database.

[0020] The target database is a graph database, which is a database used to store and process graphs and is a NoSQL database. Entities correspond to points in the graph, and relationships between entities correspond to edges in the graph. Its typical application scenarios include knowledge graphs, recommendation systems, etc. JanusGraph graph database, that is, the target database contains multiple static and dynamic nodes and dynamic and static relationships at the same time, where static nodes can contain various set data, such as: target object set information, vehicle set information, case set information, etc. Dynamic nodes can contain various spatiotemporal event data, such as: violation time, travel trajectory, etc., which will continue to increase over time. Static relationships can include association relationships, relationships between target objects and vehicles, such as: parent-child relationships, colleague relationships, owner relationships, etc. Dynamic relationships can include relationships between target objects and events, such as: accompanying relationships, violation relationships, etc., which will also continue to increase over time. Among them, the target object can be a vehicle, an animal or other organism. The query statement can be used to query static and dynamic nodes and dynamic and static relationships in the target graph database. The database engine of the target database is JanusGrap, which is a graph database engine that uses attribute graphs for modeling. JanusGraph's modular architecture enables it to adapt to a variety of storage backends and index backends. Storage backend refers to the database that actually stores the vertex and edge data of the graph database, such as Cassandra, Hbase, etc. Index backend refers to a system that uses its own characteristics to support more search function scenarios such as fuzzy search, geographic coordinate search, full-text search, etc. Optional index backend systems include ElasticSearch, Solr, Lucene, etc. The target database of this application takes Hbase as the storage backend and ElasticSearch as the external index backend as an example.

[0021] Exemplarily, the query statement in the above step S11 may be a statement that can query the time consumed by the query statement in the target database operation. The query statement in the above step S11 may be a slow query statement, which may be a query statement that can query the time consumed by the target database operation exceeding the time threshold set by the target database service. Specifically, the query statement may be a Gremlin query statement, which is a graph query language. The graph database JanusGraph supports the use of Gremlin query statements for data query and other operations, and supports the use of HTTP or WebSocket request methods to send query requests to the JanusGraph server. When the request methods corresponding to the query requests are different, the processors corresponding to the Gremlin engine are different. Among them, the graph computing engine of the target database is TinkerPop, which is a general-purpose graph computing engine for processing graph data, and one of its core components is the Gremlin engine.

[0022] In some application scenarios, the process of step S11 may be to receive a query statement sent by a client. In other application scenarios, step S11 may be to directly receive a natural language query statement sent by a client, and the server determines the query statement based on the natural language query statement.

[0023] Step S12: Execute the query statement and determine the start execution time and execution completion time of the query statement.

[0024] The start execution time of the query statement can be used to represent the timestamp corresponding to the start time when the query statement is executed. The execution completion time can be used to represent the execution time required in the process of executing the query statement. The execution completion time is the difference between the end execution time and the start execution time in the process of executing the query statement. The way to execute the query statement can be to execute the Gremlin query statement using the Gremlin engine. And determine the execution time required for the Gremlin query statement, and use the execution time as the execution completion time.

[0025] Step S13: Record the query statement and the start execution time and execution completion time of the query statement into the log of the target database.

[0026] The log of the target database is a log file in the target database used to record query statements and the execution time of the query statements. The log includes several recorded query statements. Any record in the log includes at least the query statement corresponding to the record and the start execution time and execution completion time corresponding to the query statement. In some application scenarios, any record in the log may also include client information, execution plan, resource usage, error information, and context information. Client information may refer to the client IP address and request method of initiating a natural language query statement, user ID information, etc. The execution plan may refer to the execution plan of the query statement, including the index used, table scan, connection method, etc. Resource usage may refer to memory usage, that is, the amount of memory used during the execution of the query statement corresponding to the query statement. Error information may refer to the error information that may be recorded in the log if an error occurs during the execution of the query statement. Context information may refer to context information when the query statement is executed, such as session ID, transaction ID, etc.

[0027] Specifically, the query statement and the start execution time and the execution completion time of the query statement are recorded as the information to be recorded in the log of the target database, and are recorded in the log in units of one piece of information to be recorded. In some application scenarios, regardless of whether the execution completion time of the query statement exceeds the threshold time, the query statement and the start execution time and the execution completion time of the query statement are recorded in the log as the information to be recorded. In other application scenarios, the above step S13 may be that the query statement and the start execution time and the execution completion time of the query statement are recorded in the log as the information to be recorded only when the execution completion time of the query statement exceeds the threshold time.

[0028] In the above scheme, the server obtains the query statement for the JanusGraph graph database, executes the query statement and determines the start execution time and execution completion time of the query statement, and then records the query statement and the start execution time and execution completion time of the query statement in the log of the JanusGraph graph database, so that the data or index stored in the database can be adjusted after analyzing the cause of slow query according to the log corresponding to each query statement, thereby improving the efficiency of the query.

[0029] See also Figure 2 , Figure 2 This is a flow chart of an embodiment of the log recording method of the present application. Figure 2 .

[0030] In some embodiments, the above step S11 may include the following steps: Step S21: Obtain the initial query statement sent by the client. The initial query statement is obtained by the client parsing the natural language query statement, obtaining the triple parameter corresponding to the natural language query statement and assembling the triple parameter with the query statement template parameter. Step S22: Determine the request method of the initial query statement. Different request methods correspond to different parsing methods. Step S23: Parse the initial query statement according to the parsing method corresponding to the request method of the initial query statement to obtain the query statement.

[0031] Among them, the client inputs a natural language query statement, and then the client performs semantic analysis on the natural language query statement to obtain the triple parameter of the natural language query statement. Triple is the basic unit of knowledge representation in the knowledge graph, referred to as SPO. Triple is used to represent the relationship between entities or the attribute value of a certain attribute of an entity. From the content point of view, the structure of the triple is: "resource-attribute-attribute value". The resource entity is represented by URI (Uniform Resource Identifier), and the attribute value can be the URI of another resource entity or the value of a certain data type, also known as literals. For example, the natural language query statement "Zhang San's friend is Li Si" is converted into a triple parameter, that is, the triple parameter can be expressed as (Zhang San, friend, Li Si). The query statement template parameter can include parameter content related to the slow query statement. The query statement is assembled according to the query graph structure corresponding to the triple parameter and the triple parameter.

[0032] The process in which the client assembles the triple parameter with the query statement template parameter to obtain the initial query statement may be: obtaining the query graph structure based on the triple parameter. Then, based on the query graph structure, the natural language query statement is assembled by objects to generate the query statement. The client obtains the corresponding query graph structure in the entire graph model according to the triple parameter of the natural language query statement. Specifically, the query graph structure generally refers to the graph structure generated according to the query intent, which belongs to the subgraph of the entire graph model at the conceptual level, also known as the conceptual subgraph. After the actual label (label / tag) and property value (property key value) are reduced, an equivalent query statement can be directly or indirectly generated based on it. If the query graph structure is an imperative language such as Gremlin, it is necessary to determine the traversal logic by itself. The above-mentioned acquisition of the query graph structure based on the triple parameter may be: the query statement generation device converts the triple information into a relationship matrix, and identifies the topological structure of the relationship matrix by examining the basic characteristics of the relationship matrix. First, the query statement generation device converts the relationship triple in the triple, that is, the triple representing the edge, into a relationship matrix. The query statement generation device determines the query graph structure by examining the correlation value of the relationship matrix of the triple information transformation. The query graph structure can be a chain structure, an L-type structure, a Y-type structure, an X-type structure, a radial structure, etc., wherein different types of query graph structures correspond to the number of nodes and the total number of edges in the query graph structure and the relationship between nodes and edges. Based on the query graph structure, the natural language query statement is assembled into objects, and the query statement generation can be: determining the query statement template parameters based on the query graph structure. The query pattern is used to assemble the natural language query statement into objects to generate an initial query statement.

[0033] Input natural language query statements related to natural language query to the knowledge graph platform. The knowledge graph platform can be a client, and the knowledge graph platform can use a request method related to HTTP or a request method of WebSocket to send a query request to the JanusGraph server. Exemplarily, the above step S21 can be to perform semantic parsing on the natural language query statement to obtain the triple parameter corresponding to the natural language query statement, and then request Gremlin to generate a service based on the triple parameter to obtain the natural query statement and the query statement template parameter. The client assembles the natural query statement and the query statement template parameter to obtain an initial query statement, and sends the initial query statement to the server via HTTP or WebSocket request.

[0034] The parsing method is used to parse the initial query statement sent by the client and received by the server to obtain a query statement that can be executed by the server. The request method of the initial query statement includes a request method related to HTTP and a request method of WebSocket. In some application scenarios, in response to the request method of the initial query statement being a request method related to HTTP, the initial query statement is parsed using a parsing method corresponding to the request method related to HTTP to obtain a query statement. In other application scenarios, in response to the request method of the initial query statement being a request method of WebSocket, the initial query statement is parsed using a parsing method corresponding to the request method of WebSocket to obtain a query statement.

[0035] In other application scenarios, first, the natural query statement sent by the client is obtained. Then, the natural language query statement is parsed to obtain the triple parameter corresponding to the natural language query statement. Subsequently, the triple parameter is assembled with the query statement template parameter to obtain the query statement. The server only needs to obtain the natural query statement of the client for the target database. The server parses the natural language query statement to obtain the triple parameter corresponding to the natural language query statement. The server can have a built-in query statement template parameter, assemble the triple parameter with the query statement template parameter, and obtain the query statement corresponding to the natural language query statement.

[0036] It can be considered that the initial query statement obtained by using the natural query statement and the query statement determined according to the request method of the initial query statement can achieve the execution completion time of the query statement each time the query statement is executed. In other words, it can be achieved that each time a natural language query is performed on the knowledge graph platform, the execution completion time of the corresponding query statement is recorded, and the query statement and the execution completion time can be recorded instantly, thereby improving the utilization rate of the query statement and simplifying the subsequent analysis process of the query statement.

[0037] In some embodiments, the above-mentioned logging method further comprises the following steps: determining whether the logging function is enabled, and in response to the logging function being enabled, performing the steps of determining the start execution time and the execution completion time of the query statement.

[0038] The logging function is used to indicate that the server can determine the start execution time and the execution completion time of the query statement to be executed, and record the start execution time and the execution completion time of the determined query statement as information to be recorded in the log. When the logging function of the server is turned on, the start execution time and the execution completion time of the query statement are automatically determined for each query statement. When the logging function of the server is not turned on, for each query statement, only the query statement is executed and the relevant information of the query statement is not determined and recorded.

[0039] Exemplarily, by adding a slow query logger in the JanusGraph graph database and modifying the query processing logic of the corresponding processor of the Gremlin query engine, the logging function of the query statement in the target database is realized, that is, Gremlin slow query logging is realized.

[0040] It can be considered that logging support is configurable, and users can turn logging on or off. If logging is turned on, users can record all Gremlin query statements or only query statements that exceed a certain threshold, thereby dynamically realizing the logging function of query statements.

[0041] In some embodiments, the above step S12 may include the following steps: first, determining whether the query statement satisfies the grammatical rules. Then, in response to the query statement satisfying the grammatical rules, executing the query statement and recording the start execution time of the query statement.

[0042] The grammatical rule may be a grammatical structure rule of a query statement that matches the target database. When the query statement satisfies the grammatical rule, the query statement is executed and the start execution time of the query statement is recorded. When the query statement does not satisfy the grammatical rule, the query statement is not executed, or the query statement is marked as a grammatical error, and then the query statement is executed and the start execution time of the query statement is recorded.

[0043] It can be considered that the present application first determines whether the query statement satisfies the grammatical rules and then executes the query statement and records it in the log, which can ensure that the influence of the grammatical rules on the execution completion time of the query statement is excluded when analyzing the log, so as to improve the accuracy of the analysis of the execution plan of the query statement using the execution completion time of the query statement.

[0044] In some embodiments, the above step S13 may include the following steps: recording the query statement and the start execution time and the execution completion time of the query statement in the log of the target database, including: first, determining whether the execution completion time of the query statement exceeds the threshold time. Then, in response to the execution completion time of the query statement exceeding the threshold time, recording the query statement and the execution time of the query statement in the log.

[0045] The threshold time may be a preset time. In some application scenarios, the threshold time may be a default time. In other application scenarios, the threshold time may be obtained in response to a threshold time setting operation of a client when the logging function is started, or may be a setting time of a slow query automatically configured by a server.

[0046] When the execution completion time of a query statement exceeds the threshold time, the query statement and the execution time of the query statement are recorded in the log. In some application scenarios, when the execution completion time of a query statement does not exceed the threshold time, the query statement and the execution time of the query statement are not recorded in the log. In other application scenarios, when the execution completion time of a query statement does not exceed the threshold time, the query statement is marked, and the marked query statement and the execution time of the query statement are recorded in the log. Among them, marking a query statement can be that when analyzing the log, the query statement belongs to a query statement to be analyzed with a lower priority among several recorded query statements.

[0047] It can be considered that judging whether the query statement is to be recorded in the log by the relationship between the execution completion time of the query statement and the threshold time, and recording the query statement exceeding the threshold time in the log can improve the reliability of the query statement recorded in the log.

[0048] See also Figure 3 , Figure 3 This is a flow chart of an embodiment of the log recording method of the present application. Figure 3 .

[0049] In some embodiments, the log includes several recorded query statements. After the above step S13, the above log recording method may further include the following steps: Step S31: Perform data analysis on several recorded query statements to obtain analysis results of each recorded query statement. Each analysis result includes the execution time statistics of each recorded query statement. Step S32: In response to the execution time statistics of the target query statement reaching the threshold time statistics, adjust the data related to the target query statement in the target database. The target query statement is any one of the several recorded query statements.

[0050] The data analysis of each recorded query statement may be to determine the time statistics related to the execution of the query statement, and obtain the execution time statistics of the recorded query statement. Specifically, the time related to the execution of the query statement includes: execution completion time, query parsing time, subquery execution time, index search time, traversal time, relational operation time, data return time, and access frequency of specific nodes and / or edges. The execution completion time, that is, the total query time, refers to the entire time from the start of the query to the end of the query, including the time of all sub-operations, such as parsing the query, executing the query, returning results, etc. The query parsing time may refer to the time spent parsing the query statement into an internal execution plan. The subquery execution time may refer to the execution time of each subquery if the query contains multiple subqueries or steps, which can help identify bottlenecks in the query. For example, a specific pattern matching or path search may be particularly time-consuming. The index search time may refer to the time spent using an index to quickly locate a node or edge. If the query involves a large number of index searches, this part of time may be the main part of the total time spent corresponding to the execution completion time. The traversal time may refer to the time spent on traversing nodes and edges on the graph. For example, starting from a node, the time to find related nodes along an edge. Relationship operation time can refer to the time spent processing edges or relationships, such as finding connected nodes, calculating paths, etc. Data return time can refer to the time spent by the server returning query results to the client. This includes operations such as serializing results and network transmission related to the above request methods. The access frequency of specific nodes and / or edges can be analyzed by analyzing the query trajectory to count which nodes or edges are frequently accessed, so as to optimize the query method of the query statement based on the execution time statistics obtained.

[0051] In some application scenarios, the execution time statistics may be statistics related to execution time obtained by classifying several query scenarios according to the above-mentioned static and dynamic nodes and the various contents of dynamic and static relationships, and performing statistics on the execution completion time of query statements belonging to the same query scenario. The statistics may be mean, mode, median, variance and standard deviation reflecting the degree of discreteness, and the like. Exemplarily, the same query scenario may be an association relationship in a static relationship. In other application scenarios, the execution time statistics may be the execution time statistics of each recorded query statement in several queried statements. It is understandable that the execution time statistics of each recorded query statement can characterize the query performance of the query statement, specifically including which points (nodes), which relationships (edges), and the specific time-consuming links are involved in the query statement when performing a graph query in the target database.

[0052] The threshold time statistic may be a preset value or a dynamically set value. In some application scenarios, the threshold time statistic may characterize the statistics of the execution completion time of any recorded query statement and each query statement of the target query scenario to which the recorded query statement belongs. The statistic may be a mean, a mode, a median, a variance and a standard deviation reflecting the degree of dispersion, and the like. Exemplarily, if any recorded query statement belongs to the target query scenario, for example, it belongs to an association relationship in a static relationship. In other application scenarios, the threshold time statistic may be a statistic of the execution completion time of all recorded query statements in the log. The statistic may be a mean, a mode, a median, a variance and a standard deviation reflecting the degree of dispersion, and the like.

[0053] Determine whether the execution time statistics of the target query statement reaches the threshold time statistics. When the execution time statistics of the target query statement reaches the threshold time statistics, adjust the data related to the target query statement in the target database. When the execution time statistics of the target query statement reaches the threshold time statistics, do not adjust the data related to the target query statement in the target database, or set the adjustment order of the data related to the target query statement in the target database or the display priority of the target query statement in the target database on the client to a later time. The data related to the target query statement in the target database may be an execution plan corresponding to the target query statement.

[0054] In some embodiments, the step of adjusting the data related to the target query statement in the target database may include the following steps: first, determining the query scenario in which the target query statement is located as the target query scenario. Then, adjusting the query method and / or index related to the target query scenario.

[0055] The query scenario is used to represent at least one of the above-mentioned static and dynamic nodes and dynamic and static relationships contained in the target database. Exemplarily, the target query statement is a query statement related to the natural language query statement "Who is Zhang San's mother?" The query scenario in which the target query statement is located is a static relationship, or the query scenario in which the target query statement is located is an associated relationship in a static relationship.

[0056] In some application scenarios, adjusting the query mode related to the target query scenario may be to convert the query mode of all query statements belonging to the target query scenario into an equivalent but potentially more efficient query form. Among them, the adjustment of the query mode of any query statement belonging to the target query scenario may refer to subquery execution, index search, traversal mode, and search for connected nodes and calculation paths in relational operations.

[0057] In some application scenarios, the query mode related to the target query scenario may be to adjust the query mode related to the target query scenario, or to rewrite the query mode of all query statements belonging to the target query scenario. Query rewriting may be to optimize the subgraph pattern and precompute the path for any query statement belonging to the target query scenario. Among them, subgraph pattern optimization may be to rearrange the pattern matching order in any query statement belonging to the target query scenario to reduce the size of the intermediate result set. The precomputed path may be a path that is frequently queried for each query statement in the target query scenario, and precompute and store the results may be considered to reduce the time of real-time calculation.

[0058] In other application scenarios, the query mode related to the target query scenario may be to adjust the query mode related to the target query scenario, or to pre-set the query mode of all query statements belonging to the target query scenario. Pre-setting may include partitioning the data and setting redundant attributes. Partitioning the data may be to partition the data related to the target query scenario to distinguish it from data related to other query scenarios, and using the partitioned data to implement the execution of query statements belonging to the target query scenario can reduce the execution completion time. Redundant attribute setting may be, in certain circumstances, to reduce the traversal depth when querying the target query scenario by adding redundant attributes to some relevant nodes or edges belonging to the target query scenario.

[0059] In other application scenarios, adjusting the query mode related to the target query scenario may be to reselect the indexes of all query statements belonging to the target query scenario. Index reselection may be to select a suitable index from the indexes of the target query scenario to speed up the search for nodes or edges of any query statement belonging to the target query scenario. In addition, indexes may be created for frequently queried attributes in the target query scenario to speed up data retrieval.

[0060] In some application scenarios, adjusting the indexes related to the target query scenario may include reselecting the indexes of all query statements belonging to the target query scenario and adjusting the query method of any query statement belonging to the target query scenario. For details, please refer to the above and will not be repeated here.

[0061] It can be considered that by adjusting the query method and / or index related to the target query scenario, the execution plan of the relevant query statement in the JanusGraph graph database can be optimized, and the utilization rate of computing resources in the process of executing the query statement can be improved.

[0062] In some embodiments, there are multiple target query statements, and at least some of the target query statements correspond to different target query scenarios. The above adjustment of the query method and / or index related to the target query scenario may include the following steps: First, obtain the statistical number of times related to each target query scenario in the log. Then, based on the statistical number, determine the adjustment order of the query method and / or index corresponding to each target query scenario. Subsequently, according to each adjustment order, adjust the query method and / or index related to the target query scenario respectively.

[0063] The statistical times related to each target query scenario in the log are used to represent the statistics of the query scenarios to which several recorded query statements belong respectively. The adjustment order can be the order of adjustment corresponding to each query scenario. If the statistical times of any target query scenario are higher, the adjustment weight of the target query scenario is set larger. Exemplarily, the adjustment weight of the target query scenario with the highest statistical times among the statistical times related to each target query scenario is set to the largest. Prioritize adjusting the query method of the query statement belonging to the target query scenario, any one of the indexes related to the target query scenario, or both. Please refer to the above content for the specific adjustment method, which will not be repeated here.

[0064] Each adjustment order includes the adjustment order of the query scenario to which each recorded query statement belongs. The adjustment order is determined based on the adjustment weight of the query scenario to which the recorded query statement belongs. The greater the adjustment weight, the higher the adjustment order.

[0065] It can be considered that adjusting the query mode and / or index related to the target query scenario according to the adjustment order of each target query scenario can improve the business performance of the key business scenario, that is, the query statement related to the key query scenario.

[0066] In some application scenarios, based on the above-mentioned logging function, a query log analysis task is designed and implemented. The query analysis results of the query log analysis task can be visualized on the graph console to avoid manual screening and analysis of slow query logs. Among them, the graph console can be a client that can display query analysis results. The query analysis results can be the analysis results of the above-mentioned recorded query statements, or they can be the adjustment results obtained by adjusting the query method and / or index related to the target query scenario. The log analysis task will read the log file, perform statistical analysis on the corresponding Gremlin query records in the log, and write the statistical analysis results into the library table. The statistical analysis situation can be viewed from the graph console, and then the query of graph data and the knowledge graph business scenarios can be optimized in a targeted manner to improve the efficiency of query processing.

[0067] In the above scheme, the server obtains the query statement for the JanusGraph graph database, executes the query statement and determines the start execution time and execution completion time of the query statement, and then records the query statement and the start execution time and execution completion time of the query statement in the log of the JanusGraph graph database, so that the data or index stored in the database can be adjusted after analyzing the cause of slow query according to the log corresponding to each query statement, thereby improving the efficiency of the query.

[0068] See also Figure 4 , Figure 4 It is a structural diagram of an embodiment of the log recording device of the present application. The log recording device 40 includes an acquisition module 41, an execution module 42 and a recording module 43; the acquisition module 41 is used for the server to obtain a query statement for a target database, and the target database includes a JanusGraph graph database; the execution module 42 is used to execute the query statement and determine the start execution time and execution completion time of the query statement; the recording module 43 is used to record the query statement and the start execution time and execution completion time of the query statement into the log of the target database.

[0069] In the above scheme, the server obtains the query statement for the JanusGraph graph database, executes the query statement and determines the start execution time and execution completion time of the query statement, and then records the query statement and the start execution time and execution completion time of the query statement in the log of the JanusGraph graph database, so that the data or index stored in the database can be adjusted after analyzing the cause of slow query according to the log corresponding to each query statement, thereby improving the efficiency of the query.

[0070] Please refer to the logging method for the functions performed by each module, which will not be repeated here.

[0071] See also Figure 5 , Figure 5 1 is a schematic diagram of the structure of an embodiment of an electronic device of the present application. The electronic device 50 includes a memory 51 and a processor 52, and the processor 52 is used to execute program instructions stored in the memory 51 to implement the steps in the above-mentioned log recording method embodiment. In a specific implementation scenario, the electronic device 50 may include but is not limited to: a multi-camera device, a microcomputer, and a server. In addition, the electronic device 50 may also include a mobile device such as a laptop computer and a tablet computer, which is not limited here.

[0072] Specifically, the processor 52 is used to control itself and the memory 51 to implement the steps in the above-mentioned log recording method embodiment. The processor 52 can also be called a CPU (Central Processing Unit). The processor 52 may be an integrated circuit chip with signal processing capabilities. The processor 52 can also be a general-purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field-programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. In addition, the processor 52 can be implemented by an integrated circuit chip.

[0073] In the above scheme, the server obtains the query statement for the JanusGraph graph database, executes the query statement and determines the start execution time and execution completion time of the query statement, and then records the query statement and the start execution time and execution completion time of the query statement in the log of the JanusGraph graph database, so that the data or index stored in the database can be adjusted after analyzing the cause of slow query according to the log corresponding to each query statement, thereby improving the efficiency of the query.

[0074] See also Figure 6 , Figure 6 The computer-readable storage medium 60 stores program instructions 601, which implement the steps in any of the above-mentioned log recording method embodiments when executed by a processor.

[0075] In the above scheme, the server obtains the query statement for the JanusGraph graph database, executes the query statement and determines the start execution time and execution completion time of the query statement, and then records the query statement and the start execution time and execution completion time of the query statement in the log of the JanusGraph graph database, so that the data or index stored in the database can be adjusted after analyzing the cause of slow query according to the log corresponding to each query statement, thereby improving the efficiency of the query.

[0076] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.

[0077] The above description of various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced to each other, and for the sake of brevity, they will not be repeated herein.

[0078] In the several embodiments provided in the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device implementation described above is only schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation, such as units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.

[0079] 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.

[0080] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) or a processor to execute all or part of the steps of each implementation method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.

Claims

1. A log recording method, characterized in that: The method comprises: The server obtains a query statement for a target database, wherein the target database includes a JanusGraph graph database; Execute the query statement and determine the start execution time and the execution completion time of the query statement; The query statement, the start execution time of the query statement, and the execution completion time are recorded in the log of the target database.

2. The method according to claim 1, characterized in that The step of recording the query statement and the start execution time and the execution completion time of the query statement into a log of the target database includes: Determine whether the execution completion time of the query statement exceeds a threshold time; In response to the execution completion time of the query statement exceeding a threshold time, the query statement and the execution time of the query statement are recorded in a log.

3. The method according to claim 1 or 2, characterized in that: The server obtains a query statement for a target database, including: Acquire an initial query statement sent by a client, wherein the initial query statement is obtained by the client parsing a natural language query statement, obtaining a triple parameter corresponding to the natural language query statement, and assembling the triple parameter with a query statement template parameter; Determine a request method of the initial query statement, where different request methods correspond to different parsing methods; The initial query statement is parsed according to the parsing method corresponding to the request method of the initial query statement to obtain the query statement.

4. The method according to claim 1 or 2, characterized in that: The executing the query statement and determining the start execution time and the execution completion time of the query statement includes: Determine whether the query statement satisfies the grammatical rules; In response to the query statement satisfying the grammatical rule, the query statement is executed and the start execution time of the query statement is recorded.

5. The method according to claim 1 or 2, characterized in that: The log includes a plurality of recorded query statements. After recording the query statements and the start execution time and the execution completion time of the query statements in the log of the target database, the method further includes: Performing data analysis on the plurality of recorded query statements to obtain analysis results of each of the recorded query statements, each of the analysis results including an execution time statistic of each of the recorded query statements; In response to an execution time statistic of a target query statement reaching a threshold time statistic, adjusting data related to the target query statement in the target database, the target query statement being any one of the plurality of recorded query statements.

6. The method according to claim 5, characterized in that The adjusting the data in the target database related to the target query statement includes: Determining the query scenario in which the target query statement is located as the target query scenario; The query mode and / or index related to the target query scenario is adjusted.

7. The method according to claim 6, characterized in that There are multiple target query statements, and at least some of the target query statements correspond to different target query scenarios. The adjusting of the query mode and / or index related to the target query scenario includes: Obtaining the statistical number of times related to each of the target query scenarios in the log; Based on the statistical times, determining the query mode and / or index adjustment order corresponding to each of the target query scenarios; According to each of the adjustment sequences, the query mode and / or index related to the target query scenario are adjusted respectively.

8. The method according to claim 1 or 2, characterized in that: The method further comprises: Determine whether the logging function is enabled; In response to the logging function being enabled, the step of determining the start execution time and the execution completion time of the query statement is performed.

9. An electronic device, characterized in that: include: A memory and a processor, wherein the memory stores program instructions, and the processor retrieves the program instructions from the memory to execute the method according to any one of claims 1 to 8.

10. A computer-readable storage medium having program instructions stored thereon, characterized in that: When the program instructions are executed by a processor, they are used to implement the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

  • Query statement generation method, device and system and computer readable storage medium

    CN112989145A

  • Method and system for improving document file retrieval efficiency based on knowledge graph

    CN113221562A

  • Method and system for querying SCD file of intelligent substation through natural language

    CN114168615A

  • Generation method and device of slow query log, equipment and medium

    CN117971887A

  • Data query method and system based on knowledge graph, and device and storage medium

    WO2023125718A1

Cited By

  • SQL (Structured Query Language) statement optimization suggestion generation method and device, medium and electronic equipment

    CN120067140A