考虑以下SQL:
CREATE TABLE USER1
(
pkUSER1_ID INT UNSIGNED NOT NULL AUTO_INCREMENT,
DATE_UPDATED TIMESTAMP NULL DEFAULT NULL,
NAME VARCHAR(25) NOT NULL,
CONSTRAINT PRIMARY KEY (pkUSER1_ID),
CONSTRAINT UNIQUE (NAME)
)
ENGINE = INNODB;
INSERT INTO USER1
SET NAME = 'asdf'
ON DUPLICATE KEY
UPDATE DATE_UPDATED = NOW();
INSERT INTO USER1
SET NAME = 'asdf'
ON DUPLICATE KEY
UPDATE DATE_UPDATED = NOW();
INSERT INTO USER1
SET NAME = 'asdf1'
ON DUPLICATE KEY
UPDATE DATE_UPDATED = NOW();
SELECT * FROM USER1;
现在注意结果集。尽管没有插入任何内容,auto_increment仍然增加了。
+------------+---------------------+-------+
| pkUSER1_ID | DATE_UPDATED | NAME |
+------------+---------------------+-------+
| 1 | 2010-02-09 13:29:15 | asdf |
| 3 | NULL | asdf1 |
+------------+---------------------+-------+
我在两个不同的服务器上得到不同的行为......上面的输出来自运行在2.6.9-023stab048.6-enterprise上的MySQL v5.0.45(我认为它是Red Hat)。在2.6.26-2-amd64(显然是Debian)上运行的MySQL v5.0.51a-24 + lenny2-log上不存在这个问题。
是否有配置设置我可以更改以避免这种情况?我的数据库中有大约300个用户,但是运行插入/更新语句的频率很高,最新用户ID超过600,000。