Hi <span class="HOEnZb"><font color="#888888">Earnie<br>
</font></span><div class="HOEnZb"><div class="h5">There are few more things here. As Austin mentioned db_next_id() looks as <i><b>Database::getConnection()->nextId($existing_id)</b></i><br>
</div></div> , so the nextId() plays a role here in determining the next uid. <br><br>The api nextId() , is different for different database type like for mysql it is different , for postgresql it is different ...<br><br>
Lets take the case of mysql, it makes use of a table <i><b>sequences</b></i>, in that table, <i><b>id</b></i> column is auto increment one. every time you add a user or delete a user, one entry is added to that table, so <i><b>id</b></i> gets new value every time. That id value is your next user id.<br>
<br>To check this just delete an user and add another user, you will see the new user id is N+2 assuming N was last max user id.<br><br>Not sure why it is implemented like this, probably missing the original idea behind this. <br>
<br>Thanks<br>Kamal<br>Net Cloud Systems, Bangalore<br><br><br><br><br><div class="gmail_quote">On Sat, Dec 8, 2012 at 10:54 PM, Earnie Boyd <span dir="ltr"><<a href="mailto:earnie@users.sourceforge.net" target="_blank">earnie@users.sourceforge.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Since the user table doesn't have an auto increment field as has been<br>
discussed already, simply deleting all users except UID 0 and UID 1<br>
would cause the methods to use 2 as the next id. However, you need to<br>
ensure you don't have nodes and other data dependent on the created in<br>
the DB as well. Otherwise when someone signs up your development/test<br>
data would be assigned to them.<br>
<span class="HOEnZb"><font color="#888888"><br>
Earnie<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Fri, Dec 7, 2012 at 8:49 PM, Kamal Palei <<a href="mailto:palei.kamal@gmail.com">palei.kamal@gmail.com</a>> wrote:<br>
> Hi Folks<br>
> Yes, you are right.<br>
><br>
> The db_next_id is actually playing the trick here, and UIDs will be always<br>
> unique.<br>
><br>
> The db_next_id, actually does<br>
> Database::getConnection()->nextId($existing_id); and so the ID allocated to<br>
> new user actually is under DB's control.<br>
><br>
> Now precisely my worry is, in my local environment I have added 100s of<br>
> users. Before putting to production environment I will be deleting all users<br>
> except admin user. And I want the users IDs should again start again from 2<br>
> 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<br>
> 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,<br>
> create again menus, nodes .., No No way...<br>
><br>
> If you have a better option to reset everything except nodes, new content<br>
> types, main menu, secondary menu etc..., please let me know...<br>
><br>
><br>
> Thanks<br>
> Kamal<br>
><br>
><br>
><br>
><br>
><br>
><br>
> On Sat, Dec 1, 2012 at 1:51 PM, Kamal Palei <<a href="mailto:palei.kamal@gmail.com">palei.kamal@gmail.com</a>> wrote:<br>
>><br>
>> 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<br>
>> 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<br>
>> unlikely...<br>
>><br>
>> Regards<br>
>> kamal<br>
>> necs, blr<br>
>><br>
>><br>
>> On Sat, Dec 1, 2012 at 1:26 PM, Jamie Holly <<a href="mailto:hovercrafter@earthlink.net">hovercrafter@earthlink.net</a>><br>
>> wrote:<br>
>>><br>
>>> UID is figured by select max(uid). Here is the exact code from<br>
>>> 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>
>>><br>
>>><br>
>>> Jamie Holly<br>
>>> <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>
>>> 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<br>
>>> > have gaps like the OP was experiencing.<br>
>>> ><br>
>>> > Note that the result from that query is actually fed to db_next_id()<br>
>>> > which in turn uses a DBMS specific method to ensure unique IDs. (In MySQL<br>
>>> > this means using an insert query into a table that is set to auto increment<br>
>>> > and then reading the ID of the inserted record. This cannot produce<br>
>>> > duplicate keys. see<br>
>>> > <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>
>>> ><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">earnie@users.sourceforge.net</a>><br>
>>> > 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)<br>
>>> > >> FROM<br>
>>> > >> {users}. Check user.module line 571.<br>
>>> > ><br>
>>> > > Unless the whole users table is locked then this is guaranteed to<br>
>>> > > 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<br>
>>> > > 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>
>><br>
>><br>
><br>
><br>
> --<br>
> [ Drupal support list | <a href="http://lists.drupal.org/" target="_blank">http://lists.drupal.org/</a> ]<br>
<br>
<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>
</div></div></blockquote></div><br>