Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. set autocommit=0;
  2. begin;
  3.  
  4. -- get all active references to alf_prop_root
  5. create temporary table temp1 (id bigint(20), index (id));
  6. insert into temp1 select disabled_paths_id as id from alf_audit_app;
  7. insert into temp1 select audit_values_id as id from alf_audit_entry;
  8. insert into temp1 select prop1_id as id from alf_prop_unique_ctx;
  9.  
  10. -- determine the obsolete entries from alf_prop_root
  11. create temporary table temp2 (id bigint(20), index (id));
  12. insert into temp2 select alf_prop_root.id as id from alf_prop_root left join temp1 on temp1.id = alf_prop_root.id where temp1.id is null;
  13.  
  14. -- clear alf_prop_root which cascades DELETE to alf_prop_link
  15. delete from alf_prop_root where id in (select id from temp2);
  16.  
  17. -- cleanup temporary structures
  18. drop table temp1;
  19. drop table temp2;
  20.  
  21. -- get all active references to alf_prop_value
  22. create temporary table temp1 (id bigint(20), index (id));
  23.  
  24. insert into temp1 select id from alf_prop_value where id in (select app_name_id from alf_audit_app);
  25. insert into temp1 select audit_user_id as id from alf_audit_entry;
  26. insert into temp1 select key_prop_id as id from alf_prop_link;
  27. insert into temp1 select value_prop_id as id from alf_prop_link;
  28. insert into temp1 select value1_prop_id as id from alf_prop_unique_ctx;
  29. insert into temp1 select value2_prop_id as id from alf_prop_unique_ctx;
  30. insert into temp1 select value3_prop_id as id from alf_prop_unique_ctx;
  31.  
  32. -- determine the obsolete entries from alf_prop_value
  33. create temporary table temp2 (id bigint(20), index (id));
  34. insert into temp2 select alf_prop_value.id as id from alf_prop_value left join temp1 on alf_prop_value.id = temp1.id where temp1.id is null;
  35.  
  36. -- clear the obsolete entries
  37. delete from alf_prop_value where id in (select id from temp2);
  38.  
  39. -- cleanup temporary structures
  40. drop table temp1;
  41. drop table temp2;
  42.  
  43. -- find and clear obsoleted serialized values
  44. create temporary table temp1 (id bigint(20), index (id));
  45. insert into temp1 select alf_prop_serializable_value.id as id from alf_prop_serializable_value left join alf_prop_value on alf_prop_value.long_value = alf_prop_serializable_value.id and alf_prop_value.persisted_type = 4 where alf_prop_value.id is null;
  46.  
  47. delete from alf_prop_serializable_value where id IN (select id from temp1);
  48.  
  49. -- find and clear obsoleted string values
  50. create temporary table temp2 (id bigint(20), index (id));
  51. insert into temp2 select alf_prop_string_value.id as id from alf_prop_string_value left join alf_prop_value on alf_prop_value.long_value = alf_prop_string_value.id and alf_prop_value.persisted_type in (3,5,6) where alf_prop_value.id is null;
  52. delete from alf_prop_string_value where id in (select id from temp2);
  53.  
  54. -- find and clear obsoleted double values
  55. create temporary table temp3 (id bigint(20), index (id));
  56. insert into temp3 select alf_prop_double_value.id as id from alf_prop_double_value left join alf_prop_value on alf_prop_value.long_value = alf_prop_double_value.id and alf_prop_value.persisted_type = 2 where alf_prop_value.id is null;
  57. delete from alf_prop_double_value where id in (select id from temp3);
  58.  
  59. -- cleanup temporary structures
  60. drop table temp1;
  61. drop table temp2;
  62. drop table temp3;
  63.  
  64. commit;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement