CN110109951B - Correlation query method, database application system and server - Google Patents

Correlation query method, database application system and server Download PDF

Info

Publication number
CN110109951B
CN110109951B CN201711487511.0A CN201711487511A CN110109951B CN 110109951 B CN110109951 B CN 110109951B CN 201711487511 A CN201711487511 A CN 201711487511A CN 110109951 B CN110109951 B CN 110109951B
Authority
CN
China
Prior art keywords
connection model
query
query statement
connection
target
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201711487511.0A
Other languages
Chinese (zh)
Other versions
CN110109951A (en
Inventor
李嘉陵
韩俊伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Huawei Technologies Co Ltd
Original Assignee
Huawei Technologies 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 Huawei Technologies Co Ltd filed Critical Huawei Technologies Co Ltd
Priority to CN201711487511.0A priority Critical patent/CN110109951B/en
Publication of CN110109951A publication Critical patent/CN110109951A/en
Application granted granted Critical
Publication of CN110109951B publication Critical patent/CN110109951B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/2452Query translation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2453Query optimisation
    • G06F16/24534Query rewriting; Transformation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2453Query optimisation
    • G06F16/24534Query rewriting; Transformation
    • G06F16/24535Query rewriting; Transformation of sub-queries or views
    • 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
    • G06F16/24553Query execution of query operations
    • G06F16/24558Binary matching operations
    • G06F16/2456Join operations

Abstract

The application provides a method for associated query, a database application system and a server, which simplify the difficulty of constructing associated query sentences and facilitate query. The method of the embodiment of the application comprises the following steps: acquiring data to be queried and a connection model library, wherein the connection model library comprises at least one connection model, and the connection model is defined by an incidence relation between at least two original tables; constructing first query statements according to data to be queried, and obtaining at least one target connection model from a connection model library according to the first query statements; converting the first query statement into a second query statement according to the target connection model, wherein the second query statement is a special language of a database management system, and the database management system is used for managing a database in which at least two original tables are stored; and querying the database management system according to the second query statement to obtain a query result.

Description

Correlation query method, database application system and server
Technical Field
The present application relates to the field of computers, and in particular, to a method for performing association query, a database application system, and a server.
Background
In a Database Application System (DBAS), there are various relationships between tables, and there are relationships described by a primary key and a foreign key in common; there are weak relationships that are guaranteed to be consistent and complete by the database application system. DBAS often needs to query the data related to each table, and sets a filter condition for each queried table, where the filter condition of each table often has a relationship of mutual constraint. When a DBAS needs to Query an object in a Database, it needs to construct a Domain Specific Language (DDL) statement provided by a Database Management System (DBMS), for example, a Structured Query Language (SQL) statement, and because various objects are stored in different tables, the Query statement constructed when querying the object is very complex, which affects Query efficiency.
The first query method is that the DBAS constructs a query statement by using the association relationship between tables, for example, constructs an SQL statement of a multi-table association query by a JOIN clause, and when constructing the SQL statement, it needs to consider whether the query result has a duplicate record to really use the DISTINCT keyword.
The second query method is that DBAS uses the association relationship between tables to nest and connect the associated tables through sub-queries to construct query statements, for example, using EXISTS, IN and other sub-queries to construct SQL statements IN a WHERE clause.
The third query method is that the DBAS defines a table and an association relation thereof that need to be subjected to association query as a database view, and queries the view.
However, in the first query method, the DBAS, the table structure and the table data have large coupling, that is, when the association relationship of each table changes, the DBAS must be modified in a linkage manner, and whether the query result has repeated records or not also needs to be determined according to the multiplicity of the table data; the second query method also has the problem of large coupling between the DBAS and the table structure, and the associated tables need to be nested and connected through sub-queries, so that query statements are very complex; in the third query method, if a plurality of associated table combinations exist, a plurality of database views need to be defined, and the database views do not allow the DBAS to specify a sub-query filtering condition in a WHERE clause in the view, and the problem of large coupling between the DBAS and table data exists. Therefore, the above three query methods all make the multi-table association query statement of the DBAS difficult to construct and inconvenient to query.
Disclosure of Invention
The application provides a correlation query method, a database application system and a server, which simplify the construction difficulty of correlation query sentences and facilitate query.
A first aspect of the present application provides a method for associating queries, including:
acquiring data to be queried and a connection model library, wherein the connection model library comprises at least one connection model, and the connection model is defined by an incidence relation between at least two original tables;
constructing first query statements according to the data to be queried, and obtaining at least one target connection model from the connection model library according to the first query statements;
converting the first query statement into a second query statement according to the target connection model, wherein the second query statement is a special language of a database management system, and the database management system is used for managing a database in which the at least two original tables are stored;
and querying the database management system according to the second query statement to obtain a query result.
When a user needs to inquire certain data through the DBAS, inputting data to be inquired on the DBAS, the DBAS acquiring a connection model library from a connection model repository or a connection model configuration file, wherein the connection model library comprises at least one connection model, the connection model is obtained by the DBAS according to the definition of the incidence relation between at least two original tables, because the original tables comprise various data and some original tables comprise the data to be inquired, and the DBAS inquires the connection model with the data to be inquired from the connection model library according to the data to be inquired, constructing a first inquiry statement according to the data to be inquired, wherein the first inquiry statement is actually an inquiry statement for inquiring the connection model, the inquiry statement is DSL language, particularly SQL language, and a target connection model is obtained from the connection model library according to the first inquiry statement, and because the original table with the data to be inquired possibly exists in a plurality of original tables, and the plurality of original tables all have connection models, then the target connection model may also be a plurality of, all the original tables are stored in a DB managed and stored by the DBMS, then the query is actually executed by the DBMS, and the first query statement is only a statement queried based on the connection model, then the first query statement needs to be converted into a second query statement supported by the DBMS, therefore, the DBAS further needs to convert the first query statement into a second query statement executable by the DBMS according to the target connection model according to a specification which initially defines the target connection model, and after obtaining the second query statement, submit the second query statement to the DBMS, the DBMS queries according to the second query statement to obtain a query result, and then return the query result to the DBAS, because the DBAS packs the association relationship among the plurality of tables into the connection model in advance, then, a target connection model can be obtained by directly querying with a first query statement similar to a query list table, so that the DBAS is liberated from the construction of complex query statements; but also supports table associations by subqueries that are not supported by the database view while allowing the specification of filtering criteria for the subqueries; and converting the first query statement into a second query statement according to the target connection model, so that the second query statement can be executed on the existing DBMS.
With reference to the first aspect of the present application, in a first implementation manner of the first aspect of the present application, before the obtaining the data to be queried and the connecting the model library, the method further includes:
acquiring table information of at least two original tables, wherein the table information comprises table identification and table fields;
establishing at least one connection model according to the incidence relation of the at least two original tables, wherein each connection model comprises connection model basic information, connection model attributes and a table relation, the connection model basic information comprises connection model identifications and connection model names, the connection model attributes comprise attribute identifications, attribute names, table identifications and table fields of corresponding original tables, and the table relation comprises table relation identifications, table identifications of all the original tables, connection modes of adjacent original tables and connection expressions;
obtaining a connection model library according to the at least one connection model;
storing the connection model repository to a connection model repository;
or the like, or, alternatively,
and obtaining a connection model configuration file according to the connection model library.
The method comprises the steps of obtaining table information of at least two original tables, wherein the table information comprises table identifications and table fields, establishing at least one connection model according to the incidence relation of the at least two original tables, each connection model comprises connection model basic information, connection model attributes and table relations, the connection model basic information comprises connection model identifications and connection model names, the connection model attributes comprise attribute identifications, attribute names, corresponding table identifications of the original tables and table fields, the table relations comprise table relation identifications, the table identifications of the original tables, the connection modes of adjacent original tables and connection expressions, and the connection model establishing modes can be stored through connection model storage libraries or connection model configuration files. After packaging, the DBAS treats the connection model as a table or view building first query statement without concern for the internal composition of the connection model.
With reference to the first embodiment of the first aspect of the present application, in the second embodiment of the first aspect of the present application, the acquiring information to be queried and a connection model library includes:
receiving data to be queried input by a user;
obtaining a connection model library from a connection model repository;
or the like, or, alternatively,
and receiving a connection model configuration file, and analyzing the connection model configuration file to obtain a connection model library.
After the connection model library is established by the above embodiment, after the DBAS receives the data to be queried input by the user, the connection model library may be obtained from the connection model repository, or the connection model library may be obtained by analyzing the connection model repository by receiving the connection model configuration file, and a specific obtaining manner is not limited.
With reference to the second implementation manner of the first aspect of the present application, in the third implementation manner of the first aspect of the present application, the constructing a first query statement according to the data to be queried and obtaining a target connection model from the connection model library according to the first query statement includes:
constructing a first query statement according to the data to be queried;
querying each connection model in the connection model library according to the first query statement;
and when the table field of the original table corresponding to the connection model attribute of the inquired connection model has the data to be inquired, determining that the inquired connection model is a target connection model, wherein the number of the target connection models is at least one.
And constructing a first query statement according to the data to be queried, wherein the first query statement is a statement for querying the connection model, and specifically can be SQL, querying each connection model in the connection model library according to the first query statement, and when the table field of the original table corresponding to the connection model attribute of the queried connection model has the data to be queried, indicating that the connection model has the original table having the data to be queried, determining that the connection model is a target connection model and the target connection model is at least one.
With reference to the first aspect, the first implementation manner of the first aspect, the second implementation manner of the first aspect, or the third implementation manner of the first aspect, in a fourth implementation manner of the first aspect of the present application, the converting the first query statement into a second query statement according to the target connection model includes:
judging whether the first query statement is a special language of a database management system or not;
if so, expanding the first query statement according to the target connection model to obtain a second query statement;
if not, translating the first query statement according to the target connection model to obtain a second query statement.
When the first query statement is converted into the second query statement, it is further determined whether the first query statement is a specific language supported by DBAS, for example, SQL supported by DBAS, and the first query statement is SQL, which indicates that the first query statement is a specific language of a database management system, at this time, only the first query statement needs to be expanded, and if the specific language supported by DBAS is not SQL and the first query statement is SQL, the first query statement needs to be translated according to a specific conversion mode to obtain the second query statement, and a specific translation rule is determined according to the specific language supported by DBAS and is not specifically described.
With reference to the fourth implementation manner of the first aspect of the present application, in the fifth implementation manner of the first aspect of the present application, the expanding the first query statement according to the target connection model to obtain a second query statement includes:
determining a table identifier and a table field of a target original table with the data to be queried in the target connection model, wherein the number of the target original tables is at least one;
determining the sequence of the target original table to obtain a table set;
and expanding the first query statement into a second query statement according to the table set and the table relation in the target connection model.
Since various DBMSs do not support the join model at present, and the query must be completed by the DBMS, the query SQL (or other query DSL) needs to be expanded and translated into SQL supported by the DBMS, and then submitted to the DBMS for query and result acquisition. One query statement can only search one connection model, and can also simultaneously search a plurality of connection models and other tables. When a plurality of connection models or other tables are queried simultaneously, in order to reduce the influence of other tables on the expansion logic, the places where the connection models appear, such as FROM or JOIN clauses in SQL, can be replaced by sub-queries on the connection models to obtain SQL equivalent to the input SQL, and the expansion action is performed in the sub-queries.
A second aspect of the present application provides a database application system, including:
the system comprises an acquisition module, a connection model library and a query module, wherein the acquisition module is used for acquiring data to be queried and the connection model library, the connection model library comprises at least one connection model, and the connection model is defined by an incidence relation between at least two original tables;
the query module is used for constructing a first query statement according to the data to be queried and obtaining at least one target connection model from the connection model library according to the first query statement;
the query statement conversion module is further used for converting the first query statement into a second query statement according to the target connection model, wherein the second query statement is a special language of a database management system, and the database management system is used for managing a database in which the at least two original tables are stored;
the query statement conversion module is further configured to query the database management system according to the second query statement to obtain a query result.
Because the DBAS packages the incidence relations among the tables in advance as the connection model, after the acquisition module acquires the data to be queried and the connection model library, the query module can directly query by using a first query statement similar to a query list table to obtain a target connection model, so that the DBAS is liberated from the construction of complex query statements; but also supports table associations by subqueries that are not supported by the database view while allowing the specification of filtering criteria for the subqueries; and the query statement conversion module converts the first query statement into the second query statement according to the target connection model, so that the second query statement can be executed on the existing DBMS.
With reference to the second aspect of the present application, in a first embodiment of the second aspect of the present application, the database application system further includes:
the connection model building module is used for obtaining table information of at least two original tables, and the table information comprises table identification and table fields;
the connection model building module is further configured to build at least one connection model according to the association relationship between the at least two original tables, each connection model includes connection model basic information, connection model attributes and a table relationship, the connection model basic information includes connection model identifiers and connection model names, the connection model attributes include attribute identifiers, attribute names, table identifiers and table fields of corresponding original tables, and the table relationship includes table relationship identifiers, table identifiers of the original tables, connection modes of adjacent original tables and connection expressions;
the connection model building module is also used for obtaining a connection model library according to the at least one connection model;
the connection model building module is further used for storing the connection model library into a connection model repository;
or the like, or, alternatively,
the connection model building module is also used for obtaining a connection model configuration file according to the connection model library.
The connection model building module obtains table information of at least two original tables, the table information comprises table identifications and table fields, at least one connection model is built according to the incidence relation of the at least two original tables, each connection model comprises connection model basic information, connection model attributes and table relations, the connection model basic information comprises connection model identifications and connection model names, the connection model attributes comprise attribute identifications, attribute names, the corresponding table identifications of the original tables and the table fields, the table relations comprise table relation identifications, the table identifications of the original tables, the connection modes of adjacent original tables and connection expressions, and the connection model building modes can be stored in the form of a connection model repository or a connection model configuration file. After packaging, the DBAS treats the connection model as a table or view building first query statement without concern for the internal composition of the connection model.
In combination with the first embodiment of the second aspect of the present application, in the second embodiment of the second aspect of the present application,
the acquisition module is specifically used for receiving information to be queried input by a user, and the information to be queried comprises data to be queried and query conditions;
the acquisition module is further used for acquiring a connection model library from the connection model repository;
or the like, or, alternatively,
the acquisition module is also used for receiving the connection model configuration file and analyzing the connection model configuration file to obtain a connection model library.
In combination with the second embodiment of the second aspect of the present application, in the third embodiment of the second aspect of the present application,
the query module is specifically used for constructing a first query statement according to the data to be queried and the query condition;
the query module is further configured to query each connection model in the connection model library according to the first query statement;
the query module is further configured to determine that the queried connection model is a target connection model when the table field of the original table corresponding to the connection model attribute of the queried connection model has the data to be queried, where the number of the target connection models is at least one.
After the connection model building module builds the connection model library through the above embodiments, after the obtaining module receives the data to be queried input by the user, the connection model library may be obtained from the connection model repository, or the connection model library may be obtained by receiving the connection model configuration file and analyzing the connection model configuration file, and the specific obtaining manner is not limited.
With reference to the second aspect of the present application, the first embodiment of the second aspect, the second embodiment of the second aspect, or the third embodiment of the second aspect, in the fourth embodiment of the second aspect of the present application,
the query sentence conversion module is also used for judging whether the first query sentence is a special language of the database management system;
the query statement conversion module is further configured to, when the first query statement is a specific language of the database management system, expand the first query statement according to the target connection model to obtain a second query statement;
the query statement conversion module is further configured to, when the first query statement is not a specific language of the database management system, translate the first query statement according to the target connection model to obtain a second query statement.
The query module constructs a first query statement according to the data to be queried, where the first query statement is a statement for querying the connection model, and may specifically be SQL, and the query module queries each connection model in the connection model library according to the first query statement, and when the table field of the original table corresponding to the connection model attribute of the queried connection model has the data to be queried, it indicates that the connection model has the original table having the data to be queried, then the query module 602 determines that the connection model is a target connection model, and the target connection model is at least one.
In combination with the fourth embodiment of the second aspect of the present application, in the fifth embodiment of the second aspect of the present application,
the query statement conversion module is further configured to determine a table identifier and a table field of a target original table having the data to be queried in the target connection model, where at least one target original table is provided;
the query statement conversion module is further configured to determine an order of the target original table to obtain a table set;
the query statement conversion module is further configured to convert the expression list of the first query statement into a second query statement according to the table set and the table relationship in the target connection model.
When the query statement conversion module converts the first query statement into the second query statement, it needs to determine whether the first query statement is a specific language supported by DBAS, for example, the first query statement is SQL supported by DBAS, which indicates that the first query statement is a specific language of the database management system, and at this time, only the first query statement needs to be expanded, and if the specific language supported by DBAS is not SQL and the first query statement is SQL, the first query statement needs to be translated according to a specific conversion mode to obtain the second query statement.
A third aspect of the present application provides a server comprising:
a processor and a memory, wherein the memory may be used to store code executed by the processor;
the processor and the memory are connected through a bus system;
the processor is used for acquiring data to be queried and a connection model library, wherein the connection model library comprises at least one connection model, and the connection model is defined by an incidence relation between at least two original tables;
the processor is used for constructing a first query statement according to the data to be queried and obtaining at least one target connection model from the connection model library according to the first query statement;
the processor is further configured to convert the first query statement into a second query statement according to the target connection model, where the second query statement is a language specific to a database management system, and the database management system is configured to manage a database in which the at least two original tables are stored;
the processor is further configured to query the database management system according to the second query statement to obtain a query result.
Since various DBMSs do not support the connection model at present, and the query must be completed by the DBMS, the query statement conversion module needs to expand the query SQL (or other query DSL) into the SQL supported by the DBMS, and then deliver the query result to the DBMS for query.
A fourth aspect of the present application provides a computer-readable storage medium having stored therein instructions, which, when run on a computer, cause the computer to perform the method of the above-described aspects.
A fifth aspect of the present application provides a computer program product comprising instructions which, when run on a computer, cause the computer to perform the method of the above-described aspects.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings used in the description of the embodiments and the prior art will be briefly described below.
FIG. 1 is a schematic diagram of the system architecture provided herein;
FIG. 2 is a table structure and relationship diagram provided herein;
FIG. 3 is a schematic diagram of a method for converting data into a WHERE clause of an SQL statement according to the present application;
FIG. 4 is a flowchart illustrating an embodiment of a method for correlating queries provided herein;
FIG. 5 is a schematic diagram of a meta model of a connection model established by the present application;
FIG. 6 is a block diagram illustrating an embodiment of a database application system provided herein;
FIG. 7 is a schematic block diagram of another embodiment of a database application system provided in the present application;
fig. 8 is a schematic structural diagram of an embodiment of a server provided in the present application.
Detailed Description
The application provides a correlation query method, a database application system and a server, which simplify the construction difficulty of correlation query sentences and facilitate query.
The technical solutions in the present application will be clearly and completely described below with reference to the accompanying drawings in the present application.
First, a system architecture or scenario in which the present application is applied will be briefly described.
The system architecture diagram of the application is shown in fig. 1, and comprises a DBMS and a DBAS, wherein the DBAS comprises a query module, a connection model library, and query statement expansion and translation. The DBMS: is a large software for manipulating and managing a Database (DB) for establishing, using and maintaining the DB, which performs a unified management and control on the DB to ensure the security and integrity of the DB. The DB is a repository that organizes, stores, and manages data according to a data structure. DBAS: is a computer application system built under the support of DBMS. The SQL language is a special purpose computer programming language used for standard data query languages in databases. The DSL language is a computer language specific to a particular problem, for example, SQL is a special case of DSL, and is a language specific to the database field. The data query refers to that the DBAS acquires data meeting the condition from the DB through the DBMS. Typically DBAS describes the query requirements in SQL statements (and possibly other DSLs provided by the DBMS).
The query module: DBAS requires a module to query data from the DB. In a conventional DBAS, this module directly constructs a query DSL for the DBMS, and initiates the query to the DBMS and obtains the result. In the present application, this module constructs the query DSL based on the connection model and submits the DSL to the "query statement expansion and translation" module.
Connecting a model library: maintains and is responsible for maintaining the connection model defined in DBAS. The definition of the specific connection model is done by the service actually provided by the DBAS.
Query DSL deployment and translation: and the system is responsible for expanding and translating the query DSL (generally SQL) from the query model into the query DSL (generally SQL) supported by the DBMS according to the definition of the connection model, submitting the DSL to the DBMS for query and acquiring the result, and returning the result to the query module.
In the current DBAS, various relationships often exist among a plurality of tables, and a relationship described by a primary key and a foreign key is common; there is also a weak relationship that is guaranteed by the application itself to be consistent and complete. DBAS usually needs to query the data related to each table, and sets a filtering condition for each queried table, where the filtering condition of each table usually has a mutual constraint relationship. Typically, DBAS (e.g., fault Management (FM), performance Management (PM), etc.) based on a Configuration Management Database (CMDB) often has such usage. The CDMB is used for storing and managing various configuration Information of devices in an enterprise Information Technology (IT) architecture, is closely associated with all service support and service delivery processes, supports the operation of the processes, exerts the value of the configuration Information, and simultaneously ensures the accuracy of data depending on the related processes. FM refers to management operations in the case of system abnormalities, and is a series of activities used to dynamically maintain the network operating normally and reaching a certain service level. PM refers to system performance such as evaluating the operating conditions and communication efficiency of system resources, and its capability includes monitoring and analyzing the managed network and its performance mechanism of the services provided.
An example of a business scenario is made: in the FM service, alarms are screened according to the value of certain attribute of an alarm generating object and the alarm level. Such as a severity level alarm generated by screening all 10GE ports. The alarm and the object are respectively stored in two tables; there is a field in the alarm table to store the ID of the alarm generating object. In the PM service, objects in each level are selected on an object relationship tree as objects of a certain PM report, for example, any object in any level is selected on an object tree with a structure of providence, city, BSC, BTS, cell. Cell is a basic wireless coverage area in a network. A Base station (Base Transceiver station), also known as a Base Transceiver station, controls a group of cells. : a Base Station Controller (BSC) controls a set of BTSs.
Taking the PM service scenario as an example, in this scenario, the provice, city, BSC, BTS, and Cell objects are stored in respective tables. The relationship between Province and City is represented by the City's foreign key. Likewise, the relationship between the BSC and BTS and the relationship between BTS and Cell are also the same. In contrast, the relationship between City and BSC is described by the City _ BSC _ Relation table, which is used to describe many-to-many relationship. Each record of this table is used to represent a relationship between City and BSC. The complete table structure and relationships are shown in fig. 2. In FIG. 2, the City and BSC are associated through City _ BSC _ Relations to realize many-to-many association. That is, one City object may be associated with a plurality of BSC objects, and one BSC object may be associated with a plurality of City objects. The PM service allows objects of each hierarchy to be checked on the object relationship tree described by the table shown in fig. 2 (for example, checking according to names of the objects), and a Cell object of the checked object is used as an object for which a certain report needs to output performance index data. Assuming that the selection results are shown in table 1 below,
TABLE 1
Figure BDA0001535028060000081
Figure BDA0001535028060000091
Figure BDA0001535028060000101
In the actual use process, the object may be changed (for example, adding a child object). In order to achieve the effect that when a new sub-object is added to a selected object, the newly added sub-object is also selected, generally, each specific object selected at that time is not directly stored, but the selection condition is stored, and query is performed according to the current object when the specific object needs to be used. When the DBAS saves the object selection condition by saving the actively selected and passively selected objects, it only needs to save the actively selected objects, the actively excluded objects, and the positions of the objects, and does not need to save the passively selected and passively excluded objects (the sub-objects have the positions of the actively selected and passively selected objects that need to be saved to represent the sub-objects). Taking the example shown in table 1 above as an example, the stored data are shown in table 2 below,
TABLE 2
Figure BDA0001535028060000111
When the DBAS queries the Cell object from the database according to the check condition, it needs to construct a corresponding SQL statement, and may also construct other DSL statements provided by the DBMS. For simplicity, SQL is described as the query DSL for DBMS. Since various objects are stored in different tables, it is complicated to construct SQL statements. To simplify the problem, assume that the associations between tables have been described in the SQL statement, and the emphasis is on describing how to construct the object filter conditions in the SQL statement according to the previously saved object selection cases. The method of fig. 3 may be used to convert the data of the object selection case (e.g., table 2) into the WHERE clause of the SQL statement. This approach does not require knowledge of how the tables holding the various types of objects are related.
In fig. 3, "generating equal expression" specifically includes:
generating an expression for the current object: name field = object name;
the expression is connected with the expressions of its children (if any) using an OR logical relationship;
the expression constructed by the expression and the sub-object expression thereof is connected with the expression constructed by other objects and respective sub-object expressions of the current layer by using an OR logical relationship.
In fig. 3, "generating unequal expressions" specifically includes:
generating an expression for the current object: name field of object is name of object;
the expression AND the expressions of the sub-objects thereof are connected by using an AND logical relationship;
the expression constructed by the expression AND the sub-object expression thereof is connected with the expression constructed by other objects AND respective sub-object expressions of the current layer by using AND logical relation.
The WHERE clause of SQL is obtained by converting the above table 2 according to the method shown in FIG. 3, as follows:
Figure BDA0001535028060000121
the above statements are intended to query cell objects that meet the following conditions:
among cells in Guangdong province, cells satisfying the following conditions:
the other market cells except Shenzhen;
and a cell under the BTS named shenzhen BTS 31;
and cell named shenzhen cell 332;
and cells in Jiangsu province, which meet the following conditions:
a cell under a BSC named NanjingBSC 3;
and a cell under the BTS named nanjingtbts 31;
and cells under the BTS named nanjingcbts 33, which are not named NanjingCell332 and NanjingCell 333.
There are other SQL equivalents to the above, or other algorithms to generate the above or equivalents. This document only describes the present application with the above SQL assistance. In practice, SQL statements like the above cannot be executed directly by the DBMS, and the SQL statements that can actually be executed by the DBMS are complex. How to save the object selection and how to convert the object selection into the above SQL statements is not the focus of the present application. The present application is intended to enable database applications to query by constructing the relatively simple SQL described above.
The first query method most commonly used at present is to construct an SQL statement of a multi-table associative query by a JOIN clause, and one possible writing method is as follows:
select distinting cell.id — use the distinting keyword to avoid the same cell object appearing many times in the result.
from cell- -Table cell in which the object to be checked is located.
join bsts on bsts.id = cell.
join bsc on bsc.id = bsts.
join _ bstc _ relationship on _ bstc _ relationship, bstc = bstc.id — since bstc and city are related by a city _ bstc _ relationship table, the relationship table needs to be related first.
join city on city.id = city _ bsc _ relation.city — the city table at the other head of the association relationship table.
join science on science id = city.
Figure BDA0001535028060000131
Figure BDA0001535028060000141
The first query method has the following disadvantages: SQL is constructed directly based on a database table, and a connection manner (e.g., INNER JOIN, LEFT JOIN, RIGHT JOIN, etc.) between tables and fields (e.g., bsts.id = cell.bsts, bsc.id = bsts.bsc, etc.) associated between tables must be described in SQL, once a table relationship changes, a query module needs to modify in a linkage manner, and when an SQL statement is constructed, it needs to determine whether a DISTINCT key needs to be used according to whether a query result has a duplicate record, that is, DBAS is greatly coupled with table data.
At present, the second query mode is to use exit, IN, etc. sub-queries IN the WHERE clause to construct an SQL statement. One possible writing is as follows:
Figure BDA0001535028060000142
Figure BDA0001535028060000151
Figure BDA0001535028060000161
Figure BDA0001535028060000171
Figure BDA0001535028060000181
according to the above written analysis, the second query method does not find duplicate data in SQL compared to the first query method. The second query method has the disadvantages that: SQL is also constructed directly based on a database table, and therefore, the connection manner between tables (e.g., exit, IN, etc. sub-queries) and the associated fields between tables (e.g., bts.id = cell.bsts, bsc.id = bts.bsc, etc.) must be described IN SQL, that is, DBAS is largely coupled with the table structure, and because the associated tables need to be nested and connected by sub-queries, SQL constructed using this technology has a very long WHERE clause, and SQL is difficult to construct and is prone to errors.
At present, the third query method is based on the first query method, and defines a table to be subjected to association query and an association relationship thereof as a database view, where an SQL statement for creating the database view is as follows:
create view overview _ to _ cell — the entire view definition does not contain the WHERE clause.
as
SELECT-write fields that need to be queried and fields that need to be a query condition into a SELECT clause.
province.name as province_name,
city.name as city_name,
bsc.name as bsc_name,
bts.name as bts_name,
cell.name as cell_name,
cell.id as cell_id
from cell
join bts on bts.id=cell.bts
join bsc on bsc.id=bts.bsc
join city_bsc_relation on city_bsc_relation.bsc=bsc.id
join city on city.id=city_bsc_relation.city
join province on province.id=city.province
The SQL sentences constructed based on the database view defined by the SQL sentences are as follows:
selection distinting cell _ id-use the distinting keyword to avoid the same cell object appearing in the result for many times.
from provide _ to _ cell _ view — a view named provide _ to _ cell _ view is queried.
WHERE- -WHERE clause modifies the field name to the field name defined in the view.
Figure BDA0001535028060000191
Figure BDA0001535028060000201
Compared with the first query method, for the DBAS, the third query method does not need to care about details of the association relationship between the tables (for example, which fields are associated between the two tables), and can shield the influence of table relationship changes on the query module to a certain extent, but when the associated tables are combined more, a plurality of database views are defined; and the database view does not allow the DBAS to specify the sub-query filtering condition in the WHERE clause in the database view; and when the query module constructs the SQL statement, whether the DISTINCT keyword needs to be used is determined according to whether repeated records exist in the query result. I.e. the query application is coupled to the table data much larger.
In order to solve the above problem of the query method, as shown in fig. 4, an embodiment of the present application provides a method for associating queries, which includes:
401. acquiring data to be queried and a connection model library;
in this embodiment, when a user needs to query a certain data through the DBAS, the data to be queried is input on the DBAS, the DBAS obtains a connection model library from a connection model repository or a connection model configuration file, the connection model library includes at least one connection model, and the connection model is defined by the DBAS according to an association relationship between at least two original tables.
402. Constructing a first query statement according to data to be queried, and obtaining a target connection model from a connection model library according to the first query statement;
in this embodiment, because the original tables include various data, and some of the original tables include data to be queried, and the DBAS can query the connection model with the data to be queried from the connection model library according to the data to be queried, a first query statement is constructed according to the data to be queried, where the first query statement is actually a query statement for querying the connection model, and the query statement is a DSL language, specifically, an SQL language, and a target connection model is obtained from the connection model library according to the first query statement.
403. Converting the first query statement into a second query statement according to the target connection model;
in this embodiment, all the original tables are stored in the DB managed by the DBMS, so that the query is actually executed by the DBMS, and the first query statement is only a statement queried based on the connection model, and the first query statement needs to be converted into a second query statement supported by the DBMS.
404. And querying the database management system according to the second query statement to obtain a query result.
In this embodiment, after the second query statement is obtained, the second query statement is submitted to the DBMS, the DBMS queries according to the second query statement to obtain a query result, and then returns the query result to the DBAS.
In the embodiment of the application, because the DBAS packages the association relations among the tables as the connection model in advance, a target connection model can be obtained by directly querying through a first query statement similar to a query single table, so that the DBAS is liberated from the construction of complex query statements; but also supports table associations by subqueries that are not supported by the database view while allowing the specification of filtering criteria for the subqueries; and converting the first query statement into the second query statement according to the target connection model, so that the second query statement can be executed on the existing DBMS.
Optionally, in some embodiments of the present application, before acquiring the data to be queried and connecting the model library, the method further includes:
acquiring table information of at least two original tables, wherein the table information comprises table identification and table fields;
establishing at least one connection model according to the incidence relation of at least two original tables, wherein each connection model comprises connection model basic information, connection model attributes and a table relation, the connection model basic information comprises connection model identifications and connection model names, the connection model attributes comprise attribute identifications, attribute names, corresponding table identifications of the original tables and table fields, and the table relation comprises a table relation identification, the table identification of each original table, the connection mode of adjacent original tables and a connection expression;
obtaining a connection model library according to at least one connection model;
storing the connection model repository to a connection model repository;
or the like, or a combination thereof,
and obtaining a connection model configuration file according to the connection model library.
In the embodiment of the application, table information of at least two original tables is obtained, the table information includes table identifiers and table fields, at least one connection model is established according to an incidence relation of the at least two original tables, each connection model includes connection model basic information, connection model attributes and table relations, the connection model basic information includes connection model identifiers and connection model names, the connection model attributes include attribute identifiers, attribute names, corresponding table identifiers of the original tables and table fields, the table relations include table relation identifiers, table identifiers of each original table, connection modes and connection expressions of adjacent original tables, and the connection model establishment mode can be stored through forms of connection model storage libraries or connection model configuration files. As shown in fig. 5, for the meta model of the established connection model, the main description information is: connection model basic information: ID of the connection model; name of the connection model (used in constructing the first query statement); connection model attributes: the ID of the attribute, the name of the attribute (used in constructing the first query statement), an original table corresponding to the attribute (used for expanding the first query statement), and a field in the original table corresponding to the attribute (used for expanding the first query statement); table relationships (first query statement expansion use): the ID, LEFT table name, RIGHT table name, connection mode (different connection modes such as INNER JOIN, LEFT JOIN, RIGHT JOIN, EXISTS, IN, etc.) of the table relationship, and connection expression (connection expression of two adjacent tables, if the adjacent tables are associated by an outer key, this information can also be obtained according to metadata of the database table). Through the above packaging, the DBAS regards the connection model as a table or view to construct the first query statement, without having to care about the internal composition of the connection model.
Optionally, in some embodiments of the present application, the obtaining of the information to be queried and the connection model library includes:
receiving data to be queried input by a user;
obtaining a connection model library from a connection model repository;
or the like, or, alternatively,
and receiving a connection model configuration file, and analyzing the connection model configuration file to obtain a connection model library.
In the embodiment of the present application, after the connection model library is established by the above embodiment, after the DBAS receives data to be queried input by a user, the connection model library may be obtained from a connection model repository, or the connection model library may be obtained by analyzing a connection model configuration file by receiving the connection model configuration file, and a specific obtaining manner is not limited.
Optionally, in some embodiments of the present application, constructing a first query statement according to data to be queried, and obtaining a target connection model from a connection model library according to the first query statement includes:
constructing a first query statement according to data to be queried;
querying each connection model in the connection model library according to the first query statement;
and when the table field of the original table corresponding to the connection model attribute of the inquired connection model has the data to be inquired, determining the inquired connection model as a target connection model, wherein the number of the target connection models is at least one.
In this embodiment of the present application, a first query statement is constructed according to data to be queried, where the first query statement is a statement for querying a connection model, and may specifically be SQL, each connection model in a connection model library is queried according to the first query statement, and when a table field of an original table corresponding to an attribute of the connection model of the queried connection model has data to be queried, it indicates that the connection model has the original table having the data to be queried, it is determined that the connection model is a target connection model, and the target connection model is at least one.
Optionally, in some embodiments of the present application, converting the first query statement into the second query statement according to the target connection model includes:
judging whether the first query statement is a special language of the database management system;
if so, expanding the first query statement according to the target connection model to obtain a second query statement;
if not, translating the first query statement according to the target connection model to obtain a second query statement.
In the embodiment of the present application, when the first query statement is converted into the second query statement, it is further determined whether the first query statement is a specific language supported by the DBAS, for example, SQL is supported by the DBAS, and the first query statement is SQL, which indicates that the first query statement is a specific language of the database management system, at this time, only the first query statement needs to be expanded, and if the specific language supported by the DBAS is not SQL and the first query statement is SQL, the first query statement needs to be translated according to a specific conversion manner to obtain the second query statement, and a specific translation rule is determined according to the specific language supported by the DBAS and is not specifically described.
Optionally, in some embodiments of the application, expanding the first query statement according to the target connection model to obtain a second query statement includes:
determining table identification and table fields of a target original table with data to be inquired in a target connection model, wherein at least one target original table is provided;
determining the sequence of a target original table to obtain a table set;
and expanding the first query statement into a second query statement according to the table set and the table relation in the target connection model.
In the embodiment of the present application, since various DBMSs do not support the connection model at present, and the query must be completed by the DBMS, the query SQL (or other query DSL) needs to be expanded and translated into SQL supported by the DBMS, and then submitted to the DBMS for query and obtaining the result. If the query statement constructed by the query module and the query statement of the DBMS are the same DSL, only the expansion of the query statement (i.e. replacing the query for the connection model with the query for the table) needs to be performed, and the following method is described by taking SQL as an example:
a query statement may only query one connection model, or may query multiple connection models and other tables simultaneously. When a plurality of connection models or other tables are queried simultaneously, in order to reduce the influence of other tables on the expansion logic, the places where the connection models appear, such as FROM or JOIN clauses in SQL, can be replaced by sub-queries on the connection models to obtain an SQL equivalent to the input SQL, and the expansion action can be performed in the sub-queries. The SQL statement of a query connection model can be abstractly summarized as the following SQL statement:
select { select expression List }
from { connected model }
where { where expression }
group by { group by expression list }
having { having expression }
The expansion method for a single join model query (possibly a sub-query in some SQL) is as follows:
for convenience of description, a query to the connection model (i.e., SQL to be expanded) will be referred to as SQL1,
step 1, determining a table identifier and a table field of a target original table with data to be queried in SQL 1;
and acquiring the table identifier and the table field of the target original table corresponding to the field of the queried connection model in SQL1 according to the definition of the queried connection model. The positions of the fields of the connection model in SQL1 are a select expression list, a where expression, a group by expression list and a haiving expression. Let set A be the set of original tables referred to by the fields appearing in the select expression list and the group by expression list (there may be multiple tables). The set of target original tables referred to by the fields appearing in the where expression and the hashing expression is referred to as set B (there may be multiple tables). All objects passing between set A and set B in the definition of the connection model are originally represented as set C (possibly with intersection with set A and set B). The set of target raw tables involved in the query is: a { [ U ] B { [ U ] C } is referred to as a set D. The set D may be all or a subset of the target original tables contained by the connection model being queried.
Step 2, determining the sequence of the target original table;
the set D is composed of a plurality of original tables, the tables form a chain (or vector called original table, denoted as V) according to the sequential connection relationship of the original tables defined by the connection model, and this step is to determine the direction of the vector V, i.e. the sequence of the original tables in the set D. To be consistent with the following step descriptions, the order of the original table is denoted "left" and "right," left "first and" right "last. For convenience of understanding, assuming that the set D = { a, b, c, D },4 elements are different from each other, the connection model defines that the 4 tables are connected by a, b, c, D in sequence, and the connection model is divided into several cases:
(1) And if a = B, then either end of a on V is left and the other end of V is right. Such as a = D, and B = D, then V = < a, B, c, D >, or V = < D, c, B, a >;
(2) If, if
Figure BDA0001535028060000231
The other end of V with respect to B is left and the other end point of V is right. For example, a = { a }, B = { c, d }, then V =<a,b,c,d>;
(3) If, say, that
Figure BDA0001535028060000232
And is provided with
Figure BDA0001535028060000233
And is provided with
Figure BDA0001535028060000234
The other end of ase:Sub>A-B on V opposite to B-ase:Sub>A is left and the other end of V is right. For example, a = { a, B }, B = { B, c, d }, then V = d<a,b,c,d>;
(4) If, say, that
Figure BDA0001535028060000235
And A ≠ B, then the other end of B-A on V is right relative to A, and the other end of V is left. For example, a = { a }, B = { a, B, c, d }, then V =<a,b,c,d>;
(5) If, say, that
Figure BDA0001535028060000236
And A ≠ B, then A-B is shown as left at V relative to the other end of B, and the other end of V is right. For example, a = { d }, B = { a, B, c, d }, then V =<d,c,b,a>。
Step 3, converting the fields of each connection model appearing in the select expression list and the group by expression list in SQL1 into corresponding original models, original fields and obtaining the SQL in the following form:
select { result of conversion of select expression list in SQL1 according to this step }
from { connected model }
where { where expression }
group by { result of conversion of group by expression list in SQL1 according to this step }
happy { happy expression }
Step 4, starting from the table at the leftmost side in the V, sequentially finding all tables which are continuously connected through the JOIN to the right, recording the subvectors of the tables in the V as W, and generating sentences which are connected by the JOIN type specified in the connection model definition according to the sequence of the tables in the vectors to obtain the following SQL fragments:
{ W form 1}
{ W connection type of table 1 and table 2} join { W table 2} on in a chart W connection condition of table 1 and table 2}
{ W connection type of tables 2 and 3} join { W table 3} on quick map W connection condition of tables 2 and 3} on
...
There is an extreme case where there is only one table in vector W, then the SQL fragment has only "{ table 1 in W }".
And 5, substituting the SQL fragments obtained in the step 4 into the 'connection model' in the SQL obtained in the step 3.
Step 6, expanding the where expression based on the SQL obtained in step 5, wherein in the step, for each minimum logic expression (that is, there is no and or inside the expression) in the "{ where expression }" connected through an and or, the minimum logic expression is processed respectively, and the processing method of each minimum logic expression is as follows:
if the table to which the field in the expression belongs is in the vector W, converting the field in the expression into a corresponding form of 'original model, original field';
if the table to which the fields in the expression belong is not in the vector W, but the table is located to the right of the vector W in V, the expression needs to be converted into an EXISTS sub-query, and the conversion result replaces the expression. The conversion method is described below, and the information required at this time is: vector V, the rightmost table (denoted as table N) in vector W, and the expression to be converted currently;
otherwise, the deployment process fails.
And 7, if the SQL1 has a happy clause, developing a happy expression based on the SQL obtained in the step 6. The method of this step is similar to that of step 6, except that only the fields of the table in vector W can appear in "{ hashing expression }", and if the fields of the table other than vector W appear, the expansion process fails.
And 8, obtaining the SQL processed in the steps 1 to 7 as an expansion result, namely a second query statement.
It should be noted that, if the logic expression needs to be converted into the EXISTS sub-query in step 6, the expression to be converted is processed according to the vector V and the table N by the following method:
sequentially finding all tables connected continuously by JOIN to the right in V from one table on the right side of the table N until an original table related in an expression to be converted is found, wherein the subvectors of the tables in V are marked as W, and generating an EXISTS subquery SQL fragment according to W as follows:
{ connection types (exists or not exists) of Table 1 in tables N and W } [ (in tables N and W)
select null
from { W table 1}
{ W connection type of table 1 and table 2} join { W table 2} on in a chart W connection condition of table 1 and table 2}
{ W connection type of tables 2 and 3} join { W table 3} on quick map W connection condition of tables 2 and 3} on
...
where
{ connection conditions in Table 1 in tables N and W }
)
There are two cases at this time: if the original table related to the expression to be converted is in W, adding a logic expression connected by an and in the where clause of the EXISTS sub-query SQL segment, wherein the logic expression is used for converting the field of the connection model appearing in the expression to be converted into a corresponding original model, the original field is obtained, the conversion is finished, and the SQL segment obtained in the step is the result of the expression to be converted; if the original table related to the expression to be converted is not in W, then carrying out (two);
and (II) adding an SQL segment connected by an and in the where clause of the obtained SQL segment innermost layer query, wherein the SQL segment is also obtained by the method, and the difference is that the table N is the rightmost table of the vector W.
The method for associating queries in the above embodiments is described in the present application, and the database query system applying the method is described in detail in the following embodiments.
Referring to fig. 6, an embodiment of the present application provides a database query system, including:
an obtaining module 601, configured to obtain data to be queried and a connection model library, where the connection model library includes at least one connection model, and the connection model is defined by an association relationship between at least two original tables;
the query module 602 is configured to construct a first query statement according to the data to be queried, and obtain at least one target connection model from the connection model library according to the first query statement;
the query statement conversion module 603 is further configured to convert the first query statement into a second query statement according to the target connection model, where the second query statement is a special language of a database management system, and the database management system is configured to manage a database in which at least two original tables are stored;
the query statement conversion module 603 is further configured to query the database management system according to the second query statement to obtain a query result.
In the embodiment of the application, because the DBAS packages the association relationships among the multiple tables in advance as the connection model, after the acquisition module 601 acquires the data to be queried and the connection model library, the query module 602 may directly query to obtain the target connection model by using the first query statement similar to the query single table, so that the DBAS is liberated from the construction of complex query statements; but also supports table associations by subqueries that are not supported by the database view while allowing the specification of filtering criteria for the subqueries; and the query sentence conversion module 603 converts the first query sentence into the second query sentence according to the target connection model, so that the second query sentence can be executed on the existing DBMS.
Optionally, as shown in fig. 7, in some embodiments of the present application, the database application system further includes:
a connection model building module 701, configured to obtain table information of at least two original tables, where the table information includes a table identifier and a table field;
the connection model building module 701 is further configured to build at least one connection model according to an association relationship between at least two original tables, where each connection model includes connection model basic information, connection model attributes, and a table relationship, the connection model basic information includes a connection model identifier and a connection model name, the connection model attributes include an attribute identifier, an attribute name, a table identifier of a corresponding original table, and a table field, and the table relationship includes a table relationship identifier, a table identifier of each original table, a connection mode of an adjacent original table, and a connection expression;
the connection model constructing module 701 is further configured to obtain a connection model library according to at least one connection model;
the connection model building module 701 is further configured to store the connection model library in the connection model repository;
or the like, or, alternatively,
the connection model constructing module 701 is further configured to obtain a connection model configuration file according to the connection model library.
In this embodiment, the connection model building module 701 obtains table information of at least two original tables, where the table information includes table identifiers and table fields, and builds at least one connection model according to an association relationship between the at least two original tables, where each connection model includes connection model basic information, connection model attributes, and table relationships, the connection model basic information includes connection model identifiers and connection model names, the connection model attributes include attribute identifiers, attribute names, and corresponding table identifiers and table fields of the original tables, and the table relationships include table relationship identifiers, table identifiers of each original table, connection modes and connection expressions of adjacent original tables, and the connection model building mode may be stored in a connection model repository or a connection model configuration file. As shown in fig. 5, for the meta model of the established connection model, the main description information is: connection model basic information: ID of the connection model; name of the connection model (used in constructing the first query statement); connection model attributes: the ID of the attribute, the name of the attribute (used in constructing the first query statement), the original table corresponding to the attribute (used in expanding the first query statement), and the field in the original table corresponding to the attribute (used in expanding the first query statement); table relationships (first query statement expansion use): the ID, LEFT table name, RIGHT table name, connection mode (different connection modes such as INNER JOIN, LEFT JOIN, RIGHT JOIN, EXISTS, IN, etc.) of the table relationship, and connection expression (connection expression of two adjacent tables, if the adjacent tables are associated by an outer key, this information can also be obtained according to metadata of the database table). Through the above packaging, the DBAS regards the connection model as a table or view to construct the first query statement without having to care about the internal composition of the connection model.
Alternatively, as shown in fig. 7, in some embodiments of the present application,
an obtaining module 601, specifically configured to receive data to be queried input by a user;
an obtaining module 601, configured to obtain a connection model library from a connection model repository;
or the like, or, alternatively,
the obtaining module 601 is further configured to receive a connection model configuration file, and obtain a connection model library from analysis of the connection model configuration file.
In this embodiment of the present application, after the connection model building module 701 builds the connection model library through the above embodiments, after the obtaining module 601 receives data to be queried input by a user, the connection model library may be obtained from a connection model repository, or the connection model library may be obtained by analyzing the connection model repository through receiving a connection model configuration file, and a specific obtaining manner is not limited.
Alternatively, as shown in fig. 7, in some embodiments of the present application,
the query module 602 is specifically configured to construct a first query statement according to the data to be queried and the query condition;
a query module 602, configured to query each connection model in the connection model library according to the first query statement;
the query module 602 is further configured to determine, when the table field of the original table corresponding to the connection model attribute of the queried connection model has data to be queried, that the queried connection model is a target connection model, where the target connection model is at least one.
In this embodiment of the application, the query module 602 constructs a first query statement according to the data to be queried, where the first query statement is a statement for querying a connection model, and may specifically be SQL, the query module 602 queries each connection model in the connection model library according to the first query statement, and when a table field of a corresponding original table in the connection model attribute of a queried connection model has the data to be queried, it indicates that the connection model is the original table having the data to be queried, and then the query module 602 determines that the connection model is a target connection model, and the target connection model is at least one.
Alternatively, as shown in fig. 7, in some embodiments of the present application,
the query statement conversion module 603 is further configured to determine whether the first query statement is a specific language of the database management system;
the query statement conversion module 603 is further configured to, when the first query statement is a language dedicated to the database management system, expand the first query statement according to the target connection model to obtain a second query statement;
the query statement conversion module 603 is further configured to, when the first query statement is not a specific language of the database management system, translate the first query statement according to the target connection model to obtain a second query statement.
In this embodiment of the application, when the query statement conversion module 603 converts the first query statement into the second query statement, it is further required to determine whether the first query statement is a specific language supported by the DBAS, for example, SQL supported by the DBAS, and the first query statement is SQL, which indicates that the first query statement is a specific language of the database management system, at this time, only the first query statement needs to be expanded, and if the specific language supported by the DBAS is not SQL and the first query statement is SQL, the first query statement needs to be translated according to a specific conversion manner to obtain the second query statement, and a specific translation rule is determined according to the specific language supported by the DBAS, and is not specifically described.
Alternatively, as shown in fig. 7, in some embodiments of the present application,
the query statement conversion module 603 is further configured to determine a table identifier and a table field of a target original table having data to be queried in the target connection model, where at least one target original table is provided;
the query statement conversion module 603 is further configured to determine an order of the target original table to obtain a table set;
the query statement conversion module 603 is further configured to convert the expression list of the first query statement into a second query statement according to the table relationship in the table set and the target connection model.
In the embodiment of the present application, because various DBMSs do not support the connection model at present, and the query must be completed by the DBMS, the query statement conversion module 603 needs to expand the query SQL (or other query DSL) into the SQL supported by the DBMS, and then deliver the SQL to the DBMS for query and obtaining a result, and the specific expansion method is as shown in the above steps 1 to 8, and is not specifically described.
The method for association query can be run on equipment using a server as an entity device, and specifically comprises the following steps:
referring to fig. 8, the present application provides a server, including:
a processor 801 and a memory 802, wherein the memory 802 may be used to store code executed by the processor 801;
the processor 801 and the memory 802 are connected by a bus system 803;
the processor 801 is configured to obtain data to be queried and a connection model library, where the connection model library includes at least one connection model, and the connection model is defined by an association relationship between at least two original tables;
the processor 801 is configured to construct a first query statement according to data to be queried, and obtain at least one target connection model from the connection model library according to the first query statement;
the processor 801 is further configured to convert the first query statement into a second query statement according to the target connection model, where the second query statement is a dedicated language of a database management system, and the database management system is configured to manage a database in which at least two original tables are stored;
the processor 801 is further configured to query the database management system according to the second query statement to obtain a query result.
In the embodiment of the present application, because the DBAS packages the association relationships among the multiple tables in advance as the connection model, after the transceiver 802 obtains the data to be queried and the connection model library, the processor 801 may directly query the connection model to obtain the target connection model by using the first query statement similar to the query single table, so that the DBAS is liberated from the construction of the complex query statement; but also supports table associations by subqueries that are not supported by the database view while allowing the specification of filtering criteria for the subqueries; and the processor 801 converts the first query statement into the second query statement according to the target connection model, so that the second query statement can be executed on the existing DBMS.
The present application also provides a computer-readable storage medium having stored therein instructions, which when run on a computer, cause the computer to execute the method of correlating queries described in the above embodiments.
The present application also provides a computer program product containing instructions which, when run on a computer, cause the computer to perform the method of correlating queries as described in the above embodiments.
In the above embodiments, all or part of the implementation may be realized by software, hardware, firmware, or any combination thereof. When implemented in software, it may be implemented in whole or in part in the form of a computer program product.
The computer program product includes one or more computer instructions. When loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the application to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can store or a data storage device, such as a server, a data center, etc., that includes one or more available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid State Disk (SSD)), among others.
It should be understood that, in the various embodiments of the present application, the sequence numbers of the above-mentioned processes do not imply any order of execution, and the order of execution of the processes should be determined by their functions and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
The above embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present application.

Claims (12)

1. A method of correlating queries, comprising:
acquiring data to be inquired and a connection model library, wherein the connection model library comprises at least one connection model, the connection model is defined by an incidence relation between at least two original tables, and the connection model comprises connection model basic information, connection model attributes and table relations;
constructing first query statements according to the data to be queried, and obtaining at least one target connection model from the connection model library according to the first query statements;
judging whether the first query statement is a special language of a database management system;
if so, expanding the first query statement according to the target connection model to obtain a second query statement;
if not, translating the first query statement according to the target connection model to obtain a second query statement, wherein the second query statement is a special language of a database management system, and the database management system is used for managing a database in which the at least two original tables are stored;
and querying the database management system according to the second query statement to obtain a query result.
2. The method of claim 1, wherein before the obtaining the data to be queried and connecting the model base, further comprising:
acquiring table information of at least two original tables, wherein the table information comprises table identification and table fields;
establishing at least one connection model according to the incidence relation of the at least two original tables, wherein the basic information of the connection model comprises a connection model identifier and a connection model name, the connection model attribute comprises an attribute identifier, an attribute name, a table identifier and a table field of the corresponding original table, and the table relation comprises a table relation identifier, a table identifier of each original table, a connection mode of adjacent original tables and a connection expression;
obtaining a connection model library according to the at least one connection model;
storing the connection model repository to a connection model repository;
or the like, or, alternatively,
and obtaining a connection model configuration file according to the connection model library.
3. The method of claim 2, wherein the obtaining the data to be queried and the connection model library comprises:
receiving data to be queried input by a user;
obtaining a connection model library from a connection model repository;
or the like, or a combination thereof,
and receiving a connection model configuration file, and analyzing the connection model configuration file to obtain a connection model library.
4. The method of claim 3, wherein the constructing a first query statement according to the data to be queried and obtaining a target connection model from the connection model library according to the first query statement comprises:
constructing a first query statement according to the data to be queried;
querying each connection model in the connection model library according to the first query statement;
and when the table field of the original table corresponding to the connection model attribute of the inquired connection model has the data to be inquired, determining that the inquired connection model is a target connection model, wherein the number of the target connection models is at least one.
5. The method of claim 1, wherein expanding the first query statement to obtain a second query statement according to the target connection model comprises:
determining a table identifier and a table field of a target original table with the data to be queried in the target connection model, wherein the number of the target original tables is at least one;
determining the sequence of the target original table to obtain a table set;
and expanding the first query statement into a second query statement according to the table set and the table relation in the target connection model.
6. A database application system, comprising:
the system comprises an acquisition module, a connection model library and a query module, wherein the acquisition module is used for acquiring data to be queried and the connection model library comprises at least one connection model, the connection model is obtained by defining an incidence relation between at least two original tables, and the connection model comprises connection model basic information, connection model attributes and table relations;
the query module is used for constructing a first query statement according to the data to be queried and obtaining at least one target connection model from the connection model library according to the first query statement;
the query statement conversion module is used for judging whether the first query statement is a special language of the database management system; when the first query statement is a special language of the database management system, the first query statement is expanded according to the target connection model to obtain a second query statement; the database management system is further configured to, when the first query statement is not a specific language of the database management system, translate the first query statement according to the target connection model to obtain a second query statement, where the second query statement is a specific language of the database management system, and the database management system is configured to manage a database in which the at least two original tables are stored;
the query statement conversion module is further configured to query the database management system according to the second query statement to obtain a query result.
7. The system of claim 6, wherein the database application system further comprises:
the connection model building module is used for obtaining table information of at least two original tables, and the table information comprises table identification and table fields;
the connection model building module is further configured to build at least one connection model according to the association relationship between the at least two original tables, where the basic information of the connection model includes a connection model identifier and a connection model name, the connection model attribute includes an attribute identifier, an attribute name, a table identifier and a table field of a corresponding original table, and the table relationship includes a table relationship identifier, a table identifier of each original table, a connection mode of an adjacent original table, and a connection expression;
the connection model construction module is also used for obtaining a connection model library according to the at least one connection model;
the connection model building module is further used for storing the connection model library into a connection model repository;
or the like, or, alternatively,
and the connection model construction module is also used for obtaining a connection model configuration file according to the connection model library.
8. The system of claim 7,
the acquisition module is specifically used for receiving data to be queried input by a user;
the acquisition module is further used for acquiring a connection model library from the connection model repository;
or the like, or, alternatively,
the acquisition module is further used for receiving the connection model configuration file and analyzing the connection model configuration file to obtain a connection model library.
9. The system of claim 8,
the query module is specifically used for constructing a first query statement according to the data to be queried and the query condition;
the query module is further configured to query each connection model in the connection model library according to the first query statement;
the query module is further configured to determine that the queried connection model is a target connection model when the table field of the original table corresponding to the connection model attribute of the queried connection model has the data to be queried, where the number of the target connection models is at least one.
10. The system of claim 9,
the query statement conversion module is further configured to determine a table identifier and a table field of a target original table having the data to be queried in the target connection model, where at least one target original table is provided;
the query statement conversion module is further configured to determine an order of the target original table to obtain a table set;
the query statement conversion module is further configured to convert the expression list of the first query statement into a second query statement according to the table set and the table relationship in the target connection model.
11. A server, comprising:
the processor and the memory, wherein the memory is used for storing codes executed by the processor;
the processor and the memory are connected through a bus system;
the processor is used for acquiring data to be queried and a connection model library, wherein the connection model library comprises at least one connection model, the connection model is defined by an incidence relation between at least two original tables, and the connection model comprises connection model basic information, connection model attributes and table relations;
the processor is used for constructing first query statements according to the data to be queried and obtaining at least one target connection model from the connection model library according to the first query statements;
the processor is further configured to determine whether the first query statement is a language specific to a database management system;
if so, expanding the first query statement according to the target connection model to obtain a second query statement;
if not, translating the first query statement according to the target connection model to obtain a second query statement, wherein the second query statement is a special language of a database management system, and the database management system is used for managing a database in which the at least two original tables are stored;
the processor is further configured to query the database management system according to the second query statement to obtain a query result.
12. A computer-readable storage medium comprising instructions that, when executed on a computer, cause the computer to perform the method of any one of claims 1 to 5.
CN201711487511.0A 2017-12-29 2017-12-29 Correlation query method, database application system and server Active CN110109951B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711487511.0A CN110109951B (en) 2017-12-29 2017-12-29 Correlation query method, database application system and server

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711487511.0A CN110109951B (en) 2017-12-29 2017-12-29 Correlation query method, database application system and server

Publications (2)

Publication Number Publication Date
CN110109951A CN110109951A (en) 2019-08-09
CN110109951B true CN110109951B (en) 2022-12-06

Family

ID=67482987

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711487511.0A Active CN110109951B (en) 2017-12-29 2017-12-29 Correlation query method, database application system and server

Country Status (1)

Country Link
CN (1) CN110109951B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110674177B (en) * 2019-09-30 2023-04-11 奇安信科技集团股份有限公司 Data query method and device, electronic equipment and storage medium
CN113806190A (en) * 2020-06-17 2021-12-17 华为技术有限公司 Method, device and system for predicting performance of database management system
CN111984671B (en) * 2020-07-27 2023-09-12 北京天健源达科技股份有限公司 Method for generating view script

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101093493A (en) * 2006-06-23 2007-12-26 国际商业机器公司 Speech conversion method for database inquiry, converter, and database inquiry system
CN101916261A (en) * 2010-07-28 2010-12-15 北京播思软件技术有限公司 Data partitioning method for distributed parallel database system
CN103092998A (en) * 2013-02-21 2013-05-08 用友软件股份有限公司 Data query system and data query method
CN107515887A (en) * 2017-06-29 2017-12-26 中国科学院计算机网络信息中心 A kind of interactive query method suitable for a variety of big data management systems

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20120317104A1 (en) * 2011-06-13 2012-12-13 Microsoft Corporation Using Aggregate Location Metadata to Provide a Personalized Service

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101093493A (en) * 2006-06-23 2007-12-26 国际商业机器公司 Speech conversion method for database inquiry, converter, and database inquiry system
CN101916261A (en) * 2010-07-28 2010-12-15 北京播思软件技术有限公司 Data partitioning method for distributed parallel database system
CN103092998A (en) * 2013-02-21 2013-05-08 用友软件股份有限公司 Data query system and data query method
CN107515887A (en) * 2017-06-29 2017-12-26 中国科学院计算机网络信息中心 A kind of interactive query method suitable for a variety of big data management systems

Also Published As

Publication number Publication date
CN110109951A (en) 2019-08-09

Similar Documents

Publication Publication Date Title
US10572484B2 (en) Duplicate reduction or elimination with hash join operations
US9317557B2 (en) Answering relational database queries using graph exploration
US9798772B2 (en) Using persistent data samples and query-time statistics for query optimization
US9411840B2 (en) Scalable data structures
CN110096494B (en) Profiling data using source tracking
US8332389B2 (en) Join order for a database query
CN108369587B (en) Creating tables for exchange
US11436225B2 (en) Database hierarchy-independent data drilling
US9298829B2 (en) Performing a function on rows of data determined from transitive relationships between columns
US20230177078A1 (en) Conversational Database Analysis
US8417690B2 (en) Automatically avoiding unconstrained cartesian product joins
US20140046928A1 (en) Query plans with parameter markers in place of object identifiers
EP3267330A1 (en) Query rewriting in a relational data harmonization framework
US10296542B2 (en) Integration database framework
US20070083573A1 (en) Reduction of join operations when archiving related database tables
CN110109951B (en) Correlation query method, database application system and server
WO2019161679A1 (en) Data processing method and device for use in online analytical processing
US9063957B2 (en) Query systems
Mpinda et al. Evaluation of graph databases performance through indexing techniques
Jiang et al. Effective community search over large star-schema heterogeneous information networks
US8396858B2 (en) Adding entries to an index based on use of the index
CN105760418A (en) Method And System For Carrying Out Cross Column Searching On Relational Database Table
CN114138725A (en) Hierarchical log storage processing method
US20160210324A1 (en) Flexible data format for database management systems
WO2024082881A2 (en) Database query method and apparatus

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
TA01 Transfer of patent application right

Effective date of registration: 20200210

Address after: 518129 Bantian HUAWEI headquarters office building, Longgang District, Guangdong, Shenzhen

Applicant after: HUAWEI TECHNOLOGIES Co.,Ltd.

Address before: 210012 HUAWEI Nanjing base, 101 software Avenue, Yuhuatai District, Jiangsu, Nanjing

Applicant before: HUAWEI SOFTWARE TECHNOLOGIES Co.,Ltd.

TA01 Transfer of patent application right
GR01 Patent grant
GR01 Patent grant