At the moment optimizer does window function materialization even if join produces no rows:
create or replace table t1 (a int, b int, c int, index(a, b, c));
|
create or replace table t2 (a int, b int, c int, index(a, b, c));
|
|
insert into t1 select seq, seq, seq from seq_1_to_500000;
|
insert into t2 select seq, seq, seq from seq_1_to_500000;
|
|
explain
|
select * from
|
(
|
select t1.a a, t2.b b, t2.c, sum(t2.c) over ( partition by a,b,c )
|
from t1 join t2
|
where
|
t1.a=t2.a and t1.b=t2.b
|
) v1 join ( select 1000000 as a, 1000000 as b, 1000000 as c ) v2 using (a,b,c);
|
+------+-------------+------------+--------+---------------+------+---------+---------------------+--------+-------------------------------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+------------+--------+---------------+------+---------+---------------------+--------+-------------------------------------------+
|
| 1 | PRIMARY | <derived3> | system | NULL | NULL | NULL | NULL | 1 | |
|
| 1 | PRIMARY | <derived2> | ref | key0 | key0 | 15 | const,const,const | 10 | |
|
| 3 | DERIVED | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
|
| 2 | DERIVED | t1 | index | a | a | 15 | NULL | 500000 | Using where; Using index; Using temporary |
|
| 2 | DERIVED | t2 | ref | a | a | 10 | test.t1.a,test.t1.b | 1 | Using index |
|
+------+-------------+------------+--------+---------------+------+---------+---------------------+--------+-------------------------------------------+
|
MariaDB [test]> select count(*) from
|
-> (
|
-> select t1.a a, t2.b b, t2.c, sum(t2.c) over ( partition by a,b,c )
|
-> from t1 join t2
|
-> where
|
-> t1.a=t2.a and t1.b=t2.b
|
-> ) v1 join ( select 1000000 as a, 1000000 as b, 1000000 as c ) v2 using (a,b,c);
|
+----------+
|
| count(*) |
|
+----------+
|
| 0 |
|
+----------+
|
1 row in set (2.27 sec)
|
For good performance it is required to skip materialization at all if no rows are joined and try to push condition if only few rows are joined like in MDEV-13385
- relates to
-
MDEV-13385
Window Functions: Push condition into inner query
-
-
Closed
{"report":{"fcp":875.5999999046326,"ttfb":183.79999995231628,"pageVisibility":"visible","entityId":62402,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"a7c07ca9-0c73-4d30-8082-7179db12e6c0","navigationType":0,"readyForUser":957.0999999046326,"redirectCount":0,"resourceLoadedEnd":944.2000000476837,"resourceLoadedStart":189.70000004768372,"resourceTiming":[{"duration":216.59999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":189.70000004768372,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":189.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":406.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":216.30000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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":190.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":190.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":406.40000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":225.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":190.20000004768372,"connectEnd":190.20000004768372,"connectStart":190.20000004768372,"domainLookupEnd":190.20000004768372,"domainLookupStart":190.20000004768372,"fetchStart":190.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":190.20000004768372,"responseEnd":415.2999999523163,"responseStart":415.2999999523163,"secureConnectionStart":190.20000004768372},{"duration":327.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/099b33461394b8015fc36c0a4b96e19f-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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":190.29999995231628,"connectEnd":190.29999995231628,"connectStart":190.29999995231628,"domainLookupEnd":190.29999995231628,"domainLookupStart":190.29999995231628,"fetchStart":190.29999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":190.29999995231628,"responseEnd":517.7000000476837,"responseStart":517.7000000476837,"secureConnectionStart":190.29999995231628},{"duration":330.89999985694885,"initiatorType":"script","name":"https://jira.mariadb.org/s/94c15bff32baef80f4096a08aceae8bc-CDN/lu2bu7/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":190.40000009536743,"connectEnd":190.40000009536743,"connectStart":190.40000009536743,"domainLookupEnd":190.40000009536743,"domainLookupStart":190.40000009536743,"fetchStart":190.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":190.40000009536743,"responseEnd":521.2999999523163,"responseStart":521.2999999523163,"secureConnectionStart":190.40000009536743},{"duration":331.40000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":190.5,"connectEnd":190.5,"connectStart":190.5,"domainLookupEnd":190.5,"domainLookupStart":190.5,"fetchStart":190.5,"redirectEnd":0,"redirectStart":0,"requestStart":190.5,"responseEnd":521.9000000953674,"responseStart":521.9000000953674,"secureConnectionStart":190.5},{"duration":331.7999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":190.70000004768372,"connectEnd":190.70000004768372,"connectStart":190.70000004768372,"domainLookupEnd":190.70000004768372,"domainLookupStart":190.70000004768372,"fetchStart":190.70000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":190.70000004768372,"responseEnd":522.5,"responseStart":522.5,"secureConnectionStart":190.70000004768372},{"duration":332.2000000476837,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bu7/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":190.79999995231628,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":190.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":523,"responseStart":0,"secureConnectionStart":0},{"duration":332.2000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":190.79999995231628,"connectEnd":190.79999995231628,"connectStart":190.79999995231628,"domainLookupEnd":190.79999995231628,"domainLookupStart":190.79999995231628,"fetchStart":190.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":190.79999995231628,"responseEnd":523,"responseStart":523,"secureConnectionStart":190.79999995231628},{"duration":332.7999999523163,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bu7/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":190.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":190.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":523.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":332.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/3339d87fa2538a859872f2df449bf8d0-CDN/lu2bu7/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":191.20000004768372,"connectEnd":191.20000004768372,"connectStart":191.20000004768372,"domainLookupEnd":191.20000004768372,"domainLookupStart":191.20000004768372,"fetchStart":191.20000004768372,"redirectEnd":0,"redirectStart":0,"requestStart":191.20000004768372,"responseEnd":523.7000000476837,"responseStart":523.7000000476837,"secureConnectionStart":191.20000004768372},{"duration":429.10000014305115,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":191.79999995231628,"connectEnd":191.79999995231628,"connectStart":191.79999995231628,"domainLookupEnd":191.79999995231628,"domainLookupStart":191.79999995231628,"fetchStart":191.79999995231628,"redirectEnd":0,"redirectStart":0,"requestStart":191.79999995231628,"responseEnd":620.9000000953674,"responseStart":620.9000000953674,"secureConnectionStart":191.79999995231628},{"duration":737.0999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":191.90000009536743,"connectEnd":191.90000009536743,"connectStart":191.90000009536743,"domainLookupEnd":191.90000009536743,"domainLookupStart":191.90000009536743,"fetchStart":191.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":191.90000009536743,"responseEnd":929,"responseStart":929,"secureConnectionStart":191.90000009536743},{"duration":57.5,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":564.5,"connectEnd":564.5,"connectStart":564.5,"domainLookupEnd":564.5,"domainLookupStart":564.5,"fetchStart":564.5,"redirectEnd":0,"redirectStart":0,"requestStart":564.5,"responseEnd":622,"responseStart":621.9000000953674,"secureConnectionStart":564.5},{"duration":148.29999995231628,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2bu7/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":795.9000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":795.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":944.2000000476837,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":22,"responseStart":184,"responseEnd":187,"domLoading":187,"domInteractive":1015,"domContentLoadedEventStart":1015,"domContentLoadedEventEnd":1060,"domComplete":1461,"loadEventStart":1461,"loadEventEnd":1462,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":996.7000000476837},{"name":"bigPipe.sidebar-id.end","time":997.4000000953674},{"name":"bigPipe.activity-panel-pipe-id.start","time":997.5},{"name":"bigPipe.activity-panel-pipe-id.end","time":998.2000000476837},{"name":"activityTabFullyLoaded","time":1076.7000000476837}],"measures":[],"correlationId":"d7d414778b73ad","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":92,"dbReadsTimeInMs":11,"dbConnsTimeInMs":19,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
A full cost-base solution was pushed into the 10.3 tree