Hello experts, `Join related feasibility question...
# troubleshooting
r
Hello experts,
Join related feasibility question:
I have, • fact table leads_data (35M) rows and a dim table user_data (40M) rows • leads_data.user_id needs to be joined with user_data.user_id to get user details I can have filters on leads_data, but cannot restrict user_data as
leads can have any of the 40M users
stamped on it. Issue: Loading full user_data (40M rows) into memory to perform HASH join is not possible
What is the correct way out.
Pre-Joining is not so much of an option as I do have other child tables which are 1:N rows to lead_data
@Mayank — Can you pls. comment pls.
m
What will be the selectivity on the leads_data table for the query? Assuming it is high (low number of rows selected), then you can use that as the right table and user_data as left table, and perform colocated join
r
@Mayank — I think the swapping of the join order may not be possible in many cases. I just ran the same query on PrestoDB/Trino setup and it executed well with something called
*partitioned hash joins*, *dynamic filters and hash exchanges.*
I was hoping to achieve JOIN perf atleast as much as my existing system with PinotDB
Below is its execution plan:
Copy code
Trino version: 410 Fragment 0 [SINGLE] Output layout: [name, username] Output partitioning: SINGLE [] Output[columnNames = [name, user - user_id__username]] │ Layout: [name:varchar, username:varchar] │ Estimates: {rows: 1048575 (110.00MB), cpu: 0, memory: 0B, network: 0B} │ user - user_id__username := username └─ Limit[count = 1048575] │ Layout: [name:varchar, username:varchar] │ Estimates: {rows: 1048575 (110.00MB), cpu: 110.00M, memory: 0B, network: 0B} └─ LocalExchange[partitioning = SINGLE] │ Layout: [name:varchar, username:varchar] │ Estimates: {rows: 1048575 (110.00MB), cpu: 0, memory: 0B, network: 0B} └─ RemoteSource[sourceFragmentIds = [1]] Layout: [name:varchar, username:varchar] Fragment 1 [HASH] Output layout: [name, username] Output partitioning: SINGLE [] LimitPartial[count = 1048575] │ Layout: [name:varchar, username:varchar] │ Estimates: {rows: 1048575 (110.00MB), cpu: 110.00M, memory: 0B, network: 0B} └─ InnerJoin[criteria = ("user_id" = "id_1"), hash = [$hashvalue, $hashvalue_15], distribution = PARTITIONED] │ Layout: [name:varchar, username:varchar] │ Estimates: {rows: ? (?), cpu: ?, memory: ?, network: 0B} │ Distribution: PARTITIONED │ dynamicFilterAssignments = {id_1 -> #df_390} ├─ RemoteSource[sourceFragmentIds = [2]] │ Layout: [name:varchar, user_id:varchar, $hashvalue:bigint] └─ LocalExchange[partitioning = HASH, hashColumn = [$hashvalue_15], arguments = ["id_1"]] │ Layout: [id_1:varchar, username:varchar, $hashvalue_15:bigint] │ Estimates: {rows: ? (?), cpu: ?, memory: 0B, network: 0B} └─ RemoteSource[sourceFragmentIds = [3]] Layout: [id_1:varchar, username:varchar, $hashvalue_16:bigint] Fragment 2 [SOURCE] Output layout: [name, user_id, $hashvalue_14] Output partitioning: HASH [user_id][$hashvalue_14] ScanFilterProject[table = hive-v2:homeservice:base_lead, dynamicFilters = {"user_id" = #df_390}] Layout: [name:varchar, user_id:varchar, $hashvalue_14:bigint] Estimates: {rows: ? (?), cpu: ?, memory: 0B, network: 0B}/{rows: ? (?), cpu: ?, memory: 0B, network: 0B}/{rows: ? (?), cpu: ?, memory: 0B, network: 0B} $hashvalue_14 := combine_hash(bigint '0', COALESCE("$operator$hash_code"("user_id"), 0)) user_id := user_id:string:REGULAR name := name:string:REGULAR Fragment 3 [SOURCE] Output layout: [id_1, username, $hashvalue_17] Output partitioning: HASH [id_1][$hashvalue_17] ScanProject[table = hive-v2:nobroker:user] Layout: [id_1:varchar, username:varchar, $hashvalue_17:bigint] Estimates: {rows: ? (?), cpu: ?, memory: 0B, network: 0B}/{rows: ? (?), cpu: ?, memory: 0B, network: 0B} $hashvalue_17 := combine_hash(bigint '0', COALESCE("$operator$hash_code"("id_1"), 0)) id_1 := id:string:REGULAR username := username:string:REGULAR creation_date_partitioned:bigint:PARTITION_KEY :: [[201403, 202502]]
Fragment 0(Limit Partial, LocalExchange, Remote Source F1) :: Fragment 1(LimitPartial,, Inner Join, RemoteSourceF2, LocalExchange, RemoteSourceF3 ) :: Fragment 2 (base_lead table) :: Fragment 3 (user table)