Software / code / prosody
Comparison
plugins/mod_storage_sql.lua @ 13836:c600794cafb6 13.0
mod_storage_sql: Handle failure to deploy new UNIQUE index
Somehow a user ended up with duplicate data preventing creation of the
new unique index needed for UPSERT (see 3ec48555b773).
This should eventually self-heal #1918 if the duplicate data is replaced
by the older DELETE + INSERT method.
Without any index at all, it will be slower.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 09 Apr 2025 18:27:42 +0200 |
| parent | 13833:497efa2cbf2c |
| child | 13838:a93e7310bfcd |
comparison
equal
deleted
inserted
replaced
| 13835:a4b58ea5bf7b | 13836:c600794cafb6 |
|---|---|
| 44 | 44 |
| 45 -- COMPAT Support for UPSERT is not in all versions of all compatible databases. | 45 -- COMPAT Support for UPSERT is not in all versions of all compatible databases. |
| 46 local function has_upsert(engine) | 46 local function has_upsert(engine) |
| 47 if engine.params.driver == "SQLite3" then | 47 if engine.params.driver == "SQLite3" then |
| 48 -- SQLite3 >= 3.24.0 | 48 -- SQLite3 >= 3.24.0 |
| 49 return engine.sqlite_version and (engine.sqlite_version[2] or 0) >= 24; | 49 return engine.sqlite_version and (engine.sqlite_version[2] or 0) >= 24 and engine.has_upsert_index; |
| 50 elseif engine.params.driver == "PostgreSQL" then | 50 elseif engine.params.driver == "PostgreSQL" then |
| 51 -- PostgreSQL >= 9.5 | 51 -- PostgreSQL >= 9.5 |
| 52 -- Versions without support have long since reached end of life. | 52 -- Versions without support have long since reached end of life. |
| 53 return true; | 53 return engine.has_upsert_index; |
| 54 end | 54 end |
| 55 -- We don't support UPSERT on MySQL/MariaDB, they seem to have a completely different syntax, uncertaint from which versions. | 55 -- We don't support UPSERT on MySQL/MariaDB, they seem to have a completely different syntax, uncertaint from which versions. |
| 56 return false | 56 return false |
| 57 end | 57 end |
| 58 | 58 |
| 896 module:log("error", "Failed to delete obsolete index \"prosody_index\""); | 896 module:log("error", "Failed to delete obsolete index \"prosody_index\""); |
| 897 return false; | 897 return false; |
| 898 end | 898 end |
| 899 end | 899 end |
| 900 if not indices["prosody_unique_index"] then | 900 if not indices["prosody_unique_index"] then |
| 901 module:log("error", "New index \"prosody_unique_index\" does not exist!"); | 901 module:log("warn", "Index \"prosody_unique_index\" does not exist, performance may be worse than normal!"); |
| 902 return false; | 902 engine.has_upsert_index = false; |
| 903 else | |
| 904 engine.has_upsert_index = true; | |
| 903 end | 905 end |
| 904 end | 906 end |
| 905 return changes; | 907 return changes; |
| 906 end | 908 end |
| 907 | 909 |