]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 394574: bzdbcopy should avoid reading entire tables into memory
authoreseyman%linagora.com <>
Thu, 26 Jun 2008 14:23:07 +0000 (14:23 +0000)
committereseyman%linagora.com <>
Thu, 26 Jun 2008 14:23:07 +0000 (14:23 +0000)
Patch By Olav Vitters <bugzilla-mozilla@bkor.dhs.org> r=mkanat, a=mkanat

contrib/bzdbcopy.pl

index 489909882a80b0208ad61e0a9f24ad1373b1d26e..9b9c066dd5f37679de5f6c846c57be6bd810d912 100755 (executable)
@@ -48,6 +48,14 @@ print "Connecting to the '" . SOURCE_DB_NAME . "' source database on "
       . SOURCE_DB_TYPE . "...\n";
 my $source_db = Bugzilla::DB::_connect(SOURCE_DB_TYPE, 'localhost', 
     SOURCE_DB_NAME, undef, undef, SOURCE_DB_USER, SOURCE_DB_PASSWORD);
+# Don't read entire tables into memory.
+if (SOURCE_DB_TYPE eq 'Mysql') {
+    $source_db->{'mysql_use_result'}=1;
+
+    # MySQL cannot have two queries running at the same time. Ensure the schema
+    # is loaded from the database so bz_column_info will not execute a query
+    $source_db->_bz_real_schema;
+}
 
 print "Connecting to the '" . TARGET_DB_NAME . "' target database on "
       . TARGET_DB_TYPE . "...\n";
@@ -81,7 +89,8 @@ foreach my $table (@table_list) {
                          @table_columns;
 
     my $select_query = "SELECT " . join(',', @table_columns) . " FROM $table";
-    my $data_in = $source_db->selectall_arrayref($select_query);
+    my $select_sth = $source_db->prepare($select_query);
+    $select_sth->execute();
 
     my $insert_query = "INSERT INTO $table ( " . join(',', @table_columns) 
                        . " ) VALUES (";
@@ -97,7 +106,7 @@ foreach my $table (@table_list) {
     
     print "Writing data to the target '$table' table on " 
           . TARGET_DB_TYPE . "...";
-    foreach my $row (@$data_in) {
+    while (my $row = $select_sth->fetchrow_arrayref) {
         # Each column needs to be bound separately, because
         # many columns need to be dealt with specially.
         my $colnum = 0;