You've already forked explain.depesz.com
							
							
				mirror of
				https://gitlab.com/depesz/explain.depesz.com.git
				synced 2025-10-31 00:07:57 +02:00 
			
		
		
		
	Move to partitioned plans
We don't have that many of them, but on slow(ish) server dumps or vacuums take long time. Partitioning will make it possible to handle work in smaller increments
This commit is contained in:
		
							
								
								
									
										65
									
								
								sql/patch-004.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										65
									
								
								sql/patch-004.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,65 @@ | ||||
| BEGIN; | ||||
| CREATE SCHEMA plans; | ||||
| create table plans."part_0" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_1" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_2" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_3" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_4" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_5" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_6" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_7" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_8" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_9" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_A" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_B" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_C" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_D" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_E" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_F" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_G" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_H" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_I" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_J" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_K" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_L" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_M" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_N" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_O" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_P" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_Q" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_R" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_S" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_T" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_U" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_V" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_W" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_X" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_Y" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_Z" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_a" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_b" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_c" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_d" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_e" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_f" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_g" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_h" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_i" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_j" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_k" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_l" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_m" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_n" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_o" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_p" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_q" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_r" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_s" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_t" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_u" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_v" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_w" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_x" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_y" ( like public.plans including all ) inherits (public.plans); | ||||
| create table plans."part_z" ( like public.plans including all ) inherits (public.plans); | ||||
| COMMIT; | ||||
							
								
								
									
										62
									
								
								sql/patch-005.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								sql/patch-005.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,62 @@ | ||||
| with x as (delete from only public.plans where id ~ '^0' returning *) insert into plans."part_0" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^1' returning *) insert into plans."part_1" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^2' returning *) insert into plans."part_2" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^3' returning *) insert into plans."part_3" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^4' returning *) insert into plans."part_4" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^5' returning *) insert into plans."part_5" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^6' returning *) insert into plans."part_6" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^7' returning *) insert into plans."part_7" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^8' returning *) insert into plans."part_8" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^9' returning *) insert into plans."part_9" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^A' returning *) insert into plans."part_A" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^B' returning *) insert into plans."part_B" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^C' returning *) insert into plans."part_C" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^D' returning *) insert into plans."part_D" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^E' returning *) insert into plans."part_E" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^F' returning *) insert into plans."part_F" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^G' returning *) insert into plans."part_G" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^H' returning *) insert into plans."part_H" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^I' returning *) insert into plans."part_I" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^J' returning *) insert into plans."part_J" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^K' returning *) insert into plans."part_K" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^L' returning *) insert into plans."part_L" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^M' returning *) insert into plans."part_M" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^N' returning *) insert into plans."part_N" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^O' returning *) insert into plans."part_O" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^P' returning *) insert into plans."part_P" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^Q' returning *) insert into plans."part_Q" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^R' returning *) insert into plans."part_R" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^S' returning *) insert into plans."part_S" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^T' returning *) insert into plans."part_T" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^U' returning *) insert into plans."part_U" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^V' returning *) insert into plans."part_V" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^W' returning *) insert into plans."part_W" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^X' returning *) insert into plans."part_X" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^Y' returning *) insert into plans."part_Y" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^Z' returning *) insert into plans."part_Z" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^a' returning *) insert into plans."part_a" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^b' returning *) insert into plans."part_b" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^c' returning *) insert into plans."part_c" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^d' returning *) insert into plans."part_d" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^e' returning *) insert into plans."part_e" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^f' returning *) insert into plans."part_f" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^g' returning *) insert into plans."part_g" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^h' returning *) insert into plans."part_h" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^i' returning *) insert into plans."part_i" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^j' returning *) insert into plans."part_j" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^k' returning *) insert into plans."part_k" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^l' returning *) insert into plans."part_l" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^m' returning *) insert into plans."part_m" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^n' returning *) insert into plans."part_n" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^o' returning *) insert into plans."part_o" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^p' returning *) insert into plans."part_p" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^q' returning *) insert into plans."part_q" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^r' returning *) insert into plans."part_r" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^s' returning *) insert into plans."part_s" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^t' returning *) insert into plans."part_t" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^u' returning *) insert into plans."part_u" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^v' returning *) insert into plans."part_v" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^w' returning *) insert into plans."part_w" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^x' returning *) insert into plans."part_x" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^y' returning *) insert into plans."part_y" select * from x; | ||||
| with x as (delete from only public.plans where id ~ '^z' returning *) insert into plans."part_z" select * from x; | ||||
							
								
								
									
										62
									
								
								sql/patch-006.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								sql/patch-006.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,62 @@ | ||||
| alter table plans."part_0" add check ( substr(id, 1, 1) = '0' ); | ||||
| alter table plans."part_1" add check ( substr(id, 1, 1) = '1' ); | ||||
| alter table plans."part_2" add check ( substr(id, 1, 1) = '2' ); | ||||
| alter table plans."part_3" add check ( substr(id, 1, 1) = '3' ); | ||||
| alter table plans."part_4" add check ( substr(id, 1, 1) = '4' ); | ||||
| alter table plans."part_5" add check ( substr(id, 1, 1) = '5' ); | ||||
| alter table plans."part_6" add check ( substr(id, 1, 1) = '6' ); | ||||
| alter table plans."part_7" add check ( substr(id, 1, 1) = '7' ); | ||||
| alter table plans."part_8" add check ( substr(id, 1, 1) = '8' ); | ||||
| alter table plans."part_9" add check ( substr(id, 1, 1) = '9' ); | ||||
| alter table plans."part_A" add check ( substr(id, 1, 1) = 'A' ); | ||||
| alter table plans."part_B" add check ( substr(id, 1, 1) = 'B' ); | ||||
| alter table plans."part_C" add check ( substr(id, 1, 1) = 'C' ); | ||||
| alter table plans."part_D" add check ( substr(id, 1, 1) = 'D' ); | ||||
| alter table plans."part_E" add check ( substr(id, 1, 1) = 'E' ); | ||||
| alter table plans."part_F" add check ( substr(id, 1, 1) = 'F' ); | ||||
| alter table plans."part_G" add check ( substr(id, 1, 1) = 'G' ); | ||||
| alter table plans."part_H" add check ( substr(id, 1, 1) = 'H' ); | ||||
| alter table plans."part_I" add check ( substr(id, 1, 1) = 'I' ); | ||||
| alter table plans."part_J" add check ( substr(id, 1, 1) = 'J' ); | ||||
| alter table plans."part_K" add check ( substr(id, 1, 1) = 'K' ); | ||||
| alter table plans."part_L" add check ( substr(id, 1, 1) = 'L' ); | ||||
| alter table plans."part_M" add check ( substr(id, 1, 1) = 'M' ); | ||||
| alter table plans."part_N" add check ( substr(id, 1, 1) = 'N' ); | ||||
| alter table plans."part_O" add check ( substr(id, 1, 1) = 'O' ); | ||||
| alter table plans."part_P" add check ( substr(id, 1, 1) = 'P' ); | ||||
| alter table plans."part_Q" add check ( substr(id, 1, 1) = 'Q' ); | ||||
| alter table plans."part_R" add check ( substr(id, 1, 1) = 'R' ); | ||||
| alter table plans."part_S" add check ( substr(id, 1, 1) = 'S' ); | ||||
| alter table plans."part_T" add check ( substr(id, 1, 1) = 'T' ); | ||||
| alter table plans."part_U" add check ( substr(id, 1, 1) = 'U' ); | ||||
| alter table plans."part_V" add check ( substr(id, 1, 1) = 'V' ); | ||||
| alter table plans."part_W" add check ( substr(id, 1, 1) = 'W' ); | ||||
| alter table plans."part_X" add check ( substr(id, 1, 1) = 'X' ); | ||||
| alter table plans."part_Y" add check ( substr(id, 1, 1) = 'Y' ); | ||||
| alter table plans."part_Z" add check ( substr(id, 1, 1) = 'Z' ); | ||||
| alter table plans."part_a" add check ( substr(id, 1, 1) = 'a' ); | ||||
| alter table plans."part_b" add check ( substr(id, 1, 1) = 'b' ); | ||||
| alter table plans."part_c" add check ( substr(id, 1, 1) = 'c' ); | ||||
| alter table plans."part_d" add check ( substr(id, 1, 1) = 'd' ); | ||||
| alter table plans."part_e" add check ( substr(id, 1, 1) = 'e' ); | ||||
| alter table plans."part_f" add check ( substr(id, 1, 1) = 'f' ); | ||||
| alter table plans."part_g" add check ( substr(id, 1, 1) = 'g' ); | ||||
| alter table plans."part_h" add check ( substr(id, 1, 1) = 'h' ); | ||||
| alter table plans."part_i" add check ( substr(id, 1, 1) = 'i' ); | ||||
| alter table plans."part_j" add check ( substr(id, 1, 1) = 'j' ); | ||||
| alter table plans."part_k" add check ( substr(id, 1, 1) = 'k' ); | ||||
| alter table plans."part_l" add check ( substr(id, 1, 1) = 'l' ); | ||||
| alter table plans."part_m" add check ( substr(id, 1, 1) = 'm' ); | ||||
| alter table plans."part_n" add check ( substr(id, 1, 1) = 'n' ); | ||||
| alter table plans."part_o" add check ( substr(id, 1, 1) = 'o' ); | ||||
| alter table plans."part_p" add check ( substr(id, 1, 1) = 'p' ); | ||||
| alter table plans."part_q" add check ( substr(id, 1, 1) = 'q' ); | ||||
| alter table plans."part_r" add check ( substr(id, 1, 1) = 'r' ); | ||||
| alter table plans."part_s" add check ( substr(id, 1, 1) = 's' ); | ||||
| alter table plans."part_t" add check ( substr(id, 1, 1) = 't' ); | ||||
| alter table plans."part_u" add check ( substr(id, 1, 1) = 'u' ); | ||||
| alter table plans."part_v" add check ( substr(id, 1, 1) = 'v' ); | ||||
| alter table plans."part_w" add check ( substr(id, 1, 1) = 'w' ); | ||||
| alter table plans."part_x" add check ( substr(id, 1, 1) = 'x' ); | ||||
| alter table plans."part_y" add check ( substr(id, 1, 1) = 'y' ); | ||||
| alter table plans."part_z" add check ( substr(id, 1, 1) = 'z' ); | ||||
							
								
								
									
										25
									
								
								sql/patch-007.sql
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								sql/patch-007.sql
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,25 @@ | ||||
| CREATE OR REPLACE FUNCTION register_plan(in_title text, in_plan text, in_is_public boolean, in_is_anonymized boolean, in_username text) RETURNS register_plan_return | ||||
|     LANGUAGE plpgsql | ||||
|     AS $$ | ||||
| DECLARE | ||||
|     use_hash_length int4 := 2; | ||||
|     reply register_plan_return; | ||||
|     use_sql TEXT; | ||||
| BEGIN | ||||
|     reply.delete_key := get_random_string( 50 ); | ||||
|     LOOP | ||||
|         reply.id := get_random_string(use_hash_length); | ||||
|         use_sql := format( 'INSERT INTO plans.%I (id, title, plan, is_public, entered_on, is_anonymized, delete_key, added_by) VALUES ($1, $2, $3, $4, now(), $5, $6, $7 )', 'part_' || substr(reply.id, 1, 1) ); | ||||
|         BEGIN | ||||
|             execute use_sql using reply.id, in_title, in_plan, in_is_public, in_is_anonymized, reply.delete_key, in_username; | ||||
|             RETURN reply; | ||||
|         EXCEPTION WHEN unique_violation THEN | ||||
|                 -- do nothing | ||||
|         END; | ||||
|         use_hash_length := use_hash_length + 1; | ||||
|         IF use_hash_length >= 30 THEN | ||||
|             raise exception 'Random string of length == 30 requested. something''s wrong.'; | ||||
|         END IF; | ||||
|     END LOOP; | ||||
| END; | ||||
| $$; | ||||
		Reference in New Issue
	
	Block a user