databend icon indicating copy to clipboard operation
databend copied to clipboard

Bug: prefer table names defined by CTE

Open xudong963 opened this issue 1 year ago • 4 comments

Summary

For the case, the last query has cte named source, ideally, the query SELECT * FROM source should use the table of cte, but it uses the table source defined before.

create table source(a int);
insert into source values(1);
select * from source;

select * from  (WITH source AS (select 1 as e) SELECT * FROM source) A,   (WITH source AS (select 2 as e) SELECT * FROM source) B;

xudong963 avatar Jun 20 '24 08:06 xudong963

@xudong963 can i work on this issue?

Vasanth-96 avatar Jun 26 '24 15:06 Vasanth-96

@BohuTANG i'm new to this code base if possbile can you help me with the start or some idea about the files i should look into.

Vasanth-96 avatar Jun 26 '24 17:06 Vasanth-96

@Vasanth-96 Hi, this guide is helpful https://docs.databend.com/guides/community/contributor/good-pr

bohutang avatar Jun 27 '24 01:06 bohutang

You can read the file: https://github.com/datafuselabs/databend/blob/main/src/query/sql/src/planner/binder/bind_table_reference/bind_table.rs#L36.

xudong963 avatar Jun 27 '24 05:06 xudong963

The issue has been solved by https://github.com/datafuselabs/databend/pull/15941

xudong963 avatar Jul 02 '24 05:07 xudong963