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

Improve performance of "reinterpretAsFixedString" function #9342

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 16 additions & 2 deletions dbms/src/Functions/FunctionsReinterpret.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class FunctionReinterpretAsFixedStringImpl : public IFunction
throw Exception("Cannot reinterpret " + type.getName() + " as FixedString because it is not fixed size and contiguous in memory", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
}

void executeToFixedString(const IColumn & src, ColumnFixedString & dst, size_t n)
void NO_INLINE executeToFixedString(const IColumn & src, ColumnFixedString & dst, size_t n)
{
size_t rows = src.size();
ColumnFixedString::Chars & data_to = dst.getChars();
Expand All @@ -133,6 +133,15 @@ class FunctionReinterpretAsFixedStringImpl : public IFunction
}
}

void NO_INLINE executeContiguousToFixedString(const IColumn & src, ColumnFixedString & dst, size_t n)
{
size_t rows = src.size();
ColumnFixedString::Chars & data_to = dst.getChars();
data_to.resize(n * rows);

memcpy(data_to.data(), src.getRawData().data, data_to.size());
}

bool useDefaultImplementationForConstants() const override { return true; }

void executeImpl(Block & block, const ColumnNumbers & arguments, size_t result, size_t /*input_rows_count*/) override
Expand All @@ -141,7 +150,12 @@ class FunctionReinterpretAsFixedStringImpl : public IFunction
MutableColumnPtr dst = block.getByPosition(result).type->createColumn();

if (ColumnFixedString * dst_concrete = typeid_cast<ColumnFixedString *>(dst.get()))
executeToFixedString(src, *dst_concrete, dst_concrete->getN());
{
if (src.isFixedAndContiguous() && src.sizeOfValueIfFixed() == dst_concrete->getN())
executeContiguousToFixedString(src, *dst_concrete, dst_concrete->getN());
else
executeToFixedString(src, *dst_concrete, dst_concrete->getN());
}
else
throw Exception("Illegal column " + src.getName() + " of argument of function " + getName(), ErrorCodes::ILLEGAL_COLUMN);

Expand Down