Details
-
Task
-
Status: Open (View Workflow)
-
Critical
-
Resolution: Unresolved
-
None
-
None
Description
Should we support DISTINCT for aggregate functions that are computed over a window?
PostgreSQL doesn't support this:
test=# select a, count(distinct b) over (order by a) from t1 ;
|
ERROR: DISTINCT is not implemented for window functions
|
LINE 1: select a, count(distinct b) over (order by a) from t1 ;
|
^
|
http://www.postgresql.org/docs/9.5/static/sql-expressions.html says "Aggregate window functions, unlike normal aggregate functions, do not allow DISTINCT or ORDER BY to be used within the function argument list"
SQL Server doesn't support it:
https://connect.microsoft.com/SQLServer/feedback/details/254393/over-clause-enhancement-request-distinct-clause-for-aggregate-functions
(verified with SQL Server 2008 and 2014)
but one can find many requests for them to support this.
Sybase documentation says:
No aggregation functions in the rank query are allowed to specify DISTINCT
http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc38151.1510/html/iqrefbb/BCGEEBHA.htm
Does this mean they don't support it?
Oracle 12.1 gives this error
ORA-30487: ORDER BY not allowed here
|
Apache Drill DOESNT support it:
https://issues.apache.org/jira/browse/DRILL-3182
Attachments
Issue Links
- blocks
-
MCOL-645 MariaDB WF Add DISTINCT to Window Functions SUM, AVG, COUNT
-
- Closed
-
- is part of
-
MDEV-6115 window functions as in the SQL standard
-
- Closed
-
-
MDEV-12987 complete window function support for columnstore parity
-
- Open
-
Activity
Description |
Should we support DISTINCT for aggregate functions that are computed over a window? PostgreSQL doesn't support this: {noformat} test=# select a, count(distinct b) over (order by a) from t1 ; ERROR: DISTINCT is not implemented for window functions LINE 1: select a, count(distinct b) over (order by a) from t1 ; ^ {noformat} SQL Server doesn't support it: https://connect.microsoft.com/SQLServer/feedback/details/254393/over-clause-enhancement-request-distinct-clause-for-aggregate-functions (verified with SQL Server 2008 and 2014) but one can find many requests for them to support this. Sybase documentation says: " No aggregation functions in the rank query are allowed to specify DISTINCT." http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc38151.1510/html/iqrefbb/BCGEEBHA.htm Does this mean they don't support it? Apache Drill supports it: https://issues.apache.org/jira/browse/DRILL-3182 |
Should we support DISTINCT for aggregate functions that are computed over a window? PostgreSQL doesn't support this: {noformat} test=# select a, count(distinct b) over (order by a) from t1 ; ERROR: DISTINCT is not implemented for window functions LINE 1: select a, count(distinct b) over (order by a) from t1 ; ^ {noformat} SQL Server doesn't support it: https://connect.microsoft.com/SQLServer/feedback/details/254393/over-clause-enhancement-request-distinct-clause-for-aggregate-functions (verified with SQL Server 2008 and 2014) but one can find many requests for them to support this. Sybase documentation says: " No aggregation functions in the rank query are allowed to specify DISTINCT." http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc38151.1510/html/iqrefbb/BCGEEBHA.htm Does this mean they don't support it? Oracle 12.1 gives this error {noformat} ORA-30487: ORDER BY not allowed here {noformat} Apache Drill supports it: https://issues.apache.org/jira/browse/DRILL-3182 |
Description |
Should we support DISTINCT for aggregate functions that are computed over a window? PostgreSQL doesn't support this: {noformat} test=# select a, count(distinct b) over (order by a) from t1 ; ERROR: DISTINCT is not implemented for window functions LINE 1: select a, count(distinct b) over (order by a) from t1 ; ^ {noformat} SQL Server doesn't support it: https://connect.microsoft.com/SQLServer/feedback/details/254393/over-clause-enhancement-request-distinct-clause-for-aggregate-functions (verified with SQL Server 2008 and 2014) but one can find many requests for them to support this. Sybase documentation says: " No aggregation functions in the rank query are allowed to specify DISTINCT." http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc38151.1510/html/iqrefbb/BCGEEBHA.htm Does this mean they don't support it? Oracle 12.1 gives this error {noformat} ORA-30487: ORDER BY not allowed here {noformat} Apache Drill supports it: https://issues.apache.org/jira/browse/DRILL-3182 |
Should we support DISTINCT for aggregate functions that are computed over a window? PostgreSQL doesn't support this: {noformat} test=# select a, count(distinct b) over (order by a) from t1 ; ERROR: DISTINCT is not implemented for window functions LINE 1: select a, count(distinct b) over (order by a) from t1 ; ^ {noformat} SQL Server doesn't support it: https://connect.microsoft.com/SQLServer/feedback/details/254393/over-clause-enhancement-request-distinct-clause-for-aggregate-functions (verified with SQL Server 2008 and 2014) but one can find many requests for them to support this. Sybase documentation says: bq.No aggregation functions in the rank query are allowed to specify DISTINCT http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc38151.1510/html/iqrefbb/BCGEEBHA.htm Does this mean they don't support it? Oracle 12.1 gives this error {noformat} ORA-30487: ORDER BY not allowed here {noformat} Apache Drill supports it: https://issues.apache.org/jira/browse/DRILL-3182 |
Description |
Should we support DISTINCT for aggregate functions that are computed over a window? PostgreSQL doesn't support this: {noformat} test=# select a, count(distinct b) over (order by a) from t1 ; ERROR: DISTINCT is not implemented for window functions LINE 1: select a, count(distinct b) over (order by a) from t1 ; ^ {noformat} SQL Server doesn't support it: https://connect.microsoft.com/SQLServer/feedback/details/254393/over-clause-enhancement-request-distinct-clause-for-aggregate-functions (verified with SQL Server 2008 and 2014) but one can find many requests for them to support this. Sybase documentation says: bq.No aggregation functions in the rank query are allowed to specify DISTINCT http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc38151.1510/html/iqrefbb/BCGEEBHA.htm Does this mean they don't support it? Oracle 12.1 gives this error {noformat} ORA-30487: ORDER BY not allowed here {noformat} Apache Drill supports it: https://issues.apache.org/jira/browse/DRILL-3182 |
Should we support DISTINCT for aggregate functions that are computed over a window?
PostgreSQL doesn't support this: {noformat} test=# select a, count(distinct b) over (order by a) from t1 ; ERROR: DISTINCT is not implemented for window functions LINE 1: select a, count(distinct b) over (order by a) from t1 ; ^ {noformat} http://www.postgresql.org/docs/9.5/static/sql-expressions.html says "Aggregate window functions, unlike normal aggregate functions, do not allow DISTINCT or ORDER BY to be used within the function argument list" SQL Server doesn't support it: https://connect.microsoft.com/SQLServer/feedback/details/254393/over-clause-enhancement-request-distinct-clause-for-aggregate-functions (verified with SQL Server 2008 and 2014) but one can find many requests for them to support this. Sybase documentation says: bq.No aggregation functions in the rank query are allowed to specify DISTINCT http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc38151.1510/html/iqrefbb/BCGEEBHA.htm Does this mean they don't support it? Oracle 12.1 gives this error {noformat} ORA-30487: ORDER BY not allowed here {noformat} Apache Drill supports it: https://issues.apache.org/jira/browse/DRILL-3182 |
Description |
Should we support DISTINCT for aggregate functions that are computed over a window?
PostgreSQL doesn't support this: {noformat} test=# select a, count(distinct b) over (order by a) from t1 ; ERROR: DISTINCT is not implemented for window functions LINE 1: select a, count(distinct b) over (order by a) from t1 ; ^ {noformat} http://www.postgresql.org/docs/9.5/static/sql-expressions.html says "Aggregate window functions, unlike normal aggregate functions, do not allow DISTINCT or ORDER BY to be used within the function argument list" SQL Server doesn't support it: https://connect.microsoft.com/SQLServer/feedback/details/254393/over-clause-enhancement-request-distinct-clause-for-aggregate-functions (verified with SQL Server 2008 and 2014) but one can find many requests for them to support this. Sybase documentation says: bq.No aggregation functions in the rank query are allowed to specify DISTINCT http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc38151.1510/html/iqrefbb/BCGEEBHA.htm Does this mean they don't support it? Oracle 12.1 gives this error {noformat} ORA-30487: ORDER BY not allowed here {noformat} Apache Drill supports it: https://issues.apache.org/jira/browse/DRILL-3182 |
Should we support DISTINCT for aggregate functions that are computed over a window?
PostgreSQL doesn't support this: {noformat} test=# select a, count(distinct b) over (order by a) from t1 ; ERROR: DISTINCT is not implemented for window functions LINE 1: select a, count(distinct b) over (order by a) from t1 ; ^ {noformat} http://www.postgresql.org/docs/9.5/static/sql-expressions.html says "Aggregate window functions, unlike normal aggregate functions, do not allow DISTINCT or ORDER BY to be used within the function argument list" SQL Server doesn't support it: https://connect.microsoft.com/SQLServer/feedback/details/254393/over-clause-enhancement-request-distinct-clause-for-aggregate-functions (verified with SQL Server 2008 and 2014) but one can find many requests for them to support this. Sybase documentation says: bq.No aggregation functions in the rank query are allowed to specify DISTINCT http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc38151.1510/html/iqrefbb/BCGEEBHA.htm Does this mean they don't support it? Oracle 12.1 gives this error {noformat} ORA-30487: ORDER BY not allowed here {noformat} Apache Drill DOESNT support it: https://issues.apache.org/jira/browse/DRILL-3182 |
Component/s | Optimizer - Window functions [ 13502 ] | |
Component/s | Optimizer [ 10200 ] |
Link | This issue is part of MDEV-12987 [ MDEV-12987 ] |
Fix Version/s | 10.2 [ 14601 ] |
Priority | Major [ 3 ] | Critical [ 2 ] |
Workflow | MariaDB v3 [ 73882 ] | MariaDB v4 [ 130435 ] |
MySQL/MariaDB's algorithm for aggregate_func(DISTINCT x) uses Unique class to remove duplicates. This approach cannot be easily extended to handle the case where rows move in and out of the window frame.
Consider a query
SELECT agg_func(DISTINCT c) OVER (PARTITION BY a ORDER BY b ) FROM ...
Normally, window function code will sort the query output by (a, b). What if we sorted by (a,b,c) instead? We would be able to compute
agg_func(DISTINCT c) easily:
Consider some value of c=$c1. As soon as the first row with c=$c1 goes into window frame, we can compute the current agg_func value $val. All subsequent rows with c=$c1 have the same value agg_func(...)=$val.