Spatial database and table database query method and device, electronic equipment and storage medium

By identifying and assembling the routing policy information of SQL statements, the problem that JDBC DataSource cannot meet the configuration of flexible routing policy is solved, flexible database query routing is realized, and database query efficiency and flexibility are improved.

CN119166665AInactive Publication Date: 2024-12-20成方金融科技有限公司

Patent Information

Application Number
CN202411670502.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-21
Publication Date
2024-12-20
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The existing JDBC DataSource cannot meet the requirements of flexible routing policy configuration, resulting in the need for continuous adjustment and optimization of routing policies in actual applications, which cannot meet the needs of business development.

Method used

By receiving SQL statements, identifying routing policy information based on predefined routing configuration information, determining database number and data table number, assembling physical SQL statements, and switching to the corresponding data source for execution, realizing flexible routing policy configuration.

Benefits of technology

It realizes flexible routing policy configuration, and can dynamically adjust data source and table configuration according to business needs, improving the flexibility and efficiency of database queries, and avoiding the need for frequent routing policies.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119166665A_ABST
    Figure CN119166665A_ABST
Patent Text Reader

Abstract

The invention provides a sub-database and sub-table database query method and device, electronic equipment and a storage medium, and belongs to the technical field of data processing.The method comprises the steps that SQL statements are received; based on predefined routing configuration information, routing strategy information corresponding to the SQL statement is identified and obtained, and the routing configuration information comprises data source information and routing strategy information; determining a database number and a data table number based on the routing policy information; based on the data table number, assembling to obtain a physical SQL statement; and after switching to a data source corresponding to the database number, executing the physical SQL statement to obtain a database query result. According to the invention, the data source configuration and the routing strategy information are preset through the predefined routing configuration information, and a self-defined routing strategy can be called in the routing configuration information through a specified field, so that flexible routing strategy configuration is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of data processing technology, and in particular to a method, device, electronic device and storage medium for querying a database with separate libraries and tables. Background Art

[0002] With the development of the Internet and mobile Internet, the amount of data in application systems has grown exponentially. If a single database is used for data storage, the read and write capabilities of a single database instance are limited. As the amount of data and concurrent access increase, performance will gradually decline. A large number of read and write operations may lead to I / O bottlenecks, and the scalability of a single database is poor. To solve the above problems, sharded databases came into being. Sharded databases store data in a dispersed manner, making the amount of data in a single database / table smaller to alleviate the performance problems of a single database, thereby achieving the purpose of improving database performance.

[0003] Currently, the database and table sharding components are implemented based on JDBC DataSource, which is a standard interface for connecting to databases in Java applications. Its main functions include data routing and data load balancing. These components effectively solve problems such as database scalability, concurrent access, and data distribution. However, in actual applications, as the business develops, the routing strategy may need to be continuously adjusted and optimized, and JDBC DataSource cannot meet the flexible routing strategy configuration requirements.

[0004] Therefore, there is an urgent need for a method to flexibly configure database routing strategies for sharding. Summary of the invention

[0005] The present invention provides a database query method and device for sub-library and sub-table, an electronic device and a storage medium, which are used to solve the defect that the JDBC DataSource in the prior art cannot meet the flexible routing strategy configuration requirements.

[0006] The present invention provides a database query method for sub-library and sub-table, comprising the following steps: Receive SQL statements; Based on predefined routing configuration information, identify and obtain routing policy information corresponding to the SQL statement, wherein the routing configuration information includes data source information and routing policy information; Based on the routing policy information, determine a database number and a data table number; Based on the data table number, assemble and obtain a physical SQL statement; After switching to the data source corresponding to the database number, the physical SQL statement is executed to obtain the database query result.

[0007] According to a database query method for a sub-library and sub-table provided by the present invention, after switching to the data source corresponding to the database number, executing the physical SQL statement to obtain the database query result includes: After switching to the data source corresponding to the database number, obtaining the data connection of the data source; Based on the data connection, executing the physical SQL statement to obtain an execution result, wherein the execution result includes one or more result sets; If the execution result includes a result set, the result set is used as the database query result; If the execution result includes multiple result sets, the multiple result sets are merged to obtain the database query result.

[0008] According to a database query method for sub-libraries and sub-tables provided by the present invention, the merging of the multiple result sets includes: If the physical SQL statement is a data query language, merging the multiple result sets into a list; If the physical SQL statement contains an aggregate function, a merge algorithm is used to merge multiple lists into one list.

[0009] According to a database query method for sub-libraries and sub-tables provided by the present invention, after receiving the SQL statement, the method further includes: Determine whether the relevant information of the SQL statement is stored in the cache; If the relevant information of the SQL statement is not stored in the cache, the SQL statement is parsed to obtain a SQLStatement, and the SQLStatement is stored in the cache; If the cache stores relevant information of the SQL statement, the SQLStatement is obtained from the cache.

[0010] According to a database query method for sub-libraries and sub-tables provided by the present invention, the method of identifying and obtaining routing policy information corresponding to the SQL statement based on predefined routing configuration information includes: Based on the predefined routing configuration information, the routing policy information corresponding to the SQLStatement corresponding to the SQL statement is obtained.

[0011] According to a database query method for a sub-database and sub-table provided by the present invention, the routing policy information includes a routing field and a routing algorithm, and the determining of a database number and a data table number based on the routing policy information includes: Based on the routing field, the routing algorithm is used to calculate and obtain the database number and data table number corresponding to the SQL statement.

[0012] The present invention also provides a sub-library and sub-table database query device, comprising the following modules: A receiving module, used for receiving SQL statements; An information identification module, used to identify and obtain routing policy information corresponding to the SQL statement based on predefined routing configuration information, wherein the routing configuration information includes data source information and routing policy information; A number determination module, used to determine a database number and a data table number based on the routing policy information; A statement reorganization module, used for assembling and obtaining a physical SQL statement based on the data table number; The statement execution module is used to switch to the data source corresponding to the database number, execute the physical SQL statement, and obtain the database query result.

[0013] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the sub-library and sub-table database query method described above is implemented.

[0014] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the sub-library and sub-table database query method as described above is implemented.

[0015] The present invention also provides a computer program product, including a computer program, which, when executed by a processor, implements any of the above-mentioned database query methods for sub-libraries and sub-tables.

[0016] The method, device, electronic device and storage medium for querying a database with separate libraries and separate tables provided by the present invention receive an SQL statement; based on predefined routing configuration information, identify and obtain routing policy information corresponding to the SQL statement, the routing configuration information includes data source information and routing policy information; based on the routing policy information, determine the database number and data table number; based on the data table number, assemble and obtain a physical SQL statement; after switching to the data source corresponding to the database number, execute the physical SQL statement to obtain a database query result. The present invention pre-sets the data source configuration and routing policy information through predefined routing configuration information, and can call a custom routing policy through a specified field in the routing configuration information to achieve flexible routing policy configuration. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0018] Figure 1 It is a flowchart of the database query method of the sub-library and sub-table provided by the present invention; Figure 2 It is an example flow chart of the sub-library and sub-table database query method provided by the present invention; Figure 3 It is a schematic diagram of the process of merging result sets provided by the present invention; Figure 4 It is a schematic diagram of the SQL meta-information resource cache process provided by the present invention; Figure 5 It is a schematic diagram of the architecture of the sub-library and sub-table database provided by the present invention; Figure 6 It is a structural schematic diagram of the sub-library and sub-table database query device provided by the present invention; Figure 7 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0019] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0020] It should be noted that in the description of the embodiments of the present invention, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "include one..." do not exclude the existence of other identical elements in the process, method, article or device including the elements. The orientation or position relationship indicated by the terms "upper", "lower" and the like is based on the orientation or position relationship shown in the drawings, which is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention. Unless otherwise clearly specified and limited, the terms "installed", "connected" and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be directly connected, or indirectly connected through an intermediate medium, or it can be a connection between two elements. For those skilled in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0021] The terms "first", "second", etc. in this application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.

[0022] Combine the following Figure 1-Figure 7 The invention describes a method, device, electronic device and storage medium for querying a database with separate libraries and tables provided in an embodiment of the invention.

[0023] Figure 1 It is a flowchart of the database query method of the sub-library and sub-table provided by the present invention, such as Figure 1 As shown, the method includes the following: S110, receiving an SQL statement; S120, identifying and obtaining routing policy information corresponding to the SQL statement based on predefined routing configuration information; S130, determining a database number and a data table number based on the routing policy information; S140, assembling and obtaining a physical SQL statement based on the data table number; S150, after switching to the data source corresponding to the database number, execute the physical SQL statement to obtain a database query result.

[0024] It should be noted that the executor of the task construction method provided in the embodiment of the present application may be a server, a computer device, etc.

[0025] Figure 2 is an example flow chart of the database query method for sub-library and sub-table provided by the present invention, such as Figure 2 For ease of understanding, the following embodiments are described using the SQL statement "SELECT FROM T_CUSTOMER WHERE USER_ID = 111" is taken as an example to illustrate the sub-library and sub-table database query method provided by the present invention, wherein the number of sub-libraries is 2 and the number of sub-tables in each library is 8.

[0026] In S120, after receiving the SQL statement, the predefined routing configuration information (data source information, routing policy information) is read to identify the relevant database table in the SQL statement, and then the corresponding routing policy information is identified according to the database table.

[0027] In the embodiment of the present invention, the routing configuration information includes data source information and routing policy information. The data source information is the relevant information of the data source, for example, it may include the data source name, the configuration information of the data source, etc.; the routing policy information is the relevant information of the routing policy, for example, it may include the routing field, the routing algorithm, etc.

[0028] In some embodiments, the routing policy information includes a database table name, a routing field, a routing algorithm, a number of sub-databases, and a number of sub-tables.

[0029] It is understandable that the routing configuration information is defined in XML files, encapsulated into middleware and deployed for use.

[0030] Table 1 Routing configuration information table

[0031] As shown in Table 1 above, an exemplary routing configuration information is given: "system" indicates the configuration information of the middleware; "base_SingleNode" indicates whether it is running on a single node. If it is a single node, database routing cannot be performed; "executor_CorePoolSize" and "executor_MaxPoolSize" indicate the size of the middleware's internal thread pool. You can configure these parameters to meet the needs of parallel processing. "executor_CorePoolSize" is the size of the middleware's core thread pool, and "executor_MaxPoolSize" is the middleware's maximum thread pool. "tables" indicates the list of database tables; "shardingTable" indicates whether the table needs to be routed to a separate database or table. If the value of "shardingTable" is "true", it means that it needs to be routed to a separate database or table; if the value of "shardingTable" is "false", it means that it does not need to be routed to a separate database or table. 0-1"" indicates that the table is in "dn 0", "dn 1" has 2 data nodes in total; "ruleRef" indicates the routing strategy used by the table, and "ruleRef="rule1"" indicates that the table uses the routing strategy "rule1"; "dataNodes" indicates the data node list; where "dataNode name="dn 0-1"" means that the data node has 2 data nodes, and the data node names are "dn 0", "dn 1"; "dataSource" indicates the name of the data source to which each data node belongs, <name> %NODENAME% - 0< / name> " indicates that the data source names are "data node name-0", that is, "dn 0-0", "dn 1-0”; "dataSources" indicates a list of data sources; where "dataSource name="dn (0-1)-0"" means there are two data sources and their names are "dn 0-0", "dn 1-0"; "type="druid"" indicates that the database connection pool type used is Druid; "pool-param id="0"" corresponds to the data source "dn 0-0" configuration information, "pool-param id="1" corresponds to the data source "dn 1-0” configuration information; "rules" indicates the routing policy; "rule id="rule1"" indicates that the routing policy is identified as "rule1"; "subrule" indicates the specific routing field and routing algorithm under the policy, "column" indicates the routing field, "db_algorithm" indicates the sub-database routing algorithm, and "tb_algorithm" indicates the sub-table routing algorithm; "functions" indicates the routing algorithm, where "function id="modfunc1" class="moddb"" indicates that the routing algorithm is identified as "modfunc1", and the specific routing algorithm used is the Java implementation class "moddb" of the modulo mode, "dbCount" indicates the number of sub-databases, and "tbCount" indicates the number of sub-tables in each sub-database; "function id="modfunc2" class="modtb"" indicates that the routing algorithm is identified as "modfunc2", and the specific routing algorithm used is the Java implementation class "modtb" of the modulo mode.

[0032] In S140, after the corresponding database number and data table number are determined, the existing SQL statement is reassembled to obtain a physical SQL statement.

[0033] In S150, the corresponding data source information defined internally is obtained according to the determined database number, and the data source is dynamically switched to obtain the data connection of the data source, and the reassembled physical SQL statement is executed.

[0034] The sub-library and sub-table database query method provided by the embodiment of the present invention receives an SQL statement; based on predefined routing configuration information, identifies and obtains routing policy information corresponding to the SQL statement, the routing configuration information includes data source information and routing policy information; based on the routing policy information, determines the database number and data table number; based on the data table number, assembles and obtains a physical SQL statement; after switching to the data source corresponding to the database number, executes the physical SQL statement to obtain a database query result. The present invention pre-sets the data source configuration and routing policy information through predefined routing configuration information, and can call a custom routing policy through a specified field in the routing configuration information to achieve flexible routing policy configuration.

[0035] In an optional embodiment, after switching to the data source corresponding to the database number, executing the physical SQL statement to obtain the database query result includes: After switching to the data source corresponding to the database number, obtaining the data connection of the data source; Based on the data connection, executing the physical SQL statement to obtain an execution result, wherein the execution result includes one or more result sets; If the execution result includes a result set, the result set is used as the database query result; If the execution result includes multiple result sets, the multiple result sets are merged to obtain the database query result.

[0036] Specifically, after receiving the SQL statement result set ResultSet, each ResultSet result set is merged through the result set processor TaskPostProcessor.

[0037] The database query method for sub-libraries and sub-tables provided in the embodiment of the present invention merges the result sets when they involve result sets of multiple databases or data tables to finally obtain a unified result set, that is, the final database query result.

[0038] In an optional embodiment, the merging of the multiple result sets includes: If the physical SQL statement is a data query language, merging the multiple result sets into a list; If the physical SQL statement contains an aggregate function, a merge algorithm is used to merge multiple lists into one list.

[0039] Figure 3 is a flow chart of the result set merging process provided by the present invention, such as Figure 3 As shown in the figure, if the SQL statement is a Data Manipulation Language (DML) type operation, the merge process is a common result set merge, which will directly affect the cumulative number of rows; if the SQL statement is a Data Query Language (DQL) type operation, the queried result sets ResultSet will be merged into a List object.

[0040] like Figure 3 As shown in the figure, if there are aggregate functions such as OrderBy (sorting) and GroupBy (grouping) in the SQL statement, the data in multiple List objects are merged into a whole List object using the merge algorithm, and the final whole List object is returned to the user.

[0041] The database query method for sub-libraries and sub-tables provided in the embodiment of the present invention combines the result sets in a corresponding manner according to the content of the SQL statement after routing and query execution, so as to facilitate subsequent application use.

[0042] In an optional embodiment, after receiving the SQL statement, the method further includes: Determine whether the relevant information of the SQL statement is stored in the cache; If the relevant information of the SQL statement is not stored in the cache, the SQL statement is parsed to obtain a SQLStatement, and the SQLStatement is stored in the cache; If the cache stores relevant information of the SQL statement, the SQLStatement is obtained from the cache.

[0043] Optionally, store the SQLStatement in a ThreadLocal object of the application.

[0044] Figure 4 The SQL meta-information resource cache process diagram provided by the present invention is as follows: Figure 4 As shown, after receiving the SQL statement, first obtain the JDBC connection ZeusConnection; Create a ZeusPrepareStatement object based on the obtained ZeusConnection; SQL statements are parsed through the SQL statement parser ZeusParserManager and parsed into SQLStatement objects. According to the database type and operation type, they can be divided into MySqlDeleteStatement, MySqlCreateTableStatement, OracleDeleteStatement, OracleCreateTableStatement, etc., to determine ThreadLocal <HashMap<String, SQLStatement> >Whether the object contains relevant meta information of the SQL statement. If so, it is directly obtained from the object. If not, it is directly created and cached. Get the routing information corresponding to the SQL statement meta information SQLStatement through the SQL router ZeusRouterManager; The final real SQL statement is executed through the SQL statement executor ZeusExecutor and the execution result is obtained.

[0045] The database query method for sub-libraries and sub-tables provided in the embodiment of the present invention caches the parsed SQL statement meta-information SQLStatement in the ThreadLocal object of the application. The subsequent re-execution of the SQL statement will directly use the data in the cache, thereby avoiding repeated parsing of SQL statements and saving system resource overhead.

[0046] In an optional embodiment, the identifying and obtaining routing policy information corresponding to the SQL statement based on predefined routing configuration information includes: Based on the predefined routing configuration information, the routing policy information corresponding to the SQLStatement corresponding to the SQL statement is obtained.

[0047] Specifically, select the corresponding router (ZeusHashRouter, ZeusRangeRouter, DefaultZeusRouter) according to the routing method of the SQL statement (hash modulus, range value range, custom); obtain the database and table sharding strategy configured in the SQL statement, including database node information, whether the database is sharded and the number of shards, whether the data table is sharded and the number of shards, and routing fields; calculate the database number and data table number in the SQL statement according to the database and table sharding strategy; find the corresponding database node information based on the obtained database number.

[0048] The sub-library and sub-table database query method provided by the embodiment of the present invention directly obtains the routing policy information corresponding to the cached SQL statement meta-information SQLStatement, thereby saving repeated analysis of SQL statements and saving system resource overhead.

[0049] Based on any of the above embodiments, the routing policy information includes a routing field and a routing algorithm, and the determining the database number and the data table number based on the routing policy information includes: Based on the routing field, the routing algorithm is used to calculate and obtain the database number and data table number corresponding to the SQL statement.

[0050] like Figure 2 As shown, for the SQL statement "SELECT FROM T_CUSTOMER WHERE USER_ID = 111", determine whether the routing algorithm is a modulo type, a range type, or other custom algorithms. If it is a modulo type, perform modulo on the routing field value; if it is a range type, perform range determination on the routing field value; if it is custom, use the custom algorithm to process the routing field value to obtain the sub-library number and sub-table number. Figure 2 The user id field value is modulo-calculated. If the modulo-calculated result is 0, the sub-table table0 of the sub-database db1 is obtained. If the modulo-calculated result is 15, the sub-table table15 of the sub-database db2 is obtained.

[0051] The sub-library and sub-table database query method provided by the embodiment of the present invention is based on the routing field and is calculated according to the acquired routing algorithm to obtain the database number and the data table number.

[0052] Figure 5 It is a schematic diagram of the architecture of the sub-library and sub-table database provided by the present invention, such as Figure 5 As shown, the present invention caches the original information SQLStatement of the parsed SQL statement in the ThreadLocal object of the application. The subsequent re-execution of the SQL statement will directly use the data in the cache, without the need for repeated parsing, effectively saving system overhead. The sub-library + sub-table mechanism is used to effectively cope with operations such as database expansion. The routing strategy of business data can be pre-set, and the specific sub-library and sub-table are determined by formulating fields through modulus, range mode and custom mode to form the final physical SQL. The physical SQL is subsequently executed by switching the data source to complete DML, DQL and other operations. For more complex sub-library and sub-table scenarios, the corresponding fields and corresponding modes can be dynamically added, flexibly configured, and effectively adapted to various sub-library and sub-table scenarios. After the SQL statement is parsed, routed and executed by the middleware, multiple result sets are merged to finally obtain a unified result set.

[0053] In summary, the database query method for sharding libraries and tables provided by the present invention can customize the configuration strategy of routing fields, add routing fields and specify routing algorithms according to business requirements, form an overall routing strategy, and realize flexible configuration of routing fields and routing algorithms; merge the result sets after routing and execution are completed to facilitate subsequent application use; cache SQL metadata data resources to reduce system resource loss.

[0054] The following is a description of a sub-library and sub-table database query device provided in an embodiment of the present application. The sub-library and sub-table database query device described below and the sub-library and sub-table database query method described above can be referenced to each other.

[0055] Figure 6 It is a structural diagram of the sub-library and sub-table database query device provided by the present invention, such as Figure 6 As shown, the sub-library and sub-table database query device may include but is not limited to: Receiving module 610, used for receiving SQL statements; An information identification module 620, configured to identify and obtain routing policy information corresponding to the SQL statement based on predefined routing configuration information, wherein the routing configuration information includes data source information and routing policy information; A number determination module 630, configured to determine a database number and a data table number based on the routing policy information; A statement reorganization module 640 is used to assemble and obtain a physical SQL statement based on the data table number; The statement execution module 650 is used to switch to the data source corresponding to the database number, execute the physical SQL statement, and obtain the database query result.

[0056] It should be noted that the sub-library and sub-table database query device provided in the embodiment of the present invention can execute the sub-library and sub-table database query method described in any of the above embodiments during specific operation, which will not be elaborated in this embodiment.

[0057] Figure 7 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 7 As shown, the electronic device may include: a processor 710, a communication interface 720, a memory 730 and a communication bus 740, wherein the processor 710, the communication interface 720 and the memory 730 communicate with each other through the communication bus 740. The processor 710 may call the logic instructions in the memory 730 to execute the database query method of sub-library and sub-table, and the method includes: receiving an SQL statement; Based on predefined routing configuration information, identify and obtain routing policy information corresponding to the SQL statement, wherein the routing configuration information includes data source information and routing policy information; Based on the routing policy information, determine a database number and a data table number; Based on the data table number, assemble and obtain a physical SQL statement; After switching to the data source corresponding to the database number, the physical SQL statement is executed to obtain the database query result.

[0058] In addition, the logic instructions in the above-mentioned memory 730 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on this understanding, the technical solution of the present invention can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc. Various media that can store program codes.

[0059] On the other hand, the present invention further provides a computer program product, the computer program product includes a computer program, the computer program can be stored in a non-transitory computer-readable storage medium, when the computer program is executed by a processor, the computer can execute the database query method provided by the above methods, the method includes: receiving an SQL statement; Based on predefined routing configuration information, identify and obtain routing policy information corresponding to the SQL statement, wherein the routing configuration information includes data source information and routing policy information; Based on the routing policy information, determine a database number and a data table number; Based on the data table number, assemble and obtain a physical SQL statement; After switching to the data source corresponding to the database number, the physical SQL statement is executed to obtain the database query result.

[0060] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the computer program is executed by a processor to execute the database query method for sub-libraries and sub-tables provided by the above methods, the method comprising: receiving an SQL statement; Based on predefined routing configuration information, identify and obtain routing policy information corresponding to the SQL statement, wherein the routing configuration information includes data source information and routing policy information; Based on the routing policy information, determine a database number and a data table number; Based on the data table number, assemble and obtain a physical SQL statement; After switching to the data source corresponding to the database number, the physical SQL statement is executed to obtain the database query result.

[0061] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0062] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0063] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention 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 make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for querying a database with separate libraries and tables, characterized in that: include: Receive SQL statements; Based on predefined routing configuration information, identify and obtain routing policy information corresponding to the SQL statement, wherein the routing configuration information includes data source information and routing policy information; Based on the routing policy information, determine a database number and a data table number; Based on the data table number, assemble and obtain a physical SQL statement; After switching to the data source corresponding to the database number, the physical SQL statement is executed to obtain the database query result.

2. The method for querying a database with separate libraries and tables according to claim 1, characterized in that: After switching to the data source corresponding to the database number, executing the physical SQL statement to obtain the database query result includes: After switching to the data source corresponding to the database number, obtaining the data connection of the data source; Based on the data connection, executing the physical SQL statement to obtain an execution result, wherein the execution result includes one or more result sets; If the execution result includes a result set, the result set is used as the database query result; If the execution result includes multiple result sets, the multiple result sets are merged to obtain the database query result.

3. The method for querying a database with separate libraries and tables according to claim 2, characterized in that: The merging of the multiple result sets includes: If the physical SQL statement is a data query language, merging the multiple result sets into a list; If the physical SQL statement contains an aggregate function, a merge algorithm is used to merge multiple lists into one list.

4. The method for querying a database with separate libraries and tables according to claim 1, characterized in that: After receiving the SQL statement, the method further includes: Determine whether the relevant information of the SQL statement is stored in the cache; If the relevant information of the SQL statement is not stored in the cache, the SQL statement is parsed to obtain a SQLStatement, and the SQLStatement is stored in the cache; If the cache stores relevant information of the SQL statement, the SQLStatement is obtained from the cache.

5. The method for querying a database with separate libraries and tables according to claim 4 is characterized in that: The identifying and obtaining routing policy information corresponding to the SQL statement based on predefined routing configuration information includes: Based on the predefined routing configuration information, the routing policy information corresponding to the SQLStatement corresponding to the SQL statement is obtained.

6. The method for querying a database of sub-libraries and sub-tables according to any one of claims 1 to 5, characterized in that: The routing policy information includes a routing field and a routing algorithm, and the determining of a database number and a data table number based on the routing policy information includes: Based on the routing field, the routing algorithm is used to calculate and obtain the database number and data table number corresponding to the SQL statement.

7. A database query device for sub-libraries and sub-tables, characterized in that: include: A receiving module, used for receiving SQL statements; An information identification module, used to identify and obtain routing policy information corresponding to the SQL statement based on predefined routing configuration information, wherein the routing configuration information includes data source information and routing policy information; A number determination module, used to determine a database number and a data table number based on the routing policy information; A statement reorganization module, used for assembling and obtaining a physical SQL statement based on the data table number; The statement execution module is used to switch to the data source corresponding to the database number, execute the physical SQL statement, and obtain the database query result.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the sub-library and sub-table database query method as described in any one of claims 1 to 6 is implemented.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the sub-library and sub-table database query method as described in any one of claims 1 to 6 is implemented.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the sub-library and sub-table database query method as described in any one of claims 1 to 6 is implemented.

Citation Information

Patent Citations

  • Data query method and device, computer equipment and storage medium

    CN108628986A

  • Data routing method and device based on database distributed storage

    CN110046181A

  • System, method, and program for extending a SQL compiler for handling control statements packaged with SQL query statements

    US5875334A

  • Methods and systems for cloud database resource extension and service extension

    WO2017143929A1

Cited By

  • Data query method and device, computer equipment and storage medium

    CN121705331A