Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB::Exception: Newly added column B has a default expression, so adding expressions that use it to the sorting key is forbidden. #13592

Open
den-crane opened this issue Aug 11, 2020 · 2 comments

Comments

@den-crane
Copy link
Contributor

den-crane commented Aug 11, 2020

create table mx(A Int64) Engine=MergeTree order by A;

alter table mx add column B Int64 default 111, modify order by (A,B);

DB::Exception: Newly added column B has a default expression, so adding expressions that use it to the sorting key is forbidden.

This behaviour has no sense. I don't see a reason why it's forbidden.

Moreover there is a workaround:

alter table mx add column B Int64 , modify order by (A,B);
alter table mx modify column B default 111;
@filimonov
Copy link
Contributor

Non constant DEFAULT can require reordering of existing data, that's why it's forbidden.

Constant DEFAULTs actually may be allowed.

@jlazdw
Copy link

jlazdw commented Nov 20, 2020

Hi: I have an application that requires adding new columns with Constant Default Values and these columns are used for order-by key expression. Given the above comment on "Constant DEFAULTs actually may be allowed.", can the current code in MergeTreeData.cpp, https://github.com/ClickHouse/ClickHouse/blob/master/src/Storages/MergeTree/MergeTreeData.cpp#L364, be fixed to reflect the above logic, that is, if the default expression of the column only contains constant expression, then no exception gets thrown. Currently, the code has:

if (new_metadata.columns.getDefaults().count(col)) throw Exception("Newly added column " + backQuoteIfNeed(col) + " has a default expression, so adding " "expressions that use it to the sorting key is forbidden", ErrorCodes::BAD_ARGUMENTS)

If the fix is feasible, when can I get it from the future ClickHouse release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants