Short syntax for UNLIST with IN operator#8878
Short syntax for UNLIST with IN operator#8878ChudaykinAlex wants to merge 2 commits intoFirebirdSQL:masterfrom
Conversation
One of the following options would be acceptable to me:
|
|
Considering that such a construction will be performed by the Hash semi-join algorithm or, at best, via SELECT * FROM EMPLOYEE WHERE EMP_NO IN UNLIST('2,4,5,7,11')transform to SELECT * FROM EMPLOYEE
WHERE EMP_NO IN (SELECT N FROM UNLIST('2,4,5,7,11') AS U(N));vs SELECT * FROM EMPLOYEE
WHERE EMP_NO IN (SELECT N FROM UNLIST('2,4,5,7,11' RETURNING BIGINT) AS U(N));or best choise SELECT * FROM EMPLOYEE E
JOIN (SELECT DISTINCT N FROM UNLIST('2,4,5,7,11') AS U(N)) T ON T.N = E.EMP_NO;vs SELECT * FROM EMPLOYEE E
JOIN (SELECT DISTINCT N FROM UNLIST('2,4,5,7,11' RETURNING BIGINT) AS U(N)) T ON T.N = E.EMP_NO;In either case, it is best to avoid wide buffer or wide external sort. |
The type of function's parameter is known at compile or at least run time, there is no point to return output string longer than input. |
Input is a blob which may contain strings (delimited or not) of any length. |
|
smallint, int, bigint - bigint |
Why not |
You can cast it to int128. The main thing is not to make varchars too large by default. If it's really necessary, you can always explicitly set the type in returning. |
Short syntax for UNLIST with IN operator
Summary
Added a simplified syntax form for using UNLIST with the IN operator.
Instead of:
You can now write:
Changes
IN UNLIST(...), an internal subquery with correlation name and column name is automatically created.Open Questions
1. Automatic RETURNING type inference
Currently, UNLIST returns VARCHAR(1024) by default. This works fine for comparison with INT/BIGINT without issues, but what if the query contains
VERY_LONG_VARCHAR IN UNLIST(...)? The default type might cause an exception.Question: Should we implement automatic RETURNING type inference based on the left operand type in comparison? If RETURNING is explicitly specified, use it; otherwise, infer from context.
2. Issue with automatic type detection
Found a problematic case:
It will try to convert the number to INT and fail with an overflow error.
Possible solutions: