hierarchy-data-closure-table

This is a mysql and postgresql store procedure and trigger implementation of closure table in RDBMS about hierarchy data model.

Github星跟踪图

Closure Table

This is a mysql store procedure and trigger implementation of closure table in
RDBMS about hierarchy data model.

Closure Table Node Paths

Query the subtree nodes

Features

  • Automatically add new paths when you insert a new node

  • Automatically update(DELETE old paths and INSERT new paths) paths when you
    update parent_id of a node. (This means move a node/subtree to a new parent)

  • A store procedure that is used to select a whole subtree by a node_id
    (if the node_id has descendant)

Triggers

  • trigger_add_paths

The trigger is execute when insert a node into prefix_nodes table, and call p_node_add to add update paths.

  • prefix_node_move:

The trigger is execute when update the parent_id column of prefix_nodes
table only if OLD.parent_id != NEW.parent_id

Store Procedures

  • p_node_add(param_node_new_id INT UNSIGNED,param_node_parent_id INT UNSIGNED)

    Add new paths when insert a node to prefix_nodes table

  • p_get_tree(node_id INT UNSIGNED)

    Get subtree by a node id

  • p_node_move(node_old_parent_id INT UNSIGNED,node_new_parent_id INT UNSIGNED)

    Update paths when move a node to a new parent node

  • p_node_hide(node_id INT UNSIGNED, is_deleted INT UNSIGNED)

    Hide or show nodes from subtree, explains as following:

    • Step 1. call p_get_tree(6) get the HARDWARE subtree,
    • Step 2. call p_node_hide(6, 0) to hide a subtree,
    • Step 3. call p_get_tree(6) get the HARDWARE subtree, when you get a subtree, it is not show in the result.
    • Step 4. call p_node_hide(6, 1) show HARDWARE subtree

MySQL Files

  • ./mysql/tables.sql

    Create tables.

  • ./mysql/sample_data.sql

    Some insert statements for testing

Postgresql Files

TODO::

主要指标

概览
名称与所有者developerworks/hierarchy-data-closure-table
主编程语言PLpgSQL
编程语言PLpgSQL (语言数: 1)
平台
许可证Other
所有者活动
创建于2013-05-14 05:16:38
推送于2023-07-13 06:10:15
最后一次提交2023-07-13 14:10:14
发布数0
用户参与
星数175
关注者数18
派生数59
提交数29
已启用问题?
问题数14
打开的问题数7
拉请求数3
打开的拉请求数0
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?