When you set up completion criteria in a course, there's an option for 'Completion of other courses'.
If you set up a Course A so that its completion is dependent on the completion of Course B, then subsequently delete Course B, the record is not deleted from mdl_course_completion_criteria. If you look in the database, you'll find a record with Course A in the course column, 8 in the criteriatype column, and Course B's ID in the courseinstance column.
This makes it impossible to open the Course Completion Report - it fails with "Cannot find record in database table course".
If you subsequently unlock the course completion criteria on Course A, leave the completion of other courses section empty, then save the criteria, it inserts another record into mdl_course_completion_criteria. This record has Course A's ID in the course column, 8 in the criteriatype column, and NULL in the courseinstance column.
This results in two erroneous records for Course A in the table: one with a course ID for a course that no longer exists, and one with NULL for the course.
As far as I can tell, there's no way to fix this from Moodle's UI. The only solution is to delete these records from the database manually. But doing this leaves course completion broken for the course, and using Moodle's UI to unlock the completion criteria for Course A, then save it without making changes, results in another (courseid, 8, NULL) record being inserted into mdl_course_completion_criteria.