A data query method and device, a server and a readable storage medium
By using Elasticsearch to generate a full-text search engine index in a relational database, multi-table queries are transformed into single-table queries, solving the problem of low efficiency in multi-table queries and achieving efficient cross-table data querying and full-text retrieval.
Patent Information
- Application Number
- CN202010737086.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-28
- Publication Date
- 2026-02-27
- Estimated Expiration
- 2040-07-28
AI Technical Summary
In existing technologies, multi-table queries are inefficient and unsuitable for full-text search, especially when performing cross-table data queries in relational databases, where it is difficult to achieve efficient data retrieval.
By employing the full-text search engine Elasticsearch, we generate indexes across multiple single tables and utilize its search syntax to perform data queries, transforming multi-table queries into single-table queries. This is combined with Elasticsearch's distributed architecture to achieve cross-table data queries.
It improves the efficiency of data querying, supports full-text search, can handle the retrieval of trillions of records, and solves the problem of low efficiency in multi-table queries.
Smart Images

Figure CN111767303B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of database, and in particular to a data query method and device, a server and a readable storage medium. BACKGROUND
[0002] At present, the single table form engine based on the relational database has a simple implementation mode, but in daily application and use, there are few scenes in which the data query can be completed only by using the single table form. In most cases, the query for certain data still depends on the multi-table (cross-table) query. For example, the multi-table query generates a view by associating multiple tables through a view, but the view is not suitable for full-text retrieval because the association result of the multi-tables can be very large, and the efficiency of data query is also relatively low. SUMMARY
[0003] The embodiments of the present application provide a data query method, device, server and readable storage medium, which can support full-text retrieval of stored data, realize data query across multiple tables, and improve the efficiency of data query.
[0004] The first aspect of the embodiments of the present application provides a data query method, comprising:
[0005] obtaining a data query request submitted by a user through a query interface, wherein the data query request comprises a query condition and a target field related to the query condition, and the target field corresponds to multiple single tables of a relational database;
[0006] obtaining an index of a full-text search engine corresponding to the multiple single tables, wherein the index of the full-text search engine is generated according to the multiple single tables, and the index of the full-text search engine comprises all fields of the multiple single tables;
[0007] querying data matched with the query condition from the index of the full-text search engine by using a retrieval syntax of the full-text search engine.
[0008] The second aspect of the embodiments of the present application provides a data query device, comprising:
[0009] an obtaining module, configured to obtain a data query request submitted by a user through a query interface, wherein the data query request comprises a query condition and a target field related to the query condition, and the target field corresponds to multiple single tables of a relational database;
[0010] The obtaining module is further configured to obtain an index of a full-text search engine corresponding to the multiple single tables, wherein the index of the full-text search engine is generated according to the multiple single tables, and the index of the full-text search engine comprises all fields of the multiple single tables;
[0011] A processing module is configured to query data matching the query condition from the index of the full-text search engine by using a search syntax of the full-text search engine.
[0012] The third aspect of the embodiment of the present application provides a server, comprising a processor, a network interface and a storage device, which are connected with each other, wherein the network interface is controlled by the processor to receive and send data, the storage device is configured to store a computer program, the computer program comprises program instructions, and the processor is configured to invoke the program instructions to execute the data query method in the first aspect.
[0013] The fourth aspect of the embodiment of the present application provides a computer readable storage medium, which stores program instructions, and the program instructions are configured to implement the data query method in the first aspect when executed.
[0014] The fifth aspect of the embodiment of the present application provides a computer program product or a computer program, which comprises computer instructions stored in a computer readable storage medium. A processor of a computer device reads the computer instructions from the computer readable storage medium, and the processor executes the computer instructions to enable the computer device to execute the data query method in the first aspect.
[0015] In the embodiment of the present application, the server acquires a data query request submitted by a user through a query interface, the data query request comprises a query condition and a target field related to the query condition, the target field corresponds to multiple single tables of a relational database, and the server acquires indexes of a full-text search engine corresponding to the multiple single tables, the indexes of the full-text search engine are generated according to the multiple single tables, the indexes of the full-text search engine comprise all fields of the multiple single tables, and then the server queries data matching the query condition from the indexes of the full-text search engine by using a search syntax of the full-text search engine, so that full-text search of stored data can be supported, data query across multiple tables can be implemented, and the efficiency of data query is improved. BRIEF DESCRIPTION OF DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed in the embodiments or the prior art description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort on the basis of these drawings.
[0017] Figure 1 is a flowchart of a data query method provided by the embodiment of the present application;
[0018] Figure 2 is a flow diagram of another data query method provided by an embodiment of the present application;
[0019] Figure 3a is a form engine configuration interface provided by an embodiment of the present application;
[0020] Figure 3b is a query condition configuration interface provided by an embodiment of the present application;
[0021] Figure 3c is an editing style diagram provided by an embodiment of the present application;
[0022] Figure 3d is a result setting and display field provided by an embodiment of the present application;
[0023] Figure 3e is a query interface provided by an embodiment of the present application;
[0024] Figure 4 is a single table generation diagram provided by an embodiment of the present application;
[0025] Figure 5 is a structure diagram of a data query device provided by an embodiment of the present application;
[0026] Figure 6 is a structure diagram of a server provided by an embodiment of the present application. DETAILED DESCRIPTION
[0027] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative work fall within the protection scope of the present application.
[0028] Cloud computing refers to a delivery and use model of IT infrastructure where IT resources are accessed over the Internet as a service, and the resources are available on demand, easily scalable, and manageable. Broadly, cloud computing refers to the delivery of services over the Internet, and the services can be IT and software, Internet related, or other services. Cloud computing is a product of the development of grid computing, distributed computing, parallel computing, utility computing, network storage technologies, virtualization, load balancing, and other traditional computer and network technologies.
[0029] With the development of the Internet, real-time data flow, and diversified connected devices, and the promotion of requirements of search services, social networks, mobile commerce, and open collaboration, cloud computing has rapidly developed. Unlike previous parallel distributed computing, cloud computing will revolutionize the entire Internet model and enterprise management model from the concept.
[0030] Cloud storage is a new concept extended and developed on the basis of the concept of cloud computing. A distributed cloud storage system (hereinafter referred to as a storage system) refers to a storage system that cooperatively works together to provide data storage and business access functions by collecting a large number of various types of storage devices (storage nodes) in a network through cluster applications, grid technologies, and distributed storage file systems, and the like.
[0031] At present, the storage method of the storage system is as follows: a logical volume is created, and a physical storage space is allocated to each logical volume when the logical volume is created. The physical storage space can be a disk of a certain storage device or a disk group of several storage devices. A client stores data on a certain logical volume, that is, stores data on a file system, the file system divides the data into many parts, each part is an object, the object contains not only data but also additional information such as data ID (IDentity), the file system writes each object into the physical storage space of the logical volume, and the file system records the storage location information of each object, so that when the client requests to access data, the file system can enable the client to access the data according to the storage location information of each object.
[0032] The storage system allocates physical storage space for a logical volume by dividing the physical storage space into sections in advance according to the capacity of objects stored in the logical volume and the group of RAID (Redundant Array of Independent Disk), and a logical volume can be understood as a section, thereby allocating the physical storage space for the logical volume.
[0033] A database can be briefly regarded as an electronic file cabinet, i.e., a place for storing electronic files, and a user can add, query, update, delete, etc. data in the files. The so-called "database" is a collection of data stored together in a certain way, shared by multiple users, with as little redundancy as possible, and independent of application programs.
[0034] A database management system (DBMS) is a computer software system designed to manage a database, and generally has basic functions such as storage, interception, security, backup, etc. A database management system can be classified according to the database model it supports, such as relational, XML (Extensible Markup Language), full-text search engine Elasticsearch, or according to the type of computer it supports, such as server cluster, mobile phone, or according to the query language it uses, such as SQL (Structured Query Language), XQuery, or according to the performance focus, such as maximum size, maximum running speed, or other classification methods. Regardless of the classification method used, some DBMSs can cross categories, such as supporting multiple query languages at the same time.
[0035] At present, for multi-table (cross-table) data query, a view is mainly used to associate multiple tables to generate a view, thereby realizing data query before multiple tables, which can realize cross-table query, but the association result of multiple tables can be very large, the query efficiency can be very low, and it is not suitable for full-text search.
[0036] Therefore, the embodiment of the present application learns the form engine idea of the single table, changes the related multiple single tables into one single table, makes the multiple table query become the same as the single table query, does not need to develop the code, greatly improves the development efficiency, and utilizes the natural distributed architecture of Elasticsearch to realize the trillion level record retrieval. Meanwhile, Elasticsearch supports the full text retrieval very well, and can solve the problem of low query efficiency. The Elasticsearch is a nosql database, provides a distributed multi-user full text search engine, is realized based on Lucene, and provides the RESTful web interface. The Elasticsearch is developed by using the Java language, is published as the open source under the Apache license, and is a popular enterprise level search engine. In the cloud computing, the real time search, stability, reliability, rapidness, and convenient installation and use can be achieved.
[0037] In a feasible embodiment, the server can acquire a data query request submitted by a user through a query interface, the data query request including a query condition and a target field related to the query condition, the target field corresponding to multiple single tables of a relational database, and acquire indexes of a full text search engine corresponding to the multiple single tables, the indexes of the full text search engine being generated according to the multiple single tables, the indexes of the full text search engine including all fields of the multiple single tables, and then query data matching the query condition from the indexes of the full text search engine by using a retrieval syntax of the full text search engine, so that the full text retrieval of the stored data can be supported, the data query across multiple tables can be implemented, and the efficiency of the data query can be improved.
[0038] Please refer to Figure 1 , Figure 1 A flowchart of a data query method provided by the embodiment of the present application is shown. The method can be executed by a server. The data query method described in the embodiment includes the following steps.
[0039] 101. Acquire a data query request submitted by a user through a query interface, the data query request including a query condition and a target field related to the query condition, the target field corresponding to multiple single tables of a relational database.
[0040] The target field includes at least two fields related to the query condition, and the query condition can be related to gender, time, identity card, etc. For example, assuming that the data query request is to query which roles a certain user has, the data query request includes the query condition and the target field associated with the query condition, the query condition is user and role, and the target field associated with the query condition includes the field corresponding to the role and the field corresponding to the user.
[0041] The plurality of single tables include an association relationship table between the single tables, and the association relationship table includes a primary-foreign key relationship of the single tables, and the primary-foreign key relationship can be used to determine the association relationship between the plurality of tables.
[0042] Specifically, the server obtains a data query request submitted by a user through a query interface, and the server can determine at least two single tables corresponding to a relational database according to at least two fields related to a query condition. For example, in the above example, the target fields related to the query condition include a field corresponding to a role and a field corresponding to a user, and according to the field corresponding to the role and the field corresponding to the user, it can be determined that there is a user table A, a user_role table, and a role table.
[0043] For example, according to the above example, the target fields related to the query condition include a field corresponding to a role and a field corresponding to a user, and according to the field corresponding to the role and the field corresponding to the user, it can be determined that there are three single tables (multiple tables), which are a user table A of Table 1, a user_role table of Table 2, and a role table of Table 3. In Table 2, the primary-foreign key relationship of the remaining two single tables is included, and the association between Table 1 and Table 2 can be established through the user_role table of Table 2, so that subsequent multi-table query can be performed according to the corresponding primary-foreign key relationship.
[0044] Table 1
[0045] Field Type Length Description user_id bigint 20 Primary key user_name char 50 Name create_time datetime 10 Creation time channel tinyint 4 Registration channel source
[0046] Table 2
[0047] Field Type Length Description role_id bigint 20 Primary key, foreign key role table user_id bigint 20 Primary key, foreign key user table
[0048] Table 3
[0049] Field Type Length Description role_id bigint 20 Primary key role_name char 20 Role name
[0050] It should be noted that the at least two single tables queried according to the at least two fields related to the query condition are not one-to-one, and the tables associated with the at least two fields related to the query condition can also be queried, for example, in the above example, three single tables are queried.
[0051] 102、Obtain an index of a full-text search engine corresponding to the plurality of single tables, the index of the full-text search engine being generated according to the plurality of single tables, and the index of the full-text search engine including all fields of the plurality of single tables.
[0052] Wherein, the full-text search engine can be Elasticsearch, if the full-text search engine is Elasticsearch, the index of the full-text search engine is an Elasticsearch index, and the Elasticsearch index is a table similar to a relational database.
[0053] The index of the full-text search engine can be understood as a single table, and the single table includes all fields in the multiple single tables.
[0054] Specifically, after the server obtains the data query request submitted by the user through the query interface, the server first obtains the multiple single tables corresponding to the target field according to the target field. Since the index of the full-text search engine is generated from the multiple single tables, the index of the full-text search engine includes all fields of the multiple single tables. Therefore, the index of the full-text search engine generated from the multiple single tables can be obtained according to the fields included in the multiple single tables.
[0055] 103. Query data matching the query condition from the index of the full-text search engine by using the retrieval syntax of the full-text search engine.
[0056] Wherein, the full-text search engine has a fixed retrieval syntax, for example, the retrieval syntax of a general full-text search engine can be restapi or dsl.
[0057] In a feasible embodiment, the server can construct a retrieval statement by using the retrieval syntax of the full-text search engine and the query condition, and query data matching the query condition from the index of the full-text search engine by using the retrieval statement. Wherein, the construction of the retrieval statement by using the retrieval syntax of the full-text search engine and the query condition can realize the retrieval modification of the index of the full-text search engine, thereby replacing the structured query language SQL query in the relational database.
[0058] For example, the retrieval statement of the structured query language SQL query in the relational database is:
[0059]
[0060]
[0061] And the retrieval statement of the full-text search engine (such as elasticsearch dsl syntax) is:
[0062]
[0063] Through the retrieval modification, it can be seen that the retrieval statement of the full-text search engine is relatively simple.
[0064] In the embodiment of the present application, the server can acquire a data query request submitted by a user through a query interface, the data query request comprising a query condition and a target field related to the query condition, the target field corresponding to multiple single tables of a relational database, and acquire indexes of a full-text search engine corresponding to the multiple single tables, and then query data matching the query condition from the indexes of the full-text search engine by using a search syntax of the full-text search engine, so as to support full-text search of stored data, realize data query across multiple tables, and improve the efficiency of data query.
[0065] Please refer to Figure 2 , Figure 2 The flowchart of another data query method provided by the embodiment of the present application is shown. The method can be executed by a server. The data query method described in the embodiment comprises the following steps.
[0066] 201. Acquire multiple fields in the fields included in the multiple single tables, the multiple fields being selected from the fields included in the multiple single tables by an administrator through a form engine configuration interface.
[0067] Specifically, the multiple fields are composed of at least one field in each single table in the multiple single tables preselected by an administrator (such as a developer) through the form engine configuration interface, and the server can acquire the multiple fields of the at least one field in each single table.
[0068] In a feasible embodiment, the form engine configuration interface can provide a form engine configuration interface for configuring a single table, the server responds to a form engine configuration request for a single table, and outputs the form engine configuration interface through a client. In the form engine configuration interface, a data source, a query condition, and the like need to be selected. When the data source is selected, it is necessary to determine which fields can be used as fields corresponding to the query condition. In 3a, it can be seen that the fields sfzh, sbsj_date, and gender can be used as fields corresponding to the query condition. After the data source is selected, the server outputs an interface for configuring the query condition, such as Figure 3b The query condition can be an ID card, an application time, a gender, and the like, and the field sfzh corresponding to the ID card, the field gender corresponding to the gender, and the field sbsj_date corresponding to the application time are determined. The corresponding styles can be edited for the ID card, the application time, and the gender. The gender style editing interface is shown in Figure 3c After the query condition is configured, go to Figure 3d to set the result and display fields, that is, the display order of the result and display fields can be set. When the configuration is successful, the entire query interface can be displayed through the client. The query interface is shown in Figure 3eAs shown, the date field can be retrieved by date query, the gender can be generated in dictionary form, and the data query can be performed by date, ID, and gender.
[0069] It should be noted that the above multiple single tables are configured through the single table process.
[0070] 202. Obtain the multiple single tables from the relational database according to the multiple fields.
[0071] The multiple single tables include an association relationship table between the single tables, and the association relationship table includes a primary-foreign key relationship of the single tables.
[0072] Specifically, the multiple fields are matched with the multiple single tables included in the relational database, and if the multiple fields match the fields included in the multiple single tables, the multiple single tables are obtained from the relational database.
[0073] 203. Perform field mapping processing on the multiple single tables by using a structured query language and a field mapping relationship to generate an index of the full-text search engine.
[0074] The structured query language can be SQL.
[0075] Because the relational databases are relatively many and the type definitions are different, a field mapping relationship is set to map the field types of the relational databases and the field types in the full-text search engine, so as to facilitate subsequent form engine processing.
[0076] Specifically, the server processes the multiple single tables by using the structured query language to obtain a result index of the full-text search engine, the field types included in the result index are the same as the field types in the multiple tables, and then the field types included in the result index are mapped according to the field mapping relationship in the full-text search engine, the field types are unified, and thus the index of the full-text search engine is obtained.
[0077] For example, in the embodiment Figure 1 , the user table A, the user_role user and role association table, and the role table are mentioned, and according to the structured query language SQL and the field mapping relationship, a single table (that is, the index of the full-text search engine) as shown in Figure 4 can be generated, and it can be seen that the single table includes all the fields in the three single tables of the user table A, the user_role user and role association table, and the role table. The single table Figure 4 can be implemented by the following sql:
[0078] select user.user_id, user.user_name, user.create_time, user.channel,
[0079] role.role_id, role.role_name
[0080] from user, user_role, role
[0081] where user.user_id=user_role.user_id and user_role.role_id=role.role_id
[0082] According to the above sql, the field of the result index is obtained, and the field of the result index is mapped through field mapping to unify the mapping, so as to construct the index as Figure 4 The middle index.
[0083] It should be noted that if the fields of different tables are the same, the table name + field can be used as the field of the result index when naming to distinguish different single tables.
[0084] In a feasible embodiment, before the server generates the index of the full-text search engine by using the structured query language and the field mapping relationship to process multiple single tables, the server can determine the field mapping relationship between the field types of each relational database and the field types in the full-text search engine, and store the field mapping relationship in the full-text search engine, so as to directly use the field mapping relationship for subsequent field mapping. For example, in Table 4, each database field type can be mapped to the type in the elasticsearch index, such as mapping int, integer, etc. to long, mapping date, datetime, timestamp to date, etc.
[0085] Table 4
[0086]
[0087]
[0088] In an embodiment, after the field mapping of the multiple single tables is performed by using the structured query language and the field mapping relationship to generate the index of the full-text search engine, the data included in each of the multiple single tables is imported into the index of the full-text search engine through full-quantity synchronization. The implementation is as follows: the server queries the data included in each of the multiple single tables by using the structured query language, and imports the data included in each of the multiple single tables into the index of the full-text search engine. If the data included in each of the multiple single tables is too much, the data can be imported into the index of the full-text search engine in batches, so as to synchronize the data included in each of the multiple single tables with the data in the index of the full-text search engine.
[0089] Further, when the data included in any of the multiple single tables changes, the changed data is updated into the index of the full-text search engine through incremental synchronization. The implementation is as follows: when the data included in any of the multiple single tables changes, the server updates the changed data into the index of the full-text search engine according to the field corresponding to the changed data of any of the multiple single tables. When the data included in any of the multiple single tables changes, the server puts the changed data into a queue. When the code responsible for updating the changed data is obtained, the data corresponding to the update of the index of the full-text search engine is determined according to the field corresponding to the changed data and the field mapping relationship in the full-text search engine, that is, the index of the full-text search engine is found according to the field corresponding to the changed data and the field mapping relationship, and then the changed data is updated into the index of the full-text search engine. For example, when the role table in the user table A, the user and role association table, and the role table is modified (that is, the data included in the role table changes), the data corresponding to the update of the index of the full-text search engine is determined according to the field corresponding to the modified data in the role table and the field mapping relationship in the full-text search engine.
[0090] 204、obtain a data query request submitted by a user through a query interface, the data query request including a query condition and a target field related to the query condition, the target field corresponding to multiple single tables of a relational database.
[0091] 205、obtain an index of a full-text search engine corresponding to the multiple single tables, the index of the full-text search engine being generated according to the multiple single tables, and the index of the full-text search engine including all fields of the multiple single tables.
[0092] 206、query data matching the query condition from the index of the full-text search engine by using a retrieval syntax of the full-text search engine.
[0093] The specific implementation of steps 204-206 can refer to the related description in 101-103 of the above data query method, and will not be described here.
[0094] In the embodiment of the application, the server acquires a plurality of fields in the fields included in the plurality of single tables, the plurality of fields being selected by an administrator from the fields included in the plurality of single tables through a form engine configuration interface, and acquires the plurality of single tables from a relational database according to the plurality of fields, performs field mapping processing on the plurality of single tables by using a structured query language and a field mapping relationship, to generate an index of a full-text search engine, acquires a data query request submitted by a user through a query interface, the data query request including a query condition and a target field related to the query condition, the target field corresponding to the plurality of single tables of the relational database, acquires an index of the full-text search engine corresponding to the plurality of single tables, the index of the full-text search engine being generated according to the plurality of single tables, the index of the full-text search engine including all fields of the plurality of single tables, queries data matching the query condition from the index of the full-text search engine by using a search syntax of the full-text search engine, and realizes conversion of the plurality of tables into a single table, thereby indirectly realizing a form engine for multi-table (cross-table) query and improving the efficiency of data query.
[0095] Please refer to Figure 5 A structural schematic diagram of a data query device provided in the embodiment of the application is shown in FIG. 1. The data query device described in the embodiment can be executed by a server and includes:
[0096] The acquisition module 501 is configured to acquire a data query request submitted by a user through a query interface, the data query request including a query condition and a target field related to the query condition, the target field corresponding to a plurality of single tables of a relational database.
[0097] The acquisition module 501 is further configured to acquire an index of a full-text search engine corresponding to the plurality of single tables, the index of the full-text search engine being generated according to the plurality of single tables, the index of the full-text search engine including all fields of the plurality of single tables.
[0098] The processing module 502 is configured to query data matching the query condition from the index of the full-text search engine by using a search syntax of the full-text search engine.
[0099] Optionally, the acquisition module 501 is further configured to:
[0100] acquire a plurality of fields in the fields included in the plurality of single tables, the plurality of fields being selected by an administrator from the fields included in the plurality of single tables through a form engine configuration interface;
[0101] acquire the plurality of single tables from the relational database according to the plurality of fields;
[0102] The multiple single tables are subjected to field mapping processing by using a structured query language and a field mapping relationship, so as to generate an index of the full-text search engine.
[0103] Optionally, the processing module 502 is further configured to:
[0104] determine the field mapping relationship between the field types of each relational database and the field types in the full-text search engine;
[0105] store the field mapping relationship in the full-text search engine.
[0106] Optionally, the multiple single tables include an association relationship table between the single tables, and the association relationship table includes a primary-foreign key relationship of the single tables.
[0107] Optionally, after the processing module 502 subjects the multiple single tables to field mapping processing by using a structured query language and a field mapping relationship, so as to generate an index of the full-text search engine, the processing module 502 is further configured to:
[0108] query data included in each single table in the multiple single tables by using the structured query language;
[0109] import the data included in each single table into the index of the full-text search engine.
[0110] Optionally, the processing module 502 is further configured to:
[0111] when data included in any single table in the multiple single tables changes, update the changed data into the index of the full-text search engine according to a field corresponding to the changed data of the any single table.
[0112] Optionally, the processing module 502 is specifically configured to:
[0113] construct a search statement by using a search syntax of the full-text search engine and the query condition;
[0114] query data matching the query condition from the index of the full-text search engine by using the search statement.
[0115] It can be understood that the functions of the functional modules of the data query apparatus in this embodiment can be specifically implemented according to the methods in the method embodiments, and the specific implementation process can refer to the related descriptions of the method embodiments Figure 1 or Figure 2 , which will not be described here in detail.
[0116] In the embodiment of the present application, the acquisition module 501 can acquire a data query request submitted by a user through a query interface, the data query request comprising a query condition and a target field related to the query condition, the target field corresponding to multiple single tables of a relational database, and acquire indexes of a full-text search engine corresponding to the multiple single tables, the indexes being generated according to the multiple single tables, and then the processing module 502 queries data matching the query condition from the indexes of the full-text search engine by using a retrieval syntax of the full-text search engine, so that full-text retrieval of stored data can be supported, data query across multiple tables can be implemented, and the efficiency of data query can be improved.
[0117] Please refer to Figure 6 A structural schematic diagram of a server is provided in the embodiment of the present application. The server described in the embodiment comprises a processor 601, a network interface 602 and a memory 603. The processor 601, the network interface 602 and the memory 603 can be connected by a bus or other means, and the embodiment of the present application takes the connection by the bus as an example.
[0118] The processor 601 (or a central processing unit (CPU)) is the calculation core and control core of the server. The network interface 602 can optionally comprise a standard wired interface, a wireless interface (such as a WI-FI interface, a mobile communication interface, etc.), and is controlled by the processor 601 to receive and send data. The memory 603 is the memory device of the server, and is used to store programs and data. It can be understood that the memory 603 here can be a high-speed RAM memory, or a non-volatile memory, for example, at least one disk memory; optionally, it can also be at least one storage device located away from the aforementioned processor 601. The memory 603 provides a storage space that stores the operating system and executable program code of the server, and can comprise but is not limited to: a Windows system (a kind of operating system), a Linux (a kind of operating system) system, etc., and the present application does not limit this.
[0119] In the embodiment of the present application, the processor 601 executes the following operations by running the executable program code in the memory 603:
[0120] acquire a data query request submitted by a user through a query interface, the data query request comprising a query condition and a target field related to the query condition, the target field corresponding to multiple single tables of a relational database;
[0121] acquire indexes of a full-text search engine corresponding to the multiple single tables, the indexes of the full-text search engine being generated according to the multiple single tables, and the indexes of the full-text search engine comprising all fields of the multiple single tables;
[0122] query, from an index of the full-text search engine, data matching the query condition using a search syntax of the full-text search engine.
[0123] Optionally, before the processor 601 acquires the data query request submitted by the user through the query interface, the processor 601 is further configured to:
[0124] acquire a plurality of fields in the fields included in the plurality of single tables, the plurality of fields being selected by an administrator from the fields included in the plurality of single tables through a form engine configuration interface;
[0125] acquire the plurality of single tables from the relational database according to the plurality of fields;
[0126] perform field mapping processing on the plurality of single tables using a structured query language and a field mapping relationship to generate an index of a full-text search engine.
[0127] Optionally, before the processor 601 performs field mapping processing on the plurality of single tables using a structured query language and a field mapping relationship to generate an index of a full-text search engine, the processor 601 is further configured to:
[0128] determine a field mapping relationship between field types of each relational database and field types in the full-text search engine;
[0129] store the field mapping relationship in the full-text search engine.
[0130] Optionally, the plurality of single tables include an association relationship table between single tables, and the association relationship table includes a primary-foreign key relationship of the single tables.
[0131] Optionally, after the processor 601 performs field mapping processing on the plurality of single tables using a structured query language and a field mapping relationship to generate an index of a full-text search engine, the processor 601 is further configured to:
[0132] query data included in each single table of the plurality of single tables using the structured query language;
[0133] import the data included in each single table into the index of the full-text search engine.
[0134] Optionally, the processor 601 is further configured to:
[0135] when data included in any single table of the plurality of single tables changes, update the changed data into the index of the full-text search engine according to a field corresponding to the changed data of the any single table.
[0136] Optionally, the processor 601 is specifically configured to:
[0137] construct a search sentence using the search syntax of the full-text search engine and the query condition;
[0138] query data matching the query condition from the index of the full-text search engine using the search sentence.
[0139] In the embodiment of the present application, the server 601 can acquire a data query request submitted by a user through a query interface, the data query request including a query condition and a target field related to the query condition, the target field corresponding to multiple single tables of a relational database, and acquire multiple single tables corresponding to indexes of a full-text search engine generated according to the multiple single tables, and then the server 601 queries data matching the query condition from the indexes of the full-text search engine using the search syntax of the full-text search engine, which can support full-text search of stored data, realize data query across multiple tables, and improve the efficiency of data query.
[0140] In a specific implementation, the processor 601, the network interface 602, and the memory 603 described in the embodiment of the present application can execute the implementation described in the flow of the data query method provided by the embodiment of the present application, and can also execute the implementation described in the data query apparatus provided by the embodiment of the present application, which will not be described here.
[0141] The embodiment of the present application further provides a computer readable storage medium, which stores a computer program, the computer program including program instructions, the program instructions being executed by a processor to perform the steps performed in the data query embodiment described above.
[0142] The embodiment of the present application further provides a computer program product or a computer program, the computer program product or the computer program including computer instructions stored in a computer readable storage medium. A processor of a computer device reads the computer instructions from the computer readable storage medium, and the processor executes the computer instructions to make the computer device perform the steps performed in the data query embodiment described above.
[0143] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by a computer program instructing related hardware, and the program can be stored in a computer readable storage medium. When the program is executed, it can include the processes of the above-mentioned embodiment methods. The storage medium can be a magnetic disc, an optical disc, a read-only memory (ROM), a random access memory (RAM), or the like.
[0144] The above disclosed is only a preferred embodiment of the present application, of course, cannot be limited by this to limit the scope of the present application, the person skilled in the art can understand that the implementation of all or part of the above-mentioned processes, and according to the equivalent changes of the claims of the present application, still belong to the scope covered by the present application.
Claims
1. A data query method, characterized by, The method comprises: obtaining a plurality of fields included in a plurality of single tables, the plurality of fields being selected by an administrator from fields included in the plurality of single tables through a form engine configuration interface; the plurality of single tables have a correlation relationship; the plurality of single tables comprise a role table, a user table and a user and role association table; the user and role association table comprises a primary-foreign key relationship between the role table and the user table; obtaining the plurality of single tables from a relational database according to the plurality of fields; processing the plurality of single tables by using a structured query language to obtain a result index of a full-text search engine, the result index comprising the same field types as those in the plurality of single tables; when the plurality of single tables comprise the same fields, the fields in the result index are determined according to the table names of corresponding single tables and the fields in the corresponding single tables to distinguish different single tables; mapping the field types included in the result index according to a field mapping relationship between each relational database and the field types in the full-text search engine to generate an index of the full-text search engine; the index of the full-text search engine is a single table, and the index of the full-text search engine comprises all fields of the plurality of single tables; obtaining a data query request submitted by a user through a query interface, the data query request comprising a query condition and at least two target fields related to the query condition; determining a plurality of single tables corresponding to the at least two target fields related to the query condition in a relational database according to the at least two target fields; obtaining an index of a full-text search engine corresponding to the plurality of single tables according to the fields in the plurality of single tables; querying data matching the query condition from the index of the full-text search engine by using a search syntax of the full-text search engine.
2. The method of claim 1, wherein, Before the processing of the plurality of single tables by using the structured query language to obtain the result index of the full-text search engine, the method further comprises: determining a field mapping relationship between the field types of each relational database and the field types in the full-text search engine; storing the field mapping relationship in the full-text search engine.
3. The method of claim 1, wherein, After the mapping processing of the field types included in the result index according to the field mapping relationship between each relational database and the field types in the full-text search engine to generate the index of the full-text search engine, the method further comprises: querying data included in each single table of the plurality of single tables by using the structured query language; importing the data included in each single table into the index of the full-text search engine.
4. The method of claim 3, wherein, The method further comprises: when data included in any single table of the plurality of single tables changes, updating the changed data into the index of the full-text search engine according to the fields corresponding to the changed data of the any single table.
5. The method of claim 1, wherein, The querying of data matching the query condition from the index of the full-text search engine by using the search syntax of the full-text search engine comprises: constructing a search statement by using the search syntax of the full-text search engine and the query condition; Query data matching the query condition from the index of the full-text search engine using the search statement.
6. A data query apparatus, characterized by comprising: The device comprises: An acquisition module is configured to acquire a plurality of fields in a plurality of single tables, the plurality of fields being selected from fields in the plurality of single tables by an administrator through a form engine configuration interface; the plurality of single tables have a correlation relationship; the plurality of single tables comprise a role table, a user table, and a user and role association table; the user and role association table comprises a primary-foreign key relationship between the role table and the user table; The acquisition module is further configured to acquire the plurality of single tables from a relational database according to the plurality of fields; The acquisition module is further configured to process the plurality of single tables using a structured query language to obtain a result index of a full-text search engine, the result index comprising the same field types as those in the plurality of single tables; when the plurality of single tables have the same fields, the fields in the result index are determined according to the table names of corresponding single tables and the fields in the corresponding single tables; The acquisition module is further configured to perform mapping processing on the field types included in the result index according to a field mapping relationship between each relational database and the field types in the full-text search engine to generate an index of the full-text search engine; the index of the full-text search engine is a single table, and the index of the full-text search engine comprises all the fields of the plurality of single tables; The acquisition module is further configured to acquire a data query request submitted by a user through a query interface, the data query request comprising a query condition and at least two target fields related to the query condition, the target fields corresponding to a plurality of single tables of a relational database; The acquisition module is further configured to determine the plurality of single tables corresponding to the at least two target fields related to the query condition in the relational database according to the at least two target fields; The acquisition module is further configured to acquire an index of a full-text search engine corresponding to the plurality of single tables according to the fields in the plurality of single tables, the index of the full-text search engine being generated according to the plurality of single tables, and the index of the full-text search engine comprising all the fields of the plurality of single tables; A processing module is configured to query data matching the query condition from the index of the full-text search engine using a search syntax of the full-text search engine.
7. A server, characterized by A device comprises a processor, a network interface, and a storage device, which are connected to each other, wherein the network interface is controlled by the processor to receive and transmit data, the storage device is used to store a computer program, the computer program comprises program instructions, the processor is configured to invoke the program instructions to execute the data 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 a computer program, the computer program comprises program instructions, and the program instructions make the processor execute the data query method according to any one of claims 1-5 when executed by the processor.
9. A computer program product, characterised in that, The computer program product comprises computer programs or computer instructions which, when executed by a processor, implement the data query method of any one of claims 1-5.
Citation Information
Patent Citations
Management method and system capable for aiming at search server, and service side
CN108491470A
Search service creation method and device and computer readable storage medium
CN108874924A
Database query and retrieval method and device and electronic equipment
CN111382226A