KB-2909

IU b/c/f Pure Read-Only Live Proof — Query Appendix (2026-05-28)

12 min read Revision 1
iutests-b-flive-proofquery-appendixsqlread-onlyevidence2026-05-28

IU b/c/f Pure Read-Only Live Proof — Query Appendix (2026-05-28)

Verbatim SELECT-only queries for IU_B_C_F_PURE_READONLY_LIVE_PROOF_100000X, with result summaries. Channel: query_pg (read-only role context_pack_readonly, READ ONLY transaction, AST-validated, no writes/DDL). Companion to iu-b-c-f-pure-readonly-live-proof-2026-05-28.md.

All queries are reproducible. None mutates. current_setting() for arbitrary params is denied by the channel's AST validator (encountered once; replaced with inet_server_addr()/inet_server_port()).


P1 — Identity

SELECT current_user, current_database() AS db, version() AS server_version,
       inet_server_addr()::text AS server_addr, inet_server_port() AS server_port;

context_pack_readonly · directus · PostgreSQL 16.13 · 172.19.0.3 · 5432

P2 — Read-only role confirmation (no write probe)

SELECT rolname, rolsuper, rolcreatedb, rolcreaterole, rolcanlogin, rolconfig
FROM pg_roles WHERE rolname = current_user;

→ rolsuper=f, rolcreatedb=f, rolcreaterole=f, rolcanlogin=t, rolconfig=null

P3 — Object existence

SELECT n.nspname AS schema, c.relname AS name,
  CASE c.relkind WHEN 'r' THEN 'table' WHEN 'v' THEN 'view' WHEN 'm' THEN 'matview'
       WHEN 'p' THEN 'partitioned' ELSE c.relkind::text END AS kind
FROM pg_class c JOIN pg_namespace n ON n.oid=c.relnamespace
WHERE c.relname IN ('information_unit','iu_three_axis_envelope','iu_metadata_tag',
  'iu_metadata_tag_registry','iu_tree_path','iu_relation','iu_sql_link',
  'v_iu_sql_link_resolved','dot_iu_command_catalog','dot_iu_command_run',
  'iu_split_set','iu_merge_set','iu_route_dead_letter','iu_outbound_route')
  AND c.relkind IN ('r','v','m','p')
ORDER BY n.nspname, c.relname;

→ all 14 in public; v_iu_sql_link_resolved is a view.

P4 — Function signatures + volatility

SELECT n.nspname, p.proname, pg_get_function_arguments(p.oid) AS args,
  CASE p.provolatile WHEN 'i' THEN 'immutable' WHEN 's' THEN 'stable' WHEN 'v' THEN 'volatile' END AS volatility,
  t.typname AS return_type
FROM pg_proc p JOIN pg_namespace n ON n.oid=p.pronamespace JOIN pg_type t ON t.oid=p.prorettype
WHERE p.proname IN ('fn_iu_sql_link_validate','fn_iu_subtree','fn_iu_sql_link_inbound_capture',
  'fn_iu_piece_split','fn_iu_piece_merge','fn_iu_structure_op_rollback')
ORDER BY p.proname;

SELECT p.proname, p.proretset, pg_get_function_result(p.oid) AS result_sig
FROM pg_proc p WHERE p.proname IN ('fn_iu_subtree','fn_iu_sql_link_validate');

fn_iu_sql_link_validate(p_link_id uuid)→jsonb STABLE; fn_iu_subtree(p_root uuid)→TABLE(iu_id uuid, canonical_address text, depth int, parent_id uuid, relative_depth int) STABLE (proretset=t). fn_iu_sql_link_inbound_capture→trigger VOLATILE; split/merge/rollback VOLATILE.

P5 — Row counts

SELECT 'information_unit' AS tbl, count(*) FROM information_unit
UNION ALL SELECT 'iu_three_axis_envelope', count(*) FROM iu_three_axis_envelope
UNION ALL SELECT 'iu_metadata_tag', count(*) FROM iu_metadata_tag
UNION ALL SELECT 'iu_metadata_tag_registry', count(*) FROM iu_metadata_tag_registry
UNION ALL SELECT 'iu_tree_path', count(*) FROM iu_tree_path
UNION ALL SELECT 'iu_relation', count(*) FROM iu_relation
UNION ALL SELECT 'iu_sql_link', count(*) FROM iu_sql_link
UNION ALL SELECT 'iu_split_set', count(*) FROM iu_split_set
UNION ALL SELECT 'iu_merge_set', count(*) FROM iu_merge_set
UNION ALL SELECT 'iu_outbound_route', count(*) FROM iu_outbound_route
UNION ALL SELECT 'iu_route_dead_letter', count(*) FROM iu_route_dead_letter
UNION ALL SELECT 'dot_iu_command_catalog', count(*) FROM dot_iu_command_catalog
UNION ALL SELECT 'dot_iu_command_run', count(*) FROM dot_iu_command_run
ORDER BY tbl;

→ information_unit 216 · envelope 216 · metadata_tag 536 · registry 36 · tree_path 199 · relation 60 · sql_link 3 · split_set 0 · merge_set 0 · outbound_route 15 · dead_letter 0 · catalog 42 · command_run 45.


Test b queries

B1 — Axis-B vocabulary families

SELECT r.tag_kind, count(*) AS joined_rows,
       count(mt.id) AS tag_assignments
FROM iu_metadata_tag_registry r
LEFT JOIN iu_metadata_tag mt ON mt.tag_key = r.tag_key
GROUP BY r.tag_kind ORDER BY tag_assignments DESC NULLS LAST;

→ unit_kind 216 · legal_document 143 · section_type 127 · topic 25 · legal_domain 25.

B2 — Applied domain/topic values + IU counts

SELECT r.tag_kind, mt.tag_key, r.tag_label, count(DISTINCT mt.iu_id) AS iu_count
FROM iu_metadata_tag mt JOIN iu_metadata_tag_registry r ON r.tag_key=mt.tag_key
WHERE r.tag_kind IN ('legal_domain','topic')
GROUP BY r.tag_kind, mt.tag_key, r.tag_label
ORDER BY r.tag_kind, iu_count DESC, mt.tag_key LIMIT 40;

→ legal_domain: knowledge_systems 16, governance 5, technology 4. topic: knowledge_graph 10, architecture 5, dot_trigger 3, governance 3, workflow 2, cut_pipeline 1, render_pipeline 1.

B3 — Coverage

SELECT
 (SELECT count(*) FROM information_unit) AS total_iu,
 (SELECT count(DISTINCT iu_id) FROM iu_metadata_tag mt JOIN iu_metadata_tag_registry r ON r.tag_key=mt.tag_key WHERE r.tag_kind='legal_domain') AS iu_with_legal_domain,
 (SELECT count(DISTINCT iu_id) FROM iu_metadata_tag mt JOIN iu_metadata_tag_registry r ON r.tag_key=mt.tag_key WHERE r.tag_kind='topic') AS iu_with_topic,
 (SELECT count(DISTINCT mt.tag_key) FROM iu_metadata_tag mt JOIN iu_metadata_tag_registry r ON r.tag_key=mt.tag_key WHERE r.tag_kind='legal_domain') AS applied_legal_domain_keys,
 (SELECT count(*) FROM iu_metadata_tag_registry WHERE tag_kind='legal_domain') AS registered_legal_domain_keys,
 (SELECT count(*) FROM iu_three_axis_envelope WHERE axis_b_tags IS NOT NULL AND axis_b_tags <> '[]'::jsonb AND axis_b_tags <> '{}'::jsonb) AS env_with_axis_b_tags;

→ total_iu 216 · iu_with_legal_domain 16 · iu_with_topic 16 · applied_legal_domain_keys 3 · registered_legal_domain_keys 3 · env_with_axis_b_tags 216.

B4 — Sample IUs for a law/constitution domain

SELECT e.canonical_address, e.unit_kind, e.section_type, e.lifecycle_status, e.axis_b_tags
FROM iu_metadata_tag mt JOIN iu_three_axis_envelope e ON e.unit_id=mt.iu_id
WHERE mt.tag_key='legal_domain:knowledge_systems'
ORDER BY e.canonical_address LIMIT 5;

→ 5 law_unit rows from dieu39-knowledge-graph-law.md; axis_b_tags jsonb nests legal_domain/topic/unit_kind/section_type/legal_document and matches the normalized tags.


Test c queries

C1 — Depth distribution

SELECT axis_c_depth, count(*) AS units,
       count(*) FILTER (WHERE axis_c_parent_id IS NULL) AS roots_at_depth
FROM iu_three_axis_envelope GROUP BY axis_c_depth ORDER BY axis_c_depth;

→ depth 0: 156 units / 133 roots · depth 1: 55 / 0 · depth 2: 5 / 0.

C2 — Grandchildren (depth 2) + ancestor chains

SELECT unit_id, canonical_address, axis_c_depth, axis_c_parent_id, axis_c_ancestors
FROM iu_three_axis_envelope WHERE axis_c_depth=2 ORDER BY canonical_address;

→ 5 grandchildren in two subtrees: root cb211ee6→child 3477ff71→{P1-1,P1-2,P1-3}; root f1273184→child 10649925→{7b,7c}.

C3 — Full 3-level subtree (STABLE function)

SELECT iu_id, canonical_address, depth, parent_id, relative_depth
FROM fn_iu_subtree('cb211ee6-2b61-496e-b191-ef502ea28345')
ORDER BY relative_depth, canonical_address;

→ 8 nodes: root D38-DIEU35-S4 (d0); P1,P2,P3,P4 (d1); P1-1,P1-2,P1-3 (d2). Linkage consistent.

C4 — Mid-parent + leaf

SELECT 'mid-parent 3477ff71 (P1)' AS case, count(*) AS subtree_size,
       min(relative_depth) AS min_rd, max(relative_depth) AS max_rd
FROM fn_iu_subtree('3477ff71-b8a4-4dd8-b854-d86c1567ba83')
UNION ALL
SELECT 'leaf 5410e681 (P1-1)', count(*), min(relative_depth), max(relative_depth)
FROM fn_iu_subtree('5410e681-6d53-48ba-b202-076ecc857115');

→ mid-parent: 4 nodes (rd 0→1) · leaf: 1 node (rd 0).

C5 — Integrity (orphans / cycles / depth consistency)

SELECT
 (SELECT count(*) FROM iu_three_axis_envelope c WHERE c.axis_c_parent_id IS NOT NULL AND NOT EXISTS (SELECT 1 FROM iu_three_axis_envelope p WHERE p.unit_id=c.axis_c_parent_id)) AS orphan_dangling_parent,
 (SELECT count(*) FROM iu_three_axis_envelope WHERE axis_c_parent_id = unit_id) AS self_parent_cycle,
 (SELECT count(*) FROM iu_three_axis_envelope WHERE unit_id = ANY(axis_c_ancestors[1:array_length(axis_c_ancestors,1)-1])) AS self_in_ancestors_cycle,
 (SELECT count(*) FROM iu_three_axis_envelope WHERE axis_c_parent_id IS NULL AND axis_c_depth <> 0) AS root_with_nonzero_depth,
 (SELECT count(*) FROM iu_three_axis_envelope WHERE axis_c_parent_id IS NOT NULL AND axis_c_depth = 0) AS depth0_with_parent,
 (SELECT count(*) FROM iu_three_axis_envelope c JOIN iu_three_axis_envelope p ON p.unit_id=c.axis_c_parent_id WHERE c.axis_c_depth <> p.axis_c_depth + 1) AS depth_parent_mismatch;

→ orphan 0 · self_parent 0 · self_in_ancestors 0 · root_nonzero_depth 0 · depth0_with_parent 23 · depth_parent_mismatch 23.

C6 — Proof fn_iu_subtree is authoritative over stale stored depth

WITH stale AS (
  SELECT c.unit_id AS child_id, c.axis_c_parent_id AS parent_id,
         c.axis_c_depth AS child_stored_depth, p.axis_c_depth AS parent_stored_depth, c.canonical_address
  FROM iu_three_axis_envelope c JOIN iu_three_axis_envelope p ON p.unit_id=c.axis_c_parent_id
  WHERE c.axis_c_depth=0 AND c.axis_c_parent_id IS NOT NULL
  ORDER BY c.canonical_address LIMIT 1)
SELECT s.canonical_address AS stale_child, s.child_stored_depth, s.parent_stored_depth,
 (SELECT relative_depth FROM fn_iu_subtree(s.parent_id) t WHERE t.iu_id=s.child_id) AS fn_relative_depth_under_parent,
 (SELECT count(*) FROM fn_iu_subtree(s.parent_id)) AS parent_subtree_size
FROM stale s;

DIEU-37-v3.3#changelog: stored depth 0, parent stored depth 0, fn relative_depth = 1 (correct), parent subtree size 17. Stored depth stale; function authoritative.


Test f queries

SELECT id, canonical_address, link_role, object_kind, object_schema, object_name,
       collection_name, direction, lifecycle_status, enabled, object_fingerprint,
       function_identity, trigger_name
FROM iu_sql_link ORDER BY canonical_address;

→ 3 rows, all active + enabled=false + fingerprint NULL: view v_iu_section_type_vocab_sync (governs/outbound), function fn_iu_three_axis_envelope_refresh(text,boolean) (governs/outbound), table tac_publication (represents/bidirectional).

F2 — Validate via view + direct function (cross-check)

SELECT v.id, v.object_kind, v.object_name, v.enabled,
       v.validation AS view_validation,
       fn_iu_sql_link_validate(v.id) AS direct_validate
FROM v_iu_sql_link_resolved v ORDER BY v.canonical_address;

→ all 3 resolved:true (pg_class_match for view+table, pg_proc_match for function); view_validation == direct_validate (identical incl. checked_at).


Stability + no-mutation re-run

SELECT
 (SELECT count(DISTINCT iu_id) FROM iu_metadata_tag WHERE tag_key='legal_domain:knowledge_systems') AS b_knowledge_systems_iu_rerun,
 (SELECT count(*) FROM fn_iu_subtree('cb211ee6-2b61-496e-b191-ef502ea28345')) AS c_subtree_size_rerun,
 (SELECT count(*) FROM v_iu_sql_link_resolved WHERE (validation->>'resolved')::boolean IS TRUE) AS f_links_resolved_rerun,
 (SELECT count(*) FROM iu_sql_link) AS f_total_links_rerun,
 (SELECT count(*) FROM dot_iu_command_run) AS audit_rows_now,
 (SELECT count(*) FROM iu_split_set) AS split_set_now,
 (SELECT count(*) FROM iu_merge_set) AS merge_set_now;

→ b 16 · c 8 · f 3/3 · audit_rows 45 (delta 0) · split 0 · merge 0. Stable; zero mutation.

Back to Knowledge Hub knowledge/dev/reports/architecture/iu-b-c-f-pure-readonly-live-proof-query-appendix-2026-05-28.md