CN114356959A - SQL (structured query language) analysis method and device based on multiple tenants, computer equipment and storage medium - Google Patents

SQL (structured query language) analysis method and device based on multiple tenants, computer equipment and storage medium Download PDF

Info

Publication number
CN114356959A
CN114356959A CN202111531521.6A CN202111531521A CN114356959A CN 114356959 A CN114356959 A CN 114356959A CN 202111531521 A CN202111531521 A CN 202111531521A CN 114356959 A CN114356959 A CN 114356959A
Authority
CN
China
Prior art keywords
sql
tenant
syntax tree
matching
tree
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111531521.6A
Other languages
Chinese (zh)
Inventor
麦韬
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huameng Technology Consulting Shenzhen Co ltd
Original Assignee
Huameng Technology Consulting Shenzhen 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 Huameng Technology Consulting Shenzhen Co ltd filed Critical Huameng Technology Consulting Shenzhen Co ltd
Priority to CN202111531521.6A priority Critical patent/CN114356959A/en
Publication of CN114356959A publication Critical patent/CN114356959A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application relates to the field of artificial intelligence, and discloses a SQL (structured query language) analysis method, a device, computer equipment and a storage medium based on multiple tenants, wherein the method comprises the steps of receiving executive personnel information and a task set to be allocated; sequencing the tasks to be distributed according to the resource values corresponding to the tasks to be distributed in the task set to be distributed; based on the images of the executive personnel in the executive personnel information and the resource values corresponding to the tasks to be distributed, utilizing a difference distribution algorithm to pre-distribute the sequenced tasks to be distributed to the executive personnel in sequence; verifying by using a judgment engine according to the portrait of each executive worker and the pre-distributed tasks to be distributed; when the verification is passed, SQL analysis based on multiple tenants is carried out according to tasks to be distributed pre-distributed by each executive; this application improves production and operation efficiency.

Description

SQL (structured query language) analysis method and device based on multiple tenants, computer equipment and storage medium
Technical Field
The present application relates to the field of artificial intelligence, and in particular, to a method and an apparatus for SQL analysis based on multiple tenants, a computer device, and a storage medium.
Background
With the continuous development of enterprises, when business expansion of an enterprise is fast and users are many, the enterprise will face pressure of excessive data acceleration, and tenants need to be divided for the users. The data of the users are distributed into different isolation spaces by dividing into multiple tenants, and the data of the users are isolated from each other by certain isolation standards, so that safer services are provided.
In the traditional multi-tenant security technology, a database or a table is isolated by using simple and rough SQL sentences, and the corresponding database needs to be continuously connected for multi-tenant identification. Therefore, the difficulty in managing a plurality of data sources is increased, excessive space waste is caused, even if the database instance is directly controlled improperly, the database is subjected to addition, deletion, modification and check, information inconsistency among a plurality of tenants of the database is caused, and troubles in production and operation are caused. Therefore, how to process the SQL statement and improve the efficiency of production and operation becomes an urgent problem to be solved.
Disclosure of Invention
The application provides a multi-tenant-based SQL analysis method and device, computer equipment and a storage medium, and aims to solve the problem of difficult management caused by the fact that SQL sentences are used for directly isolating a database in the prior art.
In order to solve the above problem, the present application provides a SQL parsing method based on multiple tenants, including:
receiving a processing instruction;
intercepting SQL sentences in the system through an interceptor based on the processing instruction;
constructing the SQL statement by using an abstract syntax tree algorithm to obtain a corresponding syntax tree;
acquiring an SQL request, and matching the SQL request with a syntax tree by using a character string matching algorithm;
and acquiring corresponding data according to the matching result.
Further, the constructing the SQL statement to obtain the corresponding syntax tree by using an abstract syntax tree algorithm includes:
according to the abstract syntax tree algorithm, performing lexical analysis on the SQL statement to obtain a corresponding array;
and carrying out syntactic analysis on the array through the abstract syntactic tree algorithm, and converting the array into a tree shape so as to obtain the syntactic tree.
Further, the matching the SQL request with the syntax tree using a string matching algorithm includes:
constructing a corresponding key tree by using each key data according to each key data in the syntax tree;
and obtaining a key tree corresponding to the SQL request type according to the SQL request type, and matching the SQL request with the key tree corresponding to the SQL request type.
Further, the matching the SQL request with the syntax tree using a string matching algorithm includes:
according to the tenant IDs under the key data in the syntax tree, constructing a tenant ID tree from top to bottom in the order of the number of digits of the tenant IDs;
extracting the ID of the tenant to be processed in the SQL request;
and matching the tenant ID to be processed with the tenant ID tree through a character string matching algorithm.
Further, before the constructing the SQL statement to obtain the corresponding syntax tree by using the abstract syntax tree algorithm, the method further includes:
and judging whether the SQL statement is safe or not by using a preset condition, and if not, not processing the SQL statement.
Further, the intercepting, by the interceptor, the SQL statement in the system includes:
identifying SQL sentences in the system according to a preset regular expression in the interceptor;
and intercepting the SQL statement after the SQL statement is identified.
Further, the intercepting, by the interceptor, the SQL statement in the system includes:
acquiring a dynamic configuration table and a field from a database;
and intercepting all the SQL sentences in the system by dynamically configuring tables and fields by the interceptor.
In order to solve the above problem, the present application further provides a multi-tenant based SQL parsing apparatus, where the apparatus includes:
the receiving module is used for receiving a processing instruction;
the interception module is used for intercepting SQL sentences in the system through an interceptor based on the processing instruction;
the building module is used for building the SQL statement to obtain a corresponding syntax tree by using an abstract syntax tree algorithm;
the matching module is used for acquiring the SQL request and matching the SQL request with the syntax tree by using a character string matching algorithm;
and the acquisition module is used for acquiring corresponding data according to the matching result.
In order to solve the above problem, the present application also provides a computer device, including:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the multi-tenant based SQL parsing method as described above.
To solve the above problem, the present application also provides a non-transitory computer-readable storage medium having stored thereon computer-readable instructions that, when executed by a processor, implement the multi-tenant based SQL parsing method as described above.
Compared with the prior art, the SQL analyzing method, the SQL analyzing device, the computer equipment and the storage medium based on the multi-tenant provided by the embodiment of the application have the following beneficial effects:
intercepting SQL statements in a system through an interceptor based on a processing instruction by receiving the processing instruction; the method comprises the steps of extracting all SQL sentences, constructing the SQL sentences by using an abstract syntax tree algorithm to obtain a corresponding syntax tree, constructing syntax relations of all the SQL sentences, matching the SQL requests with the syntax tree by using a character string matching algorithm through obtaining the SQL requests, and obtaining corresponding data according to matching results, so that the SQL sentences are quickly analyzed, the efficiency of judging tenant data sources is improved according to the SQL requests, and the production and operation efficiency is improved.
Drawings
In order to more clearly illustrate the solution of the present application, a brief description will be given below of the drawings required for describing the embodiments of the present application, and it is obvious that the drawings in the following description are some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings without inventive effort.
Fig. 1 is a schematic flowchart of a multi-tenant-based SQL parsing method according to an embodiment of the present application;
FIG. 2 is a flowchart of one embodiment of step S3 of FIG. 1;
FIG. 3 is a flowchart of one embodiment of step S4 of FIG. 1;
fig. 4 is a schematic diagram of a tenant ID tree according to an embodiment of the present application.
Fig. 5 is a schematic block diagram of a multi-tenant-based SQL parsing apparatus according to an embodiment of the present application;
fig. 6 is a schematic structural diagram of a computer device according to an embodiment of the present application.
Detailed Description
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs; the terminology used in the description of the application herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application; the terms "including" and "having," and any variations thereof, in the description and claims of this application and the description of the above figures are intended to cover non-exclusive inclusions. The terms "first," "second," and the like in the description and claims of this application or in the above-described drawings are used for distinguishing between different objects and not for describing a particular order.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the application. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. One skilled in the art will explicitly or implicitly appreciate that the embodiments described herein can be combined with other embodiments.
The application provides a SQL analysis method based on multiple tenants. Referring to fig. 1, fig. 1 is a schematic flowchart of a multi-tenant based SQL parsing method according to an embodiment of the present application.
In this embodiment, the SQL parsing method based on multiple tenants includes:
s1, receiving a processing instruction;
in the present application, a processing instruction sent by the front end is received, and the processing instruction can be understood as being triggered by a user clicking a specific button on the front end or inputting a specific language. And sending the processing instruction to a server side.
S2, intercepting SQL statements in the system through an interceptor based on the processing instruction;
specifically, according to a received processing instruction, an SQL statement in the system is intercepted by an interceptor, further, the interceptor may be mybatis, which is a persistent layer framework based on Java and supports customized SQL, stored procedures, and advanced mapping, while the system is SAAS (Software-as-a-Service), which means Software as a Service, that is, a Software Service is provided through a network, and there are a large number of SQL statements in the SAAS. All SQL statements in the SAAS system are intercepted by a mybatis interceptor.
The method comprises the steps of intercepting SQL by an interceptor, applying codes to projects in a low-intrusion mode, and particularly applying codes to current micro-services in an intercepting mode for sharing a plurality of services.
The system service executes the SQL, the SQL is intercepted firstly at a mybatis interceptor, the information of the current system service is acquired, the intercepted data source is acquired, the complete SQL statement to be executed is acquired, a filtering rule can be set to record the SQL statement information before the SQL statement is executed, and the abnormal SQL statement is captured and recorded, so that the whole execution is not influenced. The SQL sentences to be executed are further acquired from the data source by acquiring the source database of the SQL sentences.
Furthermore, the data source of the SQL statement can be changed, and SQL is executed on the new data source, so that the execution of the redirection library is achieved.
SQL interception and analysis and key value extraction for service judgment belong to time-consuming operation. So is asynchronous queue processing. SQL rules need to be formulated according to business changes of companies, and the SQL analysis and extraction rules are dynamically configured.
SQL rule configuration implementation:
all the intercepted SQL can be stored in a Mongo database, the rules are analyzed and extracted for multi-tenant configuration, and the rules which are in line with the multi-tenant configuration rules are displayed for multi-tenant data security monitoring and subsequent processing.
Further, the intercepting, by the interceptor, the SQL statement in the system includes:
identifying SQL sentences in the system according to a preset regular expression in the interceptor;
and intercepting the SQL statement after the SQL statement is identified.
In this embodiment, the SQL statement in the SAAS system may be identified by presetting a regular expression in the interceptor, and after the SQL statement is identified, the SQL statement is intercepted, that is, extracted to a fixed location for storage, because the SQL statement often includes: keywords such as select, from, where, and, or, join, etc. can be well extracted from the SQL statement by using the regular expression.
The SQL sentences are extracted by utilizing the preset regular expression, so that all the SQL sentences in the system can be preferably extracted.
Further, the intercepting, by the interceptor, the SQL statement in the system includes:
acquiring a dynamic configuration table and a field from a database;
and intercepting all the SQL sentences in the system by dynamically configuring tables and fields by the interceptor.
Specifically, the interception of the SQL statement may further obtain the tables and the fields of the dynamic configuration from the database, load the tables and the fields of the dynamic configuration into the memory before the SQL interception, and support the dynamic modification of the tables and the fields. Before interception, a corresponding table and a corresponding field are acquired from a memory, and if the table and the field are matched, the corresponding rule is used for processing.
In the multi-tenant, part of tables and fields are not required to be distinguished and are shared by the multi-tenant, and when the part of SQL statements is intercepted, the tables and the fields are obtained from the memory and then processed according to the corresponding multi-tenant rules.
The SQL statement is intercepted according to the dynamic configuration table and the field, so that the SQL statement can be intercepted more accurately.
S3, constructing the SQL statement to obtain a corresponding syntax tree by using an abstract syntax tree algorithm;
specifically, after all SQL statements in the system are obtained, the syntax tree is constructed through processing of an abstract syntax tree algorithm. And performing lexical analysis and syntactic analysis processing on the SQL statement according to the abstract syntax tree algorithm to finally obtain a syntax tree.
Further, as shown in fig. 2, the constructing the SQL statement to obtain the corresponding syntax tree by using the abstract syntax tree algorithm includes:
according to the abstract syntax tree algorithm, performing lexical analysis on the SQL statement to obtain a corresponding array;
and carrying out syntactic analysis on the array through the abstract syntactic tree algorithm, and converting the array into a tree shape so as to obtain the syntactic tree.
Specifically, the first step: lexical analysis
The complete SQL is read and then merged into individual identifications according to a preset rule, meanwhile, blank symbols and comments are removed, and meaningful logic units, keywords, numbers, function names and the like are identified. After processing, the entire SQL is partitioned into a list of arrays.
Such as: select from table where _ id is 1 and column is 2;
in the example, the annotation line # or- - -is determined, the special space and characters t, \\ n, \ r are determined, and filtered out, by lexical analysis. Acquiring corresponding types, SQL keywords, SQL word types, SQL offSet, word lengths { "type": key "," value ": Select", "offSet": "0", "length": "6"}
The second step is that: syntactic analysis
And after the complete lexical analysis, judging 1 an output field (after the keyword Select) of the query according to a result of the lexical analysis, namely an array. 2. The table of the query (after the keyword From). 3. Filtration conditions (after where). And constructing an AST syntax tree according to the where condition, and combining the recognized words into meaningful sentences. As in the above example, the final nodes { "ent _ id", type, value }, { "column", type, value } of the syntax tree are identified, labeled and constructed based on regular expressions.
By constructing the syntax tree of all SQL sentences by using the abstract syntax tree algorithm, the subsequent matching can be quickly performed conveniently.
Further, before the constructing the SQL statement to obtain the corresponding syntax tree by using the abstract syntax tree algorithm, the method further includes:
and judging whether the SQL statement is safe or not by using a preset condition, and if not, not processing the SQL statement.
Specifically, whether each SQL statement is safe is judged according to preset conditions, and the preset conditions are factors of multiple tenants and include identifiers of the multiple tenants.
Whether the SQL sentence is safe or not is judged through preset conditions, if not, the subsequent flow cannot be executed, and the execution safety is improved.
S4, acquiring the SQL request, and matching the SQL request with the syntax tree by using a character string matching algorithm;
specifically, after the syntax tree is constructed, the tree is searched and matched on the basis, and the SQL information can be acquired more quickly.
For example, when the SQL request input by the user is obtained, the SQL request is matched with the syntax tree by using a string matching algorithm.
Further, as shown in fig. 3, the matching the SQL request with the syntax tree by using the string matching algorithm includes:
constructing a corresponding key tree by using each key data according to each key data in the syntax tree;
and obtaining a key tree corresponding to the SQL request type according to the SQL request type, and matching the SQL request with the key tree corresponding to the SQL request type.
Specifically, each key data in the syntax tree may be split, a key tree corresponding to doo is constructed by using each key data, a key tree corresponding to the SQL request type is obtained subsequently according to the SQL request type, and the SQL request is matched with the key tree corresponding to the SQL request, so as to obtain data corresponding to the SQL request.
For example, the existing test main string data abcdeaabcdefg is obtained from a syntax tree; and testing the substring abcdef, obtaining from the SQL request, comparing the main string and the substring in the first round, comparing the character strings, and failing matching when the character strings are unequal. The sub-string needs to continue moving backwards. The number of backward shift bits is determined by matching unequal characters. The rule of matching is to return the place one bit after the prefix corresponding to the longest common prefix-prefix before the mismatch bit. In this example, f does not match a, and f is preceded by a string abcde, which is about c, i.e. the longest common prefix is ab, and the beginning of the next comparison on that side is c, which is one bit after the prefix ab.
In the multi-tenant application, SQL is quickly matched through a character string matching and word segmentation analysis algorithm, the characteristic value of the multi-tenant is quickly obtained, and the characteristic value is provided for multi-tenant distinguishing and business processing.
The syntax tree is re-split to obtain a corresponding key tree, and matching is performed according to the key tree and the SQL request, so that the matching efficiency is further improved.
Further, the matching the SQL request with the syntax tree using a string matching algorithm includes:
according to the tenant IDs under the key data in the syntax tree, constructing a tenant ID tree from top to bottom in the order of the number of digits of the tenant IDs;
extracting the ID of the tenant to be processed in the SQL request;
and matching the tenant ID to be processed with the tenant ID tree through a character string matching algorithm.
Specifically, as shown in fig. 4, taking the tenant ID under the key data in the syntax tree as an example, according to the tenant ID under the key data in the syntax tree, the tenant ID tree is constructed from top to bottom in the order of the number of digits of the tenant ID; for example, because the 3 tenant IDs are sequentially based on ent _ ID 2108, ent _ ID 2145, and ent _ ID 8808, as shown in fig. 4, the first row is 2,8 (the same number is merged into one node), and the second row is 1, 8; the third row is 0,4,0 (since the last node belongs to a different branch, the same numbers cannot be merged); row 4 is 8,5, 8.
When a specific character string is queried, starting from the first character, the character strings are continuously searched according to the sequence of searching the characters in the character strings until the path exists and returns the corresponding value.
When a character string '2145' is searched, a branch at the beginning of 2 is found from an array of a root node, then a branch at the beginning of 1 is found from the node 2, and thus continuous downward search is carried out, when the length of the branch which we walk through is equal to the length of the 2145 character string, whether the value of the last character node is empty is judged, if yes, the character node is not hit, and if not, the character string exists.
By matching the tenant ID, the data of processing the tenant ID corresponding to the SQL request is obtained, and the matching efficiency is improved.
And S5, acquiring corresponding data according to the matching result.
Intercepting SQL statements in a system through an interceptor based on a processing instruction by receiving the processing instruction; the method comprises the steps of extracting all SQL sentences, constructing the SQL sentences by using an abstract syntax tree algorithm to obtain a corresponding syntax tree, constructing syntax relations of all the SQL sentences, matching the SQL requests with the syntax tree by using a character string matching algorithm through obtaining the SQL requests, and obtaining corresponding data according to matching results, so that the SQL sentences are quickly analyzed, the efficiency of judging tenant data sources is improved according to the SQL requests, and the production and operation efficiency is improved.
The embodiment of the application can acquire and process related data based on an artificial intelligence technology. Among them, Artificial Intelligence (AI) is a theory, method, technique and application system that simulates, extends and expands human Intelligence using a digital computer or a machine controlled by a digital computer, senses the environment, acquires knowledge and uses the knowledge to obtain the best result.
The artificial intelligence infrastructure generally includes technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technologies, operation/interaction systems, mechatronics, and the like. The artificial intelligence software technology mainly comprises a computer vision technology, a robot technology, a biological recognition technology, a voice processing technology, a natural language processing technology, machine learning/deep learning and the like.
The present embodiment further provides a multi-tenant based SQL parsing apparatus, which is a functional block diagram of the multi-tenant based SQL parsing apparatus according to the present application, as shown in fig. 5.
The multi-tenant based SQL parsing apparatus 100 according to the present application may be installed in an electronic device. According to the implemented functions, the multi-tenant based SQL parsing apparatus 100 may include a receiving module 101, an intercepting module 102, a constructing module 103, a matching module 104, and an obtaining module 105. A module, which may also be referred to as a unit in this application, refers to a series of computer program segments that can be executed by a processor of an electronic device and that can perform a fixed function, and that are stored in a memory of the electronic device.
In the present embodiment, the functions regarding the respective modules/units are as follows:
a receiving module 101, configured to receive a processing instruction;
the interception module 102 is configured to intercept, based on the processing instruction, an SQL statement in the system by an interceptor;
further, the intercepting module 102 includes an identifying sub-module and a first intercepting sub-module;
the identification submodule is used for identifying SQL sentences in the system according to a preset regular expression in the interceptor;
the first interception submodule is used for intercepting the SQL statement after the SQL statement is identified.
Through the matching of the recognition submodule and the first interception submodule, the SQL sentences are extracted by using the preset regular expression, and all the SQL sentences in the system can be preferably extracted.
Further, the intercepting module 102 includes an extracting sub-module and a second intercepting sub-module;
the first extraction submodule is used for acquiring a dynamic configuration table and a field from a database;
and the second interception submodule is used for intercepting all the SQL statements in the system by dynamically configuring tables and fields through the interceptor.
The SQL sentences are intercepted according to the dynamic configuration table and the fields by matching the extraction sub-module and the second interception sub-module, and the SQL sentences can be intercepted more accurately.
The building module 103 is configured to build the SQL statement to obtain a corresponding syntax tree by using an abstract syntax tree algorithm;
further, the building module 103 includes a lexical analysis submodule and a syntax analysis submodule;
the lexical analysis submodule is used for carrying out lexical analysis on the SQL statement according to the abstract syntax tree algorithm to obtain a corresponding array;
and the syntax analysis submodule is used for carrying out syntax analysis on the array through the abstract syntax tree algorithm and converting the array into a tree shape so as to obtain the syntax tree.
Through the matching of the lexical analysis submodule and the syntax analysis submodule, the abstract syntax tree algorithm is utilized to construct syntax trees of all SQL sentences, and subsequent matching can be performed quickly.
Further, the multi-tenant-based SQL parsing apparatus 100 further includes a security judgment module;
and the safety judgment module is used for judging whether the SQL statement is safe or not by using a preset condition, and if not, the SQL statement is not processed.
Through the cooperation of the safety judgment module, whether the SQL sentence is safe or not is judged through the preset condition, if not, the subsequent flow cannot be executed, and the execution safety is improved.
The matching module 104 is used for acquiring the SQL request and matching the SQL request with the syntax tree by using a character string matching algorithm;
further, the matching module 104 includes a key tree construction sub-module and a first matching sub-module;
the key tree construction submodule is used for constructing and obtaining a corresponding key tree by utilizing each key data according to each key data in the syntax tree;
the first matching sub-module is used for acquiring a key tree corresponding to the SQL request type according to the SQL request type and matching the SQL request with the key tree corresponding to the SQL request type.
Through the matching of the key tree construction sub-module and the first matching sub-module, the syntax tree is re-split, a corresponding key tree is obtained, and matching is performed according to the key tree and the SQL request, so that the matching efficiency is further improved.
Further, the matching module 104 includes a tenant ID tree construction sub-module, a second extraction sub-module, and a second matching sub-module;
the tenant ID tree construction sub-module is used for constructing a tenant ID tree from top to bottom according to the tenant IDs under the key data in the syntax tree in the order of the number of digits of the tenant IDs;
the second extraction submodule is used for extracting the tenant ID to be processed in the SQL request;
and the second matching submodule is used for matching the tenant ID to be processed with the tenant ID tree through a character string matching algorithm.
Through the cooperation of the tenant ID tree construction sub-module, the second extraction sub-module and the second matching sub-module, the tenant IDs are matched, data for processing the tenant IDs corresponding to the SQL request are obtained, and the matching efficiency is improved.
And an obtaining module 105, configured to obtain corresponding data according to the matching result.
By adopting the device, the SQL parsing device 100 based on multiple tenants intercepts SQL statements in a system through an interceptor by receiving a processing instruction and based on the processing instruction through the cooperative use of the receiving module 101, the intercepting module 102, the constructing module 103, the matching module 104, and the obtaining module 105; the method comprises the steps of extracting all SQL sentences, constructing the SQL sentences by using an abstract syntax tree algorithm to obtain a corresponding syntax tree, constructing syntax relations of all the SQL sentences, matching the SQL requests with the syntax tree by using a character string matching algorithm through obtaining the SQL requests, and obtaining corresponding data according to matching results, so that the SQL sentences are quickly analyzed, the efficiency of judging tenant data sources is improved according to the SQL requests, and the production and operation efficiency is improved.
The embodiment of the application also provides computer equipment. Referring to fig. 6, fig. 6 is a block diagram of a basic structure of a computer device according to the present embodiment.
The computer device 4 comprises a memory 41, a processor 42, a network interface 43 communicatively connected to each other via a system bus. It is noted that only computer device 4 having components 41-43 is shown, but it is understood that not all of the shown components are required to be implemented, and that more or fewer components may be implemented instead. As will be understood by those skilled in the art, the computer device is a device capable of automatically performing numerical calculation and/or information processing according to a preset or stored instruction, and the hardware includes, but is not limited to, a microprocessor, an Application Specific Integrated Circuit (ASIC), a Programmable Gate Array (FPGA), a Digital Signal Processor (DSP), an embedded device, and the like.
The computer device can be a desktop computer, a notebook, a palm computer, a cloud server and other computing devices. The computer equipment can carry out man-machine interaction with a user through a keyboard, a mouse, a remote controller, a touch panel or voice control equipment and the like.
The memory 41 includes at least one type of readable storage medium including a flash memory, a hard disk, a multimedia card, a card type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Read Only Memory (ROM), an Electrically Erasable Programmable Read Only Memory (EEPROM), a Programmable Read Only Memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the memory 41 may be an internal storage unit of the computer device 4, such as a hard disk or a memory of the computer device 4. In other embodiments, the memory 41 may also be an external storage device of the computer device 4, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on the computer device 4. Of course, the memory 41 may also include both internal and external storage devices of the computer device 4. In this embodiment, the memory 41 is generally used for storing an operating system and various application software installed on the computer device 4, such as computer readable instructions of the multi-tenant based SQL parsing method. Further, the memory 41 may also be used to temporarily store various types of data that have been output or are to be output.
The processor 42 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor, or other data Processing chip in some embodiments. The processor 42 is typically used to control the overall operation of the computer device 4. In this embodiment, the processor 42 is configured to execute the computer readable instructions or process data stored in the memory 41, for example, execute the computer readable instructions of the multi-tenant based SQL parsing method.
The network interface 43 may comprise a wireless network interface or a wired network interface, and the network interface 43 is generally used for establishing communication connection between the computer device 4 and other electronic devices.
The present embodiment implements the steps of the SQL parsing method based on multiple tenants according to the above embodiment when the processor executes the computer readable instructions stored in the memory, and intercepts an SQL statement in the system by an interceptor based on a processing instruction by receiving the processing instruction; the method comprises the steps of extracting all SQL sentences, constructing the SQL sentences by using an abstract syntax tree algorithm to obtain a corresponding syntax tree, constructing syntax relations of all the SQL sentences, matching the SQL requests with the syntax tree by using a character string matching algorithm through obtaining the SQL requests, and obtaining corresponding data according to matching results, so that the SQL sentences are quickly analyzed, the efficiency of judging tenant data sources is improved according to the SQL requests, and the production and operation efficiency is improved.
The embodiment of the present application further provides a computer-readable storage medium, which stores computer-readable instructions executable by at least one processor to cause the at least one processor to perform the steps of the multi-tenant based SQL parsing method as described above, by receiving a processing instruction, based on which, an SQL statement in a system is intercepted by an interceptor; the method comprises the steps of extracting all SQL sentences, constructing the SQL sentences by using an abstract syntax tree algorithm to obtain a corresponding syntax tree, constructing syntax relations of all the SQL sentences, matching the SQL requests with the syntax tree by using a character string matching algorithm through obtaining the SQL requests, and obtaining corresponding data according to matching results, so that the SQL sentences are quickly analyzed, the efficiency of judging tenant data sources is improved according to the SQL requests, and the production and operation efficiency is improved.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present application.
The multi-tenant-based SQL parsing apparatus, the computer device, and the computer-readable storage medium according to the embodiments of the present application have the same technical effects as the multi-tenant-based SQL parsing method according to the embodiments, and are not expanded herein.
It is to be understood that the above-described embodiments are merely illustrative of some, but not restrictive, of the broad invention, and that the appended drawings illustrate preferred embodiments of the invention and do not limit the scope of the invention. This application is capable of embodiments in many different forms and is provided for the purpose of enabling a thorough understanding of the disclosure of the application. Although the present application has been described in detail with reference to the foregoing embodiments, it will be apparent to one skilled in the art that the present application may be practiced without modification or with equivalents of some of the features described in the foregoing embodiments. All equivalent structures made by using the contents of the specification and the drawings of the present application are directly or indirectly applied to other related technical fields and are within the protection scope of the present application.

Claims (10)

1. A SQL parsing method based on multiple tenants is characterized in that the method comprises the following steps:
receiving a processing instruction;
intercepting SQL sentences in the system through an interceptor based on the processing instruction;
constructing the SQL statement by using an abstract syntax tree algorithm to obtain a corresponding syntax tree;
acquiring an SQL request, and matching the SQL request with a syntax tree by using a character string matching algorithm;
and acquiring corresponding data according to the matching result.
2. The multi-tenant-based SQL parsing method of claim 1, wherein the constructing the SQL statement into the corresponding syntax tree using an abstract syntax tree algorithm comprises:
according to the abstract syntax tree algorithm, performing lexical analysis on the SQL statement to obtain a corresponding array;
and carrying out syntactic analysis on the array through the abstract syntactic tree algorithm, and converting the array into a tree shape so as to obtain the syntactic tree.
3. The multi-tenant based SQL parsing method of claim 1, wherein the matching SQL requests to a syntax tree using a string matching algorithm comprises:
constructing a corresponding key tree by using each key data according to each key data in the syntax tree;
and obtaining a key tree corresponding to the SQL request type according to the SQL request type, and matching the SQL request with the key tree corresponding to the SQL request type.
4. The multi-tenant based SQL parsing method of claim 1, wherein the matching SQL requests to a syntax tree using a string matching algorithm comprises:
according to the tenant IDs under the key data in the syntax tree, constructing a tenant ID tree from top to bottom in the order of the number of digits of the tenant IDs;
extracting the ID of the tenant to be processed in the SQL request;
and matching the tenant ID to be processed with the tenant ID tree through a character string matching algorithm.
5. The multi-tenant based SQL parsing method of claim 1, further comprising, before the constructing the SQL statement into the corresponding syntax tree using an abstract syntax tree algorithm:
and judging whether the SQL statement is safe or not by using a preset condition, and if not, not processing the SQL statement.
6. The multi-tenant-based SQL parsing method of claim 1, wherein the intercepting SQL statements in the system by an interceptor comprises:
identifying SQL sentences in the system according to a preset regular expression in the interceptor;
and intercepting the SQL statement after the SQL statement is identified.
7. The multi-tenant-based SQL parsing method of claim 1, wherein the intercepting SQL statements in the system by an interceptor comprises:
acquiring a dynamic configuration table and a field from a database;
and intercepting all the SQL sentences in the system by dynamically configuring tables and fields by the interceptor.
8. A multi-tenant based SQL parsing apparatus, the apparatus comprising:
the receiving module is used for receiving a processing instruction;
the interception module is used for intercepting SQL sentences in the system through an interceptor based on the processing instruction;
the building module is used for building the SQL statement to obtain a corresponding syntax tree by using an abstract syntax tree algorithm;
the matching module is used for acquiring the SQL request and matching the SQL request with the syntax tree by using a character string matching algorithm;
and the acquisition module is used for acquiring corresponding data according to the matching result.
9. A computer device, characterized in that the computer device comprises:
at least one processor; and the number of the first and second groups,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores computer readable instructions that, when executed by the processor, implement the multi-tenant based SQL parsing method of any of claims 1-7.
10. A computer readable storage medium having computer readable instructions stored thereon which, when executed by a processor, implement the multi-tenant based SQL parsing method of any of claims 1-7.
CN202111531521.6A 2021-12-14 2021-12-14 SQL (structured query language) analysis method and device based on multiple tenants, computer equipment and storage medium Pending CN114356959A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111531521.6A CN114356959A (en) 2021-12-14 2021-12-14 SQL (structured query language) analysis method and device based on multiple tenants, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111531521.6A CN114356959A (en) 2021-12-14 2021-12-14 SQL (structured query language) analysis method and device based on multiple tenants, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114356959A true CN114356959A (en) 2022-04-15

Family

ID=81098900

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111531521.6A Pending CN114356959A (en) 2021-12-14 2021-12-14 SQL (structured query language) analysis method and device based on multiple tenants, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114356959A (en)

Similar Documents

Publication Publication Date Title
CN108932294B (en) Resume data processing method, device, equipment and storage medium based on index
KR101617696B1 (en) Method and device for mining data regular expression
CN112052138A (en) Service data quality detection method and device, computer equipment and storage medium
CN113495902A (en) Data processing method and data standard management system
CN111813845A (en) ETL task-based incremental data extraction method, device, equipment and medium
CN112231417A (en) Data classification method and device, electronic equipment and storage medium
CN114817243A (en) Method, device and equipment for establishing database joint index and storage medium
CN112559526A (en) Data table export method and device, computer equipment and storage medium
CN113297251A (en) Multi-source data retrieval method, device, equipment and storage medium
KR101019627B1 (en) System and Method for Construction Automatic Bibliography based Pattern, and Recording Medium therefor
CN107679055B (en) Information retrieval method, server and readable storage medium
CN113032371A (en) Database grammar analysis method and device and computer equipment
CN111752958A (en) Intelligent associated label method, device, computer equipment and storage medium
CN111078671A (en) Method, device, equipment and medium for modifying data table field
Eyal-Salman et al. Feature-to-code traceability in legacy software variants
CN107633094B (en) Method and device for data retrieval in cluster environment
CN114356959A (en) SQL (structured query language) analysis method and device based on multiple tenants, computer equipment and storage medium
CN106682107B (en) Method and device for determining incidence relation of database table
CN115269713A (en) Data visualization method, system, computer equipment and medium
CN114385656A (en) Script detection method and device, computer equipment and storage medium
Eyal-Salman et al. Identifying traceability links between product variants and their features
CN113407495A (en) SIMHASH-based file similarity determination method and system
CN112433943A (en) Method, device, equipment and medium for detecting environment variable based on abstract syntax tree
CN110737707A (en) Multi-system log searching method and device and computer readable storage medium
CN112527880B (en) Method, device, equipment and medium for collecting metadata information of big data cluster

Legal Events

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