Skip to content

Commit 614ce95

Browse files
jhfclaude
andcommitted
perf: Spawn only populated partitions in derive_statistical_unit_facet
The integrity check compared staging partition count against a hardcoded 128 threshold. For small datasets (~40 units → ~35 hash buckets), this forced a full 128-partition refresh every time, spawning ~100 empty tasks. Fix: Compare staging against actual populated partitions from statistical_unit.report_partition_seq. Full refresh now spawns only partitions that have data. Also fix test determinism: nextval() survives ROLLBACK, so shared tests running sequentially saw accumulated sequence values, causing non-deterministic unit_ids and partition counts. Added ALTER SEQUENCE RESTART in test/setup.sql (transactional DDL, reverted on ROLLBACK). Suppress setup/teardown boilerplate in test output with \set ECHO none and \o /dev/null for cleaner expected files (-3000 lines). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0853dfd commit 614ce95

File tree

69 files changed

+1999
-4986
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1999
-4986
lines changed

app/src/lib/database.types.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3323,6 +3323,7 @@ export type Database = {
33233323
related_enterprise_ids: number[] | null
33243324
related_establishment_ids: number[] | null
33253325
related_legal_unit_ids: number[] | null
3326+
report_partition_seq: number | null
33263327
search: string | null
33273328
secondary_activity_category_code: string | null
33283329
secondary_activity_category_id: number | null
@@ -3410,6 +3411,7 @@ export type Database = {
34103411
related_enterprise_ids?: number[] | null
34113412
related_establishment_ids?: number[] | null
34123413
related_legal_unit_ids?: number[] | null
3414+
report_partition_seq?: number | null
34133415
search?: string | null
34143416
secondary_activity_category_code?: string | null
34153417
secondary_activity_category_id?: number | null
@@ -3497,6 +3499,7 @@ export type Database = {
34973499
related_enterprise_ids?: number[] | null
34983500
related_establishment_ids?: number[] | null
34993501
related_legal_unit_ids?: number[] | null
3502+
report_partition_seq?: number | null
35003503
search?: string | null
35013504
secondary_activity_category_code?: string | null
35023505
secondary_activity_category_id?: number | null
@@ -3568,6 +3571,66 @@ export type Database = {
35683571
},
35693572
Relationships: []
35703573
},
3574+
statistical_unit_facet_dirty_partitions: {
3575+
Row: {
3576+
partition_seq: number
3577+
},
3578+
Insert: {
3579+
partition_seq: number
3580+
},
3581+
Update: {
3582+
partition_seq?: number
3583+
},
3584+
Relationships: []
3585+
},
3586+
statistical_unit_facet_staging: {
3587+
Row: {
3588+
count: number
3589+
legal_form_id: number | null
3590+
partition_seq: number
3591+
physical_country_id: number | null
3592+
physical_region_path: string | null
3593+
primary_activity_category_path: string | null
3594+
sector_path: string | null
3595+
stats_summary: Json | null
3596+
status_id: number | null
3597+
unit_type: Database["public"]["Enums"]["statistical_unit_type"] | null
3598+
valid_from: string | null
3599+
valid_to: string | null
3600+
valid_until: string | null
3601+
},
3602+
Insert: {
3603+
count: number
3604+
legal_form_id?: number | null
3605+
partition_seq: number
3606+
physical_country_id?: number | null
3607+
physical_region_path?: string | null
3608+
primary_activity_category_path?: string | null
3609+
sector_path?: string | null
3610+
stats_summary?: Json | null
3611+
status_id?: number | null
3612+
unit_type?: Database["public"]["Enums"]["statistical_unit_type"] | null
3613+
valid_from?: string | null
3614+
valid_to?: string | null
3615+
valid_until?: string | null
3616+
},
3617+
Update: {
3618+
count?: number
3619+
legal_form_id?: number | null
3620+
partition_seq?: number
3621+
physical_country_id?: number | null
3622+
physical_region_path?: string | null
3623+
primary_activity_category_path?: string | null
3624+
sector_path?: string | null
3625+
stats_summary?: Json | null
3626+
status_id?: number | null
3627+
unit_type?: Database["public"]["Enums"]["statistical_unit_type"] | null
3628+
valid_from?: string | null
3629+
valid_to?: string | null
3630+
valid_until?: string | null
3631+
},
3632+
Relationships: []
3633+
},
35713634
statistical_unit_staging: {
35723635
Row: {
35733636
activity_category_paths: string[] | null
@@ -3632,6 +3695,7 @@ export type Database = {
36323695
related_enterprise_ids: number[] | null
36333696
related_establishment_ids: number[] | null
36343697
related_legal_unit_ids: number[] | null
3698+
report_partition_seq: number | null
36353699
search: string | null
36363700
secondary_activity_category_code: string | null
36373701
secondary_activity_category_id: number | null
@@ -3718,6 +3782,7 @@ export type Database = {
37183782
related_enterprise_ids?: number[] | null
37193783
related_establishment_ids?: number[] | null
37203784
related_legal_unit_ids?: number[] | null
3785+
report_partition_seq?: number | null
37213786
search?: string | null
37223787
secondary_activity_category_code?: string | null
37233788
secondary_activity_category_id?: number | null
@@ -3804,6 +3869,7 @@ export type Database = {
38043869
related_enterprise_ids?: number[] | null
38053870
related_establishment_ids?: number[] | null
38063871
related_legal_unit_ids?: number[] | null
3872+
report_partition_seq?: number | null
38073873
search?: string | null
38083874
secondary_activity_category_code?: string | null
38093875
secondary_activity_category_id?: number | null
@@ -12497,6 +12563,22 @@ export type Database = {
1249712563
}
1249812564
Returns: string
1249912565
},
12566+
report_partition_seq: {
12567+
Args: {
12568+
p_unit_type?: string
12569+
p_unit_id?: number
12570+
p_num_partitions?: number
12571+
}
12572+
Returns: number
12573+
}
12574+
| {
12575+
Args: {
12576+
p_unit_type?: Database["public"]["Enums"]["statistical_unit_type"]
12577+
p_unit_id?: number
12578+
p_num_partitions?: number
12579+
}
12580+
Returns: number
12581+
},
1250012582
reset: {
1250112583
Args: {
1250212584
confirmed?: boolean

doc/data-model.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Enumerated types used across the schema, with their possible values.
139139
- Enums: `unit_type` (`public.statistical_unit_type`).
140140
- `timeline_establishment, `timeline_legal_unit`, `timeline_enterprise`(unit_type, name, primary_activity_category_path, primary_activity_category_code, secondary_activity_category_path, secondary_activity_category_code, activity_category_paths, sector_path, sector_code, sector_name, data_source_codes, legal_form_code, legal_form_name, physical_postcode, physical_region_path, physical_region_code, postal_postcode, postal_region_path, postal_region_code, email_address, unit_size_code, status_code, invalid_codes, unit_id, primary_activity_category_id, secondary_activity_category_id, sector_id, legal_form_id, physical_region_id, physical_country_id, postal_region_id, postal_country_id, unit_size_id, status_id, last_edit_by_user_id, establishment_id, legal_unit_id, enterprise_id, valid_from, valid_to, valid_until, last_edit_at, birth_date, death_date, search, data_source_ids, physical_address_part1, physical_address_part2, physical_address_part3, physical_postplace, physical_country_iso_2, physical_latitude, physical_longitude, physical_altitude, domestic, postal_address_part1, postal_address_part2, postal_address_part3, postal_postplace, postal_country_iso_2, postal_latitude, postal_longitude, postal_altitude, web_address, phone_number, landline, mobile_number, fax_number, used_for_counting, last_edit_comment, has_legal_unit, primary_for_enterprise, primary_for_legal_unit, stats, stats_summary, related_establishment_ids, excluded_establishment_ids, included_establishment_ids, related_legal_unit_ids, excluded_legal_unit_ids, included_legal_unit_ids, related_enterprise_ids, excluded_enterprise_ids, included_enterprise_ids)` (temporal)
141141
- Enums: `unit_type` (`public.statistical_unit_type`).
142-
- `statistical_unit(unit_type, external_idents, name, primary_activity_category_path, primary_activity_category_code, secondary_activity_category_path, secondary_activity_category_code, activity_category_paths, sector_path, sector_code, sector_name, data_source_codes, legal_form_code, legal_form_name, physical_postcode, physical_region_path, physical_region_code, postal_postcode, postal_region_path, postal_region_code, email_address, unit_size_code, status_code, invalid_codes, tag_paths, unit_id, primary_activity_category_id, secondary_activity_category_id, sector_id, legal_form_id, physical_region_id, physical_country_id, postal_region_id, postal_country_id, unit_size_id, status_id, last_edit_by_user_id, valid_from, valid_to, valid_until, last_edit_at, valid_range, birth_date, death_date, search, data_source_ids, physical_address_part1, physical_address_part2, physical_address_part3, physical_postplace, physical_country_iso_2, physical_latitude, physical_longitude, physical_altitude, domestic, postal_address_part1, postal_address_part2, postal_address_part3, postal_postplace, postal_country_iso_2, postal_latitude, postal_longitude, postal_altitude, web_address, phone_number, landline, mobile_number, fax_number, used_for_counting, last_edit_comment, has_legal_unit, related_establishment_ids, excluded_establishment_ids, included_establishment_ids, related_legal_unit_ids, excluded_legal_unit_ids, included_legal_unit_ids, related_enterprise_ids, excluded_enterprise_ids, included_enterprise_ids, stats, stats_summary, included_establishment_count, included_legal_unit_count, included_enterprise_count)` (temporal)
142+
- `statistical_unit(unit_type, external_idents, name, primary_activity_category_path, primary_activity_category_code, secondary_activity_category_path, secondary_activity_category_code, activity_category_paths, sector_path, sector_code, sector_name, data_source_codes, legal_form_code, legal_form_name, physical_postcode, physical_region_path, physical_region_code, postal_postcode, postal_region_path, postal_region_code, email_address, unit_size_code, status_code, invalid_codes, tag_paths, unit_id, primary_activity_category_id, secondary_activity_category_id, sector_id, legal_form_id, physical_region_id, physical_country_id, postal_region_id, postal_country_id, unit_size_id, status_id, last_edit_by_user_id, valid_from, valid_to, valid_until, last_edit_at, valid_range, birth_date, death_date, search, data_source_ids, physical_address_part1, physical_address_part2, physical_address_part3, physical_postplace, physical_country_iso_2, physical_latitude, physical_longitude, physical_altitude, domestic, postal_address_part1, postal_address_part2, postal_address_part3, postal_postplace, postal_country_iso_2, postal_latitude, postal_longitude, postal_altitude, web_address, phone_number, landline, mobile_number, fax_number, used_for_counting, last_edit_comment, has_legal_unit, related_establishment_ids, excluded_establishment_ids, included_establishment_ids, related_legal_unit_ids, excluded_legal_unit_ids, included_legal_unit_ids, related_enterprise_ids, excluded_enterprise_ids, included_enterprise_ids, stats, stats_summary, included_establishment_count, included_legal_unit_count, included_enterprise_count, report_partition_seq)` (temporal)
143143
- Enums: `unit_type` (`public.statistical_unit_type`).
144144

145145
### Derivations for UI listing of relevant time periods
@@ -156,6 +156,7 @@ Enumerated types used across the schema, with their possible values.
156156

157157
- `statistical_unit_facet(unit_type, physical_region_path, primary_activity_category_path, sector_path, legal_form_id, physical_country_id, status_id, valid_from, valid_to, valid_until, count, stats_summary)` (temporal)
158158
- Enums: `unit_type` (`public.statistical_unit_type`).
159+
- `statistical_unit_facet_dirty_partitions(partition_seq)`
159160

160161
### Derivations to create statistical_history for reporting and statistical_history_facet for drilldown.
161162

0 commit comments

Comments
 (0)