cube2222 / octosql

OctoSQL is a query tool that allows you to join, analyse and transform data from multiple databases and file formats using SQL.
Mozilla Public License 2.0
4.76k stars 200 forks source link

Slow query result #184

Closed willy140198 closed 4 years ago

willy140198 commented 4 years ago

so i have query like this

SELECT * 
FROM lms.transactions lmsTran
JOIN mifos.m_loan_transaction mifosTran
on lmsTran.external_txn_id = mifosTran.external_id
WHERE lmsTran.created_at > start_date(?) and lmsTran.created_at < end_date(?)
limit 1

and the result take so long, more than 1 minute with 32k data, and this query using mysql and postgres at once. and start_date is our function to parse to parset_time dont mind it. are you have any sugestion? thank you!

cube2222 commented 4 years ago

Depends on what start_date/end_date are referencing in the arguments.

I suppose the predicates (lmsTran.created_at > start_date(?) and lmsTran.created_at < end_date(?)) aren't getting pushed down to the underlying database, and it has to scan the whole mifos.m_loan_transaction table for each transaction. You could try changing the JOIN order (mifos.m_loan_transaction mifosTran JOIN lms.transactions lmsTran).

I'll try to add some kind of query plan printing in the near future.

willy140198 commented 4 years ago

oh i see, that's make sense, thank you!

cube2222 commented 4 years ago

Closing for now, feel free to reopen.