CN110516010B - Database entity relation model extraction method and device based on adjacency list - Google Patents

Database entity relation model extraction method and device based on adjacency list Download PDF

Info

Publication number
CN110516010B
CN110516010B CN201910799710.8A CN201910799710A CN110516010B CN 110516010 B CN110516010 B CN 110516010B CN 201910799710 A CN201910799710 A CN 201910799710A CN 110516010 B CN110516010 B CN 110516010B
Authority
CN
China
Prior art keywords
vertex
turning
reading
edge
key
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
CN201910799710.8A
Other languages
Chinese (zh)
Other versions
CN110516010A (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.)
Inspur Software Group Co Ltd
Original Assignee
Inspur Software Group 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 Inspur Software Group Co Ltd filed Critical Inspur Software Group Co Ltd
Priority to CN201910799710.8A priority Critical patent/CN110516010B/en
Publication of CN110516010A publication Critical patent/CN110516010A/en
Application granted granted Critical
Publication of CN110516010B publication Critical patent/CN110516010B/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/25Integrating or interfacing systems involving database management systems
    • G06F16/258Data format conversion from or to a database
    • 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/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases
    • G06F16/288Entity relationship models
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention provides a method and a device for extracting a database entity relation model based on an adjacency list, which belong to the technical fields of databases, entity relation models and adjacency lists, and comprise the following steps: s1: the database table structure is standardized; s2: constructing a vertex table of the adjacency table; s3: constructing an edge table of the adjacency table; s4: the type of relationship between the table structures is calculated. Meanwhile, the invention also provides a database entity relation model extraction device based on the adjacency list for realizing the method. The theoretical basis of the invention is that the association relation and the relation type between the table structures are deduced according to the main key and the external key of the table structures, so that a database entity relation model is obtained and stored by using an adjacent table. The entity relation model can be directly obtained, and the actual requirements of dynamic ontology creation, database structure conversion and the like are supported.

Description

Database entity relation model extraction method and device based on adjacency list
Technical Field
The present invention relates to a database, an entity relationship model, and an adjacency list technology, and in particular, to a method and an apparatus for extracting a database entity relationship model based on an adjacency list.
Background
The entity relation model belongs to a conceptual model in database design, represents common concepts of the information world and the relation between the common concepts, is a first-layer abstraction from the real world to the information world, is semantic description of the data model, and has strong semantic expression capability.
Representing concepts and relationships in the entity relationship model by adopting different types of data structures to obtain different types of logic models, wherein the logic models comprise: hierarchical models, mesh models, relational models, and object-oriented models. Among them, the widely used relational model uses a two-dimensional table as a basic data structure, and a main key and an external key are used to represent concepts and relations, respectively. The logic model is imported into database modeling software, and a corresponding database system can be generated. Therefore, the entity relationship model plays an important role in database modeling.
In the field of knowledge engineering, a dynamic body representing knowledge needs to be extracted from an existing database, so that a flexible and changeable data model is built, and data management and multi-source data integration are facilitated. The dynamic body is composed of an object, an attribute and a relation 3 part, and has similarity with the entity relation model; therefore, after the entity relation model is extracted from the database, the required dynamic body can be formed through a small amount of correction and perfection. Thus, the entity relationship model is the basis for building dynamic ontologies.
The traditional relation model is not necessarily the optimal data structure of big data in a database, and the hierarchical model or the mesh model is more suitable for representing the hierarchical relation or the complex relation among entities, and the relation model needs to be converted into the hierarchical model or the mesh model. The entity relation model is used as an intermediate medium, and conversion is a feasible scheme. Thus, the entity-relationship model is the basis for database structure transformations.
However, some early informatization systems, due to the overlong time, cannot find the entity relationship model when the initial database is modeled, and bring invariance to later maintenance; some database systems are maintained by different teams, but entity relation models cannot be updated in time, and the later upgrading and transformation are not facilitated; in addition, when multiple databases are integrated, even if the entity relation model of each database is known, the entity relation model of a new database after integration is not easy to obtain, and the whole planning is not facilitated.
In order to solve the above problems, a reverse engineering method is required to automatically extract the corresponding entity relationship model from the database.
At present, some database software (such as My SQL and Oracle) can extract an ER diagram, but the entity relation model serving as intermediate data is not easy to obtain, and the actual requirements of building a dynamic ontology, database structure conversion and the like cannot be supported.
Disclosure of Invention
In order to solve the technical problems, the invention provides a database entity relation model extraction method based on an adjacency list, which can directly acquire an entity relation model and support the actual requirements of dynamic ontology creation, database structure conversion and the like.
The technical scheme of the invention is as follows:
the database entity relation model extraction method based on the adjacency list is characterized by comprising the following steps of:
s1: the database table structure is standardized;
s2: constructing a vertex table of the adjacency table;
s3: constructing an edge table of the adjacency table;
s4: the type of relationship between the table structures is calculated.
In the step S1, each table structure of the database is represented as a table composed of triples (attribute names, primary keys, foreign keys), wherein "attribute names" represent attribute names, "primary keys" and "foreign keys" represent whether the attribute is a primary key and a foreign key, respectively, Y represents yes, and N represents no.
In the step S2, the method specifically includes:
s21: initializing a vertex table to be empty;
s22: reading a first standardized table structure TS;
s23: constructing a vertex VA corresponding to TS, and adding the vertex VA into a vertex table; in step S23, specifically, the method includes:
s231: newly-built vertex VA;
s232: setting the table name of the table structure TS as the table name of the vertex VA;
s233: reading a first attribute TA of the table structure TS;
s234: adding the attribute name of TA into the attribute name array of the vertex VA;
s235: if the "primary key" value of TA is Y, go to S236, otherwise go to S237;
s236: adding an attribute name of TA into a main key of the vertex VA;
s237: if the "foreign key" value of TA is Y, go to S238, otherwise go to S239;
s238: adding the attribute name of TA into the foreign key of the vertex VA;
s239: judging whether the attribute is read completely, if not, turning to S23A, otherwise turning to S23B;
S23A: reading the next attribute TA, and turning to S234;
S23B: vertex VA is added to the vertex table.
S24: judging whether the table structure is read completely, if not, turning to S25, otherwise turning to S26;
s25: reading the next table structure TS, and turning to S23;
s26: returning the generated vertex table.
In the step S3, the method specifically includes:
s31: initializing an edge table to be empty;
s32: reading a first vertex VA of the vertex table;
s33: constructing an edge set corresponding to the vertex VA; in step S33, specifically, the method includes:
s331: counting the attribute number Q of the vertex VA external key;
s332: initializing edge set to be empty, processing an external key set ProcedKey to be empty, and determining attribute number K=Q of main keys to be tested;
s333: initializing the number of times t=0 of the tested external keys, wherein the tested external key set TestKeySet is empty;
s334: judging whether t is equal to C (Q, K), if so, turning to S33D, otherwise turning to S335;
s335: k attributes are selected from the vertex VA external keys to form a main key set TestKey to be tested;
s336: if the TestKey is not a subset of TestKeySet, go to S337, otherwise go to S335;
s337: updating the tested foreign key times t=t+1;
s338: if the TestKey is not a subset of the ProcedKey, then go to S339, otherwise go to S334;
s339: traversing the vertex table, if the primary key of a vertex VB is a TestKey, turning to S33A, otherwise turning to S334;
S33A: generating a pointer Pt_VB pointing to VB;
S33B: adding Pt_VB to the tail of a pointer linked list of the edge set;
S33C: updating ProcedKey=ProcedKey U TestKey, turning to S334;
S33D: updating the attribute number K=K-1 of the main key to be tested;
S33E: if K is greater than 0, go to S333, otherwise go to S33F;
S33F: and returning the generated edge set.
S34: adding the edge set into an edge table;
s35: judging whether the vertex table is read completely, if not, turning to S36, otherwise turning to S37;
s36: reading the next vertex VA, and turning to S33;
s37: returning the generated edge table.
In the step S4, the method specifically includes:
s41: reading a first vertex VA of the vertex table;
s42: reading an edge set corresponding to the vertex VA;
s43: calculating the relation type between the VA and the edge set corresponding table structure, and generating a new edge set; in step S43, specifically, the method includes:
s431: initializing EdgeSetRT to be null;
s432: reading a table structure TSA corresponding to VA;
s433: reading a first element PT_VB in the edge set;
s434: reading a table structure TSB corresponding to PT_VB;
s435: calculating a relation type RT_VB between the TSA and the TSB; in step S435, specifically, the method includes:
s4351: reading a main key Prike_A and an external key ForKey_A of the TSA;
s4352: reading a main key Prike_B and an external key ForKey_B of the TSB;
s4353: calculating TSA main key and TSB external key membership PKA_in_FKB; in step S4353, the method specifically includes:
s43531: if the TSA primary key is a subset of the TSB foreign key, go to S43532, otherwise go to S43533;
s43532: pka_in_fkb=1, go to S43534;
S43533:PKA_in_FKB=0;
s43534: return PKA_in_FKB.
S4354: calculating TSB primary key and TSA external key membership PKB_in_ FKA; in step S4354, the method specifically includes:
s43541: if the TSB primary key is a subset of the TSA foreign key, then go to S43542, else go to S43543;
s43542: pkb_in_ FKA =1, transition S43544;
S43543:PKB_in_FKA=0;
s43544: pkb_in_ FKA is returned.
S4355: calculating RT_VB according to PKA_in_FKB and PKB_in_ FKA; in step S4355, the method specifically includes:
s43551: initializing RT_VB= -1;
s43552: if pka_in_fkb= 1 and pkb_in_ FKA = 1, then go to S43553, otherwise go to S43554;
s43553: rt_vb=1, turning to S4355A;
s43554: if pka_in_fkb= 1 and pkb_in_ FKA = 0, then go to S43555, otherwise go to S43556
S43555: rt_vb=2, turning to S4355A;
s43556: if pka_in_fkb= 0 and pkb_in_ FKA = 1, then go to S43557, otherwise go to S43558;
s43557: rt_vb=3, turning to S4355A;
s43558: if pka_in_fkb= 0 and pkb_in_ FKA = 0, then go to S43559, otherwise go to S4355A;
S43559:RT_VB=4;
S4355A: the relationship type rt_vb is returned.
S4356: the relationship type rt_vb is returned.
S436: adding { PT_VB, RT_VB } to the end of the pointer chain table of the EdgeSetRT;
s437: judging whether the elements in the edge set are read completely, if not, turning to S438, otherwise turning to S439;
s438: reading the next element PT_VB, and turning to S434;
s439: returning the generated edge set EdgeSetRT.
S44: deleting edge set in the edge table;
s45: adding an edge set EdgeSetRT to an edge table;
s46: judging whether the vertex table is read completely, if not, turning to S47, otherwise turning to S48;
s47: reading the next vertex VA, and turning to S42;
s48: and returning the updated edge table.
The invention also discloses a database entity relation model extraction device based on the adjacency list, which comprises:
a table structure normalizing means M1 for expressing each table structure of the database as a table composed of triples (attribute names, primary keys, foreign keys);
vertex table construction means M2 for constructing a vertex table of the adjacency table;
an edge table constructing section M3 for constructing an edge table of the adjacency table;
a table structure relationship type calculating section M4 for calculating a relationship type between table structures.
Wherein, the liquid crystal display device comprises a liquid crystal display device,
the vertex table construction part M2 specifically includes:
vertex table initializing means M21 for initializing a vertex table;
a table structure reading section M22 for reading the standardized table structure;
and the vertex construction component M23 is used for constructing the vertex corresponding to the table structure and adding the vertex into the vertex table.
The side table construction part M3 specifically includes:
an edge table initializing section M31 for initializing an edge table;
a class 1 vertex reading unit M32 for reading vertices in the adjacency list for which no corresponding edge set has been constructed;
an edge set constructing unit M33, configured to construct an edge set corresponding to the vertex, and add the edge set to the vertex table.
The table structural relation type calculating section M4 specifically includes:
class 2 vertex reading means M41 for reading vertices in the adjacency list for which the table structure relationship type has not been calculated yet;
an edge set reading unit M42 for reading the edge set corresponding to the vertex;
a relationship type calculating means M43 for calculating a relationship type between the vertex and the corresponding edge set table structure;
an edge set updating part M44, configured to generate a new edge set according to the calculated relationship type, and delete and replace the original edge set.
The invention has the beneficial effects that
The association relation and the relation type between the table structures are deduced according to the main key and the external key of the table structures, so that a database entity relation model is obtained, and the database entity relation model is stored by using the adjacency table, so that the operation is simple and the speed is high, the problem that the entity relation model is not easy to obtain is solved, the entity relation model can be directly obtained, and the actual requirements of dynamic ontology creation, database structure conversion and the like are supported.
Drawings
FIG. 1 is a flow chart of the steps of the adjacency list-based database entity relationship model extraction method of the present invention;
FIG. 2 is a detailed step flow chart of step S2;
fig. 3 is a specific step flowchart of step S23;
FIG. 4 is a vertex table obtained by processing tables 1 to 5;
FIG. 5 is a detailed structure of the corresponding vertices of the teacher lecture table;
FIG. 6 is a detailed step flow chart of step S3;
fig. 7 is a specific step flowchart of step S33;
FIG. 8 is an adjacency table consisting of vertex tables and edge tables;
FIG. 9 is a student score table edge set of add relationship types;
FIG. 10 is a detailed step flow chart of step S4;
fig. 11 is a specific step flowchart of step S43;
fig. 12 is a specific step flowchart of step S435;
fig. 13 is a specific step flowchart of step S4353;
fig. 14 is a specific step flowchart of step S4354;
fig. 15 is a specific step flowchart of step S4355;
FIG. 16 is an adjacency table with relationship types;
FIG. 17 is a block diagram of the structure of the adjacency list-based database entity relationship model extraction apparatus of the present invention;
fig. 18 is a block diagram of the structure of the vertex table construction part M2;
fig. 19 is a block diagram of the structure of the edge table constructing section M3;
fig. 20 is a block diagram of the table structural relationship type calculating section M4.
Detailed Description
For the purpose of making the objects, technical solutions and advantages of the embodiments of the present invention more apparent, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are some embodiments of the present invention, but not all embodiments, and all other embodiments obtained by those skilled in the art without making any inventive effort based on the embodiments of the present invention are within the scope of protection of the present invention.
The invention is realized by the following scheme: a database entity relation model extraction method based on an adjacency list, as shown in fig. 1, comprises the following steps:
s1: the database table structure is standardized;
this step represents each table structure of the database as a table made up of triples (attribute names, primary keys, foreign keys), where "attribute names" represent attribute names, "primary keys" and "foreign keys" represent whether the attribute is a primary key and a foreign key, respectively, and Y represents yes and N represents no.
Let a database contain 5 tables, the structure is as follows:
A. student watch: the method comprises the following steps: the number, the name, the gender, the birth date and the class of the student, wherein the number is a primary key;
B. curriculum schedule: the method comprises the following steps: course number, course name, course time, wherein course number is the primary key;
C. student score table: the method comprises the following steps: the number of the school, the number of the course and the score, wherein the number of the school and the number of the course are primary keys, and the number of the school and the number of the course are external keys from other tables respectively;
D. teaching teachers: the method comprises the following steps: teacher number, teacher name, teacher gender, teacher birth date, teacher title and teacher department, wherein the teacher number is a primary key;
E. teacher teaching school timetable: the method comprises the following steps: course number, teacher number, teaching place, teaching time, wherein (course number, teacher number) is the primary key, course number and teacher number are the foreign keys from other tables respectively.
The structures of the 5 tables were standardized, and the results are shown in tables 1 to 5.
Table 1 student Table Structure standardization
Attribute name Main key External key
Number of school Y N
Student name N N
Sex of student N N
Student birth date N N
Class of student N N
Table 2 curriculum schedule structure normalization
Attribute name Main key External key
Course numbering Y N
Course name N N
School time of course N N
Table 3 student score Structure normalization
Attribute name Main key External key
Number of school Y Y
Course numbering Y Y
Achievement N N
Table 4 teacher Table structure standardization
Attribute name Main key External key
Teacher numbering Y N
Teacher name N N
Sex of teacher N N
Teacher date of birth N N
Teacher's title N N
Teacher's department N N
Table 5 teacher teaching table structure standardization
Attribute name Main key External key
Course numbering Y Y
Teacher numbering Y Y
Teaching place N N
Teaching time N N
S2: constructing a vertex table of the adjacency table;
the vertex table is a one-dimensional array, and records each table structure information, including table names, attribute name arrays, a main key and an external key; the attribute name array element stores the name of each attribute, the main key and the external key are arrays, and the attribute names corresponding to the main key and the external key are respectively stored.
Further, as shown in fig. 2, the step S2 specifically includes:
s21: initializing a vertex table to be empty;
s22: reading a first standardized table structure TS;
s23: constructing a vertex VA corresponding to TS, and adding the vertex VA into a vertex table;
further, as shown in fig. 3, the step S23 specifically includes:
s231: newly-built vertex VA;
s232: setting the table name of the table structure TS as the table name of the vertex VA;
s233: reading a first attribute TA of the table structure TS;
s234: adding the attribute name of TA into the attribute name array of the vertex VA;
s235: if the "primary key" value of TA is Y, go to S236, otherwise go to S237;
s236: adding an attribute name of TA into a main key of the vertex VA;
s237: if the "foreign key" value of TA is Y, go to S238, otherwise go to S239;
s238: adding the attribute name of TA into the foreign key of the vertex VA;
s239: judging whether the attribute is read completely, if not, turning to S23A, otherwise turning to S23B;
S23A: reading the next attribute TA, and turning to S234;
S23B: vertex VA is added to the vertex table.
S24: judging whether the table structure is read completely, if not, turning to S25, otherwise turning to S26;
s25: reading the next table structure TS, and turning to S23;
s26: returning the generated vertex table.
The vertex tables obtained by performing the above operations on tables 1 to 5 are shown in fig. 4.
In fig. 4, each row represents 1 vertex corresponding to a table structure in the order from top to bottom. Each row is divided into a left part and a right part, wherein the left side is vertex information and comprises a table name, an attribute name array (shown by AL), a main key (shown by PK) and an external key (shown by FK); the right side is the edge set corresponding to the vertex, which is initially empty. For the sake of brevity, we list only the detailed structure of the 3 rd vertex of fig. 4, as shown in fig. 5, and the detailed structure of the other vertices is similar.
S3: constructing an edge table of the adjacency table;
in ER diagram represented by adjacency list, vertex record list structure information, if there is association relation between two list structures, then connecting an edge between their corresponding vertices; for each vertex in the vertex set, storing the storage position of another vertex in the vertex edge by adopting a pointer linked list, so as to form the edge set of the vertex; the set of all vertex edge sets is referred to as the edge table of the adjacency table.
Further, as shown in fig. 6, the step S3 specifically includes:
s31: initializing an edge table to be empty;
s32: reading a first vertex VA of the vertex table;
s33: constructing an edge set corresponding to the vertex VA;
further, as shown in fig. 7, the step S33 specifically includes:
s331: counting the attribute number Q of the vertex VA external key;
s332: initializing edge set to be empty, processing an external key set ProcedKey to be empty, and determining attribute number K=Q of main keys to be tested;
s333: initializing the number of times t=0 of the tested external keys, wherein the tested external key set TestKeySet is empty;
s334: judging whether t is equal to C (Q, K), if so, turning to S33D, otherwise turning to S335;
s335: k attributes are selected from the vertex VA external keys to form a main key set TestKey to be tested;
s336: if the TestKey is not a subset of TestKeySet, go to S337, otherwise go to S335;
s337: updating the tested foreign key times t=t+1;
s338: if the TestKey is not a subset of the ProcedKey, then go to S339, otherwise go to S334;
s339: traversing the vertex table, if the primary key of a vertex VB is a TestKey, turning to S33A, otherwise turning to S334;
S33A: generating a pointer Pt_VB pointing to VB;
S33B: adding Pt_VB to the tail of a pointer linked list of the edge set;
S33C: updating ProcedKey=ProcedKey U TestKey, turning to S334;
S33D: updating the attribute number K=K-1 of the main key to be tested;
S33E: if K is greater than 0, go to S333, otherwise go to S33F;
S33F: and returning the generated edge set.
S34: adding the edge set into an edge table;
s35: judging whether the vertex table is read completely, if not, turning to S36, otherwise turning to S37;
s36: reading the next vertex VA, and turning to S33;
s37: returning the generated edge table.
The vertex table shown in fig. 4 is subjected to the above operation, and an edge table is obtained, and a complete adjacent table is formed by the vertex table and the edge table, as shown in fig. 8.
In fig. 8, the right pointer of the vertex points to the corresponding edge set, which is a linked list formed by the connected vertex pointers, and for convenience of representation, the following vertex pointers are defined:
A. pt_vbs: a pointer to the vertex of the "student table";
B. pt_vbc: a pointer to the "curriculum" vertex;
C. pt_vbsc: a pointer to the vertex of the student score table;
D. pt_vbt: a pointer to the vertex of the teacher's table;
E. pt_vbtc: a pointer to the vertex of the teacher teaching form;
in fig. 8, the edge set corresponding to the vertex of the "curriculum schedule" includes pt_vbsc and pt_vbtc, and the relationship between the "student score list" and the "teacher teaching desk" is shown.
S4: the type of relationship between the table structures is calculated.
To represent the relationship type, a new field needs to be added in the adjacency list element, as shown in FIG. 9.
In contrast to fig. 8, the added field rt_vbs in fig. 9 indicates the relationship type between the student score table and the student table, and rt_vbc indicates the relationship type between the student score table and the curriculum table. For ease of representation, we define the range of relationship type values to be 1, 2, 3, 4, respectively 1: 1. 1: n, M: 1. m: n.
Further, as shown in fig. 10, the step S4 specifically includes:
s41: reading a first vertex VA of the vertex table;
s42: reading an edge set corresponding to the vertex VA;
s43: calculating the relation type between the VA and the edge set corresponding table structure, and generating a new edge set;
further, as shown in fig. 11, the step S43 specifically includes:
s431: initializing EdgeSetRT to be null;
s432: reading a table structure TSA corresponding to VA;
s433: reading a first element PT_VB in the edge set;
s434: reading a table structure TSB corresponding to PT_VB;
s435: calculating a relation type RT_VB between the TSA and the TSB;
further, as shown in fig. 12, the step S435 specifically includes:
s4351: reading a main key Prike_A and an external key ForKey_A of the TSA;
s4352: reading a main key Prike_B and an external key ForKey_B of the TSB;
s4353: calculating TSA main key and TSB external key membership PKA_in_FKB;
further, as shown in fig. 13, the step S4353 specifically includes:
s43531: if the TSA primary key is a subset of the TSB foreign key, go to S43532, otherwise go to S43533;
s43532: pka_in_fkb=1, go to S43534;
S43533:PKA_in_FKB=0;
s43534: return PKA_in_FKB.
S4354: calculating TSB primary key and TSA external key membership PKB_in_ FKA;
further, as shown in fig. 14, the step S4354 specifically includes:
s43541: if the TSB primary key is a subset of the TSA foreign key, then go to S43542, else go to S43543;
s43542: pkb_in_ FKA =1, transition S43544;
S43543:PKB_in_FKA=0;
s43544: pkb_in_ FKA is returned.
S4355: calculating RT_VB according to PKA_in_FKB and PKB_in_ FKA;
further, as shown in fig. 15, the step S4355 specifically includes:
s43551: initializing RT_VB= -1;
s43552: if pka_in_fkb= 1 and pkb_in_ FKA = 1, then go to S43553, otherwise go to S43554;
s43553: rt_vb=1, turning to S4355A;
s43554: if pka_in_fkb= 1 and pkb_in_ FKA = 0, then go to S43555, otherwise go to S43556
S43555: rt_vb=2, turning to S4355A;
s43556: if pka_in_fkb= 0 and pkb_in_ FKA = 1, then go to S43557, otherwise go to S43558;
s43557: rt_vb=3, turning to S4355A;
s43558: if pka_in_fkb= 0 and pkb_in_ FKA = 0, then go to S43559, otherwise go to S4355A;
S43559:RT_VB=4;
S4355A: the relationship type rt_vb is returned.
S4356: the relationship type rt_vb is returned.
S436: adding { PT_VB, RT_VB } to the end of the pointer chain table of the EdgeSetRT;
s437: judging whether the elements in the edge set are read completely, if not, turning to S438, otherwise turning to S439;
s438: reading the next element PT_VB, and turning to S434;
s439: returning the generated edge set EdgeSetRT.
S44: deleting edge set in the edge table;
s45: adding an edge set EdgeSetRT to an edge table;
s46: judging whether the vertex table is read completely, if not, turning to S47, otherwise turning to S48;
s47: reading the next vertex VA, and turning to S42;
s48: and returning the updated edge table.
The adjacency list shown in fig. 8 is subjected to the above operation, and an adjacency list with a relationship type can be obtained as shown in fig. 16.
In fig. 16, the relationship type of the "curriculum" vertex corresponding to the edge set element pt_vbsc (or pt_vbtc) has a value of 2, which indicates that the relationship type between the "curriculum" and the "student score table" (or "teacher teaching table") is 1: n.
The invention also provides a database entity relation model extraction device based on the adjacency list, as shown in fig. 17, comprising:
a table structure normalizing means M1 for expressing each table structure of the database as a table composed of triples (attribute names, primary keys, foreign keys);
a vertex table construction unit M2 for constructing a vertex table of an adjacency table, as shown in fig. 18, the vertex table construction unit M2 comprising:
vertex table initializing means M21 for initializing a vertex table;
a table structure reading section M22 for reading the standardized table structure;
and the vertex construction component M23 is used for constructing the vertex corresponding to the table structure and adding the vertex into the vertex table.
An edge table constructing section M3 for constructing an edge table of an adjacent table, as shown in fig. 19, the edge table constructing section M3 including:
an edge table initializing section M31 for initializing an edge table;
a class 1 vertex reading unit M32 for reading vertices in the adjacency list for which no corresponding edge set has been constructed;
an edge set constructing unit M33, configured to construct an edge set corresponding to the vertex, and add the edge set to the vertex table.
A table structure relationship type calculating section M4 for calculating relationship types between table structures, as shown in fig. 20, the table structure relationship type calculating section M4 including:
class 2 vertex reading means M41 for reading vertices in the adjacency list for which the table structure relationship type has not been calculated yet;
an edge set reading unit M42 for reading the edge set corresponding to the vertex;
a relationship type calculating means M43 for calculating a relationship type between the vertex and the corresponding edge set table structure; an edge set updating part M44, configured to generate a new edge set according to the calculated relationship type, and delete and replace the original edge set.
The foregoing description is only illustrative of the preferred embodiments of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.

Claims (3)

1. A database entity relation model extraction method based on adjacency list is characterized in that,
the method comprises the following steps:
s1: the database table structure is standardized;
s2: constructing a vertex table of the adjacency table;
s3: constructing an edge table of the adjacency table;
s4: calculating the relationship type between the table structures;
the step S2 specifically includes:
s21: initializing a vertex table to be empty;
s22: reading a first standardized table structure TS;
s23: constructing a vertex VA corresponding to TS, and adding the vertex VA into a vertex table;
the method specifically comprises the following steps:
s231: newly-built vertex VA;
s232: setting the table name of the table structure TS as the table name of the vertex VA;
s233: reading a first attribute TA of the table structure TS;
s234: adding the attribute name of TA into the attribute name array of the vertex VA;
s235: if the "primary key" value of TA is Y, go to S236, otherwise go to S237;
s236: adding an attribute name of TA into a main key of the vertex VA;
s237: if the "foreign key" value of TA is Y, go to S238, otherwise go to S239;
s238: adding the attribute name of TA into the foreign key of the vertex VA;
s239: judging whether the attribute is read completely, if not, turning to S23A, otherwise turning to S23B;
S23A: reading the next attribute TA, and turning to S234;
S23B: adding vertex VA to the vertex table;
s24: judging whether the table structure is read completely, if not, turning to S25, otherwise turning to S26;
s25: reading the next table structure TS, and turning to S23;
s26: returning the generated vertex table;
the step S3 specifically includes:
s31: initializing an edge table to be empty;
s32: reading a first vertex VA of the vertex table;
s33: constructing an edge set corresponding to the vertex VA;
s331: counting the attribute number Q of the vertex VA external key;
s332: initializing edge set to be empty, processing an external key set ProcedKey to be empty, and determining attribute number K=Q of main keys to be tested;
s333: initializing the number of times t=0 of the tested external keys, wherein the tested external key set TestKeySet is empty;
s334: judging whether t is equal to C (Q, K), if so, turning to S33D, otherwise turning to S335;
s335: k attributes are selected from the vertex VA external keys to form a main key set TestKey to be tested;
s336: if the TestKey is not a subset of TestKeySet, go to S337, otherwise go to S335;
s337: updating the tested foreign key times t=t+1;
s338: if the TestKey is not a subset of the ProcedKey, then go to S339, otherwise go to S334;
s339: traversing the vertex table, if the primary key of a vertex VB is a TestKey, turning to S33A, otherwise turning to S334;
S33A: generating a pointer Pt_VB pointing to VB;
S33B: adding Pt_VB to the tail of a pointer linked list of the edge set;
S33C: updating ProcedKey=ProcedKey U TestKey, turning to S334;
S33D: updating the attribute number K=K-1 of the main key to be tested;
S33E: if K is greater than 0, go to S333, otherwise go to S33F;
S33F: returning the generated edge set;
s34: adding the edge set into an edge table;
s35: judging whether the vertex table is read completely, if not, turning to S36, otherwise turning to S37;
s36: reading the next vertex VA, and turning to S33;
s37: returning the generated edge table
The step S4 specifically includes:
s41: reading a first vertex VA of the vertex table;
s42: reading an edge set corresponding to the vertex VA;
s43: calculating the relation type between the VA and the edge set corresponding table structure, and generating a new edge set;
s431: initializing EdgeSetRT to be null;
s432: reading a table structure TSA corresponding to VA;
s433: reading a first element PT_VB in the edge set;
s434: reading a table structure TSB corresponding to PT_VB;
s435: calculating a relation type RT_VB between the TSA and the TSB;
s4351: reading a main key Prike_A and an external key ForKey_A of the TSA;
s4352: reading a main key Prike_B and an external key ForKey_B of the TSB;
s4353: calculating TSA main key and TSB external key membership PKA_in_FKB;
s43531: if the TSA primary key is a subset of the TSB foreign key, go to S43532, otherwise go to S43533;
s43532: pka_in_fkb=1, go to S43534;
S43533:PKA_in_FKB=0;
s43534: returning PKA_in_FKB;
s4354: calculating TSB primary key and TSA external key membership PKB_in_ FKA;
s43541: if the TSB primary key is a subset of the TSA foreign key, then go to S43542, else go to S43543;
s43542: pkb_in_ FKA =1, transition S43544;
S43543:PKB_in_FKA=0;
s43544: return pkb_in_ FKA;
s4355: calculating RT_VB according to PKA_in_FKB and PKB_in_ FKA;
s43551: initializing RT_VB= -1;
s43552: if pka_in_fkb= 1 and pkb_in_ FKA = 1, then go to S43553, otherwise go to S43554;
s43553: rt_vb=1, turning to S4355A;
s43554: if pka_in_fkb= 1 and pkb_in_ FKA = 0, then go to S43555, otherwise go to S43556
S43555: rt_vb=2, turning to S4355A;
s43556: if pka_in_fkb= 0 and pkb_in_ FKA = 1, then go to S43557, otherwise go to S43558;
s43557: rt_vb=3, turning to S4355A;
s43558: if pka_in_fkb= 0 and pkb_in_ FKA = 0, then go to S43559, otherwise go to S4355A;
S43559:RT_VB=4;
S4355A: returning a relationship type RT_VB;
s4356: returning a relationship type RT_VB;
s436: adding { PT_VB, RT_VB } to the end of the pointer chain table of the EdgeSetRT;
s437: judging whether the elements in the edge set are read completely, if not, turning to S438, otherwise turning to S439;
s438: reading the next element PT_VB, and turning to S434;
s439: returning the generated edge set EdgeSetRT;
s44: deleting edge set in the edge table;
s45: adding an edge set EdgeSetRT to an edge table;
s46: judging whether the vertex table is read completely, if not, turning to S47, otherwise turning to S48;
s47: reading the next vertex VA, and turning to S42;
s48: and returning the updated edge table.
2. The method of claim 1, wherein the step of determining the position of the substrate comprises,
in step S1, each table structure of the database is represented as a table composed of triplets, i.e., attribute names, primary keys, and foreign keys, where "attribute names" indicate attribute names, "primary keys" and "foreign keys" indicate whether the attribute is a primary key and a foreign key, respectively, Y indicates yes, and N indicates no.
3. A database entity relationship model extraction device based on an adjacency list, which is characterized by comprising:
a table structure normalization means M1 for representing each table structure of the database as a table composed of triples, i.e., attribute names, primary keys, foreign keys;
vertex table construction means M2 for constructing a vertex table of the adjacency table;
an edge table constructing section M3 for constructing an edge table of the adjacency table;
a table structure relationship type calculating section M4 for calculating a relationship type between table structures;
the vertex table construction part M2 specifically includes:
vertex table initializing means M21 for initializing a vertex table;
a table structure reading section M22 for reading the standardized table structure;
a vertex construction part M23 for constructing a vertex corresponding to the table structure and adding to the vertex table;
the side table construction part M3 specifically includes:
an edge table initializing section M31 for initializing an edge table;
a class 1 vertex reading unit M32 for reading vertices in the adjacency list for which no corresponding edge set has been constructed;
an edge set constructing part M33 for constructing an edge set corresponding to the vertex and adding the edge set to the vertex table;
the table structural relation type calculating section M4 specifically includes:
class 2 vertex reading means M41 for reading vertices in the adjacency list for which the table structure relationship type has not been calculated yet;
an edge set reading unit M42 for reading the edge set corresponding to the vertex;
a relationship type calculating means M43 for calculating a relationship type between the vertex and the corresponding edge set table structure;
an edge set updating part M44, configured to generate a new edge set according to the calculated relationship type, and delete and replace the original edge set.
CN201910799710.8A 2019-08-28 2019-08-28 Database entity relation model extraction method and device based on adjacency list Active CN110516010B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910799710.8A CN110516010B (en) 2019-08-28 2019-08-28 Database entity relation model extraction method and device based on adjacency list

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910799710.8A CN110516010B (en) 2019-08-28 2019-08-28 Database entity relation model extraction method and device based on adjacency list

Publications (2)

Publication Number Publication Date
CN110516010A CN110516010A (en) 2019-11-29
CN110516010B true CN110516010B (en) 2023-06-09

Family

ID=68628426

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910799710.8A Active CN110516010B (en) 2019-08-28 2019-08-28 Database entity relation model extraction method and device based on adjacency list

Country Status (1)

Country Link
CN (1) CN110516010B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111190971B (en) * 2019-12-31 2023-08-01 浪潮软件股份有限公司 ER diagram drawing method and device based on neighbor table node state and priority
CN113722294B (en) * 2021-09-01 2024-02-23 达梦数据技术(江苏)有限公司 Data migration method and system from graph database to relational database

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108037916A (en) * 2017-11-29 2018-05-15 福州市智捷信息科技有限公司 A kind of graphical service modeling method based on web

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10387496B2 (en) * 2015-05-21 2019-08-20 International Business Machines Corporation Storing graph data in a relational database

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108037916A (en) * 2017-11-29 2018-05-15 福州市智捷信息科技有限公司 A kind of graphical service modeling method based on web

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
关系数据库设计的实用方法及应用;李湘林;《网络财富》;20100723(第14期);全文 *

Also Published As

Publication number Publication date
CN110516010A (en) 2019-11-29

Similar Documents

Publication Publication Date Title
Vaisman et al. Data warehouse systems
CN103577590A (en) Data query method and system
Goodchild et al. Geographic information systems and science
CN110516010B (en) Database entity relation model extraction method and device based on adjacency list
CN104021210B (en) Geographic data reading and writing method of MongoDB cluster of geographic data stored in GeoJSON-format semi-structured mode
CN104008209B (en) Reading-writing method for MongoDB cluster geographic data stored with GeoJSON format structuring method
CN112613611A (en) Tax knowledge base system based on knowledge graph
CN111126461A (en) Intelligent auditing method based on machine learning model explanation
CN114417012A (en) Method for generating knowledge graph and electronic equipment
Panneerselvam Database Management Systems
Di Tria et al. Research data mart in an academic system
CN117112648A (en) College student learning portrait generation system and method based on intelligent education data
Meng Analysis and Prediction of College Students' Employment based on Decision Tree Classification Algorithm
CN114490568A (en) Cross-domain database integration and migration method and system
Zhang A campus big-data platform architecture for data mining and business intelligence in education institutes
Dahlan et al. Transformation of data warehouse using snowflake scheme method
Gregersen Timeer plus: A temporal eer model supporting schema changes
Taniar et al. Data warehousing and analytics: fueling the data engine
Dolbear et al. Semantic interoperability between topographic data and a flood defence ontology
CN116431736B (en) Method and system for constructing online data warehouse model
Boukerch et al. The setting up of a gis for the general population and housing census
Hamdani et al. DESIGN OF DATA WAREHOUSE ARCHITECTURE FOR TRACER STUDY DATA MANAGEMENT BASED ON OLAP.
Drakopoulos et al. Political analytics for public electronic proposal deliberation at municipal level
Wang et al. Accounting for the Benefits of Database Normalization.
Castillejos Management of time series data

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
GR01 Patent grant
GR01 Patent grant