I have a .sqlite
database:
$db = new PDO("sqlite:db.sqlite");
It's size is 60MB. It has 1 table. One of this table columns (the only heavy one) holds BLOB_TEXT
data. I am trying to compress this column values:
$pdo = $db->query("SELECT id, house_plan FROM houses");
$houses = $pdo->fetchAll(PDO::FETCH_ASSOC);
$initial_length = 0;
$compressed_length= 0;
for ($i = 0; $i < count($houses); $i++) {
$id = $houses[$i]["id"];
$house_plan = $houses[$i]["house_plan"];
$compressed = gzcompress($house_plan);
$initial_length += strlen($house_plan);
$compressed_length += strlen($compressed);
flush();
$query = $db->prepare("UPDATE houses SET house_plan=? WHERE id=" . $id);
$query->bindParam(1, $compressed, PDO::PARAM_LOB);
$query->execute();
}
Then printing summed initial BLOB_TEXT
data length and compressed data length (which replaced the initial data in the table):
echo "Before: " . $initial_length . ", After: " . $compressed_length;
// Before: 52222553, After: 2577948
And their difference in %:
echo "Difference: " . (100 - round($compressed_length / $initial_length * 100)) . "%";
// Difference: 95%
Afterwards I check the size of the database, and it's still 60MB. BLOB_TEXT
data difference was 95%, but the size of the database is not changed.
How that might be? Or what I am doing wrong compressing BLOB_TEXT
?
I expect database size reduces as well, because this is the only heavy column I have.