WO2021051522A1 - Sql指纹还原方法、装置、计算机设备和存储介质 - Google Patents

Sql指纹还原方法、装置、计算机设备和存储介质 Download PDF

Info

Publication number
WO2021051522A1
WO2021051522A1 PCT/CN2019/116950 CN2019116950W WO2021051522A1 WO 2021051522 A1 WO2021051522 A1 WO 2021051522A1 CN 2019116950 W CN2019116950 W CN 2019116950W WO 2021051522 A1 WO2021051522 A1 WO 2021051522A1
Authority
WO
WIPO (PCT)
Prior art keywords
variable
restored
sql
fingerprint
column
Prior art date
Application number
PCT/CN2019/116950
Other languages
English (en)
French (fr)
Inventor
高中正
金海锋
Original Assignee
平安科技(深圳)有限公司
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 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2021051522A1 publication Critical patent/WO2021051522A1/zh

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/2455Query execution

Definitions

  • This application relates to a SQL fingerprint restoration method, device, computer equipment and storage medium.
  • the inventor realizes that currently obtaining the execution plan in MySQL (relational database management system) corresponding to the OLTP system (online transaction processing system) will cause very high contention and consumption of resources, and may also cause congestion.
  • MySQL relational database management system
  • OLTP online transaction processing system
  • a SQL fingerprint restoration method for example, a SQL fingerprint restoration method, device, computer equipment, and storage medium are provided.
  • a SQL fingerprint restoration method includes:
  • a SQL fingerprint restoration device includes:
  • the SQL fingerprint acquisition module is used to acquire the SQL fingerprint to be restored
  • the syntax tree obtaining module is used to parse the SQL fingerprint to be restored to obtain the syntax tree of the SQL fingerprint to be restored; wherein, the syntax tree includes variable nodes; the variable nodes are configured to describe the variables The Jason structure of the corresponding relationship between the node and the list;
  • the traversal module is used to traverse the variable nodes of the syntax tree, and obtain the list names and variable column names corresponding to the variables of each variable node from the Jason structure;
  • the column type obtaining module is configured to obtain the type of the corresponding column in the list where each variable is located in the database where the SQL fingerprint to be restored is located according to the list name and variable column name corresponding to each variable;
  • the restoration module is used to restore the SQL fingerprint to be restored according to the type of the column corresponding to each of the variables to obtain the restored SQL statement.
  • a computer device including a memory and one or more processors, the memory stores computer readable instructions, and when the computer readable instructions are executed by the processor, the one or more processors execute The following steps:
  • One or more non-volatile computer-readable storage media storing computer-readable instructions.
  • the computer-readable instructions When executed by one or more processors, the one or more processors perform the following steps:
  • Fig. 1 is an application scenario diagram of the SQL fingerprint restoration method according to one or more embodiments.
  • Fig. 2 is a schematic flowchart of a method for restoring SQL fingerprints according to one or more embodiments.
  • Fig. 3 is a structural block diagram of an SQL fingerprint restoration device according to one or more embodiments.
  • Fig. 4 is a structural block diagram of the SQL fingerprint restoration device in another embodiment.
  • Fig. 5 is an internal structure diagram of a computer device according to one or more embodiments.
  • the SQL fingerprint restoration method provided in this application can be applied to the application environment as shown in FIG. 1.
  • the terminal 102 communicates with the server 104 through the network through the network.
  • the SQL fingerprint to be restored can be obtained through the terminal 102; the SQL fingerprint to be restored is parsed to obtain the syntax tree of the SQL fingerprint to be restored; the syntax tree contains variable nodes; the variable nodes are configured with a Jason structure used to describe the correspondence between variable nodes and lists Body; Traverse the variable nodes of the syntax tree, and obtain the list name and variable column name corresponding to the variable of each variable node from the Jason structure; according to the list name and variable column name corresponding to each variable in the database where the SQL fingerprint to be restored is located, Obtain the type of the corresponding column in the list where each variable is located; restore the SQL fingerprint to be restored according to the type of the corresponding column of each variable to obtain the restored SQL statement.
  • the terminal 102 can also interact with the server 104 through the network.
  • the server 104 obtains the SQL fingerprint to be restored uploaded by the terminal 102; the server 104 parses the SQL fingerprint to be restored to obtain the syntax tree of the SQL fingerprint to be restored; the syntax tree contains variables Nodes; variable nodes are configured with a Jason structure used to describe the correspondence between variable nodes and lists; traverse the variable nodes of the syntax tree, and obtain the list names and variable column names corresponding to the variables of each variable node from the Jason structure; according to each The name of the list corresponding to the variable and the name of the variable column are in the database where the SQL fingerprint to be restored is located, and the type of the corresponding column in the list where each variable is located is obtained; the SQL fingerprint to be restored is restored according to the type of the corresponding column of each variable to obtain the restored SQL Statement.
  • the terminal 102 may be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, and portable wearable devices.
  • the server 104 may be implemented by an independent server
  • a method for restoring SQL fingerprints is provided. Taking the method applied to the terminal in FIG. 1 as an example for description, the method includes the following steps:
  • Step S220 Obtain the SQL fingerprint to be restored.
  • the SQL fingerprint to be restored refers to the SQL fingerprint that needs to be restored to the SQL statement.
  • the user can directly upload the SQL fingerprint to be restored through the terminal; it can also be that the user pre-stores the SQL fingerprint to be restored in the database and obtains the SQL fingerprint to be restored from the database.
  • step S240 the SQL fingerprint to be restored is parsed to obtain a syntax tree of the SQL fingerprint to be restored; wherein the syntax tree includes variable nodes; the variable nodes are configured with a Jason structure for describing the corresponding relationship between the variable nodes and the list.
  • the grammar tree is a graphical representation of the sentence structure, which represents the result of sentence derivation, which is conducive to understanding the level of the sentence grammatical structure.
  • the grammar tree is a tree structure diagram formed when deriving according to a certain rule.
  • the syntax tree of the SQL fingerprint to be restored is a tree derived from the SQL fingerprint to be restored.
  • the SQL fingerprint to be restored can be parsed through the SQL parsing package to obtain the syntax tree of the SQL fingerprint to be restored.
  • Other tools that can parse the SQL fingerprint to be restored can also be used to parse the SQL fingerprint to be restored to obtain the syntax tree of the SQL fingerprint to be restored.
  • Step S260 traverse the variable nodes of the syntax tree, and obtain the list names and variable column names corresponding to the variables of each variable node from the Jason structure.
  • variable node is configured with a Jason structure used to describe the corresponding relationship between the variable node and the list, that is, the list name and variable column name corresponding to the variable are recorded in the json structure.
  • a Jason structure used to describe the corresponding relationship between the variable node and the list, that is, the list name and variable column name corresponding to the variable are recorded in the json structure.
  • variable identification traverse the syntax tree of the SQL fingerprint to be restored, determine each variable node in the syntax tree, and obtain the list name and variable column name corresponding to each variable node according to each variable node, such as: in the syntax tree of the SQL fingerprint to be restored ,
  • the variable node is identified by a question mark "?”, it can be judged as a variable node by traversing to "?”, and the list name and variable column name corresponding to the variable of the variable node can be obtained according to the variable node. Based on the list name and variable column name corresponding to the variable, you can further find the corresponding column in the list where the variable is located.
  • step S280 the type of the corresponding column in the list where each variable is located is obtained in the database where the SQL fingerprint to be restored is located according to the list name and variable column name corresponding to each variable.
  • information_schema is a database, to be precise, an information database, which stores information about all other databases maintained by the MySQL server, such as database names, database tables , The data type and access authority of the table column, etc.
  • the database where the SQL fingerprint to be restored is located, obtain the type of the corresponding column in the list where each variable is located, for example: for columns under information_schema (provides the column information in the table, and describes it in detail All the columns of a certain table and the information of each column, the columns table has table_name (table name), column_name (column name), data_type (data type) and other information.
  • table_name (table Name), column_name (column name), data_type (data type) and other information.) table query, you can get the data type of the corresponding column of the variable in the columns table, according to the list name, you can find the corresponding list, in the corresponding column of the list The corresponding data type can be obtained.
  • step S300 the SQL fingerprint to be restored is restored according to the type of the column corresponding to each variable to obtain the restored SQL statement.
  • variable in the SQL fingerprint can be replaced according to the type of the corresponding column of the obtained variable (the type refers to the data type).
  • the type refers to the data type.
  • the SQL fingerprint to be restored is obtained; by parsing the SQL fingerprint to be restored, obtaining the SQL fingerprint to be restored is beneficial to obtain the syntax tree of the variable and the list name and the variable column name corresponding to the variable, and the variable can be accurately found; By traversing the variable nodes of the syntax tree, obtain the list name and variable column name corresponding to each variable; according to the list name and variable column name corresponding to each variable in the database where the SQL fingerprint to be restored is located, obtain the corresponding column in the list where each variable is located
  • the type of SQL can accurately restore the SQL fingerprint to be restored; according to the type of the corresponding column of each variable, the SQL fingerprint to be restored is restored to obtain the restored SQL statement. Restore SQL statements through SQL fingerprints, realize the performance of SQL statements through SQL fingerprint analysis, and improve the efficiency of analyzing the performance of SQL statements.
  • the step of obtaining the SQL fingerprint to be restored includes: obtaining the SQL fingerprint; calling the grammar verification interface in the SQL parsing package to perform grammar verification on the SQL fingerprint to obtain the verification result; and setting the verification result as passed
  • the SQL fingerprint is used as the SQL fingerprint to be restored.
  • the SQL parsing package can be the open source Vitess/sqlparse parsing package; it can also be the sqlparser package of the open source database TiDB; it can also go to other parsing packages, and different open source parsing packages can be designed based on the language.
  • the grammar verification interface in the SQL parsing package can be the interface for grammar verification provided in the Vitess/sqlparse parsing package; it can also be the interface for grammar verification provided in the sqlparser package of the open source database TiDB.
  • the SQL fingerprint is grammatically verified based on the grammar verification interface, and the verification result is obtained.
  • the verification result is passed, and the SQL fingerprint whose verification result is passed is used as the SQL fingerprint to be restored; when the syntax is incorrect, the verification result is If it fails, remind the user to re-upload the SQL fingerprint and remind the syntax error. And to prevent users from uploading wrong SQL fingerprints, and improve the running speed.
  • the step of parsing the SQL fingerprint to be restored to obtain the syntax tree of the SQL fingerprint to be restored includes: invoking the parsing interface in the SQL parsing package, parsing the SQL fingerprint to be restored, and obtaining the grammar of the SQL fingerprint to be restored tree.
  • the SQL parsing package can be the open source Vitess/sqlparse parsing package; it can also be the sqlparser package of the open source database TiDB; it can also go to other parsing packages, and different open source parsing packages can be designed based on the language.
  • the parsing interface in the SQL parsing package can be the interface for parsing SQL fingerprints provided in the Vitess/sqlparse parsing package; it can also be the interface for parsing SQL fingerprints provided in the sqlparser package of the open source database TiDB.
  • the parsing interface in the open source Vitess/sqlparse parsing package is called to analyze the SQL fingerprint to be restored to obtain the syntax tree of the SQL fingerprint to be restored, which can improve the parsing efficiency.
  • the step of obtaining the type of the corresponding column in the list where each variable is located in the database where the SQL fingerprint to be restored is located according to the list name and variable column name corresponding to each variable includes: obtaining where the SQL fingerprint to be restored is located The identification of the database; according to the identification to connect to the database where the SQL fingerprint to be restored is located; according to the list name and variable column name corresponding to each variable, search in the database where the SQL fingerprint to be restored is located, and determine the corresponding column in the list where each variable is located Types of.
  • the database identifier can be passed in as a parameter through the terminal when the user starts the SQL fingerprint restoration method; it can also be the identifier of the database where the SQL fingerprint to be restored is preset, and the corresponding database identifier can be directly obtained.
  • the corresponding list can be found according to the list name, and the corresponding data type can be obtained in the corresponding column of the list, such as: columns There are table_name (table name), column_name (column name), data_type (data type) and other information in the table.
  • the above-mentioned related information can be obtained by querying table_name in the columns table.
  • the step of searching in the database where the SQL fingerprint to be restored is located according to the list name and variable column name corresponding to each variable to determine the type of the corresponding column in the list where each variable is located includes: corresponding to each variable According to the list name of each variable, determine the list where each variable is located; determine the column where each variable is located in the list where each variable is located according to the column name of each variable; determine the type of the column corresponding to each variable according to the column where each variable is located.
  • the name of the list corresponding to variable A is "b”
  • the variable column name is "c”
  • the corresponding "b” list is found in the columns table of the information_schema database according to the list name "b” and the variable column name "c”
  • the “c” column in the column corresponds to the data type of the “c” column where each variable is located, and the data type is the type of the corresponding column of variable A. Further determine the type of the corresponding column in the list where each variable is located, and improve the efficiency of the SQL fingerprint restoration to the SQL statement.
  • the step of restoring the SQL fingerprint to be restored according to the type of the column corresponding to each variable to obtain the restored SQL statement includes: replacing the variable in the SQL fingerprint to be restored according to the type of the column corresponding to each variable, Get the restored SQL statement.
  • the variable in the SQL fingerprint can be replaced according to the type of the corresponding column of the obtained variable (the type refers to the data type).
  • the type refers to the data type.
  • the method further includes: calling the explain method to obtain the execution plan of the restored SQL statement, and obtaining the execution plan of the restored SQL statement; performing the restored SQL statement according to the execution plan of the restored SQL statement Performance analysis.
  • MySQL database is an open source relational database management system (RDBMS), which uses the most commonly used database management language-Structured Query Language (SQL) for database management.
  • the explain method is used to help optimize indexes and query statements and so on. This solves the problem that the SQL fingerprint cannot obtain the execution plan in MySQL, and improves the efficiency of analyzing the performance of the SQL statement.
  • the corresponding execution plan can be obtained according to the original SQL statement based on the SQL fingerprint to optimize performance and improve work efficiency.
  • steps in the flowchart of FIG. 2 are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless there is a clear description in this article, there is no strict order for the execution of these steps, and these steps can be executed in other orders. Moreover, at least part of the steps in FIG. 2 may include multiple sub-steps or multiple stages. These sub-steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution of these sub-steps or stages The sequence is not necessarily performed sequentially, but may be performed alternately or alternately with at least a part of other steps or sub-steps or stages of other steps.
  • a SQL fingerprint restoration device including: SQL fingerprint acquisition module 310, syntax tree acquisition module 320, traversal module 330, column type acquisition module 340, and restoration module 350 ,among them:
  • the SQL fingerprint acquisition module 310 is used to acquire the SQL fingerprint to be restored
  • the syntax tree obtaining module 320 is used to parse the SQL fingerprint to be restored to obtain the syntax tree of the SQL fingerprint to be restored, where the syntax tree contains variable nodes; the variable nodes are configured with a Jason structure for describing the correspondence between variable nodes and lists body;
  • the traversal module 330 is used to traverse the variable nodes of the syntax tree, and obtain the list names and variable column names corresponding to the variables of each variable node from the Jason structure;
  • the column type obtaining module 340 is used to obtain the type of the corresponding column in the list where each variable is located in the database where the SQL fingerprint to be restored is located according to the list name and variable column name corresponding to each variable;
  • the restoration module 350 is used for restoring the SQL fingerprint to be restored according to the type of the corresponding column of each variable to obtain the restored SQL statement.
  • the SQL fingerprint acquisition module 310 is also used to: acquire the SQL fingerprint; call the syntax verification interface in the SQL parsing package to perform syntax verification on the SQL fingerprint to obtain the verification result; and the verification result is passed
  • the SQL fingerprint is used as the SQL fingerprint to be restored.
  • the syntax tree obtaining module 320 is further used to: call the analysis interface in the SQL analysis package, analyze the SQL fingerprint to be restored, and obtain the syntax tree of the SQL fingerprint to be restored.
  • the column type obtaining module 340 is also used to: obtain the identification of the database where the SQL fingerprint to be restored is located; connect to the database where the SQL fingerprint to be restored is located according to the identification; according to the list name and variable column name corresponding to each variable , Search in the database where the SQL fingerprint to be restored is located, and determine the type of the corresponding column in the list where each variable is located.
  • the column type obtaining module 340 is further used to: determine the list where each variable is located according to the list name corresponding to each variable; determine the list where each variable is located according to the column name of each variable The column where each variable is located; the type of the column corresponding to each variable is determined according to the column where each variable is located.
  • the restoration module 350 is further configured to: according to the type of the column corresponding to each variable, replace the variable in the SQL fingerprint to be restored to obtain the restored SQL statement.
  • the SQL fingerprint restoration device further includes a performance analysis module 360 for invoking the explain method to obtain the execution plan of the restored SQL statement, and obtain the execution plan of the restored SQL statement; Perform performance analysis on the restored SQL statement according to the execution plan of the restored SQL statement.
  • a performance analysis module 360 for invoking the explain method to obtain the execution plan of the restored SQL statement, and obtain the execution plan of the restored SQL statement; Perform performance analysis on the restored SQL statement according to the execution plan of the restored SQL statement.
  • Each module in the above SQL fingerprint restoration device can be implemented in whole or in part by software, hardware and a combination thereof.
  • the above-mentioned modules may be embedded in the form of hardware or independent of the processor in the computer equipment, or may be stored in the memory of the computer equipment in the form of software, so that the processor can call and execute the operations corresponding to the above-mentioned modules.
  • a computer device is provided.
  • the computer device may be a terminal, and its internal structure diagram may be as shown in FIG. 5.
  • the computer equipment includes a processor, a memory, a network interface, a display screen and an input device connected through a system bus.
  • the processor of the computer device is used to provide calculation and control capabilities.
  • the memory of the computer device includes a non-volatile storage medium and an internal memory.
  • the non-volatile storage medium stores an operating system and computer readable instructions.
  • the internal memory provides an environment for the operation of the operating system and computer-readable instructions in the non-volatile storage medium.
  • the network interface of the computer device is used to communicate with an external terminal through a network connection.
  • the display screen of the computer equipment can be a liquid crystal display screen or an electronic ink display screen
  • the input device of the computer equipment can be a touch layer covered on the display screen, or it can be a button, a trackball or a touchpad set on the housing of the computer equipment , It can also be an external keyboard, touchpad, or mouse.
  • FIG. 5 is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied.
  • the specific computer device may Including more or fewer parts than shown in the figure, or combining some parts, or having a different arrangement of parts.
  • a computer device includes a memory and one or more processors.
  • the memory stores computer-readable instructions.
  • the one or more processors perform the following steps:
  • the SQL fingerprint to be restored is restored according to the type of the corresponding column of each variable, and the restored SQL statement is obtained.
  • the processor further implements the following steps when executing the computer-readable instructions:
  • the SQL fingerprint whose verification result is passed is used as the SQL fingerprint to be restored.
  • the processor further implements the following steps when executing the computer-readable instructions: calling the parsing interface in the SQL parsing package, parsing the SQL fingerprint to be restored, and obtaining the syntax tree of the SQL fingerprint to be restored.
  • the processor further implements the following steps when executing the computer-readable instructions:
  • search in the database where the SQL fingerprint to be restored is located to determine the type of the corresponding column in the list where each variable is located.
  • the processor further implements the following steps when executing the computer-readable instructions:
  • each variable determines the type of the column corresponding to each variable.
  • the processor further implements the following steps when executing the computer-readable instructions: according to the type of the column corresponding to each variable, the variable in the SQL fingerprint to be restored is replaced to obtain the restored SQL statement.
  • the processor further implements the following steps when executing the computer-readable instructions:
  • One or more non-volatile computer-readable storage media storing computer-readable instructions.
  • the computer-readable instructions When executed by one or more processors, the one or more processors perform the following steps:
  • the syntax tree contains variable nodes;
  • the variable nodes are configured with a Jason structure used to describe the correspondence between variable nodes and lists;
  • the SQL fingerprint to be restored is restored according to the type of the corresponding column of each variable, and the restored SQL statement is obtained.
  • the SQL fingerprint whose verification result is passed is used as the SQL fingerprint to be restored.
  • the following steps are also implemented: calling the parsing interface in the SQL parsing package, parsing the SQL fingerprint to be restored, and obtaining the syntax tree of the SQL fingerprint to be restored.
  • search in the database where the SQL fingerprint to be restored is located to determine the type of the corresponding column in the list where each variable is located.
  • each variable determines the type of the column corresponding to each variable.
  • the following steps are further implemented: according to the type of the column corresponding to each variable, the variable in the SQL fingerprint to be restored is replaced to obtain the restored SQL statement.
  • Non-volatile memory may include read only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory.
  • Volatile memory may include random access memory (RAM) or external cache memory.
  • RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous chain Channel (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.

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)
  • Collating Specific Patterns (AREA)

Abstract

一种SQL指纹还原方法、装置、计算机设备和存储介质。包括:获取待还原SQL指纹;对所述待还原SQL指纹进行解析,获得所述待还原SQL指纹的语法树;其中,所述语法树包含了变量节点;所述变量节点配置有用于描述所述变量节点与列表之间对应关系的Jason结构体;遍历所述语法树的变量节点,从所述Jason结构体中获取各变量节点的变量对应的列表名称和变量列名;根据各所述变量对应的列表名称和变量列名在所述待还原SQL指纹所在的数据库中,获取各所述变量所在的列表中对应列的类型;及根据各所述变量对应列的类型对所述待还原SQL指纹进行还原,获得还原后的SQL语句。

Description

SQL指纹还原方法、装置、计算机设备和存储介质
相关申请的交叉引用
本申请要求于2019年09月18日提交中国专利局,申请号为2019108812575,申请名称为“SQL指纹还原方法、装置、计算机设备和存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及一种SQL指纹还原方法、装置、计算机设备和存储介质。
背景技术
在SQL(结构化查询语言)中使用绑定变量已成为开发人员的共识。一般来说,在OLTP系统(联机事务处理系统)中经常会出现同一条SQL语句,该SQL语句除了谓词不同之外会被经常反复的执行,而每次执行就由于谓词的不同而被认为是不同的SQL语句,所以每次都会重新生成执行计划。
发明人意识到,目前在OLTP系统(联机事务处理系统)对应的MySQL(关系型数据库管理系统)中获取执行计划,带来的资源的争用和消耗会非常大,也可能会产生阻塞,通常我们只能在MySQL(关系型数据库管理系统)中获取到SQL指纹,而分析MySQL的SQL语句的性能,需要获取SQL语句的执行计划才能分析SQL语句的性能。而目前还没有很好的方法通过MySQL(关系型数据库管理系统)中的SQL指纹,获得SQL语句的执行计划进行性能分析,导致MySQL的SQL语句性能分析的工作效率低。
发明内容
根据本申请公开的各种实施例,提供一种SQL指纹还原方法、装置、计算机设备和存储介质。
一种SQL指纹还原方法包括:
获取待还原SQL指纹;
对所述待还原SQL指纹进行解析,获得所述待还原SQL指纹的语法树;其中,所述语法树包含了变量节点;所述变量节点配置有用于描述所述变量节点与列表之间对应关系的Jason结构体;
遍历所述语法树的变量节点,从所述Jason结构体中获取各变量节点的变量对应的列表名称和变量列名;
根据各所述变量对应的列表名称和变量列名在所述待还原SQL指纹所在的数据库中,获取各所述变量所在的列表中对应列的类型;及
根据各所述变量对应列的类型对所述待还原SQL指纹进行还原,获得还原后的SQL语句。
一种SQL指纹还原装置包括:
SQL指纹获取模块,用于获取待还原SQL指纹;
语法树获取模块,用于对所述待还原SQL指纹进行解析,获得所述待还原SQL指纹的语法树;其中,所述语法树包含了变量节点;所述变量节点配置有用于描述所述变量节点与列表之间对应关系的Jason结构体;
遍历模块,用于遍历所述语法树的变量节点,从所述Jason结构体中获取各变量节点的变量对应的列表名称和变量列名;
列的类型获取模块,用于根据各所述变量对应的列表名称和变量列名在所述待还原 SQL指纹所在的数据库中,获取各所述变量所在的列表中对应列的类型;及
还原模块,用于根据各所述变量对应列的类型对所述待还原SQL指纹进行还原,获得还原后的SQL语句。
一种计算机设备,包括存储器和一个或多个处理器,所述存储器中储存有计算机可读指令,所述计算机可读指令被所述处理器执行时,使得所述一个或多个处理器执行以下步骤:
获取待还原SQL指纹;
对所述待还原SQL指纹进行解析,获得所述待还原SQL指纹的语法树;其中,所述语法树包含了变量节点;所述变量节点配置有用于描述所述变量节点与列表之间对应关系的Jason结构体;
遍历所述语法树的变量节点,从所述Jason结构体中获取各变量节点的变量对应的列表名称和变量列名;
根据各所述变量对应的列表名称和变量列名在所述待还原SQL指纹所在的数据库中,获取各所述变量所在的列表中对应列的类型;及
根据各所述变量对应列的类型对所述待还原SQL指纹进行还原,获得还原后的SQL语句。
一个或多个存储有计算机可读指令的非易失性计算机可读存储介质,计算机可读指令被一个或多个处理器执行时,使得一个或多个处理器执行以下步骤:
获取待还原SQL指纹;
对所述待还原SQL指纹进行解析,获得所述待还原SQL指纹的语法树;其中,所述语法树包含了变量节点;所述变量节点配置有用于描述所述变量节点与列表之间对应关系的Jason结构体;
遍历所述语法树的变量节点,从所述Jason结构体中获取各变量节点的变量对应的列表名称和变量列名;
根据各所述变量对应的列表名称和变量列名在所述待还原SQL指纹所在的数据库中,获取各所述变量所在的列表中对应列的类型;及
根据各所述变量对应列的类型对所述待还原SQL指纹进行还原,获得还原后的SQL语句。
本申请的一个或多个实施例的细节在下面的附图和描述中提出。本申请的其它特征和优点将从说明书、附图以及权利要求书变得明显。
附图说明
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其它的附图。
图1为根据一个或多个实施例中SQL指纹还原方法的应用场景图。
图2为根据一个或多个实施例中SQL指纹还原方法的流程示意图。
图3为根据一个或多个实施例中SQL指纹还原装置的结构框图。
图4为另一个实施例中SQL指纹还原装置的结构框图。
图5为根据一个或多个实施例中计算机设备的内部结构图。
具体实施方式
为了使本申请的技术方案及优点更加清楚明白,以下结合附图及实施例,对本申请进行进一步详细说明。应当理解,此处描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。
本申请提供的SQL指纹还原方法,可以应用于如图1所示的应用环境中。终端102通过网络与服务器104通过网络进行通信。可以通过终端102获取待还原SQL指纹;对待还原SQL指纹进行解析,获得待还原SQL指纹的语法树;语法树包含了变量节点;变量节点配置有用于描述变量节点与列表之间对应关系的Jason结构体;遍历语法树的变量节点,从Jason结构体中获取各变量节点的变量对应的列表名称和变量列名;根据各变量对应的列表名称和变量列名在待还原SQL指纹所在的数据库中,获取各变量所在的列表中对应列的类型;根据各变量对应列的类型对待还原SQL指纹进行还原,获得还原后的SQL语句。还可以是终端102通过网络与服务器104进行交互实现,服务器104通过获取终端102上传的待还原SQL指纹;服务器104对待还原SQL指纹进行解析,获得待还原SQL指纹的语法树;语法树包含了变量节点;变量节点配置有用于描述变量节点与列表之间对应关系的Jason结构体;遍历语法树的变量节点,从Jason结构体中获取各变量节点的变量对应的列表名称和变量列名;根据各变量对应的列表名称和变量列名在待还原SQL指纹所在的数据库中,获取各变量所在的列表中对应列的类型;根据各变量对应列的类型对待还原SQL指纹进行还原,获得还原后的SQL语句。终端102可以但不限于是各种个人计算机、笔记本电脑、智能手机、平板电脑和便携式可穿戴设备,服务器104可以用独立的服务器或者是多个服务器组成的服务器集群来实现。
在其中一个实施例中,如图2所示,提供了一种SQL指纹还原方法,以该方法应用于图1中的终端为例进行说明,包括以下步骤:
步骤S220,获取待还原SQL指纹。
其中,待还原SQL指纹是指需要被还原为SQL语句的SQL指纹。SQL指纹为使用绑定变量的SQL语句,如:select*from test where id=?,以下SQL语句select*from t where id=1;select*from t where id=2;select*from t where id=3为例:这三条SQL语句对应的SQL指纹就是select*from t where id=?。可以是用户通过终端直接上传待还原SQL指纹;也可以是用户将待还原SQL指纹预先存储在数据库中,向数据库中获取待还原SQL指纹。
步骤S240,对待还原SQL指纹进行解析,获得待还原SQL指纹的语法树;其中,语法树包含了变量节点;变量节点配置有用于描述变量节点与列表之间对应关系的Jason结构体。
其中,语法树是句子结构的图形表示,它代表了句子的推导结果,有利于理解句子语法结构的层次,简单说,语法树就是按照某一规则进行推导时所形成的树状结构图。待还原SQL指纹的语法树即为按照待还原SQL指纹进行推导所形成的树。可以通过SQL解析包对待还原SQL指纹进行解析,获得待还原SQL指纹的语法树。也可以使用其他可以解析待还原SQL指纹的工具,对待还原SQL指纹进行解析,获得待还原SQL指纹的语法树。
步骤S260,遍历语法树的变量节点,从Jason结构体中获取各变量节点的变量对应的列表名称和变量列名。
其中,变量节点配置有用于描述所述变量节点与列表之间对应关系的Jason结构体,即json结构体中记录了变量对应的列表名称和变量列名。当在语法树中遍历到变量节点时,可以在该变量节点配置的json结构体中找到对应列表名称和变量列名。根据变量标识,遍历待还原SQL指纹的语法树,确定语法树中的各个变量节点,根据各个变量节点获取各个变量节点对应的列表名称和变量列名,如:在待还原SQL指纹的语法树中,变量节点是以问号“?”标识的,遍历到“?”即可判断是变量节点,根据变量节点即可获取到变量节点的变量对应的列表名称和变量列名。可以基于变量对应的列表名称和变量列名,进一步找到变量所在列表中对应的列。
步骤S280,根据各变量对应的列表名称和变量列名在待还原SQL指纹所在的数据库中,获取各变量所在的列表中对应列的类型。
其中,可以通过连接待还原SQL指纹所在的数据库,如:information_schema,information_schema是一个数据库,确切说是信息数据库,其中保存着关于MySQL服务器所维护的所有其他数据库的信息,如数据库名,数据库的表,表栏的数据类型与访问权限等。根据各变量对应的列表名称和变量列名在待还原SQL指纹所在的数据库中,获取各变量所在列表中对应列的类型,比如:对information_schema下的columns(提供了表中的列信息,详细表述了某张表的所有列以及每个列的信息,columns表中有table_name(表名)、column_name(列名)、data_type(数据类型)等信息。通过查询table_name在columns表中可以获取table_name(表名)、column_name(列名)、data_type(数据类型)等信息。)表进行查询,可以获取变量在columns表中对应列的数据类型,根据列表名称可以找到对应的列表,在该列表的对应列可以获取到对应的数据类型。
步骤S300,根据各变量对应列的类型对待还原SQL指纹进行还原,获得还原后的SQL语句。
其中,可以根据获取的变量对应列的类型(该类型指的是数据类型)替换SQL指纹中的变量。针对范例SQL语句,假设id的数据类型为int,则SQL指纹还原后的SQL语句为:select*from test where id=1。
上述SQL指纹还原方法中,获取待还原SQL指纹;通过对待还原SQL指纹进行解析,获得待还原SQL指纹有利于获取变量及变量对应的列表名称和变量列名的语法树,可以准确的找到变量;通过遍历语法树的变量节点,获取各变量对应的列表名称和变量列名;根据各变量对应的列表名称和变量列名在待还原SQL指纹所在的数据库中,获取各变量所在的列表中对应列的类型,可以准确的还原待还原SQL指纹;根据各变量对应列的类型对待还原SQL指纹进行还原,获得还原后的SQL语句。通过SQL指纹来还原SQL语句,实现通过SQL指纹分析SQL语句的性能,提高了分析SQL语句性能的工作效率。
在其中一个实施例中,获取待还原SQL指纹的步骤,包括:获取SQL指纹;调用SQL解析包中的语法校验接口对SQL指纹进行语法校验,获得校验结果;将校验结果为通过的SQL指纹作为待还原SQL指纹。
其中,SQL解析包可以是开源的Vitess/sqlparse解析包;也可以是开源数据库TiDB的sqlparser包;还可以去其他解析包,可以基于语言设计不同的开源解析包。SQL解析包中的语法校验接口可以是Vitess/sqlparse解析包中提供用于语法校验的接口;也可以是开源数据库TiDB的sqlparser包中提供用于语法校验的接口。基于语法校验接口对SQL指纹进行语法校验,获得校验结果,当语法正确时校验结果为通过,将校验结果为通过的SQL指纹作为待还原SQL指纹;当语法错误时校验结果为未通过,提醒用户重新上传SQL指纹,并提醒语法错误。并避免用户上传错误的SQL指纹,提高运行速度。
在其中一个实施例中,对待还原SQL指纹进行解析,获得待还原SQL指纹的语法树的步骤,包括:调用SQL解析包中的解析接口,对待还原SQL指纹进行解析,获得待还原SQL指纹的语法树。
其中,SQL解析包可以是开源的Vitess/sqlparse解析包;也可以是开源数据库TiDB的sqlparser包;还可以去其他解析包,可以基于语言设计不同的开源解析包。SQL解析包中的解析接口可以是Vitess/sqlparse解析包中提供用于解析SQL指纹的接口;也可以是开源数据库TiDB的sqlparser包中提供用于解析SQL指纹的接口。具体地,调用开源的Vitess/sqlparse解析包中的解析接口,对待还原SQL指纹进行解析,获得待还原SQL指纹的语法树,可以提高解析效率。
在其中一个实施例中,根据各变量对应的列表名称和变量列名在待还原SQL指纹所在的数据库中,获取各变量所在的列表中对应列的类型的步骤,包括:获取待还原SQL指纹所在的数据库的标识;根据标识连接待还原SQL指纹所在的数据库;根据各变量对应的列表名称和变量列名,在待还原SQL指纹所在的数据库中进行查找,确定各变量所在的列表 中对应列的类型。
其中,数据库的标识可以是用户在启动SQL指纹还原方法时通过终端以参数的形式传入的;也可以是预先设定待还原SQL指纹所在的数据库的标识,直接获取对应数据库的标识。通过数据库的标识连接SQL指纹所在的数据库,通过传入的参数连接到SQL指纹所在的数据库,根据列表名称可以找到对应的列表,在该列表的对应列可以获取到对应的数据类型,如:columns表中有table_name(表名)、column_name(列名)、data_type(数据类型)等信息,通过查询table_name在columns表中可以获取上述相关信息。可以通过用户在启动SQL指纹还原方法时通过终端传入的参数,自动连接待还原SQL指纹所在的数据库,进一步确定各变量所在列表中对应列的类型,提高了SQL指纹还原为SQL语句的效率。
在其中一个实施例中,根据各变量对应的列表名称和变量列名,在待还原SQL指纹所在的数据库中进行查找,确定各变量所在列表中对应列的类型的步骤,包括:根据各变量对应的列表名称,确定各变量所在的列表;根据各变量列名在各变量所在的列表中,确定各变量所在的列;根据各变量所在的列,确定各变量对应列的类型。
其中,如:变量A对应的列表名称为“b”,变量列名为“c”,根据列表名称“b”和变量列名“c”在information_schema数据库的columns表中找到对应的“b”列表中的“c”列,根据各变量所在的“c”列对应数据类型,该数据类型即为变量A对应列的类型。进一步确定各变量所在列表中对应列的类型,提高了SQL指纹还原为SQL语句的效率。
在其中一个实施例中,根据各变量对应列的类型对待还原SQL指纹进行还原,获得还原后的SQL语句的步骤,包括:根据各变量对应列的类型,对待还原SQL指纹中的变量进行替换,获得还原后的SQL语句。
其中,可以根据获取的变量对应列的类型(该类型指的是数据类型)替换SQL指纹中的变量。针对范例SQL语句,假设id的数据类型为int,则SQL指纹还原后的SQL语句为:select*from test where id=1。通过SQL指纹对SQL语句进行还原,实现通过SQL指纹分析SQL语句的性能,提高了分析SQL语句性能的工作效率。
在其中一个实施例中,还包括:调用explain的方法获取还原后的SQL语句的执行计划,获得还原后的SQL语句的执行计划;根据还原后的SQL语句的执行计划对还原后的SQL语句进行性能分析。
其中,获得还原后的SQL语句后,连接MySQL数据库,调用explain的方法获取还原后的SQL语句的执行计划,获得还原后的SQL语句的执行计划;根据还原后的SQL语句的执行计划对还原后的SQL语句进行性能分析。MySQL数据库是一种开放源代码的关系型数据库管理系统(RDBMS),使用最常用的数据库管理语言--结构化查询语言(SQL)进行数据库管理。explain的方法用来帮助优化索引和查询语句等等。从而解决了SQL指纹无法在MySQL中获取执行计划的问题,并提升分析SQL语句性能的工作效率。在只能获取到SQL指纹时,为了分析SQL语句的性能,可以根据SQL指纹来原后SQL语句获取对应的执行计划,进行性能优化,提高了工作效率。
应该理解的是,虽然图2的流程图中的各个步骤按照箭头的指示依次显示,但是这些步骤并不是必然按照箭头指示的顺序依次执行。除非本文中有明确的说明,这些步骤的执行并没有严格的顺序限制,这些步骤可以以其它的顺序执行。而且,图2中的至少一部分步骤可以包括多个子步骤或者多个阶段,这些子步骤或者阶段并不必然是在同一时刻执行完成,而是可以在不同的时刻执行,这些子步骤或者阶段的执行顺序也不必然是依次进行,而是可以与其它步骤或者其它步骤的子步骤或者阶段的至少一部分轮流或者交替地执行。
在其中一个实施例中,如图3所示,提供了一种SQL指纹还原装置,包括:SQL指纹获取模块310、语法树获取模块320、遍历模块330、列的类型获取模块340和还原模块 350,其中:
SQL指纹获取模块310,用于获取待还原SQL指纹;
语法树获取模块320,用于对待还原SQL指纹进行解析,获得待还原SQL指纹的语法树,其中,语法树包含了变量节点;变量节点配置有用于描述变量节点与列表之间对应关系的Jason结构体;
遍历模块330,用于遍历语法树的变量节点,从Jason结构体中获取各变量节点的变量对应的列表名称和变量列名;
列的类型获取模块340,用于根据各变量对应的列表名称和变量列名在待还原SQL指纹所在的数据库中,获取各变量所在的列表中对应列的类型;及
还原模块350,用于根据各变量对应列的类型对待还原SQL指纹进行还原,获得还原后的SQL语句。
在其中一个实施例中,SQL指纹获取模块310还用于:获取SQL指纹;调用SQL解析包中的语法校验接口对SQL指纹进行语法校验,获得校验结果;将校验结果为通过的SQL指纹作为待还原SQL指纹。
在其中一个实施例中,语法树获取模块320还用于:调用SQL解析包中的解析接口,对待还原SQL指纹进行解析,获得待还原SQL指纹的语法树。
在其中一个实施例中,列的类型获取模块340还用于:获取待还原SQL指纹所在的数据库的标识;根据标识连接待还原SQL指纹所在的数据库;根据各变量对应的列表名称和变量列名,在待还原SQL指纹所在的数据库中进行查找,确定各变量所在的列表中对应列的类型。
在其中一个实施例中,列的类型获取模块340还用于:根据各变量对应的列表名称,确定各变量所在的列表;根据各所述变量列名在各所述变量所在的列表中,确定各所述变量所在的列;根据各变量所在的列,确定各变量对应列的类型。
在其中一个实施例中,还原模块350还用于:根据各变量对应列的类型,对待还原SQL指纹中的变量进行替换,获得还原后的SQL语句。
如图4所示,在其中一个实施例中,SQL指纹还原装置还包括性能分析模块360,用于调用explain的方法获取还原后的SQL语句的执行计划,获得还原后的SQL语句的执行计划;根据还原后的SQL语句的执行计划对还原后的SQL语句进行性能分析。
关于SQL指纹还原装置的具体限定可以参见上文中对于SQL指纹还原方法的限定,在此不再赘述。上述SQL指纹还原装置中的各个模块可全部或部分通过软件、硬件及其组合来实现。上述各模块可以硬件形式内嵌于或独立于计算机设备中的处理器中,也可以以软件形式存储于计算机设备中的存储器中,以便于处理器调用执行以上各个模块对应的操作。
在其中一个实施例中,提供了一种计算机设备,该计算机设备可以是终端,其内部结构图可以如图5所示。该计算机设备包括通过系统总线连接的处理器、存储器、网络接口、显示屏和输入装置。其中,该计算机设备的处理器用于提供计算和控制能力。该计算机设备的存储器包括非易失性存储介质、内存储器。该非易失性存储介质存储有操作系统和计算机可读指令。该内存储器为非易失性存储介质中的操作系统和计算机可读指令的运行提供环境。该计算机设备的网络接口用于与外部的终端通过网络连接通信。该计算机可读指令被处理器执行时以实现一种SQL指纹还原方法。该计算机设备的显示屏可以是液晶显示屏或者电子墨水显示屏,该计算机设备的输入装置可以是显示屏上覆盖的触摸层,也可以是计算机设备外壳上设置的按键、轨迹球或触控板,还可以是外接的键盘、触控板或鼠标等。
本领域技术人员可以理解,图5中示出的结构,仅仅是与本申请方案相关的部分结构的框图,并不构成对本申请方案所应用于其上的计算机设备的限定,具体的计算机设备可 以包括比图中所示更多或更少的部件,或者组合某些部件,或者具有不同的部件布置。
一种计算机设备,包括存储器和一个或多个处理器,存储器中储存有计算机可读指令,计算机可读指令被处理器执行时,使得一个或多个处理器执行以下步骤:
获取待还原SQL指纹;
对待还原SQL指纹进行解析,获得待还原SQL指纹的语法树,其中,语法树包含了变量节点,变量节点配置有用于描述变量节点与列表之间对应关系的Jason结构体;
遍历语法树的变量节点,从Jason结构体中获取各变量节点的变量对应的列表名称和变量列名;
根据各变量对应的列表名称和变量列名在待还原SQL指纹所在的数据库中,获取各变量所在的列表中对应列的类型;及
根据各变量对应列的类型对待还原SQL指纹进行还原,获得还原后的SQL语句。
在其中一个实施例中,处理器执行计算机可读指令时还实现以下步骤:
获取SQL指纹;
调用SQL解析包中的语法校验接口对SQL指纹进行语法校验,获得校验结果;及
将校验结果为通过的SQL指纹作为待还原SQL指纹。
在其中一个实施例中,处理器执行计算机可读指令时还实现以下步骤:调用SQL解析包中的解析接口,对待还原SQL指纹进行解析,获得待还原SQL指纹的语法树。
在其中一个实施例中,处理器执行计算机可读指令时还实现以下步骤:
获取待还原SQL指纹所在的数据库的标识;
根据标识连接待还原SQL指纹所在的数据库;及
根据各变量对应的列表名称和变量列名,在待还原SQL指纹所在的数据库中进行查找,确定各变量所在的列表中对应列的类型。
在其中一个实施例中,处理器执行计算机可读指令时还实现以下步骤:
根据各变量对应的列表名称,确定各变量所在的列表;
根据各所述变量列名在各所述变量所在的列表中,确定各所述变量所在的列;及
根据各变量所在的列,确定各变量对应列的类型。
在其中一个实施例中,处理器执行计算机可读指令时还实现以下步骤:根据各变量对应列的类型,对待还原SQL指纹中的变量进行替换,获得还原后的SQL语句。
在其中一个实施例中,处理器执行计算机可读指令时还实现以下步骤:
调用explain的方法获取还原后的SQL语句的执行计划,获得还原后的SQL语句的执行计划;及
根据还原后的SQL语句的执行计划对还原后的SQL语句进行性能分析。
一个或多个存储有计算机可读指令的非易失性计算机可读存储介质,计算机可读指令被一个或多个处理器执行时,使得一个或多个处理器执行以下步骤:
获取待还原SQL指纹;
对待还原SQL指纹进行解析,获得待还原SQL指纹的语法树;其中,语法树包含了变量节点;变量节点配置有用于描述变量节点与列表之间对应关系的Jason结构体;
遍历语法树的变量节点,从Jason结构体中获取各变量节点的变量对应的列表名称和变量列名;
根据各变量对应的列表名称和变量列名在待还原SQL指纹所在的数据库中,获取各变量所在的列表中对应列的类型;及
根据各变量对应列的类型对待还原SQL指纹进行还原,获得还原后的SQL语句。
在其中一个实施例中,计算机可读指令被处理器执行时还实现以下步骤:
获取SQL指纹;
调用SQL解析包中的语法校验接口对SQL指纹进行语法校验,获得校验结果;及
将校验结果为通过的SQL指纹作为待还原SQL指纹。
在其中一个实施例中,计算机可读指令被处理器执行时还实现以下步骤:调用SQL解析包中的解析接口,对待还原SQL指纹进行解析,获得待还原SQL指纹的语法树。
在其中一个实施例中,计算机可读指令被处理器执行时还实现以下步骤:
获取待还原SQL指纹所在的数据库的标识;
根据标识连接待还原SQL指纹所在的数据库;及
根据各变量对应的列表名称和变量列名,在待还原SQL指纹所在的数据库中进行查找,确定各变量所在的列表中对应列的类型。
在其中一个实施例中,计算机可读指令被处理器执行时还实现以下步骤:
根据各变量对应的列表名称,确定各变量所在的列表;
根据各所述变量列名在各所述变量所在的列表中,确定各所述变量所在的列;及
根据各变量所在的列,确定各变量对应列的类型。
在其中一个实施例中,计算机可读指令被处理器执行时还实现以下步骤:根据各变量对应列的类型,对待还原SQL指纹中的变量进行替换,获得还原后的SQL语句。
在其中一个实施例中,计算机可读指令被处理器执行时还实现以下步骤:
调用explain的方法获取还原后的SQL语句的执行计划,获得还原后的SQL语句的执行计划;及
根据还原后的SQL语句的执行计划对还原后的SQL语句进行性能分析。
本领域普通技术人员可以理解实现上述实施例方法中的全部或部分流程,是可以通过计算机可读指令来指令相关的硬件来完成,所述的计算机可读指令可存储于一非易失性计算机可读取存储介质中,该计算机可读指令在执行时,可包括如上述各方法的实施例的流程。其中,本申请所提供的各实施例中所使用的对存储器、存储、数据库或其它介质的任何引用,均可包括非易失性和/或易失性存储器。非易失性存储器可包括只读存储器(ROM)、可编程ROM(PROM)、电可编程ROM(EPROM)、电可擦除可编程ROM(EEPROM)或闪存。易失性存储器可包括随机存取存储器(RAM)或者外部高速缓冲存储器。作为说明而非局限,RAM以多种形式可得,诸如静态RAM(SRAM)、动态RAM(DRAM)、同步DRAM(SDRAM)、双数据率SDRAM(DDRSDRAM)、增强型SDRAM(ESDRAM)、同步链路(Synchlink)DRAM(SLDRAM)、存储器总线(Rambus)直接RAM(RDRAM)、直接存储器总线动态RAM(DRDRAM)、以及存储器总线动态RAM(RDRAM)等。
以上实施例的各技术特征可以进行任意的组合,为使描述简洁,未对上述实施例中的各个技术特征所有可能的组合都进行描述,然而,只要这些技术特征的组合不存在矛盾,都应当认为是本说明书记载的范围。
以上所述实施例仅表达了本申请的几种实施方式,其描述较为具体和详细,但并不能因此而理解为对发明专利范围的限制。应当指出的是,对于本领域的普通技术人员来说,在不脱离本申请构思的前提下,还可以做出若干变形和改进,这些都属于本申请的保护范围。因此,本申请专利的保护范围应以所附权利要求为准。

Claims (20)

  1. 一种SQL指纹还原方法,包括:
    获取待还原SQL指纹;
    对所述待还原SQL指纹进行解析,获得所述待还原SQL指纹的语法树;其中,所述语法树包含了变量节点;所述变量节点配置有用于描述所述变量节点与列表之间对应关系的Jason结构体;
    遍历所述语法树的变量节点,从所述Jason结构体中获取各变量节点的变量对应的列表名称和变量列名;
    根据各所述变量对应的列表名称和变量列名在所述待还原SQL指纹所在的数据库中,获取各所述变量所在的列表中对应列的类型;及
    根据各所述变量对应列的类型对所述待还原SQL指纹进行还原,获得还原后的SQL语句。
  2. 根据权利要求1所述的方法,其特征在于,获取待还原SQL指纹,包括:
    获取SQL指纹;
    调用SQL解析包中的语法校验接口对所述SQL指纹进行语法校验,获得校验结果;及将校验结果为通过的SQL指纹作为待还原SQL指纹。
  3. 根据权利要求1所述的方法,其特征在于,对所述待还原SQL指纹进行解析,获得所述待还原SQL指纹的语法树,包括:
    调用SQL解析包中的解析接口,对所述待还原SQL指纹进行解析,获得所述待还原SQL指纹的语法树。
  4. 根据权利要求1所述的方法,其特征在于,根据各所述变量对应的列表名称和变量列名在所述待还原SQL指纹所在的数据库中,获取各所述变量所在的列表中对应列的类型,包括:
    获取所述待还原SQL指纹所在的数据库的标识;
    根据所述标识连接所述待还原SQL指纹所在的数据库;及
    根据各所述变量对应的列表名称和变量列名,在所述待还原SQL指纹所在的数据库中进行查找,确定各所述变量所在的列表中对应列的类型。
  5. 根据权利要求4所述的方法,其特征在于,根据各所述变量对应的列表名称和变量列名,在所述待还原SQL指纹所在的数据库中进行查找,确定各所述变量所在的列表中对应列的类型,包括:
    根据各所述变量对应的列表名称,确定各所述变量所在的列表;
    根据各所述变量列名在各所述变量所在的列表中,确定各所述变量所在的列;及
    根据各所述变量所在的列,确定各所述变量对应列的类型。
  6. 根据权利要求1所述的方法,其特征在于,根据各所述变量对应列的类型对所述待还原SQL指纹进行还原,获得还原后的SQL语句,包括:
    根据各所述变量对应列的类型,对所述待还原SQL指纹中的变量进行替换,获得还原后的SQL语句。
  7. 根据权利要求1-6任一项所述的方法,其特征在于,还包括:
    调用explain的方法获取所述还原后的SQL语句的执行计划,获得所述还原后的SQL语句的执行计划;及
    根据所述还原后的SQL语句的执行计划对所述还原后的SQL语句进行性能分析。
  8. 一种SQL指纹还原装置,包括:
    SQL指纹获取模块,用于获取待还原SQL指纹;
    语法树获取模块,用于对所述待还原SQL指纹进行解析,获得所述待还原SQL指纹的语法树;其中,所述语法树包含了变量节点;所述变量节点配置有用于描述所述变量节点 与列表之间对应关系的Jason结构体;
    遍历模块,用于遍历所述语法树的变量节点,从所述Jason结构体中获取各变量节点的变量对应的列表名称和变量列名;
    列的类型获取模块,用于根据各所述变量对应的列表名称和变量列名在所述待还原SQL指纹所在的数据库中,获取各所述变量所在的列表中对应列的类型;及
    还原模块,用于根据各所述变量对应列的类型对所述待还原SQL指纹进行还原,获得还原后的SQL语句。
  9. 根据权利要求8所述的装置,其特征在于,所述SQL指纹获取模块还用于:获取SQL指纹;调用SQL解析包中的语法校验接口对所述SQL指纹进行语法校验,获得校验结果;将所述校验结果为通过的SQL指纹作为待还原SQL指纹。
  10. 一种计算机设备,包括存储器及一个或多个处理器,所述存储器中储存有计算机可读指令,所述计算机可读指令被所述一个或多个处理器执行时,使得所述一个或多个处理器执行以下步骤:
    获取待还原SQL指纹;
    对所述待还原SQL指纹进行解析,获得所述待还原SQL指纹的语法树;其中,所述语法树包含了变量节点;所述变量节点配置有用于描述所述变量节点与列表之间对应关系的Jason结构体;
    遍历所述语法树的变量节点,从所述Jason结构体中获取各变量节点的变量对应的列表名称和变量列名;
    根据各所述变量对应的列表名称和变量列名在所述待还原SQL指纹所在的数据库中,获取各所述变量所在的列表中对应列的类型;及
    根据各所述变量对应列的类型对所述待还原SQL指纹进行还原,获得还原后的SQL语句。
  11. 根据权利要求10所述的计算机设备,其特征在于,所述处理器执行所述计算机可读指令时还执行以下步骤:
    获取SQL指纹;
    调用SQL解析包中的语法校验接口对所述SQL指纹进行语法校验,获得校验结果;及将校验结果为通过的SQL指纹作为待还原SQL指纹。
  12. 根据权利要求10所述的计算机设备,其特征在于,所述处理器执行所述计算机可读指令时还执行以下步骤:
    调用SQL解析包中的解析接口,对所述待还原SQL指纹进行解析,获得所述待还原SQL指纹的语法树。
  13. 根据权利要求10所述的计算机设备,其特征在于,所述处理器执行所述计算机可读指令时还执行以下步骤:
    获取所述待还原SQL指纹所在的数据库的标识;
    根据所述标识连接所述待还原SQL指纹所在的数据库;及
    根据各所述变量对应的列表名称和变量列名,在所述待还原SQL指纹所在的数据库中进行查找,确定各所述变量所在的列表中对应列的类型。
  14. 根据权利要求13所述的计算机设备,其特征在于,所述处理器执行所述计算机可读指令时还执行以下步骤:
    根据各所述变量对应的列表名称,确定各所述变量所在的列表;
    根据各所述变量列名在各所述变量所在的列表中,确定各所述变量所在的列;及
    根据各所述变量所在的列,确定各所述变量对应列的类型。
  15. 根据权利要求10所述的计算机设备,其特征在于,所述处理器执行所述计算机可读指令时还执行以下步骤:
    根据各所述变量对应列的类型,对所述待还原SQL指纹中的变量进行替换,获得还原后的SQL语句。
  16. 一个或多个存储有计算机可读指令的非易失性计算机可读存储介质,所述计算机可读指令被一个或多个处理器执行时,使得所述一个或多个处理器执行以下步骤:
    获取待还原SQL指纹;
    对所述待还原SQL指纹进行解析,获得所述待还原SQL指纹的语法树;其中,所述语法树包含了变量节点;所述变量节点配置有用于描述所述变量节点与列表之间对应关系的Jason结构体;
    遍历所述语法树的变量节点,从所述Jason结构体中获取各变量节点的变量对应的列表名称和变量列名;
    根据各所述变量对应的列表名称和变量列名在所述待还原SQL指纹所在的数据库中,获取各所述变量所在的列表中对应列的类型;及
    根据各所述变量对应列的类型对所述待还原SQL指纹进行还原,获得还原后的SQL语句。
  17. 根据权利要求16所述的存储介质,其特征在于,所述计算机可读指令被所述处理器执行时还执行以下步骤:
    获取SQL指纹;
    调用SQL解析包中的语法校验接口对所述SQL指纹进行语法校验,获得校验结果;及将校验结果为通过的SQL指纹作为待还原SQL指纹。
  18. 根据权利要求16所述的存储介质,其特征在于,所述计算机可读指令被所述处理器执行时还执行以下步骤:
    调用SQL解析包中的解析接口,对所述待还原SQL指纹进行解析,获得所述待还原SQL指纹的语法树。
  19. 根据权利要求16所述的存储介质,其特征在于,所述计算机可读指令被所述处理器执行时还执行以下步骤:
    获取所述待还原SQL指纹所在的数据库的标识;
    根据所述标识连接所述待还原SQL指纹所在的数据库;及
    根据各所述变量对应的列表名称和变量列名,在所述待还原SQL指纹所在的数据库中进行查找,确定各所述变量所在的列表中对应列的类型。
  20. 根据权利要求19所述的存储介质,其特征在于,所述计算机可读指令被所述处理器执行时还执行以下步骤:
    根据各所述变量对应的列表名称,确定各所述变量所在的列表;
    根据各所述变量列名在各所述变量所在的列表中,确定各所述变量所在的列;及根据各所述变量所在的列,确定各所述变量对应列的类型。
PCT/CN2019/116950 2019-09-18 2019-11-11 Sql指纹还原方法、装置、计算机设备和存储介质 WO2021051522A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910881257.5A CN110795451B (zh) 2019-09-18 2019-09-18 Sql指纹还原方法、装置、计算机设备和存储介质
CN201910881257.5 2019-09-18

Publications (1)

Publication Number Publication Date
WO2021051522A1 true WO2021051522A1 (zh) 2021-03-25

Family

ID=69427324

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/116950 WO2021051522A1 (zh) 2019-09-18 2019-11-11 Sql指纹还原方法、装置、计算机设备和存储介质

Country Status (2)

Country Link
CN (1) CN110795451B (zh)
WO (1) WO2021051522A1 (zh)

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090063435A1 (en) * 2007-08-31 2009-03-05 Ebersole Steven Parameter type prediction in object relational mapping
US20160063063A1 (en) * 2014-09-02 2016-03-03 Salesforce.Com, Inc. Database query system
CN106844380A (zh) * 2015-12-04 2017-06-13 阿里巴巴集团控股有限公司 一种数据库操作方法、信息处理方法和相应装置
CN110096513A (zh) * 2019-04-10 2019-08-06 阿里巴巴集团控股有限公司 一种数据查询、资金核对方法及装置

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7092931B1 (en) * 2002-05-10 2006-08-15 Oracle Corporation Methods and systems for database statement execution plan optimization
CN101013442A (zh) * 2007-02-07 2007-08-08 浙江大学 数据库性能的无代理统一监控方法
CN110134707A (zh) * 2019-04-12 2019-08-16 平安普惠企业管理有限公司 一种数据查询方法、装置、电子设备及存储介质

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090063435A1 (en) * 2007-08-31 2009-03-05 Ebersole Steven Parameter type prediction in object relational mapping
US20160063063A1 (en) * 2014-09-02 2016-03-03 Salesforce.Com, Inc. Database query system
CN106844380A (zh) * 2015-12-04 2017-06-13 阿里巴巴集团控股有限公司 一种数据库操作方法、信息处理方法和相应装置
CN110096513A (zh) * 2019-04-10 2019-08-06 阿里巴巴集团控股有限公司 一种数据查询、资金核对方法及装置

Also Published As

Publication number Publication date
CN110795451A (zh) 2020-02-14
CN110795451B (zh) 2023-05-16

Similar Documents

Publication Publication Date Title
WO2020015150A1 (zh) 数据表动态导出方法、装置、计算机设备及存储介质
US11023486B2 (en) Low-latency predictive database analysis
US11941034B2 (en) Conversational database analysis
US9128991B2 (en) Techniques to perform in-database computational programming
US8682876B2 (en) Techniques to perform in-database computational programming
CN110795455A (zh) 依赖关系解析方法、电子装置、计算机设备及可读存储介质
US10229210B2 (en) Search query task management for search system tuning
WO2021179722A1 (zh) Sql语句解析方法、系统、计算机设备和存储介质
US10936478B2 (en) Fast change impact analysis tool for large-scale software systems
WO2021003913A1 (zh) 注释信息处理方法、装置、计算机设备及存储介质
CN108563694B (zh) 对逻辑删除的sql执行方法、装置、计算机设备和存储介质
WO2021217846A1 (zh) 接口数据处理方法、装置、计算机设备和存储介质
US20190361999A1 (en) Data analysis over the combination of relational and big data
WO2020192141A1 (zh) 接口模拟方法、装置、计算机设备和存储介质
CN109710220B (zh) 关系型数据库查询方法、装置、设备及存储介质
US20180150530A1 (en) Method, Apparatus, Computing Device and Storage Medium for Analyzing and Processing Data
CN110688544A (zh) 一种查询数据库的方法、设备及存储介质
CN111177113B (zh) 数据迁移方法、装置、计算机设备和存储介质
US11144562B1 (en) Method and apparatus of indicator information determination
US20230101890A1 (en) Object Scriptability
WO2021051501A1 (zh) Sql提取方法、装置、计算机设备和存储介质
CN113010502A (zh) 数据质量稽核方法、装置、设备和存储介质
CN112182637A (zh) 一种安全控制系统、方法、装置及存储介质
US10719424B1 (en) Compositional string analysis
WO2021051522A1 (zh) Sql指纹还原方法、装置、计算机设备和存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19945488

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19945488

Country of ref document: EP

Kind code of ref document: A1