On a very heavy traffic LAMP server I'm using a memory table to keep track of several data items as counters. It is implemented like this:
$query = "INSERT INTO daily_info_mem SET di_num=1 ,di_type=9, di_date = current_date(), di_sid= $sid_int ,di_name='user_counter' ON DUPLICATE KEY UPDATE di_num=di_num+1";
The index sets unique di_type and date, so if the counter exists for this date then di_type it is incremented, if not a row for this date and data type is created with 0 value.
There are several such queries for each page view. Which means several mysql calls.
Is it possible to optimize this as much as possible into one mysql call that will update several arbitrary counters and still keep the idea of creating the row if needed or increasing the vale if it exists?