Review
v2: vacuumlo: Find OID references inside domains, composites, and arrays
- Proposal version
- 2
- Base commit
- 412848dac37f2e4455e1505f83f0af0f3d28a67d
Applied both v2 patches with git am. They applied cleanly. vacuumlo.c compiled cleanly as one translation unit. The Commitfest page shows the latest cfbot run green. The TAP test was not executed here.
vacuumlo() still fills vacuum_l from pg_largeobject_metadata, then deletes rows whose lo value it thinks is referenced. On server version 14 and above, that discovery is one recursive query over pg_class, pg_attribute, pg_namespace, and pg_type. It keeps relkind r and m (ordinary tables and matviews) in schemas that do not match ^pg_, so real partitions are scanned and the partitioned parent, foreign tables, and views are not. The same filter still skips pg_catalog, pg_toast, and the vacuum_l temp table. For each remaining column the query peels domains (pg_type.typtype d via typbasetype), turns a varlena type with a non-zero typelem into unnest(expr), and walks composite attributes (typtype c, typrelid not zero) as (expr).attname. Names are passed through quote_ident(). A result row is emitted when the walked type is 26 (OIDOID) or when pg_type.typname is lo, in any schema. Servers older than 14 keep the previous scan of typname in ('oid', 'lo'). Each check is DELETE FROM vacuum_l WHERE lo IN (SELECT expr FROM schema.table). Those statements run before BEGIN. If one fails, vacuumlo() returns -1 and never reaches the lo_unlink loop.
That walker does find large-object OIDs stored through domains, arrays, and composites, and the expressions it builds return those OIDs rather than dropping them. Checked shapes included a domain over oid whose name is not lo, a domain over that domain, a domain over oid[], a domain over a composite, a composite field of such a domain, nested composites, oid[] and lo[] (lo is itself a domain over oid), a multidimensional oid[] via one unnest(), an array of composites, and unnest((unnest(h)).arr) for an array of composites of oid[]. Also checked: a dropped composite attribute (only the live field is emitted), a quoted schema and column, a partition (the partition is visited, not the parent), a matview, and null array elements beside a real OID. With search_path emptied the way vacuumlo() does, unnest still resolved. None of these referenced OIDs were missing from the result, so they would not be removed. CheckAttributeType rejects a composite that contains itself, including through an array or a domain over that array, and it rejects mutual recursion, so the CTE is not unbounded on a catalog PostgreSQL will accept.
Ranges are a real miss, not a false hit. oidrange and its multirange have typlen -1, typelem 0, and typtype r and m. DefineRange does not set typelem, so the unnest arm does not treat them as arrays, and the query never reads pg_range.rngsubtype. An OID that exists only as an inclusive bound, oidrange(o, o, '[]'), the same bound inside oidmultirange, or that range stored in a composite field, produces no expression. vacuumlo() would still delete those large objects. Text and bigint references are also invisible; the new caution says so. Range and multirange bounds are the same kind of hole and are not named.
The extra typname = 'lo' test is not needed for the lo extension. That type is a domain over oid, and the peel to 26 already emits the same expression, which is why lo columns show up twice. The name test also matches every other type named lo. A domain over text named lo, including a composite field of that domain, makes the check fail with operator does not exist: oid = s.lo. vacuumlo() then returns -1 and unlinks nothing. A domain over int4 or int8 does compare with oid, so those integers are kept as if they were large-object OIDs (extra retention, not extra deletion). Matching only OID 26 after the peel would keep the extension type and ignore unrelated types named lo. oidvector is selected too: it is varlena and its typelem is oid, and unnest(oidvector) succeeds, so its elements are retained. int2vector is not selected, because the element type is not oid.
002_orphan_remove.pl is a real improvement over the old help-only test. It keeps plain oid, lo, composites of lo, a nested composite, oid[], lo[], and an array of composites, and it checks that five orphans disappear. It never creates a domain that is not named lo, so a break of only the typbasetype peel would still pass through the typname = 'lo' arm. That is the case the bug report is about. The script also runs CREATE EXTENSION lo, but contrib/vacuumlo/Makefile does not set EXTRA_INSTALL to contrib/lo. A standalone make check installs only this module into tmp_install, so the extension statement fails. check-world runs checkprep across contrib and therefore installs lo, and the meson test install includes it, which is consistent with a green cfbot run. The Description in vacuumlo.sgml still says an orphan is an OID that appears in no oid or lo column. Only the Notes section mentions domains, composites, and arrays. The caution belongs there; the definition above it is now wrong.
Assessment 68, nearest anchor 70. The walk in vacuumlo() is right for domains, arrays, and composites, and a failed check still cannot unlink, but the new test does not lock in a domain that is not named lo, standalone make check cannot build that test, and range or multirange bounds are still deleted. Consensus 70. The thread pins down the data loss bug, agrees that domains need a recursive catalog walk, and Nathan accepts exploring composites and arrays together with a data loss caution and a nudge toward the lo extension. No message after the v2 series reviews the query.