Backfill organization ids on webhooks
This backfills nil
organization_id
to SystemHook
s on the web_hooks
table.
It is the third step in completing the ProtocellsSharding issue Add organization_id to the web_hooks table (#524812)
References
Query PLans
Organization lookup
explain SELECT id FROM organizations ORDER BY id ASC LIMIT 1;
Limit (cost=0.14..0.19 rows=1 width=8) (actual time=0.648..0.649 rows=1 loops=1)
Buffers: shared read=2
I/O Timings: read=0.583 write=0.000
-> Index Only Scan using organizations_pkey on public.organizations (cost=0.14..4.57 rows=95 width=8) (actual time=0.647..0.647 rows=1 loops=1)
Heap Fetches: 0
Buffers: shared read=2
I/O Timings: read=0.583 write=0.000
Settings: jit = 'off', random_page_cost = '1.5', seq_page_cost = '4', work_mem = '100MB', effective_cache_size = '472585MB'
Time: 1.230 ms
- planning: 0.552 ms
- execution: 0.678 ms
- I/O read: 0.583 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 0 from the buffer pool
- reads: 2 (~16.00 KiB) from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0
Batch Query Plan SystemHooks
explain SELECT * FROM web_hooks WHERE type = 'SystemHook' AND organization_id IS NULL ORDER BY id LIMIT 1000;
Limit (cost=3.15..3.15 rows=1 width=424) (actual time=0.011..0.012 rows=0 loops=1)
Buffers: shared hit=4
I/O Timings: read=0.000 write=0.000
-> Sort (cost=3.15..3.15 rows=1 width=424) (actual time=0.011..0.011 rows=0 loops=1)
Sort Key: web_hooks.id
Sort Method: quicksort Memory: 25kB
Buffers: shared hit=4
I/O Timings: read=0.000 write=0.000
-> Index Scan using tmp_idx_web_hooks_type_org_id on public.web_hooks (cost=0.12..3.14 rows=1 width=424) (actual time=0.001..0.002 rows=0 loops=1)
Buffers: shared hit=1
I/O Timings: read=0.000 write=0.000
Settings: random_page_cost = '1.5', seq_page_cost = '4', work_mem = '100MB', effective_cache_size = '472585MB', jit = 'off'
Time: 1.473 ms
- planning: 1.431 ms
- execution: 0.042 ms
- I/O read: 0.000 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 4 (~32.00 KiB) from the buffer pool
- reads: 0 from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0
Update Query Batch Updates
explain UPDATE web_hooks SET organization_id = 1 WHERE type = 'SystemHook' AND organization_id IS NULL AND id BETWEEN 1 AND 1000;
ModifyTable on public.web_hooks (cost=0.12..3.15 rows=0 width=0) (actual time=0.011..0.012 rows=0 loops=1)
Buffers: shared hit=2
I/O Timings: read=0.000 write=0.000
-> Index Scan using tmp_idx_web_hooks_type_org_id on public.web_hooks (cost=0.12..3.15 rows=1 width=14) (actual time=0.009..0.009 rows=0 loops=1)
Index Cond: (((web_hooks.type)::text = 'SystemHook'::text) AND (web_hooks.organization_id IS NULL))
Filter: ((web_hooks.id >= 1) AND (web_hooks.id <= 1000))
Rows Removed by Filter: 0
Buffers: shared hit=2
I/O Timings: read=0.000 write=0.000
Settings: effective_cache_size = '472585MB', jit = 'off', random_page_cost = '1.5', seq_page_cost = '4', work_mem = '100MB'
Time: 0.973 ms
- planning: 0.908 ms
- execution: 0.065 ms
- I/O read: 0.000 ms
- I/O write: 0.000 ms
Shared buffers:
- hits: 2 (~16.00 KiB) from the buffer pool
- reads: 0 from the OS file cache, including disk I/O
- dirtied: 0
- writes: 0
How to set up and validate locally
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #524812
Edited by Carla Drago