Copy Between 2 and 3 billion rows from a heap table with no key to a new partioned table.

  • Hello,

    i need to copy Between 2 and 3 billion rows from a heap table with no identity to a new partioned table. The primary key is made up of a smallint value that represents a Month and a loan_number.

    --The partion key is a small int value.

    --I have tried the approach of selecting by the partition key, but as you can imagine because of the amount of data each select can take quite some time.

    --I also tried using an import\export task it started moving some data, but it is also extremly slow.

    --The new table has 24 partitions. each partition represents 24 values of the partition key from 0 - 552

    Here is the definition of the partitioned table. The heap tablle is the same except it does not have the identity column created_by\date attributes.

    --Partitioned table

    CREATE TABLE dbo.qc_partition

    (

    qccq_partition_idBIGINT IDENTITY(1,1)

    ,pool_idCHAR(3)NOT NULL

    ,deal_noCHAR(5)NOT NULL

    ,group_noCHAR(3)NOT NULL

    ,servicerVARCHAR(4)NULL

    ,loan_idCHAR(6)NOT NULL

    ,exloan_idVARCHAR(18)NOTNULL

    ,last_int_pSMALLDATETIMENULL

    ,balanceMONEYNULL

    ,int_rateNUMERIC(6, 3)NULL

    ,totpmt_dueMONEYNULL

    ,sched_principal,sched_mnth_pMONEYNULL

    ,mba_statVARCHAR(1)NULL

    ,ots_statVARCHAR(1)NULL

    ,payment_histVARCHAR(12)NULL

    ,exceptionVARCHAR(1)NULL

    ,start_dateSMALLDATETIMENULL

    ,end_dateSMALLDATETIMENULL

    ,fc_end_typVARCHAR(1)NULL

    ,payoff_dSMALLDATETIMENULL

    ,payoff_rVARCHAR(1)NULL

    ,sell_dateSMALLDATETIMENULL

    ,inv_balMONEYNULL

    ,next_percentNUMERIC(6, 3)NULL

    ,loss_valMONEYNULL

    ,net_rateNUMERIC(7, 4)NULL

    ,periodSMALLINTNOT NULL

    ,file_nameCHAR(8)NOT NULL

    ,created_byVARCHAR(70)NOT NULLDEFAULT CURRENT_USER

    ,created_dateDATETIMENOT NULLDEFAULT (GETDATE())

    ) ON partition_scheme_qc (period)

    Does anyone have any ideas?

    Thanks,

    Michael

  • I usually handle large data moves in batches by setting up a loop and copying a set amount. Since these are during production I put in a delay to prevent hogging all the cpu. I don't know if this is practical for your situation.

    InsertMore:

    WAITFOR DELAY '00:00:05' -- 5 second delay allow other process some CPU

    INSERT top (100000) INTO NewTable

    SELECT columns

    FROM OldTable

    where id between @ID_First and @ID_Last

    and ID not in (select ID from NewTable) -- Not already inserted

    if @@rowcount > 0 goto InsertMore

  • The Heap table does not have an Id column only the partioned table does.

    thanks for the input.

  • I think you've made a mistake in chosing what to partition by. My recommenation would be to partition by month or year of the column that best represents the age of the row. Hopefully, the older the row, the fewer updates it will actually have and THAT is what will save your butt at reindexing time over time.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Hello,

    1st of all sorry for creating a duplicate topic it was an user error. I noticed it only after I created the 2nd. I was not able to delete.

    The current partition key does represent Months. 1 = '01/1989', 2 = '02/1989', 3 = '03/1989'..... Any Ideas on what I can do to copy the data to the partition table?

    thank you,

  • Hello,

    Does anyone have any ideas on the copying of the data in my situation?

    Thanks

  • mishka-723908 (1/10/2013)


    Hello,

    Does anyone have any ideas on the copying of the data in my situation?

    Thanks

    Yes. First, get rid of that partition key you're using and base it on the date, instead.

    Then, split one month at a time off the original source table and load it into the final table. I believe you should drop most of your the partitions you made in the target table because there's a trick to loading a whole "split" table in just milliseconds if you have a new empty partition.

    I haven't done this in a while so I'd have to do just like I recommend you do. Lookup the method in Books Online.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (1/10/2013)


    mishka-723908 (1/10/2013)


    Hello,

    Does anyone have any ideas on the copying of the data in my situation?

    Thanks

    Yes. First, get rid of that partition key you're using and base it on the date, instead.

    Then, split one month at a time off the original source table and load it into the final table. I believe you should drop most of your the partitions you made in the target table because there's a trick to loading a whole "split" table in just milliseconds if you have a new empty partition.

    I haven't done this in a while so I'd have to do just like I recommend you do. Lookup the method in Books Online.

    I agree with Jeff. You may find it by looking for a topic discussing SLIDING WINDOWS, or something to that affect.

  • Ugh! Almost forgot because it's been a while. What are you planning on using for the PK on the new table? I ask because, on paritioned tables, any unique index must include the partitioning column. That can lead to some pretty nasy FK problems if you intend for other tables to point to the partitioed table usig DRI.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Thank you guys for the replys.

    Unfortunately, in the current table we do not have a date column that we can use. I am assuming that the designer of the table used the "period" attribute because that is the way it is received from the vendor. The period does represent Months. Period-1 = '01/1989', Period-2 = '02/1989', Period-3 = '03/1989'. At any given time we can insert\delete\update data for any of the periods. All periods will be used at the same level for reporting so we will not be doing sliding window.

    --this is what I currently have for indexing. The Primary key is (period, external_loan_id), but I was not sure of the best way to create it on the partitioned table.

    CREATE NONCLUSTERED INDEX IX_period_external_loan_id

    ON qc_partition (period, external_loan_id)

    ON partition_scheme_qc (period)

    GO

    --Current Table

    CREATE TABLE dbo.qc_partition

    (

    pool_id CHAR(3) NOT NULL

    , deal_no CHAR(5) NOT NULL

    , group_no CHAR(3) NOT NULL

    , servicer VARCHAR(4) NULL

    , loan_id CHAR(6) NOT NULL

    , exloan_id VARCHAR(18) NOT NULL

    , last_int_p SMALLDATETIME NULL

    , balance MONEY NULL

    , int_rate NUMERIC(6, 3) NULL

    , totpmt_due MONEY NULL

    , sched_principal , sched_mnth_p MONEY NULL

    , mba_stat VARCHAR(1) NULL

    , ots_stat VARCHAR(1) NULL

    , payment_hist VARCHAR(12) NULL

    , exception VARCHAR(1) NULL

    , start_date SMALLDATETIME NULL

    , end_date SMALLDATETIME NULL

    , fc_end_typ VARCHAR(1) NULL

    , payoff_d SMALLDATETIME NULL

    , payoff_r VARCHAR(1) NULL

    , sell_date SMALLDATETIME NULL

    , inv_bal MONEY NULL

    , next_percent NUMERIC(6, 3) NULL

    , loss_val MONEY NULL

    , net_rate NUMERIC(7, 4) NULL

    , period SMALLINT NOT NULL

    , file_name CHAR(8) NOT NULL

    ) ON primary

    --Partitioned table

    CREATE TABLE dbo.qc_partition

    (

    qc_partition_id BIGINT IDENTITY(1,1)

    , pool_id CHAR(3) NOT NULL

    , deal_no CHAR(5) NOT NULL

    , group_no CHAR(3) NOT NULL

    , servicer VARCHAR(4) NULL

    , loan_id CHAR(6) NOT NULL

    , exloan_id VARCHAR(18) NOT NULL

    , last_int_p SMALLDATETIME NULL

    , balance MONEY NULL

    , int_rate NUMERIC(6, 3) NULL

    , totpmt_due MONEY NULL

    , sched_principal , sched_mnth_p MONEY NULL

    , mba_stat VARCHAR(1) NULL

    , ots_stat VARCHAR(1) NULL

    , payment_hist VARCHAR(12) NULL

    , exception VARCHAR(1) NULL

    , start_date SMALLDATETIME NULL

    , end_date SMALLDATETIME NULL

    , fc_end_typ VARCHAR(1) NULL

    , payoff_d SMALLDATETIME NULL

    , payoff_r VARCHAR(1) NULL

    , sell_date SMALLDATETIME NULL

    , inv_bal MONEY NULL

    , next_percent NUMERIC(6, 3) NULL

    , loss_val MONEY NULL

    , net_rate NUMERIC(7, 4) NULL

    , period SMALLINT NOT NULL

    , file_name CHAR(8) NOT NULL

    , created_by VARCHAR(70) NOT NULL DEFAULT CURRENT_USER

    , created_date DATETIME NOT NULL DEFAULT (GETDATE())

    ) ON partition_scheme_qc (period)

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply