risingwavelabs / risingwave

SQL stream processing, analytics, and management. We decouple storage and compute to offer efficient joins, instant failover, dynamic scaling, speedy bootstrapping, and concurrent query serving.
https://www.risingwave.com/slack
Apache License 2.0
6.63k stars 544 forks source link

bug: column mapping mismatch when insert. #17626

Open st1page opened 2 weeks ago

st1page commented 2 weeks ago
dev=> create table t(v1 int, v2 int as v1 + v1, v3 int default 10, v4 varchar);
CREATE_TABLE
dev=> insert into t(v3) values (1);
ERROR:  Failed to run the query

Caused by these errors (recent errors listed first):
  1: gRPC request to batch service failed: Internal error
  2: broken fifo_channel

CN log

thread 'rw-batch' panicked at src/dml/src/table.rs:127:10:
table source write txn_msg schema check failed: "column type mismatched at position 2: expected Some(Varchar), found Some(\"Int32\")"
stack backtrace:
   0: rust_begin_unwind
             at /rustc/4a0cc881dcc4d800f10672747f61a94377ff6662/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_fmt
             at /rustc/4a0cc881dcc4d800f10672747f61a94377ff6662/library/core/src/panicking.rs:72:14
   2: core::result::unwrap_failed
             at /rustc/4a0cc881dcc4d800f10672747f61a94377ff6662/library/core/src/result.rs:1654:5
   3: core::result::Result<T,E>::expect
             at /rustc/4a0cc881dcc4d800f10672747f61a94377ff6662/library/core/src/result.rs:1034:23
   4: risingwave_dml::table::TableDmlHandle::check_chunk_schema
             at ./src/dml/src/table.rs:121:9
   5: risingwave_batch::executor::insert::InsertExecutor::do_execute::{{closure}}::{{closure}}::{{closure}}
             at ./src/batch/src/executor/insert.rs:167:13
   6: risingwave_batch::executor::insert::InsertExecutor::do_execute::{{closure}}
             at ./src/batch/src/executor/insert.rs:189:47
.......

additional info: this case will produce the wrong result

dev=> create table t(v1 int, v2 int as v1 + v1, v3 int default 10, v4 int);
CREATE_TABLE
dev=> insert into t(v3) values (1);
INSERT 0 1
dev=> select * from t;
 v1 | v2 | v3 | v4 
----+----+----+----
    |    |  1 | 10
(1 row)
st1page commented 2 weeks ago

It is because the default_columns_from_catalog is indexed with the table's catalog but the default_column_indices is indexed with the insert's schema https://github.com/risingwavelabs/risingwave/blob/607a2afdc15a188d0ad974b1b963f27d247c594d/src/frontend/src/binder/insert.rs#L268-L281