Preserve signed subtraction results in select expressions - #4550
Preserve signed subtraction results in select expressions#4550sanikolaev wants to merge 1 commit into
Conversation
8621173 to
dd37e04
Compare
|
As the patch changed DWORD into in64 result set for negate \ substract expression The cases need 1000 runs of the queries like:
Could be better to explicitly set cutoff=0 to make sure the optimizer does not early exit after filled the default limit=20 matches. |
|
Clarification on:
Example: Imagine you use Manticore to schedule something in the future. When the time comes, an event should happen. The easiest way to do it is The workaround is quite ugly: In the PR: |
This script was run in docker images DetailsResults:
So there's a difference for 2 queries, but it should be taken into consideration that the results for them differ since in the master branch while in the PR branch they return results: |
|
Results with
|
|
As discussed in Slack, it makes sense to test a query like Updated table:
So still no sign of a performance degradation. |
| DECLARE_UNARY_TRAITS ( Expr_Sint_c ) | ||
| float Eval ( const CSphMatch & tMatch ) const final { return (float)Int64Eval ( tMatch ); } | ||
| int IntEval ( const CSphMatch & tMatch ) const final { return (int)Int64Eval ( tMatch ); } | ||
| int64_t Int64Eval ( const CSphMatch & tMatch ) const final { return INT64FIRST; } | ||
| }; |
There was a problem hiding this comment.
too complex and redundand.
Original line can be just replaced to
DECLARE_UNARY_INT ( Expr_Sint_c, INT64FIRST, INT64FIRST, INT64FIRST )
(that is - simple change INTFIRST to INT64FIRST triple.
| SELECT *, 1-2 AS diff FROM test WHERE id=10; | ||
| SELECT *, aa-4 AS diff FROM test ORDER BY id ASC; | ||
| SELECT *, 1-aa AS diff FROM test ORDER BY id ASC; | ||
| SELECT *, aa-(aa+1) AS diff FROM test ORDER BY id ASC; | ||
| SELECT *, (1-2)+aa AS diff FROM test ORDER BY id ASC; | ||
| SELECT *, (1-2)-(3-4) AS diff FROM test WHERE id=10; |
There was a problem hiding this comment.
suggest to add:
SELECT *, 1-2+2000000000+1000000001 AS diff FROM test WHERE id=10;
SELECT *, aa-4+2000000000+1000000001 AS diff FROM test ORDER BY id ASC;
SELECT *, 1-aa+2000000000+1000000001 AS diff FROM test ORDER BY id ASC;
SELECT *, aa-(aa+1)+2000000000+1000000001 AS diff FROM test ORDER BY id ASC;
SELECT *, (1-2)+aa+2000000000+1000000001 AS diff FROM test ORDER BY id ASC;
SELECT *, (1-2)-(3-4)+2000000000+1000000001 AS diff FROM test WHERE id=10;
after this block. Comparing to current master, it also reveals prominent difference in result
|
It might make sense to use functions like datediff() (or create a new one if this one doesn't fit) for operations with dates. |
I suggest we create a new function Specification:Implement a new date/time function: Behavior
Arguments
Return type
Examples Notes
|
Problem
A simple query such as:
could return:
instead of:
This is especially annoying when you need to compare something with
now(), where any positive number means the value you're comparing is greater than or less thannow(), but you always get a positive number.Fix
Special-case
-inExprParser_t::AddNodeOp():GetWidestRet()to determine the arithmetic familySPH_ATTR_INTEGER, promote the result type toSPH_ATTR_BIGINTThis preserves signed output for negative subtraction results while keeping the rest of the arithmetic type flow unchanged.