Data update for 76 million rows

Hello All,
we have added a new column into one of our tables and we need to populate the column.Problem is it has 76 million rows.If i issue the update coomand to populate this ,approximately it will take 120 hrs to complete.Please let me know the best way of doing this. Can i run it in batches applying commit in between??
Thanks.

It´d be something like this:
DECLARE
  V_QRY          VARCHAR2(10000);
  V_COMMIT_RANGE INTEGER;
BEGIN
  V_COMMIT_RANGE := 10000; -- Change this according with your environment
  * Prevents exceeding ROLL BACK segments.
  LOOP
    V_QRY := 'UPDATE transaction_fact a '
          || '   SET a.start_time = (SELECT TO_DATE ( TO_CHAR (:v_year        , ''fm0000'') '
          || '                                     || TO_CHAR (:v_month       , ''fm00'') '
          || '                                     || TO_CHAR (:v_day_of_month, ''fm00''), '
          || '                                     ''YYYYMMDD'' '
          || '                                    ) '
          || '                       FROM TIME '
          || '                      WHERE TIME.time_id = a.time_id) '
          || ' WHERE a.start_time IS NULL '
          || '   AND ROWNUM <= ' || V_COMMIT_RANGE;
    EXECUTE IMMEDIATE V_QRY
                USING YEAR
                    , MONTH
                    , day_of_month;
    EXIT WHEN SQL%ROWCOUNT = 0;
    COMMIT;
  END LOOP;
EXCEPTION
  WHEN NO_DATA_FOUND THEN
    DBMS_OUTPUT.PUT_LINE('no content');
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;Assumptions made:
a) YEAR, MONTH and day_of_month are all variables;
b) a.start_time has null values for all rows (or all you wish to update);
Although this will do the job, it might not be as performatic as you need it to be. So, if your Oracle version allows you to rename tables, you should consider looking into Walter´s post (if you havent already).
All the best..

Similar Messages

  • Query taking more than 1/2 hour for 80 million rows in fact table

    Hi All,
    I am stuck in this query as it it taking more than 35 mins to execute for 80 million rows. My SLA is less than 30 mins for 160 million rows i.e. double the number.
    Below is the query and the Execution Plan.
    SELECT txn_id AS txn_id,
    acntng_entry_src AS txn_src,
    f.hrarchy_dmn_id AS hrarchy_dmn_id,
    f.prduct_dmn_id AS prduct_dmn_id,
    f.pstng_crncy_id AS pstng_crncy_id,
    f.acntng_entry_typ AS acntng_entry_typ,
    MIN (d.date_value) AS min_val_dt,
    GREATEST (MAX (d.date_value),
    LEAST ('07-Feb-2009', d.fin_year_end_dt))
    AS max_val_dt
    FROM Position_Fact f, Date_Dimension d
    WHERE f.val_dt_dmn_id = d.date_dmn_id
    GROUP BY txn_id,
    acntng_entry_src,
    f.hrarchy_dmn_id,
    f.prduct_dmn_id,
    f.pstng_crncy_id,
    f.acntng_entry_typ,
    d.fin_year_end_dt
    Execution Plan is as:
    11 HASH JOIN Cost: 914,089 Bytes: 3,698,035,872 Cardinality: 77,042,414      
                                                                                    9 TABLE ACCESS FULL TABLE Date_Dimension Cost: 29 Bytes: 94,960 Cardinality: 4,748
                                                                                    10 TABLE ACCESS FULL TABLE Position_Fact Cost: 913,693 Bytes: 2,157,187,592 Cardinality: 77,042,414
    Kindly suggest, how to make it faster.
    Regards,
    Sid

    The above is just a part of the query that is taking the maximum time.
    Kindly find the entire query and the plan as follows:
    WITH MIN_MX_DT
    AS
    ( SELECT
    TXN_ID AS TXN_ID,
    ACNTNG_ENTRY_SRC AS TXN_SRC,
    F.HRARCHY_DMN_ID AS HRARCHY_DMN_ID,
    F.PRDUCT_DMN_ID AS PRDUCT_DMN_ID,
    F.PSTNG_CRNCY_ID AS PSTNG_CRNCY_ID,
    F.ACNTNG_ENTRY_TYP AS ACNTNG_ENTRY_TYP,
    MIN (D.DATE_VALUE) AS MIN_VAL_DT,
    GREATEST (MAX (D.DATE_VALUE), LEAST (:B1, D.FIN_YEAR_END_DT))
    AS MAX_VAL_DT
    FROM
    proj_PSTNG_FCT F, proj_DATE_DMN D
    WHERE
    F.VAL_DT_DMN_ID = D.DATE_DMN_ID
    GROUP BY
    TXN_ID,
    ACNTNG_ENTRY_SRC,
    F.HRARCHY_DMN_ID,
    F.PRDUCT_DMN_ID,
    F.PSTNG_CRNCY_ID,
    F.ACNTNG_ENTRY_TYP,
    D.FIN_YEAR_END_DT),
    SLCT_RCRDS
    AS (
    SELECT
    M.TXN_ID,
    M.TXN_SRC,
    M.HRARCHY_DMN_ID,
    M.PRDUCT_DMN_ID,
    M.PSTNG_CRNCY_ID,
    M.ACNTNG_ENTRY_TYP,
    D.DATE_VALUE AS VAL_DT,
    D.DATE_DMN_ID,
    D.FIN_WEEK_NUM AS FIN_WEEK_NUM,
    D.FIN_YEAR_STRT AS FIN_YEAR_STRT,
    D.FIN_YEAR_END AS FIN_YEAR_END
    FROM
    MIN_MX_DT M, proj_DATE_DMN D
    WHERE
    D.HOLIDAY_IND = 0
    AND D.DATE_VALUE >= MIN_VAL_DT
    AND D.DATE_VALUE <= MAX_VAL_DT),
    DLY_HDRS
    AS (
    SELECT
    S.TXN_ID AS TXN_ID,
    S.TXN_SRC AS TXN_SRC,
    S.DATE_DMN_ID AS VAL_DT_DMN_ID,
    S.HRARCHY_DMN_ID AS HRARCHY_DMN_ID,
    S.PRDUCT_DMN_ID AS PRDUCT_DMN_ID,
    S.PSTNG_CRNCY_ID AS PSTNG_CRNCY_ID,
    SUM
    DECODE
    PNL_TYP_NM,
    :B5, DECODE (NVL (F.PSTNG_TYP, :B2),
    :B2, NVL (F.PSTNG_AMNT, 0) * (-1),
    NVL (F.PSTNG_AMNT, 0)),
    0))
    AS MTM_AMT,
    NVL (
    LAG (
    SUM (
    DECODE (
    PNL_TYP_NM,
    :B5, DECODE (NVL (F.PSTNG_TYP, :B2),
    :B2, NVL (F.PSTNG_AMNT, 0) * (-1),
    NVL (F.PSTNG_AMNT, 0)),
    0)))
    OVER (
    PARTITION BY S.TXN_ID,
    S.TXN_SRC,
    S.HRARCHY_DMN_ID,
    S.PRDUCT_DMN_ID,
    S.PSTNG_CRNCY_ID
    ORDER BY S.VAL_DT),
    0)
    AS YSTDY_MTM,
    SUM (
    DECODE (
    PNL_TYP_NM,
    :B4, DECODE (NVL (F.PSTNG_TYP, :B2),
    :B2, NVL (F.PSTNG_AMNT, 0) * (-1),
    NVL (F.PSTNG_AMNT, 0)),
    0))
    AS CASH_AMT,
    SUM (
    DECODE (
    PNL_TYP_NM,
    :B3, DECODE (NVL (F.PSTNG_TYP, :B2),
    :B2, NVL (F.PSTNG_AMNT, 0) * (-1),
    NVL (F.PSTNG_AMNT, 0)),
    0))
    AS PAY_REC_AMT,
    S.VAL_DT,
    S.FIN_WEEK_NUM,
    S.FIN_YEAR_STRT,
    S.FIN_YEAR_END,
    NVL (TRUNC (F.REVSN_DT), S.VAL_DT) AS REVSN_DT,
    S.ACNTNG_ENTRY_TYP AS ACNTNG_ENTRY_TYP
    FROM
    SLCT_RCRDS S,
    proj_PSTNG_FCT F,
    proj_ACNT_DMN AD,
    proj_PNL_TYP_DMN PTD
    WHERE
    S.TXN_ID = F.TXN_ID(+)
    AND S.TXN_SRC = F.ACNTNG_ENTRY_SRC(+)
    AND S.HRARCHY_DMN_ID = F.HRARCHY_DMN_ID(+)
    AND S.PRDUCT_DMN_ID = F.PRDUCT_DMN_ID(+)
    AND S.PSTNG_CRNCY_ID = F.PSTNG_CRNCY_ID(+)
    AND S.DATE_DMN_ID = F.VAL_DT_DMN_ID(+)
    AND S.ACNTNG_ENTRY_TYP = F.ACNTNG_ENTRY_TYP(+)
    AND SUBSTR (AD.ACNT_NUM, 0, 1) IN (1, 2, 3)
    AND NVL (F.ACNT_DMN_ID, 1) = AD.ACNT_DMN_ID
    AND NVL (F.PNL_TYP_DMN_ID, 1) = PTD.PNL_TYP_DMN_ID
    GROUP BY
    S.TXN_ID,
    S.TXN_SRC,
    S.DATE_DMN_ID,
    S.HRARCHY_DMN_ID,
    S.PRDUCT_DMN_ID,
    S.PSTNG_CRNCY_ID,
    S.VAL_DT,
    S.FIN_WEEK_NUM,
    S.FIN_YEAR_STRT,
    S.FIN_YEAR_END,
    TRUNC (F.REVSN_DT),
    S.ACNTNG_ENTRY_TYP,
    F.TXN_ID)
    SELECT
    D.TXN_ID,
    D.VAL_DT_DMN_ID,
    D.REVSN_DT,
    D.TXN_SRC,
    D.HRARCHY_DMN_ID,
    D.PRDUCT_DMN_ID,
    D.PSTNG_CRNCY_ID,
    D.YSTDY_MTM,
    D.MTM_AMT,
    D.CASH_AMT,
    D.PAY_REC_AMT,
    MTM_AMT + CASH_AMT + PAY_REC_AMT AS DLY_PNL,
    SUM (
    MTM_AMT + CASH_AMT + PAY_REC_AMT)
    OVER (
    PARTITION BY D.TXN_ID,
    D.TXN_SRC,
    D.HRARCHY_DMN_ID,
    D.PRDUCT_DMN_ID,
    D.PSTNG_CRNCY_ID,
    D.FIN_WEEK_NUM || D.FIN_YEAR_STRT || D.FIN_YEAR_END
    ORDER BY D.VAL_DT)
    AS WTD_PNL,
    SUM (
    MTM_AMT + CASH_AMT + PAY_REC_AMT)
    OVER (
    PARTITION BY D.TXN_ID,
    D.TXN_SRC,
    D.HRARCHY_DMN_ID,
    D.PRDUCT_DMN_ID,
    D.PSTNG_CRNCY_ID,
    D.FIN_YEAR_STRT || D.FIN_YEAR_END
    ORDER BY D.VAL_DT)
    AS YTD_PNL,
    D.ACNTNG_ENTRY_TYP AS ACNTNG_PSTNG_TYP,
    'EOD ETL' AS CRTD_BY,
    SYSTIMESTAMP AS CRTN_DT,
    NULL AS MDFD_BY,
    NULL AS MDFCTN_DT
    FROM
    DLY_HDRS D
    Plan
    SELECT STATEMENT ALL_ROWSCost: 11,950,256 Bytes: 3,369,680,886 Cardinality: 7,854,734
    25 WINDOW SORT Cost: 11,950,256 Bytes: 3,369,680,886 Cardinality: 7,854,734
    24 WINDOW SORT Cost: 11,950,256 Bytes: 3,369,680,886 Cardinality: 7,854,734
    23 VIEW Cost: 10,519,225 Bytes: 3,369,680,886 Cardinality: 7,854,734
    22 WINDOW BUFFER Cost: 10,519,225 Bytes: 997,551,218 Cardinality: 7,854,734
    21 SORT GROUP BY Cost: 10,519,225 Bytes: 997,551,218 Cardinality: 7,854,734
    20 HASH JOIN Cost: 10,296,285 Bytes: 997,551,218 Cardinality: 7,854,734
    1 TABLE ACCESS FULL TABLE proj_PNL_TYP_DMN Cost: 3 Bytes: 45 Cardinality: 5
    19 HASH JOIN Cost: 10,296,173 Bytes: 2,695,349,628 Cardinality: 22,841,946
    5 VIEW VIEW index$_join$_007 Cost: 3 Bytes: 84 Cardinality: 7
    4 HASH JOIN
    2 INDEX FAST FULL SCAN INDEX (UNIQUE) proj_ACNT_DMN_PK Cost: 1 Bytes: 84 Cardinality: 7
    3 INDEX FAST FULL SCAN INDEX (UNIQUE) proj_ACNT_DMN_UNQ Cost: 1 Bytes: 84 Cardinality: 7
    18 HASH JOIN RIGHT OUTER Cost: 10,293,077 Bytes: 68,925,225,244 Cardinality: 650,237,974
    6 TABLE ACCESS FULL TABLE proj_PSTNG_FCT Cost: 913,986 Bytes: 4,545,502,426 Cardinality: 77,042,414
    17 VIEW Cost: 7,300,017 Bytes: 30,561,184,778 Cardinality: 650,237,974
    16 MERGE JOIN Cost: 7,300,017 Bytes: 230,184,242,796 Cardinality: 650,237,974
    8 SORT JOIN Cost: 30 Bytes: 87,776 Cardinality: 3,376
    7 TABLE ACCESS FULL TABLE proj_DATE_DMN Cost: 29 Bytes: 87,776 Cardinality: 3,376
    15 FILTER
    14 SORT JOIN Cost: 7,238,488 Bytes: 25,269,911,792 Cardinality: 77,042,414
    13 VIEW Cost: 1,835,219 Bytes: 25,269,911,792 Cardinality: 77,042,414
    12 SORT GROUP BY Cost: 1,835,219 Bytes: 3,698,035,872 Cardinality: 77,042,414
    11 HASH JOIN Cost: 914,089 Bytes: 3,698,035,872 Cardinality: 77,042,414
    9 TABLE ACCESS FULL TABLE proj_DATE_DMN Cost: 29 Bytes: 94,960 Cardinality: 4,748
    10 TABLE ACCESS FULL TABLE proj_PSTNG_FCT Cost: 913,693 Bytes: 2,157,187,592 Cardinality: 77,042,414

  • How to aggregate a column based date column (for weekly single row)?

    How to aggregate a column based date column (for weekly single row)?

    Hi,
    Consider the below statement for daily bases which is ok
    SELECT ID, DATE, SUM(AMOUNT) FROM TABLE_NAME GROUP BY ID, DATE ORDER BY ID, DATE
    The same like the above statement, I want output on weekly, fortnightly, and monthly bases, How to do this? Need your help...

  • Poor timing for update of a million rows in TimesTen

    This is not a scientific test but I am dissappointed in my results.
    I created SALES table in TT 11.2.1.4.0 in the image of Oracle 11g table sh.SALES. Data also came from SALES as well. Just make sure that you have a million rows in your version of sh.SALES in Oracle. Spool it out to /var/tmp/abc.log as follows:
    set feedback off
    set pagesize 0
    set verify off
    set timing off
    select prod_id ||','||cust_id||','||to_char(TIME_ID,'YYYY-MM-DD')||','||channel_id||','||PROMO_ID||','||QUANTITY_SOLD||','||AMOUNT_SOLD
    from sys.sales;
    exit
    Now use
    ttbulkcp -i -s "," DSN=ttdemo1 SALES /var/tmp/abc.log
    TT table description is as follows with no index
    Table HR.SALES:
    Columns:
    PROD_ID NUMBER NOT NULL
    CUST_ID NUMBER NOT NULL
    TIME_ID DATE NOT NULL
    CHANNEL_ID NUMBER NOT NULL
    PROMO_ID NUMBER NOT NULL
    QUANTITY_SOLD NUMBER (10,2) NOT NULL
    AMOUNT_SOLD NUMBER (10,2) NOT NULL
    1 table found.
    (primary key columns are indicated with *)
    The data store has 1024MB PermStore and 512MB TempStore
    [ttimdb1]
    Driver=/home/oracle/TimesTen/11.2.1.4.0/TimesTen/ttimdb1/lib/libtten.so
    DataStore=/work/oracle/TimesTen_store/ttimdb1
    PermSize=1024
    TempSize=512
    OracleId=MYDB
    DatabaseCharacterSet=WE8MSWIN1252
    ConnectionCharacterSet=WE8MSWIN1252
    Now do a simple UPDATE. REmember it is all tablescan!
    Command> set autocommit 0
    Command> showplan 1
    Command> timing 1
    Command> UPDATE SALES SET AMOUNT_SOLD = AMOUNT_SOLD + 10.22;
    Query Optimizer Plan:
    STEP: 1
    LEVEL: 1
    OPERATION: TblLkSerialScan
    TBLNAME: SALES
    IXNAME: <NULL>
    INDEXED CONDITION: <NULL>
    NOT INDEXED: <NULL>
    STEP: 2
    LEVEL: 1
    OPERATION: TblLkUpdate
    TBLNAME: SALES
    IXNAME: <NULL>
    INDEXED CONDITION: <NULL>
    NOT INDEXED: <NULL>
    1000000 rows updated.
    Execution time (SQLExecute) = 76.141563 seconds.
    I tried few times but I still cannot make it go below 60 seconds. Oracle 11g does it better.
    Any help and advice is appreciated.
    Thanks,
    Mich

    Guys,
    running the job and doing UNIX top I am getting this
    Mem: 4014080k total, 3729940k used, 284140k free, 136988k buffers
    Swap: 10241396k total, 8k used, 10241388k free, 3283284k cached
    PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
    11428 oracle 19 0 2138m 802m 799m S 17 20.5 0:29.58 ttIsqlCmd
    5559 oracle 18 0 2158m 719m 711m S 11 18.4 7:03.63 timestensubd
    5874 root 16 0 1964 628 548 S 7 0.0 1:06.14 hald-addon-stor
    4910 root 16 0 2444 368 260 S 5 0.0 0:16.69 irqbalance
    17 root 10 -5 0 0 0 S 3 0.0 0:20.78 kblockd/0
    So there is memory there and no swap usage. System does not look to be overloaded or anything. However, there is a wait somewhere!
    TIME_OF_1ST_CONNECT: Tue Jan 19 12:23:30 2010
    DS_CONNECTS: 11
    DS_DISCONNECTS: 0
    DS_CHECKPOINTS: 0
    DS_CHECKPOINTS_FUZZY: 0
    DS_COMPACTS: 0
    PERM_ALLOCATED_SIZE: 1048576
    PERM_IN_USE_SIZE: 134048
    PERM_IN_USE_HIGH_WATER: 134048
    TEMP_ALLOCATED_SIZE: 524288
    TEMP_IN_USE_SIZE: 19447
    TEMP_IN_USE_HIGH_WATER: 19511
    SYS18: 0
    TPL_FETCHES: 0
    TPL_EXECS: 0
    CACHE_HITS: 0
    PASSTHROUGH_COUNT: 0
    XACT_BEGINS: 6
    XACT_COMMITS: 5
    XACT_D_COMMITS: 0
    XACT_ROLLBACKS: 0
    LOG_FORCES: 0
    DEADLOCKS: 0
    LOCK_TIMEOUTS: 0
    LOCK_GRANTS_IMMED: 148
    LOCK_GRANTS_WAIT: 0
    SYS19: 0
    CMD_PREPARES: 3
    CMD_REPREPARES: 0
    CMD_TEMP_INDEXES: 0
    LAST_LOG_FILE: 240
    REPHOLD_LOG_FILE: -1
    REPHOLD_LOG_OFF: -1
    REP_XACT_COUNT: 0
    REP_CONFLICT_COUNT: 0
    REP_PEER_CONNECTIONS: 0
    REP_PEER_RETRIES: 0
    FIRST_LOG_FILE: 209
    LOG_BYTES_TO_LOG_BUFFER: 120
    LOG_FS_READS: 0
    LOG_FS_WRITES: 0
    LOG_BUFFER_WAITS: 0
    CHECKPOINT_BYTES_WRITTEN: 0
    CURSOR_OPENS: 5
    CURSOR_CLOSES: 5
    SYS3: 0
    SYS4: 0
    SYS5: 0
    SYS6: 0
    CHECKPOINT_BLOCKS_WRITTEN: 0
    CHECKPOINT_WRITES: 0
    REQUIRED_RECOVERY: 0
    SYS11: 0
    SYS12: 1
    TYPE_MODE: 0
    SYS13: 0
    SYS14: 0
    SYS15: 0
    SYS16: 0
    SYS17: 0
    SYS9:
    Command> UPDATE SALES SET AMOUNT_SOLD = AMOUNT_SOLD + 10.22;
    1000000 rows updated.
    Execution time (SQLExecute) = 86.476318 seconds.
    Command> monitor;
    TIME_OF_1ST_CONNECT: Tue Jan 19 12:23:30 2010
    DS_CONNECTS: 11
    DS_DISCONNECTS: 0
    DS_CHECKPOINTS: 0
    DS_CHECKPOINTS_FUZZY: 0
    DS_COMPACTS: 0
    PERM_ALLOCATED_SIZE: 1048576
    PERM_IN_USE_SIZE: 134079
    PERM_IN_USE_HIGH_WATER: 252800
    TEMP_ALLOCATED_SIZE: 524288
    TEMP_IN_USE_SIZE: 19512
    TEMP_IN_USE_HIGH_WATER: 43024
    SYS18: 0
    TPL_FETCHES: 0
    TPL_EXECS: 0
    CACHE_HITS: 0
    PASSTHROUGH_COUNT: 0
    XACT_BEGINS: 13
    XACT_COMMITS: 12
    XACT_D_COMMITS: 0
    XACT_ROLLBACKS: 0
    LOG_FORCES: 6
    DEADLOCKS: 0
    LOCK_TIMEOUTS: 0
    LOCK_GRANTS_IMMED: 177
    LOCK_GRANTS_WAIT: 0
    SYS19: 0
    CMD_PREPARES: 4
    CMD_REPREPARES: 0
    CMD_TEMP_INDEXES: 0
    LAST_LOG_FILE: 246
    REPHOLD_LOG_FILE: -1
    REPHOLD_LOG_OFF: -1
    REP_XACT_COUNT: 0
    REP_CONFLICT_COUNT: 0
    REP_PEER_CONNECTIONS: 0
    REP_PEER_RETRIES: 0
    FIRST_LOG_FILE: 209
    LOG_BYTES_TO_LOG_BUFFER: 386966680
    LOG_FS_READS: 121453
    LOG_FS_WRITES: 331
    LOG_BUFFER_WAITS: 8
    CHECKPOINT_BYTES_WRITTEN: 0
    CURSOR_OPENS: 6
    CURSOR_CLOSES: 6
    SYS3: 0
    SYS4: 0
    SYS5: 0
    SYS6: 0
    CHECKPOINT_BLOCKS_WRITTEN: 0
    CHECKPOINT_WRITES: 0
    REQUIRED_RECOVERY: 0
    SYS11: 0
    SYS12: 1
    TYPE_MODE: 0
    SYS13: 0
    SYS14: 0
    SYS15: 0
    SYS16: 0
    SYS17: 0
    SYS9:
    Command> commit;
    Execution time (SQLTransact) = 0.000007 seconds.

  • How to tune the Update statement for 20 million rows

    Hi,
    I want to update 20 million rows of a table. I wrote the PL/SQL code like this:
    DECLARE
    v1
    v2
    cursor C1 is
    select ....
    BEGIN
    Open C1;
    loop
    fetch C1 bulk collect into v1,v2 LIMIT 1000
    exit when C1%NOTFOUND;
    forall i in v1.first..v1.last
    update /*+INDEX(tab indx)*/....
    end loop;
    commit;
    close C1;
    END;
    The above code took 24 mins to update 100k records, so for around 20 million records it will take 4800 mins (80 hrs).
    How can I tune the code further ? Will a simple Update statement, instead of PL/SQL make the update faster ?
    Will adding few more hints help ?
    Thanks for your suggestions.
    Regards,
    Yogini Joshi

    Hello
    You have implemented this update in the slowest possible way. Cursor FOR loops should be absolute last resort. If you post the SQL in your cursor there is a very good chance we can re-code it to be a single update statement with a subquery which will be the fastest possible way to run this. Please remember to use the {noformat}{noformat} tags before and after your code so the formatting is preserved.
    David                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • SQL Tuning for 50 million rows--- Group by

    For example i have 50 million+ rows in a table with columns Customer_ID, Order_ID and trans_date. I need a query to return customers with more than 2 orders over the past 60 days.
    [sql]
    Select customer_id from table
    where trans_date between sysdate-60 and sysdate
    group by customer_id
    having count(customer_id)>=2
    [/sql]
    I am trying to understand if there is a fastest alternative for group by and having. Especially for large data sets. Thanks in advance for your help/suggestions.

    varun wrote:
    For example i have 50 million+ rows in a table with columns Customer_ID, Order_ID and trans_date. I need a query to return customers with more than 2 orders over the past 60 days.
    [sql]
    Select customer_id from table
    where trans_date between sysdate-60 and sysdate
    group by customer_id
    having count(customer_id)>=2
    [/sql]
    I am trying to understand if there is a fastest alternative for group by and having. Especially for large data sets. Thanks in advance for your help/suggestions.
    The first task is to write a query that actually works properly; that one doesn't. Your business rule was 'more than 2 orders' but that query uses '>=2'.
    And there is NOTHING in that query having anything to do with 'orders'.
    That query returns 'customers with two or more rows' in the last 60 days. Why aren't you using 'ORDER_ID' in the query?
    First write a query that returns the correct results. There is no need for an alternative unless you can demonstrate that the query actually HAS a performance problem.

  • Erroneous no of data updation for RDA

    Hi experts,
             i have created a generic datasource made it RDA enabled  for test purpose, executed successfully init of delta. As per method created RDA package assigned package and
    dtp to daemon, settings were period -1 MIN and autometic closure of request in 1 hr. Now i
    added 4 records in table associated with this datasource these 4 recoeds are being updatd in
    DSO in every one minute adding overall 240 records in an hour. What to do?

    Hi sunil ..
    I feel there is problem with your request closing ..of demon..
    Requests are opened and closed as follows:
    .1.      When a daemon is started, it opens a PSA request in the first load process.
    2.      The system opens a DTP request and change log request when the PSA request contains data.
    3.      The daemon uses the threshold values defined in the InfoPackage to determine when to close a
              request. The data transfer process copies these settings from the InfoPackage.
              When a PSA request is closed, the related DTP and change log requests in the same load       
              process are closed too.
    4.      When the requests are closed, new requests are opened automatically the next time the daemon
             accesses data and the data transfer for real-time data acquisition continues with these new 
             requests.
    5.      Again, the system only opens a DTP request and change log request when the PSA request
             contains data.
    6.      If you are transferring data from an SAP source system, data is automatically deleted from the
             delta queue when the new PSA request is opened.
       The data (and the open requests) are available for analysis and reporting as soon as they have been   successfully updated and activated in the DataStore object.
    With real-time data acquisition, the requests (PSA requests, DTP requests and change log requests) remain open across several load processes. The requests are closed when the threshold values set in the InfoPackage are reached. The system opens new requests and data transfer is continued using the new requests. In the monitor for real-time data acquisition, you can close PSA and DTP requests manually.
    If errors occur, you can close an open request manually, correct the error and then restart data transfer.
    Regards,
    Shikha

  • Fast Updates for 8 million records..!!

    Hi All,
    I was wondering is there any fast method for updating 8 million records out of 10 million table?
    For eg :
    I am having a customer table of 10m records and columns are cust_id, cust_num and cust_name.
    i need to update 8m records out of 10m customer table as follows.
    update customer set cust_id=46 where cust_id=75;
    The above statement will update 8m records. And cust_id is indexed.
    But if i fire the above update statement we'll face rollback segment problem..
    Even if i use ROWNUM and commit after 100K records still its gonna take huge time and also i know CTAS will be lot lot faster but for this scenario i guess its not possible.. Right?
    Any help is much appreciated...
    Thanks.

    You didn't specify what version you're on, but have you looked at dbms_redefinition?
    create table cust (cust_num number, constraint cust_pk primary key (cust_num), cust_id number, name varchar2(10));
    create index cust_id_idx on cust(cust_id);
    insert into cust values( 1, 1, 'a');
    insert into cust values( 2, 2, 'b');
    insert into cust values( 3, 1, 'c');
    insert into cust values( 4, 4, 'd');
    insert into cust values( 5, 1, 'e');
    select * From cust;
    create table cust_int (cust_num number, cust_id number, name varchar2(10));
    exec dbms_redefinition.start_redef_table(user,'cust', 'cust_int', 'cust_num cust_num, decode(cust_id, 1, 99, cust_id) cust_id, name name');
    declare
    i pls_integer;
    begin
    dbms_redefinition.copy_table_dependents( user, 'cust', 'cust_int', copy_indexes=>dbms_redefinition.cons_orig_params, copy_triggers=>true, copy_constraints=>true, copy_privileges=>true, ignore_errors=>false, num_errors=>i);
    dbms_output.put_line('Errors: ' || i);
    end;
    exec dbms_redefinition.finish_redef_table(user, 'cust', 'cust_int');
    select * From cust;
    select table_name, index_name from user_indexes;
    You would probably want to run a sync_interim_table in there before the finish.
    Good luck.

  • SOP-S076, Actual Data Update for Sales and Production

    Hi All,
    I have been working on a prototype to display the Actual Sales and Actual Production figures accurred during the past periods along with the Sales Forecast figures.  I am using Product Groups and the standard Info Structure S076 provided in the Standard SOP.
    Currently, the system is live with similar solution.  However, when I display the entries in SE16 for the Version 000, I get a message "No entries found".  As per the documentation, Version 000 needs to be populated by SAP and it can not be changed.  Therefore, I can not pull these figures in any of the Planning Types I created.
    I would appreciate any guidance to activate the Actual Version 000, in the Info Structure S076.
    Regards and happy SAPping to all.
    Mumin DIKMEN

    Hi Mahesh,
    Thanks for the reply.  I replied to perform the Statistical Update as well.  However, the response I am getting for the Info Structure S076 is
    <b>No information structure with active updating exists!
    Message no. M2784
    Diagnosis
    No information structure with active updating exists for event  and update group .
    System response
    Due to your data, the system cannot update any information structures.
    Procedure
    1. Check to see whether information structures using event  exist in the update rules for udate group .
    2. Check to see whether updating has been switched on for this information structure.</b>
    I also tried to activate this info structure in the case that SAP might have allowed updating definitions for S076 in ECC5, using the TCodes OMO* series in the IMG.  However, there is still no Update Definition option for S076.  When I display S076 using SE16N for the Version 000, nothing is displayed again in Production System. 
    I guess all this leads to posting an OSS note.
    I would appreciate your comments.
    Regards,
    Mumin DIKMEN

  • Data allocation for internal table rows Dynamically

    Hi Friends
    I have requirement like below:
    I have one internal table with 400 amounts columns, I will get the value from another program
    that indicates to which column I have to add the values. I dont want to write the case statement
    because I need to write 400 WHEN statements.
    Is there any alternative way dynamically I can choose the internal table column and assign the value which
    I am getting from external program.
    Please help on this as soon as possible.
    Points will be rewarded
    Thanks
    Praveen

    Hi Praveen,
    you may use the ASSIGN COMPONENT ... OF STRUCTURE ... statement.
    It allows to assign the field by name or by sequence.
    Assume you columns have names like amount_001 to amount_999 and are fields of structure ls_amounts. The do as decribed here roughly:
    data:
      lv_fieldseq type NUMC_3,
      lv_fieldname type fieldname,
      lv_amount type (???).
    fieldsymbols:
      <amount> type any.
    * fetch amount and field sequence from external data into  lv_amount and lv_fieldseq
    concatenate 'AMOUNT_' lv_fieldseq into lv_fieldname.
    * <amount> is something like a pointer
    assign component (lv_fieldname) of structure ls_amounts to <amount>.
    add lv_amount  to <amount>. 
    if you are sure you have the correct position of the amount field in the structure stored in variable lv_position, you may use
    assign component lv_position of structure ls_amounts to <amount>.
    I prefer the ASSIGN (fieldname) for reasons of more transparency and less danger in case of structural changes.
    Regards,
    Clemens
    Regards,
    Clemens

  • Any official word on Maps data update for Symbian?

    Hello,
    if anyone else still is using Symbian phone...
    The wonders of the world are not over..
    I'm just updating new maps to my Nokia 808 with Nokia Suite 3.8.54.
    1/3 done and loading, will give later more comments as the full update is done...
    BR jeeveeas

    jeeveeas wrote: After little driving, I can see that the maps data is still little old. I'd estimete it's nearly 1 year old, maybe early summer 2014 (as my area was build some new motorways and part of it is already in data but not all).
    Confirmation HERE in Message 3

  • How do i force a data update for iCloud on a device?

    I am trying to view updates made to a pages file on a mobile device. The mobile device is NOT showing the changes made to the document. How can I force the update in info from iCloud? If I can not force an update how long does it take for changes made to show up on mobile devices?
    Notes:
    Pages file modified on iMac (with active wifi) saved to iCloud.
    Modifications not showing on iPad (with active wifi) in pages iCloud files.
    iMac pages file has been saved and closed. iPad still not showing modifications, which are extensive, after 20 min.
    HELP! I NEED THESE UPDATES TO BE SEAMLESS!
    I have restarted the iPad twice with no change in iCloud files list. What am I doing wrong?

    Hello kcswift,
    After reviewing your post, it sounds like updates to documents are not updated to an iOS device. I would recommend that you read this article, it may be able to help the issue.
    iCloud: Troubleshooting Documents in the Cloud - Apple Support
    Thanks for using Apple Support Communities.
    Have a nice day,
    Mario

  • Edit Date updated for whole catalog (how to view edit date?)

    I suddenly found out that my publish service that exports newly edited photos suddenly contained all my photos, and I have no idea how that happened. It seems the Edit Date has been changed, but I can not find any way to view the date, so it's difficult to pinpoint exactly when it happened.
    So - two questions:
    How could that happen? I have not made any mass updates and not changed the development version either
    How to view the Edit Date?
    Thanks

    Well, a good guess would be: something is getting (or did get) changed.
    If its not a plugin, then its something else (at the risk of stating the obvious...)
    ChangeManager can provide a detailed list of all develop settings and metadata changes between any two states of a photo, so if its develop settings or metadata that's changing, then you can see exactly what.
    Some kinds of changes ChangeManager can not detail - if the changes are falling in the "mystery" class, at least you'd have it narrowed down... - may be worth trying...
    PS - Have you checked Metadata Status Date in the library panel - thats the closest thing I know of to the edit-date that is exposed by the Lightroom UI - you cant filter or collect on it, but you can at least view it.
    R

  • Up to date Update of Mac OS X Lion

    The up-to-date update for OS X Lion, i want to do this but during the prossec of this it says that i need to show proof that i bought this laptop and i dont have any because i got it from santa and i am 11 years old, so what do i do? any suggestions

    Macaby wrote:
    If "Santa" is in your family, Santa should be able to take care of it.  A legal copy of update for OS X can be used for ALL computers in the same household.
    Assuming there are other Macs there (very likely) and Santa has created an account at App Store and udgraded to Lion.  Some have not because they want to stay with Snow Leopard.
    But this part is odd "need to show proof that i bought this laptop". I've never been asked for proof of purchase at the App store. Of course, at that age he probably cannot create an App Store acct and has no credit card.
    I'd call the local Apple Store, or Apple Tech support, and see what they advise. There must be a way to get Lion without being old enough to vote
    Phil

  • Update all rows in a table which has 8-10 million rows take for ever

    Hi All,
    Greetings!
    I have to update 8million rows on a table. Basically have to reset the batch_id with the current batch number. it contains 8-10 million rows and i have tried with bulk update and then also it takes long time. below is the table structure
    sales_stg (it has composite key of product,upc and market)
    =======
    product_id
    upc
    market_id
    batch_id
    process_status
    I have to update batch_id,process_status to current batch_id (a number) and process_status as zero. I have to update all the rows with these values for batch_id = 0.
    I tried bulk update an it takes more than 2hrs to do. (I limit the update to 1000).
    Any help in this regard.
    Naveen.

    The fastest way will probably be to not use a select loop but a direct update like in William's example. The main downside is if you do too many rows you risk filling up your rollback/undo; to keep things as simple as possible I wouldn't do batching except for this. Also, we did some insert timings a few years ago on 9iR1 and found that the performance curve on frequent commits started to level off after 4K rows (fewer commits were still better) so you could see how performance improves by performing fewer commits if that's an issue.
    The other thing you could consider if you have the license is using the parallel query option.

Maybe you are looking for

  • How do I delete a contact which is not in my contact list or anywhere else?

    I need to delete contact information (email addresses and names) on my iPhone which keep coming up every time I type a remotely similar name in Mail, but isn't in my contact list. I tried searching for the name and then the associated email address u

  • Why are my files not showing up on desktop?

    I was running several programs on my macbook air: iChat, iCal, Mail, Word for Mac, Safari, and Finder. In Safari, I would right click on any file (word, powerpoint, pdf, etc) to download it to desktop as I normally would. All goes well until I actual

  • XML Gateway outbound from BPEL

    We are trying to get the data from EBS using BPEL Process through XML Gateway outbound. We created XML Gateway DTD and Map and successfully posting to ECX_OUTBOUND and other sysyems(WebMethods). Now we are trying access it from BPEL. We created Recei

  • Display "without PGI" & "PGI done not invoiced" in the selection screen

    Hi All, I am preparing a query to track the status of outbound deliveries and would greatly appreciate it if you could guide me on the following requirement. Is there a way to display the following two fields in the "Selection Screen" of a query (TCo

  • Jsp, jrun and cookies

    I have i problem with ie6 and cookies We have a web server with jrun3.1 and database server sqlserver2000. For ie6, session variable is like a cookies and block it... When i use services from Web site "A" by using a frameset (or portal) on Web site "