last_value (this is frame-based) (DONE)
these require two passes over partition to compute. The extra information that we require is the number of rows in the partition. In order to find the number of rows, we must first detect partition boundaries and then we can compute the number of rows per partition.
Two-cursor window functions:
lag (DONE)
lead (DONE)
these require an additional cursor that is traveling n rows ahead/behind the current_row cursor.
Key pieces for implementing this:
Make use of the filesort interface, since we do not need temporary tables for these functions.
It is a very similar use case to the GROUP BY statement. An important task is figuring out partition boundaries. The classes used for computing GROUP BY, might prove useful.
Overview of the solution sketch that was pushed into 10.1-window branch:
JOIN::exec has a piece of code that detects that
the select uses one table
all windowing functions have the same ORDER BY clause
all windowing functions allow for streaming computation
if this is the case
it runs filesort() to sort the source table in the required ordering
then, end_send() has a code that calls func->advance_window() for
all window function items
then
+void Item_window_func::advance_window() {
+ int changed = test_if_group_changed(partition_fields);
+
+ if (changed > -1) {
+ window_func->clear();
+ }
+ window_func->add();
+}
and this computes the window function. It is done on the fly.
Sergei Petrunia
added a comment - Overview of the solution sketch that was pushed into 10.1-window branch:
JOIN::exec has a piece of code that detects that
the select uses one table
all windowing functions have the same ORDER BY clause
all windowing functions allow for streaming computation
if this is the case
it runs filesort() to sort the source table in the required ordering
then, end_send() has a code that calls func->advance_window() for
all window function items
then
+void Item_window_func::advance_window() {
+ int changed = test_if_group_changed(partition_fields);
+
+ if (changed > -1) {
+ window_func->clear();
+ }
+ window_func->add();
+}
and this computes the window function. It is done on the fly.
¿Is possible to use Window Functions over columns which contain Aggregate Functions (For example: count(Column_Name)?
SELECT
count(Column_Name) AS MyCount,
PERCENT_RANK() OVER (MyCount)
FROM
myTable;
Juan Telleria
added a comment - - edited ¿Is possible to use Window Functions over columns which contain Aggregate Functions (For example: count(Column_Name)?
SELECT
count(Column_Name) AS MyCount,
PERCENT_RANK() OVER (MyCount)
FROM
myTable;
People
Vicențiu Ciorbaru
Vicențiu Ciorbaru
Votes:
9Vote for this issue
Watchers:
14Start watching this issue
Dates
Created:
Updated:
Resolved:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":860.1999998092651,"ttfb":244.59999990463257,"pageVisibility":"visible","entityId":51155,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"a3d1c1fc-6350-4323-9a59-8c7b10eafb47","navigationType":0,"readyForUser":968.9000000953674,"redirectCount":0,"resourceLoadedEnd":625,"resourceLoadedStart":251.7999997138977,"resourceTiming":[{"duration":4.400000095367432,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":251.7999997138977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":251.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":256.19999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":6.299999713897705,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":252,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":252,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":258.2999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":131.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":252.19999980926514,"connectEnd":252.19999980926514,"connectStart":252.19999980926514,"domainLookupEnd":252.19999980926514,"domainLookupStart":252.19999980926514,"fetchStart":252.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":261,"responseEnd":383.69999980926514,"responseStart":280,"secureConnectionStart":252.19999980926514},{"duration":320.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":252.5,"connectEnd":260.09999990463257,"connectStart":260.09999990463257,"domainLookupEnd":260.09999990463257,"domainLookupStart":260.09999990463257,"fetchStart":252.5,"redirectEnd":0,"redirectStart":0,"requestStart":260.69999980926514,"responseEnd":572.6999998092651,"responseStart":275.2999997138977,"secureConnectionStart":260.09999990463257},{"duration":21.90000009536743,"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":252.69999980926514,"connectEnd":252.69999980926514,"connectStart":252.69999980926514,"domainLookupEnd":252.69999980926514,"domainLookupStart":252.69999980926514,"fetchStart":252.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":261.19999980926514,"responseEnd":274.59999990463257,"responseStart":271.40000009536743,"secureConnectionStart":252.69999980926514},{"duration":31,"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":252.90000009536743,"connectEnd":252.90000009536743,"connectStart":252.90000009536743,"domainLookupEnd":252.90000009536743,"domainLookupStart":252.90000009536743,"fetchStart":252.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":264.69999980926514,"responseEnd":283.90000009536743,"responseStart":281,"secureConnectionStart":252.90000009536743},{"duration":30.90000009536743,"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":253.09999990463257,"connectEnd":253.09999990463257,"connectStart":253.09999990463257,"domainLookupEnd":253.09999990463257,"domainLookupStart":253.09999990463257,"fetchStart":253.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":265,"responseEnd":284,"responseStart":282.40000009536743,"secureConnectionStart":253.09999990463257},{"duration":8.800000190734863,"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":253.2999997138977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":253.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":262.09999990463257,"responseStart":0,"secureConnectionStart":0},{"duration":33.5,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":253.5,"connectEnd":253.5,"connectStart":253.5,"domainLookupEnd":253.5,"domainLookupStart":253.5,"fetchStart":253.5,"redirectEnd":0,"redirectStart":0,"requestStart":265.69999980926514,"responseEnd":287,"responseStart":285.69999980926514,"secureConnectionStart":253.5},{"duration":12.099999904632568,"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":253.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":253.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":265.69999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":41.200000286102295,"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":253.7999997138977,"connectEnd":253.7999997138977,"connectStart":253.7999997138977,"domainLookupEnd":253.7999997138977,"domainLookupStart":253.7999997138977,"fetchStart":253.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":274.90000009536743,"responseEnd":295,"responseStart":293.2999997138977,"secureConnectionStart":253.7999997138977},{"duration":366.69999980926514,"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":258.09999990463257,"connectEnd":258.09999990463257,"connectStart":258.09999990463257,"domainLookupEnd":258.09999990463257,"domainLookupStart":258.09999990463257,"fetchStart":258.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":280.7999997138977,"responseEnd":624.7999997138977,"responseStart":618,"secureConnectionStart":258.09999990463257},{"duration":366.90000009536743,"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":258.09999990463257,"connectEnd":258.09999990463257,"connectStart":258.09999990463257,"domainLookupEnd":258.09999990463257,"domainLookupStart":258.09999990463257,"fetchStart":258.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":290.09999990463257,"responseEnd":625,"responseStart":618.7999997138977,"secureConnectionStart":258.09999990463257},{"duration":82.2000002861023,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":528.6999998092651,"connectEnd":528.6999998092651,"connectStart":528.6999998092651,"domainLookupEnd":528.6999998092651,"domainLookupStart":528.6999998092651,"fetchStart":528.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":568.9000000953674,"responseEnd":610.9000000953674,"responseStart":608,"secureConnectionStart":528.6999998092651},{"duration":222.69999980926514,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":803,"connectEnd":803,"connectStart":803,"domainLookupEnd":803,"domainLookupStart":803,"fetchStart":803,"redirectEnd":0,"redirectStart":0,"requestStart":992.5999999046326,"responseEnd":1025.6999998092651,"responseStart":1024.9000000953674,"secureConnectionStart":803},{"duration":179.7999997138977,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":845.4000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":845.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1025.1999998092651,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":66,"responseStart":245,"responseEnd":256,"domLoading":248,"domInteractive":1056,"domContentLoadedEventStart":1056,"domContentLoadedEventEnd":1122,"domComplete":1631,"loadEventStart":1631,"loadEventEnd":1631,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1027.2999997138977},{"name":"bigPipe.sidebar-id.end","time":1028},{"name":"bigPipe.activity-panel-pipe-id.start","time":1028.1999998092651},{"name":"bigPipe.activity-panel-pipe-id.end","time":1030.2999997138977},{"name":"activityTabFullyLoaded","time":1137.5999999046326}],"measures":[],"correlationId":"69f17709b8f6e8","effectiveType":"4g","downlink":9.1,"rtt":0,"serverDuration":96,"dbReadsTimeInMs":10,"dbConnsTimeInMs":18,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
psergeyigorsanja