Data query method and device, electronic equipment, storage medium and program product
By matching the target rows between the main table and the secondary table, the number of queries is reduced, the problem of inefficiency in associated queries of large data tables is solved, and more efficient database queries are achieved.
Patent Information
- Application Number
- CN202410641496.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-22
- Publication Date
- 2024-09-03
AI Technical Summary
When querying correlations between large data tables, the query efficiency is low, resulting in data table locks and database service downtime.
By determining the main table and the secondary table, and using the field names to be queried in the main table to satisfy the constraints, the corresponding target rows are searched in the secondary table for each target row, and the field names to be displayed are added to the query results, reducing Query times and reduce database load.
It improves the efficiency of data query, avoids data table locks and database service downtime, and improves query performance.
Smart Images

Figure CN118585531A
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a data query method, device, electronic device, storage medium and program product. Background Art
[0002] There are a large number of business queries in most current business processing systems. For more complex queries, it is often necessary to associate multiple tables and obtain information from multiple tables.
[0003] At present, the query method generally performs a database association query, that is, the query conditions of multiple tables are associated by using join in the query statement.
[0004] However, if associated queries are used between large tables with large amounts of data, the query efficiency is very low, and in serious cases it may cause table locks and database service downtime. Summary of the invention
[0005] The present application provides a data query method, device, electronic device, storage medium and program product to reduce the query load of a database and improve query efficiency.
[0006] In a first aspect, the present application provides a data query method, comprising:
[0007] Obtain query conditions and field names to be displayed, wherein the query conditions include at least one field name to be queried and constraint conditions corresponding to each field name to be queried;
[0008] Determine at least one first data table related to the query condition and at least one second data table related to the field name to be displayed, and determine a main table from the at least one first data table, and the data tables other than the main table in the first data table and the second data table are sub-tables; the field names contained in both the main table and the sub-table are common field names;
[0009] Determine at least one first target row in the main table, the field of the field name to be queried appearing in the first target row satisfies the corresponding constraint condition, if the secondary table contains some of the field names to be queried and does not contain the field name to be displayed, then for each first target row, search for at least one corresponding second target row in the secondary table according to the field corresponding to the common field name in the target row, if the field of the field name to be queried appearing in any second target row found satisfies the corresponding constraint condition, then add the field of the field name to be displayed in the first target row to the query result;
[0010] The query result is output.
[0011] In a possible design, at least one first target row in the main table is determined, and the field of the field name to be queried appearing in the first target row satisfies the corresponding constraint condition. If the secondary table contains some of the field names to be queried and does not contain the field name to be displayed, then for each first target row, at least one corresponding second target row is searched in the secondary table according to the field corresponding to the common field name in the target row. If the field of the field name to be queried appearing in any second target row found satisfies the corresponding constraint condition, then the field of the field name to be displayed in the first target row is added to the query result, including:
[0012] Generate a first query statement according to the field names to be queried and the corresponding constraints that appear in the main table;
[0013] Generate a second query statement according to the field name to be queried and the corresponding constraint condition appearing in the secondary table;
[0014] Add the second query statement and the common field name to an EXISTS statement, and connect the obtained statement with the first query statement using AND to obtain a target query statement;
[0015] The target query statement is used to query the main table and the secondary table to obtain the query result.
[0016] In one possible design, the method further includes:
[0017] If the secondary table does not contain the field name to be queried and contains at least part of the field name to be displayed, searching the secondary table for at least one corresponding third target row according to the field of the common field name in the at least one first target row;
[0018] The query result is determined according to the field of the to-be-displayed field name in the at least one third target row.
[0019] In a possible design, if the secondary table does not contain the field name to be queried but contains at least part of the field name to be displayed, searching the secondary table for at least one corresponding third target row according to the field of the common field name in the at least one first target row includes:
[0020] If the secondary table does not contain the field name to be queried, contains at least part of the field name to be displayed, and the query is not a paging query, searching the secondary table for at least one corresponding third target row according to the common field name in the at least one first target row;
[0021] The method further comprises:
[0022] If the secondary table does not contain the field name to be queried, contains at least part of the field name to be displayed, and the query is a paging query, then the number of single-page display items and the starting row information sent by the user end are obtained;
[0023] Filtering at least one fourth target row from the at least one first target row according to the number of displayed items on the single page and the starting row information;
[0024] Searching for at least one corresponding fifth target row in the secondary table according to the field of the common field name in the at least one fourth target row;
[0025] The query result is determined according to the field of the to-be-displayed field name in the at least one fifth target row.
[0026] In a possible design, if the secondary table does not contain the field name to be queried but contains at least part of the field name to be displayed, searching the secondary table for at least one corresponding third target row according to the field of the common field name in the at least one first target row includes:
[0027] If the secondary table does not contain the field name to be queried, contains at least part of the field name to be displayed, and the data volume of the secondary table exceeds a preset threshold, searching the secondary table for at least one corresponding third target row according to the common field name in the at least one first target row;
[0028] Accordingly, the method further includes:
[0029] If the secondary table does not contain the field name to be queried, contains at least part of the field name to be displayed, and the data volume of the secondary table does not exceed a preset threshold, then an associated query method is used for query.
[0030] In one possible design, the method further includes:
[0031] If the secondary table includes some of the field names to be queried and includes at least some of the field names to be displayed, then determining at least one sixth target row in the secondary table, wherein the field of the field name to be queried appearing in the at least one sixth target row satisfies the corresponding constraint condition;
[0032] The query result is determined according to the field of the to-be-displayed field name in the at least one sixth target row and the field of the to-be-displayed field name in the at least one first target row.
[0033] In one possible design, determining the main table from the at least one first data table includes:
[0034] When the number of the first data table is 1, determining that the first data table is a main table;
[0035] When the number of the first data tables is greater than 1, the data volume corresponding to each first data table is determined, and the main table is determined according to the data volume.
[0036] In a second aspect, the present application provides a data query device, comprising:
[0037] An acquisition module, used to acquire query conditions and field names to be displayed, wherein the query conditions include at least one field name to be queried and constraint conditions corresponding to each field name to be queried;
[0038] a determination module, configured to determine at least one first data table related to the query condition and at least one second data table related to the field name to be displayed, and determine a primary table from the at least one first data table, wherein the data tables other than the primary table in the first data table and the second data table are secondary tables; the field names contained in both the primary table and the secondary table are common field names;
[0039] A search module is used to determine at least one first target row in the main table, where the field of the field name to be queried in the first target row satisfies the corresponding constraint condition; if the secondary table contains some of the field names to be queried and does not contain the field name to be displayed, then for each first target row, search the secondary table for at least one corresponding second target row according to the field corresponding to the common field name in the target row; if the field of the field name to be queried in any second target row found satisfies the corresponding constraint condition, then add the field of the field name to be displayed in the first target row to the query result;
[0040] An output module is used to output the query result.
[0041] In a third aspect, an embodiment of the present application provides an electronic device, comprising: at least one processor and a memory; the memory stores computer execution instructions; the at least one processor executes the computer execution instructions stored in the memory, so that the at least one processor executes the data query method described in the first aspect and various possible designs of the first aspect.
[0042] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer execution instructions are stored. When a processor executes the computer execution instructions, the data query method described in the first aspect and various possible designs of the first aspect is implemented.
[0043] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program. When the computer program is executed by a processor, it implements the data query method described in the first aspect and various possible designs of the first aspect.
[0044] The present application provides a data query method, device, electronic device, storage medium and program product. In the method, the secondary table contains some field names to be queried but does not contain field names to be displayed, indicating that the significance of querying the secondary table is to further constrain the query result of the main table. In this case, the main table is first queried to obtain the query result of the main table. The query result of the main table is a collection of multiple first target rows. For each first target row, the secondary table is queried according to the field corresponding to the common field name in the first target row to obtain the second target row. The second target row can be one or more. As long as the field of the field name to be queried in a second target row satisfies the corresponding constraint condition, it means that the first target row satisfies the query condition. There is no need to continue to query other second target rows. The second target row corresponding to the next first target row can be directly queried, thereby reducing the number of queries, reducing the query load of the database, and improving query efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0046] Figure 1 An application scenario diagram provided for an embodiment of the present application;
[0047] Figure 2 A schematic diagram of the processing flow of the server provided in the embodiment of the present application;
[0048] Figure 3 A flowchart of a data query method provided in an embodiment of the present application;
[0049] Figure 4 A schematic diagram of the structure of a data query device provided in an embodiment of the present application;
[0050] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.
[0051] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0052] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0053] It should be noted that the collection, storage, use, processing, transmission, provision and disclosure of financial data or user data and other information involved in the technical solution of this application are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals. The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards, and provide corresponding operation portals for users to choose to authorize or refuse.
[0054] In most current business processing systems, there are a large number of business queries. At the bottom of the database, a business module often corresponds to multiple data tables. The back-end server needs to obtain data from multiple data tables when processing these query requests.
[0055] At present, the query method generally performs a database association query, that is, the query conditions of multiple tables are associated by using join in the query statement.
[0056] However, the use of associated query method seems to have few query statements and simple implementation. When the amount of data in multiple data tables involved in the associated query is not large, the problem is not obvious. However, when the amount of data in the data table increases to a certain extent, it will greatly waste database resources and cause a sharp decline in database query performance. In the worst case, it will cause the query time to increase and the system delay to increase. In the worst case, it will cause the data table to be locked and cause the database service to crash.
[0057] In view of this, the present application provides a data query method, which can obtain query conditions and field names to be displayed, wherein the query conditions include at least one field name to be queried and constraints corresponding to each field name to be queried; determine at least one first data table related to the query conditions, and at least one second data table related to the field name to be displayed, and determine a main table from the at least one first data table, and the data tables other than the main table in the first data table and the second data table are sub-tables; determine the common field names of the main table and the sub-table, and determine at least one first target row in the main table, and the field of the field name to be queried appearing in the at least one first target row satisfies the corresponding constraint conditions; if the sub-table contains some of the field names to be queried and does not contain the field name to be displayed, then for each first target row, search the sub-table for the corresponding at least one second target row according to the field corresponding to the common field name in the target row, if the field of the field name to be queried appearing in any second target row of the at least one second target row found satisfies the corresponding constraint conditions. If the corresponding constraint condition is satisfied, at least one field of the field name to be displayed in the first target row is added to the query result; the query result is output, and the secondary table contains some of the field names to be queried but does not contain the field name to be displayed, indicating that the significance of querying the secondary table is to further constrain the query result of the main table. In this case, the main table is first queried to obtain the query result of the main table. The query result of the main table is a collection of multiple first target rows. For each first target row, the secondary table is queried according to the field corresponding to the common field name in the first target row to obtain a second target row. The second target row can be one or more. As long as the field of the field name to be queried in a second target row satisfies the corresponding constraint condition, it means that the first target row meets the query condition, and there is no need to continue to query other second target rows. The second target row corresponding to the next first target row can be directly queried, thereby reducing the number of queries, reducing the query load of the database, and improving the query efficiency.
[0058] Figure 1 An application scenario diagram provided for an embodiment of the present application, such as Figure 1 As shown, the data query system includes a user terminal and a server. The user enters the query conditions and the field names to be displayed on the user terminal. The query conditions include at least one field name to be queried and the constraint conditions corresponding to each field name to be queried. For example, the query conditions are: age is greater than 20 years old and the score is greater than 60 points, and the field names to be displayed are: name, student number. After the user completes the input, click the OK button, and the user terminal sends the query conditions and the field names to be displayed to the server. After receiving the query conditions, the server queries the database according to the query conditions and the field names to be displayed to obtain the query results. The query results are shown in Table 1.
[0059] Table 1
[0060] Student ID Name 01 open** 02 king**
[0061] The server sends the query results to the client, and the client displays the query results on the page after receiving them so that the user can view them.
[0062] Figure 2 A schematic diagram of the processing flow of the server provided in the embodiment of the present application is as follows: Figure 2 As shown, the server first determines a first data table related to the query condition and a second data table related to the field name to be displayed, wherein both the first data table and the second data table can be one or more, then determines a main table from the first data table, and the table other than the main table is a secondary table; determines the common field name of the main table and the secondary table, and queries the main table according to the query condition related to the main table to determine the first target row in the main table, wherein the first target row can also be one or more, and the field of the field name to be queried appearing in the first target row meets the corresponding constraint condition; on the premise that the secondary table contains some of the field names to be queried and does not contain the field name to be displayed, for each first target row, according to the field corresponding to the common field name in the target row, search for the corresponding second target row in the secondary table, if the field of the field name to be queried appearing in any second target row of at least one second target row found meets the corresponding constraint condition, then the field of the field name to be displayed in the first target row is added to the query result, and the remaining second target rows corresponding to the first target row are no longer queried, and the query result is output.
[0063] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0064] Figure 3 This is a flow chart of a data query method provided in an embodiment of the present application. The execution subject of this embodiment can be any device with data processing function. This application uses the server as the execution subject for specific description. Figure 3 As shown, a data query method provided in an embodiment of the present application may include:
[0065] Step 301: Obtain query conditions and field names to be displayed, wherein the query conditions include at least one field name to be queried and constraint conditions corresponding to each field name to be queried.
[0066] Specifically, the user enters the query conditions and the names of the fields to be displayed on the user side. The query conditions include at least one field name to be queried and the constraints corresponding to each field name to be queried. For example, the query conditions are: age is greater than 20 years old and the score is greater than 60 points, where the field names to be queried in the query conditions are age and score, and the field names to be displayed are: name and student number. After the user completes the input, clicks the OK button, and the user side sends the query conditions and the field names to be displayed to the server, and the server obtains the query conditions and the field names to be displayed.
[0067] Step 302: determine at least one first data table related to the query condition and at least one second data table related to the field name to be displayed, and determine a main table from the at least one first data table, and the data tables other than the main table in the first and second data tables are sub-tables; the field names contained in both the main table and the sub-table are common field names.
[0068] Specifically, after the server obtains the query conditions and the names of the fields to be displayed, it determines at least one first data table related to the query conditions "age greater than 20 years old and score greater than 60 points", the first data table is an age table and a score table, the age table is shown in Table 2, and the score table is shown in Table 3, and then determines at least one second data table related to the field names to be displayed "name, student number", the second data table is the "age table".
[0069] Table 2
[0070] Student ID Name Age / years 01 open** 21 02 king** 22 03 plum** 18 04 Zhao** 17
[0071] Table 3
[0072] Student ID suject Grade / Score 01 Language 71 01 math 55 02 Language 43 02 math 82 03 Language 72 03 math 80 04 Language 95 04 math 59
[0073] Determine that the age table in the first data table is the main table, and the tables in the first and second data tables other than the main table, i.e., the age table, are sub-tables. Therefore, the sub-table is the grade table, and determine that the common field name of the age table and the grade table is the student ID.
[0074] Optionally, determining the main table from the at least one first data table includes:
[0075] When the number of the first data table is 1, determining that the first data table is a main table;
[0076] When the number of the first data tables is greater than 1, the data volume corresponding to each first data table is determined, and the main table is determined according to the data volume.
[0077] Specifically, when the number of first data tables is 1, the first data table is determined to be the main table. When the number of first data tables is greater than , the data volume corresponding to each first data table is determined, wherein the first data table with the largest data volume is the main table.
[0078] The main table is usually the starting point of the query. When the query conditions involve only one data table, that is, when the number of the first data table is 1, this data table is the main table. When the query conditions involve two data tables, that is, when the number of the first data tables is 2, any first data table can be used as the main table. However, when the first data table with a larger amount of data is used as the main table, the query process will start from the first data table with a larger amount of data, and filter out useful information from the main table, which can discard more useless information, reduce the number of times useless information appears repeatedly in subsequent query processes, and improve overall query efficiency.
[0079] Step 303, determine at least one first target row in the main table, the field of the field name to be queried appearing in the first target row meets the corresponding constraint condition, if the sub-table contains some of the field names to be queried and does not contain the field name to be displayed, then for each first target row, search for at least one corresponding second target row in the sub-table according to the field corresponding to the common field name in the target row, if the field of the field name to be queried appearing in any second target row found meets the corresponding constraint condition, then add the field of the field name to be displayed in the first target row to the query result.
[0080] Specifically, the age table is queried according to the query condition "age greater than 20 years old" corresponding to the age table, and at least one first target row is obtained. The at least one first target row is shown in Table 4, and the field name "age" to be queried appearing in the first target row satisfies the corresponding constraint condition "greater than 20 years old".
[0081] Table 4
[0082] 01 open** 21 02 king** 22
[0083] When the secondary table (grade table) contains some of the field names to be queried "grades" but does not contain the field names to be displayed "student number, name", first target the first row, "01, Zhang**, 21", and search for at least one corresponding second target row in the secondary table (grade table) according to the field "01" corresponding to the common field name in the target row. The at least one second target row is shown in Table 5.
[0084] Table 5
[0085] 01 Language 71 01 math 55
[0086] For the first second target row, "01, Chinese, 71", the field "71" of the field name to be queried in the second target row meets the corresponding constraint condition "the score is greater than 60 points", then the field "01, Zhang**" of the field name to be displayed in the first target row is added to the query results, and there is no need to query other second target rows, "01, Mathematics, 55".
[0087] Then, for the next first target row "02, Wang**, 22", at least one corresponding second target row is searched in the score table according to the field "02" corresponding to the common field name in the target row. The at least one second target row is shown in Table 6.
[0088] Table 6
[0089] 02 Language 43 02 math 82
[0090] For the first second target row, "02, Chinese, 43", the field "43" corresponding to the field name to be queried in the second target row does not meet the corresponding constraint condition "the score is greater than 60 points", then for the second second target row "02, Mathematics, 82", the field "82" corresponding to the name to be queried in the second target row meets the corresponding constraint condition "the score is greater than 60 points", then the field "02, Wang**" of the field name to be displayed in the first target row is added to the query results.
[0091] The final query results are shown in Table 1.
[0092] In another example, the query condition entered by the user is "the message processing time is before 0:00 on March 20, 2024 and the recipient is node a", and the field name to be displayed is "message processing time, message number", and at least one first data table related to the query condition is determined. The first data table is the message timetable and the message receiving and receiving table, where the message timetable is shown in Table 7.
[0093] Table 7
[0094] Message number Message processing time 01 2024.3.18,7:00 02 2024.3.22,18:00 03 2024.3.21,7:00 04 2024.3.19,9:00
[0095] The message reception and reception table is shown in Table 8.
[0096] Table 8
[0097] Message number Message Type Initiator Receiver 01 Type I c a 02 Type II a b 03 Type II c a 04 Type I a c
[0098] The message schedule is determined as the main table, the message receiving table is determined as the secondary table, and the common field name of the message schedule and the message receiving table is the message number.
[0099] The message schedule is queried according to the query condition "message processing time is before 0:00 on March 20, 2024" corresponding to the message schedule, and at least one first target row is obtained. The at least one first target row is shown in Table 9, and the field name to be queried "message processing time" appearing in the first target row satisfies the corresponding constraint condition "before 0:00 on March 20, 2024".
[0100] Table 9
[0101] Message number Message processing time 01 2024.3.18,7:00 04 2024.3.19,9:00
[0102] When the sub-table (message receiving and listing table) contains some of the field names to be queried "recipient" and does not contain the field names to be displayed "message processing time, message number", first target the first target row, "01, 2024.3.18, 7:00", and search for at least one corresponding second target row in the sub-table (message receiving and listing table) according to the field "01" corresponding to the common field name in the target row. The at least one second target row is shown in Table 10.
[0103] Table 10
[0104] 01 Type I c a
[0105] If the field "a" of the field name to be queried in the second target row satisfies the corresponding constraint condition "the receiver is node a", the field "01, 2024.3.18, 7:00" of the field name to be displayed in the first target row is added to the query result.
[0106] For the second first target row, "04, 2024.3.19, 9:00", according to the field "04" corresponding to the common field name in the target row, search for at least one corresponding second target row in the sub-table (message receiving and receiving table), and the at least one second target row is shown in Table 11.
[0107] Table 11
[0108] 04 Type I a c
[0109] If the field "c" of the field name to be queried that appears in the second target row does not satisfy the corresponding constraint condition "the receiver is node a", there is no need to add the field of the field name to be displayed in the first target row to the query result.
[0110] The query results are shown in Table 12.
[0111] Table 12
[0112] Message number Message processing time 01 2024.3.18,7:00
[0113] Optionally, at least one first target row in the main table is determined, and the field of the field name to be queried appearing in the first target row satisfies the corresponding constraint condition; if the secondary table contains some of the field names to be queried and does not contain the field name to be displayed, then for each first target row, at least one corresponding second target row is searched in the secondary table according to the field corresponding to the common field name in the target row; if the field of the field name to be queried appearing in any second target row found satisfies the corresponding constraint condition, then the field of the field name to be displayed in the first target row is added to the query result, including:
[0114] Generate a first query statement according to the field names to be queried and the corresponding constraints that appear in the main table;
[0115] Generate a second query statement according to the field name to be queried and the corresponding constraint condition appearing in the secondary table;
[0116] Add the second query statement and the common field name to an EXISTS statement, and connect the obtained statement with the first query statement using AND to obtain a target query statement;
[0117] The target query statement is used to query the main table and the secondary table to obtain the query result.
[0118] For example, referring to the above query condition of "age greater than 20 years old and score greater than 60 points", the names of the fields to be displayed are "name, student number", the main table is the age table, and the sub-table is the score table.
[0119] According to the field name "age" to be queried in the main table (age table) and the corresponding constraint condition "greater than 20 years old", the first query statement is generated, that is, SELECT student number, name FROM age table a WHERE a.age>20.
[0120] According to the field name "score" to be queried in the secondary table (score table) and the corresponding constraint condition "greater than 60 points", the second query statement is generated, that is, SELECT student number FROM score table b WHERE b.score>60.
[0121] Add the second query statement and the public field name "student number" to the EXISTS statement, and the resulting statement is "EXISTS(SELECT student number FROM grade table b WHERE b.grade>60AND b.student number=a.student number)". Connect the resulting statement with the first query statement with AND to obtain the target query statement, i.e. SELECT*FROM age table a WHERE a.age>20AND EXISTS(SELECT student number FROM grade table bWHERE b.grade>60AND b.student number=a.student number).
[0122] Use the target query statement to query the main table and the secondary table to obtain the query results.
[0123] In this way, by avoiding the use of associated queries and using the EXISTS statement in the query condition clause to implement condition filtering, query time can be saved and query efficiency can be improved.
[0124] Step 304: output the query result.
[0125] Specifically, the server sends the query result to the user end, and the user end displays the query result after receiving the query result so that the user can view the query result.
[0126] The secondary table contains some field names to be queried but does not contain field names to be displayed, which means that the significance of querying the secondary table is to further constrain the query results of the main table. In this case, the main table is queried first to obtain the query results of the main table. The query results of the main table are a collection of multiple first target rows. For each first target row, the secondary table is queried according to the fields corresponding to the common field names in the first target row to obtain the second target row. The second target row can be one or more. As long as the fields of the field names to be queried in a second target row meet the corresponding constraints, it means that the first target row meets the query conditions. There is no need to continue querying other second target rows. The second target row corresponding to the next first target row can be queried directly, thereby reducing the number of queries, reducing the query load of the database, and improving query efficiency.
[0127] Optionally, the data query method provided by the present application further includes:
[0128] If the secondary table does not contain the field name to be queried and contains at least part of the field name to be displayed, searching the secondary table for at least one corresponding third target row according to the field of the common field name in the at least one first target row;
[0129] The query result is determined according to the field of the to-be-displayed field name in the at least one third target row.
[0130] Specifically, if the sub-table does not contain the field name to be queried and contains at least part of the field name to be displayed, then the corresponding at least one third target row is searched in the sub-table according to the field of the common field name in at least one first target row; the query result is determined according to the field of the field name to be displayed in at least one third target row.
[0131] If the secondary table does not contain the field name to be queried but contains all the field names to be displayed, searching the secondary table for at least one corresponding third target row according to the field of the common field name in at least one first target row;
[0132] Add the field with the field name to be displayed in at least one third target row to the query result.
[0133] For example, the query condition is "age is greater than 20 years old", the field name to be queried is "age", the first data table determined according to the field name to be queried is the age table, the age table is shown in Table 2, the corresponding field names to be displayed are "student number, name, score", the second data table determined according to the fields to be displayed is the age table and the score table, the score table is shown in Table 3. The age table is the main table, and the score table is the secondary table.
[0134] The main table is queried using the constraint condition “greater than 20 years old” corresponding to the field name “age” to be queried corresponding to the main table to determine at least one first target row in the main table. The at least one first target row is shown in Table 4.
[0135] At this time, the secondary table (grade table) does not contain the field name to be queried "age", but contains some field names to be displayed "student number, grade". According to the fields (01, 02) corresponding to the common field name (student number) in at least one first target row, the secondary table (grade table) is queried for at least one corresponding third target row. The at least one third target row is shown in Table 13.
[0136] Table 13
[0137] 01 Language 71 01 math 55 02 Language 43 02 math 82
[0138] The fields "01, 71; 01, 55; 02, 43; 02, 82" of the field names to be displayed in at least one third target row and the fields (01, Zhang**; 02, Wang**) of the field names to be displayed in at least one first target row are added to the query results, and the final query results are shown in Table 14.
[0139] Table 14
[0140] Student ID Name Grade / Score 01 open** 71 01 open** 55 02 king** 43 02 king** 82
[0141] In this way, the secondary table does not contain the field name to be queried, but contains at least part of the field name to be displayed, which means that the significance of the secondary table is to supplement the query result of the primary table. When encountering the above situation, the prior art adopts the method of associated query. The data association process can be summarized as taking n records from the primary table, and then merging the taken n records with each row of m data in the secondary table. Then the product of n*m can reflect the data processing level of the associated query. When the data levels of the primary table and the secondary table are both large, the query will be very time-consuming and inefficient.
[0142] In addition, there will be subqueries in the query result column of the main table. The subqueries correspond to the constraints of the secondary table. Since the subqueries are executed one by one for the results of the main table query when implemented in the database, when these subqueries are very complex queries themselves, the accumulated query time of multiple executions is also very substantial.
[0143] Therefore, changing the associated query and subquery into a multi-step single-table query greatly reduces the query load of the database, improves efficiency, and reduces time consumption.
[0144] Optionally, the data query method provided by the present application further includes:
[0145] If the secondary table includes some of the field names to be queried and includes at least some of the field names to be displayed, then determining at least one sixth target row in the secondary table, wherein the field of the field name to be queried appearing in the at least one sixth target row satisfies the corresponding constraint condition;
[0146] The query result is determined according to the field of the to-be-displayed field name in the at least one sixth target row and the field of the to-be-displayed field name in the at least one first target row.
[0147] For example, the query condition is "age is greater than 20 years old and score is greater than 60 points", the field name to be queried is "age, score", the first data table determined according to the field name to be queried is the age table and the score table, the age table is shown in Table 2, the score table is shown in Table 3, the corresponding field name to be displayed is "student number, name, score", and the second data table determined according to the field to be displayed is the age table and the score table. At this time, both the age table and the score table can be used as the main table. In order to be consistent with the above embodiment, the age table is also used as the main table and the score table is used as the secondary table.
[0148] The main table is queried using the constraint condition “greater than 20 years old” corresponding to the field name “age” to be queried corresponding to the main table to determine at least one first target row in the main table. The at least one first target row is shown in Table 4.
[0149] The sub-table is queried using the constraint condition “greater than 60 points” corresponding to the field name “score” to be queried corresponding to the sub-table to determine at least one sixth target row in the sub-table. The at least one sixth target row is shown in Table 15.
[0150] Table 15
[0151] 01 Language 71 02 math 82 03 Language 72 03 math 80 04 Language 95
[0152] The fields of the field names to be displayed in at least one sixth target row are shown in Table 16.
[0153] Table 16
[0154] 01 71 02 82 03 72 03 80 04 95
[0155] The fields of the field names to be displayed in at least one first target row are shown in Table 17.
[0156] Table 17
[0157] 01 open** 02 king**
[0158] Since the query condition is "age greater than 20 years old and score greater than 60 points", the fields in Table 16 and Table 17 are operated with AND, and the final query result is shown in Table 18.
[0159] Table 18
[0160] Student ID Name score 01 open** 71 02 king** 82
[0161] If the query condition is "age greater than 20 years old or score greater than 60 points", the fields in Table 16 and Table 17 are ORed, and the final query result is shown in Table 19.
[0162] Table 19
[0163] Student ID Name score 01 open** 71 02 king** 82 03 plum** 72 03 plum** 80 04 Zhao** 95
[0164] In this way, when the secondary table contains some field names to be queried and at least some field names to be displayed, the main table and the secondary table can be queried separately to obtain their own query results, and then the respective query results are merged to obtain the query results. For tables with relatively large amounts of data, using a single table query can greatly improve query efficiency and reduce time consumption.
[0165] Optionally, if the secondary table does not contain the field name to be queried but contains at least part of the field name to be displayed, searching the secondary table for at least one corresponding third target row according to the field of the common field name in the at least one first target row includes:
[0166] If the secondary table does not contain the field name to be queried, contains at least part of the field name to be displayed, and the query is not a paging query, searching the secondary table for at least one corresponding third target row according to the common field name in the at least one first target row;
[0167] Accordingly, the data query method provided by the present application also includes:
[0168] If the secondary table does not contain the field name to be queried, contains at least part of the field name to be displayed, and the query is a paging query, then the number of single-page display items and the starting row information sent by the user end are obtained;
[0169] Filtering at least one fourth target row from the at least one first target row according to the number of displayed items on the single page and the starting row information;
[0170] Searching for at least one corresponding fifth target row in the secondary table according to the field of the common field name in the at least one fourth target row;
[0171] The query result is determined according to the field of the to-be-displayed field name in the at least one fifth target row.
[0172] Specifically, if the secondary table does not contain the field name to be queried but contains at least part of the field name to be displayed and the current query is not a paging query, then the secondary table is searched for at least one corresponding third target row according to the common field name in at least one first target row.
[0173] When the secondary table does not contain the field name to be queried, contains at least part of the field name to be displayed, and this query is a paging query, it is necessary to obtain the single-page display number and the starting row information sent by the user end.
[0174] Optionally, after the user selects the query conditions and the field names to be displayed, when the confirmation button is clicked, the user end can send the query conditions, the field names to be displayed, the number of items displayed on a single page and the starting row information to the server together. Alternatively, the user end can first send the query conditions, the field names to be displayed, and the paging query instructions to the server. When the server determines that the secondary table does not contain the field names to be queried, contains at least part of the field names to be displayed and the current query is a paging query, it sends an instruction to the user end to obtain the number of items displayed on a single page and the starting row information. After the user receives the acquisition instruction, the user sends the number of items displayed on a single page and the starting row information to the server.
[0175] When the secondary table does not contain the field name to be queried, contains part of the field name to be displayed, and this query is a paginated query, the field of the field name to be displayed in at least one fourth target row and the field of the field name to be displayed in at least one fifth target row are added to the query results.
[0176] When the secondary table does not contain the field name to be queried, contains all the field names to be displayed, and the current query is a paging query, at least one field of the field name to be displayed in the fifth target row is added to the query result.
[0177] Referring to the above query condition of "age greater than 20 years old", the names of the fields to be displayed are "student number, name, and grades", the main table is the age table, and the secondary table is the grade table. Determine at least one first target row of the main table as shown in Table 4.
[0178] Assuming that the number of single-page display items obtained is "1" and the starting row information is "first row", at least one fourth target row is filtered out from at least one first target row, as shown in Table 20.
[0179] Table 20
[0180] 01 open** 21
[0181] According to the field "01" of the common field name in at least one fourth target row, search for at least one corresponding fifth target row in the secondary table (score table), as shown in Table 21.
[0182] Table 21
[0183] 01 Language 71 01 math 55
[0184] Add the fields (01, 71; 01, 55) of the field names to be displayed in at least one fourth target row and the fields (01, Zhang**) of the field names to be displayed in at least one fifth target row to the query results, and the query results are shown in Table 22.
[0185] Table 22
[0186] Student ID Name Grade / Score 01 open** 71 01 open** 55
[0187] In this way, when performing paging queries, the data to be displayed on the homepage is queried first, and when the user triggers the query structure display of the next page, the query of the next page of data continues, rather than querying all the required data at once and then paging, which improves the response speed and query efficiency during querying, and also improves the user's experience of querying data. In addition, converting related queries can avoid table locks that cause database service downtime.
[0188] Optionally, if the secondary table does not contain the field name to be queried but contains at least part of the field name to be displayed, searching the secondary table for at least one corresponding third target row according to the field of the common field name in the at least one first target row includes:
[0189] If the secondary table does not contain the field name to be queried, contains at least part of the field name to be displayed, and the data volume of the secondary table exceeds a preset threshold, searching the secondary table for at least one corresponding third target row according to the common field name in the at least one first target row;
[0190] Accordingly, the data query method provided by the present application also includes:
[0191] If the secondary table does not contain the field name to be queried, contains at least part of the field name to be displayed, and the data volume of the secondary table does not exceed a preset threshold, then an associated query method is used for query.
[0192] Specifically, when the secondary table does not contain the field name to be queried but contains at least part of the field name to be displayed, it can be determined whether the data volume of the secondary table exceeds a preset threshold. If it exceeds the preset threshold, subsequent operations are performed according to the above embodiment.
[0193] If the threshold is not exceeded, a correlation query is used for query, and the query statement corresponding to the correlation query contains join.
[0194] In this way, when the amount of data in the secondary table is not large, the time consumption of querying by using the associated query and multi-step single-table query method is not much different, and the query statement of the associated query is simpler, so the associated query is used. When the amount of data in the secondary table is relatively large, the multi-step single-table query method can greatly save time and improve query efficiency. Therefore, the multi-step single-table query method is used for querying.
[0195] Corresponding to the above data query method, an embodiment of the present application also provides a data query device. Figure 4 This is a schematic diagram of the structure of a data query device provided in an embodiment of the present application. Figure 4 As shown, the device comprises:
[0196] The acquisition module 401 is used to acquire query conditions and field names to be displayed, wherein the query conditions include at least one field name to be queried and constraint conditions corresponding to each field name to be queried;
[0197] The determination module 402 is used to determine at least one first data table related to the query condition and at least one second data table related to the field name to be displayed, and determine a primary table from the at least one first data table, and the data tables other than the primary table in the first data table and the second data table are secondary tables; the field names contained in both the primary table and the secondary table are common field names;
[0198] The search module 403 is used to determine at least one first target row in the main table, where the field of the field name to be queried in the first target row satisfies the corresponding constraint condition. If the secondary table contains some of the field names to be queried and does not contain the field name to be displayed, then for each first target row, according to the field corresponding to the common field name in the target row, search for at least one corresponding second target row in the secondary table. If the field of the field name to be queried in any second target row found satisfies the corresponding constraint condition, then the field of the field name to be displayed in the first target row is added to the query result.
[0199] The output module 404 is used to output the query result.
[0200] Optionally, the search module 403 is specifically used for:
[0201] Generate a first query statement according to the field names to be queried and the corresponding constraints that appear in the main table;
[0202] Generate a second query statement according to the field name to be queried and the corresponding constraint condition appearing in the secondary table;
[0203] Add the second query statement and the common field name to an EXISTS statement, and connect the obtained statement with the first query statement using AND to obtain a target query statement;
[0204] The target query statement is used to query the main table and the secondary table to obtain the query result.
[0205] Optionally, the search module 403 is further used to:
[0206] If the secondary table does not contain the field name to be queried and contains at least part of the field name to be displayed, searching the secondary table for at least one corresponding third target row according to the field of the common field name in the at least one first target row;
[0207] The query result is determined according to the field of the to-be-displayed field name in the at least one third target row.
[0208] Optionally, the search module 403, when the secondary table does not contain the field name to be queried but contains at least part of the field name to be displayed, searches the secondary table for at least one corresponding third target row according to the common field name in the at least one first target row, specifically for:
[0209] If the secondary table does not contain the field name to be queried, contains at least part of the field name to be displayed, and the query is not a paging query, searching the secondary table for at least one corresponding third target row according to the common field name in the at least one first target row;
[0210] Accordingly, the search module 403 is further used for:
[0211] If the secondary table does not contain the field name to be queried, contains at least part of the field name to be displayed, and the query is a paging query, then the number of single-page display items and the starting row information sent by the user end are obtained;
[0212] Filtering at least one fourth target row from the at least one first target row according to the number of displayed items on the single page and the starting row information;
[0213] Searching for at least one corresponding fifth target row in the secondary table according to the field of the common field name in the at least one fourth target row;
[0214] The query result is determined according to the field of the to-be-displayed field name in the at least one fifth target row.
[0215] Optionally, the search module 403, when the secondary table does not contain the field name to be queried but contains at least part of the field name to be displayed, searches the secondary table for at least one corresponding third target row according to the common field name in the at least one first target row, specifically for:
[0216] If the secondary table does not contain the field name to be queried, contains at least part of the field name to be displayed, and the data volume of the secondary table exceeds a preset threshold, searching the secondary table for at least one corresponding third target row according to the common field name in the at least one first target row;
[0217] Accordingly, the search module 403 is further used for:
[0218] If the secondary table does not contain the field name to be queried, contains at least part of the field name to be displayed, and the data volume of the secondary table does not exceed a preset threshold, then an associated query method is used for query.
[0219] Optionally, the search module 403 is further used to:
[0220] If the secondary table includes some of the field names to be queried and includes at least some of the field names to be displayed, then determining at least one sixth target row in the secondary table, wherein the field of the field name to be queried appearing in the at least one sixth target row satisfies the corresponding constraint condition;
[0221] The query result is determined according to the field of the to-be-displayed field name in the at least one sixth target row and the field of the to-be-displayed field name in the at least one first target row.
[0222] Optionally, when determining the main table from the at least one first data table, the determining module 402 is specifically configured to:
[0223] When the number of the first data table is 1, determining that the first data table is a main table;
[0224] When the number of the first data tables is greater than 1, the data volume corresponding to each first data table is determined, and the main table is determined according to the data volume.
[0225] The specific implementation principle and effect of the data query device provided in the embodiment of the present application can be found in the aforementioned embodiment and will not be repeated here.
[0226] It should be noted that it should be understood that the division of the various modules of the above device is only a division of logical functions. In actual implementation, they can be fully or partially integrated into one physical entity, or they can be physically separated. And these modules can all be implemented in the form of software called by processing elements; they can also be all implemented in the form of hardware; some modules can also be implemented in the form of software called by processing elements, and some modules can be implemented in the form of hardware. Each module can be a separately established processing element, or it can be integrated in a chip of the above device. In addition, it can also be stored in the memory of the above device in the form of program code, and called and executed by a processing element of the above device. The functions of each module. In addition, all or part of these modules can be integrated together, or they can be implemented independently. The processing element here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each module above can be completed by an integrated logic circuit of hardware in the processor element or instructions in the form of software.
[0227] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 5 As shown, the electronic device of this embodiment may include:
[0228] at least one processor 501; and
[0229] A memory 502 communicatively connected to the at least one processor;
[0230] The memory 502 stores instructions that can be executed by the at least one processor 501, and the instructions are executed by the at least one processor 501 to enable the electronic device to execute the method described in any of the above embodiments.
[0231] Optionally, the memory 502 may be independent or integrated with the processor 501 .
[0232] The implementation principle and technical effects of the electronic device provided in this embodiment can be found in the aforementioned embodiments and will not be described in detail here.
[0233] An embodiment of the present application also provides a chip for executing instructions, which is used to execute the technical solution of the data query method in the above embodiment.
[0234] The embodiment of the present application further provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are executed on a computer, the computer executes the technical solution of the data query method of the above embodiment.
[0235] An embodiment of the present application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. At least one processor can read the computer program from the computer-readable storage medium. When at least one processor executes the computer program, it can implement the technical solution of the data query method in the above embodiment.
[0236] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules is only a logical function division, and there may be other division methods in actual implementation, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.
[0237] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to implement the solution of this embodiment.
[0238] In addition, each functional module in each embodiment of the present application can be integrated into one processing unit, or each module can exist physically separately, or two or more modules can be integrated into one unit. The above-mentioned module-composed unit can be implemented in the form of hardware or in the form of hardware plus software functional units.
[0239] The above-mentioned integrated module implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform some steps of the methods of various embodiments of the present application.
[0240] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be implemented by a combination of hardware and software modules in the processor.
[0241] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk memory, and may also be a USB flash drive, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk, etc.
[0242] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.
[0243] The above storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The storage medium can be any available medium that can be accessed by a general or special purpose computer.
[0244] An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the storage medium can also exist as discrete components in an electronic control unit or a main control device.
[0245] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0246] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A data query method, characterized in that: include: Obtain query conditions and field names to be displayed, wherein the query conditions include at least one field name to be queried and constraint conditions corresponding to each field name to be queried; Determine at least one first data table related to the query condition and at least one second data table related to the field name to be displayed, and determine a main table from the at least one first data table, and the data tables other than the main table in the first data table and the second data table are sub-tables; the field names contained in both the main table and the sub-table are common field names; Determine at least one first target row in the main table, the field of the field name to be queried appearing in the first target row satisfies the corresponding constraint condition, if the secondary table contains some of the field names to be queried and does not contain the field name to be displayed, then for each first target row, search for at least one corresponding second target row in the secondary table according to the field corresponding to the common field name in the target row, if the field of the field name to be queried appearing in any second target row found satisfies the corresponding constraint condition, then add the field of the field name to be displayed in the first target row to the query result; The query result is output.
2. The method according to claim 1, characterized in that Determine at least one first target row in the main table, the field of the field name to be queried appearing in the first target row meets the corresponding constraint condition, if the secondary table contains some of the field names to be queried and does not contain the field name to be displayed, then for each first target row, search for at least one corresponding second target row in the secondary table according to the field corresponding to the common field name in the target row, if the field of the field name to be queried appearing in any second target row found meets the corresponding constraint condition, then add the field of the field name to be displayed in the first target row to the query result, including: Generate a first query statement according to the field names to be queried and the corresponding constraints that appear in the main table; Generate a second query statement according to the field name to be queried and the corresponding constraint condition appearing in the secondary table; Add the second query statement and the common field name to an EXISTS statement, and connect the obtained statement with the first query statement using AND to obtain a target query statement; The target query statement is used to query the main table and the secondary table to obtain the query result.
3. The method according to claim 1, characterized in that The method further comprises: If the secondary table does not contain the field name to be queried and contains at least part of the field name to be displayed, searching the secondary table for at least one corresponding third target row according to the field of the common field name in the at least one first target row; The query result is determined according to the field of the to-be-displayed field name in the at least one third target row.
4. The method according to claim 3, characterized in that If the secondary table does not contain the field name to be queried but contains at least part of the field name to be displayed, searching the secondary table for at least one corresponding third target row according to the field of the common field name in the at least one first target row, including: If the secondary table does not contain the field name to be queried, contains at least part of the field name to be displayed, and the query is not a paging query, searching the secondary table for at least one corresponding third target row according to the common field name in the at least one first target row; The method further comprises: If the secondary table does not contain the field name to be queried, contains at least part of the field name to be displayed, and the query is a paging query, then the number of single-page display items and the starting row information sent by the user end are obtained; Filtering at least one fourth target row from the at least one first target row according to the number of displayed items on the single page and the starting row information; Searching for at least one corresponding fifth target row in the secondary table according to the field of the common field name in the at least one fourth target row; The query result is determined according to the field of the to-be-displayed field name in the at least one fifth target row.
5. The method according to claim 3, characterized in that: If the secondary table does not contain the field name to be queried but contains at least part of the field name to be displayed, searching the secondary table for at least one corresponding third target row according to the field of the common field name in the at least one first target row, including: If the secondary table does not contain the field name to be queried, contains at least part of the field name to be displayed, and the data volume of the secondary table exceeds a preset threshold, searching the secondary table for at least one corresponding third target row according to the common field name in the at least one first target row; Accordingly, the method further includes: If the secondary table does not contain the field name to be queried, contains at least part of the field name to be displayed, and the data volume of the secondary table does not exceed a preset threshold, then an associated query method is used for query.
6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: If the secondary table includes some of the field names to be queried and includes at least some of the field names to be displayed, then determining at least one sixth target row in the secondary table, wherein the field of the field name to be queried appearing in the at least one sixth target row satisfies the corresponding constraint condition; The query result is determined according to the field of the to-be-displayed field name in the at least one sixth target row and the field of the to-be-displayed field name in the at least one first target row.
7. The method according to claim 1, characterized in that Determining a main table from the at least one first data table includes: When the number of the first data table is 1, determining that the first data table is a main table; When the number of the first data tables is greater than 1, the data volume corresponding to each first data table is determined, and the main table is determined according to the data volume.
8. A data query device, characterized in that: include: An acquisition module, used to acquire query conditions and field names to be displayed, wherein the query conditions include at least one field name to be queried and constraint conditions corresponding to each field name to be queried; a determination module, configured to determine at least one first data table related to the query condition and at least one second data table related to the field name to be displayed, and determine a primary table from the at least one first data table, wherein the data tables other than the primary table in the first data table and the second data table are secondary tables; the field names contained in both the primary table and the secondary table are common field names; A search module is used to determine at least one first target row in the main table, where the field of the field name to be queried in the first target row satisfies the corresponding constraint condition; if the secondary table contains some of the field names to be queried and does not contain the field name to be displayed, then for each first target row, search the secondary table for at least one corresponding second target row according to the field corresponding to the common field name in the target row; if the field of the field name to be queried in any second target row found satisfies the corresponding constraint condition, then add the field of the field name to be displayed in the first target row to the query result; An output module is used to output the query result.
9. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the processor executes the computer-executable instructions, the method according to any one of claims 1 to 7 is implemented.
11. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Data isolation implementation method based on SQL statement interception analysis technology
CN110941628A
Data query method and device, equipment and storage medium
CN116910085A
Generating an index for a table in a database background
US20160147751A1
