A data query method, device, equipment and storage medium
By receiving and analyzing query statements in the data query system, automatically determine the target database and generate query statements, solve the problem of high complexity of a large data library, and achieve efficient data query.
Patent Information
- Application Number
- CN202210692189.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-17
- Publication Date
- 2025-01-21
- Estimated Expiration
- 2042-06-17
AI Technical Summary
When queries data between multiple different types of databases, the prior art requires users to write different query statements according to different data models, resulting in high query complexity and low efficiency.
By receiving the query statement for the first database, based on the matching of the attributes to be queried and the auxiliary query attributes, the target database is determined from the plurality of second databases, and a query statement associated with each target database is generated. Then, according to the query cost of each query statement, the target query statement is selected and sent to the corresponding database to obtain the query results.
It reduces the complexity of data query and improves query efficiency. Users only need to write a query statement once, and the system automatically generates query statements suitable for different databases.
Smart Images

Figure CN115062044B_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present invention relate to the field of big data technology, and in particular to a data query method, device, equipment and storage medium. Background Art
[0002] With the development of enterprise digitalization, more and more business data is generated for different businesses. However, when business data is stored in different databases, the corresponding data models are also different. For example, when the data source is stored in a relational database, the corresponding data model is a two-dimensional table model; when the data source is stored in a key-value database, the corresponding data model is a KV model; when the data source is stored in a document-oriented database, the corresponding data model is a full-text retrieval model.
[0003] In the related art, when performing data query, the user writes a corresponding type of query statement for the data model corresponding to the database to be queried, however, the query costs of different databases are different, which may result in selecting a database with a higher query cost for query. Moreover, for the data models corresponding to different databases, it is necessary to write a corresponding type of query statement, which increases the complexity of data query and leads to low query efficiency. Summary of the invention
[0004] The embodiments of the present application provide a data query method, apparatus, device and storage medium for reducing the complexity of data query and improving query efficiency.
[0005] On the one hand, an embodiment of the present application provides a data query method, the method comprising:
[0006] receiving a first query statement for a first database, wherein the first query statement includes a to-be-queried attribute and an auxiliary query attribute associated with an auxiliary query content;
[0007] Based on the matching of the attribute to be queried and the auxiliary query attribute, determining a target database from a plurality of second databases, and generating a second query statement associated with each target database;
[0008] Selecting a target query statement from the first query statement and the second query statements based on the query cost of the first query statement and the query costs of the second query statements;
[0009] The target query statement is sent to a corresponding database, and a data query result returned by the corresponding database is obtained.
[0010] Optionally, determining a target database from a plurality of second databases based on a matching condition between the attribute to be queried and the auxiliary query attribute, and generating a second query statement associated with each target database, comprises:
[0011] For each second database, if the second database matches the attribute to be queried and the auxiliary query attribute, the second database is used as a target database, and a target data table containing the attribute to be queried and the auxiliary query attribute is determined from a plurality of second data tables in the target database;
[0012] A second query statement for the target database is generated based on the identifier of the target data table, the attribute to be queried and the auxiliary query attribute.
[0013] Optionally, the query cost of the second query statement is determined by the target database based on the attribute to be queried and the auxiliary query attribute.
[0014] Optionally, it also includes:
[0015] If the second database matches the auxiliary query attribute and does not match the attribute to be queried, the second database is used as a target database, and a target data table containing the auxiliary query attribute is obtained from a plurality of second data tables in the target database;
[0016] Based on the identifier of the target data table and the auxiliary query attribute, a sub-query statement for the target database associated with the auxiliary query attribute is generated, and a sub-query statement associated with the attribute to be queried is obtained from the first query statement;
[0017] The second query statement is generated based on the sub-query statement associated with the auxiliary query attribute and the sub-query statement associated with the attribute to be queried.
[0018] Optionally, before selecting a target query statement from the first query statement and the second query statements based on the query cost of the first query statement and the query costs of the second query statements, the method further includes:
[0019] receiving a subquery cost of the attribute to be queried sent by the first database, and receiving a subquery cost of the auxiliary query attribute sent by the target database;
[0020] The query cost of the second query statement is determined based on the sub-query cost of the attribute to be queried and the sub-query cost of the auxiliary query attribute.
[0021] Optionally, the selecting a target query statement from the first query statement and each second query statement based on the query cost of the first query statement and the query costs of each second query statement includes:
[0022] The query cost of the first query statement and the query statement with the smallest corresponding query cost among the second query statements are used as the target query statement.
[0023] Optionally, the first database includes a first data table, and the first data table includes the attribute to be queried and the auxiliary query attribute;
[0024] Before receiving the first query statement for the first database, the method further includes:
[0025] receiving a first table creation statement for the first database;
[0026] If the first table creation statement includes a full-text search statement, generating a second table creation statement for the first database and at least one third table creation statement for each second database according to the first table creation statement and the full-text search statement;
[0027] Sending the second table creation statement to the first database to trigger the first database to create the first data table;
[0028] For each second database, at least one corresponding third table creation statement is sent to the second database, triggering the second database to build at least one second data table.
[0029] Optionally, if the first table creation statement includes a full-text search statement, generating a second table creation statement for the first database and at least one third table creation statement for each second database according to the first table creation statement and the full-text search statement, including:
[0030] If the first table creation statement includes a full-text search statement, determining at least one index attribute based on the full-text search statement;
[0031] Obtaining an identifier of a first data table and at least one query attribute from the first table creation statement;
[0032] Generate a second table creation statement based on the identifier of the first data table, at least one query attribute, and a virtual attribute;
[0033] At least one third table creation statement is generated based on the at least one index attribute and the virtual attribute.
[0034] Optionally, it also includes:
[0035] Loading the to-be-stored data corresponding to the at least one query attribute into the first data table;
[0036] Generate a unique identifier corresponding to the virtual attribute in the first data table;
[0037] For each second data table, the data to be stored corresponding to the corresponding index attribute and the unique identifier corresponding to the virtual attribute are loaded into the second data table.
[0038] On the one hand, an embodiment of the present application provides a data query device, the device comprising:
[0039] A receiving module, configured to receive a first query statement for a first database, wherein the first query statement includes an attribute to be queried and an auxiliary query attribute associated with auxiliary query content;
[0040] An acquisition module, configured to determine a target database from a plurality of second databases based on a match between the attribute to be queried and the auxiliary query attribute, and to generate a second query statement associated with each target database;
[0041] A comparison module, configured to select a target query statement from the first query statement and each second query statement based on the query cost of the first query statement and the query costs of each second query statement;
[0042] The sending module is used to send the target query statement to the corresponding database and obtain the data query result returned by the corresponding database.
[0043] Optionally, the acquisition module is specifically used for:
[0044] For each second database, if the second database matches the attribute to be queried and the auxiliary query attribute, the second database is used as a target database, and a target data table containing the attribute to be queried and the auxiliary query attribute is determined from a plurality of second data tables in the target database;
[0045] A second query statement for the target database is generated based on the identifier of the target data table, the attribute to be queried and the auxiliary query attribute.
[0046] Optionally, the query cost of the second query statement is determined by the target database based on the attribute to be queried and the auxiliary query attribute.
[0047] Optionally, the acquisition module is further used to:
[0048] If the second database matches the auxiliary query attribute and does not match the attribute to be queried, the second database is used as a target database, and a target data table containing the auxiliary query attribute is obtained from a plurality of second data tables in the target database;
[0049] Based on the identifier of the target data table and the auxiliary query attribute, a sub-query statement for the target database associated with the auxiliary query attribute is generated, and a sub-query statement associated with the attribute to be queried is obtained from the first query statement;
[0050] The second query statement is generated based on the sub-query statement associated with the auxiliary query attribute and the sub-query statement associated with the attribute to be queried.
[0051] Optionally, the receiving module is further used for:
[0052] The query cost based on the first query statement and the query costs of each second query statement, before selecting a target query statement from the first query statement and each second query statement, receiving a sub-query cost of the attribute to be queried sent by the first database, and receiving a sub-query cost of the auxiliary query attribute sent by the target database;
[0053] The query cost of the second query statement is determined based on the sub-query cost of the attribute to be queried and the sub-query cost of the auxiliary query attribute.
[0054] Optionally, the comparison module is specifically used for:
[0055] The query cost of the first query statement and the query statement with the smallest corresponding query cost among the second query statements are used as the target query statement.
[0056] Optionally, the first database includes a first data table, and the first data table includes the attribute to be queried and the auxiliary query attribute;
[0057] It also includes a table building module, which is specifically used for:
[0058] Before receiving the first query statement for the first database, receiving a first table creation statement for the first database;
[0059] If the first table creation statement includes a full-text search statement, generating a second table creation statement for the first database and at least one third table creation statement for each second database according to the first table creation statement and the full-text search statement;
[0060] Sending the second table creation statement to the first database to trigger the first database to create the first data table;
[0061] For each second database, at least one corresponding third table creation statement is sent to the second database, triggering the second database to build at least one second data table.
[0062] Optionally, the table building module is specifically used for:
[0063] If the first table creation statement includes a full-text search statement, determining at least one index attribute based on the full-text search statement;
[0064] Obtaining an identifier of a first data table and at least one query attribute from the first table creation statement;
[0065] Generate a second table creation statement based on the identifier of the first data table, at least one query attribute, and a virtual attribute;
[0066] At least one third table creation statement is generated based on the at least one index attribute and the virtual attribute.
[0067] Optionally, an insertion module is further included, and the insertion module is specifically used for:
[0068] Loading the to-be-stored data corresponding to the at least one query attribute into the first data table;
[0069] Generate a unique identifier corresponding to the virtual attribute in the first data table;
[0070] For each second data table, the data to be stored corresponding to the corresponding index attribute and the unique identifier corresponding to the virtual attribute are loaded into the second data table.
[0071] On the one hand, an embodiment of the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned data query method when executing the program.
[0072] On the one hand, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program executable by a computer device. When the program is run on the computer device, the computer device executes the steps of the above-mentioned data query method.
[0073] In an embodiment of the present application, a first query statement for a first database is received, wherein the first query statement includes an attribute to be queried and an auxiliary query attribute associated with auxiliary query content. Based on the matching of the attribute to be queried and the auxiliary query attribute, a target database is determined from multiple second databases, and a second query statement associated with each target database is generated. Then, based on the query cost of the first query statement and the query cost of each second query statement, a target query statement is selected from the first query statement and each second query statement. Finally, the target query statement is sent to the corresponding database, and the data query result returned by the corresponding database is obtained. Since the user only needs to write the first query statement for the first database, and the second query statement for the second database is automatically generated by the data query system, the complexity of the data query is reduced. At the same time, since the target query statement is determined based on the query cost of the first query statement and the query cost of each second query statement, the query efficiency can be effectively improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0074] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0075] Figure 1 A schematic diagram of a system architecture provided for an embodiment of the present application;
[0076] Figure 2 A flowchart of a data query method provided in an embodiment of the present application;
[0077] Figure 3 A flowchart of a table creation method provided in an embodiment of the present application;
[0078] Figure 4 A schematic diagram of a data query process provided by an embodiment of the present application;
[0079] Figure 5 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0080] In order to make the purpose, technical solution and beneficial effects of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0081] refer to Figure 1, which is a system architecture diagram applicable to an embodiment of the present application, and the system architecture diagram at least includes a terminal device 101 and a data query system 102.
[0082] The terminal device 101 is installed with a target application for data query, which may be a pre-installed client, a web application, or a small program embedded in other applications, etc. The terminal device 101 may be a smart phone, a tablet computer, a laptop computer, a desktop computer, etc., but is not limited thereto.
[0083] The data query system 102 is the backend server of the target application and provides services for the target application. The data query system 102 can be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), and big data and artificial intelligence platforms.
[0084] The terminal device 101 and the data query system 102 may be connected directly or indirectly via wired or wireless communication, which is not limited in the present application.
[0085] The terminal device 101 responds to the user's data query operation and sends a data query instruction to the data query system 102. The data query system 102 receives a first query statement for a first database, wherein the first query statement includes an attribute to be queried and an auxiliary query attribute associated with auxiliary query content; based on the matching of the attribute to be queried and the auxiliary query attribute, a target database is determined from a plurality of second databases, and a second query statement associated with each target database is generated; based on the query cost of the first query statement and the query costs of each second query statement, a target query statement is selected from the first query statement and each second query statement; the target query statement is sent to the corresponding database, and a data query result returned by the corresponding database is obtained.
[0086] based on Figure 1 The system architecture diagram, the embodiment of the present application provides a process of a data query method, such as Figure 2 As shown, the process of this method is Figure 1 The data query system 102 shown in the figure performs the following steps:
[0087] Step S201: receiving a first query statement for a first database.
[0088] Among them, the first database can be a relational database, such as MySQL, Oracle, etc.; it can also be a key-value database, such as Redis database, etc.; it can also be a document-oriented database, such as ElasticSearch database, Solar data, etc.
[0089] The first query statement is written according to the data model corresponding to the first database. The first query statement includes the identifier of the first data table, the attribute to be queried, and the auxiliary query attribute associated with the auxiliary query content. The first data table includes multiple query attributes and multiple user information. Each user information includes data corresponding to multiple query attributes.
[0090] For example, as shown in Table 1, the first data table is a user information table, and the first data table includes three query attributes, namely name, age and address. The user information table includes three pieces of user information, the first piece of user information includes Zhang San, 23, Shenzhen, the second piece of user information includes Li Si, 24, Shanghai, and the third piece of user information includes Wang Wu, 26, Shanghai Pudong New Area.
[0091] Table 1.
[0092] Name age address Zhang San 23 Shenzhen Li Si 24 Shanghai Wang Wu 26 Shanghai Pudong New Area
[0093] If the attribute to be queried is name, the auxiliary query attribute is address, and the auxiliary query attribute associated with the auxiliary query content is the address containing "Shanghai", the first query statement is used to query the name containing "Shanghai" in the address from the user information table, and the result is shown in Table 2.
[0094] Table 2.
[0095] Name Li Si Wang Wu
[0096] Step S202: determining a target database from a plurality of second databases based on the matching of the to-be-queried attribute and the auxiliary query attribute, and generating a second query statement associated with each target database.
[0097] Specifically, when the first database is a relational database, the second database may be a key-value database or a document-oriented database. The second query statement is written according to a data model corresponding to the second database.
[0098] The metadata information in the data query system includes first data table information corresponding to the first data table in the first database, and second data table information corresponding to each second data table in the second database. According to the matching of multiple second data table information in each second database with the attributes to be queried and the auxiliary query attributes, the target database is determined from the multiple second databases.
[0099] Generating a second query statement associated with each target database includes the following two possible implementations:
[0100] In a possible implementation, all second data tables in the target database are determined, and a second query statement associated with each second data table is generated.
[0101] Another possible implementation manner is to determine some second data tables in the target database, and generate an associated second query statement for each second data table.
[0102] Step S203 : selecting a target query statement from the first query statement and each of the second query statements based on the query cost of the first query statement and the query costs of each of the second query statements.
[0103] Specifically, the query cost may represent the time spent on the query. The query cost of the first query statement and the query statement with the smallest corresponding query cost among the second query statements are used as the target query statement.
[0104] Step S204, sending the target query statement to the corresponding database, and obtaining the data query result returned by the corresponding database.
[0105] In an embodiment of the present application, a first query statement for a first database is received, wherein the first query statement includes an attribute to be queried and an auxiliary query attribute associated with auxiliary query content. Based on the matching of the attribute to be queried and the auxiliary query attribute, a target database is determined from multiple second databases, and a second query statement associated with each target database is generated. Then, based on the query cost of the first query statement and the query cost of each second query statement, a target query statement is selected from the first query statement and each second query statement. Finally, the target query statement is sent to the corresponding database, and the data query result returned by the corresponding database is obtained. Since the user only needs to write the first query statement for the first database, and the second query statement for the second database is automatically generated by the data query system, the complexity of the data query is reduced. At the same time, since the target query statement is determined based on the query cost of the first query statement and the query cost of each second query statement, the query efficiency can be effectively improved.
[0106] Optionally, in the above step S202, for each second database, the following two possible implementations are performed:
[0107] A first possible implementation method is that if the second database matches the attribute to be queried and the auxiliary query attribute, the second database is used as the target database, and a target data table containing the attribute to be queried and the auxiliary query attribute is determined from multiple second data tables in the target database; based on the identifier of the target data table, the attribute to be queried and the auxiliary query attribute, a second query statement for the target database is generated.
[0108] For example, the target database is a document-oriented database, and two second data tables are stored in the target database, namely index table 1 and index table 2. Index table 1 is shown in Table 3, and index table 1 includes two query attributes, namely name and address.
[0109] Table 3.
[0110] Name address Zhang San Shenzhen Li Si Shanghai Wang Wu Shanghai Pudong New Area
[0111] Index table 2 is shown in Table 4. Index table 2 includes one query attribute, namely, address.
[0112] Table 4.
[0113] address Shenzhen Shanghai Shanghai Pudong New Area
[0114] When the attribute to be queried is name and the auxiliary query attribute is address, since index table 1 contains name and address, and index table 2 only contains address, index table 1 is determined to be the target data table. Then, based on the identifier, name and address of index table 1, a second query statement for the target database is generated.
[0115] In the embodiment of the present application, the second query statement is only related to the target database, which can effectively improve the query efficiency.
[0116] A second possible implementation method is that if the second database matches the auxiliary query attribute and does not match the attribute to be queried, the second database is used as the target database, and a target data table containing the auxiliary query attribute is obtained from multiple second data tables in the target database; based on the identifier of the target data table and the auxiliary query attribute, a sub-query statement for the target database associated with the auxiliary query attribute is generated, and a sub-query statement associated with the attribute to be queried is obtained from the first query statement; based on the sub-query statement associated with the auxiliary query attribute and the sub-query statement associated with the attribute to be queried, a second query statement is generated.
[0117] For example, the first database is a relational database, and the target database is a document-oriented database. The first database stores a first data table, as shown in Table 1. The target database stores two second data tables, namely, index table 1 and index table 2. Index table 1 is shown in Table 3, and index table 1 includes two query attributes, namely, name and address. Index table 2 is shown in Table 4, and index table 2 includes one query attribute, namely, address.
[0118] When the attribute to be queried is age and the auxiliary query attribute is address, since index table 1 only contains address but not age, and index table 2 only contains address but not age, both index table 1 and index table 2 meet the requirements, and index table 2 is randomly selected as the target data table.
[0119] Generate a subquery statement for the target database based on the identifier and address of index table 2. Generate a subquery statement for the first database based on the identifier and name of the first data table. Combine the subquery statement for the target database with the subquery statement for the first database as the second query statement.
[0120] In the embodiment of the present application, the second query statement is not only related to the target database, but also related to the first database, which can increase the query diversity.
[0121] Optionally, in the above step S203, determining the query cost of the second query statement includes the following two possible implementations:
[0122] Implementation method 1: When the second database matches the attribute to be queried and the auxiliary query attribute, the target database determines the query cost of the second query statement based on the attribute to be queried and the auxiliary query attribute.
[0123] Implementation method 2: When the second database matches the auxiliary query attribute but does not match the attribute to be queried, receive the subquery cost of the attribute to be queried sent by the first database, and receive the subquery cost of the auxiliary query attribute sent by the target database; based on the subquery cost of the attribute to be queried and the subquery cost of the auxiliary query attribute, determine the query cost of the second query statement.
[0124] Optionally, before the above step S201, in order to construct the first data table and the second data table, the following steps are performed: Figure 3 The following steps are shown:
[0125] Step S301: receiving a first table creation statement for a first database.
[0126] Step S302, determining whether the first table creation statement contains a full-text search statement, if not, executing step S303; otherwise, executing step S304.
[0127] Specifically, the full-text search statement includes multiple situations. The full-text search statement includes only the combined index, or only the individual index, or both the combined index and the individual index.
[0128] Joint search corresponds to multiple index attributes, and separate search corresponds to one index attribute.
[0129] Step S303: Send the first table creation statement to the first database, triggering the first database to build a first data table.
[0130] At the same time, first data table information corresponding to the first data table sent by the first database is received and stored in the metadata information.
[0131] Step S304: Generate a second table creation statement for the first database and at least one third table creation statement for each second database according to the first table creation statement and the full-text search statement.
[0132] Specifically, at least one index attribute is determined based on the full-text search statement; an identifier of the first data table and at least one query attribute are obtained from the first table creation statement; a second table creation statement is generated based on the identifier of the first data table, at least one query attribute and a virtual attribute; and at least one third table creation statement is generated based on at least one index attribute and a virtual attribute.
[0133] Step S305: Send the second table creation statement to the first database, triggering the first database to build a first data table.
[0134] At the same time, first data table information corresponding to the first data table sent by the first database is received and stored in the metadata information.
[0135] Step S306: for each second database, send the corresponding at least one third table creation statement to the second database, triggering the second database to build at least one second data table.
[0136] At the same time, second data table information corresponding to the second data table sent by each second database is received and saved in the metadata information. The virtual attribute is used to characterize the relationship between the first data table and at least one second data table. The first data table and at least one second data table can be associated according to the virtual attribute.
[0137] After the first data table and the second data table are constructed, inserting data into the first data table and inserting data into the second data table includes the following steps:
[0138] The data to be stored corresponding to at least one query attribute are loaded into the first data table, and a unique identifier corresponding to the virtual attribute in the first data table is generated. Then, for each second data table, the data to be stored corresponding to the corresponding index attribute and the unique identifier corresponding to the virtual attribute are loaded into the second data table.
[0139] Specifically, through the submission interface, the data to be stored corresponding to at least one query attribute is sent to the first database and loaded into the first data table by the first database. Through the withdrawal interface, the data to be stored corresponding to at least one query attribute can be avoided from being sent to the first database.
[0140] Through the submission interface, the data to be stored corresponding to the corresponding index attribute and the unique identifier corresponding to the virtual attribute are sent to the second database, and loaded into the second data table by the second database. Through the withdrawal interface, the data to be stored corresponding to the corresponding index attribute and the unique identifier corresponding to the virtual attribute can be avoided from being sent to the second database.
[0141] In the present application, the submission interface and the withdrawal interface can effectively ensure the consistency of the data to be stored corresponding to the same attributes stored in the first database and the second database.
[0142] After data is inserted into the first data table and data is inserted into the second data table, data updating and data deletion operations may be performed on the first data table or the second data table, which will not be described in detail here.
[0143] In an embodiment of the present application, when the first table creation statement contains a full-text search statement, the data query system generates a second table creation statement for the first database and at least one third table creation statement for each second database based on the first table creation statement and the full-text search statement, rather than the user writing the second table creation statement and the third table creation statement, which can effectively reduce the complexity of table creation.
[0144] Based on the same technical concept, the present application embodiment provides a data query device, such as Figure 4 As shown, the data query device 400 includes:
[0145] A receiving module 401 is configured to receive a first query statement for a first database, wherein the first query statement includes a to-be-queried attribute and an auxiliary query attribute associated with an auxiliary query content;
[0146] An acquisition module 402 is used to determine a target database from a plurality of second databases based on a matching condition between the attribute to be queried and the auxiliary query attribute, and to generate a second query statement associated with each target database;
[0147] A comparison module 403, configured to select a target query statement from the first query statement and each second query statement based on the query cost of the first query statement and the query costs of each second query statement;
[0148] The sending module 404 is used to send the target query statement to the corresponding database and obtain the data query result returned by the corresponding database.
[0149] Optionally, the acquisition module 402 is specifically used for:
[0150] For each second database, if the second database matches the attribute to be queried and the auxiliary query attribute, the second database is used as a target database, and a target data table containing the attribute to be queried and the auxiliary query attribute is determined from a plurality of second data tables in the target database;
[0151] A second query statement for the target database is generated based on the identifier of the target data table, the attribute to be queried and the auxiliary query attribute.
[0152] Optionally, the query cost of the second query statement is determined by the target database based on the attribute to be queried and the auxiliary query attribute.
[0153] Optionally, the acquisition module 402 is further used to:
[0154] If the second database matches the auxiliary query attribute and does not match the attribute to be queried, the second database is used as a target database, and a target data table containing the auxiliary query attribute is obtained from a plurality of second data tables in the target database;
[0155] Based on the identifier of the target data table and the auxiliary query attribute, a sub-query statement for the target database associated with the auxiliary query attribute is generated, and a sub-query statement associated with the attribute to be queried is obtained from the first query statement;
[0156] The second query statement is generated based on the sub-query statement associated with the auxiliary query attribute and the sub-query statement associated with the attribute to be queried.
[0157] Optionally, the receiving module 401 is further used for:
[0158] The query cost based on the first query statement and the query costs of each second query statement, before selecting a target query statement from the first query statement and each second query statement, receiving a sub-query cost of the attribute to be queried sent by the first database, and receiving a sub-query cost of the auxiliary query attribute sent by the target database;
[0159] The query cost of the second query statement is determined based on the sub-query cost of the attribute to be queried and the sub-query cost of the auxiliary query attribute.
[0160] Optionally, the comparison module 403 is specifically used for:
[0161] The query cost of the first query statement and the query statement with the smallest corresponding query cost among the second query statements are used as the target query statement.
[0162] Optionally, the first database includes a first data table, and the first data table includes the attribute to be queried and the auxiliary query attribute;
[0163] The table building module 405 is further included, and the table building module 405 is specifically used for:
[0164] Before receiving the first query statement for the first database, receiving a first table creation statement for the first database;
[0165] If the first table creation statement includes a full-text search statement, generating a second table creation statement for the first database and at least one third table creation statement for each second database according to the first table creation statement and the full-text search statement;
[0166] Sending the second table creation statement to the first database to trigger the first database to create the first data table;
[0167] For each second database, at least one corresponding third table creation statement is sent to the second database, triggering the second database to build at least one second data table.
[0168] Optionally, the table building module 405 is specifically used for:
[0169] If the first table creation statement includes a full-text search statement, determining at least one index attribute based on the full-text search statement;
[0170] Obtaining an identifier of a first data table and at least one query attribute from the first table creation statement;
[0171] Generate a second table creation statement based on the identifier of the first data table, at least one query attribute, and a virtual attribute;
[0172] At least one third table creation statement is generated based on the at least one index attribute and the virtual attribute.
[0173] Optionally, an insert module 406 is further included, and the insert module is specifically used to:
[0174] Loading the to-be-stored data corresponding to the at least one query attribute into the first data table;
[0175] Generate a unique identifier corresponding to the virtual attribute in the first data table;
[0176] For each second data table, the data to be stored corresponding to the corresponding index attribute and the unique identifier corresponding to the virtual attribute are loaded into the second data table.
[0177] Based on the same technical concept, the embodiment of the present application provides a computer device, which may be a terminal or a server, such as Figure 5 As shown, it includes at least one processor 501 and a memory 502 connected to the at least one processor. The specific connection medium between the processor 501 and the memory 502 is not limited in the embodiment of the present application. Figure 5 For example, the processor 501 and the memory 502 are connected via a bus. The bus can be divided into an address bus, a data bus, a control bus, etc.
[0178] In the embodiment of the present application, the memory 502 stores instructions that can be executed by at least one processor 501, and the at least one processor 501 can execute the steps included in the above-mentioned data query method by executing the instructions stored in the memory 502.
[0179] Among them, the processor 501 is the control center of the computer device, and can use various interfaces and lines to connect various parts of the computer device, and perform data query by running or executing instructions stored in the memory 502 and calling data stored in the memory 502. Optionally, the processor 501 may include one or more processing units, and the processor 501 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 501. In some embodiments, the processor 501 and the memory 502 may be implemented on the same chip, and in some embodiments, they may also be implemented separately on independent chips.
[0180] The processor 501 may be a general-purpose processor, such as a central processing unit (CPU), a digital signal processor, an application-specific integrated circuit (ASIC), a field programmable gate array or other programmable logic device, a discrete gate or transistor logic device, or a discrete hardware component, and may implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of the present application. A general-purpose processor may be a microprocessor or any conventional processor, etc. The steps of the method disclosed in the embodiments of the present application may be directly embodied as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
[0181] The memory 502 is a non-volatile computer-readable storage medium that can be used to store non-volatile software programs, non-volatile computer executable programs and modules. The memory 502 may include at least one type of storage medium, such as a flash memory, a hard disk, a multimedia card, a card-type memory, a random access memory (Random Access Memory, RAM), a static random access memory (Static Random Access Memory, SRAM), a programmable read-only memory (Programmable Read Only Memory, PROM), a read-only memory (Read Only Memory, ROM), an electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, EEPROM), a magnetic memory, a disk, an optical disk, etc. The memory 502 is any other medium that can be used to carry or store a desired program code in the form of an instruction or data structure and can be accessed by a computer, but is not limited thereto. The memory 502 in the embodiment of the present application can also be a circuit or any other device that can realize a storage function, for storing program instructions and / or data.
[0182] Based on the same inventive concept, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program executable by a computer device. When the program runs on the computer device, the computer device executes the steps of the above-mentioned data query method.
[0183] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0184] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0185] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0186] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0187] Obviously, those skilled in the art can make various changes and modifications to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A data query method, characterized in that: include: receiving a first query statement for a first database, wherein the first query statement includes a to-be-queried attribute and an auxiliary query attribute associated with an auxiliary query content; Based on the matching of the attribute to be queried and the auxiliary query attribute, determining a target database from a plurality of second databases, and generating a second query statement associated with each target database; Selecting a target query statement from the first query statement and the second query statements based on the query cost of the first query statement and the query costs of the second query statements; Sending the target query statement to a corresponding database, and obtaining a data query result returned by the corresponding database; Among them, based on the matching situation of the attribute to be queried and the auxiliary query attribute, determining the target database from multiple second databases and generating a second query statement associated with each target database includes: for each second database, if the second database matches the auxiliary query attribute but does not match the attribute to be queried, taking the second database as the target database, and obtaining a target data table containing the auxiliary query attribute from multiple second data tables in the target database; based on the identifier of the target data table and the auxiliary query attribute, generating a sub-query statement for the target database associated with the auxiliary query attribute, and obtaining a sub-query statement associated with the attribute to be queried from the first query statement; generating the second query statement based on the sub-query statement associated with the auxiliary query attribute and the sub-query statement associated with the attribute to be queried.
2. The method according to claim 1, characterized in that The method of determining a target database from a plurality of second databases based on a matching condition between the attribute to be queried and the auxiliary query attribute, and generating a second query statement associated with each target database, further includes: For each second database, if the second database matches the attribute to be queried and the auxiliary query attribute, the second database is used as a target database, and a target data table containing the attribute to be queried and the auxiliary query attribute is determined from a plurality of second data tables in the target database; A second query statement for the target database is generated based on the identifier of the target data table, the attribute to be queried and the auxiliary query attribute.
3. The method according to claim 2, characterized in that The query cost of the second query statement is determined by the target database based on the attribute to be queried and the auxiliary query attribute.
4. The method according to claim 1, characterized in that Before selecting a target query statement from the first query statement and the second query statements based on the query cost of the first query statement and the query costs of the second query statements, the method further includes: receiving a subquery cost of the attribute to be queried sent by the first database, and receiving a subquery cost of the auxiliary query attribute sent by the target database; The query cost of the second query statement is determined based on the sub-query cost of the attribute to be queried and the sub-query cost of the auxiliary query attribute.
5. The method according to claim 1, characterized in that The selecting a target query statement from the first query statement and each second query statement based on the query cost of the first query statement and the query costs of each second query statement includes: The query cost of the first query statement and the query statement with the smallest corresponding query cost among the second query statements are used as the target query statement.
6. The method according to claim 1, characterized in that The first database includes a first data table, and the first data table includes the attribute to be queried and the auxiliary query attribute; Before receiving the first query statement for the first database, the method further includes: receiving a first table creation statement for the first database; If the first table creation statement includes a full-text search statement, generating a second table creation statement for the first database and at least one third table creation statement for each second database according to the first table creation statement and the full-text search statement; Sending the second table creation statement to the first database to trigger the first database to create the first data table; For each second database, at least one corresponding third table creation statement is sent to the second database, triggering the second database to build at least one second data table.
7. The method according to claim 6, characterized in that If the first table creation statement includes a full-text search statement, generating a second table creation statement for the first database and at least one third table creation statement for each second database according to the first table creation statement and the full-text search statement, including: If the first table creation statement includes a full-text search statement, determining at least one index attribute based on the full-text search statement; Obtaining an identifier of a first data table and at least one query attribute from the first table creation statement; Generate a second table creation statement based on the identifier of the first data table, at least one query attribute, and a virtual attribute; At least one third table creation statement is generated based on the at least one index attribute and the virtual attribute.
8. The method according to claim 7, characterized in that Also includes: Loading the to-be-stored data corresponding to the at least one query attribute into the first data table; Generate a unique identifier corresponding to the virtual attribute in the first data table; For each second data table, the data to be stored corresponding to the corresponding index attribute and the unique identifier corresponding to the virtual attribute are loaded into the second data table.
9. A data query device, characterized in that: include: A receiving module, configured to receive a first query statement for a first database, wherein the first query statement includes an attribute to be queried and an auxiliary query attribute associated with auxiliary query content; An acquisition module, configured to determine a target database from a plurality of second databases based on a match between the attribute to be queried and the auxiliary query attribute, and to generate a second query statement associated with each target database; A comparison module, configured to select a target query statement from the first query statement and each second query statement based on the query cost of the first query statement and the query costs of each second query statement; A sending module, used to send the target query statement to a corresponding database and obtain a data query result returned by the corresponding database; Among them, based on the matching situation of the attribute to be queried and the auxiliary query attribute, determining the target database from multiple second databases and generating a second query statement associated with each target database includes: for each second database, if the second database matches the auxiliary query attribute but does not match the attribute to be queried, taking the second database as the target database, and obtaining a target data table containing the auxiliary query attribute from multiple second data tables in the target database; based on the identifier of the target data table and the auxiliary query attribute, generating a sub-query statement for the target database associated with the auxiliary query attribute, and obtaining a sub-query statement associated with the attribute to be queried from the first query statement; generating the second query statement based on the sub-query statement associated with the auxiliary query attribute and the sub-query statement associated with the attribute to be queried.
10. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of any one of the methods of claims 1 to 8 are implemented.
11. A computer-readable storage medium, characterized in that: It stores a computer program executable by a computer device. When the program is run on the computer device, the computer device executes the steps of any method described in claims 1 to 8.
Citation Information
Patent Citations
Multi-table association query method, device and equipment
CN109656946A
Association query method, database application system and server
CN110109951A