Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-6259

DELETE with OFFSET

    XMLWordPrintable

Details

    • Task
    • Status: Open (View Workflow)
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None

    Description

      Allow DELETE statment with OFFSET, this allow a DELETE like SQLITE:
      http://www.sqlite.org/lang_delete.html

      it's interesting with history table applications where a fixed number of rows is wanted, for example

      CREATE TABLE history (
       channel_id INT NOT NULL DEFAULT 0,
       date_unix DECIMAL(22,6) NOT NULL DEFAULT 0,
       value DECIMAL(22,7) NOT NULL DEFAULT 0,
       PRIMARY KEY (channel_id,date_unix)
      );

      many inserts....

      INSERT INTO history (1,now(),current_temperature);
      INSERT INTO history (1,now(),current_temperature);
      INSERT INTO history (1,now(),current_temperature);
      INSERT INTO history (1,now(),current_temperature);
      .....

      an crond job executed at every hour:

      DELETE FROM history WHERE channel_id=1 ORDER BY date_unix DESC LIMIT -1 OFFSET 5000

      from SQLITE: A negative LIMIT value is interpreted as "no limit".

      this will remove all rows from this 'channel' that are older than the 5000th row

      —
      today this should be done with two queries:

      SELECT date_unix FROM history WHERE channel_id=1 ORDER BY date_unix DESC LIMIT 1 OFFSET 5000

      get the date_unix value, and execute:

      DELETE FROM history WHERE channel_id=1 AND date_unix<"{$date_unix from previous query$}"

      Attachments

        Activity

          People

            Unassigned Unassigned
            rspadim roberto spadim
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.