CN110716949A - Method, device, medium and electronic equipment for automatically optimizing structured query statement - Google Patents

Method, device, medium and electronic equipment for automatically optimizing structured query statement Download PDF

Info

Publication number
CN110716949A
CN110716949A CN201910853947.XA CN201910853947A CN110716949A CN 110716949 A CN110716949 A CN 110716949A CN 201910853947 A CN201910853947 A CN 201910853947A CN 110716949 A CN110716949 A CN 110716949A
Authority
CN
China
Prior art keywords
structured query
query statement
optimized
optimizable
variable
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201910853947.XA
Other languages
Chinese (zh)
Inventor
胡鹏强
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ping An Puhui Enterprise Management Co Ltd
Original Assignee
Ping An Puhui Enterprise Management Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ping An Puhui Enterprise Management Co Ltd filed Critical Ping An Puhui Enterprise Management Co Ltd
Priority to CN201910853947.XA priority Critical patent/CN110716949A/en
Publication of CN110716949A publication Critical patent/CN110716949A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2453Query optimisation

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application relates to a method, a device, a medium and electronic equipment for automatically optimizing a structured query statement, belonging to the technical field of code optimization, wherein the method comprises the following steps: scanning a structured query statement in a target file to obtain an optimized structured query statement in the target file; judging whether the optimizable structured query statement meets a corresponding preset optimization condition; when the optimizable structured query statement meets a corresponding preset optimization condition, acquiring a preset optimization template corresponding to the optimizable structured query statement; obtaining an optimized structured query statement of the optimized structured query statement according to the preset optimization template and the optimized structured query statement; replacing the optimizable structured query statement with the optimized structured query statement. According to the method and the device, when the structured query statement meets the optimization condition, the efficient and accurate optimization of the structured query statement is realized through the optimization template.

Description

Method, device, medium and electronic equipment for automatically optimizing structured query statement
Technical Field
The application relates to the technical field of code optimization, in particular to a method, a device, a medium and electronic equipment for automatically optimizing a structured query statement.
Background
Structured Query Language (SQL), a special purpose programming Language, is a database Query and programming Language for accessing data and querying, updating, and managing relational database systems; and is also an extension of the database script file.
Currently, the optimization of the written structured query statement for application is performed by a large amount of investigation work by a worker, and then the investigated optimized structured query statement is optimized according to the work experience. In the prior art, the optimization of the structured query statement cannot be automatically performed according to the specific application environment of the structured query statement, and the optimization accuracy and efficiency are not high.
It is to be noted that the information disclosed in the above background section is only for enhancement of understanding of the background of the present application and therefore may include information that does not constitute prior art known to a person of ordinary skill in the art.
Disclosure of Invention
The application aims to provide an automatic optimization scheme for the structured query statement, and therefore when the structured query statement meets the optimization conditions at least to a certain extent, efficient and accurate optimization of the structured query statement is achieved through an optimization template.
According to one aspect of the application, an automatic optimization method for a structured query statement is provided, which includes:
scanning a structured query statement in a target file to obtain an optimized structured query statement in the target file;
judging whether the optimizable structured query statement meets a preset optimization condition corresponding to the optimizable structured query statement;
when the optimizable structured query statement meets a preset optimization condition corresponding to the optimizable structured query statement, acquiring a preset optimization template corresponding to the optimizable structured query statement;
obtaining an optimized structured query statement of the optimized structured query statement according to the preset optimization template and the optimized structured query statement;
replacing the optimizable structured query statement with the optimized structured query statement.
In an exemplary embodiment of the application, the determining whether the optimizable structured query statement satisfies a preset optimization condition corresponding to the optimizable structured query statement includes:
obtaining a query object of the optimized structured query statement;
verifying whether the target data volume corresponding to the query object exceeds a preset threshold value;
and when the target data volume corresponding to the query object exceeds a preset threshold value, determining whether the optimized structured query statement meets a preset optimization condition corresponding to the optimized structured query statement.
In an exemplary embodiment of the present application, a first tag is added to each of the optimizable structured query statements in advance, the first tag is associated with a second tag of a preset optimization template in a preset optimization template library,
the obtaining of the preset optimization template corresponding to the optimized structured query statement includes:
obtaining a first tag of the optimizable structured query statement;
searching the second label related to the first label from a preset optimization template library;
and taking the preset optimization template corresponding to the second label as the preset optimization template corresponding to the optimized structured query statement.
In an exemplary embodiment of the application, the obtaining an optimized structured query statement of the optimizable structured query statement according to the preset optimization template and the optimizable structured query statement includes:
obtaining query variables in the optimized structured query statement;
acquiring the storage position of the query variable from the preset optimization template;
and storing the query variable to the storage position to obtain the optimized structured query statement of the optimized structured query statement.
In an exemplary embodiment of the present application, said saving said query variable to said storage location comprises:
acquiring a query variable transformation rule corresponding to a preset optimization template from which the storage position comes;
converting the query variable into a pre-stored query variable according to the query variable conversion rule;
and saving the pre-stored query variable to the storage position.
In an exemplary embodiment of the present application, the converting the query variable into a pre-stored query variable according to the query variable transformation rule, where the pre-stored query variable includes:
and the plurality of sub-prestored inquiry variables are provided, wherein each sub-prestored inquiry variable is provided with a corresponding variable label.
In an exemplary embodiment of the present application, the saving the pre-stored query variable to the storage location includes:
acquiring each sub-prestored inquiry variable in the prestored inquiry variables;
acquiring each sub-storage position in the storage positions;
acquiring the sub-storage positions corresponding to the sub-prestored inquiry variables;
and storing each sub-prestored inquiry variable to the sub-storage position corresponding to each sub-prestored inquiry variable.
According to one aspect of the present application, there is provided an apparatus for automatically optimizing a structured query statement, comprising:
the scanning module is used for scanning the structured query statement in the target file to obtain the optimized structured query statement in the target file;
the judging module is used for judging whether the optimized structured query statement meets a preset optimization condition corresponding to the optimized structured query statement;
a first obtaining module, configured to obtain a preset optimization template corresponding to the optimizable structured query statement when the optimizable structured query statement satisfies a preset optimization condition corresponding to the optimizable structured query statement;
a second obtaining module, configured to obtain an optimized structured query statement of the optimized structured query statement according to the preset optimization template and the optimized structured query statement;
a replacement module to replace the optimizable structured query statement with the optimized structured query statement.
According to an aspect of the present application, there is provided a computer-readable storage medium having a structured query statement automatic optimization program stored thereon, wherein the structured query statement automatic optimization program, when executed by a processor, implements the method of any one of the above.
According to an aspect of the present application, there is provided an electronic device, comprising:
a processor; and
a memory for storing a structured query statement automatic optimization program of the processor; wherein the processor is configured to perform the method of any of the above via execution of the structured query statement auto-optimizer.
The method comprises the steps of firstly, scanning the structured query statement in a target file to obtain an optimized structured query statement in the target file; all query statements with optimization potential in the target file can be obtained, and then whether the optimized structured query statement meets the preset optimization condition corresponding to the optimized structured query statement or not is judged; a partially structured query statement that can improve query performance after optimization in the current scenario can be determined. Then, when the optimizable structured query statement meets a preset optimization condition corresponding to the optimizable structured query statement, acquiring a preset optimization template corresponding to the optimizable structured query statement; in this way, each query statement can be accurately optimized in subsequent steps according to the optimization template corresponding to each optimizable structured query statement. And then, after the optimized structured query statement of the optimized structured query statement is obtained according to the preset optimization template and the optimized structured query statement, replacing the optimized structured query statement with the optimized structured query statement. The method can realize the high-efficiency and accurate optimization of the structured query statement by optimizing the template when the structured query statement meets the optimization condition, thereby improving the query efficiency while effectively ensuring the query accuracy.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the application.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and together with the description, serve to explain the principles of the application. It is obvious that the drawings in the following description are only some embodiments of the application, and that for a person skilled in the art, other drawings can be derived from them without inventive effort.
FIG. 1 schematically illustrates a flow diagram of a method for automatic optimization of structured query statements.
FIG. 2 schematically shows an exemplary diagram of an application scenario of a method for automatically optimizing a structured query statement.
FIG. 3 schematically illustrates a flow diagram of a method of obtaining an optimized structured query statement.
FIG. 4 is a block diagram schematically illustrating an apparatus for automatic optimization of structured query statements.
FIG. 5 schematically illustrates an example block diagram of an electronic device for implementing the above-described method for automatic optimization of structured query statements.
FIG. 6 schematically illustrates a computer-readable storage medium for implementing the above-described method for automatic optimization of structured query statements.
Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. Example embodiments may, however, be embodied in many different forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of example embodiments to those skilled in the art. The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a thorough understanding of embodiments of the application. One skilled in the relevant art will recognize, however, that the subject matter of the present application can be practiced without one or more of the specific details, or with other methods, components, devices, steps, and so forth. In other instances, well-known technical solutions have not been shown or described in detail to avoid obscuring aspects of the present application.
Furthermore, the drawings are merely schematic illustrations of the present application and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and thus their repetitive description will be omitted. Some of the block diagrams shown in the figures are functional entities and do not necessarily correspond to physically or logically separate entities. These functional entities may be implemented in the form of software, or in one or more hardware modules or integrated circuits, or in different networks and/or processor devices and/or microcontroller devices.
In the present exemplary embodiment, an automatic optimization method for a structured query statement is first provided, and the automatic optimization method for a structured query statement may be executed on a server, or may be executed on a server cluster or a cloud server, or the like. Referring to fig. 1, the method for automatically optimizing the structured query statement may include the following steps:
step S110, scanning a structured query statement in a target file to obtain an optimized structured query statement in the target file;
step S120, judging whether the optimizable structured query statement meets a preset optimization condition corresponding to the optimizable structured query statement;
step S130, when the optimizable structured query statement meets a preset optimization condition corresponding to the optimizable structured query statement, acquiring a preset optimization template corresponding to the optimizable structured query statement;
step S140, obtaining an optimized structured query statement of the optimized structured query statement according to the preset optimization template and the optimized structured query statement;
step S150, replacing the optimized structured query statement with the optimized structured query statement.
In the method for automatically optimizing the structured query statement, firstly, the structured query statement in a target file is scanned to obtain an optimized structured query statement in the target file; all query statements with optimization potential in the target file can be obtained, and then whether the optimized structured query statement meets the preset optimization condition corresponding to the optimized structured query statement or not is judged; a partially structured query statement that can improve query performance after optimization in the current scenario can be determined. Then, when the optimizable structured query statement meets a preset optimization condition corresponding to the optimizable structured query statement, acquiring a preset optimization template corresponding to the optimizable structured query statement; in this way, each query statement can be accurately optimized in subsequent steps according to the optimization template corresponding to each optimizable structured query statement. And then, after the optimized structured query statement of the optimized structured query statement is obtained according to the preset optimization template and the optimized structured query statement, replacing the optimized structured query statement with the optimized structured query statement. The method can realize the high-efficiency and accurate optimization of the structured query statement by optimizing the template when the structured query statement meets the optimization condition, thereby improving the query efficiency while effectively ensuring the query accuracy.
Hereinafter, each step in the above-described structured query statement automatic optimization method in the present exemplary embodiment will be explained and explained in detail with reference to the drawings.
In step S110, the structured query statement in the target file is scanned to obtain an optimizable structured query statement in the target file.
In the embodiment of the present example, referring to fig. 2, the server 201 scans the structured query statement in the target file stored on the server 202, and the scan algorithm with different scan objects of the optimizable query statement accurately obtains the optimizable structured query statement in the target file. This allows the server 201 to optimize the structured query statement in time in subsequent steps. It will be appreciated that the structured query statement for the target file stored on itself may also be scanned directly by the server 202. The server 201 and the server 202 may be any devices with processing capability, such as a computer, a microprocessor, etc., and are not limited herein.
The optimized structured query statement is a structured query statement that can be further optimized according to a specific application environment, that is, a structured query statement with optimization potential. The structured query sentence containing the corresponding keyword or the corresponding sentence pattern can be accurately scanned through the set keyword or sentence pattern. The method can accurately scan the structured query statement in the target file through a preset scanning algorithm for scanning the optimized structured query statement from the target file to obtain the optimized structured query statement in the target file. And then, in the subsequent steps, whether the optimized structured query statements meet the optimization conditions in the corresponding query environment can be judged, namely whether performance improvement can be brought after optimization in the corresponding query environment.
In step S120, it is determined whether the optimizable structured query statement satisfies a preset optimization condition corresponding to the optimizable structured query statement.
In the embodiment of the present example, the preset optimization condition corresponding to the optimized structured query statement is a condition that each optimized structured query statement can achieve query performance improvement after being optimized, such as a preset optimization time threshold or a query data amount threshold. For example, the optimization condition of a query statement is that in a case where '+' is not necessarily used in the SELECT query clause, because Oracle converts '+' into all column names in sequence during parsing, which is completed by querying the data dictionary, which means that more time is consumed, and the preset optimization condition is a time threshold corresponding to the query time of the statement where "+" exists, for example, 10 seconds, etc. Therefore, whether the optimized structured query statement can be truly optimized in the current application environment can be accurately judged by judging whether the optimized structured query statement meets the preset optimization condition corresponding to the optimized structured query statement, and the accuracy of optimization is effectively ensured.
In an implementation manner of this example, the determining whether the optimizable structured query statement satisfies a preset optimization condition corresponding to the optimizable structured query statement includes:
obtaining a query object of the optimized structured query statement;
verifying whether the target data volume corresponding to the query object exceeds a preset threshold value;
and when the target data volume corresponding to the query object exceeds a preset threshold value, determining whether the optimized structured query statement meets a preset optimization condition corresponding to the optimized structured query statement.
The query object is the object of operations such as traversal query of a structured query statement and the like; the efficiency of query processing can be judged by verifying whether the target data volume corresponding to the query object exceeds a preset threshold value, and whether optimization is performed or not is further determined. For example, select from a floor id in (select id from B), select from a floor exists (select 1from B floor a. id. B. id); for the above two cases, in is the traversal comparison in the memory, and exists needs to query the database, so when the data amount of the B table is large, for example, when the data amount of the B table exceeds a predetermined threshold, exists efficiency is better than in, and when the data amount of the B table exceeds the predetermined threshold, for a select _ from a where id in (select id from B) query statement, the preset optimization condition corresponding to the optimizable structured query statement is satisfied.
In an implementation manner of this example, determining whether the optimizable structured query statement satisfies a preset optimization condition corresponding to the optimizable structured query statement includes:
obtaining the current query time of each optimized structured query statement;
acquiring a preset optimization time threshold corresponding to the sentence pattern of each optimized structured query sentence;
and when the current query time exceeds the preset optimization time threshold, determining that the optimized structured query statement meets a preset optimization condition corresponding to the optimized structured query statement.
The current query time of each optimized structured query statement is obtained by monitoring the query starting time point of each structured query statement to the query proceeding time point through a monitor, and then the preset optimization time threshold value for ensuring the query efficiency is set by experts in the structured query statements of different sentence patterns in advance. And when the current query time exceeds the preset optimization time threshold, the current query efficiency of the optimizable structured query statement is low, and the optimizable structured query statement is determined to meet the preset optimization condition corresponding to the optimizable structured query statement. And may then be optimized in subsequent steps to a corresponding more efficient query statement.
In step S130, when the optimizable structured query statement satisfies a preset optimization condition corresponding to the optimizable structured query statement, a preset optimization template corresponding to the optimizable structured query statement is obtained.
In the embodiment of this example, the preset optimization template corresponding to the optimizable structured query statement is a template for performing structure optimization on the optimizable structured query statement. For example, one structured query statement is: SELECT from fromoraters WHERE (customer _ num: 104AND order _ num >1001) OR order _ num: 1008; the optimization template corresponding to the statement is: SELECT FROM orders WHERE order _ num & & order _ num > & & UNION SELECT &' FROM orders WHERE order _ num &. The variables of the structural query statement are represented by &, &and & & respectively, and the optimized statement can be accurately obtained only by filling the variables in the optimized structural query statement into the corresponding position of the template; therefore, the query can be processed by utilizing the index path, a large number of data result sets exist, and the efficiency of the subsequent statement is high under the condition that the result set is not large after the query condition is limited. In this way, all optimizable structured query statements that satisfy the optimization criteria can be accurately optimized.
In one embodiment of the present example, a first tag is added to each of the optimizable structured query statements in advance, the first tag is associated with a second tag of a preset optimization template in a preset optimization template library,
the obtaining of the preset optimization template corresponding to the optimized structured query statement includes:
obtaining a first tag of the optimizable structured query statement;
searching the second label related to the first label from a preset optimization template library;
and taking the preset optimization template corresponding to the second label as the preset optimization template corresponding to the optimized structured query statement.
All the preset optimization templates are stored in the preset optimization template library, and each preset optimization template is calibrated with a second label. Each second tag is associated with a uniquely associated first tag. A first tag is associated with the scanning algorithm template for each optimizable structured query statement. A first label may be added to each optimizable structured query statement after each optimizable structured query statement is scanned. Further, a first label of the optimized structured query statement is obtained; then, the second label related to the first label is searched from a preset optimization template library. In this way, the preset optimization template corresponding to the second tag can be accurately found and used as the preset optimization template corresponding to the optimized structured query statement. Therefore, the accuracy and efficiency of obtaining the preset optimized template can be effectively ensured.
In step S140, an optimized structured query statement of the optimized structured query statement is obtained according to the preset optimization template and the optimized structured query statement.
In the embodiment of the present example, according to each preset optimization template and the corresponding optimizable structured query statement, after obtaining the variable of each optimizable structured query statement, the variable may be added to the preset optimization template, so as to obtain an optimized structured query statement of the optimizable structured query statement. For example, one structured query statement is: SELECT from fromoraters WHERE (customer _ num: 104AND order _ num >1001) OR order _ num: 1008; the optimization template corresponding to the statement is: SELECT FROM orders WHERE order _ num & & order _ num > & & UNION SELECT &' FROM orders WHERE order _ num &. The variables of the structural query statement are represented by &, &and & & respectively, and the optimized statement can be accurately obtained only by filling the variables in the optimized structural query statement into the corresponding position of the template: SELECT FROM orders WHERE order _ num 104AND order _ num >1001 unit SELECT 1008. In this way, the optimized structured query statement for each optimizable structured query statement may be accurately obtained.
In an implementation manner of this example, the obtaining an optimized structured query statement of the optimized structured query statement according to the preset optimization template and the optimized structured query statement, with reference to fig. 3, includes:
step S310, obtaining query variables in the optimized structured query statement;
step S320, obtaining the storage position of the query variable from the preset optimization template;
step S330, saving the query variable to the storage location to obtain the optimized structured query statement of the optimized structured query statement.
By obtaining query variables that can optimize the structured query statement, for example, variables 104, 1001, 1008 are obtained FROM SELECT FROM front orders where (customer _ num > 104AND order _ num >1001) OR order _ num > 1008; then, the storage locations of the query variables are obtained FROM a preset optimization template, for example, the preset optimization template is SELECT × (FROM orders) WHERE user client _ num ═ AND order _ num > & & UNION SELECT × (FROM orders) WHERE user order _ num &, AND the storage locations of the three query variables can be obtained. By presetting the incidence relation of variables at various positions between the preset optimization template and the optimized structured query statement, the position of each variable in the optimized structured query statement in the preset optimization template can be accurately obtained, and then the query variables are stored in a storage position to obtain the optimized structured query statement of the optimized structured query statement. Therefore, the optimization accuracy of each structured query statement can be effectively ensured.
In an embodiment of this example, said saving the query variable to the storage location includes:
acquiring a query variable transformation rule corresponding to a preset optimization template from which the storage position comes;
converting the query variable into a pre-stored query variable according to the query variable conversion rule;
and saving the pre-stored query variable to the storage position.
The structure of some preset optimization templates changes relative to the optimizable structured query statement, and the variables also change. For example, after the SELECT FROM 'table name' order by rand () LIMIT 10 is optimized, it is: SELECT FROM table name (WHERE id) ((SELECT MAX (id) FROM table name) - (SELECT MIN (id) FROM table name))) RAND () (SELECT MIN (id) FROM table name) LIMIT 10. By setting a variable transformation rule for the preset optimization template in advance, the variables of the optimizable structured query statement can be accurately transformed to obtain pre-stored query variables, for example, three table names' in the optimizable structured query statement are copied. The pre-stored query variables are then saved to a storage location. Therefore, the optimization accuracy of each structured query statement can be effectively ensured.
In an implementation manner of this example, the converting, according to the query variable transformation rule, the query variable into a pre-stored query variable, where the pre-stored query variable includes:
and the plurality of sub-prestored inquiry variables are provided, wherein each sub-prestored inquiry variable is provided with a corresponding variable label.
According to the variable label corresponding to each sub-pre-stored query variable, the sub-pre-stored variable can be accurately distinguished, and further, in the subsequent step, the storage position of each sub-pre-stored variable can be queried according to the label.
In an implementation manner of this example, the saving the pre-stored query variable to the storage location includes:
acquiring each sub-prestored inquiry variable in the prestored inquiry variables;
acquiring each sub-storage position in the storage positions;
acquiring the sub-storage positions corresponding to the sub-prestored inquiry variables;
and storing each sub-prestored inquiry variable to the sub-storage position corresponding to each sub-prestored inquiry variable.
The sub-prestored query variables are each individual variable, and the sub-storage locations are each individual variable storage location. By means of adding labels corresponding to the sub-storage positions of the preset optimization template and the like when obtaining the variables at the corresponding positions of each optimized structured query sentence, the sub-storage positions corresponding to the sub-prestored query variables can be accurately obtained, and then the sub-prestored query variables are stored in the sub-storage positions corresponding to the sub-prestored query variables. The optimization accuracy is effectively ensured.
In step S150, the optimizable structured query statement is replaced with the optimized structured query statement.
In the embodiment of the present example, the optimized structured query statement is used to replace the optimizable structured query statement, so that query can be performed by using the optimized structured query statement, and query efficiency in the current scenario is effectively ensured.
In a word, according to the scheme, optimization can be efficiently and accurately completed when each optimized structured query statement can be accurately judged to be optimized according to the specific application environment of each structured query statement.
The application also provides an automatic optimization device for the structured query statement. Referring to fig. 4, the apparatus for automatically optimizing a structured query statement may include a scanning module 410, a determining module 420, a first obtaining module 430, a second obtaining module 440, and a replacing module 450. Wherein:
the scanning module 410 may be configured to scan the structured query statement in the target file to obtain an optimizable structured query statement in the target file;
the determining module 420 may be configured to determine whether the optimizable structured query statement satisfies a preset optimization condition corresponding to the optimizable structured query statement;
the first obtaining module 430 may be configured to obtain a preset optimization template corresponding to the optimizable structured query statement when the optimizable structured query statement satisfies a preset optimization condition corresponding to the optimizable structured query statement;
the second obtaining module 440 may be configured to obtain the optimized structured query statement of the optimized structured query statement according to the preset optimization template and the optimized structured query statement;
the replacement module 450 may be used to replace the optimizable structured query statement with the optimized structured query statement.
The specific details of each module in the above automatic optimization device for structured query statements have been described in detail in the corresponding automatic optimization method for structured query statements, and therefore are not described herein again.
It should be noted that although in the above detailed description several modules or units of the device for action execution are mentioned, such a division is not mandatory. Indeed, the features and functionality of two or more modules or units described above may be embodied in one module or unit, according to embodiments of the application. Conversely, the features and functions of one module or unit described above may be further divided into embodiments by a plurality of modules or units.
Moreover, although the steps of the methods herein are depicted in the drawings in a particular order, this does not require or imply that the steps must be performed in this particular order, or that all of the depicted steps must be performed, to achieve desirable results. Additionally or alternatively, certain steps may be omitted, multiple steps combined into one step execution, and/or one step broken down into multiple step executions, etc.
Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein may be implemented by software, or by software in combination with necessary hardware. Therefore, the technical solution according to the embodiments of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a usb disk, a removable hard disk, etc.) or on a network, and includes several instructions to enable a computing device (which can be a personal computer, a server, a mobile terminal, or a network device, etc.) to execute the method according to the embodiments of the present application.
In an exemplary embodiment of the present application, there is also provided an electronic device capable of implementing the above method.
As will be appreciated by one skilled in the art, aspects of the present invention may be embodied as a system, method or program product. Thus, various aspects of the invention may be embodied in the form of: an entirely hardware embodiment, an entirely software embodiment (including firmware, microcode, etc.) or an embodiment combining hardware and software aspects that may all generally be referred to herein as a "circuit," module "or" system.
An electronic device 500 according to this embodiment of the invention is described below with reference to fig. 5. The electronic device 500 shown in fig. 5 is only an example and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 5, the electronic device 500 is embodied in the form of a general purpose computing device. The components of the electronic device 500 may include, but are not limited to: the at least one processing unit 510, the at least one memory unit 520, and a bus 530 that couples various system components including the memory unit 520 and the processing unit 510.
Wherein the storage unit stores program code that is executable by the processing unit 510 to cause the processing unit 510 to perform steps according to various exemplary embodiments of the present invention as described in the above section "exemplary methods" of the present specification. For example, the processing unit 510 may execute step S110 as shown in fig. 1: scanning a structured query statement in a target file to obtain an optimized structured query statement in the target file; s120: judging whether the optimizable structured query statement meets a preset optimization condition corresponding to the optimizable structured query statement; step S130: when the optimizable structured query statement meets a preset optimization condition corresponding to the optimizable structured query statement, acquiring a preset optimization template corresponding to the optimizable structured query statement; step S140: obtaining an optimized structured query statement of the optimized structured query statement according to the preset optimization template and the optimized structured query statement; step S150: replacing the optimizable structured query statement with the optimized structured query statement.
The memory unit 520 may include a readable medium in the form of a volatile memory unit, such as a random access memory unit (RAM)5201 and/or a cache memory unit 5202, and may further include a read only memory unit (ROM) 5203.
Storage unit 520 may also include a program/utility 5204 having a set (at least one) of program modules 5205, such program modules 5205 including, but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may comprise an implementation of a network environment.
Bus 530 may be one or more of any of several types of bus structures including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
The electronic device 500 may also communicate with one or more external devices 700 (e.g., keyboard, pointing device, bluetooth device, etc.), with one or more devices that enable a client to interact with the electronic device 500, and/or with any devices (e.g., router, modem, etc.) that enable the electronic device 500 to communicate with one or more other computing devices. Such communication may occur via input/output (I/O) interfaces 550. Also, the electronic device 500 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network, such as the internet) via the network adapter 560. As shown, the network adapter 560 communicates with the other modules of the electronic device 500 over the bus 530. It should be appreciated that although not shown in the figures, other hardware and/or software modules may be used in conjunction with the electronic device 500, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems, among others.
Through the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein may be implemented by software, or by software in combination with necessary hardware. Therefore, the technical solution according to the embodiments of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a usb disk, a removable hard disk, etc.) or on a network, and includes several instructions to make a computing device (which can be a personal computer, a server, a terminal device, or a network device, etc.) execute the method according to the embodiments of the present application.
In an exemplary embodiment of the present application, there is also provided a computer-readable storage medium having stored thereon a program product capable of implementing the above-described method of the present specification. In some possible embodiments, aspects of the invention may also be implemented in the form of a program product comprising program code means for causing a terminal device to carry out the steps according to various exemplary embodiments of the invention described in the above section "exemplary methods" of the present description, when said program product is run on the terminal device.
Referring to fig. 6, a program product 600 for implementing the above method according to an embodiment of the present invention is described, which may employ a portable compact disc read only memory (CD-ROM) and include program code, and may be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited in this regard and, in the present document, a readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
A computer readable signal medium may include a propagated data signal with readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A readable signal medium may also be any readable medium that is not a readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the client computing device, partly on the client device, as a stand-alone software package, partly on the client computing device and partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the client computing device over any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., over the internet using an internet service provider).
Furthermore, the above-described figures are merely schematic illustrations of processes involved in methods according to exemplary embodiments of the invention, and are not intended to be limiting. It will be readily understood that the processes shown in the above figures are not intended to indicate or limit the chronological order of the processes. In addition, it is also readily understood that these processes may be performed synchronously or asynchronously, e.g., in multiple modules.
Other embodiments of the present application will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention following, in general, the principles of the application and including such departures from the present disclosure as come within known or customary practice within the art to which the invention pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the application being indicated by the following claims.

Claims (10)

1. An automatic optimization method for a structured query statement, comprising:
scanning a structured query statement in a target file to obtain an optimized structured query statement in the target file;
judging whether the optimizable structured query statement meets a preset optimization condition corresponding to the optimizable structured query statement;
when the optimizable structured query statement meets a preset optimization condition corresponding to the optimizable structured query statement, acquiring a preset optimization template corresponding to the optimizable structured query statement;
obtaining an optimized structured query statement of the optimized structured query statement according to the preset optimization template and the optimized structured query statement;
replacing the optimizable structured query statement with the optimized structured query statement.
2. The method of claim 1, wherein the determining whether the optimizable structured query statement satisfies a preset optimization condition corresponding to the optimizable structured query statement comprises:
obtaining a query object of the optimized structured query statement;
verifying whether the target data volume corresponding to the query object exceeds a preset threshold value;
and when the target data volume corresponding to the query object exceeds a preset threshold value, determining whether the optimized structured query statement meets a preset optimization condition corresponding to the optimized structured query statement.
3. The method of claim 1, wherein a first label is added to each of the optimizable structured query statements in advance, the first label being associated with a second label of a preset optimization template in a preset optimization template library,
the obtaining of the preset optimization template corresponding to the optimized structured query statement includes:
obtaining a first tag of the optimizable structured query statement;
searching the second label related to the first label from a preset optimization template library;
and taking the preset optimization template corresponding to the second label as the preset optimization template corresponding to the optimized structured query statement.
4. The method of claim 1, wherein obtaining the optimized structured query statement for the optimizable structured query statement according to the preset optimization template and the optimizable structured query statement comprises:
obtaining query variables in the optimized structured query statement;
acquiring the storage position of the query variable from the preset optimization template;
and storing the query variable to the storage position to obtain the optimized structured query statement of the optimized structured query statement.
5. The method of claim 4, wherein saving the query variable to the storage location comprises:
acquiring a query variable transformation rule corresponding to a preset optimization template from which the storage position comes;
converting the query variable into a pre-stored query variable according to the query variable conversion rule;
and saving the pre-stored query variable to the storage position.
6. The method according to claim 5, wherein the query variable is converted into a pre-stored query variable according to the query variable conversion rule, and the pre-stored query variable comprises:
and the plurality of sub-prestored inquiry variables are provided, wherein each sub-prestored inquiry variable is provided with a corresponding variable label.
7. The method of claim 5, wherein saving the pre-stored query variable to the storage location comprises:
acquiring each sub-prestored inquiry variable in the prestored inquiry variables;
acquiring each sub-storage position in the storage positions;
acquiring the sub-storage positions corresponding to the sub-prestored inquiry variables;
and storing each sub-prestored inquiry variable to the sub-storage position corresponding to each sub-prestored inquiry variable.
8. An apparatus for automatic optimization of structured query statements, comprising:
the scanning module is used for scanning the structured query statement in the target file to obtain the optimized structured query statement in the target file;
the judging module is used for judging whether the optimized structured query statement meets a preset optimization condition corresponding to the optimized structured query statement;
a first obtaining module, configured to obtain a preset optimization template corresponding to the optimizable structured query statement when the optimizable structured query statement satisfies a preset optimization condition corresponding to the optimizable structured query statement;
a second obtaining module, configured to obtain an optimized structured query statement of the optimized structured query statement according to the preset optimization template and the optimized structured query statement;
a replacement module to replace the optimizable structured query statement with the optimized structured query statement.
9. A computer-readable storage medium having stored thereon a structured query statement automatic optimization program, wherein the structured query statement automatic optimization program, when executed by a processor, implements the method of any of claims 1-7.
10. An electronic device, comprising:
a processor; and
a memory for storing a structured query statement automatic optimization program of the processor; wherein the processor is configured to perform the method of any of claims 1-7 via execution of the structured query statement auto-optimizer.
CN201910853947.XA 2019-09-10 2019-09-10 Method, device, medium and electronic equipment for automatically optimizing structured query statement Pending CN110716949A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910853947.XA CN110716949A (en) 2019-09-10 2019-09-10 Method, device, medium and electronic equipment for automatically optimizing structured query statement

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910853947.XA CN110716949A (en) 2019-09-10 2019-09-10 Method, device, medium and electronic equipment for automatically optimizing structured query statement

Publications (1)

Publication Number Publication Date
CN110716949A true CN110716949A (en) 2020-01-21

Family

ID=69209818

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910853947.XA Pending CN110716949A (en) 2019-09-10 2019-09-10 Method, device, medium and electronic equipment for automatically optimizing structured query statement

Country Status (1)

Country Link
CN (1) CN110716949A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111831687A (en) * 2020-06-24 2020-10-27 平安普惠企业管理有限公司 Data query optimization method and device, computer equipment and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111831687A (en) * 2020-06-24 2020-10-27 平安普惠企业管理有限公司 Data query optimization method and device, computer equipment and storage medium

Similar Documents

Publication Publication Date Title
CN108519967B (en) Chart visualization method and device, terminal and storage medium
CN109902105B (en) Data query system, method, device and storage medium for micro-service architecture
CN109542901B (en) Data processing method and device, computer readable storage medium and electronic equipment
US10210240B2 (en) Systems and methods for code parsing and lineage detection
CN110554875B (en) Code conversion method and device, electronic equipment and storage medium
CN110825767A (en) Data query method, platform, equipment and storage medium
CN110688544A (en) Method, device and storage medium for querying database
CN109872230B (en) Test method and device of financial data analysis system, medium and electronic equipment
CN110727437A (en) Code optimization item acquisition method and device, storage medium and electronic equipment
CN109344374B (en) Report generation method and device based on big data, electronic equipment and storage medium
US11650875B2 (en) Abnormal inode dynamic repair method and system, and related component
US20230012642A1 (en) Method and device for snapshotting metadata, and storage medium
US20150106701A1 (en) Input support method and information processing system
CN111241111A (en) Data query method and device, data comparison method and device, medium and equipment
CN112000690B (en) Method and device for analyzing structured operation statement
CN112445775A (en) Fault analysis method, device, equipment and storage medium of photoetching machine
CN117076491A (en) Data processing method, storage medium and equipment
CN110716949A (en) Method, device, medium and electronic equipment for automatically optimizing structured query statement
CN110874364B (en) Query statement processing method, device, equipment and storage medium
CN110175128B (en) Similar code case acquisition method, device, equipment and storage medium
CN112818070A (en) Data query method and device based on global data dictionary and electronic equipment
CN111796833A (en) Code language conversion method, system, equipment and storage medium
CN115033592A (en) SQL statement processing method, device, equipment and storage medium based on database
CN113609128A (en) Method and device for generating database entity class, terminal equipment and storage medium
CN109697141B (en) Method and device for visual testing

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination