0

我只是在我的网站中插入带有表单的数据,通常数据将插入到最后一行中,例如:auto_increment name

1 a
2 b
3 c
4 d
5 e

但是,当我上次插入新数据时,它插入到表格的中间行,看起来像:

17 data17
30 data30
18 data18
19 data19
20 data20

已插入表中间行的最新数据(data30)。它很少发生在我身上(仍然发生)为什么会发生这种情况?以及我将来如何防止这件事发生?谢谢你。

4

1 回答 1

0

What you see is the result returned by the engine. It is hardly a matter which recod is fetched early and which later as it depends on a lot of issues. For one, dont think your database table to be a sequential file like FoxPro. It is way more sophisticated than that. Next, for every query that returns data use a Order by clause to avoid these instances.

So always use:

select columns from table order by column

The above will ensure you get the data the way you need and not be surprised when the DB engine finds a later record in cache while fetches an older record from a slow media in another database file. If you read the basics of RDBMS concepts then these things are discussed as also you need to study how MySQL internally works.

I found this great article that discusses the many wonderful features of a modern database query engine. http://thinkingmonster.wordpress.com/mysql/mysql-architecture/

Although the entire article discusses the topic very well but you may pay extra attention to the section that talks about Record Cache.

于 2013-04-13T17:12:51.233 回答