A query method and device, electronic equipment and storage medium

By constructing query statements with keyword phrase clauses and relational clauses in a JSON database and generating target query plans using inverted indexes, the problem of low efficiency and poor pattern adaptability in existing JSON data queries is solved, achieving efficient fuzzy queries and automatic data pattern adaptation.

CN115878661BActive Publication Date: 2026-06-19AGRICULTURAL BANK OF CHINA

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
AGRICULTURAL BANK OF CHINA
Filing Date
2022-11-17
Publication Date
2026-06-19

AI Technical Summary

Technical Problem

Existing JSON data query methods require writing separate query statements for various JSON data patterns, which is time-consuming and laborious, lacks fuzzy query capabilities, and the existing interfaces cannot adapt to new data patterns.

Method used

By constructing a query statement that includes keyword clauses and relational clauses, the system queries the list of target patterns in the inverted index of the JSON database, generates a target query plan, and achieves fuzzy search and automatic adaptation of data patterns.

Benefits of technology

It enables fuzzy queries on JSON databases, adapts to multiple data patterns, improves query efficiency and scalability, and reduces the workload of writing query statements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115878661B_ABST
    Figure CN115878661B_ABST
Patent Text Reader

Abstract

This invention discloses a query method, apparatus, electronic device, and storage medium. The method includes: obtaining a query statement, wherein the query statement includes at least one keyword clause and a relational clause, the keyword clauses being connected by the relational clauses; querying the inverted index of a JavaScript object notation JSON database based on each keyword clause to obtain at least one target pattern list, wherein the target pattern lists are connected by relational clauses, and the connection relationships between the target pattern lists are the same as the connection relationships between the keyword clauses; determining a target query plan based on the target pattern list; and querying the JSON database according to the target query plan to obtain query results. The solution provided by this invention enables fuzzy queries on JSON databases, is adaptable to various non-relational databases based on JSON documents, and is applicable to various data patterns, achieving automatic data pattern adaptation and high scalability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database management technology, and in particular to a query method, apparatus, electronic device, and storage medium. Background Technology

[0002] In big data analytics scenarios, it is often necessary to store data from different data sources in a unified manner and then use a unified query interface for querying and analysis.

[0003] JavaScript Object Notation (JSON) is a commonly used data representation format, characterized by its strong expressiveness and flexible schema. JSON data from different data sources often have different schemas. When performing unified analysis on this data, using queries with specific formatted statements can greatly improve analytical efficiency.

[0004] However, existing query methods, such as JSONPath, are mostly based on the traditional XPath query syntax. When performing unified queries on JSON data of various different formats, it is often necessary to write separate data query statements for each format, which is time-consuming and laborious, and cannot adapt well to new data formats. In addition, existing JSON data query interfaces can only match field names based on simple regular expression mechanisms and do not have the feature of fuzzy search. Summary of the Invention

[0005] This invention provides a query method, device, electronic device, and storage medium that can perform fuzzy queries on JSON databases. It is adaptable to various non-relational databases based on JSON documents, and is suitable for various data patterns. It achieves automatic data pattern adaptation and has high scalability.

[0006] According to one aspect of the present invention, a query method is provided, comprising:

[0007] Retrieve the query statement, which includes at least one keyword phrase clause and a relational clause, with the keyword phrase clauses connected by the relational clause;

[0008] For each keyword clause, query the inverted index of the JavaScript Object Notation JSON database to obtain at least one list of target patterns. The target pattern lists are connected by relational clauses, and the connection relationship between the target pattern lists is the same as the connection relationship between the keyword clauses.

[0009] Based on the list of target patterns, determine the target query plan;

[0010] The query is performed in the JSON database according to the target query plan, and the query results are obtained.

[0011] Optionally, the JSON database includes multiple JSON documents; before retrieving the query statement, it also includes:

[0012] Determine the data schema and document mapping list for each JSON document. The document mapping list includes the mapping between each value contained in the JSON document and its query path.

[0013] The query paths in all document correspondence lists are segmented to obtain a keyword list, which includes multiple keywords.

[0014] An inverted index is generated based on the keyword list, the data schema of all JSON documents, and the document mapping list. The inverted index includes the mapping between keywords and query paths, the JSON documents to which the query paths belong, and the data schema.

[0015] Optionally, retrieve the query statement, including:

[0016] Receive the user's original input statement;

[0017] The original statement is parsed to obtain keyword phrase clauses and relational clauses. Each keyword phrase clause includes at least two keywords, query operators, and query operands. The relational clauses include AND clauses and / or OR clauses.

[0018] The query statement is generated by connecting keyword group clauses with relational clauses.

[0019] Optionally, for any keyword phrase clause, perform a query in the inverted index of the JSON database based on the keyword phrase clause to obtain a list of target patterns, including:

[0020] The inverted index is used to match at least two keywords in the keyword phrase clause to obtain the original pattern list;

[0021] The original pattern list is filtered according to the constraints to obtain the target pattern list.

[0022] Optionally, the constraints include a first constraint sub-condition and a second constraint sub-condition; wherein,

[0023] The first constraint subcondition matches a non-overlapping segment of the query path for each keyword, and this segment includes all keywords in the keyword group clause;

[0024] The second constraint subcondition is that the path segments matched between different keywords satisfy the order of the keywords in the keyword group clause.

[0025] Optionally, based on the list of target patterns, determine the target query plan, including:

[0026] Construct the original query plan based on the target pattern list, query operators, and query operands;

[0027] The original query plan is optimized to obtain the target query plan.

[0028] Optionally, the original query plan can be optimized based on principles 1 and 2, or on principles 1 and 3:

[0029] Principle 1: For at least two target pattern lists joined by an AND clause, take the intersection of the data patterns involved in each target pattern list and remove the data patterns that only exist in part of the target pattern lists;

[0030] Principle 2: For a list of at least two target patterns joined by an AND clause, group them according to the data patterns involved, and construct an AND query statement for each data pattern;

[0031] Principle 3: For at least two target pattern lists joined by AND clauses, group them according to the relationship between the data patterns involved, and decompose the at least two target pattern lists into multiple AND query statements that are not related to each other.

[0032] According to another aspect of the present invention, a query apparatus is provided, comprising: a statement parsing module, a pattern query module, a plan determination module, and an execution module; wherein,

[0033] The statement parsing module is used to obtain the query statement, which includes at least one keyword group clause and a relational clause, and the keyword group clauses are connected by the relational clause;

[0034] The pattern query module is used to query the inverted index of the JavaScript Object Notation JSON database for each keyword clause to obtain at least one list of target patterns. The target pattern lists are connected by relational clauses, and the connection relationship between the target pattern lists is the same as the connection relationship between the keyword clauses.

[0035] The plan determination module is used to determine the target query plan based on the target pattern list;

[0036] The execution module is used to perform queries in the JSON database based on the target query plan and obtain the query results.

[0037] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:

[0038] At least one processor; and

[0039] A memory that is communicatively connected to at least one processor; wherein,

[0040] The memory stores a computer program that can be executed by at least one processor, such that the at least one processor is able to perform the query method of any embodiment of the present invention.

[0041] According to another aspect of the present invention, a computer-readable storage medium is provided, which stores computer instructions for causing a processor to execute and implement the query method of any embodiment of the present invention.

[0042] The technical solution of this invention constructs a query statement including at least one keyword clause and a relational clause. Based on each keyword clause, it retrieves at least one list of target patterns from the inverted index of a JSON database, thereby determining a target query plan. The query is then performed in the JSON database according to this plan to obtain the query results. Compared to existing query methods, the target query plan constructed based on keyword clause queries enables fuzzy queries on JSON databases. Furthermore, the query interface of this invention is independent of the specific database implementation, making it adaptable to various non-relational databases based on JSON documents. Simultaneously, by determining the data pattern through the form of the JSON document itself, it eliminates the need to write specific data query statements, thus making this invention applicable to various data patterns, achieving automatic data pattern adaptation, and exhibiting high scalability.

[0043] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description

[0044] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0045] Figure 1 This is a flowchart illustrating a query method provided in Embodiment 1 of the present invention;

[0046] Figure 2 This is a flowchart illustrating a query method provided in Embodiment 2 of the present invention;

[0047] Figure 3This is a schematic diagram of the structure of a query device provided in Embodiment 3 of the present invention;

[0048] Figure 4 This is a schematic diagram of another query device provided in Embodiment 3 of the present invention;

[0049] Figure 5 This is a schematic diagram of the structure of an electronic device provided in Embodiment 4 of the present invention. Detailed Implementation

[0050] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0051] It should be noted that the terms "first," "second," "original," "target," etc., used in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0052] Example 1

[0053] Figure 1 This is a flowchart illustrating a query method provided in Embodiment 1 of the present invention. This embodiment is applicable to querying a JSON database. The method can be executed by a query device, which can be implemented in hardware and / or software and can be configured in an electronic device (such as a computer or server). Figure 1 As shown, the method includes:

[0054] S110. Obtain the query statement, wherein the query statement includes at least one keyword clause and a relation clause, and the keyword clauses are connected by the relation clause.

[0055] A query statement is any statement constructed based on the original statement entered by the user. A query statement includes at least one keyword clause and a relational clause. Keyword clauses are connected by relational clauses, and the connected query statement can have a tree structure.

[0056] In one embodiment, each keyword clause includes at least two keywords, a query operator, and query operands; the relational clause includes an AND clause and / or an OR clause.

[0057] S120. For each keyword clause, query the inverted index of the JSON database to obtain at least one list of target patterns. The target pattern lists are connected by relational clauses, and the connection relationship between the target pattern lists is the same as the connection relationship between the keyword clauses.

[0058] JSON is a lightweight data-interchange format whose content consists of attributes and values, making it easy to read and process. Some document-based non-relational databases, such as MongoDB and CouchDB, typically choose JSON or its variants as their data storage and transmission format.

[0059] An inverted index, also known as a reverse index, is an indexing method used to store the mapping of the storage location of a word in a document or a group of documents under full-text search. It is the most commonly used data structure in document retrieval systems.

[0060] The JSON database contains multiple JSON documents (which can also be understood as JSON data), and the inverted index of the JSON database is generated based on the JSON documents in the JSON database. Specifically, the inverted index generation step can be performed before step S110, that is, the inverted index can be generated based on the JSON documents in the JSON database before the user has a query request. Therefore, in step S120, the pre-generated inverted index can be directly read to save query time.

[0061] Understandably, when the JSON database is updated, such as by deleting, modifying, or adding JSON documents, the inverted index also needs to be updated accordingly to ensure the accuracy of the query results.

[0062] Since the query statement includes at least one keyword clause, and each keyword clause is independent, in step S120, the query device needs to perform a query in the inverted index for each keyword clause to obtain the corresponding target pattern list.

[0063] Specifically, the method for obtaining the target pattern list can be found in the description of Example 2 below, and will not be repeated here for the sake of brevity.

[0064] S130. Determine the target query plan based on the target pattern list.

[0065] S140. Perform a query in the JSON database according to the target query plan and obtain the query results.

[0066] The query results can be displayed to the user in the form of a JSON document.

[0067] Thus, the target query plan constructed based on keyword clause queries can achieve fuzzy queries on JSON databases; and the query interface of this invention is independent of the specific database implementation during querying, and can be adapted to a variety of different non-relational databases based on JSON documents.

[0068] Example 2

[0069] Figure 2 This is a flowchart illustrating a query method provided in Embodiment 2 of the present invention. This embodiment provides a detailed query method based on a JSON database, building upon Embodiment 1 described above.

[0070] like Figure 2 As shown, the method includes:

[0071] S201. Determine the data schema and document mapping list for each JSON document in the JSON database, wherein the document mapping list includes the mapping relationship between each value contained in the JSON document and its query path.

[0072] A JSON database contains multiple JSON documents. The data schema of a JSON document can be determined by scanning each field within it; that is, the data schema of a JSON document is determined by each field. For example, a recursive scanning method can be used to scan each field in the JSON document.

[0073] The data schema of a JSON document defines the structure and format of the data. For a JSON document, the data schema determines the names of the fields and the data types of those fields. The data schema is generally determined by the design of the application system; different application systems often define and store data using different schemas.

[0074] For example, by scanning, we can see that JSON document 1 includes field 1 and field 2, JSON document 2 includes field 1 and field 3, and JSON document 3 includes field 1 and field 2. Therefore, we can conclude that JSON document 1 and JSON document 2 have different data patterns, JSON document 1 and JSON document 3 have the same data pattern, and JSON document 2 and JSON document 3 have different data patterns.

[0075] Typically, a JSON document includes at least one field, each field corresponding to at least one value V, and each value V corresponding to a query path P. The query path P starts from the root of the JSON document and is an ordered list of all field names that need to access the current value V. By scanning each field in the JSON document, we can obtain the value V corresponding to each field and its query path P, thus establishing a list of document correspondences.

[0076] For example, suppose JSON document 1 includes fields 1 and 2. Field 1 corresponds to values ​​V11 and V12, with query paths P11 and P12 for each value. Field 2 corresponds to values ​​V21, V22, and V23, with query paths P21, P22, and P23 for each value. The document mapping list for JSON document 1 can then be shown in Table 1.

[0077] Table 1

[0078] value Query path V11 P11 V12 P12 V21 P21 V22 P22 V23 P23

[0079] S202. Perform word segmentation on the query paths in the list of correspondences of all documents to obtain a keyword list, wherein the keyword list includes multiple keywords.

[0080] After obtaining the document mapping list for all JSON documents, the query paths in the list are segmented into keywords. Longer sentences representing query paths are divided into independent keywords, and all keywords are aggregated to obtain a keyword list. If different query paths have some identical keywords after segmentation, these identical keywords are merged in the keyword list. For example, if query path P11 is segmented into keywords 1 and 2, and query path P12 is segmented into keywords 2 and 3, then the keyword list includes keywords 1, 2, and 3.

[0081] Specifically, the word segmentation process in this invention can be based on character segmentation or can be implemented based on an existing Neuro-Linguistic Programming (NLP) word segmentation engine.

[0082] S203. Generate an inverted index based on the keyword list, the data patterns of all JSON documents, and the document correspondence list. The inverted index includes the correspondence between keywords and query paths, the JSON documents to which the query paths belong, and the data patterns.

[0083] Based on the steps S201-S202 above, an inverted index can be generated by combining the keyword list, the data patterns of all JSON documents, and the document correspondence list. The inverted index includes the correspondence between keywords and query paths, the JSON documents to which the query paths belong, and the data patterns.

[0084] In one embodiment, the query device can also associate a data pattern with a JSON document, mapping two JSON documents with the same data pattern to the same set. By querying the pattern information corresponding to the set, a set of all JSON documents with that data pattern can be obtained.

[0085] It should be noted that steps S201-S203 only need to be executed once in the entire process. That is, an inverted index can be generated based on the JSON document in the JSON database before the user has a query request. So that every time the user has a query request in the future, the pre-generated inverted index can be read directly to save query time.

[0086] Of course, when the JSON database is updated, such as by deleting, modifying, or adding JSON documents, the inverted index also needs to be updated accordingly to ensure the accuracy of the query results.

[0087] S204. Receive the original statement input by the user.

[0088] The original query is the query command entered by the user, such as "employee's name and start date" or "owner's house number or parking space number".

[0089] S205. Parse the original statement to obtain keyword clauses and relational clauses. Each keyword clause includes at least two keywords, query operators, and query operands. The relational clauses include AND clauses and / or OR clauses.

[0090] In one embodiment, the categories of query operators and query operands are determined based on the implementation details of the selected NoSQL database. Query operators and query operands at least support: equal to, not equal to, contain, not contain, prefix, and suffix operations for strings; and greater than, less than, equal to, greater than or equal to, and less than or equal to operations for numbers.

[0091] Each AND clause can connect any number of keyword clauses, and the query result of the AND clause is the intersection of the results of all its clauses.

[0092] Each OR clause can connect any number of keyword clauses, and the query result of the OR clause is the union of the results of all its clauses.

[0093] For example, the original statement "employee's name and start date" will be parsed to obtain two keyword clauses: "employee's name" and "employee's start date," as well as an AND clause, with each keyword clause containing two keywords. As another example, the original statement "owner's house number or parking space number" will be parsed to obtain two keyword clauses: "owner's house number" and "owner's parking space number," as well as an OR clause, with each keyword clause containing two keywords.

[0094] It should also be noted that the steps of collecting, storing, using, and processing information (such as identity information) in this invention all comply with the relevant provisions of national laws and regulations.

[0095] S206. Generate a query statement by connecting keyword group clauses through relational clauses.

[0096] Typically, the query statement after joining can be in a tree structure.

[0097] Thus, by parsing the original statement to obtain keyword clauses and relational clauses, and generating query statements, the user's query instructions can be transformed into a structured object representation that is easy for the program to process, thereby enabling fuzzy queries on the JSON database.

[0098] S207. Match at least two keywords included in the keyword phrase clause in the inverted index to obtain the original pattern list.

[0099] S208. Filter the original pattern list according to the constraints to obtain the target pattern list.

[0100] The constraints include the first constraint subcondition and the second constraint subcondition.

[0101] Specifically, the first constraint sub-condition is to match a non-overlapping segment on the query path for each keyword, and this segment includes all keywords in the keyword group clause; the second constraint sub-condition is that the path segments matched between different keywords satisfy the order of the keywords in the keyword group clause.

[0102] Combining steps S207-S208, since the query statement includes N keyword clauses, where N is an integer greater than or equal to 2, each keyword clause needs to be queried in the inverted index to obtain the corresponding list of target patterns. Therefore, steps S207-S208 need to be executed N times.

[0103] First, the inverted index is used to match at least two keywords included in the keyword clause to obtain the original pattern list, which includes at least two keywords included in the keyword clause. Then, the original pattern list is filtered according to the first and second constraints in turn, and patterns that do not meet the first and second constraints are removed to obtain the target pattern list.

[0104] S209. Construct the original query plan based on the target pattern list, query operators, and query operands.

[0105] After obtaining the list of target patterns corresponding to all keyword clauses, the keyword clauses are first replaced with a list of query paths corresponding to the data patterns. The target pattern lists are connected by relational clauses, and the connection relationships between the target pattern lists are the same as those between the keyword clauses. Secondly, based on the query syntax of the JSON database, the original query plan is constructed according to the query operators and query operands.

[0106] S210. Optimize the original query plan to obtain the target query plan.

[0107] To improve query efficiency, the original query plan can be optimized to obtain the target query plan.

[0108] Specifically, the original query plan can be optimized based on principles 1 and 2, or principles 1 and 3:

[0109] Principle 1: For at least two target pattern lists joined by an AND clause, take the intersection of the data patterns involved in each target pattern list and remove the data patterns that only exist in part of the target pattern list.

[0110] Since each JSON document belongs to only a specific data schema, and the AND clause requires that the document meets the conditions under all clauses, only documents in the schema that are involved in every query meet the query conditions.

[0111] Principle 2: For a list of at least two target patterns joined by an AND clause, group them according to the data patterns involved, and construct an AND query statement for each data pattern.

[0112] Principle 3: For at least two target pattern lists joined by AND clauses, group them according to the relationship between the data patterns involved, and decompose the at least two target pattern lists into multiple AND query statements that are not related to each other.

[0113] "Association" refers to the existence of the same query path between two data schemas; if there is no same query path between two data schemas, then there is no association between the two data schemas.

[0114] Multiple AND queries in principles 2 and 3 can be executed in parallel, and the results can then be summarized.

[0115] Principles 2 and 3 above take into account the concurrent query characteristics of databases, breaking down a single query into multiple concurrent queries to improve the execution speed of a single query. Since principles 2 and 3 involve decomposing similar AND query statements, they cannot be applied simultaneously; only one can be chosen.

[0116] S211. Perform a query in the JSON database according to the target query plan and obtain the query results.

[0117] For performance reasons, JSON databases should support path-value indexing. The JSON documents to be queried should be pre-stored in the database as is, and a path-value index should be created, allowing the program to execute multiple queries using the form <path, operator, operands>. The query results are obtained by intersecting and unifying the result sets according to the AND and OR relationships between the queries, and the results can be displayed to the user as JSON documents.

[0118] This invention provides a query method, comprising: obtaining a query statement, wherein the query statement includes at least one keyword clause and a relational clause, and the keyword clauses are connected by relational clauses; querying the inverted index of a JavaScript object notation JSON database based on each keyword clause to obtain at least one target pattern list, wherein the target pattern lists are connected by relational clauses, and the connection relationship between the target pattern lists is the same as the connection relationship between the keyword clauses; determining a target query plan based on the target pattern list; and querying the JSON database according to the target query plan to obtain query results. By constructing a query statement including at least one keyword clause and a relational clause, and then querying the inverted index of the JSON database based on each keyword clause to obtain at least one target pattern list, a target query plan is determined, and a query is performed in the JSON database according to the target query plan to obtain query results. Compared with existing query methods, the target query plan constructed based on keyword clause queries can achieve fuzzy queries on JSON databases. Furthermore, the query interface of this invention is independent of the specific database implementation during querying, and can be adapted to various non-relational databases based on JSON documents. At the same time, the data pattern is determined by the form of the JSON document itself, eliminating the need to write specific data query statements. Thus, this invention is applicable to various data patterns, achieves automatic data pattern adaptation, and has high scalability.

[0119] Example 3

[0120] Figure 3 This is a schematic diagram of the structure of a query device provided in Embodiment 3 of the present invention. Figure 3 As shown, the device includes: a statement parsing module 301, a pattern query module 302, a plan determination module 303, and an execution module 304.

[0121] The statement parsing module 301 is used to obtain the query statement, wherein the query statement includes at least one keyword group clause and a relational clause, and the keyword group clauses are connected by the relational clause;

[0122] The pattern query module 302 is used to query the inverted index of the JavaScript Object Notation JSON database according to each keyword group clause to obtain at least one target pattern list, wherein the target pattern lists are connected by relation clauses and the connection relationship between the target pattern lists is the same as the connection relationship between the keyword group clauses;

[0123] The plan determination module 303 is used to determine the target query plan based on the target pattern list;

[0124] Execution module 304 is used to perform a query in the JSON database based on the target query plan and obtain the query results.

[0125] Optionally, the JSON database includes multiple JSON documents. Combined Figure 3 , Figure 4 This is a schematic diagram of another query device provided in Embodiment 3 of the present invention. Figure 4 As shown, it also includes: an index generation module 305.

[0126] The index generation module 305 is used to determine the data pattern and document correspondence list of each JSON document before the statement parsing module 301 obtains the query statement. The document correspondence list includes the correspondence between each value contained in the JSON document and its query path. The query paths in all document correspondence lists are segmented to obtain a keyword list, which includes multiple keywords. Based on the keyword list, the data pattern and document correspondence list of all JSON documents, an inverted index is generated. The inverted index includes the correspondence between keywords and query paths, the JSON documents to which the query paths belong, and the data pattern.

[0127] Optionally, the statement parsing module 301 is specifically used to receive the original statement input by the user; parse the original statement to obtain keyword group clauses and relational clauses, wherein each keyword group clause includes at least two keywords, query operators and query operands, and the relational clauses include AND clauses and / or OR clauses; and connect the keyword group clauses through the relational clauses to generate a query statement.

[0128] Optional, for any keyword phrase clause;

[0129] The pattern query module 302 is specifically used to match at least two keywords included in the keyword group clause in the inverted index to obtain the original pattern list; and to filter the original pattern list according to the constraints to obtain the target pattern list.

[0130] Optionally, the constraints include a first constraint sub-condition and a second constraint sub-condition; wherein,

[0131] The first constraint subcondition matches a non-overlapping segment of the query path for each keyword, and this segment includes all keywords in the keyword group clause;

[0132] The second constraint subcondition is that the path segments matched between different keywords satisfy the order of the keywords in the keyword group clause.

[0133] Optionally, the plan determination module 303 is specifically used to construct an original query plan based on the target pattern list, query operators, and query operands; and to optimize the original query plan to obtain the target query plan.

[0134] Optionally, the original query plan can be optimized based on principles 1 and 2, or on principles 1 and 3:

[0135] Principle 1: For at least two target pattern lists joined by an AND clause, take the intersection of the data patterns involved in each target pattern list and remove the data patterns that only exist in part of the target pattern lists;

[0136] Principle 2: For a list of at least two target patterns joined by an AND clause, group them according to the data patterns involved, and construct an AND query statement for each data pattern;

[0137] Principle 3: For at least two target pattern lists joined by AND clauses, group them according to the relationship between the data patterns involved, and decompose the at least two target pattern lists into multiple AND query statements that are not related to each other.

[0138] The query device provided in the embodiments of the present invention can execute the query method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0139] Example 4

[0140] Figure 5 A schematic diagram of an electronic device 10 that can be used to implement embodiments of the present invention is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.

[0141] like Figure 5As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 may also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.

[0142] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0143] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as the polling method.

[0144] In some embodiments, the query method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the query method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to execute the query method by any other suitable means (e.g., by means of firmware).

[0145] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0146] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0147] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.

[0148] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0149] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or computing systems that include middleware components (e.g., application servers), or computing systems that include frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.

[0150] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.

[0151] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.

[0152] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

Claims

1. A query method, characterized in that, include: Obtain a query statement, wherein the query statement includes at least one keyword group clause and a relational clause, the keyword group clauses are connected by the relational clause, each keyword group clause includes at least two keywords, a query operator and a query operand, and the relational clause includes an AND clause and / or an OR clause; For each of the keyword group clauses, a query is performed in the inverted index of the JavaScript Object Notation JSON database to obtain at least one list of target patterns, wherein the lists of target patterns are connected by the relation clauses and the connection relationship between the lists of target patterns is the same as the connection relationship between the keyword group clauses; Construct the original query plan based on the target pattern list, the query operator, and the query operand; The original query plan is optimized to obtain the target query plan, wherein the original query plan is optimized according to principles 1 and 2, or according to principles 1 and 3: Principle 1: For at least two target pattern lists connected by AND clauses, the intersection of the data patterns involved in each target pattern list is taken, and the data patterns that only exist in some of the target pattern lists are removed; Principle 2: For at least two target pattern lists connected by AND clauses, they are grouped according to the data patterns involved, and an AND query statement is constructed for each data pattern; Principle 3: For at least two target pattern lists connected by AND clauses, they are grouped according to the association relationship of the data patterns involved, and the at least two target pattern lists are decomposed into multiple AND query statements that are not related to each other; The query is performed in the JSON database according to the target query plan, and the query results are obtained.

2. The method according to claim 1, characterized in that, The JSON database includes multiple JSON documents; before retrieving the query statement, it also includes: Determine the data schema and document correspondence list for each of the JSON documents, wherein the document correspondence list includes the correspondence between each value contained in the JSON document and its query path; The query paths in all the document correspondence lists are segmented to obtain a keyword list, wherein the keyword list includes multiple keywords; The inverted index is generated based on the keyword list, the data patterns of all the JSON documents, and the document correspondence list. The inverted index includes the correspondence between keywords and query paths, the JSON documents to which the query paths belong, and the data patterns.

3. The method according to claim 2, characterized in that, The process of obtaining the query statement includes: Receive the user's original input statement; The original statement is parsed to obtain the keyword phrase clause and the relational clause; The query statement is generated by connecting the keyword group clauses through the relational clauses.

4. The method according to claim 3, characterized in that, For any of the aforementioned keyword phrases; the step of querying the inverted index of the JSON database based on the keyword phrases to obtain a list of target patterns, including: In the inverted index, at least two keywords included in the keyword group clause are matched to obtain the original pattern list; The original pattern list is filtered according to the constraints to obtain the target pattern list.

5. The method according to claim 4, characterized in that, The constraints include a first constraint sub-condition and a second constraint sub-condition; wherein... The first constraint sub-condition matches a non-overlapping segment on the query path for each keyword, and this segment includes all keywords within the keyword group clause; The second constraint sub-condition is that the path segments matched between different keywords satisfy the order of the keywords in the keyword group clause.

6. A query device, characterized in that, include: The module consists of a statement parsing module, a pattern query module, a plan determination module, and an execution module; among them, The statement parsing module is used to obtain a query statement, wherein the query statement includes at least one keyword group clause and a relational clause, the keyword group clauses are connected by the relational clauses, each keyword group clause includes at least two keywords, a query operator and a query operand, and the relational clause includes an AND clause and / or an OR clause; The pattern query module is used to query the inverted index of the JavaScript Object Notation JSON database according to each keyword group clause to obtain at least one target pattern list, wherein the target pattern lists are connected by the relation clauses, and the connection relationship between the target pattern lists is the same as the connection relationship between the keyword group clauses; The plan determination module is used to construct an original query plan based on the target pattern list, the query operator, and the query operands; and to optimize the original query plan to obtain a target query plan. The original query plan is optimized according to principles 1 and 2, or principles 1 and 3: Principle 1: For at least two target pattern lists connected by AND clauses, the intersection of the data patterns involved in each target pattern list is taken, and data patterns that only exist in a portion of the target pattern lists are removed; Principle 2: For at least two target pattern lists connected by AND clauses, they are grouped according to the data patterns involved, and an AND query statement is constructed for each data pattern; Principle 3: For at least two target pattern lists connected by AND clauses, they are grouped according to the association relationship of the data patterns involved, and the at least two target pattern lists are decomposed into multiple AND query statements that are not related to each other. The execution module is used to perform a query in the JSON database according to the target query plan and obtain the query results.

7. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the query method according to any one of claims 1-5.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the query method according to any one of claims 1-5.