Comment 4 for bug 1179361

Revision history for this message
Gea-Suan Lin (gslin) wrote :

I have another simple version, which affect UNIQUE KEY with UTF8 column too.

CREATE TABLE `test` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `c` varchar(32) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `c` (`c`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

$ cat insert.php
<?php

$db = new PDO('mysql:host=db-test-1;dbname=t', 'test', 'test');

$p = $db->prepare('INSERT INTO test (c) VALUES (?);');

for ($i = 0;; $i++) {
    $p->execute(array('中文測試' . rand(1, 10000)));
    if (0 == $i % 1000) {
        printf("%d\n", $i);
    }
}

$ps = $db->prepare('SELECT COUNT(*) FROM `test`;');

$ cat delete.php
<?php

$db = new PDO('mysql:host=db-test-1;dbname=t', 'test', 'test');

$ps = $db->prepare('SELECT COUNT(*) FROM `test`;');

for ($i = 0;; $i++) {
    $ps->execute();
    list($c) = $ps->fetch(PDO::FETCH_NUM);

    if ($c > 100) {
        $sql = sprintf('DELETE FROM `test` ORDER BY `c` LIMIT %d;', $c / 2);
        $db->query($sql);
        printf("%d: %s\n", $i, $sql);
    }

    sleep(1);
}