php - SQL regularly counting all new votes in one table and incrementing a total count value in another -


i have 3 tables, 1 user made levels, , 2 more tables upvotes , downvotes on said levels.

i have 10 million votes cast, , it's becoming slow count votes level whenever necessary, i'm planning add 2 columns on levels table, counts upvotes , downvotes, , server update these maybe once every 24 hours.

the votes tables unfortunately don't have auto incremented primary key column, instead primary key mapid , userid combined, 1 user cannot vote same map twice.

so i'm adding column votes tables, "counted", 0 if hasn't been added aggregate data, 1 if has. way don't need recount votes have been added aggregate data, new ones.

my query needs to:

-select votes have counted set 0

-take mapid row, , increment thumbsup count mapid in levels table

-set counted 1 vote

i'm using mysql. appreciated!

table maps_thumbsup userid | mapid | counted  table maps_thumbsdown userid | mapid | counted  table maps id | authorname | leveldata | ... | thumbsupcount | thumbsdowncount 

doesn't main table have number of votes? t

able maps_thumbsup userid | mapid | counted  table maps_thumbsdown userid | mapid | counted  table maps id | authorname | leveldata | ... | thumbsupcount | thumbsdowncount 

so every time votes use set command in mysql "set thumbsup = thumbsup + 1" if doesn't have 2 columns add , can send me interface type mysql / mysql / dbo can update answer post code count , insert count in newly create columns no need count votes every time single value db can use way votes


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -