Fix possible crash for SELECT from Merge table with optimize_monotonous_functions_in_order_by eanbled.

This commit is contained in:
Nikolai Kochetov 2022-09-23 18:37:25 +00:00
parent 0414d95878
commit 1c67437aa4
2 changed files with 7 additions and 0 deletions

View File

@ -70,6 +70,9 @@ public:
if (!pos)
return false;
if (*pos >= tables.size())
return false;
if (auto data_type_and_name = tables[*pos].columns.tryGetByName(identifier->shortName()))
{
arg_data_type = data_type_and_name->type;

View File

@ -13,3 +13,7 @@ SET optimize_monotonous_functions_in_order_by = 1;
EXPLAIN SYNTAX SELECT * FROM t_02147 ORDER BY toStartOfHour(date), v;
EXPLAIN SYNTAX SELECT * FROM t_02147_dist ORDER BY toStartOfHour(date), v;
EXPLAIN SYNTAX SELECT * FROM t_02147_merge ORDER BY toStartOfHour(date), v;
drop table t_02147;
CREATE TABLE t_02147 (date DateTime, v UInt32) ENGINE = MergeTree ORDER BY date;
select *, toString(t.v) as s from t_02147_merge as t order by date, s;