I don't know mysql/mariaDB that well, but I know in ms sql server that doing a DISTINCT on a Function([Column]) would not use an index on [Column].
In this case it would be much faster to have an intermediate table or column with that statistic that could then be properly indexed.