Dr_movi
Dr_movi

Reputation: 45

best practice for mysql search query (select)?

what is the best practice for data search in mysql: 1- to extract 100 record then do filtering outside the database or to use WHERE in mysql database and extract the exact needed record even if if WHERE is going to be a little complicated (also concerning indexing columns) 2- to use or not to JOIN

Upvotes: 1

Views: 597

Answers (1)

tadman
tadman

Reputation: 211560

Doing filtering outside the database is a sign you're doing it wrong. WHERE exists to do the filtering for you. If your conditions take a long time to apply, you probably need to index better.

Using EXPLAIN can help identify where problems in your query exist.

If you can't figure out how to tune your JOIN, you can try deliberately de-normalizing your data to improve performance. Keep in mind that requires duplicating data and keeping it in sync so it's something that is usually a last resort.

Upvotes: 2

Related Questions