Jump to content


Corporate Sponsors


Latest News: (loading..)

* * * * * 1 votes

How is product_id generated?


2 replies to this topic

#1 Inferos

  • Community Member
  • 43 posts
  • Real Name:Eugen
  • Gender:Male

Posted 22 November 2009, 02:34

Hello,

I searched for information regarding this issue and looked in the code as well, but couldn't find an answer, so I was hoping there's someone here who knows it.

My question is pretty simple: how is the product_id generated / calculated when you add a new product in the admin?

For example, I have 85 products. If I add a new product, it will have the product_id 86. BUT, if I delete 3 products (let's say 83, 84 and 85), the next time I'll add a new product it will still have the product_id 86.

I couldn't find a trace of where the past memory of the deleted products is anywhere. How does the database know what there were those two products before? I deleted them. The next new product I add should have product_id 83. Because 82 is the highest product_id in the database.

The same thing happens for manufacturer_id and category_id.

Anyone?

Thanks in advance!

#2 MrPhil

  • Community Member
  • 2,900 posts
  • Real Name:Phil
  • Gender:Male

Posted 22 November 2009, 02:45

The database (MySQL) internally keeps track of where it is with "auto_increment" fields, such as *_id fields. It is not supposed to reuse a value, but always to keep increasing it. So, if your highest id value is 85, and you delete 83, 84, and 85; the next auto-incremented id is 86, not 83. That's just the way databases work. Since a *_id is an internal value, not exposed to the customer, it doesn't matter.

Edited by MrPhil, 22 November 2009, 02:46.


#3 Inferos

  • Community Member
  • 43 posts
  • Real Name:Eugen
  • Gender:Male

Posted 22 November 2009, 03:02

Thanks a lot for the explanations.

Indeed, there's a "database" called information_schema which remembers the incrementations and other needed data.

It's true, *_id is an internal value, not relevant to the customer. It does however get shown in the address bar, although this is not at all important.

Again, thank you for sharing this, MrPhil, much appreciated.