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

Fix bitShift* functions with both constant arguments #50343

Merged
merged 1 commit into from Jun 1, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Functions/FunctionBinaryArithmetic.h
Expand Up @@ -1741,7 +1741,7 @@ ColumnPtr executeStringInteger(const ColumnsWithTypeAndName & arguments, const A
OpImpl::template processString<OpCase::Vector>(in_vec.data(), col_left->getOffsets().data(), &value, out_vec, out_offsets, 1);
}

return ColumnConst::create(std::move(col_res), col_left->size());
return ColumnConst::create(std::move(col_res), col_left_const->size());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't it useDefaultImplementationForConstants?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is even separarate function FunctionBinaryArithmeticWithConstants for working with constants. I don't know why we have it, probably it's optimized somehow

}
else if (!col_left_const && !col_right_const && col_right)
{
Expand Down
@@ -0,0 +1,7 @@
\0hdhdfhp
\0hdhdfhp
\0hdhdfhp
\0hdhdfhp
\0hdhdfhp
\0bdf
13000
22 changes: 22 additions & 0 deletions tests/queries/0_stateless/02766_bitshift_with_const_arguments.sql
@@ -0,0 +1,22 @@
SELECT bitShiftLeft(if(number = NULL, '14342', '4242348'), 1) FROM numbers(1);
SELECT bitShiftLeft(if(number = NULL, '14342', '4242348'), 1) FROM numbers(3);
SELECT bitShiftLeft(if(materialize(NULL), '14342', '4242348'), 1) FROM numbers(1);
SELECT bitShiftLeft(if(materialize(1), '123', '123'), 1) from numbers(1);


-- The next queries are from fuzzer that found the bug:
DROP TABLE IF EXISTS t0;
DROP TABLE IF EXISTS t1;
CREATE TABLE t0 (vkey UInt32, pkey UInt32, c0 UInt32) engine = TinyLog;
CREATE TABLE t1 (vkey UInt32) ENGINE = AggregatingMergeTree ORDER BY vkey;
INSERT INTO t0 VALUES (15, 25000, 58);
SELECT ref_5.pkey AS c_2_c2392_6 FROM t0 AS ref_5 WHERE 'J[' < multiIf(ref_5.pkey IN ( SELECT 1 ), bitShiftLeft(multiIf(ref_5.c0 > NULL, '1', ')'), 40), NULL);
DROP TABLE t0;
DROP TABLE t1;

DROP TABLE IF EXISTS t5;
CREATE TABLE t5 (vkey UInt32, pkey UInt32, c18 Float32, c19 UInt32) ENGINE = Log;
INSERT INTO t5 VALUES (3, 13000, 73.90, 83);
SELECT subq_0.pkey as c_1_c1193_15 FROM t5 AS subq_0 WHERE sipHash128(0, subq_0.c18, bitShiftRight(case when false then (sipHash128(subq_0.pkey, subq_0.c18, 'S')) else '1' end, 0)) is not null;
DROP TABLE t5;