## Summary
<!--Explain briefly what goes wrong and explain why you believe this is a bug and not the intended behavior of SQLite (if it is not a crash).-->**No review yet**

## Minimized query

```sql
PRAGMA defer_foreign_keys = NO;
PRAGMA cache_spill = TRUE;
PRAGMA vdbe_listing = YES;
PRAGMA ignore_check_constraints = NO;
.timer 192319231923
BEGIN;
CREATE TABLE album( aid INTEGER PRIMARY KEY, title TEXT UNIQUE NOT NULL);
CREATE TABLE track( tid INTEGER PRIMARY KEY, aid INTEGER NOT NULL REFERENCES album, tn INTEGER NOT NULL, name TEXT, UNIQUE(aid, tn));
INSERT INTO album VALUES(1, '1-one'), (2, '2-two'), (3, '3-three');
INSERT INTO track VALUES (NULL, 1, 1, 'one-a'), (NULL, 2, 2, 'two-b'), (NULL, 3, 3, 'three-c'), (NULL, 1, 3, 'one-c'), (NULL, 2, 1, 'two-a'), (NULL, 3, 1, 'three-a');
COMMIT;
SELECT name FROM album JOIN track USING (aid) ORDER BY title, tn;

UPDATE track SET aid = json_object('k', aid) WHERE aid IS NOT NULL RETURNING *;
```

## Actual output

```sql
Run Time: real 0.000 user 0.000016 sys 0.000000
Run Time: real 0.000 user 0.000248 sys 0.000000
Run Time: real 0.000 user 0.000084 sys 0.000000
Run Time: real 0.000 user 0.000030 sys 0.000000
Run Time: real 0.000 user 0.000030 sys 0.000000
Run Time: real 0.000 user 0.000006 sys 0.000000
one-a
one-c
two-a
two-b
three-a
three-c
Run Time: real 0.000 user 0.000047 sys 0.000000
1|{"k":1}|1|one-a
2|{"k":2}|2|two-b
3|{"k":3}|3|three-c
4|{"k":1}|3|one-c
5|{"k":2}|1|two-a
6|{"k":3}|1|three-a
Run Time: real 0.001 user 0.000140 sys 0.000000
```

## Expectation

```sql
Run Time: real 0.000003 user 0.000000 sys 0.000013
Run Time: real 0.000157 user 0.000000 sys 0.000157
Run Time: real 0.000037 user 0.000000 sys 0.000037
Run Time: real 0.000018 user 0.000000 sys 0.000018
Run Time: real 0.000012 user 0.000000 sys 0.000013
Run Time: real 0.000003 user 0.000000 sys 0.000004
one-a
one-c
two-a
two-b
three-a
three-c
Run Time: real 0.000023 user 0.000000 sys 0.000024
1|{"k":1}|1|one-a
2|{"k":2}|2|two-b
3|{"k":3}|3|three-c
4|{"k":1}|3|one-c
5|{"k":2}|1|two-a
6|{"k":3}|1|three-a
Run Time: real 0.000200 user 0.000000 sys 0.000202
```

## Flag

```

```

