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
Less copying and a correctness fix for dotProduct
#60928
Conversation
This is an automated comment for commit 2c0612c with description of existing statuses. It's updated for the latest CI running ⏳ Click here to open a full report in a separate page
Successful checks
|
8de1d1f
to
b79980d
Compare
b79980d
to
245ea0c
Compare
dotProduct
dotProduct
if (typeid_cast<const ColumnConst *>(col_x.get())) | ||
{ | ||
return executeWithLeftArgConst<ResultType, LeftType, RightType>(col_x, col_y, input_rows_count); | ||
} | ||
else if (typeid_cast<const ColumnConst *>(col_y.get())) | ||
{ | ||
return executeWithLeftArgConst<ResultType, RightType, LeftType>(col_y, col_x, input_rows_count); | ||
} | ||
|
||
col_x = col_x->convertToFullColumnIfConst(); | ||
col_y = col_y->convertToFullColumnIfConst(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already know here that col_x
and col_y
are not constant, is there any purpose to do convertToFullColumnIfConst
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove it. Interestingly, even if col_x
and col_y
are not ColumnConst
(i.e. they are ColumnArray
), calling ColumnArray::convertToFullColumnIfConst()
does something:
ColumnPtr ColumnArray::convertToFullColumnIfConst() const
{
/// It is possible to have an array with constant data and non-constant offsets.
/// Example is the result of expression: replicate('hello', [1])
return ColumnArray::create(data->convertToFullColumnIfConst(), offsets);
}
I checked the replicate
and arrayWithConstant
(the only two SQL functions which look like they could create an array with const data), but they they both create non-const data. It looks to me as if ColumnArray::convertToFullColumnIfConst()
can be removed. I might try this in a separate PR.
No performance tests on ARM ran and the logs don't make it really clear what went wrong. In my local testing on ARM (after merging from I'll merge from |
#61519 is missing, merging from |
Risc-v build fails, a fix is on the way. This and this performance tests complain
As far as I see in the logs, this is because a new query was added to
but because of this PR, runtime improved to 0.23 sec which is below the maximum query runtime. Also, local performance test execution on x86 and ARM were good. Let me merge from a |
I was too slow and missed the short timeframe in which the Merge button was not greyed out. Another try, sorry. |
…ed9f6a0d88e3d7ea8eebd238ba9ca Cherry pick #60928 to 24.2: Less copying and a correctness fix for `dotProduct`
Backport #60928 to 24.2: Less copying and a correctness fix for `dotProduct`
This is follow-up to #60202.
There were two problems:
dotProduct
#60202. The reason is some unnecessary unpacking of the const argument, leading to unnecessary memory copies:https://pastila.nl/?000cd311/e87242ca16050916b887bc8f322e4c40#jAGOXIzrL+jNqlY0t8UIUQ==
dotProduct
#60202 (sorry). To my defense, the tests we had before VectorizedotProduct
#60202 didn't trigger it. As a result, this PR must be backported to v24.2.Example: https://fiddle.clickhouse.com/ab8f2641-9381-4ca9-9292-dbeb4be5c644 (run with v24.1 and v24.2)
Reviewer note: This PR includes commits
convertToFullColumn()
/ memcpy in the worst case 10 x 10 = 100 times) by a single call toconvertToFullColumn()
Runtime with const/non-const arguments of array cardinality 150 on a table with 50 million rows (a typical scenario for vector search) goes down from 96.9 sec to 0.32 sec.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Optimized function
dotProduct
to omit unnecessary and expensive memory copies.