I hadn't noticed this before, but due to other issues I've been tracking, I've had to closely examine the sugar log files recently and came across an interesting item.

I noticed that when one performs a save (e.g. contacts), Sugar will attempt to execute 2 queries for the _cstm table and the main module table as well if not mistaken.

The first query is an UPDATE WHERE ID = 'ID of record that was just updated' and the second query is an INSERT INTO, with the same ID value.

This seems rather wasteful and I can see where it could cause a number of performance issues if one had many custom fields.

Just my opinion, but it would seem like a better approach would be to set some flag such as edit=1 or something when one chooses to edit a contact, that way when one clicks Save, one already knows it is an update vs. an insert and execute only one query.

At the very least, it could be changed so as to check the presence of that ID in the destination table in order to determine if an update or insert is required. For example select count(id_c) from contacts where id = 'my_id'

Am I missing something obvious that explains why it behaves this way in the first place?