I was encountering a situation where big aggregating queries that took seconds on local were taking minutes or even hours on prod. After trying about a million things this Stack Exchange post finally cleared things up.
Setting innodb_buffer_pool_size = 5G
in MariaDB’s configuration and restarting instantly changed the queries to taking seconds. The default is 128M which is … not useful 🙂