As outlined in the comments of T270249, the maintenance script to remove deleted items from the term store (which was introduced in T270247) is not useful in its current form. It should be changed so it receives a set of item IDs (not term IDs), checks that they really don’t exist, collects their term IDs, deletes the wbt_item_terms rows, and then cleans those term IDs (like the current version of the script does). See the second half of T270249#6830469 for a rough sketch.
|Resolved||Addshore||T263730 Wikidata term store contains rows for deleted items|
|Resolved||Lucas_Werkmeister_WMDE||T274890 Make RemoveDeletedItemsFromTermStore.php maintenance script remove wbt_item_terms rows|