-
Notifications
You must be signed in to change notification settings - Fork 591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
returning
fails matching specified target columns
#9012
Comments
when binding returing_list: the InputRef's index is derived from the original table's column layout risingwave/src/frontend/src/binder/insert.rs Line 133 in e294250
but the inserted values may have a different column layout. if we decided to disable column pruning for insertion -> projection, the LogicalProject's logic can be entangled, can we just add a new type of PlanNode called InsertionReturningProject? |
Excellent analysis👏 That said I find introducing a new PlanNode maybe somewhat overkill? risingwave/src/frontend/src/planner/insert.rs Lines 42 to 44 in 5a61944
|
I will happily try your approach later create table t (v1 int, v2 real);
insert into t (v2) values(1.5) returning v1; in this query, since we don't need the v2 values in projection, the LogicalProject's optimizer may mess up our insert values, perhaps even lose it, but the real insertion execution haven't begin yet |
@broccoliSpicy After reflection I realize that your idea looks better👍. Would you like to fix it? |
sure, gladly, but we better finalize our approach first. would you mind some comments @st1page |
I implemented InputRef index rewiring and found some tricky bug. dev=> create table tn (v1 int, v2 int);
CREATE_TABLE
dev=> insert into tn (v2) values (1) returning v2 + 1;
?column?
----------
2
(1 row)
INSERT 0 1
dev=> insert into tn (v2) values (1) returning v2+1. v1;
v1
----
2
(1 row)
INSERT 0 1
dev=> insert into tn (v2) values (1) returning v2+1, v1;
?column? | v1
----------+----
2 |
(1 row)
INSERT 0 1
dev=> insert into tn (v2) values (1,5) returning v2+1, v1;
ERROR: QueryError: Bind error: INSERT has more expressions than target columns
dev=> insert into tn (v2) values (1.5) returning v2+1, v1;
?column? | v1
----------+----
3 |
(1 row)
INSERT 0 1
dev=> insert into tn (v2) values (1.5) returning v2+1, v1;
?column? | v1
----------+----
3 |
(1 row)
INSERT 0 1
dev=> insert into tn (v2) values (1.5) returning v2 + 1.1; │ 0:psql │ │
│ ?column? └────────┘ │
│ ---------- │
│ 3.1 │
│ (1 row)
I didn't check it through but I guess during function binding, we infer the function's input and return type based on the target table's schema, then do some type coercion I am thinking about mock a binding context before we bind returning list now |
ha, my bad, the above behavior is actually in conform with postgres. |
I used to be unfamiliar with this grammar and I find it is more powerful than I thought 🥵 dev=# with cte as (insert into t values (1, 20, 400, 5000), (2,60,600,6000) returning x,z) select sum(x) from cte;
sum
-----
80
(1 row)
dev=# explain with cte as (insert into t values (1, 20, 400, 5000), (2,60,600,6000) returning x,z) select sum(x) from cte;
QUERY PLAN
----------------------------------------------------------------------------
Aggregate (cost=0.07..0.08 rows=1 width=8)
CTE cte
-> Insert on t (cost=0.00..0.03 rows=2 width=16)
-> Values Scan on "*VALUES*" (cost=0.00..0.03 rows=2 width=16)
-> CTE Scan on cte (cost=0.00..0.04 rows=2 width=4)
(5 rows)
|
Hey, may I ask any new updates? |
this issued is fixed by #11080. |
Describe the bug
No response
To Reproduce
Expected behavior
Additional context
No response
The text was updated successfully, but these errors were encountered: