From fc745dbfa15d8cea57f64f07bb874534588d786d Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Thu, 15 Oct 2015 19:10:08 +0300 Subject: [PATCH] dbms: fixed error with removing temporary columns [#METR-18448]. --- .../DB/Interpreters/evaluateMissingDefaults.h | 2 +- dbms/src/Interpreters/ExpressionActions.cpp | 5 ++++ .../00253_insert_recursive_defaults.reference | 2 ++ .../00253_insert_recursive_defaults.sql | 23 +++++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 dbms/tests/queries/0_stateless/00253_insert_recursive_defaults.reference create mode 100644 dbms/tests/queries/0_stateless/00253_insert_recursive_defaults.sql diff --git a/dbms/include/DB/Interpreters/evaluateMissingDefaults.h b/dbms/include/DB/Interpreters/evaluateMissingDefaults.h index f15c69415af..8a65b04fd0c 100644 --- a/dbms/include/DB/Interpreters/evaluateMissingDefaults.h +++ b/dbms/include/DB/Interpreters/evaluateMissingDefaults.h @@ -36,7 +36,7 @@ inline void evaluateMissingDefaults(Block & block, return; /** ExpressionAnalyzer eliminates "unused" columns, in order to ensure their safety - * we are going to operate on a copy instead of the original block */ + * we are going to operate on a copy instead of the original block */ Block copy_block{block}; /// evaluate default values for defaulted columns ExpressionAnalyzer{default_expr_list, context, {}, required_columns}.getActions(true)->execute(copy_block); diff --git a/dbms/src/Interpreters/ExpressionActions.cpp b/dbms/src/Interpreters/ExpressionActions.cpp index 201ed096b4a..86f2647a01f 100644 --- a/dbms/src/Interpreters/ExpressionActions.cpp +++ b/dbms/src/Interpreters/ExpressionActions.cpp @@ -781,6 +781,9 @@ void ExpressionActions::finalize(const Names & output_columns) for (const auto & name : action.prerequisite_names) ++columns_refcount[name]; + + for (const auto & name_alias : action.projection) + ++columns_refcount[name_alias.first]; } Actions new_actions; @@ -809,6 +812,8 @@ void ExpressionActions::finalize(const Names & output_columns) for (const auto & name : action.prerequisite_names) process(name); + + /// Для projection тут нет уменьшения refcount, так как действие project заменяет имена у столбцов, по сути, уже удаляя их под старыми именами. } actions.swap(new_actions); diff --git a/dbms/tests/queries/0_stateless/00253_insert_recursive_defaults.reference b/dbms/tests/queries/0_stateless/00253_insert_recursive_defaults.reference new file mode 100644 index 00000000000..b86bad6651d --- /dev/null +++ b/dbms/tests/queries/0_stateless/00253_insert_recursive_defaults.reference @@ -0,0 +1,2 @@ +1 0 0 +2015-01-01 2015-01-01 01:02:03 111 123 456 789 456 9434005089510819894 9434005089510819894 diff --git a/dbms/tests/queries/0_stateless/00253_insert_recursive_defaults.sql b/dbms/tests/queries/0_stateless/00253_insert_recursive_defaults.sql new file mode 100644 index 00000000000..355408d2899 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00253_insert_recursive_defaults.sql @@ -0,0 +1,23 @@ +DROP TABLE IF EXISTS test.defaults; +CREATE TABLE test.defaults (a UInt8, b DEFAULT 0, c DEFAULT identity(b)) ENGINE = Memory; +INSERT INTO test.defaults (a) VALUES (1); +SELECT * FROM test.defaults; +DROP TABLE test.defaults; + +DROP TABLE IF EXISTS test.elog_cut; +CREATE TABLE test.elog_cut +( + date Date DEFAULT toDate(uts), + uts DateTime, + pr UInt64, + ya_uid UInt64, + adf_uid UInt64, + owner_id UInt32, + eff_uid UInt64 DEFAULT if(adf_uid != 0, adf_uid, ya_uid), + page_session UInt64 DEFAULT cityHash64(eff_uid, pr), + sample_key UInt64 ALIAS page_session +) ENGINE = MergeTree(date, cityHash64(adf_uid, ya_uid, pr), (owner_id, date, cityHash64(adf_uid, ya_uid, pr)), 8192); + +INSERT INTO test.elog_cut (uts, pr, ya_uid, adf_uid, owner_id) VALUES ('2015-01-01 01:02:03', 111, 123, 456, 789); +SELECT date, uts, pr, ya_uid, adf_uid, owner_id, eff_uid, page_session, sample_key FROM test.elog_cut; +DROP TABLE test.elog_cut;