CREATE INDEX ix1 ON history(instanceRef ) WHERE type = "history";
CRETE INDEX ix2 ON cms(id) WHERE ARRAY_LENGTH(history) > 0 ;
SELECT d.id, historyid
FROM (SELECT c.id, c.history
FROM cms AS c
LEFT JOIN history AS h ON c.id == h.instanceRef AND h.type = "history"
WHERE c.id IS NOT NULL AND ARRAY_LENGTH(c.history) > 0 AND h IS MISSING ) AS d
UNNEST d.history AS historyid;
It is LEFT JOIN. When c.id == h.instanceRef AND h.type = “history” condition is not satisfied it will produce h as MISSING.
That is your requirement “I need to find cms ids that are not in history”