tidb icon indicating copy to clipboard operation
tidb copied to clipboard

incorrect name resolution for window function in order by clause

Open alivxxx opened this issue 7 years ago • 1 comments

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. 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));
  1. What did you expect to see?

ERROR 1052 (23000): Column 'a' in window partition by is ambiguous

  1. What did you see instead?

SQL complies successfully.

  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?

https://github.com/pingcap/tidb/pull/8630

alivxxx avatar Dec 10 '18 06:12 alivxxx

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)

zz-jason avatar Mar 18 '20 00:03 zz-jason