# currently if ( DB query word exists in table ) { DB do update counter } else DB insert word with counter val of 1 } # this will always use 2 DB queries per iter, whereas this code..... unless ( execute(UPDATE table SET counter = counter + 1 WHERE word = ?) ) { # this should only fail if the bound word does not exist so # know we know we really needed an INSERT with default value (1) # but we have saved 1 DB query - IN A LOOP execute(INSERT INTO table VALUES ( word, 1 ) ) } # will only use one query if it is an update (probably the most common case) # and still only uses 2 for an insert. # this can yield savings -> 50% depending on Update:Insert ratio