Commit 4935083
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
454 | 454 | | |
455 | 455 | | |
456 | 456 | | |
457 | | - | |
| 457 | + | |
458 | 458 | | |
459 | 459 | | |
460 | 460 | | |
| |||
0 commit comments