Thursday, 15 April 2010

Mysql Show On Unseen -



Mysql Show On Unseen -

i working on photo sharing application users able upload own images , vote/comment on images uploaded others, in our app, want implement feature show them rows have never seen, means 1 time see image, removed feed. our image table pretty simple

picture_id (int 255, pk) | picture_title (varchar 255)

the table tracks views is

view_id (255, pk) | picture_id (255) | user_id (255)

previously have been using simple not in query accomplish result

select * pictures picture_id not in (select picture_id views user_id=255)

that working fine since our views table has gone past 20 1000000 rows, query takes long time in preparing state, looking suggestions rewrite query or optimize it.

thansk

use join

select p.* pictures p left bring together views v on v.picture_id = p.picture_id , v.user_id = 255 v.picture_id null

to create efficient, create sure have index on views.picture_id.

mysql

No comments:

Post a Comment