HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Keep ROW = NULL or DELETE it?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
nullkeeprowdelete

Problem

in this scheme

id  uid     content
1   1       A
2   1       B
3   1       C
4   1       D
5   1       E


If the User decided that he doesn't need the rows with id = 3, 4, 5 Is it better to make him set their content to NULL or just delete the row?

This process occur many time And he maybe use the NULL slots again. Do I still use UPDATE and set it to NULL in case he will change it in the future? Or just DELETE the entire row?

The question is like: is it better to

DELETE the Row? INSERT| -> DELETE -> INSERT .. DELETE -> INSERT

or

UPDATE the Row? INSERT| -> UPDATE to NULL -> UPDATE to value .. UPDATE to NULL -> UPDATE to value

Solution

If the rows will be re-used frequently, it is likely better to set the values to NULL, or simply add a column is_deleted to indicate that the row has been soft-deleted. Continuously deleting and inserting rows can lead to a heavily fragmented table, and can be a cause of performance degradation. This is typically used for queues where there are a known number of slots (rows) in the queue, and those slots are allocated ahead of time.

If the rows will not be re-used, or will be re-used very infrequently, then it's better to deallocate the space used by those rows.

Context

StackExchange Database Administrators Q#199226, answer score: 6

Revisions (0)

No revisions yet.