Targetlist lost when CTE join - Mailing list pgsql-hackers

From Zhang Mingli
Subject Targetlist lost when CTE join
Date
Msg-id 98c12b08-85bc-4464-80a5-f13955124223@Spark
Whole thread Raw
Responses Re: Targetlist lost when CTE join
Re: Targetlist lost when CTE join
List pgsql-hackers
Hi,


Mini repo

create table t1(c1 int, c2 int);
CREATE TABLE
create table t2(c1 int, c2 int);
CREATE TABLE
explain with cte1 as (insert into t2 values (1, 2) returning *) select * from cte1 join t1 using(c1);
 QUERY PLAN
----------------------------------------------------------------
 Hash Join (cost=0.04..41.23 rows=11 width=12)
 Hash Cond: (t1.c1 = cte1.c1)
 CTE cte1
 -> Insert on t2 (cost=0.00..0.01 rows=1 width=8)
 -> Result (cost=0.00..0.01 rows=1 width=8)
 -> Seq Scan on t1 (cost=0.00..32.60 rows=2260 width=8)
 -> Hash (cost=0.02..0.02 rows=1 width=8)
 -> CTE Scan on cte1 (cost=0.00..0.02 rows=1 width=8)
(8 rows)

with cte1 as (insert into t2 values (1, 2) returning *) select * from cte1 join t1 using(c1);
 c1 | c2 | c2
----+----+----
(0 rows)

truncate t2;
TRUNCATE TABLE
with cte1 as (insert into t2 values (1, 2) returning *) select cte1.*, t1.* from cte1 join t1 using(c1);
 c1 | c2 | c1 | c2
----+----+----+----
(0 rows)

Table t1 and  t2 both has 2 columns: c1, c2, when CTE join select *, the result target list seems to lost one’s column c1.
But it looks good when select cte1.* and t1.* explicitly .

Is it a bug?

Regards,
Zhang Mingli

pgsql-hackers by date:

Previous
From: "Joel Jacobson"
Date:
Subject: Re: Do we want a hashset type?
Next
From: Zhang Mingli
Date:
Subject: Re: Targetlist lost when CTE join