StarRocks / starrocks

The world's fastest open query engine for sub-second analytics both on and off the data lakehouse. With the flexibility to support nearly any scenario, StarRocks provides best-in-class performance for multi-dimensional analytics, real-time analytics, and ad-hoc queries. A Linux Foundation project.
https://starrocks.io
Apache License 2.0
9.03k stars 1.82k forks source link

子查询内部不能识别外部定义的表的别名 #52419

Open awesomeleo opened 3 weeks ago

awesomeleo commented 3 weeks ago

1.创建表 CREATE TABLE customers ( cust_id int(11) NOT NULL COMMENT "", cust_name varchar(150) NOT NULL COMMENT "" ) ENGINE=OLAP PRIMARY KEY(cust_id) DISTRIBUTED BY HASH(cust_id) PROPERTIES ( "replication_num" = "1", "in_memory" = "false", "enable_persistent_index" = "true", "replicated_storage" = "true", "compression" = "LZ4" );

CREATE TABLE orderitems ( order_num int(11) NOT NULL COMMENT "", order_item int(11) NOT NULL COMMENT "", prod_id varchar(30) NOT NULL COMMENT "" ) ENGINE=OLAP PRIMARY KEY(order_num, order_item) DISTRIBUTED BY HASH(order_num, order_item) PROPERTIES ( "replication_num" = "1", "in_memory" = "false", "enable_persistent_index" = "true", "replicated_storage" = "true", "compression" = "LZ4" );

CREATE TABLE orders ( order_num int(11) NOT NULL COMMENT "", order_date datetime NOT NULL COMMENT "", cust_id int(11) NOT NULL COMMENT "" ) ENGINE=OLAP PRIMARY KEY(order_num) DISTRIBUTED BY HASH(order_num) PROPERTIES ( "replication_num" = "1", "in_memory" = "false", "enable_persistent_index" = "true", "replicated_storage" = "true", "compression" = "LZ4" );

查询语句

select cust_name, cust_id from customers cm where cust_id in (select cust_id from orders where order_num in ( select order_num from orderitems where prod_id = 'TNT2' and cm.cust_name='Place')); ERROR 1064 (HY000): Getting analyzing error. Detail message: Column 'test.cm.cust_name' cannot be resolved. starrocks > show create table customers;

Expected behavior (Required)

能够执行成功

Real behavior (Required)

报错,内部子查询不能识别外部定义的表的别名

StarRocks version (Required)

PS:两层的子查询可以执行,超过三层子查询就不能识别 select cust_name, cust_id from customers cm where cust_id in (select cust_id from orders where order_num in (20005, 20007) and cm.cust_name='Yosemite Place'); +----------------+---------+ | cust_name | cust_id | +----------------+---------+ | Yosemite Place | 10004 | +----------------+---------+

awesomeleo commented 2 days ago

没有人关注自己顶一下