The query ultimately timed out - but that may be aqua data studio client - not too sure - either way, here’s the profile c044da8c-4351-48b0-97e7-cbc6a00d22f8.zip (35.1 KB)
Since you are operating only on 341,248 records, it is single threaded. I also see 15m blocked on downstream which is waiting on JDBC to consume records
how can you see the 15 min wait in the profile? Expand phase 00-xx-xx . Phase 0 is the last phase and downstream to Phase 0 is external like ODBC or JDBC etc. If you see under Phase 00-xx-xx and under “Blocked Downstream” you will see the time I am talking about
NL joins are expensive and since you are single threaded that core is probably getting used 100%
#2 We use one thread per 100,000 records but limited by number of splits. In your case you only have one split so hence the single thread. Can you partition by a different key to increase number of splits?
#3 Why does it use a NL join, in the below query, are “lctryiso” and “mctryiso” columns in kldw.reference.kl_iata_all
One thing you can try is to first join only kldw.reference.kl_iata_all and kldw.reference.iata_purchased_db and see how the query performs and look at the plan. Then add “kldw.reference.country”