Hi Folks<br>Yes, you are right.<br><br>The db_next_id is actually playing the trick here, and UIDs will be always unique.<br><br>The db_next_id, actually does <b>Database::getConnection()->nextId($existing_id);</b> and so the ID allocated to new user actually is under DB's control.<br>
<br>Now precisely my worry is, in my local environment I have added 100s of users. Before putting to production environment I will be deleting all users except admin user. And I want the users IDs should again start again from 2 and should be continuous like 2,3,4,5,6,7,8 etc..<br>
<br>What I need to do so that I can achieve it?<br><br>Had it been an auto increment field, I could have set it in data base the next auto increment value (through phpmyadmin->Operations->AUTO INCREMENT).<br><br>Now I am clueless, the only option is take a fresh copy of Drupal 715, create again menus, nodes .., No No way...<br>
<br>If you have a better option to reset everything except nodes, new content types, main menu, secondary menu etc..., please let me know...<br><br><br>Thanks<br>Kamal<br><br><br><br><br><br><div class="gmail_quote">On Sat, Dec 1, 2012 at 1:51 PM, Kamal Palei <span dir="ltr"><<a href="mailto:palei.kamal@gmail.com" target="_blank">palei.kamal@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Jamie, All<br>Thanks for info.<br><br>If this is the case, I would expect user id to be monotonically increase.<br>I can see my users table, the UIDs follow as<br>
<br>0,1,2,3,4,5,6,24,25,26,33,40,41,42<br><br>I do uninstall / install of my custom modules, but I hope that is no way related to uid selection.<br>
<br>Just wondering what may cause this.<br><br>Also I delete nodes sometimes.., can that cause this issue, I hope it is unlikely...<br><br>Regards<br>kamal<br>necs, blr<div class="HOEnZb"><div class="h5"><br><br><div class="gmail_quote">
On Sat, Dec 1, 2012 at 1:26 PM, Jamie Holly <span dir="ltr"><<a href="mailto:hovercrafter@earthlink.net" target="_blank">hovercrafter@earthlink.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">UID is figured by select max(uid). Here is the exact code from user.module:<br>
<br>
if (empty($account->uid)) {<br>
$account->uid = db_next_id(db_query('SELECT MAX(uid) FROM<br>
{users}')->fetchField());<br>
}<br>
// Allow 'created' to be set by the caller.<br>
if (!isset($account->created)) {<br>
$account->created = REQUEST_TIME;<br>
}<br>
$success = drupal_write_record('users', $account);<br>
<br>
$account->uid == 0, which is the same as empty.<br>
<br>
Other modules can influence this via the API, such as hook_user_presave,<br>
but for the core functionality, this is how the UID is figured.<br>
<div><br>
<br><div style="text-align:right">
Jamie Holly<br></div>
<a href="http://www.intoxination.net" target="_blank">http://www.intoxination.net</a><br>
<a href="http://www.hollyit.net" target="_blank">http://www.hollyit.net</a><br>
<br>
</div><div><div>On 11/30/2012 9:44 PM, Michael Prasuhn wrote:<br>
> No. If if was just using SELECT MAX(uid) FROM {users} then it wouldn't have gaps like the OP was experiencing.<br>
><br>
> Note that the result from that query is actually fed to db_next_id() which in turn uses a DBMS specific method to ensure unique IDs. (In MySQL this means using an insert query into a table that is set to auto increment and then reading the ID of the inserted record. This cannot produce duplicate keys. see <a href="http://api.drupal.org/api/drupal/includes%21database%21mysql%21database.inc/function/DatabaseConnection_mysql%3A%3AnextId/7" target="_blank">http://api.drupal.org/api/drupal/includes%21database%21mysql%21database.inc/function/DatabaseConnection_mysql%3A%3AnextId/7</a> )<br>
><br>
> -Mike<br>
> __________________<br>
> Michael Prasuhn<br>
> <a href="http://mikeyp.net" target="_blank">http://mikeyp.net</a><br>
><br>
> On Nov 30, 2012, at 5:42 AM, Earnie Boyd <<a href="mailto:earnie@users.sourceforge.net" target="_blank">earnie@users.sourceforge.net</a>> wrote:<br>
><br>
> > On Fri, Nov 30, 2012 at 8:32 AM, Jamie Holly wrote:<br>
> >> This isn't the case in D7. UID is assigned by a SELECT MAX(uid) FROM<br>
> >> {users}. Check user.module line 571.<br>
> ><br>
> > Unless the whole users table is locked then this is guaranteed to fail<br>
> > under heavy use. Some poor user is going to get a DB error of<br>
> > duplicate key. The chances may be small but there is a chance it will<br>
> > happen. Do you know the issue # that caused this to happen?<br>
> ><br>
> > --<br>
> > Earnie<br>
> > -- <a href="https://sites.google.com/site/earnieboyd" target="_blank">https://sites.google.com/site/earnieboyd</a><br>
> > --<br>
> > [ Drupal support list | <a href="http://lists.drupal.org/" target="_blank">http://lists.drupal.org/</a> ]<br>
><br>
<br>
--<br>
[ Drupal support list | <a href="http://lists.drupal.org/" target="_blank">http://lists.drupal.org/</a> ]<br>
</div></div></blockquote></div><br>
</div></div></blockquote></div><br>