sql - What is the best way to increase view counter column of a row in each select? -


often portals news sites, wonder whether practice or not update view counter field of table while selecting row. lets have news table id, title, details, publishdate , viewcounter. perform following query on each request of news detail page? how mixing of select , update each request hurt performance?

select * news id=120; update news set viewcounter=viewcounter+1 id=120; 

could there difference in performance if put view tracker data in table, table viewscount columns id, newsid,viewcount? in case, execute following code:

select * news id=120; update viewscount set viewcount=viewcount+1 newsid=120; 

i see 1 more option track browser request data each request, , later aggregate rows each news id. design, run 2 queries each request: select , insert, following:

select * news id=120; insert newsview(newsid,browser,ipaddress,operatingsystem,col1,col2) values(120,'netscape','202.xx.xx.xx','windows',col1value,col2value) 

but have seen in short span of time lots of rows , database size increases heavy traffic portals. slow down aggregate queries.

what alternatives use? or ok go page view trackers google analytics? welcome suggestions based on best practices have been following in similar context.

updating row every view take exclusive lock on row serializing read access resource, each queuing read transaction need wait previous 1 commit in turn requires confirmation transaction log has been persisted disc.

this become bottle neck moderately popular articles.

i consider tracking page view deltas in memory in application , writing them database @ periodic intervals. if application crashes lose views period may acceptable.

alternatively web server may have log files appended on each view , can periodically parsed extract information new page views.


Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -