Your issue seems like a MySQL bug. I was reviewing the logs for our production server the other day and the error logs were filled with this error. I used the workaround below and the errors are gone.
SET SESSION max_heap_table_size=536870912;
SET SESSION tmp_table_size=536870912;