Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-18-2012, 06:37 PM   PM User | #1
c1lonewolf
Regular Coder

 
Join Date: Sep 2002
Posts: 216
Thanks: 0
Thanked 11 Times in 11 Posts
c1lonewolf is an unknown quantity at this point
autoincrement...is this a problem

My datatable auto increments the id's. When I just added to new entries and checked datatble using phpmyadmin things were all out of whack!

Last page (7) id's read:
183,184,185,186,187

When I went looking for the new entries I found them on page 3 which read like:
77,78,79,188,189,81,82,83

Is this a problem or is mysql supposed to do that?
__________________
NO Limits!!
c1lonewolf is offline   Reply With Quote
Old 12-19-2012, 12:55 AM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,994 Times in 3,963 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I have no idea what you mean by "went looking for new entries" or, for that matter, what "page 3" is.

But here's a clue for you: If you do *NOT* specify an ORDER BY clause in a SQL SELECT, then MySQL (and *any* database) is allowed to return the records to you in ANY ORDER IT WANTS TO, including totally random order.

*MOST* databases will simply return the records to you in the order they are found on the disk. And you need to remember that databases *WILL* RE-USE space caused by deleted records.

If I had to guess, I'd say you deleted your record with auto_number value 80 and it was a big record (longer than average VARCHAR values??). So MySQL was able to fit *TWO* records (auto-number values 188 and 189) into the space opened up when you deleted 80.

But that is just a guess. Once again, THE ORDER OF AN AUTO_INCREMENT COLUMN MAY OR MAY NOT BE the order of the records on disk and MAY OR MAY NOT BE the order you get the records if you just do a SELECT without any ORDER BY.

If you want to see that latest records, by auto_increment value, the best thing to do is usually
Code:
SELECT * FROM yourtable ORDER BY auto_increment_field DESC LIMIT 20
or similar.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 12-19-2012, 01:14 AM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,448
Thanks: 0
Thanked 496 Times in 488 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by c1lonewolf View Post
Is this a problem or is mysql supposed to do that?
It is definitely supposed to do that.

1. The records will be fit in as best as they can be in the actual file without regard to their key values.

2. All an auto-increment value represents is a unique value to identify each record. There is no particular reason why they have to be in order - it is just easier to generate them that way.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 12-21-2012, 05:06 PM   PM User | #4
c1lonewolf
Regular Coder

 
Join Date: Sep 2002
Posts: 216
Thanks: 0
Thanked 11 Times in 11 Posts
c1lonewolf is an unknown quantity at this point
Thanks guys that's what I needed to know!
__________________
NO Limits!!
c1lonewolf is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:46 PM.


Advertisement
Log in to turn off these ads.