MySQL Forums
Forum List  »  Connector/Python

Re: Slow query performance
Posted by: Shawn Green
Date: May 28, 2024 10:56AM

Clearly you are searching on some combination of values to see if a row already exists. This combination (what defines a unique row) for you should be either be the columns in a UNIQUE() key or the PRIMARY KEY for that table.

Another option is to build a numeric hash of a string composed of that combination of values then search for that number in an index. Lots of applications use the MD5() function for this but longer and shorter on-demand hash values are available if you review the documentation.

Then, if you do choose to use the PK or UNIQUE path, you gain the option of using the alternative command INSERT...ON DUPLICATE KEY UPDATE... to skip trips to the server. It would contain both paths of your attempt (it creates a new row if one does not already exist, or modifies the existing row if one did exist)
https://dev.mysql.com/doc/refman/8.4/en/insert-on-duplicate.html

Options: ReplyQuote


Subject
Written By
Posted
Re: Slow query performance
May 28, 2024 10:56AM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.