WyCnet;11006981 wrote:
You only have known access iff you specify it during an INSERT.
Never ever specify value for an auto increment field. If you specify what to put in your auto increment field, don't make it auto increment in the first place.
As for only having "known access", no! You can always retrieve its value from the last row YOU inserted and that's the whole point. The auto incremented value used will be separate for each instance connected to the DB. If you insert a row which gets id 2 and I insert a row which gets value 3, you will still get 2 when you check what last insert id is, while I will get 3. You have access to your AI value and I to mine.
WyCnet;11006981 wrote:
and iff it is greater (+j where j > 1) than the last incremented index.
There is a system in place to handle exactly this (it's called auto increment and works by leaving the specifics of it alone by simply NOT specifying anything for that column).
WyCnet;11006981 wrote:
With the above in mind and the fact that asynchronous INSERTS are possible, a database programmer can only be assured of one auto increment index if the columns are unique or uniquely combined keys are being used, otherwise auto increment acts like a secondary non-unique key.
If your auto increment field is NOT the primary key, then why is it there in the first place?
WyCnet;11006981 wrote:
Therefore to use an auto increment index, it must be read from the database after the fact and after database commits if you use a start transaction.
And from the 5.5 docs
InnoDB uses a special table-level AUTO-INC lock that it keeps to the end of the current SQL statement, not to the end of the transaction.
Which means that you do not have to commit before accessing the AI value. You could say the AI value is pre-generated for eventual later use on commit. And if you do not commit, that is you rollback the transaction, then the current AI value to be used for next insertion isn't rolled back. In a way you could say that the DBMS is not in the same state after the rollback as it was before the rollback, but that doens't matter. What matters is that the generated keys are unique, and that they are replicable if you have to reconstruct the db from logs or if you replicate data from master to slave. What the actual values are doesn't matter. Moreover, the rollback will not affect the actual values used by other peoples' transactions either. Thus, the state of the database will be consistent and unchanged (its state is what it has stored), so wether the DBMS has the same state or not is irrelevant as long as the consistency of the DB state is guaranteed.
WyCnet;11006981 wrote:
If your Table has no keys then the auto increment index acts like one
No... you either have a key or you do not have a key. You can't NOT have one and while somehow having a key actor.
WyCnet;11006981 wrote:
, but only after you perform a relational query like :
No, it's a key or it's not a key. Either you have a key when you created the table, as per the create table definition, or you do not have one. You may of course also add/remove keys later by alter table statements and their equivalents.
WyCnet;11006981 wrote:
and in the subsequent requests having Tables that are related by Informational content, using the same auto increment index,
Which is a separate issue. You may have table rows that are related on non-auto increment fields. You may have table rows that are related on non-unique fields.
WyCnet;11006981 wrote:
This is usally achieved by database programmers by locking associated tables from write access when data is being inserted into the primary relational table.
No. Since you will insert a new unique value into the AI column, this value should NOT allready exist anywhere else (which is one of the reasons you SHOULD, as in always, use FOREIGN KEY constraints). Obviously, inserting a new row into a table to which other tables may relate, but is not being related to by those tables, there should exist no relation upon insertion. Given this constraint and NOT mucking about with choosing your own values to insert into an AI column, there will NEVER be any related rows anywhere else, and thus there is no need for locking any related tables.
WyCnet;11006981 wrote:
Using this concept there is no need to lock tables or records during updates, for a particular id.
Err, I really don't get what your after with this combination: "by locking associated tables there is no need to lock tables".
If you need to lock a table and lock it, then there will be no need to lock it since it's allready locked?
WyCnet;11006981 wrote:
There is a vast difference between relational databases and ISAM databases.
In the context of all this, mainly the use of foreign key constraints. And if you forgo the use of them you might as well not use InnoDB to begin with and stick with MyISAM. Sure, there are other differences, but if you do not ascertain a consistent database state to begin with, there is no point to use other thing that will keep it in a consistent state as far as they go, since the state either has a guarantee to be consistent or it doens't.