Skip to content

Conversation

@hawkfish
Copy link
Contributor

Instead of trying to track the combinatorial explosion of ordering types for DECIMAL arguments, just return a function that will force the binder to inject casts as if there were no custom bind function.

Instead of trying to track the combinatorial explosion of ordering types
for DECIMAL arguments, just return a function that will force the binder
to inject casts as if there were no custom bind function.
@carlopi
Copy link
Contributor

carlopi commented Feb 19, 2024

I was trying this out, bumped against this problem (that is independent, so can be addressed separately):

CREATE TABLE T (z HUGEINT);
insert into t values (-168123123123200005565479978461862821890);
insert into t values (-168123123123200005565479978461862821889);
insert into t values (-168123123123200005565479978461862821888);
insert into t values (-168123123123200005565479978461862821893);
SELECT min(z) - arg_min(z,z) FROM t;
-3

Connected to this, are casts performed by this PR always information-preserving?

@Mytherin
Copy link
Collaborator

Yes casting to double is lossy for numerics - it would be better to add the hugeint option to the switch. Good catch @carlopi

The cast from HUGEINT to DOUBLE is lossy and can generate incorrect results.

fixes: duckdblabs-duckdb-internal#1294
@github-actions github-actions bot marked this pull request as draft February 19, 2024 17:43
@hawkfish
Copy link
Contributor Author

Combined both into this PR since it was small and @carlopi had such a nice test!

@hawkfish hawkfish marked this pull request as ready for review February 21, 2024 19:17
Copy link
Contributor

@carlopi carlopi left a comment

Choose a reason for hiding this comment

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

I think in a nicer world GetArgMinMaxFunctionBy should never throw and have some other way to communicate it can't handle a type (given previously we were building functions that would only end up throwing), and after this PR also potentially (say with some more changes in).

Also, I am curious how we can guarantee that a Cast preserves information, I am not sure if we have that information (or maybe it's implicitly guaranteed?).

BUT, both problems were there before, and this PR is a clear improvement, so I think it might be just fine to merge this (after adding back at least INT16).

Comment on lines -327 to -336
case PhysicalType::INT8:
return GetArgMinMaxFunctionInternal<OP, ARG_TYPE, int8_t>(by_type, type);
case PhysicalType::INT16:
return GetArgMinMaxFunctionInternal<OP, ARG_TYPE, int16_t>(by_type, type);
case PhysicalType::INT32:
return GetArgMinMaxFunctionInternal<OP, ARG_TYPE, int32_t>(by_type, type);
case PhysicalType::INT64:
return GetArgMinMaxFunctionInternal<OP, ARG_TYPE, int64_t>(by_type, type);
case PhysicalType::FLOAT:
return GetArgMinMaxFunctionInternal<OP, ARG_TYPE, float>(by_type, type);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would avoid removing INT16 (in particular) since it's used by GetDecimalArgMinMaxFunction. Also INT8 and FLOAT probably are fine staying.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed them to reduce the code footprint back to what it was before I made the fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The impact on runtime memory is minimal because we only store one value. There is some casting overhead but that is the same as for non-DECIMAL types.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, forgot it was in the connected PR. All cool then.

@Mytherin
Copy link
Collaborator

Thanks! LGTM

@hawkfish hawkfish deleted the fuzzer-decimal-order branch February 27, 2024 02:41
github-actions bot pushed a commit to duckdb/duckdb-r that referenced this pull request Mar 15, 2024
Merge pull request duckdb/duckdb#10742 from hawkfish/fuzzer-decimal-order
Merge pull request duckdb/duckdb#10832 from krlmlr/f-setup-python-v5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants