cool79s has asked for the wisdom of the Perl Monks concerning the following question:
use DBI; use edw; use Benchmark qw(:all) ; my $maximo_connect=$maximoconf{'maximo_connect'}; my $maximo_db_user=$maximoconf{'maximo_db_user'}; my $maximo_pwd=$maximoconf{'maximo_pwd'}; my $edw_connect=$edwconf{'edw_connect'}; my $edw_db_user=$edwconf{'edw_db_user'}; my $edw_pwd=$edwconf{'edw_pwd'}; my $table=$ARGV[0]; my $edw_table="STG_EAM_$ARGV[0]_TB"; my $inserted=0; my $max_commit=30000; my $dbh1 = DBI->connect( $edw_connect, $edw_db_user, $edw_pwd , { Prin +tError => 0, RaiseError => 1,AutoCommit=>0 }); my $dbh = DBI->connect( $maximo_connect, $maximo_db_user, $maximo_pwd +, { PrintError => 0, RaiseError => 1,AutoCommit=>0 }); #$sth = DBI->connect($maximo_connect, $maximo_db_user, $maximo_pwd,{Au +toCommit => 0}) # ->column_info(undef, undef, $table, "%"); $sth=$dbh->column_info(undef, undef, $table, "%"); $sth->execute(); push @fields, $_->{COLUMN_NAME} while $_ = $sth->fetchrow_hashref; my $field_placeholders = join ", ", map {'?'} @fields; my $fieldlist = + join ", ", @fields; my $sth1=$dbh->prepare("SELECT $fieldlist from maximo.$table " ); $sth1->execute(); $t0 = Benchmark->new; my $sql_ins="INSERT INTO $edw_table ( $fieldlist ) VALUES ( $field_placeholders )"; my $sth2=$dbh1->prepare("$sql_ins"); while(@columns=$sth1->fetchrow_array) { $inserted+=$sth2->execute(@columns); unless ($inserted % $max_commit) { $dbh1->do('commit'); $inserted=0; } } $dbh1->do('commit'); $t1 = Benchmark->new; $td = timediff($t1, $t0); print "the code took:",timestr($td),"\n"; $dbh->disconnect(); $dbh1->disconnect(); exit(0);
20101011 Janitored by Corion: Added formatting, code tags, as per Writeup Formatting Tips
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI Performance help
by moritz (Cardinal) on Oct 08, 2010 at 17:15 UTC | |
|
Re: DBI Performance help
by runrig (Abbot) on Oct 08, 2010 at 17:18 UTC | |
by Tux (Canon) on Oct 09, 2010 at 11:51 UTC | |
|
Re: DBI Performance help
by locked_user sundialsvc4 (Abbot) on Oct 08, 2010 at 18:11 UTC | |
by cool79s (Initiate) on Oct 08, 2010 at 18:43 UTC | |
by ig (Vicar) on Oct 08, 2010 at 18:53 UTC | |
|
Re: DBI Performance help
by ig (Vicar) on Oct 08, 2010 at 18:36 UTC | |
|
Re: DBI Performance help
by clueless newbie (Curate) on Oct 09, 2010 at 15:32 UTC |