CN103164455B - The optimization method and device of data base - Google Patents

The optimization method and device of data base Download PDF

Info

Publication number
CN103164455B
CN103164455B CN201110421548.XA CN201110421548A CN103164455B CN 103164455 B CN103164455 B CN 103164455B CN 201110421548 A CN201110421548 A CN 201110421548A CN 103164455 B CN103164455 B CN 103164455B
Authority
CN
China
Prior art keywords
data base
code
statement
database
category information
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.)
Active
Application number
CN201110421548.XA
Other languages
Chinese (zh)
Other versions
CN103164455A (en
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.)
Beijing Baidu Netcom Science and Technology Co Ltd
Original Assignee
Beijing Baidu Netcom Science and Technology 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 Beijing Baidu Netcom Science and Technology Co Ltd filed Critical Beijing Baidu Netcom Science and Technology Co Ltd
Priority to CN201110421548.XA priority Critical patent/CN103164455B/en
Publication of CN103164455A publication Critical patent/CN103164455A/en
Application granted granted Critical
Publication of CN103164455B publication Critical patent/CN103164455B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Abstract

The present invention proposes the optimization method of a kind of data base, comprises the following steps: obtain the category information before virtual machine loads, and described category information is analyzed the database-driven category information determining in described category information;First code and the first operation category code is inweaved among described database-driven category information;Data base manipulation statement is obtained according to the described first code inweaved and the first operation category code;And according to described data base manipulation statement, described data base is optimized.Data base manipulation statement can be intercepted in the case of without intrusion by the present invention, and is optimized data base according to the data base manipulation statement intercepting acquisition further, thus promotes database performance.

Description

The optimization method and device of data base
Technical field
The present invention relates to field of computer technology, particularly to the optimization method and device of a kind of data base.
Background technology
JDBC (JavaDataBaseConnectivity, Java data base connects) it is a kind of for performing SQL (StructuredQueryLanguage, SQL) JavaAPI (ApplicationProgrammingInterface of statement, application programming interface), can be that multiple relational database provides unified access, class and interface that it is write with Java language by one group form.JDBC provides a kind of benchmark, can build instrument and the interface of higher level accordingly, enable database development personnel to write database application.Having had JDBCAPI, sending SQL statement to various relation datas is exactly a thing easily.In other words, there is JDBCAPI, just it is not necessarily access one program of sybase database bespoke, for Accessing Oracle Database one program of bespoke again, or write again another program etc. for accessing informix database, it is the most much of that programmer only need to write a program with JDBCAPI, and it can send SQL to associated databases and call.
At present, optimization analytical technology based on SQL statement is mainly all based on code intrusive mood or utilizes Java reflection technology to realize, such as p6spy product etc..The shortcoming of prior art is that the optimization analytical technology being currently based on SQL statement is required for revising JDBC connection driving configuration, not only operates complexity, and causes the stability of data base and safety all to decrease.
Summary of the invention
It is contemplated that at least solve one of technical problem present in prior art, particularly solve to need JDBC is connected and drive configuration to modify can to obtain the defect of SQL statement.
Embodiment of the present invention first aspect proposes the optimization method of a kind of data base, comprises the following steps: obtain the category information before virtual machine loads, and described category information is analyzed the database-driven category information determining in described category information;First code and the first operation category code is inweaved among described database-driven category information;Data base manipulation statement is obtained according to the described first code inweaved and the first operation category code;And according to described data base manipulation statement, described data base is optimized.
In one embodiment of the invention, above-mentioned optimization can be optimiged index or the large data sets optimization of data base.
Embodiment of the present invention second aspect also proposed the optimization system of a kind of data base, including virtual machine, virtual machine agency and DB connector, wherein, described virtual machine, for according to user instruction generate category information, and by described virtual machine agency inweave first code and first operation category code described database-driven category information be loaded;Virtual machine is acted on behalf of, for obtaining the category information before virtual machine loads, and described category information is analyzed the database-driven category information determining in described category information, and among described database-driven category information, inweave first code and the first operation category code, and by described virtual machine agency, laden for described virtual machine described database-driven category information is sent to DB connector;Described DB connector, for described laden database-driven category information is changed and is sent to data base, and by the described first operation category code described first code of execution to obtain described data base manipulation statement, and according to described data base manipulation statement, described data base is optimized.
In one embodiment of the invention, above-mentioned optimization can be optimiged index or the large data sets optimization of data base.
In the above embodiment of the present invention, the first code seamlessly inweaved by above-mentioned virtual machine agency and the first operation category code, can be without data base manipulation statement (such as SQL statement) being intercepted in the case of invading, and according to the data base manipulation statement intercepting acquisition, data base is optimized further, thus promote database performance.
The embodiment of the present invention third aspect also proposed the acquisition methods of a kind of data base manipulation statement, comprises the following steps: obtains the category information before virtual machine loads;Described category information is analyzed the database-driven category information determining in described category information;First code and the first operation category code is inweaved among described database-driven category information;Data base manipulation statement is obtained according to the described first code inweaved and the first operation category code.
In the above embodiment of the present invention, the first code seamlessly inweaved by above-mentioned virtual machine agency and the first operation category code, can be without data base manipulation statement (such as SQL statement) being intercepted in the case of invading, therefore without driving configuration to modify the connection of JDBC, thus improve the safety and stability of data base.
The additional aspect of the present invention and advantage will part be given in the following description, and part will become apparent from the description below, or is recognized by the practice of the present invention.
Accompanying drawing explanation
Above-mentioned and/or the additional aspect of the present invention and advantage will be apparent from easy to understand, wherein from combining the accompanying drawings below description to embodiment:
Fig. 1 is the flow chart of the optimization method of the data base of the embodiment of the present invention;
Fig. 2 is that the embodiment of the present invention inweaves the first operation category code and the schematic diagram of first code;
Fig. 3 is the method schematic diagram that data base is indexed optimizing by the embodiment of the present invention;
Fig. 4 is the example that embodiment of the present invention data base returns the result set explaining statement;
Fig. 5 is the method schematic diagram that the embodiment of the present invention carries out large data sets optimization to data base;
Fig. 6 is that the embodiment of the present invention inweaves the first operation category code, first code and the second operation category code and schematic diagram of second code;
Fig. 7 a and 7b is respectively the operation chart before large data sets optimizes and after optimization;
Fig. 8 is the structure chart of the optimization system of embodiment of the present invention data base;
Fig. 9 is the structure chart of the DB connector optimized for database index of the embodiment of the present invention;
Figure 10 is the structure chart of the DB connector optimized for data base's large data sets of the embodiment of the present invention;And
Figure 11 is the acquisition methods flow chart of the data base manipulation statement of the embodiment of the present invention.
Detailed description of the invention
Embodiments of the invention are described below in detail, and the example of described embodiment is shown in the drawings, and the most same or similar label represents same or similar element or has the element of same or like function.The embodiment described below with reference to accompanying drawing is exemplary, is only used for explaining the present invention, and is not considered as limiting the invention.
With reference to explained below and accompanying drawing, it will be clear that these and other aspects of embodiments of the invention.Describe at these and in accompanying drawing, specifically disclose some particular implementation in embodiments of the invention, representing some modes of the principle implementing embodiments of the invention, but it is to be understood that the scope of embodiments of the invention is not limited.On the contrary, all changes, amendment and the equivalent in the range of embodiments of the invention include falling into attached claims spirit and intension.
As it is shown in figure 1, be the flow chart of the optimization method of the data base of the embodiment of the present invention.The method comprises the following steps:
Step S101, virtual machine agency (agent) obtains the category information before virtual machine loads.In an embodiment of the present invention, virtual machine can be Java Virtual Machine.In current Java Virtual Machine technology, virtual machine agency provide a function, can obtain the category information before java class loads.Specifically, this category information is presented in bytecode.In one embodiment of the invention, these category informations are the category information loading core classes java.lang.ClassLoader to described Java Virtual Machine.Wherein, java.lang.ClassLoader is the class of load classes, and all of category information is all loaded among internal memory by java.lang.ClassLoader class.The present invention uses virtual machine to act on behalf of this characteristic of category information being obtained in that virtual machine passes through before java.lang.ClassLoader class loads just, realizes the seamless Dynamic Weave of embodiment of the present invention code.Thus be further implemented in and do not revise the acquisition realizing data base manipulation statement on the basis of JDBC connects driving configuration.
Embodiments of the invention may be adapted to the various data bases that JDBC is connected, such as Mysql data base, informix database, oracle database, sybase database etc..In following example of the present invention, to be described as a example by Mysql data base, it will be appreciated that those skilled in the art that the embodiment of the present invention can be additionally used in above-mentioned known or any data base of Future Development, as long as this data base can be supported by JDBC.
Step S102, virtual machine agency is analyzed the database-driven category information determining in category information to category information.Specifically, virtual machine agency be analyzed all category informations, filters according to the class name of category information, bag name etc., to determine database-driven category information among these category informations.In an embodiment of the present invention, as a example by Mysql data base, certain kinds com.mysql.jdbc.Driver that Mysql drives can be found, thus identify the loading that Mysql drives.In other embodiments of the invention, for other different types of data bases, it is possible to selecting the specific class of other database-driven, this is no longer going to repeat them.
Step S103, virtual machine agency inweaves first code and the first operation category code among database-driven category information, wherein, the first operation category code is the code of the instruction performing first code, and first code is for obtaining the data base manipulation statement in database-driven category information when executed.In one embodiment of the invention, still as a example by Mysql data base, wherein, first operation category code can be that common SQL statement performs description object StatementImpl, and pretreatment SQL statement performs description object PreparedStatment and storing process SQL statement performs the code of one or more in description object CallableStatement.As in figure 2 it is shown, inweave the first operation category code and the schematic diagram of first code for the embodiment of the present invention.In an embodiment of the present invention, the first operation category code and first code should perform before data base manipulation statement performs, and performed this first code by the first operation category code.The most as can be seen from the figure, first operation category code and first code between ClassStatementImpl and MethodStatementImpl so that the first operation category code and first code be limited to data base manipulation statement and by performed by DB connector.
Step S104, the database-driven category information inweaving first code and the first operation category code is loaded, and is sent laden database-driven category information to DB connector by virtual machine agency by virtual machine.In an embodiment of the present invention, the database-driven category information inweaving first code and the first operation category code can be loaded by virtual machine by core classes java.lang.ClassLoader, is loaded to internal memory.In an embodiment of the present invention, this DB connector can be Java DB connector, i.e. JDBC.
Step S105, laden database-driven category information is changed and is sent to data base, and performs first code to obtain data base manipulation statement by the first operation category code by DB connector.DB connector, before changing database-driven category information, can first pass through the first operation category code and perform first code to obtain data base manipulation statement.After obtaining data base manipulation statement, completing conversion and send the information after conversion to data base, data base can process according to normal flow.
Step S106, data base is optimized by DB connector according to data base manipulation statement.In an embodiment of the present invention, data base can be indexed optimization or large data sets optimization etc..Below in an example, will respectively optimiged index and large data sets optimization be described in detail.But skilled person would appreciate that, optimiged index and large data sets optimization are only the preferred embodiments of the present invention, those skilled in the art also can be according to data base manipulation statement after obtaining data base manipulation statement, and the thought of following optimiged index and large data sets optimization completes other optimization to data base, within the scope of these also should be included in the comprising of the embodiment of the present invention.
In the above embodiment of the present invention, the first code seamlessly inweaved by above-mentioned virtual machine agency and the first operation category code, can be without data base manipulation statement (such as SQL statement) being intercepted in the case of invading, and according to the data base manipulation statement intercepting acquisition, data base is optimized further, thus promote database performance.
As it is shown on figure 3, data base to be indexed for the embodiment of the present invention method schematic diagram optimized.The method comprises the following steps:
Step S301, virtual machine agency obtains the category information before virtual machine loads.In an embodiment of the present invention, virtual machine can be Java Virtual Machine.Specifically, this category information is presented in bytecode.In one embodiment of the invention, these category informations are the category information loading core classes java.lang.ClassLoader to described Java Virtual Machine.Wherein, java.lang.ClassLoader is the class of load classes, and all of category information is all loaded among internal memory by java.lang.ClassLoader class.Embodiments of the invention may be adapted to the various data bases that JDBC is connected, such as Mysql data base, informix database, oracle database, sybase database etc..
Step S302, virtual machine agency is analyzed the database-driven category information determining in category information to category information.Specifically, virtual machine agency be analyzed all category informations, filters according to the class name of category information, bag name etc., to determine database-driven category information among these category informations.
Step S303, virtual machine agency inweaves first code and the first operation category code among database-driven category information, wherein, the first operation category code is the code of the instruction performing first code, and first code is for obtaining the data base manipulation statement in database-driven category information when executed.In one embodiment of the invention, still as a example by Mysql data base, wherein, first operation category code can be that common SQL statement performs description object StatementImpl, and pretreatment SQL statement performs description object PreparedStatment and storing process SQL statement performs the code of one or more in description object CallableStatement.In an embodiment of the present invention, the first operation category code and first code should perform before data base manipulation statement performs, and performed this first code by the first operation category code.
Step S304, the database-driven category information inweaving first code and the first operation category code is loaded, and is sent laden database-driven category information to DB connector by virtual machine agency by virtual machine.In an embodiment of the present invention, the database-driven category information inweaving first code and the first operation category code can be loaded by virtual machine by core classes java.lang.ClassLoader, is loaded to internal memory.
Step S305, laden database-driven category information is changed and is sent to data base, and performs first code to obtain data base manipulation statement by the first operation category code by DB connector.DB connector, before changing database-driven category information, can first pass through the first operation category code and perform first code to obtain data base manipulation statement.
Step S306, DB connector judges whether data base manipulation statement is query sentence of database.In one embodiment of the invention, as a example by SQL statement (data base manipulation statement), can check whether this data base manipulation statement is query statement by the matching way that keyword " SELECT " is comprised, if comprising keyword " SELECT ", then it represents that current statement is query statement.If it is determined that be not query statement, then it be not required to be indexed optimizing, process according to existing procedure, do not repeat them here.
Step S307, if query sentence of database, then DB connector generates the explanation statement of data base manipulation statement according to data base manipulation statement.After determining that current SQL statement is query statement, then start that this statement is indexed service condition and be analyzed.First passing through the explain order that data base provides, rewrite SQL statement, such as, SQL statement is Select*fromstuentwherename=";The explanation statement of revised SQL statement is explainselect*fromstudentwherename=".
Step S308, the explanation statement of data base manipulation statement is sent to data base by DB connector.
Step S309, data base performs explaining statement and the result set explaining statement being back to DB connector of data base manipulation statement.As shown in Figure 4, the example of the result set explaining statement is returned for embodiment of the present invention data base.
Step S310, according to the result set of described explanation statement, DB connector judges whether described data base manipulation statement employs index.If having employed index, then without being indexed optimizing, according to existing flow processing.
Specifically, can referring also to Fig. 4, the embodiment of the present invention can according to return result set key, the value of this string judges whether to employ index.Wherein, the value of key row represents whether current SQL query statement employs index.If the value of key row is empty, then it represents that this SQL query statement does not make index of reference, therefore represent that this SQL query statement needs to carry out SQL and optimizes operation.If the value of key row is not empty, then it represents that this SQL query statement is used for index, represents and be made without optimiged index, according to existing flow processing.
Step S311, if it is determined that data base manipulation statement does not makes index of reference, then DB connector creates database index and creates statement, and data base creates statement transmission to data base to increase corresponding index in data base.In one embodiment of the invention, first DB connector resolves the field name obtained among data base manipulation statement to data base manipulation statement.Then, DB connector creates database index according to field name and creates statement.
Specifically, during if it find that current SQL statement does not make index of reference, then need to resolve this SQL statement by SQLparser, to obtain the field name in this SQL statement condition.Such as SQL query statement is " select*fromstudentwherename=", then can obtain name field name by SQLparser.DB connector can generate a statement creating index according to the field name obtained.Such as, DB connector can generate database index create statement, such as, CREATEINDEXstudent_nameONstudent (name) with name field name for row.Then, DB connector creates statement this database index and is sent to data base, data base can create statement according to this database index and automatically create a new index, to guarantee that original data base manipulation statement is before transmission respective request to data base, there is the index of correspondence, thus promote the efficiency of inquiry.
As it is shown in figure 5, data base to be carried out for the embodiment of the present invention method schematic diagram of large data sets optimization.The method comprises the following steps:
Step S501, virtual machine agency obtains the category information before virtual machine loads.In an embodiment of the present invention, virtual machine can be Java Virtual Machine.Specifically, this category information is presented in bytecode.In one embodiment of the invention, these category informations are the category information loading core classes java.lang.ClassLoader to described Java Virtual Machine.Wherein, java.lang.ClassLoader is the class of load classes, and all of category information is all loaded among internal memory by java.lang.ClassLoader class.Embodiments of the invention may be adapted to the various data bases that JDBC is connected, such as Mysql data base, informix database, oracle database, sybase database etc..
Step S502, virtual machine agency is analyzed the database-driven category information determining in category information to category information.Specifically, virtual machine agency be analyzed all category informations, filters according to the class name of category information, bag name etc., to determine database-driven category information among these category informations.
Step S503, virtual machine agency inweaves first code and the first operation category code among database-driven category information, and second code and second operates category code.Wherein, the first operation category code is the code of the instruction performing first code, and first code is for obtaining the data base manipulation statement in database-driven category information when executed.Second operation category code is the code of the instruction performing second code, and second code is for obtaining the result set of data base manipulation statement when executed, and second code performs after data base manipulation statement performs.In one embodiment of the invention, still as a example by Mysql data base, wherein, first operation category code can be that common SQL statement performs description object StatementImpl, and pretreatment SQL statement performs description object PreparedStatment and storing process SQL statement performs the code of one or more in description object CallableStatement.In an embodiment of the present invention, the first operation category code and first code should perform before data base manipulation statement performs, and performed this first code by the first operation category code.Second operation category code, for performing execute, only updates executeUpdate, the code of one or more in only inquiry executeQuery.
In an embodiment of the present invention, in order to perform large data sets optimization, in addition it is also necessary to virtual machine agency inweaves second code and the second operation category code among database-driven category information, and second code performs after data base manipulation statement performs.As shown in Figure 6, the first operation category code, first code and the second operation category code and schematic diagram of second code are inweaved for the embodiment of the present invention.
Step S504, the database-driven category information inweaving first code and the first operation category code, second code and the second operation category code is loaded, and is sent laden database-driven category information to DB connector by virtual machine agency by virtual machine.In an embodiment of the present invention, the database-driven category information inweaving first code and the first operation category code, second code and the second operation category code can be loaded by virtual machine by core classes java.lang.ClassLoader, is loaded to internal memory.
Step S505, laden database-driven category information is changed and is sent to data base, and performs first code to obtain data base manipulation statement by the first operation category code by DB connector.DB connector, before changing database-driven category information, can first pass through the first operation category code and perform first code to obtain data base manipulation statement.
Step S506, DB connector, after data base performs data base manipulation statement, performs second code to obtain the result set of data base manipulation statement by the second operation category code.In an embodiment of the present invention, DB connector is after data base manipulation statement is performed by data base, and DB connector performs, by the second operation category code, the result set that second code returns after data base manipulation statement to obtain data base to perform.Such as, after SQL statement has performed, data base can return the result set ResultSetImpl object of a data base.
Step S507, is analyzed determining the byte number of this result set and record line number to the result set of data base manipulation statement.Such as, in one particular embodiment of the present invention, for ResultSetImpl object, it is possible to obtain two attributes of byteSize and rowDatalength, represent the line number of the record that the byte-sized of the data that this data base manipulation statement returns and this data base manipulation statement return respectively.
Step S508, if the byte number of result set or record line number exceed preset value, then judged result integrates as large data sets.As one embodiment of the present of invention, when the value of two attributes of byteSize or rowDataLength of detection exceedes the limit value of setting, such as when row data are more than 10000 row, then it represents that this time request is the request of a large data sets.
Step S509, if it is judged that integrate as large data sets, then determines whether whether the transmission mode of result set is vernier mode.When determining that this time request is a big data set request, then the rowData attribute of ResultSetImpl object is analyzed, if the type of rowData attribute is not RowDataCursor object (vernier mode), then representing that the behavior of this time request disposably can disposably return to client the data of this 10000 row, that is the operation accounting for very much I/O bandwidth.
Step S510, if it is judged that the transmission mode integrated is not as vernier mode, then the transmission mode of described result set is set to vernier mode by DB connector.The large data sets optimal way of the embodiment of the present invention is exactly to use RowDataCursor object to replace the result set rowData of request, Connection attribute () in ResultSetImpl object is i.e. set, calling setUseCursorFetch method, arranging parameter value is true.
As illustrated in figs. 7 a and 7b, the operation chart before respectively large data sets optimizes and after optimization.As shown in the figure, after the embodiment of the present invention uses vernier mode, when Query Result 10000 row, disposably all of row will not be returned to client, but when user calls rowData.next method, taking follow-up several from data base dynamically to process, so IO for large data sets takes situation and just can effectively be alleviated.
As shown in Figure 8, for the structure chart of optimization system of embodiment of the present invention data base.This system includes virtual machine 100, virtual machine agency 200, DB connector 300 and data base 400.Wherein, virtual machine 100 generates category information for the instruction according to user, and is inweaved the database-driven category informations of first code and the first operation category code by virtual machine agency 200 and be loaded.In one embodiment of the invention, these category informations are the category information loading core classes java.lang.ClassLoader to described Java Virtual Machine.Wherein, java.lang.ClassLoader is the class of load classes, and all of category information is all loaded among internal memory by java.lang.ClassLoader class.Embodiments of the invention may be adapted to the various data bases that JDBC is connected, such as Mysql data base, informix database, oracle database, sybase database etc..
Wherein, virtual machine agency 200 is for obtaining the category information before virtual machine 100 loads, and this category information is analyzed the database-driven category information determining in this category information, and among database-driven category information, inweave first code and the first operation category code, and by virtual machine agency 200, laden for virtual machine 100 database-driven category information is sent to DB connector 300.Wherein, the first operation category code is the code of the instruction performing first code, and first code is for obtaining the data base manipulation statement in database-driven category information when executed.DB connector 300 is for changing and send laden database-driven category information to data base, and by the first operation category code execution first code to obtain data base manipulation statement, and according to data base manipulation statement, data base 400 is optimized.In an embodiment of the present invention, data base can be indexed optimization or large data sets optimization etc..Below in an example, will respectively optimiged index and large data sets optimization be described in detail.But skilled person would appreciate that, optimiged index and large data sets optimization are only the preferred embodiments of the present invention, those skilled in the art also can be according to data base manipulation statement after obtaining data base manipulation statement, and the thought of following optimiged index and large data sets optimization completes other optimization to data base, within the scope of these also should be included in the comprising of the embodiment of the present invention.
As it is shown in figure 9, be the structure chart of the DB connector optimized for database index of the embodiment of the present invention.DB connector 300 includes judge module 310, explains statement generation module 320, sending module 330, receiver module 340 and optimize module 350.Wherein, it is judged that module 310 is used for judging whether data base manipulation statement is query sentence of database.Explain that statement generation module 320, for when judge module 310 judges that data base manipulation statement is query sentence of database, generates the explanation statement of data base manipulation statement according to data base manipulation statement.Specifically, can first pass through the explain order that data base provides, rewrite SQL statement, such as, SQL statement is Select*fromstuentwherename=";The explanation statement of revised SQL statement is explainselect*fromstudentwherename=".Sending module 330 is for sending the explanation statement of data base manipulation statement to data base, to be performed the explanation statement of data base manipulation statement by data base.Receiver module 340 explains the result set of statement from data base 400 for receiving.Optimize module 350 to be used for when data base manipulation statement does not makes index of reference, create database index and create statement, and data base is created statement transmission to data base 400 to increase index accordingly in data base 400.
In an embodiment of the present invention, further, optimize module 350 include analyzing sub-module 351 and create submodule 352.Analyzing sub-module 351 for resolving the field name obtained among data base manipulation statement to data base manipulation statement.Create submodule 352 and create statement for creating database index according to this field name.
As shown in Figure 10, for the structure chart of DB connector optimized for data base's large data sets of the embodiment of the present invention.In this embodiment, virtual machine agency 200 is additionally operable among database-driven category information inweave second code and the second operation category code, wherein, second operation category code is the code of the instruction performing second code, second code is for obtaining the result set of data base manipulation statement when executed, and second code performs after data base manipulation statement performs.This DB connector 300 includes performing module 360, analyzing module 370, judge module 380 and arrange module 390.It should be noted that these modules can separately exist among DB connector 300, it is possible to exist on the basis of DB connector 300 shown in above-mentioned Fig. 9, i.e. DB connector 300 comprises optimiged index simultaneously and large data sets optimizes two kinds of functions.
Wherein, perform module 360 and be used for after data base 400 performs data base manipulation statement, perform second code to obtain the result set of data base manipulation statement by the second operation category code.Analyze module 370 to be used for being analyzed the result set of data base manipulation statement determining the byte number of result set and record line number.Judge module 380 is for when the byte number of result set or record line number exceed preset value, determining whether whether the transmission mode of result set is vernier mode.Module 390 is set for when the transmission mode of result set is not for vernier mode, the transmission mode of result set being set to vernier mode.
In an embodiment of the present invention, virtual machine 100 is Java Virtual Machine, and DB connector 300 is Java DB connector JDBC, and category information is the category information loading core classes java.lang.ClassLoader to Java Virtual Machine 100.It is in embodiment of the present invention, first operation category code is that common SQL statement performs description object StatementImpl, pretreatment SQL statement performs description object PreparedStatment and storing process SQL statement performs the code of one or more in description object CallableStatement, and second operation category code for perform ezxecute, only update the code of one or more in executeUpdate, only inquiry executeQuery.
As shown in figure 11, for the acquisition methods flow chart of the data base manipulation statement of the embodiment of the present invention, the method comprises the following steps:
Step S1101, virtual machine agency (agent) obtains the category information before virtual machine loads.In an embodiment of the present invention, virtual machine can be Java Virtual Machine.In current Java Virtual Machine technology, virtual machine agency provide a function, can obtain the category information before java class loads.Specifically, this category information is presented in bytecode.In one embodiment of the invention, these category informations are the category information loading core classes java.lang.ClassLoader to described Java Virtual Machine.Wherein, java.lang.ClassLoader is the class of load classes, and all of category information is all loaded among internal memory by java.lang.ClassLoader class.The present invention uses virtual machine to act on behalf of this characteristic of category information being obtained in that virtual machine passes through before java.lang.ClassLoader class loads just, realizes the seamless Dynamic Weave of embodiment of the present invention code.Thus be further implemented in and do not revise the acquisition realizing data base manipulation statement on the basis of JDBC connects driving configuration.
Embodiments of the invention may be adapted to the various data bases that JDBC is connected, such as Mysql data base, informix database, oracle database, sybase database etc..In following example of the present invention, to be described as a example by Mysql data base, it will be appreciated that those skilled in the art that the embodiment of the present invention can be additionally used in above-mentioned known or any data base of Future Development, as long as this data base can be supported by JDBC.
Step S1102, virtual machine agency is analyzed the database-driven category information determining in category information to category information.Specifically, virtual machine agency be analyzed all category informations, filters according to the class name of category information, bag name etc., to determine database-driven category information among these category informations.In an embodiment of the present invention, as a example by Mysql data base, certain kinds com.mysql.jdbc.Driver that Mysql drives can be found, thus identify the loading that Mysql drives.In other embodiments of the invention, for other different types of data bases, it is possible to selecting the specific class of other database-driven, this is no longer going to repeat them.
Step S1103, virtual machine agency inweaves first code and the first operation category code among database-driven category information, wherein, the first operation category code is the code of the instruction performing first code, and first code is for obtaining the data base manipulation statement in database-driven category information when executed.In one embodiment of the invention, still as a example by Mysql data base, wherein, first operation category code can be that common SQL statement performs description object StatementImpl, and pretreatment SQL statement performs description object PreparedStatment and storing process SQL statement performs the code of one or more in description object CallableStatement.As in figure 2 it is shown, inweave the first operation category code and the schematic diagram of first code for the embodiment of the present invention.In an embodiment of the present invention, the first operation category code and first code should perform before data base manipulation statement performs, and performed this first code by the first operation category code.The most as can be seen from the figure, first operation category code and first code between ClassStatementImpl and MethodStatementImpl so that the first operation category code and first code be limited to data base manipulation statement and by performed by DB connector.
Step S1104, the database-driven category information inweaving first code and the first operation category code is loaded, and is sent laden database-driven category information to DB connector by virtual machine agency by virtual machine.In an embodiment of the present invention, the database-driven category information inweaving first code and the first operation category code can be loaded by virtual machine by core classes java.lang.ClassLoader, is loaded to internal memory.In an embodiment of the present invention, this DB connector can be Java DB connector, i.e. JDBC.
Step S1105, laden database-driven category information is changed and is sent to data base, and performs first code to obtain data base manipulation statement by the first operation category code by DB connector.DB connector, before changing database-driven category information, can first pass through the first operation category code and perform first code to obtain data base manipulation statement.
In the above embodiment of the present invention, the first code seamlessly inweaved by above-mentioned virtual machine agency and the first operation category code, can be without data base manipulation statement (such as SQL statement) being intercepted in the case of invading, therefore without driving configuration to modify the connection of JDBC, thus improve the safety and stability of data base.
Represent in flow charts or the logic described otherwise above at this and/or step, such as, it is considered the sequencing list of executable instruction for realizing logic function, may be embodied in any computer-readable medium, use for instruction execution system, device or equipment (system such as computer based system, including processor or other can be from instruction execution system, device or equipment instruction fetch the system performing instruction), or combine these instruction execution systems, device or equipment and use.For the purpose of this specification, " computer-readable medium " can be any can to comprise, store, communicate, propagate or transmission procedure for instruction execution system, device or equipment or combines these instruction execution systems, device or equipment and the device that uses.
The more specifically example (non-exhaustive list) of computer-readable medium includes following: have the electrical connection section (electronic installation) of one or more wiring, portable computer diskette box (magnetic device), random access memory (RAM), read only memory (ROM), erasable edit read only memory (EPROM or flash memory), fiber device, and portable optic disk read only memory (CDROM).Additionally, computer-readable medium can even is that paper or other the suitable media that can print described program thereon, because can be such as by paper or other media be carried out optical scanning, then carry out editing, interpreting or be processed to electronically obtain described program with other suitable methods if desired, be then stored in computer storage.
Should be appreciated that each several part of the present invention can realize by hardware, software, firmware or combinations thereof.In the above-described embodiment, multiple steps or method can realize with software or the firmware that storage in memory and is performed by suitable instruction execution system.Such as, if realized with hardware, as in another embodiment, can realize by any one in following technology well known in the art or their combination: there is the discrete logic of logic gates for data signal realizes logic function, there is the special IC of suitable combination logic gate circuit, programmable gate array (PGA), field programmable gate array (FPGA) etc..
In the description of this specification, the description of reference term " embodiment ", " some embodiments ", " example ", " concrete example " or " some examples " etc. means that the specific features, structure, material or the feature that combine this embodiment or example description are contained at least one embodiment or the example of the present invention.In this manual, the schematic representation to above-mentioned term is not necessarily referring to identical embodiment or example.And, the specific features of description, structure, material or feature can combine in any one or more embodiments or example in an appropriate manner.
Although an embodiment of the present invention has been shown and described, it will be understood by those skilled in the art that: these embodiments can carry out in the case of without departing from the principle of the present invention and objective multiple change, revise, replace and modification, the scope of the present invention is limited by claim and equivalent thereof.

Claims (31)

1. the optimization method of a data base, it is characterised in that comprise the following steps:
Obtain the category information before virtual machine loads, and described category information is analyzed the database-driven category information determining in described category information;
First code and the first operation category code is inweaved among described database-driven category information;
DB connector obtains data base manipulation statement according to the described first code inweaved and described first operation category code;And
According to described data base manipulation statement, described data base is optimized.
2. the optimization method of data base as claimed in claim 1, it is characterized in that, wherein, described first operation category code is the code of the instruction performing described first code, and described first code is for obtaining the data base manipulation statement in described database-driven category information when executed.
3. the optimization method of data base as claimed in claim 2, it is characterised in that described first code and described first operation category code that described basis inweaves obtain data base manipulation statement and farther include:
The described database-driven category information inweaving described first code and described first operation category code is loaded;
Laden database-driven category information is changed, and performs described first code to obtain described data base manipulation statement by described first operation category code.
4. the optimization method of the data base as described in any one of claim 1-3, it is characterised in that described described data base is optimized for described data base is indexed optimize.
5. the optimization method of data base as claimed in claim 4, it is characterised in that described described data base is indexed optimization farther includes:
Judge whether described data base manipulation statement is query sentence of database;
If described query sentence of database, then generate the explanation statement of described data base manipulation statement according to described data base manipulation statement;
The explanation statement of described data base manipulation statement is sent to described data base;
Perform explaining statement and the result set of described explanation statement being back to described DB connector of described data base manipulation statement;
Result set according to described explanation statement judges whether described data base manipulation statement employs index;And
If it is determined that described data base manipulation statement does not uses described index, then create database index and create statement, and described database index is created statement transmission to described data base to increase corresponding index in the database.
6. the optimization method of data base as claimed in claim 5, it is characterised in that create database index establishment statement and farther include:
Resolve to obtain the field name among described data base manipulation statement to described data base manipulation statement;And
Create described database index according to described field name and create statement.
7. the optimization method of the data base as described in any one of claim 1-3, it is characterised in that also include:
Second code and the second operation category code is inweaved among described database-driven category information, wherein, described second operation category code is the code of the instruction performing described second code, described second code is for obtaining the result set of described data base manipulation statement when executed, and described second code performs after described data base manipulation statement performs.
8. the optimization method of data base as claimed in claim 7, it is characterised in that described described data base is optimized as described data base is carried out large data sets optimization.
9. the optimization method of data base as claimed in claim 8, it is characterised in that described described data base is carried out large data sets optimization farther include:
After described data base performs described data base manipulation statement, perform described second code to obtain the result set of described data base manipulation statement by described second operation category code;
It is analyzed determining the byte number of described result set and record line number to the result set of described data base manipulation statement;
If the byte number of described result set or record line number exceed preset value, then judge that described result set is large data sets, and determine whether whether the transmission mode of described result set is vernier mode;And
If it is determined that the transmission mode of described result set is not vernier mode, then the transmission mode of described result set is set to vernier mode.
10. the optimization method of data base as claimed in claim 1, it is characterised in that described virtual machine is Java Virtual Machine, and described DB connector is Java DB connector.
The optimization method of 11. data bases as claimed in claim 10, it is characterised in that described category information is the category information loading core classes java.lang.ClassLoader to described Java Virtual Machine.
The optimization method of 12. data bases as claimed in claim 9, it is characterized in that, described first operation category code is that common SQL statement performs description object StatementImpl, pretreatment SQL statement performs description object PreparedStatment and storing process SQL statement performs the code of one or more in description object CallableStatement, described second operation category code is for performing execute, only update the code of one or more in executeUpdate, only inquiry executeQuery.
The optimization system of 13. 1 kinds of data bases, it is characterised in that include that virtual machine, virtual machine are acted on behalf of and DB connector, wherein,
Described virtual machine, for generating category information according to the instruction of user, and is inweaved the database-driven category information of first code and the first operation category code by described virtual machine agency and is loaded;
Virtual machine is acted on behalf of, for obtaining the category information before virtual machine loads, and described category information is analyzed the database-driven category information determining in described category information, and among described database-driven category information, inweave first code and the first operation category code, and by described virtual machine agency, laden for described virtual machine described database-driven category information is sent to DB connector;
Described DB connector, for described laden described database-driven category information is changed and is sent to data base, and obtain data base manipulation statement according to the described first code inweaved and described first operation category code, and according to described data base manipulation statement, described data base is optimized.
The optimization system of 14. data bases as claimed in claim 13, it is characterized in that, wherein, described first operation category code is the code of the instruction performing described first code, and described first code is for obtaining the data base manipulation statement in described database-driven category information when executed.
The optimization system of 15. data bases as claimed in claim 14, it is characterised in that described DB connector performs described first code to obtain described data base manipulation statement by described first operation category code.
The optimization system of 16. data bases as described in any one of claim 13-15, it is characterised in that described data base is indexed optimizing by described DB connector.
The optimization system of 17. data bases as claimed in claim 16, it is characterised in that described DB connector farther includes:
Judge module, is used for judging whether described data base manipulation statement is query sentence of database;
Explain statement generation module, for when described judge module judges that described data base manipulation statement is described query sentence of database, generate the explanation statement of described data base manipulation statement according to described data base manipulation statement;
Sending module, for sending the explanation statement of described data base manipulation statement to described data base, to be performed the explanation statement of described data base manipulation statement by described data base;
Receiver module, for receiving the result set of described explanation statement from described data base;And
Optimize module, for when described data base manipulation statement does not makes index of reference, create database index and create statement, and described database index establishment statement is sent to described data base to increase corresponding index in the database.
The optimization system of 18. data bases as claimed in claim 17, it is characterised in that described optimization module farther includes:
Analyzing sub-module, for resolving to obtain the field name among described data base manipulation statement to described data base manipulation statement;And
Create submodule, create statement for creating described database index according to described field name.
The optimization system of 19. data bases as described in any one of claim 13-15, it is characterized in that, described virtual machine agency is additionally operable among described database-driven category information inweave second code and the second operation category code, wherein, described second operation category code is the code of the instruction performing described second code, described second code is for obtaining the result set of described data base manipulation statement when executed, and described second code performs after described data base manipulation statement performs.
The optimization system of 20. data bases as claimed in claim 19, it is characterised in that described DB connector carries out large data sets optimization to described data base.
The optimization system of 21. data bases as claimed in claim 20, it is characterised in that described DB connector farther includes:
Perform module, for after described data base performs described data base manipulation statement, perform described second code to obtain the result set of described data base manipulation statement by described second operation category code;
Analyze module, be used for being analyzed the result set of described data base manipulation statement determining the byte number of described result set and record line number;
Judge module, for when the byte number of described result set or record line number exceed preset value, determining whether whether the transmission mode of described result set is vernier mode;And
Module is set, for when the transmission mode of described result set is not vernier mode, the transmission mode of described result set is set to vernier mode.
The optimization system of 22. data bases as claimed in claim 13, it is characterised in that described virtual machine is Java Virtual Machine, and described DB connector is Java DB connector.
The optimization system of 23. data bases as claimed in claim 22, it is characterised in that described category information is the category information loading core classes java.lang.ClassLoader to described Java Virtual Machine.
The optimization system of 24. data bases as claimed in claim 19, it is characterized in that, described first operation category code is that common SQL statement performs description object StatementImpl, pretreatment SQL statement performs description object PreparedStatment and storing process SQL statement performs the code of one or more in description object CallableStatement, described second operation category code is for performing execute, only update the code of one or more in executeUpdate, only inquiry executeQuery.
The acquisition methods of 25. 1 kinds of data base manipulation statements, it is characterised in that comprise the following steps:
Obtain the category information before virtual machine loads;
Described category information is analyzed the database-driven category information determining in described category information;
First code and the first operation category code is inweaved among described database-driven category information;
DB connector obtains data base manipulation statement according to the described first code inweaved and described first operation category code.
The acquisition methods of 26. data base manipulation statements as claimed in claim 25, it is characterized in that, wherein, described first operation category code is the code of the instruction performing described first code, and described first code is for obtaining the data base manipulation statement in described database-driven category information when executed.
The acquisition methods of 27. data base manipulation statements as claimed in claim 26, it is characterised in that described first code and described first operation category code that described basis inweaves obtain data base manipulation statement and farther include:
The described database-driven category information inweaving described first code and described first operation category code is loaded;And
Laden database-driven category information is changed and sent to data base, and performs described first code to obtain described data base manipulation statement by described first operation category code.
The acquisition methods of 28. data base manipulation statements as claimed in claim 27, it is characterised in that also include:
Virtual machine agency inweaves second code and the second operation category code among described database-driven category information, wherein, described second operation category code is the code of the instruction performing described second code, described second code is for obtaining the result set of described data base manipulation statement when executed, and described second code performs after described data base manipulation statement performs.
The acquisition methods of 29. data base manipulation statements as claimed in claim 25, it is characterised in that described virtual machine is Java Virtual Machine, and described DB connector is Java DB connector.
The acquisition methods of 30. data base manipulation statements as claimed in claim 29, it is characterised in that described category information is the category information loading core classes java.lang.ClassLoader to described Java Virtual Machine.
The acquisition methods of 31. data base manipulation statements as claimed in claim 28, it is characterized in that, described first operation category code is that common SQL statement performs description object StatementImpl, pretreatment SQL statement performs description object PreparedStatment and storing process SQL statement performs the code of one or more in description object CallableStatement, described second operation category code is for performing execute, only update the code of one or more in executeUpdate, only inquiry executeQuery.
CN201110421548.XA 2011-12-15 2011-12-15 The optimization method and device of data base Active CN103164455B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201110421548.XA CN103164455B (en) 2011-12-15 2011-12-15 The optimization method and device of data base

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201110421548.XA CN103164455B (en) 2011-12-15 2011-12-15 The optimization method and device of data base

Publications (2)

Publication Number Publication Date
CN103164455A CN103164455A (en) 2013-06-19
CN103164455B true CN103164455B (en) 2016-08-03

Family

ID=48587549

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201110421548.XA Active CN103164455B (en) 2011-12-15 2011-12-15 The optimization method and device of data base

Country Status (1)

Country Link
CN (1) CN103164455B (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103440161B (en) * 2013-08-15 2017-03-29 北京京东尚科信息技术有限公司 A kind of Java virtual machine internal object monitoring method, device and system
CN104714984A (en) * 2013-12-17 2015-06-17 中国移动通信集团湖南有限公司 Database optimization method and device
CN105320679B (en) * 2014-07-11 2019-05-24 中国移动通信集团重庆有限公司 A kind of tables of data indexed set symphysis is at method and device
CN106033422A (en) * 2015-03-11 2016-10-19 中国移动通信集团内蒙古有限公司 A database operation control method, device and system
CN106528551A (en) * 2015-09-09 2017-03-22 北京国双科技有限公司 Memory application method and apparatus
CN109241076A (en) * 2018-08-01 2019-01-18 上海依图网络科技有限公司 A kind of data query method and device
CN110413641A (en) * 2019-07-15 2019-11-05 苏州浪潮智能科技有限公司 A kind of database Caton processing method and device
CN111831659B (en) * 2020-07-09 2022-09-06 天津车之家数据信息技术有限公司 Index checking method and device and computing equipment
CN114547086B (en) * 2022-04-22 2022-07-22 网易(杭州)网络有限公司 Data processing method, device, equipment and computer readable storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1499366A (en) * 2002-11-08 2004-05-26 深圳市中兴通讯股份有限公司 Loading method of driving program for database
CN101059810A (en) * 2007-03-16 2007-10-24 华为技术有限公司 System and method for implementing automatic optimization of data base system
CN101226497A (en) * 2007-12-10 2008-07-23 金蝶软件(中国)有限公司 Application program monitoring system and monitoring method
CN102110162A (en) * 2011-02-24 2011-06-29 北京中电普华信息技术有限公司 Method and device for realizing monitoring on SQL (structured query language) database

Family Cites Families (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6625617B2 (en) * 1996-01-02 2003-09-23 Timeline, Inc. Modularized data retrieval method and apparatus with multiple source capability
US7089562B1 (en) * 2000-05-04 2006-08-08 International Business Machines Corporation Universal driver server
US7805411B2 (en) * 2003-09-06 2010-09-28 Oracle International Corporation Auto-tuning SQL statements
US8655853B2 (en) * 2004-10-01 2014-02-18 Sap Ag System and method for optimizing database transaction termination
CN101436209B (en) * 2008-12-15 2011-01-05 中兴通讯股份有限公司 Method and apparatus for synchronizing multiple databases

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1499366A (en) * 2002-11-08 2004-05-26 深圳市中兴通讯股份有限公司 Loading method of driving program for database
CN101059810A (en) * 2007-03-16 2007-10-24 华为技术有限公司 System and method for implementing automatic optimization of data base system
CN101226497A (en) * 2007-12-10 2008-07-23 金蝶软件(中国)有限公司 Application program monitoring system and monitoring method
CN102110162A (en) * 2011-02-24 2011-06-29 北京中电普华信息技术有限公司 Method and device for realizing monitoring on SQL (structured query language) database

Also Published As

Publication number Publication date
CN103164455A (en) 2013-06-19

Similar Documents

Publication Publication Date Title
CN103164455B (en) The optimization method and device of data base
KR101499599B1 (en) Data logging in graph-based computations
CN102193922B (en) Method and device for accessing database
US8065315B2 (en) Solution search for software support
US7739269B2 (en) Incremental repair of query plans
US8554599B2 (en) Work item rules for a work item tracking system
US8321833B2 (en) Compact syntax for data scripting language
US8539442B2 (en) Reverse engineering for code file refactorization and conversion
US20180046675A1 (en) Automatic adjustment of an execution plan for a query
US8874601B2 (en) SADL query view—a model-driven approach to speed-up read-only use cases
CN112650766B (en) Database data operation method, system and server
CN109885642B (en) Hierarchical storage method and device for full-text retrieval
US20020091705A1 (en) Object integrated management system
Fisun et al. Query parsing in order to optimize distributed DB structure
KR101877828B1 (en) User interface integrated platform system based on artificial intelligence
CN104679500A (en) Automatic generation realizing method and device for entity classes
CN114090695A (en) Query optimization method and device for distributed database
CN110941629A (en) Metadata processing method, device, equipment and computer readable storage medium
CN105468776A (en) Method, device and system for operating database
CN116610697A (en) Query method, storage medium and device for database query statement
US20170262507A1 (en) Feedback mechanism for query execution
US20050015264A1 (en) Methods, systems, and a computer-readable medium for defining and evaluating business rules during runtime of a computer software application program
KR102202792B1 (en) Method and device for performing multi-caching on data sources of same or different types by using cluster-based processing system
Bayer Sqlalchemy documentation
CN110334098A (en) A kind of database combining method and system based on script

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant