Of course it makes a difference, one thing is one thing, another thing is something else.
Know that from the internal point of view Postgresql already creates a new line and creates another whenever it will make one UPDATE
, because he works with a technique called MVCC (Multi Version Concurrency Control), which is simple to maintain isolation and consistency in transactions. So the performance is supposed to be essentially the same. Sure, there may be a few small details that can interfere a little, but as are implementation details I wouldn’t count that much.
If everything is done in a transaction, semantically it is to be the same thing if it is in serialized mode. If you are not in transaction or are in another mode you may have a greater chance of improper access to data that is not yet complete if you do the DELETE
and INSERT
.
If deleting and creating the primary key will be the same or new? This is important because it has a different semantics. If you are to keep the same, what is the advantage to your problem of deleting and creating another line?
If it makes any difference to your problem I would go from UPDATE
. But your problem may require you to create a new line and delete it. If you don’t mind, make it simple.
If you’re going to do something different, should you justify the choice, can you justify erasure and creation? If it is very important to decide for one or the other there it is better that the decision is supported by a very thorough study and better analysis of the concrete case.
One thing I see people doing a lot of wrong is erasing or altering a data when the problem asks them not to do it. There are situations that you should never have data loss, so it should only exist INSERT
na(s) table(s). I’m just saying this as curiosity, does not seem to be the case (I hope).
Look, I don’t know in detail how the
postgresql
works, but in thesql-server
, delete and include is faster, however, the LOG file gets full as the deleted lines will end up there, except if using thetruncate table
, but both solutions require receriar all indices, and this in both banks, this is a point of attention, both performance and processing, especially IO– Ricardo Pontual
It seems that your artificial key is not useful for anything since, as you say, keep the same value (in the case of UPDATE) or modify it (in the case of TRUNCATE/INSERT) does not bring any consequences to your data.
– anonimo