Search code examples
database-performancebulkinsertsap-asesqlperformance

How to perform a Bulk Insert in Sybase SQL


I need to insert a Big amount of data(Some Millions) and I need to perform it Quickly. I read about Bulk insert via ODBC on .NET and JAVA But I need to perform it directly on the Database.

I also read about Batch Insert but What I have tried have not seemed to work Batch Insert, Example

I'm executing a INSERT SELECT but it's taking something like 0,360s per row, this is very slow and I need to perform some improvements here.

I would really appreciate some guidance here with examples and documentation if possible.

DATABASE: SYBASE ASE 15.7


Solution

  • Expanding on some of the comments ...

    • blocking, slow disk IO, and any other 'wait' events (ie, anything other than actual insert/update activity) can be ascertained from the master..monProcessWaits table (where SPID = spid_of_your_insert_update_process) [see the P&T manual for Monitoring Tables (aka MDA tables)]
    • master..monProcessObject and master..monProcessStatement will show logical/physical IOs for currently running queries [again, see P&T manual for MDA tables]
    • master..monSysStatement will show logical/physical IOs for recently completed queries [again, see P&T manual for MDA tables]
    • for UPDATE statements you'll want to take a look at the query plan to see if you're suffering from a poor join order; also of key importance ... direct (fast/good) updates vs deferred (slow/bad) updates; deferred updates can occur for many reasons ... some fixable, some not ... updating indexed columns, poor join order, updates that cause page splits and/or row forwardings
    • RI (PK/FK) constraints can be viewed with sp_helpconstraint table_name; query plans will also show the under-the-covers joins required when performing RI (PK/FK) validations during inserts/updates/deletes
    • triggers are a bit harder to locate (an official sp_helptrigger doesn't show up until ASE 16); check the sysobjects.[ins|upd|del]trig where name = your_table - these represent the object id(s) of any insert/update/delete triggers on the table; also check sysobjects records where type = 'TR' and deltrig = object_id(your_table) - provides support for additional insert/update/delete triggers (don't recall at moment if this is just ASE 16+)
    • if triggers are being fired, need to review the associated query plans to make sure the inserted and deleted tables (if referenced) are driving any queries where these pseudo tables are joined with permanent tables

    There are likely some areas I'm forgetting (off the top of my head) ... key take away is that there could be many reasons for 'slow' DML statements.


    One (relatively) quick way to find out if RI (PK/FK) constraints or triggers are at play ...

    set showplan on
    go
    insert/update/delete statements
    go
    

    Then review the resulting query plan(s); if you see references to any tables other than the ones explicitly listed in the insert/update/delete statements then you're likely dealing with RI constraints and/or triggers.