Using a database table as a queue

前端 未结 9 2231
既然无缘
既然无缘 2020-12-02 07:45

I want to use a database table as a queue. I want to insert in it and take elements from it in the inserted order (FIFO). My main consideration is performance because I have

9条回答
  •  感动是毒
    2020-12-02 08:30

    Since you don't delete the records from the table, you need to have a composite index on (processed, id), where processed is the column that indicates if the current record had been processed.

    The best thing would be creating a partitioned table for your records and make the PROCESSED field the partitioning key. This way, you can keep three or more local indexes.

    However, if you always process the records in id order, and have only two states, updating the record would mean just taking the record from the first leaf of the index and appending it to the last leaf

    The currently processed record would always have the least id of all unprocessed records and the greatest id of all processed records.

提交回复
热议问题