MyBB Community Forums

Full Version: [Solved] SQL Replace request ?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello guys,

I was looking the inc/functions_indicators.php file and the function mark_thread_read()

I am suddenly stonned about what I see : a replace sql query... O_o

Why does not Mybb simply use an UPDATE query ? Instead of this replace query which is largely more heavy than a simple update ?
If it is a problem, nothing'll get done about it now, 1.2 is old and will be unsupported soon.
I found this in MyBB 1.4.4 ...

EDIT :
OOps, sorry I used the bad forum Smile

Can someone move the thread ?

EDIT2 : Thanks to the person who moved the thread...
UP Smile ?
Actually, in some cases, REPLACE is more efficient than UPDATE.

REPLACE is perfect for low-level, small, replacements as it is just a write query (it won't read from the database, just writes data to it), whereas UPDATE will read and write. It can also be used to replace multiple values quicker too (just like INSERT).

So when compared to a "simple" UPDATE, it's sometimes better to just simply ignore what's in the database and overwrite it using REPLACE.

At least, that's my understand of it...
I really can't see the reasoning behind a replace query really using any more resources than an update query. Both require finding the row which matches the index, and thus should largely use the same amount of resources.

As for why it's used, there's no guarantee the entry already exists in the table, so we need to account for the possibility. On the other hand, if the entry is there, we need to ensure the dateline is updated.

Hope that answers your question.
(2009-01-24, 11:24 AM)Yumi Wrote: [ -> ]I really can't see the reasoning behind a replace query really using any more resources than an update query. Both require finding the row which matches the index, and thus should largely use the same amount of resources.

As for why it's used, there's no guarantee the entry already exists in the table, so we need to account for the possibility. On the other hand, if the entry is there, we need to ensure the dateline is updated.

Hope that answers your question.

Yes, it does.

Thanks for your answer, I did'nt think at the case the entry is not existing Smile