CN103279544A - Method and device for storing and inquiring tree structure data in relational database - Google Patents

Method and device for storing and inquiring tree structure data in relational database Download PDF

Info

Publication number
CN103279544A
CN103279544A CN2013102222187A CN201310222218A CN103279544A CN 103279544 A CN103279544 A CN 103279544A CN 2013102222187 A CN2013102222187 A CN 2013102222187A CN 201310222218 A CN201310222218 A CN 201310222218A CN 103279544 A CN103279544 A CN 103279544A
Authority
CN
China
Prior art keywords
node
order
level sequences
level
data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN2013102222187A
Other languages
Chinese (zh)
Inventor
何岩
宁江
尹清准
吴卫荣
郑扬飞
刘毅
贾晓霞
郭红钰
吴瑜
张勇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
CETC 15 Research Institute
Original Assignee
CETC 15 Research Institute
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 CETC 15 Research Institute filed Critical CETC 15 Research Institute
Priority to CN2013102222187A priority Critical patent/CN103279544A/en
Publication of CN103279544A publication Critical patent/CN103279544A/en
Pending legal-status Critical Current

Links

Images

Abstract

The invention discloses a method and a device for storing and inquiring tree structure data in a relational database. The method includes storing data and a rank sequence of each node in a tree structure in a data line in the relational database. The data lines in the relational database respectively correspond to the nodes in the tree structure, A process for determining the rank sequence of each node includes determining a path from a root node to the node in the tree structure if the node is a non-root node, and composing the rank sequence of the node according to codes of various nodes in the path of the node. The method and the device have the advantages that the rank sequences of the nodes are stored in the relational database, rank sequences of various superior nodes of an optional non-root node can be acquired by means of analyzing the rank sequence of the optional non-root node, and the various rank sequences are used as inquiry conditions, so that data lines of the various superior nodes of the optional non-root node can be directly inquired in the relational database, a recursion mode for inquiring the data is omitted, and the inquiry efficiency is improved.

Description

Storage and querying method and the device of tree-type structure data in relevant database
Technical field
The present invention relates to field of computer technology, relate in particular to storage and querying method and the device of a kind of tree-type structure data in relevant database.
Background technology
In daily life and the course of work, the data of belt level relation are widely used, such as the structured data that is applied to taking care of books, be applied to the structured data of organization and administration etc., hierarchical relationship between the described structured data is represented with the relation of tree usually, each node in the tree is namely represented data, and the relation between the node is then expressed the relation between the data.
The database that is used for the storage data at present is generally relevant database; In actual applications, often need to utilize relevant database to store tree-type structure data, and then the tree-type structure data of storing in the relevant database is inquired about.
And relevant database normally carries out data storages with the form of form, and wherein, form is to represent with the form of row and column: data recording of each line display of form in the relevant database, be called for short a data line; A field is shown in each tabulation.Wherein, it doesn't matter between the data line.
For tree-type structure data, if simply the data of any node in the tree are stored in the relevant database in should a data line of node, can't embody the relation between the data of each node in the tree.Namely for tree-type structure data, relevant database can only be stored the data of node in the tree usually, and can't store tree type relation.
In order in relevant database, to embody the tree type relation of tree-type structure data, adopt parents' method (claiming father's method again) usually: in every data line of relevant database, except data field and major key field, increase a foreign key field; The data of each non-root node in the tree are stored in the relevant database in should the data line of node the time, the value of the major key field of the data line of the parent node correspondence of this node is stored in the foreign key field of data line of this node correspondence.The data line of each non-root node correspondence has been set up hierarchical relationship by the foreign key field data line corresponding with the parent node of this node in the tree.
In the inquiry tree during data of parent node of arbitrary non-root node, as long as with the value of this node foreign key field of corresponding data line in relevant database as querying condition, just can directly inquire the data line of the parent node correspondence of this node, in the data line of the parent node correspondence of this node, read the data of the parent node of this node then; In the inquiry tree during data of each child nodes of arbitrary node, generation with the value of the major key field of the data line of this node correspondence as querying condition, inquiry has each data line under the foreign key field with the identical value of querying condition in relevant database, described each data line is the data line of each child nodes correspondence of this node, reads the data of each child nodes of this node then in the data line of each child nodes correspondence of this node.
But the corresponding data of each superior node (superior node claims ancestor node again) of arbitrary node in needs inquiry tree, during data that perhaps each downstream site of this node (downstream site claims descendants's node again) is corresponding, each superior node (or downstream site) of this node often has a plurality of levels, needs to adopt the mode of recursive algorithm successively to inquire about usually.And the method for recursive query need consume a large amount of system resources, and query responding time is longer, when especially the tree structure level is various, even the situation of seemingly-dead machine occurs, has had a strong impact on the efficient of inquiry.
In sum, after the existing method of tree-type structure data utilization is stored in the relevant database, the data of in relevant database, inquiring about each superior node of arbitrary node in the tree, the perhaps inefficiency of the data of each downstream site of this node.
Summary of the invention
Technical scheme of the present invention discloses storage and querying method and the device of a kind of tree-type structure data in relevant database, in order to improve the data of in relevant database, inquiring about each superior node of arbitrary node in the tree, the perhaps efficient of the data of each downstream site of this node.
Technical scheme of the present invention discloses the storage means of a kind of tree-type structure data in relevant database, comprising:
For each node in the tree, data, the level sequences in order of this node stored in the described relevant database in should the data line of node;
Wherein, the level sequences in order of this node is determined according to following method: if this node is non-root node, then determine root node in the described tree to the path of this node, form the level sequences in order of this node according to the coding of each node in the path of this node.
Preferably, the coding of each node in the described tree has nothing in common with each other; Perhaps, the coding with the node of level is unique in the described tree.
Preferably, the figure place of the coding of described node is fixed; And
The level sequences in order that described coding according to each node in the path of this node is formed this node is specially, and according to the level height order of each node in the path of this node, the coding with each node splices successively, obtains the level sequences in order of this node;
Perhaps, the figure place of the coding of described node is on-fixed; And
The level sequences in order that described coding according to each node in the path of this node is formed this node is specially, level height order according to each node in the path of this node, coding with each node splices successively, and between adjacent coding, blank character is set, obtain the level sequences in order of this node.
Technical scheme of the present invention also discloses the querying method of a kind of tree-type structure data in relevant database, comprising:
For the non-root node in the tree, when inquiring about the data of each superior node of this node, from described relevant database, read the level sequences in order of this node in the data line of this node correspondence;
According to the level sequences in order of this node, calculate the level sequences in order of each superior node of this node;
Each level sequences in order that calculates is inquired about in described relevant database as querying condition respectively, determine the data line of each superior node correspondence of this node;
From the data line of each superior node correspondence of this node, obtain the data of each superior node of this node;
Wherein, the level sequences in order of this node is to determine according to following method: determine root node in the described tree to the path of this node; The level sequences in order of forming this node according to the coding of each node in the path of this node.
Preferably, the querying method of described tree-type structure data in relevant database also comprises:
When the data of each downstream site of inquiring about this node, the level sequences in order that generates with this node is the querying condition of prefix; And inquire about in described relevant database according to the querying condition that generates, determine the data line of each downstream site correspondence of this node;
From the data line of each downstream site correspondence of this node, obtain the data of each downstream site of this node.
Preferably, the figure place of the coding of described node is fixed; And
The level sequences in order that described coding according to each node in the path of this node is formed this node is specially, and according to the level height order of each node in the path of this node, the coding with each node splices successively, obtains the level sequences in order of this node;
Perhaps, the figure place of the coding of described node is on-fixed; And
The level sequences in order that described coding according to each node in the path of this node is formed this node is specially, level height order according to each node in the path of this node, coding with each node splices successively, and between adjacent coding, blank character is set, obtain the level sequences in order of this node.
Technical scheme of the present invention also discloses the memory storage of a kind of tree-type structure data in relevant database, comprising:
The level sequences in order determination module, be used for for each node of tree, determine the level sequences in order of this node: if this node is non-root node, then determine root node in the described tree to the path of this node, form the level sequences in order of this node according to the coding of each node in the path of this node;
Memory module is used for for each node of described tree, and data, the level sequences in order of this node stored in the described relevant database in should the data line of node.
Technical scheme of the present invention also discloses the inquiry unit of a kind of tree-type structure data in relevant database, comprising:
The level sequences in order read module is used for the node for appointment, from relevant database in should the data line of node, the level sequences in order output of reading this node;
The first querying condition determination module is used for the level sequences in order according to described level sequences in order read module output, calculates the level sequences in order of each superior node of this node; Each level sequences in order that calculates is exported as querying condition respectively;
Enquiry module is used for the querying condition according to the output of the first querying condition determination module, and inquiry obtains the data line of each superior node correspondence of described node in relevant database; From the data line of each superior node correspondence of this node, obtain the data of each superior node of this node.
Preferably, the inquiry unit of described tree-type structure data in relevant database also comprises:
The inquiry control module is used for after receiving the superior node query statement, sends superior node inquiry notice to described level sequences in order read module; And
Described level sequences in order read module specifically is used for after receiving described superior node inquiry notice, node for appointment in the described superior node query statement, to in should the data line of node, the level sequences in order that reads this node outputs to the first querying condition determination module from relevant database.
Preferably, the inquiry unit of described tree-type structure data in relevant database also comprises: the second querying condition determination module; And
Described inquiry control module also is used for after receiving the downstream site query statement, sends downstream site inquiry notice to described level sequences in order read module; And
Described level sequences in order read module also is used for after receiving described downstream site inquiry notice, node for appointment in the described downstream site query statement, to in should the data line of node, the level sequences in order that reads this node outputs to the second querying condition determination module from relevant database;
The second querying condition determination module is used for the level sequences in order according to described level sequences in order read module output, and generating with this level sequences in order is that the querying condition of prefix outputs to described enquiry module;
Described enquiry module also is used for inquiring about at described relevant database according to the querying condition of second querying condition determination module output, determines the data line of each downstream site correspondence of this node; From the data line of each downstream site correspondence of this node, obtain the data of each downstream site of this node.
In the technical scheme of the present invention, owing in relevant database, stored the level sequences in order of node in the tree, and by the parsing to the level sequences in order of arbitrary non-root node, can obtain the level sequences in order of each superior node of this node, each level sequences in order can directly be inquired the data line at each level sequences in order place as querying condition in relevant database, namely directly inquire the data line of each superior node of this node; Thereby avoid using recursive fashion to inquire about, improved search efficiency, reduced the response time of inquiry.
In addition, the level sequences in order of this node as prefix generated query condition, also can directly be inquired the data line of each downstream site of this node in relevant database; Improve search efficiency, reduced the response time of inquiry.
Description of drawings
Fig. 1 a be the embodiment of the invention become the instance graph of level sequences in order based on the fixing code set of figure place;
Fig. 1 b is the instance graph that the code set based on the on-fixed figure place of the embodiment of the invention becomes level sequences in order;
Fig. 2 is the method flow diagram of the data of each superior node of inquiry tree arbitrary node in relevant database of the embodiment of the invention;
Fig. 3 is the method flow diagram of the data of each downstream site of inquiry tree arbitrary node in relevant database of the embodiment of the invention;
Fig. 4 is the inner structure block diagram of the memory storage of tree-type structure data in relevant database of the embodiment of the invention;
Fig. 5 is the inner structure block diagram of the inquiry unit of tree-type structure data in relevant database of the embodiment of the invention.
Embodiment
For making purpose of the present invention, technical scheme and advantage clearer, below with reference to accompanying drawing and enumerate preferred embodiment, the present invention is described in more detail.Yet, need to prove that many details of listing in the instructions only are in order to make the reader to one or more aspects of the present invention a thorough understanding be arranged, even if there are not these specific details also can realize these aspects of the present invention.
Terms such as " module " used in this application, " system " are intended to comprise the entity relevant with computing machine, such as but not limited to hardware, firmware, combination thereof, software or executory software.For example, module can be, but be not limited in: the thread of the process of moving on the processor, processor, object, executable program, execution, program and/or computing machine.For instance, the application program of moving on the computing equipment and this computing equipment can be modules.One or more modules can be positioned at an executory process and/or thread, and module also can be on the computing machine and/or be distributed between two or more the computing machines.
Thinking of the present invention is, for the arbitrary node in the tree, according to the coding of each node of root node in the path of this node, determines the level sequences in order of this node.The data of this node and level sequences in order are stored in the relevant database in should the data line of node.In relational data during the data of each higher level (or subordinate) node of the arbitrary node of inquiry, can determine querying condition according to the level sequences in order of this node, inquiry obtains the data line of each higher level (or subordinate) node correspondence of this node in relevant database; Further the reentry data of each higher level (or subordinate) node of this node.Owing to comprised the relevant information in the path of node in the level sequences in order, the i.e. level sequences in order information of each superior node of this node, use level sequences in order as querying condition, just can directly inquire the data line of each superior node of node, and needn't use recursive fashion to inquire about, improved search efficiency.
Following mask body introduce the embodiment of the invention tree-type structure data is stored in the relevant database method and in relevant database the method for data of each higher level (or subordinate) node of the arbitrary node of inquiry.
In the embodiment of the invention, before storing tree-type structure data into relevant database, earlier each node of tree is encoded, and determines the level sequences in order of each node:
Each node of tree is encoded, and the coding of each node can have nothing in common with each other, and is unique in the level that is coded in the place with the node of level in the tree perhaps; Root node can be encoded and also can not encoded; For example, root node is encoded to certain optional network specific digit, and perhaps the encoding setting of root node is empty.For each node in the tree, determine the path from root node to this node; According to the coding of each node in the path of this node, determine the level sequences in order of this node.Wherein, the level sequences in order of how determining this node according to the coding of each node in the path of this node can adopt following two kinds of methods:
A kind of method is based on the method for the level sequences in order that the fixing coding of figure place forms: in this method, the coding of each node of tree is fixing figure place, for the arbitrary non-root node in the tree, level height order according to each node the path from root node to this node, coding with each node splices according to this, obtains the level sequences in order of this node.
For example, in the data of national administrative region, as shown in Figure 1a, the coding figure place of the node of expression province municipality directly under the Central Government is 4, and " Beijing ", " Tianjin " and " Shanghai City " are encoded to 0001,0002 and 0003 respectively; The coding figure place of the node in expression prefecture-level city and district also is 4, and " Dongcheng District ", " Haidian District " and " Shijingshan District " that will be under the jurisdiction of " Beijing " are encoded to 0001,0002 and 0003 respectively; The coding 0001 of " Beijing " and the coding 0001 of " Dongcheng District " are spliced into the level sequences in order 00010001 of " Dongcheng District ".
Another kind method is the method for the level sequences in order formed based on the coding of on-fixed figure place: in this method, the coding of each node of tree is non-fixedly figure place, for the arbitrary non-root node in the tree structure, level height order according to each node the path from root node to this node, coding with each node splices according to this, and between adjacent coding, blank character is set, obtain the level sequences in order of this node.
For example, in the data of national administrative region, shown in Fig. 1 b, the coding figure place of the node of expression province municipality directly under the Central Government is 2, and " Henan Province ", " Tianjin " and " Shanghai City " are encoded to 01,02 and 03 respectively; The coding figure place of the node in expression prefecture-level city and district is 3, and " Zhengzhou City ", " Xinyang ", " Luoyang City " and " Nanyang " that will be under the jurisdiction of " Henan Province " are encoded to 001,002,003 and 004 respectively; The coding figure place of the node of expression county and county-level city is 4, and " Tongbo County ", " Tanghe County ", " Xixia County " and " Miyang County " that will be under the jurisdiction of " Nanyang " are encoded to 0001,0002,0003 and 0004 respectively; The coding 0002 of the coding 004 of the coding 01 in " Henan Province ", " Nanyang " and " Tanghe County " is spliced into the level sequences in order 01.004.0002 of " Tanghe County "; Wherein ". " is the blank character that arranges between the adjacent encoder.
Determining in the tree after the level sequences in order of each node, the storage means of a kind of tree-type structure data provided by the invention in relevant database is, for each node in the tree, data, the level sequences in order of this node stored in the relevant database in should the data line of node.
Concrete, in every data line of relevant database, field is set, comprise data field and level sequences in order field; The data of each node in the tree are stored in the relevant database in the data field to data line that should node; The level sequences in order of this node is stored in the level sequences in order field that this node corresponding data is capable in the relevant database.More excellent, described level sequences in order field is set at variable length character type.
After being stored in tree-type structure data in the relevant database based on storage means provided by the invention, the present invention also provides the method for the data of each higher level (or subordinate) node of the corresponding node of the arbitrary tree-type structure data of inquiry in relevant database, this method is come data query according to querying condition, avoided coming data query according to recursive algorithm, improved the efficient of inquiry.
For provided by the invention a kind of in relevant database the method for data of each superior node of the corresponding node of the arbitrary tree-type structure data of inquiry, process flow diagram specifically comprises the steps: as shown in Figure 2
S201: for arbitrary non-root node in the tree, in relevant database, in should the data line of node, read the level sequences in order of this node.
Concrete, for given arbitrary tree-type structure data, these data are corresponding node in tree, finds the data line of this node correspondence in relevant database, reads the level sequences in order of this node from the level sequences in order field of the data line of this node correspondence.
S202: according to the level sequences in order of this node, calculate the level sequences in order of each superior node of this node, with each level sequences in order of calculating respectively as querying condition.
Concrete, corresponding to the method for above-mentioned two kinds of definite node level sequences in order, the present invention also provides the method for the level sequences in order of corresponding two kinds of each superior nodes that calculates these nodes:
Become the method for level sequences in order corresponding to the fixing code set of figure place, calculate in the level sequences in order method of superior node, because the level sequences in order of arbitrary non-root node in the tree, be the level height order according to each node the path from root node to this node, according to this coding of each node spliced and to obtain; That is to say, comprised the coding of each superior node of this node in the level sequences in order of this node, and comprised the level sequences in order of each superior node of this node; Therefore, according to the coding fixedly figure place, and the splicing sequencing the level sequences in order of this node is resolved, can obtain coding and the level sequences in order of each superior node of this node successively.
For example, in Fig. 1 a, a non-root node in " the Temple of Heaven street " corresponding national administrative region, the level sequences in order during this node corresponding data in relevant database is capable is 000100010004; Comprising three codings in the level sequences in order 000100010004 of this node is respectively: 0001,0001 and 0004; 0004 is the coding of this node, and one of them 0001 is the coding of the superior node " Dongcheng District " of this node, and another 0001 is the coding of another superior node " Beijing " of this node; The level sequences in order 000100010004 of this node has also comprised the level sequences in order of superior node " Dongcheng District " and " Beijing " simultaneously: 00010001 and 0001.After according to the splicing order of the fixedly figure place of encoding and coding the level sequences in order 000100010004 of this node being resolved, the level sequences in order that obtains each superior node of this node is respectively 00010001 and 0001, with level sequences in order 00010001 and 0001 respectively as querying condition.
The method of the level sequences in order of forming corresponding to the coding of on-fixed figure place, calculate in the method for each superior node level sequences in order, because the level sequences in order of arbitrary non-root node in the tree, it is the level height order according to each node the path from root node to this node, coding with each node splices according to this, and arranges between adjacent coding that blank character obtains; That is to say, comprised the coding of each superior node of this node in the level sequences in order of this node, and comprised the level sequences in order of each superior node of this node; Therefore, according to the sequencing of splicing, and respectively the blank character between the coding is resolved the level sequences in order of this node, can obtain coding and the level sequences in order of each superior node of this node successively.
For example, a non-root node in the corresponding national administrative region, " Tanghe County " among Fig. 1 b, the level sequences in order during this node corresponding data in relevant database is capable is 01.004.0002; Obviously, having comprised three codings among this level sequences in order 01.004.0002 is followed successively by: 01,004,0002; Wherein, 0002 is the coding of this node " Tanghe County ", and 01,004 is respectively two superior nodes " Henan Province " of this node, the coding of " Nanyang "; Simultaneously, two superior nodes " Henan Province " of this node, the level sequences in order of " Nanyang " have also been comprised among this level sequences in order 01.004.0002: 01.004 and 01.After according to the splicing order of the blank character in this level sequences in order and coding this level sequences in order 01.004.0002 being resolved, the level sequences in order that can obtain each superior node of this node is followed successively by: 01.004,01, with the level sequences in order 01.004 and 01 of each superior node of this node of parsing respectively as querying condition.
S203: according to the querying condition of determining, in relevant database, inquire about, determine the data line of each superior node correspondence of this node.
Concrete, according to the querying condition of determining, the i.e. level sequences in order of each superior node of this node, each data line in relevant database under the level sequences in order of each superior node of described this node of inquiry, each data line that inquiry obtains is the data line of each superior node correspondence of this node.
For example, the level sequences in order of each superior node of " Tanghe County " corresponding node is respectively 01.004 and 01, in relevant database, inquire level sequences in order and be respectively 01.004 and 01 affiliated data line, determine that the data line that the level sequences in order that checks in is respectively under in the of 01.004 and 01 is the data line of each superior node correspondence of " Tanghe County " corresponding node.
Level sequences in order with each superior node of this node of parsing then can directly inquire the corresponding data line of each superior node of this node as querying condition, and needn't use recursive fashion to inquire about the data line of each superior node, has improved search efficiency.
S204: the data that from the data line of each superior node correspondence of this node, read each superior node of this node.
For example, the data line that level sequences in order is respectively under in the of 01.004 and 01 is the data line of each superior node correspondence of " Tanghe County " corresponding node, then read data " Nanyang " in the data line under level sequences in order 01.004, read data " Henan Province " in the data line under level sequences in order 01, then " Nanyang " and " Henan Province " is the data of each superior node of " Tanghe County " corresponding node.
For provided by the invention a kind of in relevant database the method for data of each downstream site of the corresponding node of the arbitrary tree-type structure data of inquiry, process flow diagram specifically comprises the steps: as shown in Figure 3
S301: for arbitrary non-root node in the tree, in relevant database, in the data line of this node correspondence, read the level sequences in order of this node.
Concrete, for given arbitrary tree-type structure data, these data are corresponding node in tree, finds the data line of this node correspondence in relevant database, reads the level sequences in order of this node from the level sequences in order field of the data line of this node correspondence.
S302: the level sequences in order that generates with this node is the querying condition of prefix.
Concrete, with the level sequences in order of this node as prefix, with the asterisk wildcard splicing generated query condition of expression any character.
S303: inquire about in relevant database according to the querying condition that generates, determine the data line of each downstream site correspondence of this node.
Concrete, according to the level sequences in order of this node and the querying condition of the asterisk wildcard splicing generation of expression any character, each data line in relevant database under inquiry and each level sequences in order that this querying condition conforms to is inquired about the data line that each data line that obtains is each downstream site correspondence of this node.
For example, a node in " Henan Province " corresponding national administrative region, the level sequences in order of this node is 01; Be spliced into querying condition 01% with 01 with the asterisk wildcard % that represents any character, inquiry meets the data line under each level sequences in order of 01% in relevant database, 01.001,01.002,01.003,01.004, the data line under 01.004.0001,01.004.0002,01.004.0003,01.004.0004 and the 01.004.0005 checks in the data line that meets each level sequences in order place of 01% as the data line of each downstream site correspondence of this node, comprising:.
Can directly inquire the corresponding data line of each superior node of this node according to the querying condition that generates, and needn't use recursive fashion to inquire about the data line of each superior node, improve search efficiency.
S304: the data that from the data line of each downstream site correspondence of this node, read each downstream site of this node.
For example, check in the data line of each downstream site correspondence of the corresponding node in " Henan Province ", comprise: 01.001,01.002,01.003,01.004,01.004.0001,01.004.0002,01.004.0003,01.004.0004, with the data line under the 01.004.0005, then from each level sequences in order 01.001,01.002,01.003,01.004,01.004.0001,01.004.0002,01.004.0003,01.004.0004, with read data in the data line under the 01.004.0005 respectively and be " Zhengzhou City ", " Xinyang ", " Luoyang City ", " Nanyang ", " Tongbo County ", " Tanghe County ", " Xixia County ", " Miyang County " and " Neixiang County "; Then " Zhengzhou City ", " Xinyang ", " Luoyang City ", " Nanyang ", " Tongbo County ", " Tanghe County ", " Xixia County ", " Miyang County " and " Neixiang County " are the data of each downstream site of this node.
The present invention also provides the memory storage of a kind of tree-type structure data in relevant database, and the inner structure block diagram specifically comprises as shown in Figure 4: level sequences in order determination module 401 and memory module 402.
Wherein, level sequences in order determination module 401, be used for each node for tree, determine the level sequences in order of this node: if this node is non-root node, then determine root node in the tree to the path of this node, form the level sequences in order of this node according to the coding of each node in the path of this node.
Memory module 402 is used for each node for tree, and the level sequences in order of the data of this node, this node that level sequences in order determination module 401 is determined is stored in the relevant database in should the data line of node.
The present invention also provides the inquiry unit of a kind of tree-type structure data in relevant database, and the content structure block diagram specifically comprises as shown in Figure 5: level sequences in order read module 501, the first querying condition determination modules 502 and enquiry module 503.
Wherein, level sequences in order read module 501 is used for the node for appointment, from relevant database in should the data line of node, the level sequences in order output of reading this node.
The first querying condition determination module 502 is used for the level sequences in order according to 501 outputs of level sequences in order determination module, calculates the level sequences in order of each superior node of this node; Each level sequences in order that calculates is exported as querying condition respectively.
Enquiry module 503 is used for the querying condition according to 502 outputs of the first querying condition determination module, and inquiry obtains the data line of each superior node correspondence of this node in relevant database; From the data line of each superior node correspondence of this node, obtain the data of each superior node of this node.
Further, in the inquiry unit of above-mentioned tree-type structure data in relevant database, also comprise: inquiry control module 504 and the second querying condition determination module 505.
Wherein, inquiry control module 504 after being used for accepting user's input and obtaining the superior node query statement, sends superior nodes inquiry notice to level sequences in order read module 501;
Correspondingly, level sequences in order read module 501 is after receiving this superior node inquiry notice, according to the received superior node query statement of inquiry control module 504, node for appointment in this superior node query statement, from relevant database, in should the data line of node, read the level sequences in order of this node and export to the first querying condition determination module 502.
Inquiry control module 504 also is used for behind the downstream site query statement that receives user's input, sends downstream site inquiry notice to level sequences in order read module 501; Correspondingly, level sequences in order read module 501 is after receiving this downstream site inquiry notice, for the node of this downstream site query statement appointment, from relevant database, in should the data line of node, read the level sequences in order of this node and export to the second querying condition determination module 505.
The second querying condition determination module 505 is used for the level sequences in order according to 501 outputs of level sequences in order read module, and producing with this level sequences in order is that the querying condition of prefix outputs to enquiry module 503.
Accordingly, enquiry module 503 also is used for the querying condition according to 505 outputs of the second querying condition determination module, and inquiry obtains the data line of each downstream site correspondence of this node in relevant database; From the data line of each downstream site correspondence of this node, obtain the data of each downstream site of this node.
In the technical scheme of the present invention, owing in relevant database, stored the level sequences in order of node in the tree, and by the parsing to the level sequences in order of arbitrary non-root node, can obtain the level sequences in order of each superior node of this node, each level sequences in order can directly be inquired the data line at each level sequences in order place as querying condition in relevant database, namely directly inquire the data line of each superior node of this node; Thereby avoid using recursive fashion to inquire about, improved search efficiency, reduced the response time of inquiry.
In addition, the level sequences in order of this node as prefix generated query condition, also can directly be inquired the data line of each downstream site of this node in relevant database; Improve search efficiency, reduced the response time of inquiry.
The above only is preferred implementation of the present invention; should be pointed out that for those skilled in the art, under the prerequisite that does not break away from the principle of the invention; can also make some improvements and modifications, these improvements and modifications also should be considered as protection scope of the present invention.

Claims (10)

1. the storage means of a tree-type structure data in relevant database is characterized in that, comprising:
For each node in the tree, data, the level sequences in order of this node stored in the described relevant database in should the data line of node;
Wherein, the level sequences in order of this node is determined according to following method: if this node is non-root node, then determine root node in the described tree to the path of this node, form the level sequences in order of this node according to the coding of each node in the path of this node.
2. the method for claim 1 is characterized in that, the coding of each node in the described tree has nothing in common with each other; Perhaps, the coding with the node of level is unique in the described tree.
3. method as claimed in claim 1 or 2 is characterized in that, the figure place of the coding of described node is fixed; And
The level sequences in order that described coding according to each node in the path of this node is formed this node is specially, and according to the level height order of each node in the path of this node, the coding with each node splices successively, obtains the level sequences in order of this node;
Perhaps, the figure place of the coding of described node is on-fixed; And
The level sequences in order that described coding according to each node in the path of this node is formed this node is specially, level height order according to each node in the path of this node, coding with each node splices successively, and between adjacent coding, blank character is set, obtain the level sequences in order of this node.
4. the querying method of a tree-type structure data in relevant database is characterized in that, comprising:
For the non-root node in the tree, when inquiring about the data of each superior node of this node, from described relevant database, read the level sequences in order of this node in the data line of this node correspondence;
According to the level sequences in order of this node, calculate the level sequences in order of each superior node of this node;
Each level sequences in order that calculates is inquired about in described relevant database as querying condition respectively, determine the data line of each superior node correspondence of this node;
From the data line of each superior node correspondence of this node, obtain the data of each superior node of this node;
Wherein, the level sequences in order of this node is to determine according to following method: determine root node in the described tree to the path of this node; The level sequences in order of forming this node according to the coding of each node in the path of this node.
5. method as claimed in claim 4 is characterized in that, also comprises:
When the data of each downstream site of inquiring about this node, the level sequences in order that generates with this node is the querying condition of prefix; And inquire about in described relevant database according to the querying condition that generates, determine the data line of each downstream site correspondence of this node;
From the data line of each downstream site correspondence of this node, obtain the data of each downstream site of this node.
6. as claim 4 or 5 described methods, it is characterized in that the figure place of the coding of described node is fixed; And
The level sequences in order that described coding according to each node in the path of this node is formed this node is specially, and according to the level height order of each node in the path of this node, the coding with each node splices successively, obtains the level sequences in order of this node;
Perhaps, the figure place of the coding of described node is on-fixed; And
The level sequences in order that described coding according to each node in the path of this node is formed this node is specially, level height order according to each node in the path of this node, coding with each node splices successively, and between adjacent coding, blank character is set, obtain the level sequences in order of this node.
7. the memory storage of a tree-type structure data in relevant database is characterized in that, comprising:
The level sequences in order determination module, be used for for each node of tree, determine the level sequences in order of this node: if this node is non-root node, then determine root node in the described tree to the path of this node, form the level sequences in order of this node according to the coding of each node in the path of this node;
Memory module is used for for each node of described tree, and data, the level sequences in order of this node stored in the described relevant database in should the data line of node.
8. the inquiry unit of a tree-type structure data in relevant database is characterized in that, comprising:
The level sequences in order read module is used for the node for appointment, from relevant database in should the data line of node, the level sequences in order output of reading this node;
The first querying condition determination module is used for the level sequences in order according to described level sequences in order read module output, calculates the level sequences in order of each superior node of this node; Each level sequences in order that calculates is exported as querying condition respectively;
Enquiry module is used for the querying condition according to the output of the first querying condition determination module, and inquiry obtains the data line of each superior node correspondence of described node in relevant database; From the data line of each superior node correspondence of this node, obtain the data of each superior node of this node.
9. device as claimed in claim 8 is characterized in that, also comprises:
The inquiry control module is used for after receiving the superior node query statement, sends superior node inquiry notice to described level sequences in order read module; And
Described level sequences in order read module specifically is used for after receiving described superior node inquiry notice, node for appointment in the described superior node query statement, to in should the data line of node, the level sequences in order that reads this node outputs to the first querying condition determination module from relevant database.
10. device as claimed in claim 9 is characterized in that, also comprises: the second querying condition determination module; And
Described inquiry control module also is used for after receiving the downstream site query statement, sends downstream site inquiry notice to described level sequences in order read module; And
Described level sequences in order read module also is used for after receiving described downstream site inquiry notice, node for appointment in the described downstream site query statement, to in should the data line of node, the level sequences in order that reads this node outputs to the second querying condition determination module from relevant database;
The second querying condition determination module is used for the level sequences in order according to described level sequences in order read module output, and generating with this level sequences in order is that the querying condition of prefix outputs to described enquiry module;
Described enquiry module also is used for inquiring about at described relevant database according to the querying condition of second querying condition determination module output, determines the data line of each downstream site correspondence of this node; From the data line of each downstream site correspondence of this node, obtain the data of each downstream site of this node.
CN2013102222187A 2013-06-05 2013-06-05 Method and device for storing and inquiring tree structure data in relational database Pending CN103279544A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN2013102222187A CN103279544A (en) 2013-06-05 2013-06-05 Method and device for storing and inquiring tree structure data in relational database

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN2013102222187A CN103279544A (en) 2013-06-05 2013-06-05 Method and device for storing and inquiring tree structure data in relational database

Publications (1)

Publication Number Publication Date
CN103279544A true CN103279544A (en) 2013-09-04

Family

ID=49062063

Family Applications (1)

Application Number Title Priority Date Filing Date
CN2013102222187A Pending CN103279544A (en) 2013-06-05 2013-06-05 Method and device for storing and inquiring tree structure data in relational database

Country Status (1)

Country Link
CN (1) CN103279544A (en)

Cited By (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104408067A (en) * 2014-10-29 2015-03-11 中国建设银行股份有限公司 Multi-tree structure database design method and device
CN105630943A (en) * 2015-12-23 2016-06-01 合一网络技术(北京)有限公司 Advertisement material searching method and device
CN105806348A (en) * 2014-12-30 2016-07-27 高德软件有限公司 Road data storage method and device
CN106777096A (en) * 2016-12-14 2017-05-31 努比亚技术有限公司 A kind of file memory method and device
CN107807932A (en) * 2016-09-08 2018-03-16 腾讯科技(深圳)有限公司 A kind of hierarchical data management method and system based on path enumeration
CN107832345A (en) * 2017-10-16 2018-03-23 千寻位置网络有限公司 The method of base station data unique numberization mark
CN108804570A (en) * 2018-05-23 2018-11-13 成都直赢九州科技有限公司 A kind of distribution of tree hierarchy, storage and retrieval method
CN108932300A (en) * 2018-06-06 2018-12-04 成都深思科技有限公司 A kind of filter analysis method, equipment and the storage medium of unlimited iteration
CN108985922A (en) * 2018-07-05 2018-12-11 中国银行股份有限公司 A kind of information processing method and device
CN109063072A (en) * 2018-07-24 2018-12-21 西安科技大学 The querying method and device of information in a kind of engineering management
CN110263043A (en) * 2019-06-24 2019-09-20 苏州睿威博科技有限公司 Date storage method, data query method, apparatus and storage medium
CN111339193A (en) * 2020-02-21 2020-06-26 腾讯云计算(北京)有限责任公司 Category coding method and device
CN112632500A (en) * 2020-12-30 2021-04-09 绿盟科技集团股份有限公司 Data management method and electronic equipment
CN112632065A (en) * 2020-12-18 2021-04-09 北京锐安科技有限公司 Data storage method and device, storage medium and server
CN113961713A (en) * 2021-09-29 2022-01-21 中国科学院计算机网络信息中心 Graph data structure representing, storing and inquiring method and device based on hierarchical coding

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080215520A1 (en) * 2007-03-02 2008-09-04 Xiaohui Gu Method and system for indexing and serializing data
US20100274822A1 (en) * 2008-02-02 2010-10-28 Huawei Technologies Co., Ltd Data converting method, data converting device, terminal, and server
CN102867059A (en) * 2012-09-19 2013-01-09 浪潮(北京)电子信息产业有限公司 Method and system for processing data in treelike structures
CN103106198A (en) * 2011-11-09 2013-05-15 金蝶软件(中国)有限公司 Tree structure implementation method and tree structure implementation device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080215520A1 (en) * 2007-03-02 2008-09-04 Xiaohui Gu Method and system for indexing and serializing data
US20100274822A1 (en) * 2008-02-02 2010-10-28 Huawei Technologies Co., Ltd Data converting method, data converting device, terminal, and server
CN103106198A (en) * 2011-11-09 2013-05-15 金蝶软件(中国)有限公司 Tree structure implementation method and tree structure implementation device
CN102867059A (en) * 2012-09-19 2013-01-09 浪潮(北京)电子信息产业有限公司 Method and system for processing data in treelike structures

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
李丽娟 等: "树型结构在关系型数据库中的表示方法", 《石家庄职业技术学院学报》, vol. 19, no. 2, 30 April 2007 (2007-04-30), pages 37 - 40 *

Cited By (18)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104408067B (en) * 2014-10-29 2019-08-13 中国建设银行股份有限公司 A kind of database design method and device of polytree structure
CN104408067A (en) * 2014-10-29 2015-03-11 中国建设银行股份有限公司 Multi-tree structure database design method and device
CN105806348A (en) * 2014-12-30 2016-07-27 高德软件有限公司 Road data storage method and device
CN105806348B (en) * 2014-12-30 2018-12-11 高德软件有限公司 A kind of road data storage method and equipment
CN105630943A (en) * 2015-12-23 2016-06-01 合一网络技术(北京)有限公司 Advertisement material searching method and device
CN107807932A (en) * 2016-09-08 2018-03-16 腾讯科技(深圳)有限公司 A kind of hierarchical data management method and system based on path enumeration
CN106777096A (en) * 2016-12-14 2017-05-31 努比亚技术有限公司 A kind of file memory method and device
CN107832345A (en) * 2017-10-16 2018-03-23 千寻位置网络有限公司 The method of base station data unique numberization mark
CN108804570A (en) * 2018-05-23 2018-11-13 成都直赢九州科技有限公司 A kind of distribution of tree hierarchy, storage and retrieval method
CN108932300A (en) * 2018-06-06 2018-12-04 成都深思科技有限公司 A kind of filter analysis method, equipment and the storage medium of unlimited iteration
CN108985922A (en) * 2018-07-05 2018-12-11 中国银行股份有限公司 A kind of information processing method and device
CN109063072A (en) * 2018-07-24 2018-12-21 西安科技大学 The querying method and device of information in a kind of engineering management
CN110263043A (en) * 2019-06-24 2019-09-20 苏州睿威博科技有限公司 Date storage method, data query method, apparatus and storage medium
CN111339193A (en) * 2020-02-21 2020-06-26 腾讯云计算(北京)有限责任公司 Category coding method and device
CN112632065A (en) * 2020-12-18 2021-04-09 北京锐安科技有限公司 Data storage method and device, storage medium and server
WO2022127114A1 (en) * 2020-12-18 2022-06-23 北京锐安科技有限公司 Data storage method and apparatus, and storage medium and server
CN112632500A (en) * 2020-12-30 2021-04-09 绿盟科技集团股份有限公司 Data management method and electronic equipment
CN113961713A (en) * 2021-09-29 2022-01-21 中国科学院计算机网络信息中心 Graph data structure representing, storing and inquiring method and device based on hierarchical coding

Similar Documents

Publication Publication Date Title
CN103279544A (en) Method and device for storing and inquiring tree structure data in relational database
CN102682090B (en) A kind of sensitive word matching treatment system and method based on polymerization word tree
CN103678708B (en) Method and device for recognizing preset addresses
CN101635114A (en) Method and system for updating road codes and map data server
CN110263043A (en) Date storage method, data query method, apparatus and storage medium
WO2021072874A1 (en) Dual array-based location query method and apparatus, computer device, and storage medium
CN101794318A (en) URL (Uniform Resource Location) analyzing method and equipment
CN102591787B (en) The data processing method of JAVA card and device
CN108628898A (en) The method, apparatus and equipment of data loading
CN104240747B (en) The method and device that a kind of multi-medium data is obtained
CN105095425A (en) Cross-database transfer method and device for databases
CN102982147B (en) A kind of method and apparatus improving data message integration efficiency
CN109886711A (en) A kind of bar code coding method and device
CN111507430B (en) Feature coding method, device, equipment and medium based on matrix multiplication
CN111190896B (en) Data processing method, device, storage medium and computer equipment
CN103051480B (en) The storage means of a kind of DN and DN storage device
CN113158627A (en) Code complexity detection method and device, storage medium and electronic equipment
CN111290714A (en) Data reading method and device
CN106484753A (en) Data processing method
CN107943923B (en) Telegram code database construction method, telegram code identification method and device
CN113467974B (en) Identification information generation method
CN115774837A (en) Signal verification method, device, equipment, medium, program product and vehicle
CN103124273A (en) Method and system for building and matching path inverted list based on user behavior analysis
CN114490547A (en) Data compression method, device, equipment and medium
Bouyuklieva et al. On the classification of binary self-dual [44, 22, 8] codes with an automorphism of order 3 or 7

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20130904

RJ01 Rejection of invention patent application after publication