Deleting a table is performed in 2 steps internally:
- Table is cleared (similar to TRUNCATE)
- All table files are removed from the table folder. All the external table files that were used by the table (such as wordforms, extensions or stopwords) are also deleted. Note that these external files are copied to the table folder when
CREATE TABLE
is used, so the original files specified inCREATE TABLE
will not be deleted.
Deleting a table is possible only when the server is running in the RT mode. It is possible to delete RT tables, PQ tables and distributed tables.
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
DROP TABLE products;
POST /cli -d "DROP TABLE products"
$params = [ 'table' => 'products' ];
$response = $client->indices()->drop($params);
utilsApi.sql('DROP TABLE products')
await utilsApi.sql('DROP TABLE products')
res = await utilsApi.sql('DROP TABLE products');
sqlresult = utilsApi.sql("DROP TABLE products", true);
sqlresult = utilsApi.Sql("DROP TABLE products", true);
let sqlresult = utils_api.sql("DROP TABLE products", Some(true)).await;
Query OK, 0 rows affected (0.02 sec)
{
"total":0,
"error":"",
"warning":""
}
Array
(
[total] => 0
[error] =>
[warning] =>
)
{u'error': u'', u'total': 0, u'warning': u''}
{u'error': u'', u'total': 0, u'warning': u''}
{"total":0,"error":"","warning":""}
{total=0, error=, warning=}
{total=0, error="", warning=""}
{total=0, error="", warning=""}
Here is the syntax of the DROP TABLE
statement in SQL:
DROP TABLE [IF EXISTS] table_name
When deleting a table via SQL, adding IF EXISTS
can be used to delete the table only if it exists. If you try to delete a non-existing table with the IF EXISTS
option, nothing happens.
When deleting a table via PHP, you can add an optional silent
parameter which works the same as IF EXISTS
.
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
DROP TABLE IF EXISTS products;
POST /cli -d "DROP TABLE IF EXISTS products"
$params =
[
'table' => 'products',
'body' => ['silent' => true]
];
$client->indices()->drop($params);
utilsApi.sql('DROP TABLE IF EXISTS products')
await utilsApi.sql('DROP TABLE IF EXISTS products')
res = await utilsApi.sql('DROP TABLE IF EXISTS products');
sqlresult = utilsApi.sql("DROP TABLE IF EXISTS products", true);
sqlresult = utilsApi.Sql("DROP TABLE IF EXISTS products", true);
let sqlresult = utils_api.sql("DROP TABLE IF EXISTS products", Some(true)).await;
{u'error': u'', u'total': 0, u'warning': u''}
{u'error': u'', u'total': 0, u'warning': u''}
{"total":0,"error":"","warning":""}
{total=0, error=, warning=}
{total=0, error="", warning=""}
{total=0, error="", warning=""}
The table can be emptied with a TRUNCATE TABLE
SQL statement or with a truncate()
PHP client function.
Here is the syntax for the SQL statement:
TRUNCATE TABLE table_name [WITH RECONFIGURE]
When this statement is executed, it clears the RT or distributed table completely. It disposes the in-memory data, unlinks all the table data files, and releases the associated binary logs.
For emptying a distributed table, use syntax without the with reconfigure
option. Simply execute the standard TRUNCATE statement against your distributed table.
TRUNCATE TABLE distributed_table
NOTE: Emptying a distributed table requires Manticore Buddy. If it doesn't work, make sure Buddy is installed.
A table can also be emptied with DELETE FROM index WHERE id>0
, but it's not recommended as it's slower than TRUNCATE
.
- SQL
- JSON
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
TRUNCATE TABLE products;
POST /cli -d "TRUNCATE TABLE products"
$params = [ 'table' => 'products' ];
$response = $client->indices()->truncate($params);
utilsApi.sql('TRUNCATE TABLE products')
await utilsApi.sql('TRUNCATE TABLE products')
res = await utilsApi.sql('TRUNCATE TABLE products');
utilsApi.sql("TRUNCATE TABLE products", true);
utilsApi.Sql("TRUNCATE TABLE products", true);
utils_api.sql("TRUNCATE TABLE products", Some(true)).await;
Query OK, 0 rows affected (0.02 sec)
{
"total":0,
"error":"",
"warning":""
}
Array(
[total] => 0
[error] =>
[warning] =>
)
{u'error': u'', u'total': 0, u'warning': u''}
{u'error': u'', u'total': 0, u'warning': u''}
{"total":0,"error":"","warning":""}
{total=0, error=, warning=}
{total=0, error="", warning=""}
{total=0, error="", warning=""}
One of the possible uses of this command is before attaching a table.
When RECONFIGURE
option is used new tokenization, morphology, and other text processing settings specified in the config take effect after the table gets cleared. In case the schema declaration in config is different from the table schema the new schema from config got applied after table get cleared.
NOTE: The
RECONFIGURE
option only makes sense in Plain mode, where it applies the settings from the configuration file. Note thatTRUNCATE
is only supported for RT tables, and theRECONFIGURE
option can only be used with RT tables when Manticore is running in Plain mode.
With this option clearing and reconfiguring a table becomes one atomic operation.
- SQL
- HTTP
- PHP
- Python
- Python-asyncio
- javascript
- Java
- C#
- Rust
TRUNCATE TABLE products with reconfigure;
POST /cli -d "TRUNCATE TABLE products with reconfigure"
$params = [ 'table' => 'products', 'with' => 'reconfigure' ];
$response = $client->indices()->truncate($params);
utilsApi.sql('TRUNCATE TABLE products WITH RECONFIGURE')
await utilsApi.sql('TRUNCATE TABLE products WITH RECONFIGURE')
res = await utilsApi.sql('TRUNCATE TABLE products WITH RECONFIGURE');
utilsApi.sql("TRUNCATE TABLE products WITH RECONFIGURE", true);
utilsApi.Sql("TRUNCATE TABLE products WITH RECONFIGURE" ,true);
utils_api.sql("TRUNCATE TABLE products WITH RECONFIGURE", Some(true)).await;
Query OK, 0 rows affected (0.02 sec)
{
"total":0,
"error":"",
"warning":""
}
Array(
[total] => 0
[error] =>
[warning] =>
)
{u'error': u'', u'total': 0, u'warning': u''}
{u'error': u'', u'total': 0, u'warning': u''}
{"total":0,"error":"","warning":""}
{total=0, error=, warning=}
{total=0, error="", warning=""}
Manticore Search is a highly distributed system that provides all the necessary components to create a highly available and scalable database for search. This includes:
- distributed table for sharding
- Mirroring for high availability
- Load balancing for scalability
- Replication for data safety
Manticore Search offers great flexibility in terms of how you set up your cluster. There are no limitations, so it's up to you to design your cluster according to your needs. Simply learn about the tools mentioned above and use them to achieve your desired goal.
To add a new node to a cluster, simply start another instance of Manticore and ensure that it is accessible by the other nodes in the cluster. Connect the new node to the rest of the cluster using a distributed table and ensure data safety with replication.