Repository navigation
Conversation
|
Workflow [PR], commit [074da97] Summary: ❌
AI ReviewSummaryThis PR wires Tests
Final Verdict
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a correctness issue in the query-plan optimization that lifts ARRAY JOIN by ensuring that expressions which may throw (e.g. intDiv, parsing/casting functions) are not reordered in a way that triggers exceptions on rows that would have been eliminated by empty arrays. It does so by introducing a canThrow() capability on functions and using it during ARRAY JOIN lift-up to either keep throwing expressions in place or insert a notEmpty-based filter before executing lifted throwing expressions.
Changes:
- Add
canThrow(DataTypesWithConstInfo)to function interfaces (IFunction/IFunctionBase) and forward it through adaptors. - Extend
ActionsDAGwith throwing-function detection and use it to controlsplitActionsBeforeArrayJoin, optionally inserting a filter node in the lifted plan. - Add a stateless regression test covering multiple throwing functions around
ARRAY JOIN, including aligned/unaligned and multi-column cases.
Reviewed changes
Copilot reviewed 59 out of 59 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/queries/0_stateless/04041_array_join_with_throwing_function.sql | New stateless test queries covering throwing functions with ARRAY JOIN lift-up scenarios. |
| tests/queries/0_stateless/04041_array_join_with_throwing_function.reference | Expected outputs for the new stateless test. |
| src/Processors/QueryPlan/Optimizations/liftUpArrayJoin.cpp | Insert notEmpty filter before lifted throwing expressions; avoid pushing throwing functions for aligned multi-column ARRAY JOIN. |
| src/Processors/QueryPlan/ArrayJoinStep.h | Expose isUnaligned() for lift-up logic. |
| src/Interpreters/ExpressionActions.cpp | Use ActionsDAG::Node::getArgumentTypesWithConstInfo() for short-circuit suitability checks. |
| src/Interpreters/ActionsDAG.h | Add Node::getArgumentTypesWithConstInfo(), hasThrowingFunctions(), and extend splitActionsBeforeArrayJoin() signature. |
| src/Interpreters/ActionsDAG.cpp | Implement argument const-info extraction, throwing-function detection, and throwing-aware array-join splitting. |
| src/Functions/widthBucket.cpp | Mark function as throwing via canThrow(). |
| src/Functions/vectorFunctions.cpp | Propagate canThrow() through tuple/array wrapper function. |
| src/Functions/toFixedString.h | Mark function as throwing via canThrow(). |
| src/Functions/toDecimalString.cpp | Mark function as throwing via canThrow(). |
| src/Functions/throwIf.cpp | Mark function as throwing via canThrow(). |
| src/Functions/space.cpp | Mark function as throwing via canThrow(). |
| src/Functions/sleep.cpp | Mark function as throwing via canThrow(). |
| src/Functions/seriesDecomposeSTL.cpp | Mark function as throwing via canThrow(). |
| src/Functions/s2CellsIntersect.cpp | Mark function as throwing via canThrow(). |
| src/Functions/repeat.cpp | Mark function as throwing via canThrow(). |
| src/Functions/readWkt.cpp | Mark functions as throwing via canThrow(). |
| src/Functions/readWkb.cpp | Mark functions as throwing via canThrow(). |
| src/Functions/parseTimeDelta.cpp | Mark function as throwing via canThrow(). |
| src/Functions/parseReadableSize.cpp | Make canThrow() depend on exception-mode behavior. |
| src/Functions/parseDateTime.cpp | Mark function as throwing via canThrow(). |
| src/Functions/padString.cpp | Mark function as throwing via canThrow(). |
| src/Functions/jsonMergePatch.cpp | Mark function as throwing via canThrow(). |
| src/Functions/isIPAddressInRange.cpp | Mark function as throwing via canThrow(). |
| src/Functions/h3kRing.cpp | Mark function as throwing via canThrow(). |
| src/Functions/geohashEncode.cpp | Mark function as throwing via canThrow(). |
| src/Functions/geoToH3.cpp | Mark function as throwing via canThrow(). |
| src/Functions/generateSerialID.cpp | Mark function as throwing via canThrow(). |
| src/Functions/convertCharset.cpp | Mark function as throwing via canThrow(). |
| src/Functions/conv.cpp | Mark function as throwing via canThrow(). |
| src/Functions/clamp.cpp | Mark function as throwing via canThrow(). |
| src/Functions/bech32.cpp | Mark encode/decode functions as throwing via canThrow(). |
| src/Functions/array/range.cpp | Mark function as throwing via canThrow(). |
| src/Functions/array/mapPopulateSeries.cpp | Mark function as throwing via canThrow(). |
| src/Functions/array/arrayZip.cpp | Mark function as throwing via canThrow(). |
| src/Functions/array/arrayWithConstant.cpp | Mark function as throwing via canThrow(). |
| src/Functions/array/arrayShingles.cpp | Mark function as throwing via canThrow(). |
| src/Functions/array/arrayShiftRotate.cpp | Mark function as throwing via canThrow(). |
| src/Functions/array/arrayReduceInRanges.cpp | Mark function as throwing via canThrow(). |
| src/Functions/array/arrayReduce.cpp | Mark function as throwing via canThrow(). |
| src/Functions/array/arrayNormalizedGini.cpp | Mark function as throwing via canThrow(). |
| src/Functions/array/arrayFold.cpp | Mark function as throwing via canThrow(). |
| src/Functions/array/arrayEnumerateRanked.h | Mark function as throwing via canThrow(). |
| src/Functions/array/arrayDotProduct.cpp | Mark function as throwing via canThrow(). |
| src/Functions/array/arrayDistance.cpp | Mark function as throwing via canThrow(). |
| src/Functions/array/FunctionArrayMapped.h | Mark function as throwing via canThrow(). |
| src/Functions/ULIDStringToDateTime.cpp | Mark function as throwing via canThrow(). |
| src/Functions/TimeSeries/timeSeriesThrowDuplicateSeriesIf.cpp | Mark function as throwing via canThrow(). |
| src/Functions/IFunctionAdaptors.h | Forward canThrow() from IFunction to IFunctionBase. |
| src/Functions/IFunction.h | Introduce canThrow() API on function interfaces. |
| src/Functions/HMAC.cpp | Mark function as throwing via canThrow(). |
| src/Functions/FunctionsRound.h | Implement canThrow() based on non-constant scale argument. |
| src/Functions/FunctionsConversion.h | Add canThrow() to conversion/cast-related functions based on modes/argument types. |
| src/Functions/FunctionsCodingIP.cpp | Make canThrow() depend on exception-mode behavior. |
| src/Functions/FunctionsAES.h | Mark encrypt/decrypt as throwing via canThrow(). |
| src/Functions/FunctionFile.cpp | Mark function as throwing via canThrow(). |
| src/Functions/FunctionBinaryArithmetic.h | Add canThrow() for arithmetic operations (incl. intDiv/modulo/decimal division cases). |
| src/Functions/FunctionBaseXXConversion.h | Add canThrow() derived from decode error-handling mode. |
|
This is the list of functions where |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 707/1434 (49.30%) · Uncovered code |
|
Dear @Fgrtue, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
Algunenano
left a comment
There was a problem hiding this comment.
I don't understand this PR. AFAICT every function can throw (memory, timeouts, etc), so it's "pointless"
Maybe The idea was that this is useful to know if an optimization is safe or not. For example filter push down or array join lift up above an expression could make the function throw on a row that would have been filtered out: https://fiddle.clickhouse.com/4ee100ce-1c12-42e2-ba99-f6d2bd342e77. |
|
@Algunenano here is another example for the situation which @m-selmi describes: |
|
All these seem to come from a misunderstanding of SQL. SQL is a declarative language, the engine decides what and how to execute things. Then somebody goes and say functions are executed from left to right, from inner to outer, and everything breaks |
Yes I agree with this. A point that is slightly problematic is that from a user perspective this is a behavior that can be toggled with a setting (that from first glance does not affect the result) and can break a query that used to work. But as said, I would also be reluctant to do this if it would disable useful optimizations, and I also know that most systems accept this. So I would be fine with re-discussing or abandoning this. FYI there was a relevant discussion here. |
|
Dear @Fgrtue, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
|
Dear @Fgrtue, you haven't been active on this PR for 30 days. You will be unassigned. Will you continue working on it? If so, please feel free to reassign yourself. |
This PR adds a
canThrowinterface to all functions. canThrow returns true if the function might throw during execution on the data. If a function throws independently of the data then that is seen as a formatting/structural issue with the query.This can be useful for determining wether we can apply some optimizations or not (e.g. changing the order of some operations, like ARRAY JOINs and FILTERs)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Add canThrow interface to all functions that throw an exception during execution depending on its input data.
Documentation entry for user-facing changes