## 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
CREATE TABLE T (
  A VARCHAR(20),
  B VARCHAR(10),
  C INTEGER,
  PRIMARY KEY (A, B)
);
INSERT INTO T VALUES ('a', 'p', -2147483648);
INSERT INTO T VALUES ('b', 'q', 100);
INSERT INTO T VALUES ('b', 'r', 200);
INSERT INTO T VALUES ('c', 's', 300);
INSERT INTO T VALUES ('d', 't', 2147483647);
INSERT INTO T VALUES ('b', 't', 50);
SELECT A, COUNT(*) AS D, SUM(C) AS E FROM T GROUP BY A HAVING COUNT(*) > 1;
PRAGMA case_sensitive_like = YES;
PRAGMA user_version;
PRAGMA wal_checkpoint('NOOP');
.timer 192319231923
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(w INT, x INT);
INSERT INTO t1(w,x) VALUES(1,10),(2,20),(3,30), (2,21),(3,31), (3,32);
CREATE INDEX t1wx ON t1(w,x);

DROP TABLE IF EXISTS t2;
CREATE TABLE t2(w INT, y VARCHAR(8));
INSERT INTO t2(w,y) VALUES(1,'one'),(2,'two'),(3,'three'),(4,'four');
CREATE INDEX t2wy ON t2(w,y);

SELECT cnt, xyz, (SELECT y FROM t2 WHERE w=cnt), '|' FROM (SELECT count(*) AS cnt, w AS xyz FROM t1 GROUP BY 2) ORDER BY cnt, xyz;
SELECT cnt, xyz, lower((SELECT y FROM t2 WHERE w=cnt)), '|' FROM (SELECT count(*) AS cnt, w AS xyz FROM t1 GROUP BY 2) ORDER BY cnt, xyz;
SELECT cnt, xyz, CASE WHEN (SELECT y FROM t2 WHERE w=cnt)=='two' THEN 'aaa' ELSE 'bbb' END, '|' FROM (SELECT count(*) AS cnt, w AS xyz FROM t1 GROUP BY 2) ORDER BY +cnt;

WITH cte AS (SELECT * FROM t2 WHERE w IN (SELECT w FROM t2 LIMIT 5)) SELECT * FROM cte;
REINDEX;
INSERT INTO t1 DEFAULT VALUES;
WITH n AS NOT MATERIALIZED (SELECT * FROM t2) SELECT * FROM n WHERE y > 0;
INSERT INTO t1 SELECT * FROM t1;
ALTER TABLE t1 RENAME TO t1_r1510;
VACUUM main;
ALTER TABLE T ADD COLUMN extra_934 CLOB DEFAULT 0;
```

## Actual output

```sql
b|3|350
0
0|-1|-1
Run Time: real 0.000 user 0.000000 sys 0.000020
Run Time: real 0.000 user 0.000000 sys 0.000067
Run Time: real 0.000 user 0.000000 sys 0.000023
Run Time: real 0.000 user 0.000000 sys 0.000075
Run Time: real 0.000 user 0.000000 sys 0.000005
Run Time: real 0.000 user 0.000000 sys 0.000047
Run Time: real 0.000 user 0.000000 sys 0.000015
Run Time: real 0.000 user 0.000000 sys 0.000067
1|1|one||
2|2|two||
3|3|three||
Run Time: real 0.000 user 0.000000 sys 0.000077
1|1|one||
2|2|two||
3|3|three||
Run Time: real 0.001 user 0.000000 sys 0.000053
1|1|bbb||
2|2|aaa||
3|3|bbb||
Run Time: real 0.000 user 0.000000 sys 0.000051
1|one
2|two
3|three
4|four
Run Time: real 0.000 user 0.000000 sys 0.000101
Run Time: real 0.000 user 0.000000 sys 0.000035
Run Time: real 0.000 user 0.000000 sys 0.000015
1|one
2|two
3|three
4|four
Run Time: real 0.000 user 0.000000 sys 0.000023
Run Time: real 0.000 user 0.000000 sys 0.000033
Run Time: real 0.000 user 0.000000 sys 0.000592
Run Time: real 0.001 user 0.000000 sys 0.000440
Run Time: real 0.000 user 0.000000 sys 0.000219
```

## Expectation

```sql
b|3|350
0
0|-1|-1
Run Time: real 0.000003 user 0.000014 sys 0.000000
Run Time: real 0.000025 user 0.000026 sys 0.000000
Run Time: real 0.000010 user 0.000010 sys 0.000000
Run Time: real 0.000028 user 0.000029 sys 0.000000
Run Time: real 0.000002 user 0.000001 sys 0.000000
Run Time: real 0.000018 user 0.000018 sys 0.000000
Run Time: real 0.000006 user 0.000006 sys 0.000000
Run Time: real 0.000023 user 0.000024 sys 0.000000
1|1|one||
2|2|two||
3|3|three||
Run Time: real 0.000039 user 0.000039 sys 0.000000
1|1|one||
2|2|two||
3|3|three||
Run Time: real 0.000023 user 0.000022 sys 0.000000
1|1|bbb||
2|2|aaa||
3|3|bbb||
Run Time: real 0.000019 user 0.000020 sys 0.000000
1|one
2|two
3|three
4|four
Run Time: real 0.000057 user 0.000056 sys 0.000000
Run Time: real 0.000014 user 0.000014 sys 0.000000
Run Time: real 0.000006 user 0.000006 sys 0.000000
1|one
2|two
3|three
4|four
Run Time: real 0.000008 user 0.000009 sys 0.000000
Run Time: real 0.000012 user 0.000013 sys 0.000000
Run Time: real 0.000255 user 0.000256 sys 0.000000
Run Time: real 0.000168 user 0.000169 sys 0.000000
Run Time: real 0.000087 user 0.000088 sys 0.000000
```

## Flag

```

```

