How to connect Priority queue via MySQL without corrupt the priority ordering?

430 Views Asked by At

I have a program with a priority queue (PQ) so huge that it does not fit to the memory. It was decided to move some data to MySQL database (DB) in following way: the new elements are put into DB instead of PQ, and when the PQ is emptied, it is updated by the entries in the DB. But this way appeared to spoil the priority ordering. Is there any solution which does not corrupt the priority ordering and combines PQ with DB?

For some reason I cannot get rid of PQ and use only DB.

1

There are 1 best solutions below

2
On

Your question is rather vague on the functionality, but I think the idea is wrong.

Someone seems to have the idea of using the database as secondary storage for an in-memory application. That doesn't really make much sense. Normally, you would use a simple file for this. Although you can use a database for managing secondary/tertiary storage, a database does many other things, so it is like using a smart phone only as a clock.

If you are going to use a database, then store the entire structure in the database and develop an API for it that meets your needs.

If you want help with how to structure the data, then write another question and include:

  • sample data
  • how the priority queue will be used
  • any ideas you have on the data structure