console store: the plan witness names the people lists' tie sort; first account is the earliest live membership
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+35
−3
internal/console/opstore_test.go+35 −3
CI failed — run details
diff --git a/internal/console/opstore_test.go b/internal/console/opstore_test.go| index 2885eeb7b..899a1b1f9 100644 |
| --- a/internal/console/opstore_test.go |
| +++ b/internal/console/opstore_test.go |
| @@ -99,6 +99,10 @@ type opPlanCase struct { |
| // mergeSorts is how many "USE TEMP B-TREE FOR ORDER BY" lines a MERGE |
| // (UNION) may carry, one per half; 0 everywhere else. |
| mergeSorts int |
| + // tieSort allows "USE TEMP B-TREE FOR LAST TERM OF ORDER BY": the |
| + // people lists walk users_by_created and sort only the people who |
| + // joined in the same second by address, stopping at the page's end. |
| + tieSort bool |
| } |
| // opPlanForbidden holds for every operator query: no per-row subquery and |
| @@ -131,19 +135,19 @@ var opQueryPlans = []opPlanCase{ |
| {name: "deploys", sql: opSQLDeploys, args: []any{int64(1), "promote", "rollback"}, |
| want: []string{"SEARCH audit USING INDEX audit_by_time (created_at>?)"}, |
| notWant: []string{"SCAN audit", "audit_by_action"}}, |
| - {name: "newest people", sql: opSQLNewestPeople, args: []any{50}, |
| + {name: "newest people", tieSort: true, sql: opSQLNewestPeople, args: []any{50}, |
| want: []string{"SCAN users USING INDEX users_by_created", |
| "SEARCH memberships USING INDEX memberships_by_address (address=?)", |
| "SEARCH accounts USING INTEGER PRIMARY KEY (rowid=?)", |
| "SEARCH apps USING INDEX apps_by_creator (created_by=?)"}, |
| notWant: []string{"SCAN memberships", "SCAN apps", "SCAN accounts"}}, |
| - {name: "people page", sql: opSQLPeoplePage, args: []any{"", "%%", 50, 0}, |
| + {name: "people page", tieSort: true, sql: opSQLPeoplePage, args: []any{"", "%%", 50, 0}, |
| want: []string{"SCAN users USING INDEX users_by_created", |
| "SEARCH memberships USING INDEX memberships_by_address (address=?)", |
| "SEARCH accounts USING INTEGER PRIMARY KEY (rowid=?)", |
| "SEARCH apps USING INDEX apps_by_creator (created_by=?)"}, |
| notWant: []string{"SCAN memberships", "SCAN apps", "SCAN accounts"}}, |
| - {name: "people page searched", sql: opSQLPeoplePage, args: []any{"exam", `%exam%`, 50, 0}, |
| + {name: "people page searched", tieSort: true, sql: opSQLPeoplePage, args: []any{"exam", `%exam%`, 50, 0}, |
| want: []string{"SCAN users", |
| "SEARCH memberships USING INDEX memberships_by_address (address=?)", |
| "SEARCH apps USING INDEX apps_by_creator (created_by=?)"}, |
| @@ -250,6 +254,13 @@ func opPlanProblems(db sqlHandle, c opPlanCase) ([]string, []string, error) { |
| if sorts > 0 && (sorts > c.mergeSorts || !has("MERGE (UNION)")) { |
| problems = append(problems, "has USE TEMP B-TREE FOR ORDER BY") |
| } |
| + for _, line := range plan { |
| + if strings.Contains(line, "TEMP B-TREE") && strings.Contains(line, "ORDER BY") && |
| + !strings.Contains(line, "USE TEMP B-TREE FOR ORDER BY") && |
| + !(c.tieSort && line == "USE TEMP B-TREE FOR LAST TERM OF ORDER BY") { |
| + problems = append(problems, "has "+line) |
| + } |
| + } |
| for _, w := range append(append([]string(nil), opPlanForbidden...), c.notWant...) { |
| if w != "USE TEMP B-TREE FOR ORDER BY" && has(w) { |
| problems = append(problems, "has "+w) |
| @@ -826,3 +837,24 @@ func TestOperatorCountsAtScale(t *testing.T) { |
| } |
| } |
| } |
| + |
| +func TestFirstAccountIsTheEarliestLiveMembership(t *testing.T) { |
| + s := openOpStore(t) |
| + opUser(t, s, "ann@example.com", opNow.Add(-48*time.Hour)) |
| + early, late, gone := testAccountID(), testAccountID(), testAccountID() |
| + opMust(t, s.CreateAccount(gone, "gone", "closed", "ann@example.com", opNow.Add(-3*time.Hour))) |
| + opMust(t, s.CreateAccount(late, "late", "notes", "ann@example.com", opNow.Add(-time.Hour))) |
| + opMust(t, s.CreateAccount(early, "erly", "shop", "bob@example.com", opNow.Add(-3*time.Hour))) |
| + opMust(t, s.AddMember(early, "ann@example.com", RoleMember, opNow.Add(-2*time.Hour))) |
| + opMust(t, s.DeleteAccount(gone, opNow)) |
| + for _, app := range []string{"one", "two"} { |
| + if _, err := s.CreateAppIn(late, app, "ann@example.com", opNow); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + got, err := s.NewestPeople(1) |
| + opMust(t, err) |
| + if len(got) != 1 || got[0].FirstAccount != "shop" || got[0].Accounts != 2 || got[0].Apps != 2 { |
| + t.Fatalf("NewestPeople = %+v, want first account shop, 2 accounts, 2 apps", got) |
| + } |
| +} |