ALTER TABLE bazı notlar var:
- "Alter table" masa kilitli ve kilitsiz almak neden olabilir? Tablo düzey kilit çok innodb motoru için satır düzeyinde kilit etkileyebilir.
- The table will get unlocked after an alter , as MySQL says:
http://dev.mysql.com/doc/refman/5.5/en/lock-tables.html
If you use ALTER TABLE on a locked table, it may become unlocked. For example, if you attempt a second ALTER TABLE operation, the result may be an error Table 'tbl_name' was not locked with LOCK TABLES. To handle this, lock the table again prior to the second alteration. See also Section C.5.7.1, “Problems with ALTER TABLE”.
- 17 silinmediyse 15-17 arasında, örneğin, inter delikleri innodb On (16) geri olmayacaktır.
ALTER TABLE table AUTO_INCREMENT =1
, yalnızca geçerli uppest Otomatik artış kimliği aşağı düşüyor olacak.
Why recycle ID? Because ...
For example i use InnoDB and have a stable structure of relation design on my db. So when i delete a parent item then the relative children will be removed automatically. It may be not about a table creating URLs based on the IDs and reusing an ID may have no effect on external systems such as the reports of google analytics.
However the large projects have long IDs(such as post/status systems) will be backed up with a powerful archive mechanism and also the composite PK for the posts is something like timestamp+userid.
But if we have a variable datatable which it's rows should be close to hand on an innodb(not in an archive table) the "alter table" may be a few risky.
InnoDB is a wise choice when we're gonna update/insert tables frequently(row lock level) versus MyISAM(table lock level) which will be used for more steady datatables such as archives or country lists.
Solution :
i'm ashamed , actually i had seen this question about 2 years ago when i was searching for a reason for "why we should keep the IDs increasable and we shouldn't recycle the IDs" and that time i have less time to answer.
My solusion query for myself was (not recommended for long and busy tables) :
SELECT t1.ID-1 AS ID FROM $TableName AS t1 WHERE t1.ID>1 AND 0=(SELECT COUNT(t2.ID) FROM $TableName AS t2 WHERE t2.ID=t1.ID-1) LIMIT 1;
Biz PK ile çalışıyoruz, bu yüzden çünkü sorgu zaman makul olacaktır. Ancak durumlara dayalı, sorgu zaman değişken olabilir. ben bu sorgu hızı için yeterli testler yoktu ama ben 138.335 satır ile dünya kentlerinden bir MyISAM tablo üzerinde 0.00 bir deneyim oldu.
Bu sorgu kayıtları ve geri dönüşüm kimlik onlar için akıllıca bir eylem değildir milyonlarca aktif meşgul tablolar için olduğunu unutmayın.