database - Is it better to use one complex query or several simpler ones? -


which option better:

  1. writing complex query having large number of joins, or
  2. writing 2 queries 1 after other, applying obtained result set of processed query on other.

when junior db person once worked year in marketing dept had free time did each task 2 or 3 different ways. made habit of writing 1 mega-select grabbed in 1 go , comparing script built interim tables of selected primary keys , once had correct keys went , got data values.

in every case second method faster. cases wasn't when dealing small number of small tables. noticeably faster of course large tables , multiple joins.

i got habit of select required primary keys tablea, select required primary keys tableb, etc. join them , select final set of primary keys. use selected primary keys go tables , data values.

as dba understand method resulted in less purging of data cache , played nicer others using db (as mentioned amir raminfar).

it require use of temporary tables places / dba don't (unfairly in mind)


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -