We have a query that looks for duplicates in one of our tables, based on a rare identifier, let it be called rareIdentifier INT(10) UNSIGNED NULL . We have one column of the regular old index in this column.
The corresponding request is as follows:
SELECT a.id, b.id FROM widget a INNER JOIN widget b ON a.rareIdentifier = b.rareIdentifier;
The problem is that for the recent start of the duplicate search, we actually had rows 0 with a value for rareIdentifier ; those. all rows had NULL for this column. MariaDB decided not to use the index by choosing the Using join buffer (flat, BNL join) approach, which scanned the entire table.
But NULL cannot equal each other! So why is he trying to compare each pair of lines?
I understand that MySQL / MariaDB will not use an index if its selectivity is too low. I think so. In fact, it seems that only 1 value in the index means that the request is pretty much instantaneous.
The table is an InnoDB table.
source share