Circular buffer log in mysql

Da Helpedia.

as easy as

CREATE TABLE circular_log_table (
    log_id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    row_id INTEGER UNSIGNED NOT NULL UNIQUE KEY,
    timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    payload VARCHAR(255),
    INDEX (timestamp)
);


REPLACE INTO circular_log_table
SET row_id = (SELECT COALESCE(MAX(log_id), 0) % MAX_CIRCULAR_LOG_ROWS + 1
              FROM circular_log_table AS t),
    payload = 'My log entry.'

Strumenti personali
Namespace
Varianti
Azioni
Navigazione
Strumenti