I identified an issue which happens on MariaDb because a query is very very slow compared to the same query executed on the same database schema / data /engine (innodb) in Mysql. I give you the figures to show the difference for this query.
SELECT SQL_NO_CACHE t0_.ID_TICKETS AS ID_TICKETS_0, t0_.MSISDN AS MSISDN_1, t0_.IMMAT AS IMMAT_2, t0_.OPERATEUR AS OPERATEUR_3, t0_.DHDEBUT AS DHDEBUT_4, t0_.DHMAX AS DHMAX_5, t0_.DHFIN AS DHFIN_6, t0_.PRIX AS PRIX_7, t0_.TYPE_APPEL AS TYPE_APPEL_8, t0_.PAYS AS PAYS_9, t1_.ID AS ID_10, t1_.DHTRANS AS DHTRANS_11, t1_.MONTANT AS MONTANT_12, t0_.ID_CITOYENS AS ID_CITOYENS_13, t0_.ID_ZONES AS ID_ZONES_14, t0_.STATUT AS STATUT_15, t0_.ID_TRANSACTIONS AS ID_TRANSACTIONS_16, t1_.ID_CITOYENS AS ID_CITOYENS_17, t1_.STATUT AS STATUT_18, t1_.locality_id AS locality_id_19
|
FROM TICKETS t0_ LEFT JOIN TRANSACTIONS t1_ ON t0_.ID_TRANSACTIONS = t1_.ID
|
INNER JOIN ZONES z2_ ON t0_.ID_ZONES = z2_.ID AND (z2_.ID_LOCALITE = 1)
|
ORDER BY t0_.DHDEBUT ASC LIMIT 10 OFFSET 0;
|
MariaDb | 10.1.28 => 12s
Mysql | 5.7.20 => 0.00s
desc TICKETS;
+-----------------+-------------+------+-----+---------+----------------+
|
| Field | Type | Null | Key | Default | Extra |
|
+-----------------+-------------+------+-----+---------+----------------+
|
| ID_TICKETS | int(11) | NO | PRI | NULL | auto_increment |
|
| ID_CITOYENS | int(11) | NO | MUL | NULL | |
|
| ID_ZONES | int(11) | NO | MUL | NULL | |
|
| MSISDN | varchar(20) | YES | MUL | NULL | |
|
| IMMAT | varchar(20) | YES | MUL | NULL | |
|
| OPERATEUR | int(11) | NO | | NULL | |
|
| DHDEBUT | datetime | NO | MUL | NULL | |
|
| DHMAX | datetime | NO | | NULL | |
|
| DHFIN | datetime | YES | | NULL | |
|
| PRIX | int(11) | NO | | NULL | |
|
| STATUT | int(11) | NO | MUL | NULL | |
|
| TYPE_APPEL | varchar(10) | NO | | NULL | |
|
| PAYS | varchar(3) | NO | | NULL | |
|
| ID_TRANSACTIONS | int(11) | YES | MUL | NULL | |
|
+-----------------+-------------+------+-----+---------+----------------+
|
EXPLAIN Query Mysql
+----+-------------+-------+------------+--------+------------------------------+---------+---------+-------------------------------+------+----------+-------------+
|
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
|
+----+-------------+-------+------------+--------+------------------------------+---------+---------+-------------------------------+------+----------+-------------+
|
| 1 | SIMPLE | t0_ | NULL | index | IDX_6B0363EEAAD06922 | DHDEBUT | 5 | NULL | 10 | 100.00 | NULL |
|
| 1 | SIMPLE | z2_ | NULL | eq_ref | PRIMARY,IDX_729E73D8AAFE1877 | PRIMARY | 4 | CALL2PARK.t0_.ID_ZONES | 1 | 100.00 | Using where |
|
| 1 | SIMPLE | t1_ | NULL | eq_ref | PRIMARY | PRIMARY | 4 | CALL2PARK.t0_.ID_TRANSACTIONS | 1 | 100.00 | NULL |
|
+----+-------------+-------+------------+--------+------------------------------+---------+---------+-------------------------------+------+----------+-------------+
|
EXPLAIN Query MariaDb
+----+-------------+-------+--------+--------------------------------+----------------------+---------+-------------------------------+-------+----------------------------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+----+-------------+-------+--------+--------------------------------+----------------------+---------+-------------------------------+-------+----------------------------------------------+
|
| 1 | SIMPLE | z2_ | ref | PRIMARY,IDX_729E73D8AAFE1877 | IDX_729E73D8AAFE1877 | 4 | const | 14 | Using index; Using temporary; Using filesort |
|
| 1 | SIMPLE | t0_ | ref | IDX_6B0363EEAAD06922 | IDX_6B0363EEAAD06922 | 4 | call2park.z2_.ID | 49471 | |
|
| 1 | SIMPLE | t1_ | eq_ref | PRIMARY | PRIMARY | 4 | call2park.t0_.ID_TRANSACTIONS | 1 | Using where |
|
+----+-------------+-------+--------+--------------------------------+---------------
|
If I remove some properties from the select in query it's a lot faster. It's very strange because I get only 10 rows.
SELECT SQL_NO_CACHE t0_.ID_TICKETS AS ID_TICKETS_0, t1_.ID AS ID_10
|
FROM TICKETS t0_ LEFT JOIN TRANSACTIONS t1_ ON t0_.ID_TRANSACTIONS = t1_.ID
|
INNER JOIN ZONES z2_ ON t0_.ID_ZONES = z2_.ID AND (z2_.ID_LOCALITE = 1) ORDER BY t0_.DHDEBUT ASC LIMIT 10 OFFSET 0;
|
MariaDb | 10.1.28 => 3s
If I keep all properties in select but remove the "order by" clause it takes less than 50ms.
{"report":{"fcp":939.8999996185303,"ttfb":301.69999980926514,"pageVisibility":"visible","entityId":64772,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"c35ee3bc-77b2-44be-80c4-70ae10897fee","navigationType":0,"readyForUser":1062.8000001907349,"redirectCount":0,"resourceLoadedEnd":1216.6999998092651,"resourceLoadedStart":340,"resourceTiming":[{"duration":50,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":340,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":340,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":390,"responseStart":0,"secureConnectionStart":0},{"duration":50.09999942779541,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":340.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":340.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":390.3999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":90.59999942779541,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":340.5,"connectEnd":340.5,"connectStart":340.5,"domainLookupEnd":340.5,"domainLookupStart":340.5,"fetchStart":340.5,"redirectEnd":0,"redirectStart":0,"requestStart":340.5,"responseEnd":431.0999994277954,"responseStart":431,"secureConnectionStart":340.5},{"duration":170,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":340.80000019073486,"connectEnd":340.80000019073486,"connectStart":340.80000019073486,"domainLookupEnd":340.80000019073486,"domainLookupStart":340.80000019073486,"fetchStart":340.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":340.80000019073486,"responseEnd":510.80000019073486,"responseStart":510.80000019073486,"secureConnectionStart":340.80000019073486},{"duration":173.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":340.8999996185303,"connectEnd":340.8999996185303,"connectStart":340.8999996185303,"domainLookupEnd":340.8999996185303,"domainLookupStart":340.8999996185303,"fetchStart":340.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":340.8999996185303,"responseEnd":514.6999998092651,"responseStart":514.6999998092651,"secureConnectionStart":340.8999996185303},{"duration":174.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":341.19999980926514,"connectEnd":341.19999980926514,"connectStart":341.19999980926514,"domainLookupEnd":341.19999980926514,"domainLookupStart":341.19999980926514,"fetchStart":341.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":341.19999980926514,"responseEnd":515.3999996185303,"responseStart":515.3999996185303,"secureConnectionStart":341.19999980926514},{"duration":174.39999961853027,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":341.5,"connectEnd":341.5,"connectStart":341.5,"domainLookupEnd":341.5,"domainLookupStart":341.5,"fetchStart":341.5,"redirectEnd":0,"redirectStart":0,"requestStart":341.5,"responseEnd":515.8999996185303,"responseStart":515.8999996185303,"secureConnectionStart":341.5},{"duration":234.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":341.5999994277954,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":341.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":576.0999994277954,"responseStart":0,"secureConnectionStart":0},{"duration":174.5,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":341.80000019073486,"connectEnd":341.80000019073486,"connectStart":341.80000019073486,"domainLookupEnd":341.80000019073486,"domainLookupStart":341.80000019073486,"fetchStart":341.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":341.80000019073486,"responseEnd":516.3000001907349,"responseStart":516.3000001907349,"secureConnectionStart":341.80000019073486},{"duration":234.30000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":341.8999996185303,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":341.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":576.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":174.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":342.0999994277954,"connectEnd":342.0999994277954,"connectStart":342.0999994277954,"domainLookupEnd":342.0999994277954,"domainLookupStart":342.0999994277954,"fetchStart":342.0999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":342.0999994277954,"responseEnd":516.8999996185303,"responseStart":516.8999996185303,"secureConnectionStart":342.0999994277954},{"duration":442.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":343.19999980926514,"connectEnd":343.19999980926514,"connectStart":343.19999980926514,"domainLookupEnd":343.19999980926514,"domainLookupStart":343.19999980926514,"fetchStart":343.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":343.19999980926514,"responseEnd":785.3999996185303,"responseStart":785.3999996185303,"secureConnectionStart":343.19999980926514},{"duration":843.8000001907349,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":343.19999980926514,"connectEnd":343.19999980926514,"connectStart":343.19999980926514,"domainLookupEnd":343.19999980926514,"domainLookupStart":343.19999980926514,"fetchStart":343.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":343.19999980926514,"responseEnd":1187,"responseStart":1186.8999996185303,"secureConnectionStart":343.19999980926514},{"duration":200.69999980926514,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":604.3000001907349,"connectEnd":604.3000001907349,"connectStart":604.3000001907349,"domainLookupEnd":604.3000001907349,"domainLookupStart":604.3000001907349,"fetchStart":604.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":604.3000001907349,"responseEnd":805,"responseStart":805,"secureConnectionStart":604.3000001907349},{"duration":344.69999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":867.8000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":867.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1212.5,"responseStart":0,"secureConnectionStart":0},{"duration":340.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":868.8000001907349,"connectEnd":868.8000001907349,"connectStart":868.8000001907349,"domainLookupEnd":868.8000001907349,"domainLookupStart":868.8000001907349,"fetchStart":868.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":868.8000001907349,"responseEnd":1209,"responseStart":1209,"secureConnectionStart":868.8000001907349},{"duration":347.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/097ae97cb8fbec7d6ea4bbb1f26955b9-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/js/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":869.1999998092651,"connectEnd":869.1999998092651,"connectStart":869.1999998092651,"domainLookupEnd":869.1999998092651,"domainLookupStart":869.1999998092651,"fetchStart":869.1999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":869.1999998092651,"responseEnd":1216.6999998092651,"responseStart":1216.6999998092651,"secureConnectionStart":869.1999998092651},{"duration":418.80000019073486,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":931.5999994277954,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":931.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1350.3999996185303,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":81,"responseStart":301,"responseEnd":316,"domLoading":335,"domInteractive":1275,"domContentLoadedEventStart":1275,"domContentLoadedEventEnd":1343,"domComplete":1955,"loadEventStart":1955,"loadEventEnd":1956,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1220.3000001907349},{"name":"bigPipe.sidebar-id.end","time":1221.3000001907349},{"name":"bigPipe.activity-panel-pipe-id.start","time":1221.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":1227.6999998092651},{"name":"activityTabFullyLoaded","time":1371.1999998092651}],"measures":[],"correlationId":"d70f64a7e9b2ff","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":146,"dbReadsTimeInMs":12,"dbConnsTimeInMs":21,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
--source include/have_sequence.inc
--source include/have_innodb.inc
LIMIT 10 ;
LIMIT 10 ;
analyze SELECT SQL_NO_CACHE t0.id_t0 , t1.id
FROM t0
LEFT JOIN t1 ON t0.id_t1 = t1.id
JOIN t2 ON t0.id_t2 = t2.id AND (t2.a1 = 1)
ORDER BY t0.d
LIMIT 10 ;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE t2 ref PRIMARY,a1 a1 5 const 25318 50000.00 100.00 100.00 Using index; Using temporary; Using filesort
1 SIMPLE t0 ref id_t2 id_t2 5 test.t2.id 1 1.00 100.00 100.00
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t0.id_t1 1 1.00 100.00 100.00 Using where; Using index
analyze format=json SELECT SQL_NO_CACHE t0.id_t0 , t1.id
FROM t0
LEFT JOIN t1 ON t0.id_t1 = t1.id
JOIN t2 ON t0.id_t2 = t2.id AND (t2.a1 = 1)
ORDER BY t0.d
LIMIT 10 ;
ANALYZE
{
"query_block": {
"select_id": 1,
"r_loops": 1,
"r_total_time_ms": 5731.8,
"filesort": {
"sort_key": "t0.d",
"r_loops": 1,
"r_total_time_ms": 12.705,
"r_limit": 10,
"r_used_priority_queue": true,
"r_output_rows": 11,
"temporary_table": {
"table": {
"table_name": "t2",
"access_type": "ref",
"possible_keys": ["PRIMARY", "a1"],
"key": "a1",
"key_length": "5",
"used_key_parts": ["a1"],
"ref": ["const"],
"r_loops": 1,
"rows": 25318,
"r_rows": 50000,
"r_total_time_ms": 196.81,
"filtered": 100,
"r_filtered": 100,
"using_index": true
},
"table": {
"table_name": "t0",
"access_type": "ref",
"possible_keys": ["id_t2"],
"key": "id_t2",
"key_length": "5",
"used_key_parts": ["id_t2"],
"ref": ["test.t2.id"],
"r_loops": 50000,
"rows": 1,
"r_rows": 1,
"r_total_time_ms": 4546.8,
"filtered": 100,
"r_filtered": 100
},
"table": {
"table_name": "t1",
"access_type": "eq_ref",
"possible_keys": ["PRIMARY"],
"key": "PRIMARY",
"key_length": "4",
"used_key_parts": ["id"],
"ref": ["test.t0.id_t1"],
"r_loops": 50000,
"rows": 1,
"r_rows": 1,
"r_total_time_ms": 808.79,
"filtered": 100,
"r_filtered": 100,
"attached_condition": "trigcond(trigcond(t0.id_t1 is not null))",
"using_index": true
}
}
}
}
}
With MyISAM instead of Innodb:
analyze SELECT SQL_NO_CACHE t0.id_t0 , t1.id
FROM t0
LEFT JOIN t1 ON t0.id_t1 = t1.id
JOIN t2 ON t0.id_t2 = t2.id AND (t2.a1 = 1)
ORDER BY t0.d
LIMIT 10 ;
id select_type table type possible_keys key key_len ref rows r_rows filtered r_filtered Extra
1 SIMPLE t0 index id_t2 d 6 NULL 50000 10.00 100.00 100.00 Using where
1 SIMPLE t1 eq_ref PRIMARY PRIMARY 4 test.t0.id_t1 1 1.00 100.00 100.00 Using where; Using index
1 SIMPLE t2 eq_ref PRIMARY,a1 PRIMARY 4 test.t0.id_t2 1 1.00 100.00 100.00 Using where