/harness-claude:db-hierarchical-datafrom harness-claude
Guides selection between adjacency list, nested sets, closure table, and materialized path for modeling hierarchies in relational databases based on read/write ratio, query patterns, and tree depth.
Claude never picks this skill on its own
Its frontmatter has no description. Without a description, Claude Code leaves it out of the list Claude chooses from. Typing /harness-claude:db-hierarchical-data still runs it.
What the skill costs in Claude's context, stage by stage
No description Claude Code can read, so Claude's list leaves it out: only you can start it.
SKILL.md joins the conversation and stays.
Choosing between adjacency list, nested sets, closure table, and materialized path based on read/write ratio, query patterns, and tree depth.
Four approaches exist for modeling hierarchies in relational databases. Each trades off read performance, write performance, storage, and integrity differently:
| Operation | Adjacency List | Nested Sets | Closure Table | Materialized Path |
|---|---|---|---|---|
| Insert node | O(1) | O(n) | O(depth) | O(1) |
| Delete node | O(1) | O(n) | O(subtree) | O(subtree) |
| Move subtree | O(1) | O(n) | O(subtree^2) | O(subtree) |
| Get children | O(1) indexed | O(1) | O(1) | O(1) pattern match |
| Get subtree | O(depth) recursive | O(1) range | O(1) join | O(1) LIKE |
| Get ancestors | O(depth) recursive | O(1) range | O(1) join | O(1) split |
| Get depth | Recursive | Computed | Stored | Count separators |
| Storage overhead | None | 2 cols/row | O(N log N) rows | 1 col/row |
| Referential integrity | FK enforced | App-level | FK enforced | App-level |
Decision rules:
ltree. Compact, GiST-indexable, good read/write balance.Three scenarios demonstrating which model to choose:
Scenario 1: Comment threading (frequent inserts, rare full-tree reads)
Choose adjacency list. Comments are inserted constantly. Full-thread reads (subtree) happen only when a user opens a thread. The recursive CTE cost is acceptable for occasional reads:
-- O(1) insert
INSERT INTO comments (body, parent_id) VALUES ('Reply', 42);
-- Occasional subtree read via recursive CTE
WITH RECURSIVE thread AS (
SELECT * FROM comments WHERE id = 1
UNION ALL
SELECT c.* FROM comments c JOIN thread t ON c.parent_id = t.id
)
SELECT * FROM thread;
Scenario 2: Product taxonomy (updated weekly, queried constantly)
Choose nested sets or closure table. The taxonomy changes once a week but "all products in Electronics" runs thousands of times per day:
-- Nested sets: O(1) subtree read, no recursion
SELECT * FROM categories WHERE lft BETWEEN 2 AND 11;
-- Closure table: O(1) subtree read via join
SELECT c.* FROM categories c
JOIN category_paths cp ON c.id = cp.descendant_id
WHERE cp.ancestor_id = 5;
If the taxonomy needs referential integrity, prefer closure table. If pure read speed matters most, prefer nested sets.
Scenario 3: RBAC permission hierarchy (moderate changes, frequent "is ancestor?" checks)
Choose closure table. The "is X an ancestor of Y?" check is a single-row existence query:
SELECT EXISTS(
SELECT 1 FROM role_paths
WHERE ancestor_id = 10 AND descendant_id = 42
);
-- 0.2ms with index
LIKE '/1/5/%') is fragile, prone to injection, and cannot use specialized indexes. Use ltree on PostgreSQL.ltree extension for materialized path -- the recommended default for PostgreSQL users who need hierarchy queries without closure table complexity:
CREATE EXTENSION ltree;
CREATE TABLE categories (
id serial PRIMARY KEY,
name varchar NOT NULL,
path ltree NOT NULL
);
CREATE INDEX idx_categories_path ON categories USING gist (path);
-- Insert with path
INSERT INTO categories (name, path) VALUES
('Electronics', 'electronics'),
('Computers', 'electronics.computers'),
('Laptops', 'electronics.computers.laptops');
ltree operators:
@> ancestor check: 'electronics' @> 'electronics.computers.laptops' -- true<@ descendant check: 'electronics.computers.laptops' <@ 'electronics' -- true~ regex match: path ~ '*.computers.*'? lquery match: path ? 'electronics.*{1,2}' -- depth 1-2 under electronicsGiST index on path enables fast ancestor/descendant checks without joins or recursion. ltree is often the best balance of simplicity and performance for PostgreSQL hierarchies.
Hybrid models combine two approaches for different query patterns:
Migration between models:
Depth limits and performance cliffs:
MySQL lacks the ltree extension. Materialized path on MySQL requires:
/1/5/12/WHERE path LIKE '/1/5/%'MySQL recommendations by workload:
WITH RECURSIVE (MySQL 8.0+)MySQL nested sets work identically to PostgreSQL but lack exclusion constraints for integrity validation.
Three companies, three choices:
Slack-like messaging: Adjacency list. 1B messages total, threads rarely exceed depth 5. Insert latency under 1ms. Recursive CTE for thread display adds 3-8ms -- acceptable since threads are loaded on-demand.
Amazon-like product taxonomy: Nested sets. 200K categories, rebuilt nightly from the merchandising system. Subtree queries ("all products in Electronics") complete in under 1ms. The nightly rebuild (full renumbering) takes 4 seconds.
AWS-like IAM: Closure table. 500K permission nodes in a 15-level hierarchy. "Is X an ancestor of Y?" completes in 0.2ms. Node additions average 50/day -- each insert copies ~15 closure rows. The 1.5M closure row overhead (3x node count) is justified by the 40x speedup on ancestry checks.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub intense-visions/harness-engineering --plugin harness-claudeRead when SKILL.md points to them.
793 skills in this plugin
/a11y-aria-patternsARIA Patterns> Apply ARIA roles, states, and properties correctly to enhance assistive technology support for custom widgets/a11y-color-contrastColor Contrast and Color Independence> Ensure sufficient color contrast ratios and never use color as the sole means of conveying information/a11y-form-patternsAccessible Form Patterns> Build accessible forms with proper labeling, grouped controls, inline validation, and clear error communicationOther plugins' skills for the same job