|
6 | 6 | "fmt" |
7 | 7 | "io" |
8 | 8 | "log/slog" |
| 9 | + "math" |
9 | 10 |
|
10 | 11 | "github.com/cipherstash/stack/languages/golang/internal/record" |
11 | 12 | "github.com/cipherstash/vitaminc/bindings/go/vcffi" |
@@ -60,8 +61,12 @@ type Bucket struct { |
60 | 61 | // size the fetch at. None of it is secret: the server holds the filters and |
61 | 62 | // the catalog holds the row count. |
62 | 63 | type Stats struct { |
63 | | - // Rows is the rows the query scans, such as greatest(reltuples, 0) |
64 | | - // from pg_class. |
| 64 | + // Rows is the rows the query scans, such as reltuples from pg_class |
| 65 | + // read with a reltuples >= 0 filter. reltuples is -1 for a table never |
| 66 | + // vacuumed or analysed: that is an unknown count, not an empty table, |
| 67 | + // and a count of 0 would promise a fetch of exactly want. While the |
| 68 | + // count is unknown, call no TargetLimit and page with a cursor, or run |
| 69 | + // ANALYZE first. |
65 | 70 | Rows uint64 |
66 | 71 | // Histogram is a measured histogram of the stored filters' set-bit |
67 | 72 | // counts. With none, the engine uses the index's declared prior, and |
@@ -101,12 +106,14 @@ type Limit struct { |
101 | 106 | func (l Limit) Rows() (uint64, bool) { return l.rows, l.bounded } |
102 | 107 |
|
103 | 108 | // FetchOr is the rows to fetch, or page when no finite fetch can be |
104 | | -// promised, for a caller that pages either way. |
| 109 | +// promised, for a caller that pages either way. Never more than |
| 110 | +// math.MaxInt64, the largest LIMIT PostgreSQL and database/sql take: a |
| 111 | +// larger page is cut to it. |
105 | 112 | func (l Limit) FetchOr(page uint64) uint64 { |
106 | 113 | if l.bounded { |
107 | 114 | return l.rows |
108 | 115 | } |
109 | | - return page |
| 116 | + return min(page, math.MaxInt64) |
110 | 117 | } |
111 | 118 |
|
112 | 119 | // QueryTerm derives the query term for one field of the plan, an operator |
|
0 commit comments