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,

Your logic is quite chaotic,

CodePudding user response:

reference 1st floor morliz son hin reply:
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,

Your logic is very chaotic,


I'm sorry may be I I didn't express clearly,
Is actually a warehouse daily report, today check out how many, how much, how many, abandoned, and not for a single SKU,
In addition to date, warehouse and other fields are of type int, initial fields are 0, is like checked out at the field + 1, + 1 to enter, there is other and so on operation is + 1,

Such as today appeared a data

Id date warehouse num1 num2 num3
1 the warehouse 2020-04-18 a 10 15 0
1 the warehouse 2020-04-19 a 10 15 0
1 the warehouse 2020-04-20 a 10 15 0

Similar to the warehouse daily report, it is (date) | warehouse as a dimension to ensure only, other fields are update in..




CodePudding user response:

Now I think of another solution is that today's date is 2020-04-20, I'll insert a tomorrow in today's date the 2020-04-21 | 1 warehouse records, other fields by default to 0...
But the initial data today, or there will be a concurrent ah...

CodePudding user response:

I didn't understand what is your final demand,

Said after a while, just change the number of the three, is the update happens,
For a while and said, "this number three, a record in every (date),

Since you are so designed that if the business happens, at the same time more when there is a check-in or check-out pen, that is to say for num1 or num2 happen many times the update at the same time, it must fight,

This design can not fight?

CodePudding user response:

reference 4 floor morliz son hin reply:
I didn't understand what is your final demand,

Said after a while, just change the number of the three, is the update happens,
For a while and said, "this number three, a record in every (date),

Since you are so designed that if the business happens, at the same time more when there is a check-in or check-out pen, that is to say for num1 or num2 happen many times the update at the same time, it must fight,

This design can not fight?


Final demand is actually a simple warehouse daily report,
Such as the 2020-04-20 on this day, warehouse today check out how much, signed, so-and-so operation how many, how many
Then check-in, check-out, or add a piece of code in the other operating interface,
Every time + 1 on the field, the update table set num1=num1 + 1='a warehouse where warehouse and date=' 2020-04-20 ';

Is as of the date of the judgment day + warehouse only the daily data have to be, have and then insert a today, and the corresponding operation + 1, did not update the other fields.






CodePudding user response:

Put the actual business data, and at the same time to the result set pattern, draw a,
So you know how to implement,

Concept is basically understand

CodePudding user response:

Occurred to one of the most simple solution:
In the create this table, use SQL statements into a first release date, such as
1 a warehouse 2020-04-20 0 0 0

Then perform a daily (can use the automatic task), insert a record date for the next day
Such as today's date for the 2020-04-20, I today just insert a record tomorrow (2020-04-21) :
10 warehouse 2020-04-21 0 0 0

So tomorrow (i.e., the 2020-04-20 a day), check out the operation, test first:
Select * from table where warehouse='a warehouse and the date=' 2020-04-21 '
In fact this article data were built, the day before

Even more than one transaction, also is to have the data detected

So it is good to update other fields directly

CodePudding user response:

refer to 6th floor morliz son hin reply:
put the actual business data, and at the same time to the result set pattern, draw a,
So you know how to implement,

Concept is basically understand


Well, it is a concurrent causes:
Such as the three transaction are:
Select * from table where warehouse='a warehouse and this a record date=' 2020-04-20 'as a result,

Results three transactions are detected result is 0,
So the insert a:
Id date warehouse num1 num2 num3
The 2020-04-20 warehouse a 0 0 0 1
The 2020-04-20 warehouse a 0 0 0 1
The 2020-04-20 warehouse a 0 0 0 1


Finally, will lead to date are on the same day that generated the 3 records, the actual daily need only a record,

And you look at my last a solution that how, ha, ha, ha





CodePudding user response:

I won't be free to discuss with you in the discussion, and you think feasible, yourself,
Not the actual data, I can't help you,
  • Related