Using the following table:
CREATE TABLE `obj` (
|
`partition` smallint(5) unsigned NOT NULL,
|
`oid` bigint(20) unsigned NOT NULL,
|
`tid` bigint(20) unsigned NOT NULL,
|
`data_id` bigint(20) unsigned DEFAULT NULL,
|
`value_tid` bigint(20) unsigned DEFAULT NULL,
|
PRIMARY KEY (`partition`,`tid`,`oid`),
|
KEY `partition` (`partition`,`oid`,`tid`),
|
KEY `data_id` (`data_id`)
|
) ENGINE=ROCKSDB
|
The following request is far too slow:
MariaDB [neo0]> analyze SELECT SQL_NO_CACHE `partition`, MAX(tid) FROM obj WHERE `partition`=0;
|
+------+-------------+-------+------+-------------------+-----------+---------+-------+--------+-----------+----------+------------+-------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | r_rows | filtered | r_filtered | Extra |
|
+------+-------------+-------+------+-------------------+-----------+---------+-------+--------+-----------+----------+------------+-------------+
|
| 1 | SIMPLE | obj | ref | PRIMARY,partition | partition | 2 | const | 650282 | 647396.00 | 100.00 | 100.00 | Using index |
|
+------+-------------+-------+------+-------------------+-----------+---------+-------+--------+-----------+----------+------------+-------------+
|
1 row in set (0.40 sec)
|
It used the wrong index (maybe another issue). With correct index, it's not faster:
MariaDB [neo0]> analyze SELECT SQL_NO_CACHE `partition`, MAX(tid) FROM obj FORCE INDEX (PRIMARY) WHERE `partition`=0;
|
+------+-------------+-------+------+---------------+---------+---------+-------+--------+-----------+----------+------------+-------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | r_rows | filtered | r_filtered | Extra |
|
+------+-------------+-------+------+---------------+---------+---------+-------+--------+-----------+----------+------------+-------------+
|
| 1 | SIMPLE | obj | ref | PRIMARY | PRIMARY | 2 | const | 664465 | 647396.00 | 100.00 | 100.00 | Using index |
|
+------+-------------+-------+------+---------------+---------+---------+-------+--------+-----------+----------+------------+-------------+
|
1 row in set (0.38 sec)
|
I want the `partition` column in the result because I'd like to query MAX(tid) for several values of `partition` at the same time (using GROUP BY). Without this column, it works as expected:
MariaDB [neo0]> SELECT SQL_NO_CACHE MAX(tid) FROM obj WHERE `partition`=0;
|
+--------------------+
|
| MAX(tid) |
|
+--------------------+
|
| 270055958963668676 |
|
+--------------------+
|
1 row in set (0.00 sec)
|
- is part of
-
MDEV-11588
Support for ONLY_FULL_GROUP_BY functional dependency
-
-
Stalled
{"report":{"fcp":1034.4000005722046,"ttfb":308.69999980926514,"pageVisibility":"visible","entityId":61461,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":32,"apdex":0.5,"journeyId":"038bc485-6498-48bf-ab38-53476f8286e3","navigationType":0,"readyForUser":1133,"redirectCount":0,"resourceLoadedEnd":782,"resourceLoadedStart":315.80000019073486,"resourceTiming":[{"duration":123.39999961853027,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":315.80000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":315.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":439.19999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":123.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/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":316.1000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":316.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":439.6000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":249.10000038146973,"initiatorType":"script","name":"https://jira.mariadb.org/s/e9b27a47da5fb0f74a35acd57e9847fb-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":316.30000019073486,"connectEnd":316.30000019073486,"connectStart":316.30000019073486,"domainLookupEnd":316.30000019073486,"domainLookupStart":316.30000019073486,"fetchStart":316.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":445,"responseEnd":565.4000005722046,"responseStart":474.9000005722046,"secureConnectionStart":316.30000019073486},{"duration":387.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/c32eb0da7ad9831253f8397e6cc26afd-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/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":316.5,"connectEnd":316.5,"connectStart":316.5,"domainLookupEnd":316.5,"domainLookupStart":316.5,"fetchStart":316.5,"redirectEnd":0,"redirectStart":0,"requestStart":442.6000003814697,"responseEnd":703.8000001907349,"responseStart":588.6999998092651,"secureConnectionStart":316.5},{"duration":194.70000076293945,"initiatorType":"script","name":"https://jira.mariadb.org/s/bc0bcb146314416123c992714ee00ff7-CDN/lu2bv2/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":316.69999980926514,"connectEnd":444.6000003814697,"connectStart":444.6000003814697,"domainLookupEnd":444.6000003814697,"domainLookupStart":444.6000003814697,"fetchStart":316.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":445.1000003814697,"responseEnd":511.4000005722046,"responseStart":500.4000005722046,"secureConnectionStart":444.6000003814697},{"duration":184.60000038146973,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":316.80000019073486,"connectEnd":316.80000019073486,"connectStart":316.80000019073486,"domainLookupEnd":316.80000019073486,"domainLookupStart":316.80000019073486,"fetchStart":316.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":445.30000019073486,"responseEnd":501.4000005722046,"responseStart":492,"secureConnectionStart":316.80000019073486},{"duration":144.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":317,"connectEnd":317,"connectStart":317,"domainLookupEnd":317,"domainLookupStart":317,"fetchStart":317,"redirectEnd":0,"redirectStart":0,"requestStart":449,"responseEnd":461.80000019073486,"responseStart":460.19999980926514,"secureConnectionStart":317},{"duration":131.39999961853027,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bv2/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":317.1000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":317.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":448.5,"responseStart":0,"secureConnectionStart":0},{"duration":145.89999961853027,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":317.30000019073486,"connectEnd":317.30000019073486,"connectStart":317.30000019073486,"domainLookupEnd":317.30000019073486,"domainLookupStart":317.30000019073486,"fetchStart":317.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":450.80000019073486,"responseEnd":463.19999980926514,"responseStart":462,"secureConnectionStart":317.30000019073486},{"duration":132.69999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bv2/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":317.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":317.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":450.19999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":286.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/719848dd97ebe0663199f49a3936487a-CDN/lu2bv2/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":317.6000003814697,"connectEnd":317.6000003814697,"connectStart":317.6000003814697,"domainLookupEnd":317.6000003814697,"domainLookupStart":317.6000003814697,"fetchStart":317.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":454.19999980926514,"responseEnd":604.1000003814697,"responseStart":602.4000005722046,"secureConnectionStart":317.6000003814697},{"duration":453.3999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":322.6000003814697,"connectEnd":322.6000003814697,"connectStart":322.6000003814697,"domainLookupEnd":322.6000003814697,"domainLookupStart":322.6000003814697,"fetchStart":322.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":568,"responseEnd":776,"responseStart":772.8000001907349,"secureConnectionStart":322.6000003814697},{"duration":459.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":322.69999980926514,"connectEnd":322.69999980926514,"connectStart":322.69999980926514,"domainLookupEnd":322.69999980926514,"domainLookupStart":322.69999980926514,"fetchStart":322.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":618.4000005722046,"responseEnd":782,"responseStart":776.8000001907349,"secureConnectionStart":322.69999980926514},{"duration":297.6000003814697,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":705.6999998092651,"connectEnd":705.6999998092651,"connectStart":705.6999998092651,"domainLookupEnd":705.6999998092651,"domainLookupStart":705.6999998092651,"fetchStart":705.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":965,"responseEnd":1003.3000001907349,"responseStart":1002.6000003814697,"secureConnectionStart":705.6999998092651}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":124,"responseStart":309,"responseEnd":321,"domLoading":313,"domInteractive":1209,"domContentLoadedEventStart":1209,"domContentLoadedEventEnd":1273,"domComplete":2094,"loadEventStart":2094,"loadEventEnd":2095,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1171.6999998092651},{"name":"bigPipe.sidebar-id.end","time":1172.4000005722046},{"name":"bigPipe.activity-panel-pipe-id.start","time":1172.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":1175.5},{"name":"activityTabFullyLoaded","time":1293.1000003814697}],"measures":[],"correlationId":"1e41e8b75ddadc","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":110,"dbReadsTimeInMs":12,"dbConnsTimeInMs":21,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
varun, ok I tried debugging your example.
If I remove "a" from the select list, the optimization works:
MariaDB [j50]> explain SELECT SQL_NO_CACHE MIN(b) FROM t3 WHERE a = 0 ;
+------+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Select tables optimized away |
+------+-------------+-------+------+---------------+------+---------+------+------+------------------------------+
compare with
MariaDB [j50]> explain SELECT SQL_NO_CACHE a, MIN(b) FROM t3 WHERE a = 0 ;
+------+-------------+-------+------+---------------+---------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+------+-------------+-------+------+---------------+---------+---------+-------+------+-------------+
| 1 | SIMPLE | t3 | ref | PRIMARY | PRIMARY | 4 | const | 4 | Using index |
+------+-------------+-------+------+---------------+---------+---------+-------+------+-------------+