Skip to content

feat: Push limit into hash join#20228

Open
jonathanc-n wants to merge 1 commit intoapache:mainfrom
jonathanc-n:push-limit-into-join
Open

feat: Push limit into hash join#20228
jonathanc-n wants to merge 1 commit intoapache:mainfrom
jonathanc-n:push-limit-into-join

Conversation

@jonathanc-n
Copy link
Contributor

Which issue does this PR close?

Rationale for this change

What changes are included in this PR?

Push limit down into hash join using limit pushdown optimizer. Use limit pushdown optimizer to pass the limit value to Hash Join exec using with_fetch and passing the fetch value to LimitedBatch Coalescer to emit the batch once the limit is hit.

Are these changes tested?

SLT tests + unit tests

@github-actions github-actions bot added core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) physical-plan Changes to the physical-plan crate labels Feb 9, 2026
Copy link
Contributor Author

@jonathanc-n jonathanc-n left a comment

Choose a reason for hiding this comment

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

@zhuqi-lucas
Copy link
Contributor

run benchmarks

@zhuqi-lucas zhuqi-lucas self-requested a review February 9, 2026 08:33
@alamb-ghbot
Copy link

🤖 ./gh_compare_branch.sh gh_compare_branch.sh Running
Linux aal-dev 6.14.0-1018-gcp #19~24.04.1-Ubuntu SMP Wed Sep 24 23:23:09 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing push-limit-into-join (832a79c) to 0fd6a40 diff using: tpch_mem clickbench_partitioned clickbench_extended
Results will be posted here when complete

@alamb-ghbot
Copy link

🤖: Benchmark completed

Details

Comparing HEAD and push-limit-into-join
--------------------
Benchmark clickbench_extended.json
--------------------
┏━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Query    ┃        HEAD ┃ push-limit-into-join ┃    Change ┃
┡━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ QQuery 0 │  2241.20 ms │           2288.83 ms │ no change │
│ QQuery 1 │   916.75 ms │            911.64 ms │ no change │
│ QQuery 2 │  1810.92 ms │           1834.29 ms │ no change │
│ QQuery 3 │  1023.69 ms │           1044.90 ms │ no change │
│ QQuery 4 │  2203.93 ms │           2153.86 ms │ no change │
│ QQuery 5 │ 28118.13 ms │          28127.06 ms │ no change │
│ QQuery 6 │  3882.93 ms │           3843.34 ms │ no change │
│ QQuery 7 │  2523.06 ms │           2459.08 ms │ no change │
└──────────┴─────────────┴──────────────────────┴───────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Benchmark Summary                   ┃            ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ Total Time (HEAD)                   │ 42720.62ms │
│ Total Time (push-limit-into-join)   │ 42663.01ms │
│ Average Time (HEAD)                 │  5340.08ms │
│ Average Time (push-limit-into-join) │  5332.88ms │
│ Queries Faster                      │          0 │
│ Queries Slower                      │          0 │
│ Queries with No Change              │          8 │
│ Queries with Failure                │          0 │
└─────────────────────────────────────┴────────────┘
--------------------
Benchmark clickbench_partitioned.json
--------------------
┏━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query     ┃        HEAD ┃ push-limit-into-join ┃        Change ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 0  │     2.54 ms │              2.67 ms │  1.05x slower │
│ QQuery 1  │    51.86 ms │             50.67 ms │     no change │
│ QQuery 2  │   131.49 ms │            134.76 ms │     no change │
│ QQuery 3  │   149.97 ms │            158.75 ms │  1.06x slower │
│ QQuery 4  │  1008.35 ms │            998.52 ms │     no change │
│ QQuery 5  │  1319.07 ms │           1345.33 ms │     no change │
│ QQuery 6  │     6.48 ms │              6.81 ms │  1.05x slower │
│ QQuery 7  │    52.71 ms │             56.17 ms │  1.07x slower │
│ QQuery 8  │  1401.86 ms │           1405.80 ms │     no change │
│ QQuery 9  │  1806.76 ms │           1785.18 ms │     no change │
│ QQuery 10 │   348.70 ms │            352.97 ms │     no change │
│ QQuery 11 │   409.11 ms │            407.47 ms │     no change │
│ QQuery 12 │  1212.64 ms │           1241.57 ms │     no change │
│ QQuery 13 │  1883.16 ms │           1900.00 ms │     no change │
│ QQuery 14 │  1283.92 ms │           1228.05 ms │     no change │
│ QQuery 15 │  1211.03 ms │           1155.14 ms │     no change │
│ QQuery 16 │  2545.07 ms │           2445.83 ms │     no change │
│ QQuery 17 │  2549.01 ms │           2430.71 ms │     no change │
│ QQuery 18 │  5397.79 ms │           4729.88 ms │ +1.14x faster │
│ QQuery 19 │   120.43 ms │            122.74 ms │     no change │
│ QQuery 20 │  1915.55 ms │           1942.62 ms │     no change │
│ QQuery 21 │  2187.93 ms │           2220.30 ms │     no change │
│ QQuery 22 │  3899.91 ms │           3738.43 ms │     no change │
│ QQuery 23 │ 20144.26 ms │          12099.83 ms │ +1.66x faster │
│ QQuery 24 │   220.02 ms │            221.40 ms │     no change │
│ QQuery 25 │   491.10 ms │            475.16 ms │     no change │
│ QQuery 26 │   226.21 ms │            207.62 ms │ +1.09x faster │
│ QQuery 27 │  4957.10 ms │           2663.48 ms │ +1.86x faster │
│ QQuery 28 │ 23529.46 ms │          21905.22 ms │ +1.07x faster │
│ QQuery 29 │   977.28 ms │            958.81 ms │     no change │
│ QQuery 30 │  1296.84 ms │           1241.97 ms │     no change │
│ QQuery 31 │  1352.66 ms │           1337.50 ms │     no change │
│ QQuery 32 │  4227.83 ms │           4580.63 ms │  1.08x slower │
│ QQuery 33 │  5652.02 ms │           5280.43 ms │ +1.07x faster │
│ QQuery 34 │  5615.60 ms │           5654.40 ms │     no change │
│ QQuery 35 │  1920.91 ms │           1885.60 ms │     no change │
│ QQuery 36 │   197.94 ms │            194.01 ms │     no change │
│ QQuery 37 │    75.22 ms │             74.31 ms │     no change │
│ QQuery 38 │   114.84 ms │            115.47 ms │     no change │
│ QQuery 39 │   349.70 ms │            338.82 ms │     no change │
│ QQuery 40 │    38.18 ms │             40.07 ms │     no change │
│ QQuery 41 │    35.02 ms │             34.69 ms │     no change │
│ QQuery 42 │    30.46 ms │             31.67 ms │     no change │
└───────────┴─────────────┴──────────────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┓
┃ Benchmark Summary                   ┃             ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━┩
│ Total Time (HEAD)                   │ 102348.01ms │
│ Total Time (push-limit-into-join)   │  89201.50ms │
│ Average Time (HEAD)                 │   2380.19ms │
│ Average Time (push-limit-into-join) │   2074.45ms │
│ Queries Faster                      │           6 │
│ Queries Slower                      │           5 │
│ Queries with No Change              │          32 │
│ Queries with Failure                │           0 │
└─────────────────────────────────────┴─────────────┘
--------------------
Benchmark tpch_mem_sf1.json
--------------------
┏━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query     ┃      HEAD ┃ push-limit-into-join ┃        Change ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 1  │ 102.78 ms │            103.60 ms │     no change │
│ QQuery 2  │  32.30 ms │             32.40 ms │     no change │
│ QQuery 3  │  42.97 ms │             36.37 ms │ +1.18x faster │
│ QQuery 4  │  31.69 ms │             31.28 ms │     no change │
│ QQuery 5  │  92.69 ms │             93.06 ms │     no change │
│ QQuery 6  │  20.94 ms │             21.13 ms │     no change │
│ QQuery 7  │ 160.77 ms │            164.36 ms │     no change │
│ QQuery 8  │  42.06 ms │             39.68 ms │ +1.06x faster │
│ QQuery 9  │ 104.00 ms │            101.22 ms │     no change │
│ QQuery 10 │  67.94 ms │             67.31 ms │     no change │
│ QQuery 11 │  19.33 ms │             18.88 ms │     no change │
│ QQuery 12 │  51.81 ms │             51.32 ms │     no change │
│ QQuery 13 │  50.61 ms │             49.55 ms │     no change │
│ QQuery 14 │  15.18 ms │             15.26 ms │     no change │
│ QQuery 15 │  30.56 ms │             31.16 ms │     no change │
│ QQuery 16 │  28.43 ms │             28.09 ms │     no change │
│ QQuery 17 │ 144.45 ms │            140.19 ms │     no change │
│ QQuery 18 │ 286.86 ms │            281.42 ms │     no change │
│ QQuery 19 │  40.09 ms │             40.28 ms │     no change │
│ QQuery 20 │  57.62 ms │             54.70 ms │ +1.05x faster │
│ QQuery 21 │ 194.35 ms │            192.32 ms │     no change │
│ QQuery 22 │  22.64 ms │             23.39 ms │     no change │
└───────────┴───────────┴──────────────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Benchmark Summary                   ┃           ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ Total Time (HEAD)                   │ 1640.06ms │
│ Total Time (push-limit-into-join)   │ 1616.98ms │
│ Average Time (HEAD)                 │   74.55ms │
│ Average Time (push-limit-into-join) │   73.50ms │
│ Queries Faster                      │         3 │
│ Queries Slower                      │         0 │
│ Queries with No Change              │        19 │
│ Queries with Failure                │         0 │
└─────────────────────────────────────┴───────────┘

@Dandandan
Copy link
Contributor

run benchmark tpcds

@alamb-ghbot
Copy link

🤖 ./gh_compare_branch.sh gh_compare_branch.sh Running
Linux aal-dev 6.14.0-1018-gcp #19~24.04.1-Ubuntu SMP Wed Sep 24 23:23:09 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing push-limit-into-join (832a79c) to 0fd6a40 diff using: tpcds
Results will be posted here when complete

@Dandandan
Copy link
Contributor

(not sure if there is any query benefiting from this in tpch / tpcds, but those contain joins at least)

@Dandandan
Copy link
Contributor

run benchmark tpch

@alamb-ghbot
Copy link

🤖: Benchmark completed

Details

Comparing HEAD and push-limit-into-join
--------------------
Benchmark tpcds_sf1.json
--------------------
┏━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query     ┃        HEAD ┃ push-limit-into-join ┃        Change ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 1  │    74.01 ms │             73.64 ms │     no change │
│ QQuery 2  │   218.55 ms │            214.58 ms │     no change │
│ QQuery 3  │   158.94 ms │            156.40 ms │     no change │
│ QQuery 4  │  2087.81 ms │           1887.41 ms │ +1.11x faster │
│ QQuery 5  │   276.79 ms │            261.07 ms │ +1.06x faster │
│ QQuery 6  │  1517.13 ms │           1451.95 ms │     no change │
│ QQuery 7  │   526.79 ms │            507.28 ms │     no change │
│ QQuery 8  │   174.17 ms │            168.47 ms │     no change │
│ QQuery 9  │   300.14 ms │            295.72 ms │     no change │
│ QQuery 10 │   178.79 ms │            173.65 ms │     no change │
│ QQuery 11 │  1408.62 ms │           1298.06 ms │ +1.09x faster │
│ QQuery 12 │    73.38 ms │             66.72 ms │ +1.10x faster │
│ QQuery 13 │   580.59 ms │            544.10 ms │ +1.07x faster │
│ QQuery 14 │  1948.30 ms │           1875.87 ms │     no change │
│ QQuery 15 │    28.63 ms │             27.83 ms │     no change │
│ QQuery 16 │    66.28 ms │             62.35 ms │ +1.06x faster │
│ QQuery 17 │   371.07 ms │            360.23 ms │     no change │
│ QQuery 18 │   198.97 ms │            196.22 ms │     no change │
│ QQuery 19 │   220.37 ms │            216.96 ms │     no change │
│ QQuery 20 │    25.18 ms │             24.18 ms │     no change │
│ QQuery 21 │    37.82 ms │             35.39 ms │ +1.07x faster │
│ QQuery 22 │   732.48 ms │            693.12 ms │ +1.06x faster │
│ QQuery 23 │  1822.17 ms │           1785.00 ms │     no change │
│ QQuery 24 │   706.52 ms │            685.62 ms │     no change │
│ QQuery 25 │   538.78 ms │            523.63 ms │     no change │
│ QQuery 26 │   127.33 ms │            129.05 ms │     no change │
│ QQuery 27 │   524.55 ms │            514.22 ms │     no change │
│ QQuery 28 │   302.84 ms │            296.28 ms │     no change │
│ QQuery 29 │   463.46 ms │            448.81 ms │     no change │
│ QQuery 30 │    79.65 ms │             75.00 ms │ +1.06x faster │
│ QQuery 31 │   314.79 ms │            298.55 ms │ +1.05x faster │
│ QQuery 32 │    82.27 ms │             81.98 ms │     no change │
│ QQuery 33 │   212.55 ms │            207.65 ms │     no change │
│ QQuery 34 │   165.51 ms │            159.17 ms │     no change │
│ QQuery 35 │   184.64 ms │            178.59 ms │     no change │
│ QQuery 36 │   295.92 ms │            289.18 ms │     no change │
│ QQuery 37 │   265.96 ms │            256.91 ms │     no change │
│ QQuery 38 │   160.60 ms │            151.99 ms │ +1.06x faster │
│ QQuery 39 │   210.19 ms │            194.86 ms │ +1.08x faster │
│ QQuery 40 │   183.17 ms │            181.02 ms │     no change │
│ QQuery 41 │    26.39 ms │             25.72 ms │     no change │
│ QQuery 42 │   148.74 ms │            144.53 ms │     no change │
│ QQuery 43 │   131.06 ms │            126.84 ms │     no change │
│ QQuery 44 │    30.51 ms │             28.29 ms │ +1.08x faster │
│ QQuery 45 │    86.53 ms │             84.01 ms │     no change │
│ QQuery 46 │   338.79 ms │            325.59 ms │     no change │
│ QQuery 47 │  1137.83 ms │           1031.50 ms │ +1.10x faster │
│ QQuery 48 │   435.78 ms │            401.61 ms │ +1.09x faster │
│ QQuery 49 │   384.38 ms │            384.59 ms │     no change │
│ QQuery 50 │   351.58 ms │            322.87 ms │ +1.09x faster │
│ QQuery 51 │   317.45 ms │            305.58 ms │     no change │
│ QQuery 52 │   149.41 ms │            144.42 ms │     no change │
│ QQuery 53 │   148.96 ms │            144.65 ms │     no change │
│ QQuery 54 │   212.67 ms │            202.95 ms │     no change │
│ QQuery 55 │   149.09 ms │            144.06 ms │     no change │
│ QQuery 56 │   214.57 ms │            205.36 ms │     no change │
│ QQuery 57 │   301.96 ms │            289.26 ms │     no change │
│ QQuery 58 │   511.13 ms │            496.38 ms │     no change │
│ QQuery 59 │   300.58 ms │            287.80 ms │     no change │
│ QQuery 60 │   216.67 ms │            210.82 ms │     no change │
│ QQuery 61 │   258.99 ms │            249.33 ms │     no change │
│ QQuery 62 │  1336.11 ms │           1302.56 ms │     no change │
│ QQuery 63 │   148.63 ms │            145.51 ms │     no change │
│ QQuery 64 │  1197.94 ms │           1185.23 ms │     no change │
│ QQuery 65 │   372.59 ms │            354.06 ms │     no change │
│ QQuery 66 │   393.62 ms │            392.28 ms │     no change │
│ QQuery 67 │   547.88 ms │            532.76 ms │     no change │
│ QQuery 68 │   395.19 ms │            378.29 ms │     no change │
│ QQuery 69 │   173.46 ms │            169.22 ms │     no change │
│ QQuery 70 │   501.92 ms │            492.31 ms │     no change │
│ QQuery 71 │   186.62 ms │            186.64 ms │     no change │
│ QQuery 72 │  2150.72 ms │           2100.26 ms │     no change │
│ QQuery 73 │   156.61 ms │            155.17 ms │     no change │
│ QQuery 74 │   851.79 ms │            828.27 ms │     no change │
│ QQuery 75 │   413.46 ms │            412.01 ms │     no change │
│ QQuery 76 │   187.05 ms │            187.06 ms │     no change │
│ QQuery 77 │   285.51 ms │            279.73 ms │     no change │
│ QQuery 78 │   690.91 ms │            680.51 ms │     no change │
│ QQuery 79 │   336.48 ms │            324.28 ms │     no change │
│ QQuery 80 │   544.55 ms │            526.71 ms │     no change │
│ QQuery 81 │    52.54 ms │             52.26 ms │     no change │
│ QQuery 82 │   282.16 ms │            278.39 ms │     no change │
│ QQuery 83 │    80.82 ms │             78.44 ms │     no change │
│ QQuery 84 │    70.61 ms │             69.90 ms │     no change │
│ QQuery 85 │   227.02 ms │            221.46 ms │     no change │
│ QQuery 86 │    59.38 ms │             58.81 ms │     no change │
│ QQuery 87 │   159.55 ms │            153.66 ms │     no change │
│ QQuery 88 │   267.88 ms │            256.25 ms │     no change │
│ QQuery 89 │   169.87 ms │            166.59 ms │     no change │
│ QQuery 90 │    47.40 ms │             44.54 ms │ +1.06x faster │
│ QQuery 91 │    98.18 ms │             95.84 ms │     no change │
│ QQuery 92 │    82.17 ms │             81.56 ms │     no change │
│ QQuery 93 │   291.48 ms │            277.20 ms │     no change │
│ QQuery 94 │    91.19 ms │             89.78 ms │     no change │
│ QQuery 95 │   247.16 ms │            239.82 ms │     no change │
│ QQuery 96 │   116.96 ms │            115.05 ms │     no change │
│ QQuery 97 │   201.50 ms │            194.47 ms │     no change │
│ QQuery 98 │   226.07 ms │            220.06 ms │     no change │
│ QQuery 99 │ 14374.19 ms │          14327.41 ms │     no change │
└───────────┴─────────────┴──────────────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Benchmark Summary                   ┃            ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ Total Time (HEAD)                   │ 51716.01ms │
│ Total Time (push-limit-into-join)   │ 50259.21ms │
│ Average Time (HEAD)                 │   522.38ms │
│ Average Time (push-limit-into-join) │   507.67ms │
│ Queries Faster                      │         17 │
│ Queries Slower                      │          0 │
│ Queries with No Change              │         82 │
│ Queries with Failure                │          0 │
└─────────────────────────────────────┴────────────┘

@alamb-ghbot
Copy link

🤖 ./gh_compare_branch.sh gh_compare_branch.sh Running
Linux aal-dev 6.14.0-1018-gcp #19~24.04.1-Ubuntu SMP Wed Sep 24 23:23:09 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
Comparing push-limit-into-join (832a79c) to 0fd6a40 diff using: tpch
Results will be posted here when complete

@alamb-ghbot
Copy link

🤖: Benchmark completed

Details

Comparing HEAD and push-limit-into-join
--------------------
Benchmark tpch_sf1.json
--------------------
┏━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ Query     ┃      HEAD ┃ push-limit-into-join ┃       Change ┃
┡━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
│ QQuery 1  │ 179.88 ms │            179.66 ms │    no change │
│ QQuery 2  │  85.83 ms │             86.53 ms │    no change │
│ QQuery 3  │ 124.91 ms │            120.58 ms │    no change │
│ QQuery 4  │  78.29 ms │             78.10 ms │    no change │
│ QQuery 5  │ 176.45 ms │            170.54 ms │    no change │
│ QQuery 6  │  66.82 ms │             67.87 ms │    no change │
│ QQuery 7  │ 203.32 ms │            204.60 ms │    no change │
│ QQuery 8  │ 161.51 ms │            165.91 ms │    no change │
│ QQuery 9  │ 234.77 ms │            223.69 ms │    no change │
│ QQuery 10 │ 185.20 ms │            185.05 ms │    no change │
│ QQuery 11 │  59.12 ms │             64.23 ms │ 1.09x slower │
│ QQuery 12 │ 117.63 ms │            115.83 ms │    no change │
│ QQuery 13 │ 222.07 ms │            220.27 ms │    no change │
│ QQuery 14 │  91.58 ms │             90.01 ms │    no change │
│ QQuery 15 │ 121.01 ms │            127.12 ms │ 1.05x slower │
│ QQuery 16 │  59.01 ms │             60.82 ms │    no change │
│ QQuery 17 │ 255.15 ms │            251.88 ms │    no change │
│ QQuery 18 │ 304.12 ms │            304.39 ms │    no change │
│ QQuery 19 │ 133.79 ms │            132.96 ms │    no change │
│ QQuery 20 │ 124.32 ms │            128.20 ms │    no change │
│ QQuery 21 │ 251.75 ms │            258.60 ms │    no change │
│ QQuery 22 │  41.07 ms │             42.37 ms │    no change │
└───────────┴───────────┴──────────────────────┴──────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Benchmark Summary                   ┃           ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ Total Time (HEAD)                   │ 3277.61ms │
│ Total Time (push-limit-into-join)   │ 3279.21ms │
│ Average Time (HEAD)                 │  148.98ms │
│ Average Time (push-limit-into-join) │  149.05ms │
│ Queries Faster                      │         0 │
│ Queries Slower                      │         2 │
│ Queries with No Change              │        20 │
│ Queries with Failure                │         0 │
└─────────────────────────────────────┴───────────┘

Copy link
Contributor

@2010YOUY01 2010YOUY01 left a comment

Choose a reason for hiding this comment

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

Thank you! The implementation looks very straight-forward to me.

I suggest constructing a query that favors this optimization, and ensure the performance improvement can be measured. I don't think there will be any surprises, just to be safe.

// Null-aware anti join requires seeing ALL probe rows to check for NULLs.
// If any probe row has NULL, the output must be empty.
// We can't stop early or we might miss a NULL and return wrong results.
if self.null_aware {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this part.

The output_buffer will only get filled when an output entry is finalized, so this should be handled automatically?

partition_mode: PartitionMode,
null_equality: NullEquality,
null_aware: bool,
/// Maximum number of rows to return
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// Maximum number of rows to return
/// Maximum number of rows to return
///
/// If the operator produces `< fetch` rows, it returns all available rows.
/// If it produces `>= fetch` rows, it returns exactly `fetch` rows and stops early.

// TODO stats: it is not possible in general to know the output size of joins
// There are some special cases though, for example:
// - `A LEFT JOIN B ON A.col=B.col` with `COUNT_DISTINCT(B.col)=COUNT(B.col)`
let stats = estimate_join_statistics(
Copy link
Member

Choose a reason for hiding this comment

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

Should the statistics take into account the fetch/limit when estimating ?

self.fetch
}

fn with_fetch(&self, limit: Option<usize>) -> Option<Arc<dyn ExecutionPlan>> {
Copy link
Member

Choose a reason for hiding this comment

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

Is this method really needed ?
If it is not then I'd suggest to remove it.
If the HashJoinExec is already executed then setting a new limit will be confusing/inconsistent unless it is re-executed again.

Alternatively it could be implemented as:

HashJoinExecBuilder::from(self)
    .with_fetch(limit)
    .build()
    .ok()
    .map(|exec| Arc::new(exec) as _)

This way it won't keep the calculated state.

),
partition_mode,
self.null_equality(),
self.null_aware,
Copy link
Member

Choose a reason for hiding this comment

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

The fetch field is not preserved here. Is this intentional ?

None,
*self.partition_mode(),
self.null_equality,
self.null_aware,
Copy link
Member

Choose a reason for hiding this comment

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

The fetch field is not preserved here. Is this intentional ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate physical-plan Changes to the physical-plan crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants