transitive-closure-table

Closure Table INSERT statement including the level/distance column

亡梦爱人 提交于 2019-12-13 14:59:10
问题 I'm referring Bill Karwin's presentation in order to implement a closure table which will help me manage hierarchies. Unfortunately, the presentation does not show how I could insert/update the Level column mentioned on slide 67; this would have been very useful. I've been giving it a thought but I couldn't come up with something concrete that I could test. Here's what I got so far: create procedure USP_OrganizationUnitHierarchy_AddChild @ParentId UNIQUEIDENTIFIER, @NewChildId

update table based on subquery of table

十年热恋 提交于 2019-12-13 03:55:31
问题 I have am using a closure table for some page heirarchy. I want to be able to delete a page and update the level of the children it leaves. par child level 1 1 0 1 2 1 2 2 0 1 3 2 2 3 1 3 3 0 1 4 3 2 4 2 3 4 1 4 4 0 Prior to deleting page 3 I've attempted to update the levels and then deleteing reocrds for page 3 the goal of such being: par child level 1 1 0 1 2 1 2 2 0 1 4 2 2 4 1 4 4 0 describing this with a (invalid) suquery like so: UPDATE tbl_page_structures SET page_level = page_level -

Closure Tables - Is this enough data to display a tree view?

瘦欲@ 提交于 2019-12-11 13:21:48
问题 Here is the table I have created by testing the closure table method. | id | parentId | childId | hops | | | | | 270 | 6 | 6 | 0 | 271 | 7 | 7 | 0 | 272 | 8 | 8 | 0 | 273 | 9 | 9 | 0 | 276 | 10 | 10 | 0 | 281 | 9 | 10 | 1 | 282 | 7 | 9 | 1 | 283 | 7 | 10 | 2 | 285 | 7 | 8 | 1 | 286 | 6 | 7 | 1 | 287 | 6 | 9 | 2 | 288 | 6 | 10 | 3 | 289 | 6 | 8 | 2 | 293 | 6 | 9 | 1 | 294 | 6 | 10 | 2 I am trying to create a simple tree of this using PHP. There does not seem to be enough data to create the

mySQL transitive closure table

淺唱寂寞╮ 提交于 2019-12-11 07:26:12
问题 I have some code I've been using in SQL Server to generate a closure table from another table that has just the direct parent/child relationships, I can run very simple queries against this to determine lineage. Now I am needing to do all this in mySQL, but I am having trouble with the recursive querying to generate the closure table... My original SQL server query is WHILE @@ROWCOUNT>0 INSERT INTO [ClosureTable] ([Ancestor], [Descendent]) SELECT distinct [Parent],[tc].[Descendent] FROM

How can I display tree structure in HTML from closure table

♀尐吖头ヾ 提交于 2019-12-10 17:33:59
问题 I'm storing some hierarchical data in MySQL. For various reasons, I've decided to use closure tables (instead of nested sets, adjacency lists, and the like). It's been working great for me so far, but now I'm trying to figure out how to actually display this tree in HTML (i.e. with correct indentations). As an example, let's say I have a tree like so... Food Fruits Apples Pears Vegetables Carrots My "Foods" table would look like this... [ID] [PARENT_ID] [NAME] 1 0 Food 2 1 Fruits 3 1

How to traverse a hierarchical tree-structure structure backwards using recursive queries

喜夏-厌秋 提交于 2019-12-09 04:39:37
问题 I'm using PostgreSQL 9.1 to query hierarchical tree-structured data, consisting of edges (or elements) with connections to nodes. The data are actually for stream networks, but I've abstracted the problem to simple data types. Consider the example tree table. Each edge has length and area attributes, which are used to determine some useful metrics from the network. CREATE TEMP TABLE tree ( edge text PRIMARY KEY, from_node integer UNIQUE NOT NULL, -- can also act as PK to_node integer

Running a SELECT query on a closure table with a JOIN?

落爺英雄遲暮 提交于 2019-12-08 09:54:34
问题 I have an app set up which has nested comments attached to posts. I decided to use the closure table method (slide 40) for the comments due to how cheap hard disk space is versus how easy it seems to be to query and manage the tree structure. However, I'm running into a problem. I can't seem to figure out how to grab the tree path based on the post ID, not the ancestor ID (slide 49). My database structure looks like this: table: comment_paths -------------------- parent_id (fk on comments.id)

Finding the transitive closure of a graph

青春壹個敷衍的年華 提交于 2019-12-06 09:13:02
I am trying to calculate a transitive closure of a graph. Let`s consider this graph as an example (the picture depicts the graph, its adjacency and connectivity matrix): Using Warshall's algorithm, which i found on this page, I generate this connectivity matrix (=transitive closure?), that is different from the one in the picture: 01111 01111 01011 01111 01111 I have also tried using this applet which also gives me a different result: 01111 01111 01111 01111 01111 So I'm a little confused right now, since I don't know which matrix is the right one. Can someone shed some light on my problem? C

How do I query for all the nodes between two nodes in a tree?

耗尽温柔 提交于 2019-12-06 04:41:55
I have a hierarchical database strucutre, e.g. columns ID and PARENT_ID defined for each row, with the top level rows having a NULL PARENT_ID . I have all the relationships from this table flattened into another table, e.g. if there were three records in a single hierarchy of grandparent, parent, grandchild, there would be 3 records: **ANCESTOR, DESCENDANT** grantparent, parent grandparent, grandchild parent, grandchild Rather than execute a hierarchical query to determine that the grandchild is a descendant of the grandparent I can simply check for the existence of a (grandparent, grandchild)

hierarchical data in a database: recursive query vs. closure tables vs. graph database

六眼飞鱼酱① 提交于 2019-12-05 19:11:28
问题 I'm starting on a new project that has some hierarchical data and I'm looking at all the options for storing that in a database at the moment. I am using PostgreSQL, which does allow recursive querying. I also looked into design patterns for relational databases, such as closure tables and I had a look at graph database solutions such as neo4j. I'm finding it difficult to decide between those options. For example: given that my RDBMS allows recursive queries, would it still make sense to use