14. REPAIR TABLE#

14.1. Synopsis#

REPAIR TABLE { <table_name> | <find_expression> } [, ... ]

  [ INDEX
    | IN { RANGE <range_spec> | '[' RANGE <range_spec> [, ...] ']' }
      [ WITH MONTHS IN ( <month>, <month> ) ]
      [ WITH DAYS IN ( <day>, <day> ) ]
      [ WITH TIME IN ( <time>, <time> ) ]
  ]

range_spec ::=
  ( <timestamp>, <timestamp> )
  ( <timestamp>, <time_offset> )

find_expression ::=
  FIND ( { <tag_expression> | NOT <tag_expression> } [ AND ... ] )

tag_expression ::=
  TAG = 'tag_name'

14.2. Description#

Use REPAIR TABLE to repair one or more time series tables. You must have these privileges for each target table: system, delete, update, drop, index, insert, select, set_transaction, and alter. For more information, refer to privileges.

The statement has two modes: rewrite mode and index mode.

14.2.1. Rewrite mode#

Rewrite mode is the default mode. It reads each selected bucket and writes the bucket in the current storage format. It also recomputes the micro-index metadata. QuasarDB searches for the buckets even if the table metadata is missing.

Use a time range to select specific buckets.

Use rewrite mode to update the storage layout, compression, and micro-indexes. The count result is the number of columns that QuasarDB rewrote.

Warning

QuasarDB cannot always recover all data. If data is not available, rewrite mode replaces the data with NULL values. If possible, make a backup before you use this statement.

14.2.2. Index mode#

Add INDEX to repair the bucket index for each target table.

A dead bucket alias points to bucket metadata that does not exist. QuasarDB removes dead bucket aliases from the persisted prefix tree. It then rebuilds the in-memory shard index from the bucket aliases that remain.

Index mode does not repair table data. You cannot use INDEX with a time range. The count result is the number of dead bucket aliases that QuasarDB removed.

14.3. Results#

REPAIR TABLE returns one row for each target table.

$table

The name of the target table.

count

In rewrite mode, the number of columns that QuasarDB rewrote. In index mode, the number of dead bucket aliases that QuasarDB removed.

error count

In rewrite mode, the number of columns that QuasarDB could not repair. In index mode, the total number of alias-removal errors and metadata-read errors.

14.4. Parameters#

table_name

The name of a table to repair.

find_expression

A key/value lookup that selects multiple tables. For example, FIND(TAG='stocks' AND TYPE=TS) selects all time series tables that have the stocks tag. For more information, refer to key/value lookups.

range_spec

A time range that selects buckets in rewrite mode. You can specify more than one range. You cannot use a range in index mode.

14.5. Examples#

Rewrite all buckets of the example table:

REPAIR TABLE example;

Rewrite the buckets of the example table for the year 2017:

REPAIR TABLE example IN RANGE(2017, 2018);

Rewrite the buckets for the year 2017 in all tables that have the nyse tag:

REPAIR TABLE FIND(TAG='nyse') IN RANGE(2017, 2018);

Repair the bucket index of the example table:

REPAIR TABLE example INDEX;

Repair the bucket index of all tables that have the nyse tag:

REPAIR TABLE FIND(TAG='nyse') INDEX;