The big binary tree traverses all the descendant nodes under a node?

A large binary tree with uncertain tree hierarchy. Now we need to realize the following requirements:
1. Record hierarchical relationships. For example: to give you a node id:9, needs to find out the son or grandson under this node, or. Or all descendant nodes
2. I would also like to query the statistical requirements

.

for requirement 1, I am talking about the node id stored in redis, and the structure is that zset, key is node id,score is hierarchical relationship. If it is a son node, score is-1 and grandson is-2. The levels are infinite, and there may be many layers. The later the score is, the smaller it is.

but there is a problem with this storage, that is, it is not easy to query statistical requirements. For example, I need to query all the new nodes under a node for the day. For this kind of demand, at present, all I can think of is to get the id, of all the descendant nodes under the current node from redis, and then go to the database through id to find out the new nodes of the day through in Filter. This has a problem, that is, if there are too many descendant nodes, the efficiency of in query is very low, and the service will fail.

I wonder if anyone has a better plan. Neo4j, is currently being studied as a graphic database. I wonder if such a requirement can be achieved. Has a great god ever used it?

Mar.23,2021

your requirements see no reason to use redis. You can simply use a relational database to implement a tree-level relationship and use a field to save the parent-child path relationship. For example, root 1, which has two nodes, 1-2 talks, 1-3, and 2, has a son node, 1-2-4 talk, and 1-3-5, so statistics can easily get all descendants of this node with a simple like. For example, query path like'1% colors, that is, all descendants of id=1, path like'1-2, that is, all descendants of id=2.


there's nothing wrong with the way you store binary trees. You said that you got the id, of all the descendant nodes from redis and then went to the database to use the new nodes of in Filter that day. Is that so? Select * from tab where id in (ids) and date = sysdate;, that is, if there are many descendant nodes, the ids will be very large. I don't know if that's what you want. But both id and score of your existing redis can be indexed to a relational database (id is equivalent to the primary key, distinct (score) up to 2), so there is no need to use redis. Then hash, the query conditions that often appear in the business, such as this date. If you add a lot of new data every day, you can even make a sub-table.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38bd6-2c145.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38bd6-2c145.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?