diff --git a/e2e_test/batch/basic/insert_expr.slt.part b/e2e_test/batch/basic/insert_expr.slt.part index 4e0285ea1653b..e07588cb4f793 100644 --- a/e2e_test/batch/basic/insert_expr.slt.part +++ b/e2e_test/batch/basic/insert_expr.slt.part @@ -110,7 +110,7 @@ select * from t; 1 3 2 1 2 3 2 1 3 -2 3 1 +3 1 2 statement ok insert into t (v3, v1, v2) values (1, 2, 3); @@ -121,8 +121,8 @@ select * from t; 1 3 2 1 2 3 2 1 3 -2 3 1 3 1 2 +2 3 1 statement ok insert into t (v3, v2, v1) values (1, 2, 3); @@ -133,8 +133,8 @@ select * from t; 1 3 2 1 2 3 2 1 3 -2 3 1 3 1 2 +2 3 1 3 2 1 # column and table names have to be case insensitive @@ -142,6 +142,117 @@ select * from t; statement ok drop table t; +# Bug https://github.com/risingwavelabs/risingwave/issues/6542 +# Test all permutations + +statement ok +create table t (v1 int, v2 int, v3 int, v4 int); + +statement ok +insert into t (v1, v2, v3, v4) values (1, 2, 3, 4); + +statement ok +insert into t (v1, v2, v4, v3) values (1, 2, 4, 3); + +statement ok +insert into t (v1, v3, v2, v4) values (1, 3, 2, 4); + +statement ok +insert into t (v1, v3, v4, v2) values (1, 3, 4, 2); + +statement ok +insert into t (v1, v4, v2, v3) values (1, 4, 2, 3); + +statement ok +insert into t (v1, v4, v3, v2) values (1, 4, 3, 2); + +statement ok +insert into t (v2, v1, v3, v4) values (2, 1, 3, 4); + +statement ok +insert into t (v2, v1, v4, v3) values (2, 1, 4, 3); + +statement ok +insert into t (v2, v3, v1, v4) values (2, 3, 1, 4); + +statement ok +insert into t (v2, v3, v4, v1) values (2, 3, 4, 1); + +statement ok +insert into t (v2, v4, v1, v3) values (2, 4, 1, 3); + +statement ok +insert into t (v2, v4, v3, v1) values (2, 4, 3, 1); + +statement ok +insert into t (v3, v1, v2, v4) values (3, 1, 2, 4); + +statement ok +insert into t (v3, v1, v4, v2) values (3, 1, 4, 2); + +statement ok +insert into t (v3, v2, v1, v4) values (3, 2, 1, 4); + +statement ok +insert into t (v3, v2, v4, v1) values (3, 2, 4, 1); + +statement ok +insert into t (v3, v4, v1, v2) values (3, 4, 1, 2); + +statement ok +insert into t (v3, v4, v2, v1) values (3, 4, 2, 1); + +statement ok +insert into t (v4, v1, v2, v3) values (4, 1, 2, 3); + +statement ok +insert into t (v4, v1, v3, v2) values (4, 1, 3, 2); + +statement ok +insert into t (v4, v2, v1, v3) values (4, 2, 1, 3); + +statement ok +insert into t (v4, v2, v3, v1) values (4, 2, 3, 1); + +statement ok +insert into t (v4, v3, v1, v2) values (4, 3, 1, 2); + +statement ok +insert into t (v4, v3, v2, v1) values (4, 3, 2, 1); + +query I rowsort +select * from t; +---- +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 +1 2 3 4 + +statement ok +drop table t; + + + statement ok create table t (v1 int, v2 int, v3 int); diff --git a/src/batch/src/executor/insert.rs b/src/batch/src/executor/insert.rs index 845e03c7029c0..aee76a2281b47 100644 --- a/src/batch/src/executor/insert.rs +++ b/src/batch/src/executor/insert.rs @@ -96,9 +96,9 @@ impl InsertExecutor { // No need to check for duplicate columns. This is already validated in binder if !&self.column_idxs.is_sorted() { - let mut ordered_cols: Vec = Vec::with_capacity(len); - for idx in &self.column_idxs { - ordered_cols.push(columns[*idx].clone()); + let mut ordered_cols: Vec = columns.clone(); + for (i, idx) in self.column_idxs.iter().enumerate() { + ordered_cols[*idx] = columns[i].clone() } columns = ordered_cols }