Repository navigation
Fix stack overflow in quantileDD merge - #86560
Conversation
|
CLA signed. |
|
Workflow [PR], commit [a9e70da] Summary: ❌
|
|
@raphael-theriault-swi Thanks for the PR!
Is it possible to write a SQL testcase for this? |
|
@shankar-iyer Yeah will do, sorry I was waiting for the CCLA to be signed on our side :) |
|
|
|
@shankar-iyer Added SQL test as requested Edit: It appears I'm not able to reproduce the bug with an SQL test. For reference this was extremely hard to track down as the bug was triggered by an L2 merge and corrupted our database, which we only realized when L3 merges started failing, which forced us to clear the affected column. So I don't have any real data for an SQL reproduction, but I was still able to trigger a segfault with synthetic data in the |
Thanks! I will review in the next 2 days. |
Backport #86560 to 25.9: Fix stack overflow in quantileDD merge
Backport #86560 to 25.7: Fix stack overflow in quantileDD merge
Backport #86560 to 25.8: Fix stack overflow in quantileDD merge
Backport #86560 to 25.3: Fix stack overflow in quantileDD merge
The current
quantileDDmerge implementation can recurse infinitely and cause a stack overflow when the computed gammas are not perfectly equal. This can be triggered by manually submitting data with varying relative accuracy as theAggregateFunctionstate. It could also feasibly be triggered without doing so if a database were migrated to different hardware where the computed gamma for the same relative accuracy wasn't bitwise identical to the one on the previous hardware.This happens because when merging two states where the gammas are not bitwise identical, the implementation changes the gamma of one of the states to match the other, then recurses. However, it's possible that at the end of the process (due to floating point imprecision) the two states still don't have bitwise identical gammas, which causes the same path to be taken and the function to recurse until it overflows the stack.
This logic was changed to accept a margin of error (where the margin is larger for lower precision gammas) instead of checking for bitwise equality, so that two states with gammas that are not bitwise identical but are the same in practice will get merged as is. A test was added which passes with the new fixes but segfaults without.
I also had format-on-save enabled which caused a bit of noise, I can revert the formatting only changes if requested, I just figured I'd leave them in given they only affect a few files and the diff is still readable.
Changelog category (leave one):
Changelog entry (a [user-readable short description]
Fixes a crash where some valid user-submitted data to an
AggregateFunction(quantileDD)column could cause merges to recurse infinitely.