ALTER TABLE table ADD COLUMN column_name [{INTEGER|INT|BIGINT|FLOAT|BOOL|MULTI|MULTI64|JSON|STRING|TIMESTAMP|TEXT [INDEXED [ATTRIBUTE]]}] [engine='columnar']
ALTER TABLE table DROP COLUMN column_name
This feature only supports adding one field at a time for RT tables. The supported data types are: * int
- integer attribute * timestamp
- timestamp attribute * bigint
- big integer attribute * float
- float attribute * bool
- boolean attribute * multi
- multi-valued integer attribute * multi64
- multi-valued bigint attribute * json
- json attribute * string
/ text attribute
/ string attribute
- string attribute * text
/ text indexed stored
/ string indexed stored
- full-text indexed field with original value stored in docstore * text indexed
/ string indexed
- full-text indexed field, indexed only (the original value is not stored in docstore) * text indexed attribute
/ string indexed attribute
- full text indexed field + string attribute (not storing the original value in docstore) * text stored
/ string stored
- the value will be only stored in docstore, not full-text indexed, not a string attribute * adding engine='columnar'
to any attribute (except for json) will make it stored in the columnar storage
ALTER
ing it to avoid data corruption in case of a sudden power interruption or other similar issues.ALTER
will not work for distributed tables and tables without any attributes.DROP COLUMN
will fail if a table has only one field.ALTER DROP
drops the attribute, the second one drops the full-text field.
> desc rt;
mysql+------------+-----------+
Type |
| Field | +------------+-----------+
id | bigint |
|
| text | field |group_id | uint |
| timestamp |
| date_added | +------------+-----------+
> alter table rt add column test integer;
mysql
> desc rt;
mysql+------------+-----------+
Type |
| Field | +------------+-----------+
id | bigint |
|
| text | field |group_id | uint |
| timestamp |
| date_added |
| test | uint |+------------+-----------+
> alter table rt drop column group_id;
mysql
> desc rt;
mysql+------------+-----------+
Type |
| Field | +------------+-----------+
id | bigint |
|
| text | field |timestamp |
| date_added |
| test | uint |+------------+-----------+
> alter table rt add column title text indexed;
mysql
> desc rt;
mysql+------------+-----------+------------+
Type | Properties |
| Field | +------------+-----------+------------+
id | bigint | |
| indexed |
| text | text | indexed |
| title | text | timestamp | |
| date_added |
| test | uint | |+------------+-----------+------------+
> alter table rt add column title text attribute;
mysql
> desc rt;
mysql+------------+-----------+------------+
Type | Properties |
| Field | +------------+-----------+------------+
id | bigint | |
| indexed |
| text | text | indexed |
| title | text | timestamp | |
| date_added |
| test | uint | |
| title | string | |+------------+-----------+------------+
> alter table rt drop column title;
mysql
> desc rt;
mysql+------------+-----------+------------+
Type | Properties |
| Field | +------------+-----------+------------+
id | bigint | |
| indexed |
| text | text | indexed |
| title | text | timestamp | |
| date_added |
| test | uint | |+------------+-----------+------------+
> alter table rt drop column title;
mysql
> desc rt;
mysql+------------+-----------+------------+
Type | Properties |
| Field | +------------+-----------+------------+
id | bigint | |
| indexed |
| text | text | timestamp | |
| date_added |
| test | uint | |+------------+-----------+------------+
ALTER TABLE table ft_setting='value'[, ft_setting2='value']
You can use ALTER
to modify the full-text settings of your table in RT mode. However, it only affects new documents and not existing ones. Example: * create a table with a full-text field and charset_table
that allows only 3 searchable characters: a
, b
and c
. * then we insert document ‘abcd’ and find it by query abcd
, the d
just gets ignored since it’s not in the charset_table
array * then we understand, that we want d
to be searchable too, so we add it with help of ALTER
* but the same query where match('abcd')
still says it searched by abc
, because the existing document remembers previous contents of charset_table
* then we add another document abcd
and search by abcd
again * now it finds the both documents and show meta
says it used two keywords: abc
(to find the old document) and abcd
(for the new one).
> create table rt(title text) charset_table='a,b,c';
mysql
> insert into rt(title) values('abcd');
mysql
> select * from rt where match('abcd');
mysql+---------------------+-------+
id | title |
| +---------------------+-------+
1514630637682688054 | abcd |
| +---------------------+-------+
> show meta;
mysql+---------------+-------+
Value |
| Variable_name | +---------------+-------+
1 |
| total | 1 |
| total_found | time | 0.000 |
| 0] | abc |
| keyword[0] | 1 |
| docs[0] | 1 |
| hits[+---------------+-------+
> alter table rt charset_table='a,b,c,d';
mysql> select * from rt where match('abcd');
mysql+---------------------+-------+
id | title |
| +---------------------+-------+
1514630637682688054 | abcd |
| +---------------------+-------+
> show meta
mysql+---------------+-------+
Value |
| Variable_name | +---------------+-------+
1 |
| total | 1 |
| total_found | time | 0.000 |
| 0] | abc |
| keyword[0] | 1 |
| docs[0] | 1 |
| hits[+---------------+-------+
> insert into rt(title) values('abcd');
mysql> select * from rt where match('abcd');
mysql+---------------------+-------+
id | title |
| +---------------------+-------+
1514630637682688055 | abcd |
| 1514630637682688054 | abcd |
| +---------------------+-------+
> show meta;
mysql+---------------+-------+
Value |
| Variable_name | +---------------+-------+
2 |
| total | 2 |
| total_found | time | 0.000 |
| 0] | abc |
| keyword[0] | 1 |
| docs[0] | 1 |
| hits[1] | abcd |
| keyword[1] | 1 |
| docs[1] | 1 |
| hits[+---------------+-------+
ALTER TABLE table RECONFIGURE
ALTER
can also reconfigure an RT table in the plain mode, so that new tokenization, morphology and other text processing settings from the configuration file take effect for new documents. Note, that the existing document will be left intact. Internally, it forcibly saves the current RAM chunk as a new disk chunk and adjusts the table header, so that new documents are tokenized using the updated full-text settings.
> show table rt settings;
mysql+---------------+-------+
Value |
| Variable_name | +---------------+-------+
| settings | |+---------------+-------+
1 row in set (0.00 sec)
> alter table rt reconfigure;
mysqlQuery OK, 0 rows affected (0.00 sec)
> show table rt settings;
mysql+---------------+----------------------+
Value |
| Variable_name | +---------------+----------------------+
= stem_en |
| settings | morphology +---------------+----------------------+
1 row in set (0.00 sec)
ALTER TABLE table REBUILD SECONDARY
You can also use ALTER
to rebuild secondary indexes in a given table. Sometimes, a secondary index can be disabled for the entire table or for one or multiple attributes within the table: * When an attribute is updated, its secondary index gets disabled. * If Manticore loads a table with outdated formatted secondary indexes, the secondary indexes will be disabled for the entire table.
ALTER TABLE table REBUILD SECONDARY
rebuilds secondary indexes from attribute data and enables them again.
ALTER TABLE rt REBUILD SECONDARY;
Query OK, 0 rows affected (0.00 sec)