## 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
SAVEPOINT sp6682;
ATTACH DATABASE ':memory:' AS aux6;
SAVEPOINT sp4545;
-- .timeout -1

creATE VIRTUAL TABLE t0 USING fts3("x", "y", "z");
DROP TABLE t0;
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (json_object(),3.141592653589793,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
ROLLBACK TO sp4545;
RELEASE sp4545;
DETACH DATABASE aux6;
CREATE TABLE T1 (
  A VARCHAR(10) PRIMARY KEY,
  B VARCHAR(15) UNIQUE,
  C BIGINT
);
CREATE TABLE T2 (
  X VARCHAR(20) PRIMARY KEY,
  A VARCHAR(10),
  FOREIGN KEY (A) REFERENCES T1(A)
);
INSERT INTO T1 VALUES ('a', 'p', 9999999999999);
INSERT INTO T1 VALUES ('b', 'q', -9999999999999);
INSERT INTO T2 VALUES ('m', 'a');
INSERT INTO T2 VALUES ('n', 'b');
SELECT T2.X, T1.C FROM T2 INNER JOIN T1 ON T2.A = T1.A WHERE T1.C > -1000000000000;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T2_5260 ON T2(A COLLATE NOCASE) WHERE A > 0;
SELECT LAG(C, 0, 'default') OVER (ORDER BY C RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE NO OTHERS) FROM T1;
ROLLBACK TO sp6682;
RELEASE sp6682;
SAVEPOINT sp6682;
ATTACH DATABASE ':memory:' AS aux6;
SAVEPOINT sp4545;
-- .timeout -1

creATE VIRTUAL TABLE t0 USING fts3("x", "y", "z");
DROP TABLE t0;
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (json_object(),3.141592653589793,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
ROLLBACK TO sp4545;
RELEASE sp4545;
DETACH DATABASE aux6;
CREATE TABLE T1 (
  A VARCHAR(10) PRIMARY KEY,
  B VARCHAR(15) UNIQUE,
  C BIGINT
);
CREATE TABLE T2 (
  X VARCHAR(20) PRIMARY KEY,
  A VARCHAR(10),
  FOREIGN KEY (A) REFERENCES T1(A)
);
INSERT INTO T1 VALUES ('a', 'p', 9999999999999);
INSERT INTO T1 VALUES ('b', 'q', -9999999999999);
INSERT INTO T2 VALUES ('m', 'a');
INSERT INTO T2 VALUES ('n', 'b');
SELECT T2.X, T1.C FROM T2 INNER JOIN T1 ON T2.A = T1.A WHERE T1.C > -1000000000000;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T2_5260 ON T2(A COLLATE NOCASE) WHERE A > 0;
SELECT LAG(C, 0, 'default') OVER (ORDER BY C RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE NO OTHERS) FROM T1;
ROLLBACK TO sp6682;
RELEASE sp6682;
SAVEPOINT sp6682;
ATTACH DATABASE ':memory:' AS aux6;
SAVEPOINT sp4545;
-- .timeout -1

creATE VIRTUAL TABLE t0 USING fts3("x", "y", "z");
DROP TABLE t0;
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (json_object(),3.141592653589793,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
ROLLBACK TO sp4545;
RELEASE sp4545;
DETACH DATABASE aux6;
CREATE TABLE T1 (
  A VARCHAR(10) PRIMARY KEY,
  B VARCHAR(15) UNIQUE,
  C BIGINT
);
CREATE TABLE T2 (
  X VARCHAR(20) PRIMARY KEY,
  A VARCHAR(10),
  FOREIGN KEY (A) REFERENCES T1(A)
);
INSERT INTO T1 VALUES ('a', 'p', 9999999999999);
INSERT INTO T1 VALUES ('b', 'q', -9999999999999);
INSERT INTO T2 VALUES ('m', 'a');
INSERT INTO T2 VALUES ('n', 'b');
SELECT T2.X, T1.C FROM T2 INNER JOIN T1 ON T2.A = T1.A WHERE T1.C > -1000000000000;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T2_5260 ON T2(A COLLATE NOCASE) WHERE A > 0;
SELECT LAG(C, 0, 'default') OVER (ORDER BY C RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE NO OTHERS) FROM T1;
ROLLBACK TO sp6682;
RELEASE sp6682;
SAVEPOINT sp6682;
ATTACH DATABASE ':memory:' AS aux6;
SAVEPOINT sp4545;
-- .timeout -1

creATE VIRTUAL TABLE t0 USING fts3("x", "y", "z");
DROP TABLE t0;
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (json_object(),3.141592653589793,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
ROLLBACK TO sp4545;
RELEASE sp4545;
DETACH DATABASE aux6;
CREATE TABLE T1 (
  A VARCHAR(10) PRIMARY KEY,
  B VARCHAR(15) UNIQUE,
  C BIGINT
);
CREATE TABLE T2 (
  X VARCHAR(20) PRIMARY KEY,
  A VARCHAR(10),
  FOREIGN KEY (A) REFERENCES T1(A)
);
INSERT INTO T1 VALUES ('a', 'p', 9999999999999);
INSERT INTO T1 VALUES ('b', 'q', -9999999999999);
INSERT INTO T2 VALUES ('m', 'a');
INSERT INTO T2 VALUES ('n', 'b');
SELECT T2.X, T1.C FROM T2 INNER JOIN T1 ON T2.A = T1.A WHERE T1.C > -1000000000000;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T2_5260 ON T2(A COLLATE NOCASE) WHERE A > 0;
SELECT LAG(C, 0, 'default') OVER (ORDER BY C RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE NO OTHERS) FROM T1;
ROLLBACK TO sp6682;
RELEASE sp6682;
SAVEPOINT sp6682;
ATTACH DATABASE ':memory:' AS aux6;
SAVEPOINT sp4545;
-- .timeout -1

creATE VIRTUAL TABLE t0 USING fts3("x", "y", "z");
DROP TABLE t0;
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (json_object(),3.141592653589793,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
ROLLBACK TO sp4545;
RELEASE sp4545;
DETACH DATABASE aux6;
CREATE TABLE T1 (
  A VARCHAR(10) PRIMARY KEY,
  B VARCHAR(15) UNIQUE,
  C BIGINT
);
CREATE TABLE T2 (
  X VARCHAR(20) PRIMARY KEY,
  A VARCHAR(10),
  FOREIGN KEY (A) REFERENCES T1(A)
);
INSERT INTO T1 VALUES ('a', 'p', 9999999999999);
INSERT INTO T1 VALUES ('b', 'q', -9999999999999);
INSERT INTO T2 VALUES ('m', 'a');
INSERT INTO T2 VALUES ('n', 'b');
SELECT T2.X, T1.C FROM T2 INNER JOIN T1 ON T2.A = T1.A WHERE T1.C > -1000000000000;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T2_5260 ON T2(A COLLATE NOCASE) WHERE A > 0;
SELECT LAG(C, 0, 'default') OVER (ORDER BY C RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE NO OTHERS) FROM T1;
ROLLBACK TO sp6682;
RELEASE sp6682;
SAVEPOINT sp6682;
ATTACH DATABASE ':memory:' AS aux6;
SAVEPOINT sp4545;
-- .timeout -1

creATE VIRTUAL TABLE t0 USING fts3("x", "y", "z");
DROP TABLE t0;
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (json_object(),3.141592653589793,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
ROLLBACK TO sp4545;
RELEASE sp4545;
DETACH DATABASE aux6;
CREATE TABLE T1 (
  A VARCHAR(10) PRIMARY KEY,
  B VARCHAR(15) UNIQUE,
  C BIGINT
);
CREATE TABLE T2 (
  X VARCHAR(20) PRIMARY KEY,
  A VARCHAR(10),
  FOREIGN KEY (A) REFERENCES T1(A)
);
INSERT INTO T1 VALUES ('a', 'p', 9999999999999);
INSERT INTO T1 VALUES ('b', 'q', -9999999999999);
INSERT INTO T2 VALUES ('m', 'a');
INSERT INTO T2 VALUES ('n', 'b');
SELECT T2.X, T1.C FROM T2 INNER JOIN T1 ON T2.A = T1.A WHERE T1.C > -1000000000000;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T2_5260 ON T2(A COLLATE NOCASE) WHERE A > 0;
SELECT LAG(C, 0, 'default') OVER (ORDER BY C RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE NO OTHERS) FROM T1;
ROLLBACK TO sp6682;
RELEASE sp6682;
SAVEPOINT sp6682;
ATTACH DATABASE ':memory:' AS aux6;
SAVEPOINT sp4545;
-- .timeout -1

creATE VIRTUAL TABLE t0 USING fts3("x", "y", "z");
DROP TABLE t0;
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (json_object(),3.141592653589793,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
ROLLBACK TO sp4545;
RELEASE sp4545;
DETACH DATABASE aux6;
CREATE TABLE T1 (
  A VARCHAR(10) PRIMARY KEY,
  B VARCHAR(15) UNIQUE,
  C BIGINT
);
CREATE TABLE T2 (
  X VARCHAR(20) PRIMARY KEY,
  A VARCHAR(10),
  FOREIGN KEY (A) REFERENCES T1(A)
);
INSERT INTO T1 VALUES ('a', 'p', 9999999999999);
INSERT INTO T1 VALUES ('b', 'q', -9999999999999);
INSERT INTO T2 VALUES ('m', 'a');
INSERT INTO T2 VALUES ('n', 'b');
SELECT T2.X, T1.C FROM T2 INNER JOIN T1 ON T2.A = T1.A WHERE T1.C > -1000000000000;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T2_5260 ON T2(A COLLATE NOCASE) WHERE A > 0;
SELECT LAG(C, 0, 'default') OVER (ORDER BY C RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE NO OTHERS) FROM T1;
ROLLBACK TO sp6682;
RELEASE sp6682;
SAVEPOINT sp6682;
ATTACH DATABASE ':memory:' AS aux6;
SAVEPOINT sp4545;
-- .timeout -1

creATE VIRTUAL TABLE t0 USING fts3("x", "y", "z");
DROP TABLE t0;
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (json_object(),3.141592653589793,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
ROLLBACK TO sp4545;
RELEASE sp4545;
DETACH DATABASE aux6;
CREATE TABLE T1 (
  A VARCHAR(10) PRIMARY KEY,
  B VARCHAR(15) UNIQUE,
  C BIGINT
);
CREATE TABLE T2 (
  X VARCHAR(20) PRIMARY KEY,
  A VARCHAR(10),
  FOREIGN KEY (A) REFERENCES T1(A)
);
INSERT INTO T1 VALUES ('a', 'p', 9999999999999);
INSERT INTO T1 VALUES ('b', 'q', -9999999999999);
INSERT INTO T2 VALUES ('m', 'a');
INSERT INTO T2 VALUES ('n', 'b');
SELECT T2.X, T1.C FROM T2 INNER JOIN T1 ON T2.A = T1.A WHERE T1.C > -1000000000000;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T2_5260 ON T2(A COLLATE NOCASE) WHERE A > 0;
SELECT LAG(C, 0, 'default') OVER (ORDER BY C RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE NO OTHERS) FROM T1;
ROLLBACK TO sp6682;
RELEASE sp6682;
SAVEPOINT sp6682;
ATTACH DATABASE ':memory:' AS aux6;
SAVEPOINT sp4545;
-- .timeout -1

creATE VIRTUAL TABLE t0 USING fts3("x", "y", "z");
DROP TABLE t0;
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (json_object(),3.141592653589793,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
ROLLBACK TO sp4545;
RELEASE sp4545;
DETACH DATABASE aux6;
CREATE TABLE T1 (
  A VARCHAR(10) PRIMARY KEY,
  B VARCHAR(15) UNIQUE,
  C BIGINT
);
CREATE TABLE T2 (
  X VARCHAR(20) PRIMARY KEY,
  A VARCHAR(10),
  FOREIGN KEY (A) REFERENCES T1(A)
);
INSERT INTO T1 VALUES ('a', 'p', 9999999999999);
INSERT INTO T1 VALUES ('b', 'q', -9999999999999);
INSERT INTO T2 VALUES ('m', 'a');
INSERT INTO T2 VALUES ('n', 'b');
SELECT T2.X, T1.C FROM T2 INNER JOIN T1 ON T2.A = T1.A WHERE T1.C > -1000000000000;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T2_5260 ON T2(A COLLATE NOCASE) WHERE A > 0;
SELECT LAG(C, 0, 'default') OVER (ORDER BY C RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE NO OTHERS) FROM T1;
ROLLBACK TO sp6682;
RELEASE sp6682;
SAVEPOINT sp6682;
ATTACH DATABASE ':memory:' AS aux6;
SAVEPOINT sp4545;
-- .timeout -1

creATE VIRTUAL TABLE t0 USING fts3("x", "y", "z");
DROP TABLE t0;
CREATE TABLE T (
  a INTEGER,
  b REAL,
  c REAL
);
INSERT INTO T VALUES (json_object(),3.141592653589793,10.5), (1,-3.5,20.25), (2,9e999,-1.0);
WITH d AS (SELECT a,SUM(b*c) AS e FROM T GROUP BY a) SELECT * FROM d;
ROLLBACK TO sp4545;
RELEASE sp4545;
DETACH DATABASE aux6;
CREATE TABLE T1 (
  A VARCHAR(10) PRIMARY KEY,
  B VARCHAR(15) UNIQUE,
  C BIGINT
);
CREATE TABLE T2 (
  X VARCHAR(20) PRIMARY KEY,
  A VARCHAR(10),
  FOREIGN KEY (A) REFERENCES T1(A)
);
INSERT INTO T1 VALUES ('a', 'p', 9999999999999);
INSERT INTO T1 VALUES ('b', 'q', -9999999999999);
INSERT INTO T2 VALUES ('m', 'a');
INSERT INTO T2 VALUES ('n', 'b');
SELECT T2.X, T1.C FROM T2 INNER JOIN T1 ON T2.A = T1.A WHERE T1.C > -1000000000000;
CREATE UNIQUE  INDEX IF NOT EXISTS idx_T2_5260 ON T2(A COLLATE NOCASE) WHERE A > 0;
SELECT LAG(C, 0, 'default') OVER (ORDER BY C RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING EXCLUDE NO OTHERS) FROM T1;
ROLLBACK TO sp6682;
RELEASE sp6682;

WITH cte AS (SELECT NULL AS x) SELECT COALESCE(x, 0) FROM cte;
PRAGMA max_page_count;
```

## Actual output

```sql
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
0
1073741823
```

## Expectation

```sql
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
1|-70.875
2|-Inf
{}|32.9867228626928
m|9999999999999
-9999999999999
9999999999999
0
4294967294
```

## Flag

```

```

