I have a DB table in which each row has a randomly generated primary key, a message and a user. Each user has about 10-100 messages but there are 10k-50k users.
I write the messages daily for each user in one go. I want to throw away the old messages for each user before writing the new ones to keep the table as small as possible.
Right now I effectively do this:
delete from table where user='mk'
then write all the messages for that user.
I'm seeing a lot of contention because I have lots of threads doing this at the same time.
Can anyone offer any advice?
Would it be better to:
select key from table where user='mk'
then delete individual rows from there? I'm thinking that might lead to less brutal locking.
I'm using Oracle BTW.
Thanks!
EDIT
Thanks for all the answers!
I was unclear in my question. As APC says, I do have an additional requirement to retain the most recent set of messages for each user.
I don't have access to the DB directly. I'm trying to guess at the problem based on some second hand feedback. The reason I'm focusing on this scenario is that the delete query is showing a lot of wait time (again - to the best of my knowledge) plus it's a newly added bit of functionality.
Your answers have already been helpful - thanks!