Pagination order, cursor boundaries and read snapshots
Gumi experiment recorded on 2026-10-24.

FILES
- pagination-visibility-lab.py
- pagination-visibility-lab-results.json
- pagination-visibility-lab-README.txt
All three are included at the root of pagination-visibility-lab.zip.

RUN
Tested: CPython 3.12.14, SQLite 3.53.1, macOS 27.0.1, arm64.
Python standard library only; sqlite3 is the Python module used.

python3 pagination-visibility-lab.py > result.json

Each case creates a fresh local database in an automatically removed temp
directory. It opens separate reader and writer connections with
isolation_level=None and enables WAL. SELECT results are fully fetched
before the next action. Except for the explicit snapshot case, page reads
are not held in one explicit transaction. Writer statements commit through
SQLite autocommit before the next reader query.
One process performs the specified interleaving; no threads, HTTP service,
external database, network access or business data are involved.
The report includes the actual expanded SQL trace for both connections.
Temporary file paths are not included in the SQL. No persistent DB is left.

中文说明
表 items 有整数主键 id 与非空整数 created_at。初始数据为：
(1,100), (2,100), (3,200), (4,200), (5,300), (6,300)。
created_at 是用来表示先后的教学整数，不是真实 Unix 时间戳。
两列均降序，第一页 6,5,4，完整游标由末行得到 (200,4)。
案例之间的数据完全独立；例如各案例的编号七不是同一条业务记录。
程序验证给定输入下的实际行为，不是通用分页服务、性能基准或部署方案。

日本語説明
items は整数主キー id と非 NULL の整数 created_at を持ちます。
初期値は (1,100), (2,100), (3,200), (4,200), (5,300), (6,300)。
created_at は順序を表す教材の整数で、実際の Unix タイムスタンプでは
ありません。二列とも降順で、最初は 6,5,4、末尾の完全なキーは (200,4)。
ケースごとに DB を作り直し、各例の番号七は別のデモ用行です。
与えた入力に対する動作の検査で、汎用ページングサービス、速度の
ベンチマーク、配備手順ではありません。

RECORDED CASES
1. ties_and_index
   ORDER BY created_at DESC LIMIT 3 gave 5,6,3 before the compound index,
   and 6,5,4 after creating items_feed(created_at DESC,id DESC).
   With both ORDER BY columns explicit, both runs gave 6,5,4.
   The incomplete-order observations are specific to this environment;
   no universal tie-breaking order is promised or asserted by the script.

2. insert_above_cursor
   First 6,5,4; baseline second 3,2,1. Another connection inserts (7,400).
   OFFSET 3 then gives 4,3,2; full-key cursor <(200,4) gives 3,2,1.
   The former repeats 4 and moves 1 later; it does not by itself prove
   that 1 is permanently lost from all later offset pages.

3. delete_above_cursor
   First 6,5,4; another connection deletes id 6.
   OFFSET 3 gives 2,1 and misses unread id 3; cursor gives 3,2,1.

4. incomplete_and_inclusive_cursor
   On unchanged data, created_at<200 gives 2,1 and misses the tied id 3.
   Full pair <=(200,4) gives 4,3,2 and repeats the boundary row.
   Strict pair <(200,4) gives 3,2,1.

5. new_row_below_cursor
   First 6,5,4; another connection inserts (7,150).
   Keyset second is 3,7,2. It can include a row absent at the first read.

6. mutable_sort_key
   First 6,5,4; another connection moves id 5 from created_at=300 to 150.
   Keyset second is 3,5,2 and repeats the seen id 5.

7. explicit_read_snapshot
   Reader BEGIN, then SELECT first 6,5,4 establishes its snapshot.
   Writer inserts (7,400) and commits. In the same reader transaction,
   OFFSET second remains 3,2,1 and first remains 6,5,4.
   After reader COMMIT, the next first page is 7,6,5.

8. static_walk_and_boundaries
   Page sizes 1 and 3 both traverse exactly 6,5,4,3,2,1 on unchanged data,
   ending with an empty page. Empty table gives an empty first page.
   A NULL sort-key insert is actually rejected by the table constraint.

SCOPE
Non-NULL integer sort keys, unique ids and the same descending direction
for both columns. No mixed ASC/DESC, text collation, other SQL engine,
arbitrary cursor token, cross-request transaction service, load testing
or large-table timing was tested. The script uses a fresh database per
case and checks the recorded expected outputs. A read snapshot is distinct
from a unique order or keyset boundary. No keyset query is claimed to
freeze all future rows or withstand arbitrary updates to ordering keys.

PRIMARY SOURCES (read 2026-10-24)
SQLite ORDER BY tie semantics and LIMIT/OFFSET:
https://www.sqlite.org/lang_select.html
SQLite row-value comparisons and scrolling windows:
https://www.sqlite.org/rowvalue.html
SQLite connection isolation and WAL read snapshots:
https://www.sqlite.org/isolation.html
WAL operation and reader/writer overlap:
https://www.sqlite.org/wal.html

The documented rules and the supplied measurements are kept distinct:
particular row sequences and interleavings are this experiment's results,
while proposed application choices in the article are analysis.
