Luka Zdravic created SPARK-62247:
------------------------------------
Summary: Use the cursor scan for ASOF joins with a tolerance
Key: SPARK-62247
URL: https://issues.apache.org/jira/browse/SPARK-62247
Project: Spark
Issue Type: Improvement
Components: SQL
Affects Versions: 4.4.0
Reporter: Luka Zdravic
SortMergeAsOfJoinExec has two scans. The cursor scan reads the right side once.
The buffered scan reads each right key group again from the top for every left
row, so its cost grows with the square of the group size.
A join with a tolerance always takes the buffered scan:
- DataFrame joinAsOf with a tolerance builds: l >= r AND r >= l - tolerance
- SQL writes the tolerance as an ON filter: MATCH_CONDITION (l.t >= r.t) ON r.t
>= l.t - 1000
The cursor scan is used only for one comparison of the two sort keys with no ON
filter.
Example: one key group, 80,000 rows per side, local[4], backward DataFrame
join, tolerance 1000: 14.6 s. The same join without a tolerance: 0.11 s.
Proposal: for backward and forward joins, move the cursor on the key comparison
alone, then check the tolerance only on the closest right row. If the closest
row is too far, every other row is farther. This holds only for a "not too far"
limit, so any other ON filter keeps the buffered scan. Rows, NULL handling and
errors stay the same.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]