- Code: Select all
SELECT `prices`.* FROM `prices` LEFT JOIN `prices` `p2` ON p2.commodity_guid=prices.commodity_guid
and year(p2.date)=year(prices.date)
and month(p2.date)=month(prices.date)
and prices.date<p2.date;
The [InnoDB] table definition is:
- Code: Select all
show columns in prices;
+----------------+---------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+---------------+------+-----+---------------------+-------+
| guid | varchar(32) | NO | PRI | NULL | |
| commodity_guid | varchar(32) | NO | | NULL | |
| currency_guid | varchar(32) | NO | | NULL | |
| date | datetime | NO | | 1970-01-01 00:00:00 | |
| source | varchar(2048) | YES | | NULL | |
| type | varchar(2048) | YES | | NULL | |
| value_num | bigint(20) | NO | | NULL | |
| value_denom | bigint(20) | NO | | NULL | |
+----------------+---------------+------+-----+---------------------+-------+
There are about 10,000 rows and no indexes (database not under my control).
The query runs fine on my development machine, which uses MySQL (v8.0) but very slowly on the target platform (MariaDB 10.1). I have now installed MariaDB (10.1 and 10.6) alongside MySQL on my development machine and I am seeing the same difference: the query takes 16 seconds in MariaDB but only 0.4 seconds in MySQL (both with default settings, as far as I am aware).
I'm no database expert and I have no idea what is likely to be causing such a huge difference in performance. Can anyone suggest how I could find and fix whatever is causing the bottleneck?