#3780 - Support upsert on non-MySQL backends (Make use of MySQL REPLACE INTO syntax)
| Identifier | #3780 |
|---|---|
| Issue type | Feature request or suggestion |
| Title | Support upsert on non-MySQL backends (Make use of MySQL REPLACE INTO syntax) |
| Status | Open |
| Tags |
Type: Performance (custom) |
| Handling member | Deleted |
| Addon | core_database_drivers |
| Description | put_into_cache and set_value are both highly trafficed functions that do a query_delete (DELETE FROM) followed by a query_insert (INSERT INTO). These cases could be single REPLACE INTO calls in MySQL.
The ideal solution would be to extend the insert_into method to change $fail_ok to take constants QUERY_FAIL_HARD, QUERY_FAIL_SILENT, and QUERY_REPLACE_INTO. Then each database driver could do it's own implementation. Almost every database backend has some kind of syntax for it https://en.wikipedia.org/wiki/Merge_(SQL) However, a quick and dirty detection of whether MySQL is running, and coding in an alternative query, would be fine. |
| Steps to reproduce | |
| Funded? | No |
The system will post a comment when this issue is modified (e.g., status changes). To be notified of this, click "Enable comment notifications".


Comments
These functions in v9 are worth looking at (initially implementing this as a sponsorship for a customer)...
get_num_users_site
render_field_value url.php
put_into_cache
do_comcode_attachments
_do_tags_comcode
ocf_ping_topic_read
edit_ping_script
find_theme_image
check_url_exists
_update_read_status
member_tracking_update
set_tutorial_link
Note that most DBs that implement a merge feature do not do it as simply as MySQL. For us to support those we'd either need to pass in the key fields with each REPLACE query, or we'd need to read them from the DB - complexity that I think is not worth it.
Therefore I think a better implementation is to make a new query_insert_or_replace database method, and if this returns false, do the current method of delete then insert with error ignoring. Messy, but we're only targeting changes to a few critical highly trafficked cases here.
The syntax is lot cleaner on MySQL.