I have a stream table (memory table), and a script which is inserting in this table (from 1 row/min to 100 rows/sec). I need to fetch 1000 rows every 5 seconds, i mean select top 1000 rows and then delete that selected rows.
My select query is so simple:
SELECT * FROM vdp_stream WHERE user=xxx
My problem is actually i cannot query a DELETE sql, because maybe some new rows be appended between the time that i SELECT and DELETE. Am i right? Is there any solution to fetch rows from a table?
UPDATE my table structure:
vdp_stream
---------------------
user CHAR(30)
x INT
y INT
If you are going to continue doing this using a table I would suggest using UPDATE, SELECT and DELETE statements within a transaction. Something like this perhaps –
UPDATE – as the default isolation level for InnoDB is REPEATABLE READ you can omit the update and just do the SELECT and DELETE based on the same criteria –