Skip to content

Apply the primary key tie-breaker to the first page of a sorted table - #3055

Merged
simonw merged 1 commit into
simonw:mainfrom
PDGGK:sort-first-page-tiebreak
Nov 15, 2026
Merged

simonw merged 1 commit into
simonw:mainfrom
PDGGK:sort-first-page-tiebreak

Conversation

@PDGGK

@PDGGK PDGGK commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Closes:

The primary keys were only added to the sort as a tie-breaker when ?_next= was set. So the first page of a sorted table returned ties in whatever order SQLite picked, while the cursor assumes primary key order. On tables with a text or compound primary key, following next_url repeats some rows and skips others. The issue has a script that shows it.

The tie-breaker now applies to the first page as well, for tables only, since a view has no primary keys to add. Later pages already used this order, so the first page now pays the same sort cost they do. I did not measure that on a large table.

test_sort_ties_paginate_without_skips_or_repeats covers _sort and _sort_desc on a text key and a compound key. With the tie-breaker limited to _next again, all four cases fail, for example with assert ['a', 'm', 'q', 'y', 'z', 'z'] == ['a', 'c', 'm', 'q', 'y', 'z']. With the change, tests/test_table_api.py, test_table_html.py, test_csv.py, test_html.py, test_facets.py and test_api.py give 657 passed, 4 skipped, 1 xfailed, 10 xpassed, and ruff check and black --check are clean. I ran this in a Linux container and did not run the full suite or the Playwright tests.

The primary keys were only added to the sort order when ?_next= was set,
so the first page returned ties on the sort column in whatever order
SQLite picked while the cursor assumed primary key order. Tables with a
text or compound primary key repeated some rows and skipped others when
following next_url.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T15:23:39.781280Z e1ce601 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codecov

codecov Bot commented Nov 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (4e70219) to head (e1ce601).
⚠️ Report is 30 commits behind head on main.

Files with missing lines Patch % Lines
datasette/views/table.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main   #3055   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         79      79           
  Lines      13875   13875           
=====================================
  Misses     13875   13875           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@simonw

simonw commented Nov 15, 2026

Copy link
Copy Markdown
Owner

@simonw

simonw commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

@simonw
simonw merged commit fc67ea9 into simonw:main Nov 15, 2026
15 checks passed
@simonw simonw added this to the Datasette 1.0 stable milestone Nov 15, 2026
simonw added a commit that referenced this pull request Nov 15, 2026
Refs #749, #862, #954, #1062, #1101, #1179, #1410, #2137, #2186, #2317, #2612, #2663, #2770, #2969, #2980, #2987, #3035, #3036, #3053, #3054, #3055, #3056, #3057, #3060, #3061, #3063, #3064, #3067

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants