sql - Most Efficient MySQL query to update a table from identical memory table -
I am implementing memory cache for a table that looks like this (simplified):
< P> Item1 (integer), item 2 (integer), cnt (integer)In the original table thus contains millions of pairs. And it updates fast.
To make it even more efficient, I want to add new additions to the same memory table and update the actual table on the disk by cronn from time to time.
The cron should do the following: If there is a similar combination in the non-memory table for each memory then the count in counting count increases from memory table. If there is no such pair, then make it count with memory table.
How can I flush (from the memory table to the actual table) the most efficient?
Note: Environment MySQL 5.0.45 PHP 5.2.6 CentOS
You can use the query - but it depends on the primary key or UNIQUE
index.
INSERT < Master_table & gt; & Gt; (Item 1, Item 2, CNT) Selection Item 1, Item 2, Cnt FORA & lt; Memory_table & gt; & Gt; Key update for duplicates = CNT + value (CNET) on CNET;
Comments
Post a Comment