On several production Wikimedia wikis, we have rows in discussiontools_item_pages and discussiontools_item_revisions tables where itp_items_id, itr_itemid_id, or itr_items_id field is equal to 0. This should not be possible, as these fields are references to auto-increment fields that start at 1.
I ran into this today when examining this error: T315510#8937745 and noticing that the existing row on dewiki causing the duplicate key error had itr_items_id=0:
select * from discussiontools_item_revisions where itr_itemid_id=3134897 and itr_revision_id=209812431;
itr_id | itr_itemid_id | itr_revision_id | itr_items_id | itr_parent_id | itr_transcludedfrom | itr_level | itr_headinglevel |
---|---|---|---|---|---|---|---|
3700243 | 3134897 | 209812431 | 0 | NULL | NULL | 0 | 2 |
On large wikis there are a few thousands of affected rows.
select count(*) from discussiontools_item_pages where itp_items_id=0; select count(*) from discussiontools_item_revisions where itr_itemid_id=0 or itr_items_id=0;
Unfortunately some of the faulty entries are recent, so they're probably still being inserted. Once we discover what is causing this (probably something related to T323079 / T323080), we'll need to fix the existing rows. The maintenance script persistRevisionThreadItems.php can probably be adapted to this task (just delete everything for the affected revisions and re-process them).