MIN/MAX Optimization (Select tables optimized away) does not work
MariaDB [holmes]> desc select max(id) from t1;
|
+------+-------------+--------------------------------------+-------+---------------+-----------------------+---------+------+----------+--------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+--------------------------------------+-------+---------------+-----------------------+---------+------+----------+--------------------------+
|
| 1 | SIMPLE | t1 | index | NULL | IDX_RAFNS_CREATE_TIME | 6 | NULL | 68320103 | Using where; Using index |
|
+------+-------------+--------------------------------------+-------+---------------+-----------------------+---------+------+----------+--------------------------+
|
1 row in set (0.00 sec)
|
|
|
MariaDB [holmes]> show create table t1\G;
|
*************************** 1. row ***************************
|
Table: t1
|
Create Table: CREATE TABLE `t1` (
|
`id` bigint(10) NOT NULL AUTO_INCREMENT COMMENT '',
|
`user_id` bigint(10) DEFAULT NULL COMMENT ',
|
`risk_assess_apply_id` bigint(10) DEFAULT NULL COMMENT '',
|
`risk_assess_flow_id` bigint(10) DEFAULT NULL COMMENT '',
|
`risk_assess_flow_node_id` bigint(10) DEFAULT NULL COMMENT '',
|
`apply_type` tinyint(1) DEFAULT NULL COMMENT '',
|
`state` tinyint(1) DEFAULT NULL COMMENT '',
|
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
|
`update_time` datetime DEFAULT NULL,
|
`name` varchar(30) DEFAULT NULL COMMENT '',
|
`ext_id` varchar(50) DEFAULT NULL COMMENT '',
|
`risk_assess_flow_name` varchar(45) DEFAULT NULL COMMENT '',
|
`risk_assess_flow_code` varchar(45) DEFAULT NULL COMMENT '',
|
`channel_code` varchar(30) DEFAULT NULL COMMENT '',
|
`risk_user_id` bigint(10) DEFAULT NULL COMMENT '',
|
`ext_user_id` varchar(50) DEFAULT NULL COMMENT '',
|
`risk_assess_flow_state_id` bigint(10) DEFAULT NULL COMMENT '',
|
`callback_credititem` text DEFAULT NULL COMMENT '',
|
`his_credititem` text DEFAULT NULL COMMENT '',
|
`ext_sub_credititem` text DEFAULT NULL COMMENT '',
|
`decision_sub_credititem` text DEFAULT NULL COMMENT '',
|
`total_sub_credititem` text DEFAULT NULL COMMENT '',
|
`calc_credititem_condition` varchar(400) DEFAULT NULL COMMENT '',
|
`decision_credititem_conditon` varchar(300) DEFAULT NULL COMMENT '',
|
`decision_process_id` varchar(30) DEFAULT NULL COMMENT '决策流程ID',
|
`decision_result_save_condition` varchar(300) DEFAULT NULL COMMENT '',
|
`result_save_condition` varchar(300) DEFAULT NULL COMMENT '',
|
`is_normal` int(10) DEFAULT NULL COMMENT '',
|
`normal_time` datetime DEFAULT NULL COMMENT '',
|
`is_suspend` int(10) DEFAULT NULL COMMENT '',
|
`suspend_time` datetime DEFAULT NULL COMMENT '',
|
`is_continue` int(10) DEFAULT NULL COMMENT '',
|
`continue_time` datetime DEFAULT NULL COMMENT '',
|
`is_decision_stop` int(10) DEFAULT NULL COMMENT '',
|
`decision_stop_time` datetime DEFAULT NULL COMMENT '',
|
`is_exception` int(10) DEFAULT NULL COMMENT '',
|
`exception_time` datetime DEFAULT NULL COMMENT '',
|
`decision_result_id` bigint(10) DEFAULT NULL COMMENT '',
|
`ts` timestamp(6) GENERATED ALWAYS AS ROW START,
|
`te` timestamp(6) GENERATED ALWAYS AS ROW END,
|
PRIMARY KEY (`id`,`te`),
|
KEY `IDX_RAFNS_UID` (`user_id`),
|
KEY `IDX_RAFNS_RISK_ASSESS_APPLY_ID` (`risk_assess_apply_id`),
|
KEY `IDX_RAFNS_RISK_ASSESS_FLOW_NODE_ID` (`risk_assess_flow_node_id`),
|
KEY `IDX_RAFNS_CREATE_TIME` (`create_time`),
|
KEY `IDX_RAFNS_RUI` (`risk_user_id`),
|
KEY `IDX_RAFNS_RAFSI` (`risk_assess_flow_state_id`),
|
KEY `IDX_RAFNS_RAFNI` (`risk_assess_flow_node_id`),
|
KEY `IDX_RAFNS_EUI` (`ext_user_id`),
|
PERIOD FOR SYSTEM_TIME (`ts`, `te`)
|
) ENGINE=InnoDB AUTO_INCREMENT=42164142 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='t1' WITH SYSTEM VERSIONING
|
PARTITION BY SYSTEM_TIME INTERVAL 1 MONTH
|
(PARTITION `p0` HISTORY ENGINE = InnoDB,
|
PARTITION `p1` HISTORY ENGINE = InnoDB,
|
PARTITION `p2` HISTORY ENGINE = InnoDB,
|
PARTITION `p3` HISTORY ENGINE = InnoDB,
|
PARTITION `p4` HISTORY ENGINE = InnoDB,
|
PARTITION `p5` HISTORY ENGINE = InnoDB,
|
PARTITION `p6` HISTORY ENGINE = InnoDB,
|
PARTITION `pcur` CURRENT ENGINE = InnoDB)
|
1 row in set (0.00 sec)
|
|
ERROR: No query specified
|
{"report":{"fcp":1244.6999998092651,"ttfb":314.4000005722046,"pageVisibility":"visible","entityId":70605,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"2923d04e-fc92-46df-a02d-88678aba28aa","navigationType":0,"readyForUser":1362.1999998092651,"redirectCount":0,"resourceLoadedEnd":934.6000003814697,"resourceLoadedStart":335,"resourceTiming":[{"duration":84.90000057220459,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":335,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":335,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":419.9000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":116.70000076293945,"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":335.19999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":335.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":451.9000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":436.29999923706055,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":335.4000005722046,"connectEnd":335.4000005722046,"connectStart":335.4000005722046,"domainLookupEnd":335.4000005722046,"domainLookupStart":335.4000005722046,"fetchStart":335.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":448.5,"responseEnd":771.6999998092651,"responseStart":470.9000005722046,"secureConnectionStart":335.4000005722046},{"duration":599,"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":335.6000003814697,"connectEnd":335.6000003814697,"connectStart":335.6000003814697,"domainLookupEnd":335.6000003814697,"domainLookupStart":335.6000003814697,"fetchStart":335.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":448.6000003814697,"responseEnd":934.6000003814697,"responseStart":493.80000019073486,"secureConnectionStart":335.6000003814697},{"duration":140.30000019073486,"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":335.69999980926514,"connectEnd":335.69999980926514,"connectStart":335.69999980926514,"domainLookupEnd":335.69999980926514,"domainLookupStart":335.69999980926514,"fetchStart":335.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":448.69999980926514,"responseEnd":476,"responseStart":472.6000003814697,"secureConnectionStart":335.69999980926514},{"duration":140.5,"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":335.80000019073486,"connectEnd":335.80000019073486,"connectStart":335.80000019073486,"domainLookupEnd":335.80000019073486,"domainLookupStart":335.80000019073486,"fetchStart":335.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":448.80000019073486,"responseEnd":476.30000019073486,"responseStart":473.1000003814697,"secureConnectionStart":335.80000019073486},{"duration":140.5999994277954,"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":336.1000003814697,"connectEnd":336.1000003814697,"connectStart":336.1000003814697,"domainLookupEnd":336.1000003814697,"domainLookupStart":336.1000003814697,"fetchStart":336.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":448.80000019073486,"responseEnd":476.69999980926514,"responseStart":474.69999980926514,"secureConnectionStart":336.1000003814697},{"duration":115.69999980926514,"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":336.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":336.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":452,"responseStart":0,"secureConnectionStart":0},{"duration":174.89999961853027,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":336.4000005722046,"connectEnd":336.4000005722046,"connectStart":336.4000005722046,"domainLookupEnd":336.4000005722046,"domainLookupStart":336.4000005722046,"fetchStart":336.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":457.80000019073486,"responseEnd":511.30000019073486,"responseStart":508.5,"secureConnectionStart":336.4000005722046},{"duration":120.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":336.6000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":336.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":456.9000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":174.69999980926514,"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":336.80000019073486,"connectEnd":336.80000019073486,"connectStart":336.80000019073486,"domainLookupEnd":336.80000019073486,"domainLookupStart":336.80000019073486,"fetchStart":336.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":459,"responseEnd":511.5,"responseStart":509.19999980926514,"secureConnectionStart":336.80000019073486},{"duration":517.5999994277954,"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":351.1000003814697,"connectEnd":351.1000003814697,"connectStart":351.1000003814697,"domainLookupEnd":351.1000003814697,"domainLookupStart":351.1000003814697,"fetchStart":351.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":596.6000003814697,"responseEnd":868.6999998092651,"responseStart":859.6000003814697,"secureConnectionStart":351.1000003814697},{"duration":522.3000001907349,"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":351.1000003814697,"connectEnd":351.1000003814697,"connectStart":351.1000003814697,"domainLookupEnd":351.1000003814697,"domainLookupStart":351.1000003814697,"fetchStart":351.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":651.6999998092651,"responseEnd":873.4000005722046,"responseStart":870.1000003814697,"secureConnectionStart":351.1000003814697},{"duration":153.19999980926514,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":907,"connectEnd":907,"connectStart":907,"domainLookupEnd":907,"domainLookupStart":907,"fetchStart":907,"redirectEnd":0,"redirectStart":0,"requestStart":1027.3000001907349,"responseEnd":1060.1999998092651,"responseStart":1059.6000003814697,"secureConnectionStart":907},{"duration":173.9000005722046,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1190,"connectEnd":1190,"connectStart":1190,"domainLookupEnd":1190,"domainLookupStart":1190,"fetchStart":1190,"redirectEnd":0,"redirectStart":0,"requestStart":1332.9000005722046,"responseEnd":1363.9000005722046,"responseStart":1363.3000001907349,"secureConnectionStart":1190},{"duration":219.30000019073486,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1236.1000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1236.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1455.4000005722046,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":74,"responseStart":315,"responseEnd":339,"domLoading":331,"domInteractive":1486,"domContentLoadedEventStart":1486,"domContentLoadedEventEnd":1554,"domComplete":1952,"loadEventStart":1952,"loadEventEnd":1953,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1458.3000001907349},{"name":"bigPipe.sidebar-id.end","time":1459.1000003814697},{"name":"bigPipe.activity-panel-pipe-id.start","time":1459.3000001907349},{"name":"bigPipe.activity-panel-pipe-id.end","time":1461.3000001907349},{"name":"activityTabFullyLoaded","time":1567.3000001907349}],"measures":[],"correlationId":"e0e37a4de6cd44","effectiveType":"4g","downlink":9.5,"rtt":0,"serverDuration":146,"dbReadsTimeInMs":16,"dbConnsTimeInMs":68,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
in 10.3 for table with system versioning:
MariaDB [test]> explain extended select max(id) from t1;
+------+-------------+-------+-------+---------------+-----------------------+---------+------+------+----------+--------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+------+-------------+-------+-------+---------------+-----------------------+---------+------+------+----------+--------------------------+
| 1 | SIMPLE | t1 | index | NULL | IDX_RAFNS_CREATE_TIME | 6 | NULL | 9900 | 100.00 | Using where; Using index |
+------+-------------+-------+-------+---------------+-----------------------+---------+------+------+----------+--------------------------+
1 row in set, 1 warning (0.001 sec)
Note (Code 1003): select max(`test`.`t1`.`id`) AS `max(id)` from `test`.`t1` FOR SYSTEM_TIME ALL where `test`.`t1`.`te` = TIMESTAMP'2038-01-19 04:14:07.999999'
without system versioning:
MariaDB [test]> explain extended select max(id) from t2;
+------+-------------+-------+------+---------------+------+---------+------+------+----------+------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+------------------------------+
| 1 | SIMPLE | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | Select tables optimized away |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+------------------------------+
1 row in set, 1 warning (0.001 sec)
Note (Code 1003): select max(`test`.`t2`.`id`) AS `max(id)` from `test`.`t2`