Data retrieval method, apparatus and electronic device
By explicitly converting the field types of the target data in the relational database, the problem of index failure caused by implicit type conversion is solved, and data retrieval efficiency is improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CHINA CONSTRUCTION BANK
- Filing Date
- 2022-09-15
- Publication Date
- 2026-06-09
AI Technical Summary
In relational databases, implicit type conversions can cause indexes to become invalid during the retrieval process, affecting data retrieval efficiency.
By receiving database statements and parsing search conditions, the target data's field types are explicitly converted to match those of the other data when the field types of the two sides are inconsistent. The database statements are then updated for retrieval, thus avoiding implicit type conversion.
It improves the efficiency of data retrieval in relational databases, avoids index invalidation issues, and enhances database query performance.
Smart Images

Figure CN115422232B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data analysis, and more particularly to a data retrieval method, apparatus, and electronic device. Background Technology
[0002] A relational database is a database that uses a relational model to organize data. It stores data in rows and columns; these rows and columns are called tables, and a set of tables makes up the database. Users can retrieve data from the database through queries. In a relational database, an index is a separate, physical storage structure that sorts the values of one or more columns in the database. It is a collection of values from one or more columns in a table, and indexes allow for fast retrieval of fields within the database.
[0003] Currently, relational databases have implicit type conversion functionality during the retrieval process, which can cause the indexes corresponding to fields to become invalid, thus affecting the efficiency of data retrieval. Summary of the Invention
[0004] This application provides a data retrieval method, apparatus, and electronic device to address the issue that implicit type conversion in relational databases can cause indexes corresponding to fields to become invalid, thereby affecting the efficiency of data retrieval.
[0005] The first aspect of this application provides a data retrieval method, comprising: receiving a database statement; parsing the database statement to obtain retrieval conditions, the retrieval conditions including: a comparison operator and data on both sides of the comparison operator; when the field types of the data on both sides are inconsistent, converting the field type of the target data to make the field type of the target data consistent with that of the other data, the target data being one of the data on both sides, and at least one of the data on both sides having index information in the database; updating the database statement according to the converted target data, and retrieving the target data in the database using the updated database statement.
[0006] In one embodiment of this application, when the field types of the data on both sides are inconsistent, converting the field type of the target data includes: determining whether at least one piece of data on both sides is in a field identifier set, wherein at least one piece of data is a field name, the field identifier set includes: multiple field names and the data table name of the field names, and the field names in the field identifier set have corresponding index information; if so, when the field types of the data on both sides are inconsistent, converting the field type of the target data.
[0007] In one embodiment of this application, when the field types of the data on both sides are inconsistent, the field type of the target data is converted, including: when the data on one side is a first field name and the data on the other side is a parameter, the field type of the parameter is converted to the field type of the first field name.
[0008] In one embodiment of this application, when the field types of the data on both sides are inconsistent, the field type of the target data is converted, including: when the data on one side is a second field name and the data on the other side is a third field name, the target data is determined from the second field name and the third field name, wherein the target data has a higher priority than the other field name, the field name in the field identifier set has a higher priority than the field name not in the field identifier set, and the field name with a smaller data volume has a higher priority than the field name with a larger data volume; the field type of the target data is converted.
[0009] In one embodiment of this application, the search criteria further include: an alias for the data table. If the field types of the data on both sides are inconsistent, before converting the field type of the target data, the criteria further include: determining the target name of the data table corresponding to the alias of the data table; and updating the search criteria using the target name of the data table.
[0010] In one embodiment of this application, before receiving the database statement, the method further includes: determining the target field in the database and the target data table to which the target field belongs, wherein the field type of the target field is different from the field type of the corresponding code in the system, and the target field has index information in the database; constructing a field identifier for the target field based on the target field and the target data table, wherein the field identifier includes: the field name of the target field and the target name of the data table; and storing the field identifier in a field identifier set.
[0011] In one embodiment of this application, determining a target field in a database and the target data table to which the target field belongs includes: obtaining index information of a database field when the system is started or in the configuration center of a microservice; and determining the target field and the target data table to which the target field belongs among the fields with index information.
[0012] A second aspect of this application provides a data retrieval device, comprising:
[0013] The receiving module is used to receive database statements;
[0014] The parsing module is used to parse database statements to obtain search conditions, which include comparison operators and the data on both sides of the comparison operators.
[0015] The conversion module is used to convert the field types of the target data when the field types of the data on both sides are inconsistent, so that the field types of the target data and the other data are consistent. The target data is one of the data on both sides, and at least one of the data on both sides has index information in the database.
[0016] The update module is used to update the database statements based on the transformed target data, and to retrieve the target data from the database using the updated database statements.
[0017] In one embodiment of this application, the conversion module is specifically used to: determine whether at least one piece of data in the data on both sides is in the field identifier set, wherein at least one piece of data is a field name, the field identifier set includes: multiple field names and the data table name of the field names, and the field names in the field identifier set have corresponding index information; if so, in the case that the field types of the data on both sides are inconsistent, convert the field type of the target data.
[0018] In one embodiment of this application, the conversion module is specifically used to: convert the field type of the parameter to the field type of the first field name when the data on one side is a first field name and the data on the other side is a parameter.
[0019] In one embodiment of this application, the conversion module is specifically used to: determine target data from the second field name and the third field name when the data on one side is a second field name and the data on the other side is a third field name, wherein the target data has a higher priority than the other field name, the field name in the field identifier set has a higher priority than the field name not in the field identifier set, and the field name with a smaller data volume has a higher priority than the field name with a larger data volume; and convert the field type of the target data.
[0020] In one embodiment of this application, the search criteria further include: an alias for the data table. The update module is further configured to determine the target name of the data table corresponding to the alias of the data table before converting the field type of the target data in the case where the field types of the data on both sides are inconsistent; and update the search criteria using the target name of the data table.
[0021] In one embodiment of this application, the data retrieval device further includes:
[0022] The determination module is used to determine the target field in the database and the target data table to which the target field belongs. The field type of the target field is different from the field type of the corresponding code in the system. The target field has index information in the database.
[0023] The building module is used to construct the field identifier of the target field based on the target field and the target data table. The field identifier includes: the field name of the target field and the target name of the data table.
[0024] The storage module is used to store field identifiers in a field identifier set.
[0025] In one embodiment of this application, the determining module is specifically used for:
[0026] Retrieve index information of database fields when the system starts up or in the microservice configuration center;
[0027] In fields with index information, determine the target field and the target data table to which the target field belongs.
[0028] A third aspect of this application provides an electronic device, including a memory and a processor; wherein,
[0029] The memory is used to store program code;
[0030] The processor is used to call program code to implement any of the above data retrieval methods.
[0031] A fourth aspect of this application provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, an electronic device performs any of the data retrieval methods described above.
[0032] The fifth aspect of this application provides a computer program product having a computer program stored thereon, wherein when the computer program is executed by a processor, it causes an electronic device to perform any of the above-described data retrieval methods.
[0033] As can be seen from the above technical solution, the embodiments of this application receive a database statement; parse the database statement to obtain search conditions, which include: a comparison operator and the data on both sides of the comparison operator; when the field types of the data on both sides are inconsistent, convert the field type of the target data to make the field type of the target data consistent with that of the other data, where the target data is one of the data on both sides, and at least one of the data on both sides has index information in the database; update the database statement according to the converted target data, and use the updated database statement to retrieve the target data in the database. By explicitly converting the database statement before retrieval to make the field types of the data on both sides of the comparison operator consistent, implicit type conversion during data retrieval can be avoided. Therefore, this application can improve the retrieval efficiency of data in relational databases. Attached Figure Description
[0034] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0035] Figure 1 This is a schematic diagram illustrating an application scenario of the data retrieval method provided in this application;
[0036] Figure 2 This is a flowchart of the steps of a data retrieval method provided in an embodiment of this application;
[0037] Figure 3 This is a flowchart of the steps of a data retrieval method provided in another embodiment of this application;
[0038] Figure 4 This is a structural block diagram of a data retrieval device provided in an embodiment of this application;
[0039] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0040] To enable those skilled in the art to better understand the solutions of this application, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.
[0041] The principles and spirit of this application will be explained in detail below with reference to several representative embodiments.
[0042] The inventors discovered that, in order to ensure the successful execution of database execution scripts, when operators and operands are used together, relational database engines automatically perform type conversion on the data in the relational database to ensure operational compatibility and implement implicit field type conversion. However, since implicit field type conversion is an additional type conversion of the data in the database, it will cause the index corresponding to the field to become invalid when the database execution script is executed.
[0043] Furthermore, to improve database retrieval efficiency, the most effective and direct method is to create indexes for frequently used fields in the database. This reduces the utilization of the central processing unit (CPU) and input / output (I / O) at the cost of additional write and storage space, thereby increasing the speed of data retrieval in the database. When a database table stores a large amount of data, the retrieval efficiency of an indexed table can be thousands of times greater than that of an unindexed table. However, when an index becomes invalid, it will cause a decrease in database retrieval efficiency and may even cause the database server's CPU utilization to reach 100%, leading to database program crashes. The implicit types in relational databases, due to their hidden nature, can lead developers to overlook implicit types during relational database development, resulting in index invalidation.
[0044] To address the aforementioned problems, this application provides a data retrieval method. The method involves receiving a database statement; parsing the database statement to obtain retrieval conditions, including a comparison operator and the data on both sides of the comparison operator; converting the field types of the target data to match the field types of the other data when the field types of the data on both sides are inconsistent; the target data being one of the data on both sides, with at least one data on both sides having index information in the database; updating the database statement based on the converted target data; and retrieving the target data from the database using the updated database statement. By explicitly converting the database statement before retrieval to ensure consistent field types on both sides of the comparison operator, implicit type conversion during data retrieval can be avoided. Therefore, this application can improve the retrieval efficiency of data in relational databases.
[0045] After introducing the basic principles of this application, the various non-limiting embodiments of this application will be described in detail below.
[0046] First refer to Figure 1 The diagram illustrates an application scenario for the data retrieval method provided in this application, including a terminal device 11 and a server 12. The terminal device 11 sends a retrieval request to the server 12. The server 12 is configured with a relational database. The server 12 converts the retrieval request into a corresponding database statement, retrieves the corresponding data from the relational database based on the database statement, and sends it to the terminal device 11.
[0047] In this application, database statements can be updated to avoid implicit conversions in relational databases and improve the efficiency of data retrieval in relational databases.
[0048] The technical solution of this application will now be described in detail through specific embodiments. It should be noted that the following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.
[0049] Reference Figure 2 The following is a flowchart of the steps of a data retrieval method provided in an embodiment of this application. The data retrieval method specifically includes the following steps:
[0050] S201, Receive database statement.
[0051] The database used is a relational database, including MySQL, Oracle, or SQL Server. Database statements include: simple queries, subqueries, table joins, combined queries, insert statements, update statements, delete statements, and create statements.
[0052] For example, a database statement like: select * from t_base_user where telephone = 12345678901 means to query the user table for data with the telephone number 12345678901.
[0053] Furthermore, receiving database statements includes: receiving a retrieval request sent by the terminal device, and generating a database statement based on the retrieval request. For example, if the retrieval request sent by the terminal device is to search for user information for the telephone number 12345678901, then the database statement generated based on the retrieval request would be: select * from t_base_user where telephone = 12345678901.
[0054] S202, parse the database statement to obtain the search criteria.
[0055] The search criteria include a comparison operator and the data on both sides of the comparison operator. Specifically, the comparison operators include: equal to "=", greater than ">", less than "<", greater than or equal to "≥", less than or equal to "≤", not equal to "!=", least "LEAST", greatest "GREATEST", and "AND", etc.
[0056] Furthermore, parsing the database yields multiple search criteria, each of which undergoes subsequent processing. For example, City X has three schools: AA Elementary School, BB Middle School, and CC Middle School. Data for all three schools is stored in a single database, with each school corresponding to a separate data table. Therefore, AA Elementary School corresponds to the AA Elementary School data table, BB Middle School to the BB Middle School data table, and CC Middle School to the CC Middle School data table. Additionally, each data table includes the school's organizational structure. For instance, BB Middle School includes grades 7 through 12, with grade 7 comprising classes 1 through 6. Therefore, BB Middle School includes information such as the students' names, dates of birth, home addresses, contact information, and exam rankings for each class.
[0057] Furthermore, parsing the database statement yields a search condition that could be "telephone=12345678901". Alternatively, two search conditions can be obtained: search condition 1 "telephone=12345678901", search condition 2 "BB Middle school AND 20" (meaning searching for students ranked 20th in exams at BB Middle School), and search condition 3 "grade > Junior Two" (meaning searching for students above the second year of junior high school). Multiple search conditions can be combined to form a search list.
[0058] S203: When the field types of the data on both sides are inconsistent, convert the field type of the target data to make the field type of the target data consistent with that of the other data.
[0059] The target data is one of the data on both sides, and at least one of the data on both sides has index information in the database.
[0060] Furthermore, when there are multiple search criteria, S203 is executed for each search criterion. The conversion of the target data's field types is performed using database functions corresponding to the relational database engine, such as to_char and to_number.
[0061] In addition, field types include: text, int, tinyint, datetime, vachar (a character type), and char (a character type).
[0062] In this application embodiment, only when one or two pieces of data on both sides of the comparison operator have index information in the database is it necessary to convert the field type of one of the data. This is to avoid implicit conversion during database statement execution when the field types of the data on both sides of the comparison operator are different, which would cause the index information to become invalid. This application converts the field types of the data in the search conditions before the database statement is executed, thus avoiding index invalidation.
[0063] For example, for search condition 1 "telephone=12345678901", a database function can be used to convert "telephone" into a numeric type. The converted numeric value represents the meaning of "telephone number". For example, the converted search condition 1 is "2456=12345678901", where "2456" is the result after converting "telephone" to a numeric type. Alternatively, a database function can also be used to convert "12345678901" into a character type.
[0064] Among them, the search condition 2 "BB Middle school AND 20" means BB Middle School and 20th place. Database functions can be used to convert "BB Middle school" into a numeric type if "BB Middle school" is the target data. The converted numeric value represents the meaning of "BB Middle School". If "20" is the target data, database functions can be used to convert "20" into a character type.
[0065] In addition, if the data on both sides of the comparison operator ">" in search condition 3 "grade>Junior Two" are both of type character, no conversion will be performed.
[0066] S204, Update the database statement based on the transformed target data, and retrieve the target data from the database using the updated database statement.
[0067] This involves replacing the original target data in the database statement with the transformed target data to obtain the updated database statement. Since the data fields on both sides of the comparison operator in the updated database statement have the same data type, there will be no implicit conversion problem when retrieving target data in the database using the updated database statement. Therefore, the index information of the fields will not be invalidated, which can improve retrieval efficiency.
[0068] For example, if the database statement is: select * from t_base_user where telephone = 12345678901, where the data "telephone" is converted to "2456" after field type conversion, then the database statement is updated with "2456" to obtain the updated database statement "select * from t_base_user where 2456 = 12345678901". Then, the updated database statement "select * from t_base_user where 2456 = 12345678901" is used to retrieve the target data with the phone number "12345678901".
[0069] This application, through its embodiments, receives a database statement; parses the database statement to obtain search conditions, which include a comparison operator and the data on both sides of the comparison operator; when the field types of the data on both sides are inconsistent, it converts the field type of the target data to make the field type of the target data consistent with that of the other data, wherein the target data is one of the data on both sides, and at least one of the data on both sides has index information in the database; it updates the database statement based on the converted target data, and uses the updated database statement to retrieve the target data in the database. By explicitly converting the database statement before retrieval to make the field types of the data on both sides of the comparison operator consistent, implicit type conversion during data retrieval can be avoided. Therefore, this application can improve the retrieval efficiency of data in relational databases.
[0070] Based on the above embodiments, this application also provides a data retrieval method, as detailed below. Figure 3 The data retrieval method specifically includes the following steps:
[0071] S301, determine the target field in the database and the target data table to which the target field belongs.
[0072] The target field has a different field type than the corresponding code field type in the system, and the target field has index information in the database.
[0073] In this embodiment of the application, determining the target field in the database and the target data table to which the target field belongs includes: obtaining the index information of the database field when the system is started or in the configuration center of the microservice; and determining the target field and the target data table to which the target field belongs among the fields with index information.
[0074] Specifically, the system first obtains the data structure and index information from the database. Specifically, when the target application's system starts, it automatically connects to the database corresponding to the target application, reads the database table structure to obtain the field type of each field, and reads the index information of all fields created in the data table after automatically connecting to the database.
[0075] Optionally, if the target application adopts a microservice architecture, the field type and index information of each field can be obtained from the microservice's configuration center. When adopting a microservice architecture, it is not limited to obtaining the field type and index information of each field at the system startup of the target application; the field type and index information of each field can be obtained from the microservice's configuration center under any circumstances.
[0076] Furthermore, for each acquired field, the target field and its corresponding target data table are determined. This target field is one where implicit type conversions in the database might cause index information to become invalid. First, for each acquired field, an intermediate field with index information is identified. Then, the field type of this intermediate field in the database is compared with the corresponding field type in the system code. If they do not match, the intermediate field is determined as the target field. Specifically, when the field type of an intermediate field does not match the corresponding field type in the system code, implicit type conversion issues will occur when executing database statements. Therefore, the intermediate field with a different field type than the one in the system code is used as the target field.
[0077] For example, the field "BB Middle school" is a character type in the database, but the system code indicates that "BB Middle School" should be represented by a number. Therefore, "BB Middle school" in the database is more likely to be implicitly converted when used for retrieval, so it is set as the target field.
[0078] S302, construct the field identifier of the target field based on the target field and the target data table.
[0079] The field identifier includes the field name of the target field and the target table name. In a database, each field has a field name, and each table has a table name. Therefore, the field identifier for the target field is constructed using the field name of the target field and the table name of the table to which the target field belongs. For example, `tableName_columnName`, where `tableName` identifies the data name and `columnName` represents the field name.
[0080] The index information also includes composite indexes. Specifically, a database index is a data structure that improves the speed of data retrieval operations on a data table at the cost of additional write and storage space. Similar to a book's table of contents, page numbers allow quick access to desired content. A composite index is an index composed of multiple fields. For example, if fields 'a' and 'b' are frequently used for queries with the condition 'a+b', a composite index on fields 'a' and 'b' can be created to improve retrieval efficiency. Therefore, for multiple target fields with composite indexes, the field identifiers are "tableName_columnName1, tableName_columnName2, ..., tableName_columnName N", where columnName1, columnName2 to columnNameN correspond to multiple target fields that form a composite index, and N is a positive integer.
[0081] S303, store the field identifier in the field identifier set.
[0082] The field identifier set includes multiple field identifiers.
[0083] S304, receives database statements.
[0084] The specific implementation process parameter S201 for this step will not be elaborated here.
[0085] S305, parse the database statement to obtain the search criteria.
[0086] The specific implementation process of this step is described in S202 and will not be repeated here.
[0087] S306, Determine the target name of the data table corresponding to the alias of the data table.
[0088] The search criteria also include: table aliases. During the parsing process, the target name or alias of the data table in the database statement is parsed. For example, if the target name of the data table is "BB Middle School", the alias of the data table is "BB School".
[0089] In this embodiment of the application, the corresponding target name can be determined after parsing the alias of the data table based on the pre-established correspondence between the alias of the data table and the target name of the data table.
[0090] S307, Update the search criteria using the target name of the data table.
[0091] After parsing the database statements, multiple search criteria are obtained, which together form a search list. The target name of the data table can be used to replace the alias of the data table in the search criteria.
[0092] S308, determine whether at least one piece of data from both sides is in the field identifier set.
[0093] At least one piece of data is a field name. The field identifier set includes: multiple field names and the data table name of the field names. The field names in the field identifier set have corresponding index information. If yes, execute S309; otherwise, end the process.
[0094] S309: When the field types of the data on both sides are inconsistent, convert the field type of the target data.
[0095] In one embodiment, when the field types of the data on both sides are inconsistent, converting the field type of the target data includes: when the data on one side is a first field name and the data on the other side is a parameter, converting the field type of the parameter to the field type of the first field name.
[0096] In this application, the first field name is a fixed field name in the database statement, such as "telephone, school, grade". Parameters refer to variable parameters selected by the user, such as "12345678901, Junior Two". Since the first field name and the parameter have different field types, and the first field name and / or the parameter belong to the target field, the field type of the parameter is converted to be the same as the field type of the first field name. For example, if the field type of the parameter "12345678901" is numeric, and the field type of the first field name "telephone" is character, then the field type of the parameter "12345678901" is converted from numeric to character. In this embodiment, it is preferable to convert the field type of the parameter so that the field type corresponding to the fixed field "first field name" in the database statement does not change, thereby facilitating data retrieval in the database and improving retrieval efficiency.
[0097] In another embodiment, when the field types of the data on both sides are inconsistent, the field type of the target data is converted, including: when the data on one side is a second field name and the data on the other side is a third field name, the target data is determined from the second field name and the third field name, wherein the target data has a higher priority than the other field name, the field name in the field identifier set has a higher priority than the field name not in the field identifier set, and the field name with a smaller data volume has a higher priority than the field name with a larger data volume; the field type of the target data is converted.
[0098] For example, referring to search condition 2 "BB Middle school AND 20", the second field name "BBMiddle school" and the third field name "20" are both inherent fields in the database. If the second field name is in the field identifier set, but the third field name is not in the field identifier set, it means that the field corresponding to the third field name does not have an index. Therefore, converting the third field name will not cause the index to become invalid. So, the field name that is not in the field identifier set should be converted first.
[0099] If both the second and third field names are in the field identifier set, then the data volume of the second and third field names is compared, and the field name with the smaller data volume is converted first, which can improve conversion efficiency. For example,
[0100] Search condition 2 "BB Middle school AND 20" has two field names, "BB Middle school" and "20" and are both in the field identifier set. Since the amount of data for the third field name "30" is smaller, the third field name "30" will be converted first.
[0101] S310, update the database statement based on the transformed target data, and retrieve the target data from the database using the updated database statement.
[0102] The specific implementation process of this step is described in S204 and will not be repeated here.
[0103] In the embodiments of this application, S301 to S303 may be executed during the system startup phase of the target application, and S304 to S310 may be executed during the system running phase of the target application.
[0104] This application eliminates the need for developers to monitor database field types, ensuring that all search conditions do not lead to database index failure due to implicit data type conversions. Furthermore, it requires no code modification; after converting data field types, it automatically updates the database statements with the converted target data for data retrieval.
[0105] The following are embodiments of the apparatus described in this application, which can be used to execute the embodiments of the method described in this application. For details not disclosed in the apparatus embodiments of this application, please refer to the embodiments of the method described in this application.
[0106] Reference Figure 4 This is a schematic diagram of a data retrieval device provided in an embodiment of this application. The data retrieval device 400 includes: a receiving module 401, a parsing module 402, a conversion module 403, and an updating module 404. Wherein:
[0107] Receiver module 401 is used to receive database statements;
[0108] Parsing module 402 is used to parse database statements to obtain search conditions, which include: comparison operators and the data on both sides of the comparison operators;
[0109] The conversion module 403 is used to convert the field type of the target data when the field types of the data on both sides are inconsistent, so that the field types of the target data and the other data are consistent. The target data is one of the data on both sides, and at least one of the data on both sides has index information in the database.
[0110] The update module 404 is used to update the database statement based on the transformed target data, and to retrieve the target data from the database using the updated database statement.
[0111] In one embodiment of this application, the conversion module 403 is specifically used to: determine whether at least one piece of data in the data on both sides is in the field identifier set, wherein at least one piece of data is a field name, the field identifier set includes: multiple field names and the data table name of the field names, and the field names in the field identifier set have corresponding index information; if so, in the case that the field types of the data on both sides are inconsistent, convert the field type of the target data.
[0112] In one embodiment of this application, the conversion module 403 is specifically used to: convert the field type of the parameter to the field type of the first field name when the data on one side is a first field name and the data on the other side is a parameter.
[0113] In one embodiment of this application, the conversion module 403 is specifically used to: determine target data from the second field name and the third field name when the data on one side is a second field name and the data on the other side is a third field name, wherein the target data has a higher priority than the other field name, the field name in the field identifier set has a higher priority than the field name not in the field identifier set, and the field name with a smaller data volume has a higher priority than the field name with a larger data volume; and convert the field type of the target data.
[0114] In one embodiment of this application, the search criteria further include: an alias for the data table. The update module is further configured to determine the target name of the data table corresponding to the alias of the data table before converting the field type of the target data in the case where the field types of the data on both sides are inconsistent; and update the search criteria using the target name of the data table.
[0115] In one embodiment of this application, it further includes:
[0116] The determination module (not shown) is used to determine the target field in the database and the target data table to which the target field belongs. The field type of the target field is different from the field type of the corresponding code in the system. The target field has index information in the database.
[0117] A construction module (not shown) is used to construct the field identifier of the target field based on the target field and the target data table. The field identifier includes: the field name of the target field and the target name of the data table.
[0118] A storage module (not shown) is used to store field identifiers in a field identifier set.
[0119] In one embodiment of this application, the determining module is specifically used to: obtain index information of database fields when the system starts or in the configuration center of a microservice; and determine the target field and the target data table to which the target field belongs among the fields with index information.
[0120] For details on the specific workings of each module of the data retrieval device, please refer to the embodiments of the data retrieval method described above; they will not be repeated here.
[0121] It should be noted that the division of the various modules in the above device is merely a logical functional division. In actual implementation, they can be fully or partially integrated into a single physical entity, or they can be physically separated. Furthermore, these modules can be implemented entirely in software via processing element calls; they can be fully implemented in hardware; or some modules can be implemented by processing element calls to software, while others are implemented in hardware. For example, a processing module can be a separate processing element, or it can be integrated into a chip within the device. Alternatively, it can be stored as program code in the device's memory, and its functions can be called and executed by a processing element. The implementation of other modules is similar. Moreover, these modules can be fully or partially integrated together, or they can be implemented independently. The processing element here can be an integrated circuit with signal processing capabilities. During implementation, each step of the above method or each of the above modules can be completed through integrated logic circuits in the hardware of the processor element or through software instructions.
[0122] For example, these modules can be one or more integrated circuits configured to implement the above methods, such as one or more application-specific integrated circuits (ASICs), one or more digital signal processors (DSPs), or one or more field-programmable gate arrays (FPGAs). As another example, when a module is implemented using processing element scheduler code, the processing element can be a general-purpose processor, such as a central processing unit (CPU) or other processor capable of calling program code. Furthermore, these modules can be integrated together to implement a system-on-a-chip (SOC).
[0123] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. A computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the flow or function according to the embodiments of this application is generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., a solid-state disk (SSD)).
[0124] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Specifically, this electronic device can be a bank server platform. Figure 5As shown, the electronic device may include: a processor 51, a memory 52, a communication interface 53, and a system bus 54. The memory 52 and the communication interface 53 are connected to the processor 51 via the system bus 54 and communicate with each other. The memory 52 stores computer-executed instructions, and the communication interface 53 communicates with other devices. When the processor 51 executes the aforementioned computer-executed instructions, it implements the scheme described in the above embodiment.
[0125] Should Figure 5 The system bus mentioned can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This system bus can be divided into address bus, data bus, control bus, etc. For ease of representation, only one thick line is used in the diagram, but this does not indicate that there is only one bus or one type of bus. The communication interface is used to enable communication between the database access device and other devices (e.g., user terminals, read-write databases, and read-only databases). Memory may include random access memory (RAM) and may also include non-volatile memory, such as at least one disk storage device.
[0126] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0127] Optionally, embodiments of this application also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, causes an electronic device to perform the method as described in the above embodiments.
[0128] Optionally, embodiments of this application also provide a computer program product having a computer program stored thereon, wherein when the computer program is executed by a processor, it causes an electronic device to perform the method described above.
[0129] In this application, "at least one" means one or more, and "more than one" means two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The character " / " generally indicates an "or" relationship between the preceding and following related objects; in formulas, the character " / " indicates a "division" relationship. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one of a, b, or c can represent: a, b, c, ab, ac, bc, or abc, where a, b, and c can be single or multiple.
[0130] It is understood that the various numerical designations used in the embodiments of this application are merely for descriptive convenience and are not intended to limit the scope of the embodiments of this application. In the embodiments of this application, the order of the above-mentioned process numbers does not imply the order of execution; the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0131] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.
Claims
1. A data retrieval method, characterized in that, include: Receive database statements; The database statement is parsed to obtain search conditions, which include: a comparison operator and the data on both sides of the comparison operator; If the field types of the data on both sides are inconsistent, the field type of the target data is converted to make the field type of the target data consistent with that of the other data. The target data is one of the data on both sides, and at least one of the data on both sides has index information in the database. The database statement is updated based on the transformed target data, and the target data is retrieved from the database using the updated database statement; When the field types of the data on both sides are inconsistent, converting the field type of the target data includes: Determine whether at least one piece of data from both sides is in the field identifier set, wherein the at least one piece of data is a field name, and the field identifier set includes: multiple field names and the data table name of the field name, and the field name in the field identifier set has corresponding index information; If, in the case where the data on one side is the second field name and the data on the other side is the third field name, the target data is determined from the second field name and the third field name, wherein the target data has a higher priority than the other field name, the field name in the field identifier set has a higher priority than the field name not in the field identifier set, and the field name with a smaller data volume has a higher priority than the field name with a larger data volume. Convert the field types of the target data.
2. The data retrieval method according to claim 1, characterized in that, If the field types of the data on both sides are inconsistent, converting the field type of the target data further includes: If the data on one side is the name of the first field and the data on the other side is a parameter, the field type of the parameter is converted to the field type of the name of the first field.
3. The data retrieval method according to any one of claims 1 to 2, characterized in that, The search criteria also include: aliases for the data table; and before converting the field types of the target data in cases where the field types of the data on both sides are inconsistent, the criteria further include: Determine the target name of the data table corresponding to the alias of the data table; The search criteria are updated using the target name from the data table.
4. The data retrieval method according to any one of claims 1 to 2, characterized in that, Before receiving the database statement, the following is also included: The target field in the database and the target data table to which the target field belongs are determined. The field type of the target field is different from the field type of the corresponding code in the system. The target field has index information in the database. Based on the target field and the target data table, construct a field identifier for the target field, wherein the field identifier includes: the field name of the target field and the target name of the data table; The field identifier is stored in the field identifier set.
5. The data retrieval method according to claim 4, characterized in that, The step of determining the target field in the database and the target data table to which the target field belongs includes: Retrieve index information of database fields when the system starts up or in the microservice configuration center; In the fields with index information, determine the target field and the target data table to which the target field belongs.
6. A data retrieval device, characterized in that, include: The receiving module is used to receive database statements; The parsing module is used to parse the database statement to obtain the search conditions, which include: a comparison operator and the data on both sides of the comparison operator; A conversion module is used to convert the field type of the target data to be consistent with the field type of the other data when the field types of the data on both sides are inconsistent. The target data is one of the data on both sides, and at least one of the data on both sides has index information in the database. The update module is used to update the database statement based on the transformed target data, and to retrieve the target data in the database using the updated database statement; The conversion module is specifically used for: Determine whether at least one piece of data from both sides is in the field identifier set, wherein the at least one piece of data is a field name, and the field identifier set includes: multiple field names and the data table name of the field name, and the field name in the field identifier set has corresponding index information; If, in the case where the data on one side is the second field name and the data on the other side is the third field name, the target data is determined from the second field name and the third field name, wherein the target data has a higher priority than the other field name, the field name in the field identifier set has a higher priority than the field name not in the field identifier set, and the field name with a smaller data volume has a higher priority than the field name with a larger data volume. Convert the field types of the target data.
7. The data retrieval device according to claim 6, characterized in that, The conversion module is specifically used to: if, in the case where the data on one side is a first field name and the data on the other side is a parameter, convert the field type of the parameter to the field type of the first field name.
8. The data retrieval device according to any one of claims 6 to 7, characterized in that, The search criteria also include: an alias for the data table. The update module is further configured to, in the case where the field types of the data on both sides are inconsistent, determine the target name of the data table corresponding to the alias of the data table before converting the field type of the target data; and update the search criteria using the target name of the data table.
9. The data retrieval device according to any one of claims 6 to 7, characterized in that, Also includes: The determination module is used to determine the target field in the database and the target data table to which the target field belongs. The field type of the target field is different from the field type of the corresponding code in the system to which it belongs. The target field has index information in the database. A construction module is used to construct a field identifier for the target field based on the target field and the target data table. The field identifier includes: the field name of the target field and the target name of the data table. A storage module is used to store the field identifier in the field identifier set.
10. The data retrieval device according to claim 9, characterized in that, The determining module is specifically used for: Retrieve index information of database fields when the system starts up or in the microservice configuration center; In the fields with index information, determine the target field and the target data table to which the target field belongs.
11. An electronic device, characterized in that, Includes memory and processor; among which, The memory is used to store program code; The processor is used to call the program code to implement the data retrieval method as described in any one of claims 1 to 5.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it causes the electronic device to perform the data retrieval method as described in any one of claims 1 to 5.
13. A computer program product having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it causes the electronic device to perform the data retrieval method as described in any one of claims 1 to 5.