trino icon indicating copy to clipboard operation
trino copied to clipboard

Use SortedPositionLink for BETWEEN joins

Open sopel39 opened this issue 3 years ago • 5 comments

Currently, we use inequality joins only for expressions like probe_symbol < build_symbol AND probe_symbol + 1 > build_symbol, but we don't inequality join for probe_symbol <> build_symbol. Affected queries:

tpch/q21
tpcds/q16
tpcds/q19
tpcds/q46
tpcds/q64
tpcds/q68
tpcds/q94
tpcds/q95

It would be great to know how big build side per hash entry in these joins in order to determine if such optimization makes sense. cc @skrzypo987 @lukasz-stec

sopel39 avatar Apr 22 '22 11:04 sopel39

@sopel39 Is this issue still available to get a ticket?

WinkerDu avatar Sep 22 '22 02:09 WinkerDu

@WinkerDu sure

sopel39 avatar Sep 22 '22 08:09 sopel39

@sopel39 I've check the code in SortExpressionVisitor (https://github.com/trinodb/trino/blob/master/core/trino-main/src/main/java/io/trino/sql/planner/SortExpressionExtractor.java#L95), I'd like to confirm what this issue suggests to do.

  1. visitComparisonExpression doesn't handle NOT_EQUAL (<>) operator, we could add it to case match conditions.
  2. visitBetweenPredicate can only handle one side of BETWEEN (GREATER_THAN_OR_EQUAL or LESS_THAN_OR_EQUAL), we could optimize it and let it handle both sides of BETWEEN as conjunct expressions

Correct me if I am wrong, and can you assign this issue to me if appropriate, thank you.

WinkerDu avatar Oct 07 '22 07:10 WinkerDu

@WinkerDu That looks correct

sopel39 avatar Oct 12 '22 07:10 sopel39

this looks interesting and should benefit the join queries. as the old PR is not active, can raise another PR, to keep it cleaner with the latest code. Will refer the the old PR (https://github.com/trinodb/trino/pull/14598).

does that sound good @sopel39 @mosabua?

osscm avatar May 21 '24 21:05 osscm

Fixed via https://github.com/trinodb/trino/pull/22521

sopel39 avatar Jul 23 '24 10:07 sopel39