tidb
tidb copied to clipboard
incorrect name resolution for window function in order by clause
Bug Report
Please answer these questions before submitting your issue. Thanks!
- What did you do? If possible, provide a recipe for reproducing the error.
create table t (a int, b int);
explain select a, b as a from t order by (sum(a) over(partition by a));
- What did you expect to see?
ERROR 1052 (23000): Column 'a' in window partition by is ambiguous
- What did you see instead?
SQL complies successfully.
- What version of TiDB are you using (
tidb-server -Vor runselect tidb_version();on TiDB)?
https://github.com/pingcap/tidb/pull/8630
It has been fixed in release 4.0:
TiDB([email protected]:test) > set @@tidb_enable_window_function = 1;
Query OK, 0 rows affected (0.00 sec)
TiDB([email protected]:test) > explain select a, b as a from t order by (sum(a) over(partition by a));
+----------------------------------+----------+-----------+---------------------------------------------------------------------------------+
| id | estRows | task | operator info |
+----------------------------------+----------+-----------+---------------------------------------------------------------------------------+
| Projection_8 | 10000.00 | root | test.t.a, test.t.b |
| └─Sort_9 | 10000.00 | root | Column#5:asc |
| └─Shuffle_15 | 10000.00 | root | execution info: concurrency:4, data source:TableReader_13 |
| └─Window_11 | 10000.00 | root | sum(cast(test.t.a, decimal(65,0) BINARY))->Column#5 over(partition by test.t.a) |
| └─Sort_14 | 10000.00 | root | test.t.a:asc |
| └─TableReader_13 | 10000.00 | root | data:TableFullScan_12 |
| └─TableFullScan_12 | 10000.00 | cop[tikv] | table:t, keep order:false, stats:pseudo |
+----------------------------------+----------+-----------+---------------------------------------------------------------------------------+
7 rows in set (0.00 sec)