in reply to Re: speedup sqlserver insert
in thread speedup sqlserver insert

I'll check on autocommit...I have just timed the insert; the delete is negligable.

Replies are listed 'Best First'.
Re^3: speedup sqlserver insert
by Corion (Patriarch) on Sep 12, 2014 at 13:29 UTC

    Have you investigated the bulk load facilities of your server? Most likely, large(r) bulk inserts are done faster by making the server process read from a CSV file.

      what should this look like to turn autocommit off?
      $dbh = DBI->connect("dbi:ODBC:Driver={SQL Server};Server=xxxxx\\yyyy; +UID=$user;PWD=$password, { RaiseError => 1, AutoCommit => 0 } ") or die "\t\t\nCannot +connect to SQLServer... $!";

        Did you paste that connect string from your program or did you retype it?

        That connect string is highly dubious, because it includes some strings that should be Perl code if you follow the documentation of DBI.

        Update: Maybe you should follow the documentation of DBI closer:

        $dbh = DBI->connect($dsn, $user, $password, { RaiseError => 1, AutoCommit => 0 });

        If you take that piece of code, all that remains is to fill in the three variables $dsn, $user and $password:

        my $user='fionbarr'; my $password='secret'; my $dsn= '...'; $dbh = DBI->connect($dsn, $user, $password, { RaiseError => 1, AutoCommit => 0 });
Re^3: speedup sqlserver insert
by mje (Curate) on Sep 12, 2014 at 16:17 UTC

    I wouldn't bother turning off AutoCommit as it is a global setting and you'll have to call commit everywhere you run any SQL (often even select sql). Just start a transaction with begin_work before the prepare for the insert and commit it at the end of your loop.

    If you do general searches for speedups you'll find loads of other possible speedups. Bulk loading is one someone else already mentioned, DBIs execute_array, disabling indexes on your table until after the insert etc

    UPDATE: Also, what is the point of sorting those hashes - it won't affect what rows are inserted into the database as fas as I can see.