--- title: "Delete rows" sidebarTitle: "Delete" description: "Remove rows by predicate, and reclaim their space." icon: trash availability: oss: available enterprise: available summary: >- Rows are deleted in the embedded library and on a deployment. In the embedded library you reclaim their space with `optimize()`; a deployment compacts automatically and removes old versions as its configuration sets. --- These examples use the table set up in [Ingesting data](/ingestion), and the connection made there. import { PyDeleteOperation as DeleteOperation, PyUpdateOptimizeCleanup as UpdateOptimizeCleanup, TsDeleteOperation, TsUpdateOptimizeCleanup, RsDeleteOperation, RsUpdateOptimizeCleanup, } from '/snippets/tables.mdx'; In SQL on a deployment, this is [`DELETE`](/sql/dml/delete). ## Delete rows {#delete-rows} Delete operations **soft delete** rows that match a given condition. The underlying data is not immediately removed, but is marked for deletion (in the [deletion files](https://lance.org/format/table/#deletion-files) at the Lance format level) and excluded from query results. {DeleteOperation} {TsDeleteOperation} {RsDeleteOperation} Expected table contents: | id | name | login_count | | --- | --- | --- | | 1 | Alice | 10 | | 2 | Bob | 20 | **Deleting rows removes them from the index** When rows are deleted, those rows are also excluded from the index segments, so indexed queries will not return them either. If ALL the rows are deleted (i.e., the table is emptied), ensure that you recreate the index after ingesting new data. To permanently remove deleted rows, the table has to be compacted and its old versions cleaned up, which frees up storage space. - In LanceDB OSS, compaction and cleanup are manual. Run `table.optimize()` regularly to free up disk space. - In LanceDB Enterprise, compaction runs automatically, and old versions are removed only when the deployment's configuration enables cleanup, with the retention period it sets. `optimize()` is not available there; see [Cleanup](/maintenance/cleanup). In OSS, `optimize()` removes versions older than 7 days by default. If you need to reclaim space from deleted rows more aggressively, call `table.optimize()` with a shorter retention window as follows: {UpdateOptimizeCleanup} {TsUpdateOptimizeCleanup} {RsUpdateOptimizeCleanup}