Data query method, device, electronic device and storage medium

Through the method of paging and iterative access to virtual machine data in large-scale cloud platforms, the memory overflow problem during virtual machine data query is solved, development costs are reduced, and response efficiency is improved.

CN118643077BActive Publication Date: 2024-10-29JINAN INSPUR DATA TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411126992.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-16
Publication Date
2024-10-29
Estimated Expiration
2044-08-16

AI Technical Summary

Technical Problem

In large-scale cloud platforms, the limited memory of virtual machines when querying data leads to the risk of memory overflow, increases development costs and reduces the response efficiency of simulated services.

Method used

By generating data statistics statements and paging query statements, iterative access to the target database is performed on pages based on these statements, and the data pages are saved to the business process memory to avoid memory overflow and improve response efficiency.

Benefits of technology

It effectively avoids the risk of business process memory overflow, reduces development costs, and improves the response efficiency of simulated business.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118643077B_ABST
    Figure CN118643077B_ABST
Patent Text Reader

Abstract

The present invention relates to the field of computer technology, and discloses a data query method, device, electronic device and storage medium, the method comprising: obtaining an original query statement sent by a user to a target database; generating a data statistics statement and a paging query statement according to the original query statement; obtaining statistical information of data to be accessed in the target database based on the data statistics statement; performing paging iterative access to the data to be accessed in the target database based on the paging query statement according to the statistical information of the data to be accessed, so as to save the paging of the data to be accessed to the business process memory. The method provided by the above scheme caches data to the business process memory in a paging manner by performing paging iterative access to data according to the original query statement, thereby avoiding the risk of business process memory overflow, reducing development costs, and improving the response efficiency of simulation business.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a data query method, device, electronic device and storage medium. Background Art

[0002] Currently, in order to perform logical processing and data display on virtual machines in large-scale cloud platforms, the relevant virtual resource data of the virtual machines are generally recorded in a database.

[0003] In the related art, in order to meet the needs of simulated business, the query function of the database is usually used to read the corresponding virtual resource data from the database, and the read data is saved in the memory of the business process for data processing by the business process.

[0004] However, since the memory of the business process is limited, when the amount of data read is large, there will be a risk of memory overflow. At this time, the memory size of the business process needs to be adjusted, which not only increases the development cost, but also reduces the response efficiency of the simulated business. Summary of the invention

[0005] The present application provides a data query method, device, electronic device and storage medium to solve the defects of related technologies that not only increase development costs but also reduce the response efficiency of simulated services.

[0006] The first aspect of the present application provides a data query method, comprising:

[0007] Obtain the original query statement sent by the user to the target database;

[0008] Generate a data statistics statement and a paging query statement according to the original query statement;

[0009] Based on the data statistics statement, obtaining statistical information of the data to be accessed in the target database;

[0010] Based on the paging query statement and according to the statistical information of the data to be accessed, paging iterative access is performed on the data to be accessed in the target database, so as to save the paging of the data to be accessed into the business process memory.

[0011] In an optional implementation, generating a data statistics statement and a paging query statement according to the original query statement includes:

[0012] According to the key information analysis result of the original query statement, intercepting the target character string in the original query statement;

[0013] The data statistics statement is generated according to the target character string.

[0014] In an optional implementation, before intercepting the target character string from the original query statement according to the key information analysis result of the original query statement, the method further includes:

[0015] Filter key elements in the original query statement to obtain key element filtering results;

[0016] The key information analysis result of the original query statement is determined according to the position of each of the key elements represented by the key element screening result in the original query statement.

[0017] In an optional implementation, generating a data statistics statement and a paging query statement according to the original query statement includes:

[0018] The target paging query string is concatenated at the end of the original query statement to expand the original query statement into a paging query statement.

[0019] In an optional implementation, the acquiring statistical information of the data to be accessed in the target database based on the data statistical statement includes:

[0020] Saving the data statistics statement to a statistics query interface of a preset query device, so that the preset query device applies the data statistics statement by calling the statistics query interface;

[0021] The target database returns the statistical information of the to-be-accessed data to the preset query device in response to the data statistical statement.

[0022] In an optional implementation, performing paging iterative access to the data to be accessed in the target database based on the paging query statement and according to statistical information of the data to be accessed includes:

[0023] Saving the paging query statement to a paging query interface of a preset query device, so that the preset query device applies the paging query statement by calling the paging query interface;

[0024] The target database returns the paging query result of the to-be-accessed data to the preset query device in response to the paging query statement;

[0025] According to the statistical information of the data to be accessed and the paging query result currently returned by the target database, paging iterative access is performed on the data to be accessed in the target database.

[0026] In an optional implementation, performing paging iterative access to the data to be accessed in the target database according to the statistical information of the data to be accessed and the paging query result currently returned by the target database includes:

[0027] Determine the total amount of data to be accessed based on the statistical information of the data to be accessed;

[0028] According to the paging query result currently returned by the target database, determining whether the iterative access to the current page data is completed;

[0029] When it is determined that the iteration of the current page data is completed and the amount of data currently iteratively accessed is less than the total amount of data, the paging query parameters in the paging query statement are updated to obtain a new paging query statement, so as to perform paging iterative access to the data to be accessed in the target database based on the new paging query statement.

[0030] In an optional implementation, updating the paging query parameters in the paging query statement to obtain a new paging query statement includes:

[0031] Increasing the starting page number in the paging query statement to update the starting page number in the paging query statement to obtain a new paging query statement;

[0032] The paging query parameters in the paging query statement at least include a starting page number.

[0033] In an optional embodiment, the method further includes:

[0034] When the amount of data currently iteratively accessed reaches the total amount of data, an empty object is returned to indicate that the paging iterative access to the data to be accessed has been completed.

[0035] In an optional embodiment, the method further includes:

[0036] When it is determined that the iteration of the current page data has not been completed, the current page data is continuously accessed by paging iteration according to the current iteration cursor.

[0037] In an optional implementation, continuing to perform paging iterative access to the current page data according to the current iteration cursor includes:

[0038] Determine the unaccessed data in the current page data according to the modulus calculation result of the current iteration cursor and the current page data size;

[0039] According to the unaccessed data in the current page data, the current iteration cursor is increased to continue to perform paged iterative access on the current page data.

[0040] A second aspect of the present application provides a data query device, comprising:

[0041] A first acquisition module is used to acquire the original query statement sent by the user to the target database;

[0042] A generation module, used to generate a data statistics statement and a paging query statement according to the original query statement;

[0043] A second acquisition module, used for acquiring statistical information of the data to be accessed in the target database based on the data statistical statement;

[0044] The query module is used to perform paging iterative access to the data to be accessed in the target database based on the paging query statement and according to the statistical information of the data to be accessed, so as to save the paging of the data to be accessed into the business process memory.

[0045] In an optional implementation, the generating module is specifically used to:

[0046] According to the key information analysis result of the original query statement, intercepting the target character string in the original query statement;

[0047] The data statistics statement is generated according to the target character string.

[0048] In an optional implementation, the generating module is further used to:

[0049] According to the key information analysis result of the original query statement, before intercepting the target character string in the original query statement, the key elements are screened in the original query statement to obtain a key element screening result;

[0050] The key information analysis result of the original query statement is determined according to the position of each of the key elements represented by the key element screening result in the original query statement.

[0051] In an optional implementation, the generating module is specifically used to:

[0052] The target paging query string is concatenated at the end of the original query statement to expand the original query statement into a paging query statement.

[0053] In an optional implementation manner, the second acquisition module is specifically configured to:

[0054] Saving the data statistics statement to a statistics query interface of a preset query device, so that the preset query device applies the data statistics statement by calling the statistics query interface;

[0055] The target database returns the statistical information of the to-be-accessed data to the preset query device in response to the data statistical statement.

[0056] In an optional implementation, the query module is specifically used to:

[0057] Saving the paging query statement to a paging query interface of a preset query device, so that the preset query device applies the paging query statement by calling the paging query interface;

[0058] The target database returns the paging query result of the to-be-accessed data to the preset query device in response to the paging query statement;

[0059] According to the statistical information of the data to be accessed and the paging query result currently returned by the target database, paging iterative access is performed on the data to be accessed in the target database.

[0060] In an optional implementation, the query module is specifically used to:

[0061] Determine the total amount of data to be accessed based on the statistical information of the data to be accessed;

[0062] According to the paging query result currently returned by the target database, determining whether the iterative access to the current page data is completed;

[0063] When it is determined that the iteration of the current page data is completed and the amount of data currently iteratively accessed is less than the total amount of data, the paging query parameters in the paging query statement are updated to obtain a new paging query statement, so as to perform paging iterative access to the data to be accessed in the target database based on the new paging query statement.

[0064] In an optional implementation, the query module is specifically used to:

[0065] Increasing the starting page number in the paging query statement to update the starting page number in the paging query statement to obtain a new paging query statement;

[0066] The paging query parameters in the paging query statement at least include a starting page number.

[0067] In an optional implementation, the query module is specifically used to:

[0068] When the amount of data currently iteratively accessed reaches the total amount of data, an empty object is returned to indicate that the paging iterative access to the data to be accessed has been completed.

[0069] In an optional implementation, the query module is specifically used to:

[0070] When it is determined that the iteration of the current page data has not been completed, the current page data is continuously accessed by paging iteration according to the current iteration cursor.

[0071] In an optional implementation, the query module is specifically used to:

[0072] Determine the unaccessed data in the current page data according to the modulus calculation result of the current iteration cursor and the current page data size;

[0073] According to the unaccessed data in the current page data, the current iteration cursor is increased to continue to perform paged iterative access on the current page data.

[0074] A third aspect of the present application provides an electronic device, comprising: at least one processor and a memory;

[0075] The memory stores computer-executable instructions;

[0076] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the method described in the first aspect and various possible designs of the first aspect.

[0077] A fourth aspect of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer-executable instructions. When a processor executes the computer-executable instructions, the method described in the first aspect and various possible designs of the first aspect are implemented.

[0078] A fifth aspect of the present application provides a computer program product, including computer instructions, which are used to enable a computer to execute the method described in the first aspect and various possible designs of the first aspect.

[0079] The technical solution of this application has the following advantages:

[0080] The present application provides a data query method, device, electronic device and storage medium, the method comprising: obtaining the original query statement sent by the user to the target database; generating a data statistics statement and a paging query statement based on the original query statement; obtaining the statistical information of the data to be accessed in the target database based on the data statistics statement; based on the paging query statement, performing paging iterative access to the data to be accessed in the target database according to the statistical information of the data to be accessed, so as to save the paging of the data to be accessed to the business process memory. The method provided by the above scheme caches data to the business process memory in a paging manner by performing paging iterative access to the data according to the original query statement, thereby avoiding the risk of overflow of the business process memory, reducing the development cost and improving the response efficiency of the simulation business. BRIEF DESCRIPTION OF THE DRAWINGS

[0081] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the following is a brief introduction to the drawings required for use in the embodiments or the related technical descriptions. Obviously, the drawings described below are some embodiments of the present application, and a person skilled in the art can also obtain other drawings based on these drawings.

[0082] Figure 1 A schematic diagram of the structure of a data query system based on an embodiment of the present application;

[0083] Figure 2 A flowchart of a data query method provided in an embodiment of the present application;

[0084] Figure 3 A JAVA built-in iterative data access logic diagram provided in an embodiment of the present application;

[0085] Figure 4 A flowchart of an exemplary data query method provided in an embodiment of the present application;

[0086] Figure 5 A flowchart of another exemplary data query method provided in an embodiment of the present application;

[0087] Figure 6 A schematic diagram of the structure of an exemplary data query system is provided for an embodiment of the present application;

[0088] Figure 7 A schematic diagram of the structure of a data query device provided in an embodiment of the present application;

[0089] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0090] The above drawings have shown clear embodiments of the present application, which will be described in more detail below. These drawings and text descriptions are not intended to limit the scope of the present disclosure in any way, but to illustrate the concepts of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION

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

[0092] In addition, the terms "first", "second", etc. are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. In the description of the following embodiments, the meaning of "multiple" is more than two, unless otherwise clearly and specifically defined.

[0093] In large-scale cloud platforms, in order to provide better functional usability, large amounts of data such as virtual resources are often recorded in the database for logical processing and display. However, this convenience also brings great risks. In test scenarios, when simulating ultra-large-scale environments such as thousands or tens of thousands, the platform logic will have more or less unified scheduling and processing for each virtual resource. Often, all data of the resource is obtained by using the query function of the database, and the data is iterated one by one. At this time, the queried data must be temporarily stored in the JAVA process memory before logical processing can be performed, that is, querying all data operations. This problem can be solved by adjusting the JAVA memory size when the scale is small and the access volume is small, but it needs to be adjusted according to the business volume each time, which is not conducive to the product's reputation and usability.

[0094] There are currently several ways to solve the above problems:

[0095] 1. Provide sufficient conditions to narrow the query data range and reduce memory usage;

[0096] 2. Reduce the data of the query object so that only a small part of the data is stored in the memory, thereby reducing the memory usage;

[0097] 3. By querying by pages, a fixed amount of data is queried each time, and the pages are iterated multiple times to reduce the amount of data queried each time, thereby reducing memory usage.

[0098] However, among the above solutions, Solution 1 and 2 can only play an optimization role and cannot fundamentally solve the problem. Solution 3 can fundamentally solve the problem, but it requires related businesses to be processed one by one, and users are required to write corresponding paging query instructions according to the needs of each paging query. When the amount of data to be accessed is large, users are required to manually edit multiple paging query instructions, which will greatly increase the development workload and reduce development efficiency. It is also difficult to control the granularity of paging, making the overall controllability of the system low.

[0099] In response to the above problems, the embodiments of the present application provide a data query method, device, electronic device and storage medium, the method comprising: obtaining the original query statement sent by the user to the target database; generating a data statistics statement and a paging query statement based on the original query statement; obtaining statistical information of the data to be accessed in the target database based on the data statistics statement; based on the paging query statement, performing paging iterative access to the data to be accessed in the target database according to the statistical information of the data to be accessed, so as to save the paging of the data to be accessed to the business process memory. The method provided by the above scheme caches data to the business process memory in a paging manner by performing paging iterative access to the data according to the original query statement, thereby avoiding the risk of overflow of the business process memory, reducing the development cost and improving the response efficiency of the simulation business.

[0100] The following specific embodiments may be combined with each other, and the same or similar concepts or processes may not be described in detail in some embodiments. The embodiments of the present invention will be described below in conjunction with the accompanying drawings.

[0101] First, the structure of the data query system on which this application is based is described:

[0102] The data query method, device, electronic device and storage medium provided in the embodiments of the present application are suitable for performing paging iterative access to the data to be accessed when the amount of data to be accessed is large. Figure 1 The figure is a schematic diagram of the structure of the data query system based on the embodiment of the present application, which mainly includes a statement collection device, a data query device and a target database. The statement collection device is used to collect the original query statements sent by the user to the target database, and the data query device is used to analyze and process the original query statements, and use a paging iterative access method to complete the query and cache of the data to be accessed specified by the original query data.

[0103] The embodiment of the present application provides a data query method for performing paging iterative access to the data to be accessed when the amount of data to be accessed is large. The execution subject of the embodiment of the present application is an electronic device, such as a server, a desktop computer, a laptop computer, a tablet computer, and other electronic devices that can be used to query data on a target database.

[0104] like Figure 2 FIG. 1 is a flow chart of a data query method provided in an embodiment of the present application, and the method includes:

[0105] Step 201: Obtain the original query statement sent by the user to the target database.

[0106] The original query statement is an SQL query statement input by the user, and the destination database is used to cache the virtual resource data related to the virtual machine, and the related virtual resource data includes virtual machine status information, disk status information, network status information and other configuration information. The virtual machine status information includes the memory, registers, CPU status, etc. of the virtual machine. The disk status information includes the disk data, file system, etc. of the virtual machine. The network status information includes the network configuration, IP address, etc. of the virtual machine. Other configuration information includes, for example, the hardware configuration, operating system settings, etc. of the virtual machine.

[0107] Step 202: Generate a data statistics statement and a paging query statement based on the original query statement.

[0108] Specifically, the original query statement can be analyzed and processed to determine the information related to the data to be accessed specified by the original query statement, and then the original query statement can be converted into a data statistics statement and a paging query statement to implement paging iterative access to the data to be accessed based on the data statistics statement and the paging query statement.

[0109] Step 203: Based on the data statistics statement, obtain the statistical information of the data to be accessed in the target database.

[0110] It should be noted that, since the method provided in the embodiment of the present application is to access the data to be accessed whose data volume is greater than the business process memory, the statistical information of the data to be accessed determined in the embodiment of the present application may specifically refer to the total amount of data to be accessed. In practical applications, the statistical information of the data to be accessed may include the total number of rows of the data to be accessed, the average data volume and average number of rows of multiple types of data to be accessed, etc.

[0111] Step 204 , based on the paging query statement and according to the statistical information of the data to be accessed, perform paging iterative access to the data to be accessed in the target database, so as to save the paging of the data to be accessed into the business process memory.

[0112] The business process is used to create virtual machine snapshots and virtual machine information backups, etc. To execute the business process, the user sends an original query statement to the target database to query relevant virtual resource data in the target database.

[0113] Specifically, in the process of performing paging iterative access to the data to be accessed in the target database based on the paging query statement, the paging iterative access end condition is determined according to the statistical information of the data to be accessed, so as to perform complete paging iterative access to the data to be accessed and avoid data omission or under-reading.

[0114] On the basis of the above embodiments, in order to ensure the accuracy of the data statistics statements and paging query statements generated by the embodiments of the present application, as an implementable method, in one embodiment, data statistics statements and paging query statements are generated according to the original query statements, including:

[0115] Step 221, according to the key information analysis result of the original query statement, intercept the target character string in the original query statement;

[0116] Step 2022, generating a data statistics statement according to the target character string.

[0117] Specifically, in one embodiment, key elements may be screened in the original query statement to obtain key element screening results; and key information analysis results of the original query statement may be determined based on the positions of key elements represented by the key element screening results in the original query statement.

[0118] For example, when the original query statement is select from host_table order by ip desc, "from" and "order" can be used as key elements, and the key element screening result at least includes the position in the original query statement. The position of "from" is used as the start pointer indexBegin, and the position of "order" is used as the end pointer indexEnd. If the order element does not exist, the position is the end of the statement. Using indexBegin and indexEnd as markers, the target string "from host_table" in the original query statement is intercepted. Finally, the data statistics statement is finally generated based on the target string, which is select count(1) from host_table.

[0119] In the process of generating data statistics statements, construct the statistical key statement select count(%s), and replace "%s" with the statistical keyword ("1" is used as the keyword by default). Specify the query keyword "distinct ip" statement conversion: "select dinstinct ip from host_table order by ip desc" -> "select count(dinstinct ip) from host_table".

[0120] Specifically, in one embodiment, the target paging query string may be concatenated at the end of the original query statement to expand the original query statement into a paging query statement.

[0121] Specifically, based on the original query statement, the target paging query string limit %startIndex,%maxSize can be added to the end to complete the paging statement expansion, where startIndex indicates the start position of the index and maxSize indicates the maximum size (page size).

[0122] Exemplarily, when the original query statement is select from host_table order by ip desc, the generated paging query statement is select from host_table order by ip desc limit %startIndex,%maxSize.

[0123] Among them, startIndex is continuously updated during the access iteration process, and maxSize always uses the default page size. The default page size can be determined according to information such as the business process memory, and the default page size is smaller than the business process memory size.

[0124] On the basis of the above embodiment, in order to improve the data query efficiency and further improve the response efficiency of the simulated business, as an implementable method, in one embodiment, based on the data statistics statement, the statistical information of the data to be accessed in the target database is obtained, including:

[0125] Step 2031, saving the data statistics statement to the statistics query interface of the preset query device, so that the preset query device applies the data statistics statement by calling the statistics query interface;

[0126] Step 2032: The target database returns statistical information of the data to be accessed to the preset query unit in response to the data statistical statement.

[0127] It should be noted that the data statistics statement and the paging query statement can be constructed based on the query builder. After the query builder completes the construction of the data statistics statement and the paging query statement, it triggers the iterative data access function to obtain the iterative access controller object, and then based on the iterative access controller object, it uses the JAVA language foreach (1.8 or above) or for (A a: Iterator ) statement to perform iterative access and complete the business.

[0128] Specifically, after completing the construction of the data statistics statement and the paging query statement, the query builder first stores them in the statistical query interface (countAll) and the paging query interface (queryByPage) of the preset query, so that the preset query can apply the data statistics statement by calling the statistical query interface, and then obtain the statistical information of the data to be accessed returned by the target database in response to the data statistics statement.

[0129] Based on the above embodiment, as an implementable manner, in one embodiment, based on a paging query statement, according to the statistical information of the data to be accessed, paging iterative access is performed on the data to be accessed in the target database, including:

[0130] Step 2041, saving the paging query statement to the paging query interface of the preset query unit, so that the preset query unit applies the paging query statement by calling the paging query interface;

[0131] Step 2042, the target database returns the paging query result of the to-be-accessed data to the preset query device in response to the paging query statement;

[0132] Step 2043: perform paging iterative access to the data to be accessed in the target database according to the statistical information of the data to be accessed and the paging query results currently returned by the target database.

[0133] The paging query interface is provided with a paging query parameter interface of the paging query statement, which is used to modify the paging query parameters in the paging query statement during the paging iterative access process. The paging query parameters at least include the index start position startIndex and the page size maxSize.

[0134] Specifically, the query builder returns the data statistics statement and the paging query statement to the data iterative access controller, which implements the JAVA language interface Iterable (iteration interface) in response to the data statistics statement and the paging query statement, and returns the built-in iterative paging iteration object AutoPagedIteratorWrapper by implementing the iterator interface. The object implements the JAVA language interface Iterator, and the iterative access syntax of the JAVA language is implemented through the hasNext() and next() functions of the interface.

[0135] Among them, Figure 3As shown, it is a schematic diagram of the JAVA built-in iterative access data logic provided by the embodiment of the present application, hasNext() is used to check whether there is a next element to be iterated, and next() is used to return the next element. By using the hasNext() and next() methods, Java's iterative access syntax can easily traverse the iterative object returned by the controller. This design model is used to process paging data. By encapsulating the paging logic in AutoPagedIteratorWrapper, the controller can provide a simple and consistent way to iterate data without the user having to directly handle the details of paging, which can improve the readability and maintainability of the code, and also facilitate the traversal and processing of data.

[0136] Specifically, in one embodiment, the total amount of data to be accessed can be determined based on statistical information of the data to be accessed; based on the paging query results currently returned by the target database, it is determined whether the iterative access to the current page data has been completed; when it is determined that the iteration of the current page data has been completed and the amount of data currently iteratively accessed is less than the total amount of data, the paging query parameters in the paging query statement are updated to obtain a new paging query statement, so as to perform paging iterative access to the data to be accessed in the target database based on the new paging query statement.

[0137] It should be noted that the initial value of the built-in paging iteration object flag includes the total amount of data (totalSize = -1), iteration cursor (iterCursor = 0), current page number (currentPage = 0), default page size (iteratorPageSize = 100) and page cache data pageRs list. The page cache data pageRs list is used to cache a single page of data, and finally the page cache data pageRs list is cached to the business process memory, so that the business process memory can implement data paging cache to avoid the risk of memory overflow.

[0138] Specifically, Figure 4As shown, it is a flow chart of an exemplary data query method provided by an embodiment of the present application, specifically referring to the hasNext() logic implemented by the AutoPagedIteratorWrapper object. When totalSize = -1, it indicates that the current iteration is the first iteration. At this time, according to the execution result of the data statistics statement, the total amount of data totalSize is updated, that is, the updated value of totalSize is the data returned by the database queryer countAll. When totalSize is not equal to -1, it is determined that the current iteration is not the first iteration, so it can be further determined whether the current page data has been iterated and the iterative access to the total data has not been completed. Among them, when iterCursor modulo iteratorPageSize is 0, it is determined that the iteration of the current page data is completed. If iterCursor is not equal to totalSize, it indicates that the amount of data currently iterated and accessed is less than the total amount of data. The iteration cursor iterCursor is used to indicate which data is currently accessed.

[0139] Specifically, in one embodiment, when it is determined that the current page data iteration is completed and the amount of data currently iterated and accessed is less than the total amount of data, the starting page number in the paging query statement can be increased to update the starting page number in the paging query statement to obtain a new paging query statement.

[0140] The paging query parameters in the paging query statement at least include the starting page number.

[0141] Specifically, when it is determined that the iteration of the current page data is completed and the amount of data currently iterated and accessed is less than the total amount of data, page turning processing can be performed, that is, access to the next page of data. Specifically, the currentPage of the preset query device can be updated to currentPage++, and the default page size iteratorPageSize can be used as an input parameter to call the queryPage interface of the database query device to obtain the paging query object and cache it in the page cache data pageRs list.

[0142] Among them, currentPage corresponds to the starting page number startIndex in the paging query statement, iteratorPageSize corresponds to the page size maxSize in the paging query statement, and currentPage++ means the starting page number plus 1. In the embodiment of the present application, maxSize=iteratorPageSize, that is, the page size in the paging query statement adopts the default value.

[0143] Furthermore, in one embodiment, when it is determined that the iteration of the current page data has not been completed, the current page data is continuously accessed by paging iteration according to the current iteration cursor.

[0144] Specifically, when iterCursor is smaller than totalSize and the current page data pageRs has data, it can be determined that the current page data has not been iterated completely, and thus the current page data can continue to be iteratively accessed in pages according to the current iteration cursor.

[0145] Furthermore, in one embodiment, when the amount of data currently iteratively accessed reaches the total amount of data, an empty object is returned to indicate that the paging iterative access to the data to be accessed has been completed.

[0146] Specifically, Figure 5 As shown, it is a flowchart of another exemplary data query method provided by the embodiment of the present application, specifically referring to the next() logic implemented by the AutoPagedIteratorWrapper object. When iterCursor is equal to totalSize, it is determined that the amount of data currently iterated has reached the total amount of data, that is, the paging iterative access to the data to be accessed has been completed, so an empty object is returned to end the paging iterative access process of the data to be accessed.

[0147] Specifically, in one embodiment, when it is determined that the current page data has not been iterated, the unaccessed data in the current page data can be determined based on the modulus calculation result of the current iteration cursor and the current page data size; based on the unaccessed data in the current page data, the current iteration cursor is increased to continue to perform paged iterative access to the current page data.

[0148] Specifically, in one embodiment, the object value of iterCursor modulo iteratorPageSize located in the pageRs list can be obtained, that is, the modulus calculation result of the current iteration cursor and the current page data size is determined, and the unaccessed data in the current page data is determined, and the iteration cursor is increased by 1 to continue further paging iterative access to the unaccessed data in the current page data.

[0149] Specifically, after the user obtains the data iteration access controller, the user can perform data iteration through JAVA's foreach iteration statement or for keyword. When accessing data elements one by one, the built-in paging process can be triggered to perform paging iteration access to data.

[0150] Specifically, Figure 6As shown, a schematic diagram of the structure of an exemplary data query system is provided for an embodiment of the present application, and the system includes a query builder, a data iterative access controller, and a database query. When all data need to be queried, the SQL statement to be queried is passed into the query builder, and the data iterative access controller object is returned at the same time. Through this object, the built-in iterative access mechanism of the JAVA language can be used to complete the automatic paging iterative access to data; the data iterative access controller is based on the built-in interface of the JAVA language, and the interface implemented by it will take effect in the iterative access statement of the JAVA language. When the iterative access data touches the end of the page, the page turning operation is triggered, and the next page of data is automatically iterated; the database query is built into the data iterative access controller, which can automatically parse the query statement passed in by the user, and complete the construction of data statistics and data paging statements, and complete the preparation work for data paging query. Among them, the built-in iterative access language mechanism of the JAVA language can be used to trigger data re-query at key points; the difference between the query statement and the paging statement is used to automatically parse and complete the query statement required in the paging operation.

[0151] Specifically, data statistics statements and paging query statements can be derived from data query statements (original query statements), and rewritten data statistics statements and paging query statements are returned when called. The data iterative access controller that can be identified by the JAVA language iterative access statement can trigger the data paging query operation without feeling when the developer iterates to access the data. Among them, the query builder is responsible for exposing the use entry, obtaining the necessary query statements and keywords, parsing and deriving data statistics statements and data paging statements, and returning the necessary data iterative access controller to the developer; the data iterative access controller is the key to making the developer paging without feeling, and its implementation can be recognized by the JAVA language syntax as an object that can automatically iterate to access a single data, thereby providing a calculation opportunity for whether paging needs to be triggered when accessing data, whether there are iteratively accessible resources, and whether all data iterative accesses are completed. It is the key to allowing developers to transform from the apparent all data iterative access to data paging iterative access; the database queryer accepts the query builder's derived query statements and the control mark of the data iterative access controller, calculates and implements the paging query, and returns the data, providing the data iterative access controller with key judgment basis and actual data for implementing the paging logic.

[0152] The data query method provided by the embodiment of the present application obtains the original query statement sent by the user to the target database; generates a data statistics statement and a paging query statement based on the original query statement; obtains the statistical information of the data to be accessed in the target database based on the data statistics statement; performs paging iterative access to the data to be accessed in the target database based on the paging query statement according to the statistical information of the data to be accessed, so as to save the paging of the data to be accessed to the business process memory. The method provided by the above scheme caches data to the business process memory in a paging manner by performing paging iterative access to the data according to the original query statement, thereby avoiding the risk of overflow of the business process memory, reducing the development cost and improving the response efficiency of the simulation business. In addition, the method provided in the embodiment of the present application derives statistical and paging query statements by utilizing database query statements used by developers and other users when querying data, and utilizes the basic principle of JAVA iterative access. When developers iteratively access the database query data list, the method allows developers to trigger paging queries without noticing, thereby reducing the amount of data cached in the process. When resource data is processed in batches at a high frequency in a large-scale environment, the resource data retained in the memory device is greatly reduced, thereby improving the availability and stability of the product in large-scale and high-frequency business processing scenarios without changing the code to adapt to large-scale environments.

[0153] An embodiment of the present application provides a data query device, which is used to execute the data query method provided by the above embodiment.

[0154] like Figure 7 , which is a schematic diagram of the structure of a data query device provided in an embodiment of the present application. The data query device 70 comprises: a first acquisition module 701 , a generation module 702 , a second acquisition module 703 and a query module 704 .

[0155] Among them, the first acquisition module is used to obtain the original query statement sent by the user to the target database; the generation module is used to generate data statistics statements and paging query statements based on the original query statements; the second acquisition module is used to obtain statistical information of the data to be accessed in the target database based on the data statistics statement; the query module is used to perform paging iterative access to the data to be accessed in the target database based on the paging query statement and according to the statistical information of the data to be accessed, so as to save the pages of the data to be accessed to the business process memory.

[0156] Specifically, in one embodiment, the generating module is specifically used to:

[0157] According to the key information analysis result of the original query statement, the target character string is intercepted in the original query statement;

[0158] Generate data statistics statements based on the target string.

[0159] Specifically, in one embodiment, the generating module is further used for:

[0160] According to the key information analysis result of the original query statement, before intercepting the target character string in the original query statement, the key elements are screened in the original query statement to obtain the key element screening result;

[0161] According to the positions of the key elements represented by the key element screening results in the original query statement, the key information analysis results of the original query statement are determined.

[0162] Specifically, in one embodiment, the generating module is specifically used to:

[0163] Add the target paging query string to the end of the original query statement to expand the original query statement into a paging query statement.

[0164] Specifically, in one embodiment, the second acquisition module is specifically used to:

[0165] Saving the data statistics statement to the statistics query interface of the preset query device, so that the preset query device applies the data statistics statement by calling the statistics query interface;

[0166] The target database returns the statistical information of the data to be accessed to the preset query unit in response to the data statistical statement.

[0167] Specifically, in one embodiment, the query module is specifically used to:

[0168] The paging query statement is saved to the paging query interface of the preset query device, so that the preset query device applies the paging query statement by calling the paging query interface;

[0169] The target database responds to the paging query statement and returns the paging query result of the to-be-accessed data to the preset query device;

[0170] According to the statistical information of the data to be accessed and the paging query results currently returned by the target database, paging iterative access is performed on the data to be accessed in the target database.

[0171] Specifically, in one embodiment, the query module is specifically used to:

[0172] Determine the total amount of data to be accessed based on the statistical information of the data to be accessed;

[0173] According to the paging query results currently returned by the target database, determine whether the iterative access to the current page data is completed;

[0174] When it is determined that the current page data iteration is completed and the amount of data currently iterated is less than the total amount of data, the paging query parameters in the paging query statement are updated to obtain a new paging query statement, so as to perform paging iterative access to the data to be accessed in the target database based on the new paging query statement.

[0175] Specifically, in one embodiment, the query module is specifically used to:

[0176] Add the starting page number in the paging query statement to update the starting page number in the paging query statement to obtain a new paging query statement;

[0177] The paging query parameters in the paging query statement at least include the starting page number.

[0178] Specifically, in one embodiment, the query module is specifically used to:

[0179] When the amount of data currently iterated has reached the total amount of data, an empty object is returned to indicate that the paging iterative access to the data to be accessed has been completed.

[0180] Specifically, in one embodiment, the query module is specifically used to:

[0181] When it is determined that the iteration of the current page data has not been completed, the current page data is continued to be iteratively accessed in pages according to the current iteration cursor.

[0182] Specifically, in one embodiment, the query module is specifically used to:

[0183] Determine the unaccessed data in the current page data according to the modulus calculation result of the current iteration cursor and the current page data size;

[0184] According to the unaccessed data in the current page data, the current iteration cursor is increased to continue the paging iteration access to the current page data.

[0185] Regarding the data query device in this embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0186] The data query device provided in the embodiment of the present application includes a first acquisition module for acquiring the original query statement sent by the user to the target database; a generation module for generating a data statistics statement and a paging query statement based on the original query statement; a second acquisition module for acquiring the statistical information of the data to be accessed in the target database based on the data statistics statement; and a query module for performing paging iterative access to the data to be accessed in the target database based on the paging query statement according to the statistical information of the data to be accessed, so as to save the paging of the data to be accessed to the business process memory. The device provided by the above scheme caches data to the business process memory in a paging manner by performing paging iterative access to the data according to the original query statement, thereby avoiding the risk of overflow of the business process memory, reducing the development cost and improving the response efficiency of the simulation business. In addition, the device provided in the embodiment of the present application derives statistical and paging query statements by utilizing database query statements used by developers and other users when querying data, and utilizes the basic principle of JAVA iterative access. When developers iteratively access the database query data list, the device allows developers to trigger paging queries without noticing, thereby reducing the amount of data cached in the process. When resource data is processed in batches at a high frequency in a large-scale environment, the resource data retained in the memory device is greatly reduced, thereby improving the availability and stability of the product in large-scale and high-frequency business processing scenarios without changing the code to adapt to large-scale environments.

[0187] An embodiment of the present application provides an electronic device for executing the data query method provided in the above embodiment.

[0188] like Figure 8 FIG. 8 is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. The electronic device 80 includes: at least one processor 81 and a memory 82 .

[0189] The memory stores computer-executable instructions; at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the data query method provided in the above embodiment.

[0190] The electronic device provided in the embodiment of the present application is used to execute the data query method provided in the above embodiment. Its implementation method and principle are the same and will not be repeated here.

[0191] An embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the data query method provided in any of the above embodiments is implemented.

[0192] The storage medium containing computer executable instructions provided in the embodiments of the present application can be used to store computer executable instructions of the data query method provided in the aforementioned embodiments. The implementation method and principle are the same and will not be repeated here.

[0193] An embodiment of the present application provides a computer program product, including computer instructions, which are used to enable a computer to execute the data query method provided in the aforementioned embodiment.

[0194] The computer program product provided in the embodiments of the present application can be used to execute computer instructions of the data query method provided in the aforementioned embodiments. The implementation method and principle are the same and will not be repeated here.

[0195] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0196] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0197] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of hardware plus software functional units.

[0198] The above-mentioned integrated unit implemented in the form of a software functional unit can be stored in a computer-readable storage medium. The above-mentioned software functional unit is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform some steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program codes.

[0199] A part of the present application may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of computer program instructions in computer-readable media includes, but is not limited to, source files, executable files, installation package files, etc., and accordingly, the way in which computer program instructions are executed by a computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to the computer.

[0200] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example for illustration. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. The specific working process of the device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0201] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A data query method, characterized in that: include: Obtain the original query statement sent by the user to the target database; Generate a data statistics statement and a paging query statement according to the original query statement; Based on the data statistics statement, statistical information of the data to be accessed in the target database is obtained; the statistical information of the data to be accessed includes the total number of rows of the data to be accessed, the average data volume and the average number of rows of various types of data to be accessed; Based on the paging query statement, according to the statistical information of the data to be accessed, paging iterative access is performed on the data to be accessed in the target database, so as to save the paging of the data to be accessed into the business process memory; The step of generating a data statistics statement and a paging query statement according to the original query statement includes: According to the key information analysis result of the original query statement, intercepting the target character string in the original query statement; Generate the data statistics statement according to the target character string; According to the key information analysis result of the original query statement, before intercepting the target character string in the original query statement, the method further includes: Filter key elements in the original query statement to obtain key element filtering results; Determine a key information analysis result of the original query statement according to the position of each of the key elements represented by the key element screening result in the original query statement; The step of generating a data statistics statement and a paging query statement according to the original query statement includes: The target paging query string is concatenated at the end of the original query statement to expand the original query statement into a paging query statement.

2. The method according to claim 1, characterized in that The acquiring statistical information of the data to be accessed in the target database based on the data statistical statement includes: Saving the data statistics statement to a statistics query interface of a preset query device, so that the preset query device applies the data statistics statement by calling the statistics query interface; The target database returns the statistical information of the to-be-accessed data to the preset query device in response to the data statistical statement.

3. The method according to claim 1, characterized in that: The step of performing paging iterative access to the data to be accessed in the target database based on the paging query statement and according to the statistical information of the data to be accessed includes: Saving the paging query statement to a paging query interface of a preset query device, so that the preset query device applies the paging query statement by calling the paging query interface; The target database returns the paging query result of the to-be-accessed data to the preset query device in response to the paging query statement; According to the statistical information of the data to be accessed and the paging query result currently returned by the target database, paging iterative access is performed on the data to be accessed in the target database.

4. The method according to claim 3, characterized in that The step of performing paging iterative access to the data to be accessed in the target database according to the statistical information of the data to be accessed and the paging query result currently returned by the target database includes: Determine the total amount of data to be accessed based on the statistical information of the data to be accessed; According to the paging query result currently returned by the target database, determining whether the iterative access to the current page data is completed; When it is determined that the iteration of the current page data is completed and the amount of data currently iteratively accessed is less than the total amount of data, the paging query parameters in the paging query statement are updated to obtain a new paging query statement, so as to perform paging iterative access to the data to be accessed in the target database based on the new paging query statement.

5. The method according to claim 4, characterized in that The updating of the paging query parameters in the paging query statement to obtain a new paging query statement includes: Increasing the starting page number in the paging query statement to update the starting page number in the paging query statement to obtain a new paging query statement; The paging query parameters in the paging query statement at least include a starting page number.

6. The method according to claim 4, characterized in that The method further comprises: When the amount of data currently iteratively accessed reaches the total amount of data, an empty object is returned to indicate that the paging iterative access to the data to be accessed has been completed.

7. The method according to claim 4, characterized in that The method further comprises: When it is determined that the iteration of the current page data has not been completed, the current page data is continuously accessed by paging iteration according to the current iteration cursor.

8. The method according to claim 7, characterized in that The step of continuing to perform paging iterative access to the current page data according to the current iterative cursor includes: Determine the unaccessed data in the current page data according to the modulus calculation result of the current iteration cursor and the current page data size; According to the unaccessed data in the current page data, the current iteration cursor is increased to continue to perform paged iterative access on the current page data.

9. A data query device, characterized in that: include: A first acquisition module is used to acquire the original query statement sent by the user to the target database; A generation module, used to generate a data statistics statement and a paging query statement according to the original query statement; A second acquisition module is used to acquire statistical information of the data to be accessed in the target database based on the data statistics statement; the statistical information of the data to be accessed includes the total number of rows of the data to be accessed, the average data volume and the average number of rows of multiple types of data to be accessed; A query module, configured to perform paging iterative access to the data to be accessed in the target database based on the paging query statement and according to the statistical information of the data to be accessed, so as to save the paging of the data to be accessed into the business process memory; The generating module is specifically used for: According to the key information analysis result of the original query statement, intercepting the target character string in the original query statement; Generate the data statistics statement according to the target character string; The generating module is further used for: According to the key information analysis result of the original query statement, before intercepting the target character string in the original query statement, the key elements are screened in the original query statement to obtain a key element screening result; Determine a key information analysis result of the original query statement according to the position of each of the key elements represented by the key element screening result in the original query statement; The generating module is specifically used for: The target paging query string is concatenated at the end of the original query statement to expand the original query statement into a paging query statement.

10. An electronic device, characterized in that: include: at least one processor and memory; The memory stores computer-executable instructions; The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor performs the method according to any one of claims 1 to 8.

11. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when a processor executes the computer-executable instructions, the method according to any one of claims 1 to 8 is implemented.

12. A computer program product, characterized in that The method comprises computer instructions for causing a computer to execute the method according to any one of claims 1 to 8.

Citation Information

Patent Citations

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

    CN115687417A

  • Method for caching storage process vernier result set of database, medium and product

    CN118410087A