Permalink
Browse files

Optimize export speed

git-svn-id: https://adminer.svn.sourceforge.net/svnroot/adminer/trunk@1033 7c3ca157-0c34-0410-bff1-cbf682f78f5c
  • Loading branch information...
1 parent 25f01d3 commit 8fe1aa016117b9c686f4eb41e919681f756740b8 jakubvrana committed Aug 28, 2009
Showing with 16 additions and 24 deletions.
  1. +0 −1 adminer/dump.inc.php
  2. +14 −15 adminer/include/export.inc.php
  3. +2 −7 adminer/include/functions.inc.php
  4. +0 −1 adminer/select.inc.php
View
@@ -146,7 +146,6 @@ function dump_triggers($table, $style) {
}
}
}
- dump();
exit;
}
@@ -1,5 +1,5 @@
<?php
-//! memory consumption, speed
+//! memory consumption
function dump_table($table, $style, $is_view = false) {
global $dbh;
@@ -103,12 +103,15 @@ function dump_data($table, $style, $select = "") {
$result = $dbh->query(($select ? $select : "SELECT * FROM " . idf_escape($table))); //! enum and set as numbers, microtime
if ($result) {
$fields = fields($table);
- $length = 0;
+ $insert = "";
+ $buffer = "";
while ($row = $result->fetch_assoc()) {
if ($_POST["format"] == "csv") {
dump_csv($row);
} else {
- $insert = "INSERT INTO " . idf_escape($table) . " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ") VALUES";
+ if (!$insert) {
+ $insert = "INSERT INTO " . idf_escape($table) . " (" . implode(", ", array_map('idf_escape', array_keys($row))) . ") VALUES";
+ }
$row2 = array();
foreach ($row as $key => $val) {
$row2[$key] = (isset($val) ? (ereg('int|float|double|decimal', $fields[$key]["type"]) ? $val : $dbh->quote($val)) : "NULL"); //! columns looking like functions
@@ -122,23 +125,21 @@ function dump_data($table, $style, $select = "") {
dump("$insert ($s) ON DUPLICATE KEY UPDATE " . implode(", ", $set) . ";\n");
} else {
$s = "\n($s)";
- if (!$length) {
- dump($insert . $s);
- $length = strlen($insert) + strlen($s);
+ if (!$buffer) {
+ $buffer = $insert . $s;
} else {
- $length += 1 + strlen($s); // 1 - separator length
- if ($length < $max_packet) {
- dump(",$s");
+ if (strlen($buffer) + 1 + strlen($s) < $max_packet) { // 1 - separator length
+ $buffer .= ",$s";
} else {
- dump(";\n$insert$s");
- $length = strlen($insert) + strlen($s);
+ dump("$buffer;\n");
+ $buffer = $insert . $s;
}
}
}
}
}
- if ($_POST["format"] != "csv" && $style != "INSERT+UPDATE" && $result->num_rows) {
- dump(";\n");
+ if ($_POST["format"] != "csv" && $style != "INSERT+UPDATE" && $buffer) {
+ dump("$buffer;\n");
}
}
}
@@ -151,8 +152,6 @@ function dump_headers($identifier, $multi_table = false) {
if ($_POST["output"] == "file" || $_POST["compress"]) {
header("Content-Disposition: attachment; filename=$filename.$ext" . ($_POST["compress"] == "gz" ? ".gz" : ""));
}
- ob_flush();
- flush();
return $ext;
}
@@ -360,14 +360,9 @@ function process_input($field) {
}
}
-function dump($string = null) { // null $string forces sending of buffer
- static $buffer = "";
+function dump($string) {
if ($_POST["compress"] == "gz") {
- $buffer .= $string;
- if (!isset($string) || strlen($buffer) > 1e6) {
- echo gzencode($buffer);
- $buffer = "";
- }
+ echo gzencode($string);
} else {
echo $string;
}
View
@@ -48,7 +48,6 @@
}
dump_data($_GET["select"], "INSERT", implode(" UNION ALL ", $union));
}
- dump();
exit;
}
if (!$adminer->selectEmailProcess($where)) {

0 comments on commit 8fe1aa0

Please sign in to comment.