WO2018130142A1 - 用于数据库语句的语句解析方法 - Google Patents

用于数据库语句的语句解析方法 Download PDF

Info

Publication number
WO2018130142A1
WO2018130142A1 PCT/CN2018/071916 CN2018071916W WO2018130142A1 WO 2018130142 A1 WO2018130142 A1 WO 2018130142A1 CN 2018071916 W CN2018071916 W CN 2018071916W WO 2018130142 A1 WO2018130142 A1 WO 2018130142A1
Authority
WO
WIPO (PCT)
Prior art keywords
statement
database
word sequence
similarity table
input
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.)
Ceased
Application number
PCT/CN2018/071916
Other languages
English (en)
French (fr)
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.)
China Unionpay Co Ltd
Original Assignee
China Unionpay 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 China Unionpay Co Ltd filed Critical China Unionpay Co Ltd
Priority to EP18739262.6A priority Critical patent/EP3570190A4/en
Priority to US16/478,275 priority patent/US10896180B2/en
Publication of WO2018130142A1 publication Critical patent/WO2018130142A1/zh
Anticipated expiration legal-status Critical
Ceased legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2453Query optimisation
    • G06F16/24534Query rewriting; Transformation
    • G06F16/24549Run-time optimisation
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2255Hash tables
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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 OR CALCULATING; 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
    • G06F16/2443Stored procedures
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/2452Query translation
    • G06F16/24524Access plan code generation and invalidation; Reuse of access plans
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/2452Query translation
    • G06F16/24526Internal representations for queries
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/2452Query translation
    • G06F16/24528Standardisation; Simplification
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; 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/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • G06F16/275Synchronous replication
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/20Natural language analysis
    • G06F40/205Parsing
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • G06F8/42Syntactic analysis
    • G06F8/427Parsing

Definitions

  • the present invention relates to the field of database technology, and more particularly to a statement parsing method for database statements.
  • Statement analysis is widely used in the computer field. It is one of the basic technologies for human-computer interaction. It implements the translation from natural language to machine language, such as XML, SQL, C and JAVA. It is an important application of statement parsing.
  • statement parsing is divided into two phases: lexical analysis and grammar parsing.
  • Lexical analysis is used to segment a sentence into a sequence of words
  • grammar parsing is used to construct a grammar tree or other internal data structure based on a sequence of words. The result of the analysis will be used for subsequent data calculations.
  • the client sends a SQL statement to the data
  • the server performs lexical analysis on the SQL statement, and then performs parsing and parsing into a data structure executable inside the computer.
  • the SQL statement is a bridge between the database user and the database operation, the statement complexity is high and the difference is large, so there will be a large amount of data resources in the database processing for the parsing of the SQL statement.
  • the result of multiplexing the SQL parsing of the same statement generally the execution plan
  • 2) providing the prepare statement, the variable data used by the user "?” is substituted to reduce the number of differences in the statement.
  • the above existing scheme has the following disadvantages: First, the degree of recombination of the parsing is too fine, and the parsing result can only be multiplexed for the identical statement, resulting in a large amount of cached data; 2. Replacing the variable content in the statement by using "?” The method is not very friendly to the user.
  • the above existing solutions are mainly designed for SQL language features, and are difficult to apply in other language parsing. For example, it is difficult for programmers to use "?” instead of variable content in their code, and this is only to improve the compiler. Resolution speed.
  • the object of the present invention is to provide a statement parsing method for a database statement, which can be applied independently of the database language type, can quickly parse the database statement, and further improve the response speed and work efficiency of the database.
  • the present invention provides a technical solution as follows:
  • a statement parsing method for a database statement comprising the steps of: performing lexical analysis on a database statement input into a database to obtain an input word sequence; and searching for a statement similarity table according to the input word sequence to determine whether the statement similarity table is There is an existing word sequence similar to the input word sequence; wherein the statement similarity table records the correspondence between various existing word sequences and the analytical data, and the existing word sequence is obtained by lexical analysis of the database statement.
  • the parsed data is used by the database to execute the database statement; if there is an existing word sequence similar to the input word sequence in the statement similarity table, the parsed data corresponding to the existing existing word sequence is obtained from the statement similarity table; otherwise, Inputting a sequence of words for parsing to obtain parsed data corresponding to the input word sequence, and storing the input word sequence and the corresponding parsed data in the sentence similarity table; and based on the existing word sequence corresponding to the similarity or corresponding to the input word sequence Parsing data to execute the input number According to the library's database statement.
  • the statement similarity table further includes a hash sub-table, and the hash sub-table records the correspondence between the hash values of the different existing word sequences and the parsed data; wherein the similarity is obtained from the statement similarity table.
  • the parsing data corresponding to the word sequence specifically includes: determining the parsing data corresponding to the similar existing word sequence according to the hash value corresponding to the similar existing word sequence.
  • determining whether there is an existing word sequence similar to the input word sequence in the statement similarity table comprises: comparing each existing word sequence with the input word sequence for each existing word sequence in the sentence similarity table The number of words and the position of the word obtained by the lexical analysis, if the number of words and the position of the word are the same, it is determined that there is an existing word sequence similar to the input word sequence in the sentence similarity table.
  • the hash value of the existing word sequence is calculated based on calculating the hash value of the existing word sequence based on the position of each word obtained by lexical analysis of the existing word sequence and the hash value.
  • the invention also discloses a database comprising a statement parsing unit and a statement similarity table, wherein the statement parsing unit parses the database statement of the input database by using the above method and the statement similarity table.
  • Another object of the present invention is to provide a statement parsing method for a database statement, which partially completes the statement similarity comparison work to the client to reduce the workload of the database.
  • the present invention provides another technical solution as follows:
  • a statement parsing method for a database statement comprising the steps of: performing lexical analysis on a database statement input to a client to obtain an input word sequence; and searching for a client statement similarity table according to the input word sequence to determine that the client statement is similar Whether there is an existing word sequence similar to the input word sequence in the sex table; wherein the client statement similarity table records various existing word sequences different from each other, and the existing word sequence is obtained by lexical analysis of the database statement; In the end statement similarity table, there is an existing word sequence similar to the input word sequence, and the client sends a similarity statement parsing request to the database; the database searches the database side statement similarity table based on the similarity statement parsing request to determine and similar The parsing data corresponding to the request parsing request; wherein, the database side statement similarity table records the correspondence between the parsing request and the parsing data of the similarity statement, the parsing data is used by the database to execute the database statement; the database parses the request based
  • the present invention also discloses a database application system, comprising: a database server, maintaining a database side statement similarity table; and a plurality of clients respectively maintaining a client statement similarity table; wherein the database application system utilizes the above method To parse and execute the database statement of the input client.
  • the statement parsing method for the database statement provided by the invention can quickly parse the database statement, and is beneficial to improving the response speed and work efficiency of the database. Its wide application range and low application cost make it easier for developers to perform database development work more efficiently.
  • FIG. 1 is a schematic flowchart diagram of a statement parsing method for a database statement according to a first embodiment of the present invention.
  • FIG. 2 is a schematic flowchart diagram of a statement parsing method for a database statement according to a third embodiment of the present invention.
  • a first embodiment of the present invention provides a statement parsing method for a database statement, which includes the following steps:
  • Step S10 Perform lexical analysis on the database statement input to the database to obtain an input word sequence.
  • Step S11 Find a sentence similarity table according to the input word sequence to determine whether there is an existing word sequence similar to the input word sequence in the sentence similarity table.
  • the statement similarity table records the correspondence between various existing word sequences and the analytical data, and the existing word sequence is obtained by lexical analysis of the database statement, and the parsed data is used by the database to execute the database statement.
  • Statements 1-3 can be found with similar lexical sequences.
  • the statement similarity table further includes a hash sub-table, and the hash sub-table records the correspondence between the hash values of the different existing word sequences and the parsed data.
  • the hash value of the existing word sequence can be calculated based on: calculating the hash value of the existing word sequence based on the position of each word obtained by lexical analysis of the existing word sequence and the hash value; that is, the existing word sequence
  • the hash value can be a weighted combination of calculated values.
  • the calculation method of the hash value of the word sequence is as follows:
  • the hash value of the word is a fixed value (for example, 1); if the type of the word is another value, the hash value of the word is a hash value corresponding to the word converted to a lowercase string;
  • the final sql_hash is the hash value of the word sequence.
  • determining whether there is an existing word sequence similar to the input word sequence in the sentence similarity table may be implemented as follows: for each existing word sequence in the sentence similarity table, compare the The number of words and the position of the word obtained by the lexical analysis of the existing word sequence and the input word sequence, if the number of words and the word position are the same, the existing word sequence similar to the input word sequence exists in the judgment statement similarity table. . If the number of words is not similar or the word positions are not similar, it is determined that there is no existing word sequence similar to the input word sequence.
  • Step S120 If there is an existing word sequence similar to the input word sequence in the sentence similarity table, the parsed data corresponding to the similar existing word sequence is obtained from the statement similarity table.
  • the parsed data corresponding to the similar existing word sequence is determined according to the hash value corresponding to the similar existing word sequence.
  • the hash value it is possible to facilitate determining the efficiency of parsing the data and improving the accuracy of determining the parsed data.
  • Step S121 if there is no existing word sequence similar to the input word sequence in the statement similarity table, the input word sequence is parsed to obtain the parsed data corresponding to the input word sequence, and the input word sequence and the corresponding parsed data are input. Save in the statement similarity table.
  • Step S13 executing a database statement of the input database based on the parsed data corresponding to the similar existing word sequence or the input word sequence.
  • this statement parsing method can quickly parse database statements, which is beneficial to improve the response speed and work efficiency of the database.
  • the first embodiment can be executed independently of the database language, so that it can be adapted to various database languages, and the applicable scenario is wider; it also provides a more convenient development mode for database developers.
  • the database may also assign a similarity flag to the database statement, the similar statements have the same flag, and the similarity flags of the dissimilar statements are different.
  • the similarity flag is generated when the server inserts a new record into the statement similarity table, and the unique identifier generation rule may be, for example, the following methods: 1) sequentially adding, 2) using a memory address corresponding to the cache value in the similarity hash, and the like.
  • the database can maintain the correspondence between the similarity flag and the parsed data, for example, using an array or a memory address lookup, that is, the parsing flag can uniquely find the parsed data corresponding to the similar sentence.
  • a second embodiment of the present invention provides a database (not shown in the drawing), the database includes a statement parsing unit and a statement similarity table, wherein the statement parsing unit utilizes the method and the statement provided in the first embodiment.
  • the similarity table parses the database statements entered into the database.
  • a third embodiment of the present invention provides another method for parsing a statement for a database statement, which includes the following steps:
  • Step S30 Perform lexical analysis on the database statement input to the client to obtain an input word sequence.
  • Step S31 Find a client statement similarity table according to the input word sequence to determine whether there is an existing word order similar to the input word sequence in the client statement similarity table.
  • the client statement similarity table records various existing word sequences different from each other, and the existing word sequence is obtained by lexical analysis of the database statement.
  • Step S32 If there is an existing word sequence similar to the input word sequence in the client statement similarity table, the client sends a similarity statement parsing request to the database.
  • Step S33 The database searches the database side statement similarity table based on the similarity statement parsing request to determine the parsed data corresponding to the similarity statement parsing request.
  • the database side statement similarity table records the correspondence between the parsing request of the similarity statement and the parsed data, and the parsed data is used by the database to execute the database statement.
  • Step S34 The database executes the database statement for inputting the client segment based on the parsing data corresponding to the similarity statement parsing request.
  • Step S35 The database returns the execution result to the client.
  • the client statement similarity table is in one-to-one correspondence with the database-side statement similarity table and is updated synchronously.
  • the client can send a database statement execution request to the server (database), and the server answers the execution result to the client.
  • the database assigns a similarity flag to the database statement and informs the client of the similarity flag; the similarity statements have the same flag, and the similarity flags of the dissimilar statements are different.
  • the client performs lexical analysis on the database statement, and then locally finds the statement similarity flag. If there is a statement similarity flag corresponding thereto, the statement similarity flag is sent to the server, and the server (database) searches for the corresponding identifier according to the similarity flag.
  • the reusable parsing data is directly applied; if the client does not find the statement similarity flag, the word sequence obtained by the lexical analysis is directly sent to the server, and after receiving the response, the server parses and generates a new sentence similarity. Sign.
  • the above third embodiment is directed to the client/server application scenario, and the lexical analysis and the statement similarity table searching process are distributed to the client for execution, which significantly reduces the workload of the server (database), thereby improving server-side processing.
  • the ability of data is directed to the client/server application scenario, and the lexical analysis and the statement similarity table searching process are distributed to the client for execution, which significantly reduces the workload of the server (database), thereby improving server-side processing.
  • the ability of data is directed to the client/server application scenario, and the lexical analysis and the statement similarity table searching process are distributed to the client for execution, which significantly reduces the workload of the server (database), thereby improving server-side processing.
  • the ability of data is directed to the client/server application scenario, and the lexical analysis and the statement similarity table searching process are distributed to the client for execution, which significantly reduces the workload of the server (database), thereby improving server-side processing.
  • the ability of data is directed to the client/server application scenario, and the lexic
  • a fourth embodiment of the present invention provides a database application system, including: a database server that maintains a database-side statement similarity table; and a plurality of clients each maintaining a client-side statement similarity table.
  • the database application system uses the method provided in the third embodiment to parse and execute the database statement of the input client.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Computational Linguistics (AREA)
  • Software Systems (AREA)
  • Mathematical Physics (AREA)
  • Computing Systems (AREA)
  • Artificial Intelligence (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • General Health & Medical Sciences (AREA)
  • Health & Medical Sciences (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
  • Stored Programmes (AREA)

Abstract

一种用于数据库语句的语句解析方法,包括如下步骤:对输入数据库的数据库语句进行词法分析,以获得输入单词序列;依据输入单词序列来查找语句相似性表,以确定语句相似性表中是否存在与输入单词序列相似的现有单词序列;若语句相似性表中存在与输入单词序列相似的现有单词序列,则从语句相似性表中获得相似的现有单词序列对应的解析数据;否则,对输入单词序列进行解析,以获得输入单词序列对应的解析数据,并且将输入单词序列以及对应的解析数据存入语句相似性表中;以及基于对应于相似的现有单词序列或对应于输入单词序列的解析数据,来执行输入数据库的数据库语句。该方法可以快速解析数据库语句,有利于提升数据库的响应速度、工作效率。

Description

用于数据库语句的语句解析方法 技术领域
本发明涉及数据库技术领域,更具体地说,本发明涉及一种用于数据库语句的语句解析方法。
背景技术
语句解析广泛应用于计算机领域,是人类与计算机交互的基础技术之一,实现了类自然语言向机器语言的翻译,例如XML、SQL、C和JAVA语言等,都是语句解析的重要应用。
一般地,语句解析分为2个阶段:词法分析和语法解析,词法分析用于将语句分割为一组单词序列,而语法解析用于根据单词序列构建语法树或其他内部数据结构,语法解析获得的解析结果会用于后续数据计算。
在数据库领域,一种普遍接受的语言是SQL语言,其语言有一套SQL92语法,而各种数据库产品在该语法标准上由有一些各自特殊的的语法。数据库处理的基本逻辑如下:客户端向数据发送一条SQL语句,服务端对SQL语句进行词法分析,然后进行语法解析转换为计算机内部可执行的数据结构。
由于SQL语句是数据库用户和数据库操作之间的桥梁,其语句复杂度较高,差异较大,所以数据库处理中会有大量数据资源用于SQL语句的解析。而为了降低SQL语句解析的性能开销,数据库领域有2种常用解决方法:1)对相同语句复用SQL解析的结果(一般为 执行计划);2)提供prepare语句,由用户将可变数据用“?”代替,以降低语句的差异数量。通过上述2个方案,可以较好的避免对所有语句进行语法解析,提升了数据库服务器的处理性能。
但是,上述现有方案有如下不足:一、解析的复用度过细,只能对完全相同的语句复用解析结果,导致缓存数据量较大;二、使用”?”替换语句中可变内容的方法,对使用者并不是十分友好。此外,上述现有方案主要针对SQL语言特点来设计,在其他语言解析中难以应用,例如,我们很难要求编程人员使用“?”代替其代码中的可变内容,而这只是为了提高编译器的解析速度。
发明内容
本发明的目的在于提供一种用于数据库语句的语句解析方法,其能够独立于数据库语言种类来应用,可以快速解析数据库语句,进一步提升数据库的响应速度、工作效率。
为实现上述目的,本发明提供一种技术方案如下:
一种用于数据库语句的语句解析方法,包括如下步骤:对输入数据库的数据库语句进行词法分析,以获得输入单词序列;依据输入单词序列来查找语句相似性表,以确定语句相似性表中是否存在与输入单词序列相似的现有单词序列;其中,语句相似性表记录各种彼此不同现有单词序列与解析数据之间的对应关系,现有单词序列通过对数据库语句进行词法分析而得到,解析数据由数据库用来执行数据库语句;若语句相似性表中存在与输入单词序列相似的现有单词序列,则从语句相似性表中获得相似的现有单词序列对应的解析数据;否则, 对输入单词序列进行解析,以获得输入单词序列对应的解析数据,并且将输入单词序列以及对应的解析数据存入语句相似性表中;以及基于对应于相似的现有单词序列或对应于输入单词序列的解析数据,来执行输入数据库的数据库语句。
优选地,语句相似性表还包括一hash子表,hash子表记录各种彼此不同现有单词序列的hash值与解析数据之间的对应关系;其中,从语句相似性表中获得相似的现有单词序列对应的解析数据具体包括:依据相似的现有单词序列对应的hash值来确定对应于相似的现有单词序列的解析数据。
优选地,确定语句相似性表中是否存在与输入单词序列相似的现有单词序列包括:针对语句相似性表中的每一现有单词序列,比较该现有单词序列与输入单词序列各自的经词法分析所得的单词个数以及单词位置,若单词个数以及单词位置均相同,则判定语句相似性表中存在与输入单词序列相似的现有单词序列。
优选地,现有单词序列的hash值基于如下方式来计算:基于对现有单词序列进行词法分析所得的各单词的位置以及hash值,计算现有单词序列的hash值。
本发明还公开一种数据库,包括一语句解析单元以及一语句相似性表,其中,语句解析单元利用上述方法、以及语句相似性表对输入数据库的数据库语句进行解析。
本发明的另一目的在于提供一种用于数据库语句的语句解析方法,其将语句相似性比较工作部分地交予客户端来完成,以降低数据 库的工作负载。
为实现上述目的,本发明提供另一技术方案如下:
一种用于数据库语句的语句解析方法,包括如下步骤:对输入客户端的数据库语句进行词法分析,以获得输入单词序列;依据输入单词序列来查找客户端语句相似性表,以确定客户端语句相似性表中是否存在与输入单词序列相似的现有单词序列;其中,客户端语句相似性表记录各种彼此不同现有单词序列,现有单词序列通过对数据库语句进行词法分析而得到;若客户端语句相似性表中存在与输入单词序列相似的现有单词序列,则客户端向数据库发送相似性语句解析请求;数据库基于相似性语句解析请求来查找数据库端语句相似性表,以确定与相似性语句解析请求对应的解析数据;其中,数据库端语句相似性表记录相似性语句解析请求与解析数据之间的对应关系,解析数据由数据库用来执行数据库语句;数据库基于与相似性语句解析请求对应的解析数据,来执行输入客户段的数据库语句;以及数据库将执行结果返回至客户端;其中,客户端语句相似性表与数据库端语句相似性表一一对应并同步更新。
此外,本发明还公开一种数据库应用系统,包括:数据库服务器,维护一数据库端语句相似性表;以及多个客户端,分别维护一客户端语句相似性表;其中,数据库应用系统利用上述方法来对输入客户端的数据库语句进行解析并执行。
本发明所提供的用于数据库语句的语句解析方法,可以快速解析数据库语句,有利于提升数据库的响应速度、工作效率。其应用场合 广、应用成本低,也便于开发人员更高效地进行数据库开发工作。
附图说明
图1示出本发明第一实施例提供的用于数据库语句的语句解析方法的流程示意图。
图2示出本发明第三实施例提供的用于数据库语句的语句解析方法的流程示意图。
具体实施方式
如图1所示,本发明第一实施例提供一种用于数据库语句的语句解析方法,其包括如下各步骤:
步骤S10、对输入数据库的数据库语句进行词法分析,以获得输入单词序列。
步骤S11、依据输入单词序列来查找语句相似性表,以确定语句相似性表中是否存在与输入单词序列相似的现有单词序列。
其中,语句相似性表记录各种彼此不同现有单词序列与解析数据之间的对应关系,现有单词序列通过对数据库语句进行词法分析而得到,解析数据由数据库用来执行数据库语句。
具体地,例如,以如下3条SQL语句为例:
1:select*from tbl1where a=123;
2:select*from tbl1where a=1;
3:SELECT*FROM tbl1WHERE A=3;
进行词法分析以生成单词序列时,单词一般分为:关键字、变量名和值等部分,且不区分大小写,例如语句1会被解析为类似如下的 单词序列[select,*,from,tbl1,where,a,=,123],其中[select,*,from,where,=]是关键字,[tbl1,a]是变量名,[123]为值。可以发现语句1-3,具有相似的词法序列。
作为优选的实施方式,语句相似性表还包括一hash子表,hash子表记录各种彼此不同现有单词序列的hash值与解析数据之间的对应关系。
其中,现有单词序列的hash值可基于如下方式来计算:基于对现有单词序列进行词法分析所得的各单词的位置以及hash值,计算现有单词序列的hash值;即,现有单词序列的hash值可以是一种加权组合计算得到的值。
具体地,继续以上述3条SQL语句为例,单词序列的hash值的计算方法例如:
1)对数据库语句进行词法分析,得到单词序列;
2)若单词类型为值,则该单词的hash值为固定值(例如1);如果该单词的类型为其他值,则该单词的hash值为对应单词转换为小写字符串的hash值;
3)初始化sql_hash的值(例如sql_hash=7);
4)从头开始顺序遍历各单词,执行如下伪代码,对各单词的hash值进行位移求和:
sql_hash=sql_hash<<3+hash(当前单词)
5)最终sql_hash就是单词序列的hash值。
通过本方法,可以发现上述3条SQL语句1、语句2和语句3的 单词序列hash值是一样的。
在该步骤S11中,具体地,确定语句相似性表中是否存在与输入单词序列相似的现有单词序列可按照如下方式来实现:针对语句相似性表中的每一现有单词序列,比较该现有单词序列与输入单词序列各自的经词法分析所得的单词个数以及单词位置,若单词个数以及单词位置均相同,则判定语句相似性表中存在与输入单词序列相似的现有单词序列。若单词个数不相似或单词位置不相似,则判定不存在与输入单词序列相似的现有单词序列。
为了提供数据库的响应速度,优选地为语句相似性表在数据库的缓存中设置一副本,通过查找缓存中的副本,可以更快速地确定语句相似性表中是否存在与输入单词序列相似的现有单词序列。
步骤S120、若语句相似性表中存在与输入单词序列相似的现有单词序列,则从语句相似性表中获得相似的现有单词序列对应的解析数据。
在语句相似性表还包括hash子表的情况下,相应地,在该步骤中,依据相似的现有单词序列对应的hash值来确定对应于相似的现有单词序列的解析数据。本领域技术人员可以理解,依据hash值,能够促进确定解析数据的效率、以及提升确定解析数据的准确率。
步骤S121,若语句相似性表中不存在与输入单词序列相似的现有单词序列,则对输入单词序列进行解析,以获得输入单词序列对应的解析数据,并且将输入单词序列以及对应的解析数据存入语句相似性表中。
步骤S13、基于对应于相似的现有单词序列或对应于输入单词序列的解析数据,来执行输入数据库的数据库语句。
可以理解,根据本发明上述第一实施例,通过确定语句相似性表中有无与输入单词序列相似的现有单词序列,并在存在相似现有单词序列的情况下,可以快速获得解析数据而直接应用,这种语句解析方法可以快速解析数据库语句,有利于提升数据库的响应速度、工作效率。
此外,该第一实施例能够与数据库语言无关地执行,从而可以适应于各种数据库语言,适用场景更广;其也为数据库开发人员提供了更加便利的开发模式。
作为对上述第一实施例的进一步改进,数据库也可以为数据库语句分配相似性标志,相似语句之间有相同的标志,不相似语句的相似性标志则不同。优选地,相似标志在服务器向语句相似性表中插入新记录时产生,其唯一标识产生规则可以例如采用如下方法:1)依次累加,2)使用相似性hash中缓存值对应的内存地址等。数据库可以维护相似性标志与解析数据之间的对应关系,例如使用数组或内存地址查找等,即通过相识性标志可以唯一地找到对应相似语句的解析数据。
本发明第二实施例提供一种数据库(附图未示出),该数据库包括一语句解析单元以及一语句相似性表,其中,语句解析单元利用上述第一实施例中提供的方法、以及语句相似性表对输入数据库的数据库语句进行解析。
本发明第三实施例提供另一种用于数据库语句的语句解析方法,其包括如下步骤:
步骤S30、对输入客户端的数据库语句进行词法分析,以获得输入单词序列。
步骤S31、依据输入单词序列来查找客户端语句相似性表,以确定客户端语句相似性表中是否存在与输入单词序列相似的现有单词序。
其中,客户端语句相似性表记录各种彼此不同现有单词序列,现有单词序列通过对数据库语句进行词法分析而得到。
步骤S32、若客户端语句相似性表中存在与输入单词序列相似的现有单词序列,则客户端向数据库发送相似性语句解析请求。
步骤S33、数据库基于相似性语句解析请求来查找数据库端语句相似性表,以确定与相似性语句解析请求对应的解析数据。
其中,数据库端语句相似性表记录相似性语句解析请求与解析数据之间的对应关系,解析数据由数据库用来执行数据库语句。
步骤S34、数据库基于与相似性语句解析请求对应的解析数据,来执行输入客户段的数据库语句。
步骤S35、数据库将执行结果返回至客户端。
根据该第三实施例,客户端语句相似性表与数据库端语句相似性表一一对应并同步更新。
作为对上述第三实施例的一种改进方式,客户端可以向服务器(数据库)发送数据库语句执行请求,服务器则向客户端应答执行结 果。数据库为数据库语句分配相似性标志,并将相似性标志告知客户端;相似语句之间有相同的标志,不相似语句的相似性标志则不同。
具体地,客户端对数据库语句进行词法分析,随后,本地查找语句相似性标志,若存在与其对应的语句相似性标志,则发送语句相似性标志到服务器,服务器(数据库)根据相似性标志查找对应的可复用解析数据并直接应用;若客户端未查找到语句相似性标志,则直接发送经词法分析所得的单词序列给服务器,收到应答后,服务器进行解析,并生成新的语句相似性标志。
上述第三实施例针对客户端/服务器的应用场景,将词法分析和语句相似性表的查找过程分散到客户端来执行,这显著降低了服务器(数据库)的工作负载,从而提高了服务器端处理数据的能力。
本发明第四实施例提供一种数据库应用系统,包括:数据库服务器,其维护一数据库端语句相似性表;以及多个客户端,各自分别维护一客户端语句相似性表。其中,数据库应用系统利用上述第三实施例中提供的方法来对输入客户端的数据库语句进行解析并执行。
上述说明仅针对于本发明的优选实施例,并不在于限制本发明的保护范围。本领域技术人员可作出各种变形设计,而不脱离本发明的思想及附随的权利要求。

Claims (8)

  1. 一种用于数据库语句的语句解析方法,包括如下步骤:
    对输入数据库的所述数据库语句进行词法分析,以获得输入单词序列;
    依据所述输入单词序列来查找语句相似性表,以确定所述语句相似性表中是否存在与所述输入单词序列相似的现有单词序列;其中,所述语句相似性表记录各种彼此不同所述现有单词序列与解析数据之间的对应关系,所述现有单词序列通过对所述数据库语句进行词法分析而得到,所述解析数据由所述数据库用来执行所述数据库语句;
    若所述语句相似性表中存在与所述输入单词序列相似的所述现有单词序列,则从所述语句相似性表中获得所述相似的现有单词序列对应的所述解析数据;否则,对所述输入单词序列进行解析,以获得所述输入单词序列对应的所述解析数据,并且将所述输入单词序列以及对应的所述解析数据存入所述语句相似性表中;以及
    基于对应于所述相似的现有单词序列或对应于所述输入单词序列的所述解析数据,来执行所述输入数据库的所述数据库语句。
  2. 根据权利要求1所述的方法,其特征在于,所述语句相似性表还包括一hash子表,所述hash子表记录各种彼此不同所述现有单词序列的hash值与所述解析数据之间的对应关系;
    其中,从所述语句相似性表中获得所述相似的现有单词序列对应的所述解析数据具体包括:依据所述相似的现有单词序列对应的hash 值来确定对应于所述相似的现有单词序列的所述解析数据。
  3. 根据权利要求1所述的方法,其特征在于,确定所述语句相似性表中是否存在与所述输入单词序列相似的现有单词序列包括:
    针对所述语句相似性表中的每一所述现有单词序列,比较该现有单词序列与所述输入单词序列各自的经词法分析所得的单词个数以及单词位置,若所述单词个数以及单词位置均相同,则判定所述所述语句相似性表中存在与所述输入单词序列相似的所述现有单词序列。
  4. 根据权利要求2所述的方法,其特征在于,所述现有单词序列的hash值基于如下方式来计算:
    基于对所述现有单词序列进行词法分析所得的各单词的位置以及hash值,计算所述现有单词序列的hash值。
  5. 根据权利要求1所述的方法,其特征在于,所述语句相似性表在所述数据库的缓存中设置一副本。
  6. 一种数据库,包括一语句解析单元以及一语句相似性表,其特征在于,所述语句解析单元利用如权利要求1-5中任一项所述的方法、以及所述语句相似性表对输入所述数据库的数据库语句进行解析。
  7. 一种用于数据库语句的语句解析方法,包括如下步骤:
    对输入客户端的所述数据库语句进行词法分析,以获得输入单词序列;
    依据所述输入单词序列来查找客户端语句相似性表,以确定所述客户端语句相似性表中是否存在与所述输入单词序列相似的现有单词序列;其中,所述客户端语句相似性表记录各种彼此不同所述现有 单词序列,所述现有单词序列通过对所述数据库语句进行词法分析而得到;
    若所述客户端语句相似性表中存在与所述输入单词序列相似的所述现有单词序列,则所述客户端向数据库发送相似性语句解析请求;
    所述数据库基于所述相似性语句解析请求来查找数据库端语句相似性表,以确定与所述相似性语句解析请求对应的解析数据;其中,所述数据库端语句相似性表记录所述相似性语句解析请求与所述解析数据之间的对应关系,所述解析数据由所述数据库用来执行所述数据库语句;
    所述数据库基于与所述相似性语句解析请求对应的所述解析数据,来执行所述输入客户段的所述数据库语句;以及
    所述数据库将执行结果返回至所述客户端;
    其中,所述客户端语句相似性表与所述数据库端语句相似性表一一对应并同步更新。
  8. 一种数据库应用系统,包括:
    数据库服务器,维护一数据库端语句相似性表;以及
    多个客户端,分别维护一客户端语句相似性表;
    其中,所述数据库应用系统利用如权利要求7所述的方法来对输入所述客户端的数据库语句进行解析并执行。
PCT/CN2018/071916 2017-01-16 2018-01-09 用于数据库语句的语句解析方法 Ceased WO2018130142A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP18739262.6A EP3570190A4 (en) 2017-01-16 2018-01-09 DECLARATION ANALYSIS PROCESS FOR A DATABASE REPORTING
US16/478,275 US10896180B2 (en) 2017-01-16 2018-01-09 Statement parsing method for database statement

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201710029732.7A CN107025263A (zh) 2017-01-16 2017-01-16 用于数据库语句的语句解析方法
CN201710029732.7 2017-01-16

Publications (1)

Publication Number Publication Date
WO2018130142A1 true WO2018130142A1 (zh) 2018-07-19

Family

ID=59526081

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2018/071916 Ceased WO2018130142A1 (zh) 2017-01-16 2018-01-09 用于数据库语句的语句解析方法

Country Status (4)

Country Link
US (1) US10896180B2 (zh)
EP (1) EP3570190A4 (zh)
CN (2) CN107025263A (zh)
WO (1) WO2018130142A1 (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117971862A (zh) * 2024-01-12 2024-05-03 山东浪潮科学研究院有限公司 一种异构关系型数据库统一sql处理办法及装置

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107025263A (zh) * 2017-01-16 2017-08-08 中国银联股份有限公司 用于数据库语句的语句解析方法
CN111614651A (zh) * 2020-05-14 2020-09-01 南京艾科朗克信息科技有限公司 一种基于fpga的低延迟tds协议解析的方法
CN111881094B (zh) * 2020-07-28 2023-07-18 平安科技(深圳)有限公司 日志中关键信息提取方法、装置、终端及存储介质
CN112612810A (zh) * 2020-12-23 2021-04-06 贝壳技术有限公司 慢sql语句识别方法及系统
CN113448982A (zh) * 2021-06-30 2021-09-28 未鲲(上海)科技服务有限公司 Ddl语句的解析方法、装置、计算机设备及存储介质
CN116304231B (zh) * 2023-04-07 2026-04-21 平安科技(深圳)有限公司 基于语法解析树的查询语句生成方法和装置、设备、介质
CN117539895B (zh) * 2023-11-14 2025-08-26 中电金信软件有限公司 一种查询语句相似度的确定方法、执行方法及装置

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100262604A1 (en) * 2009-04-13 2010-10-14 Fujitsu Limited Database message analysis support technique
CN104123354A (zh) * 2014-07-15 2014-10-29 大连大学 一种基于MySQL数据库的查询优化方法
CN105373607A (zh) * 2015-11-13 2016-03-02 国网智能电网研究院 一种电力业务系统sql访问日志压缩方法
CN105718593A (zh) * 2016-01-28 2016-06-29 长春师范大学 一种数据库查询优化方法及系统
CN107025263A (zh) * 2017-01-16 2017-08-08 中国银联股份有限公司 用于数据库语句的语句解析方法

Family Cites Families (16)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6115703A (en) * 1998-05-11 2000-09-05 International Business Machines Corporation Two-level caching system for prepared SQL statements in a relational database management system
US6985904B1 (en) * 2002-02-28 2006-01-10 Oracle International Corporation Systems and methods for sharing of execution plans for similar database statements
CA2382714A1 (en) * 2002-04-19 2003-10-19 Ibm Canada Limited-Ibm Canada Limitee Substituting parameter markers for literals in a database query language statement to promote reuse of previously generated access plans
US7337226B2 (en) * 2002-05-10 2008-02-26 Oracle International Corporation Method and mechanism for implementing dynamic sizing of session pools
US7174326B2 (en) * 2003-07-17 2007-02-06 Sybase, Inc. Database system providing methodology for prepared statement cloning
EP1999565A4 (en) * 2006-03-03 2012-01-11 Perfect Search Corp HYPER SPACE INDEX
US7702623B2 (en) * 2007-07-31 2010-04-20 Oracle International Corporation Extended cursor sharing
US20100257181A1 (en) * 2009-04-01 2010-10-07 Sybase, Inc. Dynamic Hash Table for Efficient Data Access In A Relational Database System
CN101567006B (zh) * 2009-05-25 2012-07-04 中兴通讯股份有限公司 一种数据库系统及分布式sql语句执行计划重用方法
US20100325136A1 (en) * 2009-06-23 2010-12-23 Microsoft Corporation Error tolerant autocompletion
US8732660B2 (en) * 2011-02-02 2014-05-20 Novell, Inc. User input auto-completion
CN102760143A (zh) * 2011-04-28 2012-10-31 国际商业机器公司 一种在数据库系统中动态整合执行结构的方法和装置
CN102945256B (zh) * 2012-10-18 2016-02-03 福建省海峡信息技术有限公司 海量sql语句合并归类的方法及装置
US10083205B2 (en) * 2014-02-12 2018-09-25 Samsung Electronics Co., Ltd. Query cards
US10129256B2 (en) * 2015-01-08 2018-11-13 BlueTalon, Inc. Distributed storage and distributed processing query statement reconstruction in accordance with a policy
US20160342646A1 (en) * 2015-05-20 2016-11-24 International Business Machines Corporation Database query cursor management

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20100262604A1 (en) * 2009-04-13 2010-10-14 Fujitsu Limited Database message analysis support technique
CN104123354A (zh) * 2014-07-15 2014-10-29 大连大学 一种基于MySQL数据库的查询优化方法
CN105373607A (zh) * 2015-11-13 2016-03-02 国网智能电网研究院 一种电力业务系统sql访问日志压缩方法
CN105718593A (zh) * 2016-01-28 2016-06-29 长春师范大学 一种数据库查询优化方法及系统
CN107025263A (zh) * 2017-01-16 2017-08-08 中国银联股份有限公司 用于数据库语句的语句解析方法

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117971862A (zh) * 2024-01-12 2024-05-03 山东浪潮科学研究院有限公司 一种异构关系型数据库统一sql处理办法及装置

Also Published As

Publication number Publication date
US10896180B2 (en) 2021-01-19
CN119719139A (zh) 2025-03-28
US20190361899A1 (en) 2019-11-28
EP3570190A4 (en) 2020-07-29
EP3570190A1 (en) 2019-11-20
CN107025263A (zh) 2017-08-08

Similar Documents

Publication Publication Date Title
WO2018130142A1 (zh) 用于数据库语句的语句解析方法
CN114756569B (zh) 结构化查询语句的多层解析方法、计算机设备及存储介质
KR102407510B1 (ko) 데이터 저장 및 조회 방법, 장치, 기기 및 매체
CN112015722B (zh) 数据库管理方法、数据血缘分析方法以及相关装置
US10866971B2 (en) Hash collision tables for relational operations
US6466931B1 (en) Method and system for transparently caching and reusing query execution plans efficiently
US9177021B2 (en) Relational query planning for non-relational data sources
US8219581B2 (en) Method and system for analyzing ordered data using pattern matching in a relational database
US7822710B1 (en) System and method for data collection
ten Wolde et al. DuckPGQ: Efficient Property Graph Queries in an analytical RDBMS.
JP7105982B2 (ja) 構造化レコード取得
US20130254193A1 (en) Distance in Contextual Network Graph
CN113515285B (zh) 生成实时计算逻辑数据的方法和装置
JP2018067279A (ja) データプロパティ認識のための装置、プログラム、及び方法
US20190213007A1 (en) Method and device for executing the distributed computation task
US7970757B2 (en) Computer program product for database query optimization
US11188594B2 (en) Wildcard searches using numeric string hash
CN118503367A (zh) 以语义关系图谱为驱动的跨端点rdf数据语义检索方法及系统
CN110069489B (zh) 一种信息处理方法、装置、设备及计算机可读存储介质
US20170132289A1 (en) Database entity analysis
US8478793B2 (en) Virtual pair algorithm for outer join resolution
CN119782343B (zh) 一种查询的优化执行方法及装置
US12475124B1 (en) Dictionary sharing for efficient join operation in column store
CN111125216B (zh) 数据导入Phoenix的方法及装置
KR20170088466A (ko) 그래프 데이터에 대한 부분 매칭 시스템

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: 18739262

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

WWE Wipo information: entry into national phase

Ref document number: 2018739262

Country of ref document: EP