Skip to content

Commit 84bf3ab

Browse files
jhfclaude
andcommitted
test: Add hierarchy function benchmarks to 401 BRREG test (~29K rows)
Benchmarks statistical_unit_stats and relevant_statistical_units against the larger BRREG dataset to catch performance regressions at scale. Output goes to test/expected/performance/401_hierarchy_benchmark.perf. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fa70414 commit 84bf3ab

File tree

4 files changed

+120
-5
lines changed

4 files changed

+120
-5
lines changed

test/expected/401_import_jobs_for_brreg_selection.out

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
--
1111
-- Performance benchmark data is written to:
1212
-- test/expected/performance/401_import_benchmark.perf
13+
-- test/expected/performance/401_hierarchy_benchmark.perf
1314
--
1415
-- ============================================================================
1516
-- PHASE 0: SETUP
@@ -842,6 +843,57 @@ SELECT queue, state, count(*) FROM worker.tasks AS t JOIN worker.command_registr
842843

843844
COMMIT;
844845
-- ============================================================================
846+
-- PHASE 3C: HIERARCHY FUNCTION BENCHMARKS (~29K rows scale)
847+
-- ============================================================================
848+
BEGIN;
849+
-- Pick the enterprise with the most establishments (deepest hierarchy)
850+
SELECT su.unit_id AS ent_unit_id
851+
FROM public.statistical_unit AS su
852+
WHERE su.unit_type = 'enterprise'
853+
AND su.valid_from <= '2025-01-01' AND '2025-01-01' < su.valid_until
854+
ORDER BY su.stats -> 'establishment_count' -> 'count' DESC NULLS LAST
855+
LIMIT 1 \gset
856+
-- Pick a legal_unit with the most establishments
857+
SELECT su.unit_id AS lu_unit_id
858+
FROM public.statistical_unit AS su
859+
WHERE su.unit_type = 'legal_unit'
860+
AND su.valid_from <= '2025-01-01' AND '2025-01-01' < su.valid_until
861+
ORDER BY su.stats -> 'establishment_count' -> 'count' DESC NULLS LAST
862+
LIMIT 1 \gset
863+
\set perf_file test/expected/performance/401_hierarchy_benchmark.perf
864+
\pset tuples_only on
865+
\pset footer off
866+
\o :perf_file
867+
SELECT '# Benchmark: statistical_unit_stats and relevant_statistical_units (~29K rows)';
868+
SELECT '# Date: ' || now()::text;
869+
SELECT '';
870+
SELECT '## EXPLAIN ANALYZE: statistical_unit_stats (legal_unit)';
871+
\pset tuples_only off
872+
EXPLAIN ANALYZE
873+
SELECT * FROM public.statistical_unit_stats('legal_unit', :lu_unit_id, '2025-01-01'::DATE);
874+
\pset tuples_only on
875+
SELECT '';
876+
SELECT '## EXPLAIN ANALYZE: statistical_unit_stats (enterprise)';
877+
\pset tuples_only off
878+
EXPLAIN ANALYZE
879+
SELECT * FROM public.statistical_unit_stats('enterprise', :ent_unit_id, '2025-01-01'::DATE);
880+
\pset tuples_only on
881+
SELECT '';
882+
SELECT '## EXPLAIN ANALYZE: relevant_statistical_units (legal_unit)';
883+
\pset tuples_only off
884+
EXPLAIN ANALYZE
885+
SELECT * FROM public.relevant_statistical_units('legal_unit', :lu_unit_id, '2025-01-01'::DATE);
886+
\pset tuples_only on
887+
SELECT '';
888+
SELECT '## EXPLAIN ANALYZE: relevant_statistical_units (enterprise)';
889+
\pset tuples_only off
890+
EXPLAIN ANALYZE
891+
SELECT * FROM public.relevant_statistical_units('enterprise', :ent_unit_id, '2025-01-01'::DATE);
892+
\o
893+
\pset tuples_only off
894+
\pset footer on
895+
ROLLBACK;
896+
-- ============================================================================
845897
-- PHASE 4: CLEANUP
846898
-- ============================================================================
847899
\echo 'Resuming background worker'

test/expected/performance/401_hierarchy_benchmark.perf

Whitespace-only changes.

test/expected/performance/401_import_benchmark.perf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
slug | total_rows | analysis_sec | processing_sec | total_sec | analysis_rows_per_sec | processing_rows_per_sec
1616
----------------------------------+------------+--------------+----------------+-----------+-----------------------+-------------------------
17-
import_hovedenhet_2025_selection | 4924 | 3.03 | 5.54 | 8.57 | 1623.12 | 904.93
18-
import_underenhet_2025_selection | 24027 | 14.70 | 50.77 | 65.46 | 1634.74 | 474.13
17+
import_hovedenhet_2025_selection | 4924 | 3.26 | 6.08 | 9.34 | 1511.10 | 823.23
18+
import_underenhet_2025_selection | 24027 | 15.78 | 52.98 | 68.76 | 1522.21 | 454.26
1919

2020

2121

@@ -25,8 +25,8 @@
2525

2626
slug | total_rows | analysis_ms_per_row | processing_ms_per_row
2727
----------------------------------+------------+---------------------+-----------------------
28-
import_hovedenhet_2025_selection | 4924 | 0.62 | 1.13
29-
import_underenhet_2025_selection | 24027 | 0.61 | 2.11
28+
import_hovedenhet_2025_selection | 4924 | 0.66 | 1.24
29+
import_underenhet_2025_selection | 24027 | 0.66 | 2.20
3030

3131

3232

@@ -36,5 +36,5 @@
3636

3737
base_phase | lu_rows | es_rows | row_ratio | ms_per_row_ratio | scaling_assessment
3838
------------+---------+---------+-----------+------------------+--------------------
39-
LU | 4924 | 24027 | 4.88 | 1.88 | SUBLINEAR
39+
LU | 4924 | 24027 | 4.88 | 1.78 | SUBLINEAR
4040

test/sql/401_import_jobs_for_brreg_selection.sql

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
--
1111
-- Performance benchmark data is written to:
1212
-- test/expected/performance/401_import_benchmark.perf
13+
-- test/expected/performance/401_hierarchy_benchmark.perf
1314
--
1415

1516
-- ============================================================================
@@ -300,6 +301,68 @@ SELECT queue, state, count(*) FROM worker.tasks AS t JOIN worker.command_registr
300301

301302
COMMIT;
302303

304+
-- ============================================================================
305+
-- PHASE 3C: HIERARCHY FUNCTION BENCHMARKS (~29K rows scale)
306+
-- ============================================================================
307+
BEGIN;
308+
309+
-- Pick the enterprise with the most establishments (deepest hierarchy)
310+
SELECT su.unit_id AS ent_unit_id
311+
FROM public.statistical_unit AS su
312+
WHERE su.unit_type = 'enterprise'
313+
AND su.valid_from <= '2025-01-01' AND '2025-01-01' < su.valid_until
314+
ORDER BY su.stats -> 'establishment_count' -> 'count' DESC NULLS LAST
315+
LIMIT 1 \gset
316+
317+
-- Pick a legal_unit with the most establishments
318+
SELECT su.unit_id AS lu_unit_id
319+
FROM public.statistical_unit AS su
320+
WHERE su.unit_type = 'legal_unit'
321+
AND su.valid_from <= '2025-01-01' AND '2025-01-01' < su.valid_until
322+
ORDER BY su.stats -> 'establishment_count' -> 'count' DESC NULLS LAST
323+
LIMIT 1 \gset
324+
325+
\set perf_file test/expected/performance/401_hierarchy_benchmark.perf
326+
\pset tuples_only on
327+
\pset footer off
328+
\o :perf_file
329+
330+
SELECT '# Benchmark: statistical_unit_stats and relevant_statistical_units (~29K rows)';
331+
SELECT '# Date: ' || now()::text;
332+
SELECT '';
333+
334+
SELECT '## EXPLAIN ANALYZE: statistical_unit_stats (legal_unit)';
335+
\pset tuples_only off
336+
EXPLAIN ANALYZE
337+
SELECT * FROM public.statistical_unit_stats('legal_unit', :lu_unit_id, '2025-01-01'::DATE);
338+
339+
\pset tuples_only on
340+
SELECT '';
341+
SELECT '## EXPLAIN ANALYZE: statistical_unit_stats (enterprise)';
342+
\pset tuples_only off
343+
EXPLAIN ANALYZE
344+
SELECT * FROM public.statistical_unit_stats('enterprise', :ent_unit_id, '2025-01-01'::DATE);
345+
346+
\pset tuples_only on
347+
SELECT '';
348+
SELECT '## EXPLAIN ANALYZE: relevant_statistical_units (legal_unit)';
349+
\pset tuples_only off
350+
EXPLAIN ANALYZE
351+
SELECT * FROM public.relevant_statistical_units('legal_unit', :lu_unit_id, '2025-01-01'::DATE);
352+
353+
\pset tuples_only on
354+
SELECT '';
355+
SELECT '## EXPLAIN ANALYZE: relevant_statistical_units (enterprise)';
356+
\pset tuples_only off
357+
EXPLAIN ANALYZE
358+
SELECT * FROM public.relevant_statistical_units('enterprise', :ent_unit_id, '2025-01-01'::DATE);
359+
360+
\o
361+
\pset tuples_only off
362+
\pset footer on
363+
364+
ROLLBACK;
365+
303366
-- ============================================================================
304367
-- PHASE 4: CLEANUP
305368
-- ============================================================================

0 commit comments

Comments
 (0)