Advertisement
shreyjain

Metrics Timeseries Column Redifinition

Jun 13th, 2022 (edited)
1,611
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CREATE TABLE centralcdb_customer_metrics_timeseries_temp$ (TIMESERIES_ID VARCHAR2(256), METRICS_ID NUMBER, VALUE NUMBER, TS TIMESTAMP(6), LABEL_NAME VARCHAR2(256));
  2.  
  3. BEGIN
  4. FOR i IN 1 .. 25000000 LOOP
  5.     INSERT INTO centralcdb_customer_metrics_timeseries$ VALUES (65, '0', '12-MAY-22 01.46.00.000000 AM', 'guid_DE6CEB2B3FCB2EF4E053DD78F80AE335', '2e36bcf3-ba9a-4dc2-833e-bd66a76e7085');
  6.  END LOOP;
  7. COMMIT;
  8. END;
  9. /
  10.  
  11. DECLARE
  12.  
  13. l_colmap VARCHAR2(200) :=
  14. q'{TIMESERIES_ID, METRICS_ID, TO_NUMBER(VALUE) AS VALUE, TS, LABEL_NAME}';
  15.  
  16. BEGIN
  17.  
  18. DBMS_REDEFINITION.ABORT_REDEF_TABLE (
  19.    uname => 'admin',
  20.    orig_table => 'centralcdb_customer_metrics_timeseries$',
  21.    int_table  =>  'centralcdb_customer_metrics_timeseries_temp$'
  22. );
  23.  
  24. DBMS_REDEFINITION.START_REDEF_TABLE (
  25.    uname => 'admin',
  26.    orig_table => 'centralcdb_customer_metrics_timeseries$',
  27.    int_table  =>  'centralcdb_customer_metrics_timeseries_temp$',
  28.    col_mapping => l_colmap,
  29.    options_flag => DBMS_REDEFINITION.CONS_USE_ROWID
  30. );
  31.  
  32. DBMS_REDEFINITION.SYNC_INTERIM_TABLE (
  33.    uname => 'admin',
  34.    orig_table => 'centralcdb_customer_metrics_timeseries$',
  35.    int_table  =>  'centralcdb_customer_metrics_timeseries_temp$'
  36. );
  37.  
  38. DBMS_REDEFINITION.FINISH_REDEF_TABLE (
  39.    uname => 'admin',
  40.    orig_table => 'centralcdb_customer_metrics_timeseries$',
  41.    int_table  =>  'centralcdb_customer_metrics_timeseries_temp$'
  42. );
  43.  
  44. END;
  45. /
  46.  
  47. BEGIN
  48. FOR i IN 1 .. 25000000 LOOP
  49.     INSERT INTO centralcdb_customer_metrics_timeseries$ VALUES (65, 0, '12-MAY-22 01.46.00.000000 AM', 'guid_DE6CEB2B3FCB2EF4E053DD78F80AE335', '2e36bcf3-ba9a-4dc2-833e-bd66a76e7085');
  50.  END LOOP;
  51. COMMIT;
  52. END;
  53. /
  54.  
  55. CREATE TABLE centralcdb_customer_metrics_timeseries_temp2$ (TIMESERIES_ID VARCHAR2(256), METRICS_ID NUMBER, VALUE VARCHAR2(256), TS TIMESTAMP(6), LABEL_NAME VARCHAR2(256));
  56.  
  57. DECLARE
  58.  
  59. l_colmap VARCHAR2(200) :=
  60. q'{TIMESERIES_ID, METRICS_ID, TO_NUMBER(VALUE) AS VALUE, TS, LABEL_NAME}';
  61.  
  62. BEGIN
  63.  
  64. DBMS_REDEFINITION.ABORT_REDEF_TABLE (
  65.    uname => 'admin',
  66.    orig_table => 'centralcdb_customer_metrics_timeseries$',
  67.    int_table  =>  'centralcdb_customer_metrics_timeseries_temp2$'
  68. );
  69.  
  70. DBMS_REDEFINITION.START_REDEF_TABLE (
  71.    uname => 'admin',
  72.    orig_table => 'centralcdb_customer_metrics_timeseries$',
  73.    int_table  =>  'centralcdb_customer_metrics_timeseries_temp2$',
  74.    col_mapping => l_colmap,
  75.    options_flag => DBMS_REDEFINITION.CONS_USE_ROWID
  76. );
  77.  
  78. DBMS_REDEFINITION.SYNC_INTERIM_TABLE (
  79.    uname => 'admin',
  80.    orig_table => 'centralcdb_customer_metrics_timeseries$',
  81.    int_table  =>  'centralcdb_customer_metrics_timeseries_temp2$'
  82. );
  83.  
  84. DBMS_REDEFINITION.FINISH_REDEF_TABLE (
  85.    uname => 'admin',
  86.    orig_table => 'centralcdb_customer_metrics_timeseries$',
  87.    int_table  =>  'centralcdb_customer_metrics_timeseries_temp2$'
  88. );
  89.  
  90. END;
  91. /
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement