Home > database > Concurrent problems about mysql insert and update, please the great god answer reasonable solution.
Concurrent problems about mysql insert and update, please the great god answer reasonable solution.
Time:09-16
Scenario is probably now: find a record, there have been inserted, have and then update,
Warehouse has a report, field has (id count abandoned warehouse date sign on check in real... ), and so on,
Warehouse, date is the only association, every day can only appear a record, Generated a record, then the other checkout, check-in, abandoned operation, such as the field + 1, But check out the daily, check-in, abandoned, and so on have a lot of operation, and even other interface constantly push, Probably the same seconds this the data, there are many a
Warehouse, for example, a 2020-04-20, 1080, 2267, 1117
Have checked out at this time, check-in, abandoned operation, such as Three transactions have to be in this sentence: SELECT * FROM table WHERE the date='2020-04-20'='a warehouse and warehouse;
Are detected no data, each insert one, at this time will be on the same day, the same article three data warehouse,
Now I think of the solution is: add the only index to | date (warehouse), transaction 2, 3 go to insert here, and then insert failure,
But if a checkout to go long transactions, and finally as a statistical failure, cause the failure of checkout, not very reasonable,
What better solution? O great god answer
CodePudding user response:
In a data transaction, embarks from the actual business background, ask a few more why?
Such as: why is checked out, signing, abandoned? In and out, is the data transaction into the storehouse, out of the storehouse, that there is nothing to doubt, But abandoned is what meaning, material disposal?
That there are two premises, premise 1: there is inventory, waste is produced, Premise 2: in the event of a particular material [signing] or [checkout], [abandoned] whether to allow,