There appears to be a problem with the results returned from a query when DISTINCT, LEFT JOIN and a subquery which contains a constant value are combined.
I've boiled down the problem into a simple example of how it fails:
If you create a table called "realtable" with columns int "id" and string "data", insert two records (1, "yes") and (2, "yes") and run the query then you'll get:
which is incorrect. The value "yes" should be returned in the recordexists column. Obviously the "virtual" records are being joined correctly to the "real" records, because the virtualid returns the correct value, but the constant "yes" is missing. If you remove DISTINCT, change LEFT JOIN to just JOIN, or change "yes" to realtable.data then you get the correct results:
I also confirmed that this is NOT caused by using the same table in both the main and sub queries.
I've got a query structured like this which is working in Postgress and MySQL, and when delivered to a client who tried it in MariaDB it started failing. This could probably be considered a data loss bug.