diff --git a/dbms/src/Flash/Coprocessor/DAGStorageInterpreter.cpp b/dbms/src/Flash/Coprocessor/DAGStorageInterpreter.cpp index d803bf8ddd1..e8e82c6137d 100644 --- a/dbms/src/Flash/Coprocessor/DAGStorageInterpreter.cpp +++ b/dbms/src/Flash/Coprocessor/DAGStorageInterpreter.cpp @@ -374,10 +374,10 @@ void DAGStorageInterpreter::executeImpl(DAGPipeline & pipeline) FAIL_POINT_PAUSE(FailPoints::pause_after_copr_streams_acquired); FAIL_POINT_PAUSE(FailPoints::pause_after_copr_streams_acquired_once); - /// handle timezone/duration cast for local and remote table scan. - executeCastAfterTableScan(remote_read_streams_start_index, pipeline); /// handle generated column if necessary. executeGeneratedColumnPlaceholder(remote_read_streams_start_index, generated_column_infos, log, pipeline); + /// handle timezone/duration cast for local and remote table scan. + executeCastAfterTableScan(remote_read_streams_start_index, pipeline); recordProfileStreams(pipeline, table_scan.getTableScanExecutorID()); /// handle pushed down filter for local and remote table scan. @@ -1034,7 +1034,9 @@ std::tuple> DAGStorageIn } Names required_columns_tmp; + required_columns_tmp.reserve(table_scan.getColumnSize()); NamesAndTypes source_columns_tmp; + source_columns_tmp.reserve(table_scan.getColumnSize()); std::vector need_cast_column; need_cast_column.reserve(table_scan.getColumnSize()); String handle_column_name = MutableSupport::tidb_pk_column_name; @@ -1054,6 +1056,7 @@ std::tuple> DAGStorageIn const auto & col_name = GeneratedColumnPlaceholderBlockInputStream::getColumnName(i); generated_column_infos.push_back(std::make_tuple(i, col_name, data_type)); source_columns_tmp.emplace_back(NameAndTypePair{col_name, data_type}); + need_cast_column.push_back(ExtraCastAfterTSMode::None); continue; } // Column ID -1 return the handle column diff --git a/tests/fullstack-test/expr/generated_column.test b/tests/fullstack-test/expr/generated_column.test new file mode 100644 index 00000000000..6d1697e36c1 --- /dev/null +++ b/tests/fullstack-test/expr/generated_column.test @@ -0,0 +1,45 @@ +# Copyright 2022 PingCAP, Ltd. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +mysql> drop table if exists test.t; +mysql> CREATE TABLE test.t (`COL102` float DEFAULT NULL, `COL103` float DEFAULT NULL, `COL1` float GENERATED ALWAYS AS ((`COL102` DIV 10)) VIRTUAL, `COL2` varchar(20) COLLATE utf8mb4_bin DEFAULT NULL, `COL4` datetime DEFAULT NULL, `COL3` bigint DEFAULT NULL, `COL5` time DEFAULT NULL, KEY `UK_COL1` (`COL1`) /*!80000 INVISIBLE */) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +mysql> insert into test.t (COL102, COL103, COL2, COL4, COL3, COL5) values (NULL, NULL, NULL, NULL, NULL, NULL); +mysql> insert into test.t (COL102, COL103, COL2, COL4, COL3, COL5) values (NULL, NULL, 'r2Ic', NULL, NULL, NULL); +mysql> insert into test.t (COL102, COL103, COL2, COL4, COL3, COL5) values (NULL, NULL, NULL, NULL, NULL, '700:11:11.123456'); +mysql> alter table test.t set tiflash replica 1; +func> wait_table test t + +mysql> set tidb_isolation_read_engines='tiflash'; select * from test.t where col2 = 'r2Ic'; ++--------+--------+------+------+------+------+------+ +| COL102 | COL103 | COL1 | COL2 | COL4 | COL3 | COL5 | ++--------+--------+------+------+------+------+------+ +| NULL | NULL | NULL | r2Ic | NULL | NULL | NULL | ++--------+--------+------+------+------+------+------+ + +mysql> set tidb_isolation_read_engines='tiflash'; select * from test.t where col1 is NULL or col2 = 'r2Ic'; ++--------+--------+------+------+------+------+-----------+ +| COL102 | COL103 | COL1 | COL2 | COL4 | COL3 | COL5 | ++--------+--------+------+------+------+------+-----------+ +| NULL | NULL | NULL | NULL | NULL | NULL | NULL | +| NULL | NULL | NULL | r2Ic | NULL | NULL | NULL | +| NULL | NULL | NULL | NULL | NULL | NULL | 700:11:11 | ++--------+--------+------+------+------+------+-----------+ + +mysql> set tidb_isolation_read_engines='tiflash'; select hour(col5) from test.t where col2 is NULL; ++------------+ +| hour(col5) | ++------------+ +| NULL | +| 700 | ++------------+