Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Inner Join with IN clause

Is this sentence optimized?

select d.id, d.wfid, d.docid , k.keyword, k.value from keywords k
inner join documents d 
where k.document_id in (23,24) AND k.document_id = d.id;

I have some ID's via POST (23,24) and I need to get the info for only them, so for that I do the IN. Here are hardcoded for testing purposes.

I know MySQL parses the sentences and generates a more optimized one. Is there a way to get that sentence so I avoid having mysql optimizing it all the time?

Thanks!

like image 255
JorgeeFG Avatar asked Sep 01 '25 02:09

JorgeeFG


1 Answers

If you run these you n see how MySQL rewrite handle them. Note the SQL in the show warnings is not always valid SQL syntax

explain extended select d.id, d.wfid, d.docid , k.keyword, k.value from keywords k
inner join documents d 
where k.document_id in (23,24) AND k.document_id = d.id;
show warnings;
like image 199
Raymond Nijland Avatar answered Sep 02 '25 16:09

Raymond Nijland