Skip to content

Commit 4935083

Browse files
authored
Fix PostgreSQL cleanup query that never deletes orphan mesh rows (Ylianst#7798)
The cleanup pass on PostgreSQL is supposed to garbage-collect rows whose `extra` references a mesh ID that no longer exists in the current `meshlist` (matching the MongoDB branch a few lines down). As written: DELETE FROM Main WHERE ((extra != NULL) AND (extra LIKE ('mesh/%')) AND (extra != ANY ($1))) Two interlocking bugs: 1. `extra != NULL` is invalid SQL. In three-valued logic, `<expr> != NULL` evaluates to NULL, which the WHERE clause treats as falsy. The AND chain is therefore always NULL/falsy and zero rows are ever deleted. PostgreSQL's `transform_null_equals` setting only affects `=`, not `<>`/`!=`, and is off by default. Result today: cleanup silently no-ops on Postgres and orphan mesh-extra rows accumulate forever. 2. `<> ANY (array)` is *not* "not in the list" semantics. It returns TRUE when at least one array element is not equal to the value -- which is true for almost every input as soon as `meshlist` has 2+ distinct elements. Naively fixing only bug #1 (e.g., to `extra IS NOT NULL`) would mass-delete every row matching `extra LIKE 'mesh/%'`, including rows whose mesh is in the current list. The correct form is `<> ALL (array)`. This patch replaces both with the minimal correct query: DELETE FROM main WHERE extra LIKE 'mesh/%' AND extra <> ALL ($1) The redundant `extra != NULL` predicate is dropped because `extra LIKE 'mesh/%'` already filters out NULLs. The `<> ALL` form matches the intent of the parallel MongoDB query (`{ meshid: { $exists: true, $nin: meshlist } }`). `Main` -> `main` is cosmetic (PostgreSQL folds unquoted identifiers to lowercase), included only to match the actual `CREATE TABLE main` schema at db.js:1407 and other queries throughout the file. Note: the MariaDB/MySQL branch on the next line is also broken (mismatched parens; query throws on every call). That is a separate fix.
1 parent a4d3230 commit 4935083

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

db.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ module.exports.CreateDB = function (parent, func) {
454454

455455
} else if (obj.databaseType == DB_POSTGRESQL) {
456456
// Postgres
457-
sqlDbQuery('DELETE FROM Main WHERE ((extra != NULL) AND (extra LIKE (\'mesh/%\')) AND (extra != ANY ($1)))', [meshlist], function (err, response) { });
457+
sqlDbQuery('DELETE FROM main WHERE extra LIKE \'mesh/%\' AND extra <> ALL ($1)', [meshlist], function (err, response) { });
458458
} else if ((obj.databaseType == DB_MARIADB) || (obj.databaseType == DB_MYSQL)) {
459459
// MariaDB
460460
sqlDbQuery('DELETE FROM Main WHERE (extra LIKE ("mesh/%") AND (extra NOT IN ?)', [meshlist], function (err, response) { });

0 commit comments

Comments
 (0)