mirror of
https://github.com/lancedb/lancedb.git
synced 2026-12-03 07:45:17 +00:00
docs: document visible row counts for RTE tables (#5362)
## Summary Document how to count visible rows in an Enterprise Realtime Engine table. Use `COUNT(*)` when Flight SQL is reachable, or sum Arrow batch sizes from an unbounded, one-column REST scan. Explain the cost of the REST scan and the scope of the explicit base-table count. ## Validation Exercised both routes through published Python clients on isolated Linux. The large fixture returned 100,000 visible rows, then 99,999 after an overwrite and a base-key delete, then 99,998 after a fresh-key delete. An independent key/value oracle matched each stage. The REST base-only count stayed at 80,000 and the default REST count returned HTTP 400.
This commit is contained in:
@@ -49,6 +49,40 @@ for a full scan of the memtable only when it can't honor the query through
|
||||
a graph -- a prefilter, a primary-key override, a distance lower bound, or
|
||||
before the memtable has any index yet on a cold start.
|
||||
|
||||
## Count visible rows in Enterprise {#count-visible-rows}
|
||||
|
||||
On an RTE-enabled Enterprise table, `count_rows()` returns HTTP 400.
|
||||
The following queries count the visible rows after merging the base table and
|
||||
the fresh tier by primary key, including the effects of fresh deletes.
|
||||
|
||||
### With Flight SQL
|
||||
|
||||
If your client can reach the deployment's Flight SQL endpoint, use
|
||||
[`execute_query()`](/basics/sql#sql-from-python) with `COUNT(*)`. In this
|
||||
example, `db` connects to the same database as `frames` and sets
|
||||
`sql_host_override` to that endpoint.
|
||||
|
||||
```python
|
||||
reader = db.execute_query("SELECT COUNT(*) AS visible_rows FROM frames")
|
||||
visible_rows = reader.read_all()["visible_rows"][0].as_py()
|
||||
```
|
||||
|
||||
### With REST
|
||||
|
||||
If your client connects over REST only, scan one column without a limit
|
||||
and sum the Arrow batch sizes.
|
||||
|
||||
```python
|
||||
batches = frames.search().select(["frame_id"]).use_rte(True).to_batches()
|
||||
visible_rows = sum(batch.num_rows for batch in batches)
|
||||
```
|
||||
|
||||
This scans the table and transfers the selected column for every visible row.
|
||||
Use the primary key or another small column to limit the data transferred.
|
||||
|
||||
The REST `count_rows` endpoint accepts `use_rte=false` for a base-table count.
|
||||
That count excludes RTE changes that have yet to be compacted into the base table.
|
||||
|
||||
## Embedded: one process, one dataset {#embedded}
|
||||
|
||||
LanceDB Embedded runs this same LSM scanner directly against the local Lance
|
||||
@@ -72,7 +106,8 @@ returning a result that omits un-compacted rows.
|
||||
<Note>
|
||||
Support for all table operations on RTE tables is coming soon. Time travel,{/* Draft until branching reaches early access: restore " branching," */}
|
||||
`count_rows`, row IDs (`with_row_id`), and `TABLESAMPLE` are not yet
|
||||
available.
|
||||
available. In Enterprise, you can [count visible rows](#count-visible-rows)
|
||||
using Flight SQL or a REST scan.
|
||||
</Note>
|
||||
|
||||
## Next steps {#next-steps}
|
||||
|
||||
Reference in New Issue
Block a user