mysql - Database better inner join for performance in this case -


i have 2 tables manages time spent on doing various things:

@times(id, time_in_minutes) @times_intervals(id, times_id, time_in_minutes, start, end) 

then @times might relate different things:

@tasks(id, description) @products(id, description, serial_number, year) 

what best practice in order reuse same @times , @times_intervals @task , @products?

i think about:

@times(+task_id, +product_id)  // add task_id , product_id original @times table 

but if so, when i'd join @times table @task , @products table slower should choice between 2 (task_id or product_id). when task_id not null join on @tasks , viceversa.

(i'm using mysql6)

thanks lot

i drop time_in_minutes column times table. information redundant if sum of detail , premature optimization.

i add product_time table containing product_id, times_id , task_time table containing task_id, time_id

then total time product:

select * product p inner join product_time pt     on pt.product_id = p.id inner join (     select times_id, sum(time_in_minutes) time_in_minutes     times_intervals     group times_id ) t     on t.times_id = pt.times_id 

typically make perform, have non-clustered covering index times_intervals columns times_id , time_in_minutes - note times table data-less header table @ point , purpose group times_intervals , it's necessary because have similar arrangement tasks.

if there not 2 (or more) entities using times_intervals, might put product_id in times_intervals , treat header/master id.


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 -