last day (14 days later) » 

3:51 AM
0
A: Second auto incrementing row in MySql

SchwernAssuming that the desire is to know what order to do the tasks in, and not believing for one minute that no rows will be deleted, here's an alternative schema that needs no triggers. create table tenant_tasks( ID integer primary key auto_increment, Tenant_ID integer refere...

 
This is not using a safe Intention Lock and therefore it should not be used.
 
@Drew What is an intention lock and why is it needed here?
 
An intention lock is like this crafted in various fashions to eliminate, entirely, risk.
 
@Drew I don't understand how it applies here. Is this some generic problem with InnoDB and auto_increment, or specific to this problem?
 
Ultimately what one tries to do is force it into a baton holder. So only one user can perform an operation in a split second tight code chunk and to prevent what you said as "There's a small chance two processes will ..." ... so you strive to have all systems endure being pounded on by multitudes at once.
 
3:51 AM
@Drew It probably doesn't matter if two rows happen to have the same created_at, and you can force a deterministic order by mixing in id (ie. order by created_at,id). The OP will have to decide whether it's a problem, I don't know what they're using task_id for.
@Drew So you were saying in the post comments that the task_id is unnecessary, could you elaborate?
 
I am working on a safe snippet you can embed in your answer if you want
 
What's your idea of what this is being used for? A lot depends on that.
 
well based on the question there is no question-side support for why he needs anything other than the auto_inc and the tenant# columns.
That said, assuming he must have it, like he has a gun to his head, I am forgetting my complaint and just moving with it
 
4:07 AM
So you're assuming the id will always increment?
 
I know there are some regulatory environments that mandate certain ordering inside of groups
 
If we make that assumption, then yeah, id + tenant_id is sufficient.
I don't like to make that assumption because I've seen what happens when you do. :)
Although it could be argued if you run out of ids you have much bigger problems.
 
That is why I posted the close vote in the socvr chat room when I saw the question
Because otherwise we are like senior peers supporting a bad idea
 
I'd recommend answering with why it's an XY problem and suggest id + tenant_id.
I do that all the time. It's educational for the OP.
Then if there's any flaws in your assumptions about the question and their situation they can be discussed in comments on your answer.
 
Just give me about 15 minutes or so and I should have this thing done. Just finishing watching the amer football game while I do it
 
4:13 AM
No worries.
 
4:52 AM
 

last day (14 days later) »